verify before validator set change at sprint end

This commit is contained in:
Jaynti Kanani 2019-12-03 18:50:30 +05:30
parent 6e9fb12945
commit 29e8a42df6
No known key found for this signature in database
GPG key ID: 4396982C976BAE5E
2 changed files with 16 additions and 16 deletions

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
@ -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()