Merge pull request #9 from maticnetwork/mat-494

MAT-494 verify block before validator set change at sprint end
This commit is contained in:
Vaibhav Chellani 2019-12-04 17:07:59 +05:30 committed by GitHub
commit d9ffa9605d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 19 deletions

View file

@ -577,7 +577,7 @@ func (c *Bor) verifySeal(chain consensus.ChainReader, header *types.Header, pare
}
proposerIndex, _ := snap.ValidatorSet.GetByAddress(proposer)
signerIndex, _ := snap.ValidatorSet.GetByAddress(signer)
limit := len(validators) - (len(validators)/2 + 1)
limit := len(validators)/2 + 1
// temp index
tempIndex := signerIndex
@ -761,7 +761,7 @@ func (c *Bor) Seal(chain consensus.ChainReader, block *types.Block, results chan
proposerIndex, _ := snap.ValidatorSet.GetByAddress(proposer)
signerIndex, _ := snap.ValidatorSet.GetByAddress(signer)
limit := len(validators) - (len(validators)/2 + 1)
limit := len(validators)/2 + 1
// temp index
tempIndex := signerIndex

View file

@ -65,7 +65,6 @@ func FetchFromHeimdallWithRetry(client http.Client, urlString string, paths ...s
}
fmt.Println("Retrying again in 5 seconds", u.String())
time.Sleep(5 * time.Second)
}
}

View file

@ -21,12 +21,12 @@ import (
"encoding/json"
"fmt"
lru "github.com/hashicorp/golang-lru"
"github.com/maticnetwork/bor/common"
"github.com/maticnetwork/bor/core/types"
"github.com/maticnetwork/bor/ethdb"
"github.com/maticnetwork/bor/internal/ethapi"
"github.com/maticnetwork/bor/params"
lru "github.com/hashicorp/golang-lru"
)
// Snapshot is the state of the authorization voting at a given point in time.
@ -150,20 +150,6 @@ func (s *Snapshot) apply(headers []*types.Header) (*Snapshot, error) {
return nil, err
}
// change validator set and change proposer
if number > 0 && (number+1)%s.config.Sprint == 0 {
validatorBytes := header.Extra[extraVanity : len(header.Extra)-extraSeal]
// get validators from headers and use that for new validator set
newVals, _ := ParseValidators(validatorBytes)
v := getUpdatedValidatorSet(snap.ValidatorSet.Copy(), newVals)
v.IncrementProposerPriority(1)
snap.ValidatorSet = v
// log new validator set
fmt.Println("Current validator set", "number", snap.Number, "validatorSet", snap.ValidatorSet)
}
// check if signer is in validator set
if !snap.ValidatorSet.HasAddress(signer.Bytes()) {
return nil, errUnauthorizedSigner
@ -178,7 +164,7 @@ func (s *Snapshot) apply(headers []*types.Header) (*Snapshot, error) {
proposer := snap.ValidatorSet.GetProposer().Address
proposerIndex, _ := snap.ValidatorSet.GetByAddress(proposer)
signerIndex, _ := snap.ValidatorSet.GetByAddress(signer)
limit := len(validators) - (len(validators)/2 + 1)
limit := len(validators)/2 + 1
// temp index
tempIndex := signerIndex
@ -188,12 +174,27 @@ func (s *Snapshot) apply(headers []*types.Header) (*Snapshot, error) {
}
if tempIndex-proposerIndex > limit {
fmt.Println("Invalid signer: error while applying headers", "proposerIndex", validators[proposerIndex].Address.Hex(), "signerIndex", validators[signerIndex].Address.Hex())
return nil, errRecentlySigned
}
}
// add recents
snap.Recents[number] = signer
// change validator set and change proposer
if number > 0 && (number+1)%s.config.Sprint == 0 {
validatorBytes := header.Extra[extraVanity : len(header.Extra)-extraSeal]
// get validators from headers and use that for new validator set
newVals, _ := ParseValidators(validatorBytes)
v := getUpdatedValidatorSet(snap.ValidatorSet.Copy(), newVals)
v.IncrementProposerPriority(1)
snap.ValidatorSet = v
// log new validator set
fmt.Println("New changed validator set", "number", snap.Number, "validatorSet", snap.ValidatorSet, "currentSigner", signer.Hex())
}
}
snap.Number += uint64(len(headers))
snap.Hash = headers[len(headers)-1].Hash()