diff --git a/consensus/bor/rest.go b/consensus/bor/rest.go index d68c70304e..6e234c18ac 100644 --- a/consensus/bor/rest.go +++ b/consensus/bor/rest.go @@ -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) - } } diff --git a/consensus/bor/snapshot.go b/consensus/bor/snapshot.go index 09f08af5ad..9d41d7f3fb 100644 --- a/consensus/bor/snapshot.go +++ b/consensus/bor/snapshot.go @@ -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 @@ -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()