consensus/bor: validate valset from header at sprint end (#7438)

This PR adds changes from https://github.com/maticnetwork/bor/pull/768
and https://github.com/maticnetwork/bor/pull/787.

Note that bor fetches the data from the child chain contract via
`getBorValidators` method while erigon does it via fetching the required
span from heimdall (or cache if present). Hence, as done in bor, we
don't really need to create new methods to get data via block number or
hash.
This commit is contained in:
Manav Darji 2023-05-09 23:08:47 +05:30 committed by GitHub
parent f38ec1e772
commit b4fc18ad14
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -477,6 +477,33 @@ func (c *Bor) verifyCascadingFields(chain consensus.ChainHeaderReader, header *t
return err
}
// Verify the validator list match the local contract
if isSprintStart(number+1, c.config.CalculateSprint(number)) {
newValidators, err := c.spanner.GetCurrentValidators(number+1, c.authorizedSigner.Load().signer, c.getSpanForBlock)
if err != nil {
return err
}
sort.Sort(valset.ValidatorsByAddress(newValidators))
headerVals, err := valset.ParseValidators(header.Extra[extraVanity : len(header.Extra)-extraSeal])
if err != nil {
return err
}
if len(newValidators) != len(headerVals) {
return errInvalidSpanValidators
}
for i, val := range newValidators {
if !bytes.Equal(val.HeaderBytes(), headerVals[i].HeaderBytes()) {
return errInvalidSpanValidators
}
}
}
// verify the validator list in the last sprint block
if isSprintStart(number, c.config.CalculateSprint(number)) {
parentValidatorBytes := parent.Extra[extraVanity : len(parent.Extra)-extraSeal]