Skip to content

Commit

Permalink
consensus/bor: validate valset from header at sprint end (#7438)
Browse files Browse the repository at this point in the history
This PR adds changes from maticnetwork/bor#768
and maticnetwork/bor#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.
  • Loading branch information
manav2401 authored May 9, 2023
1 parent f38ec1e commit b4fc18a
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions consensus/bor/bor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit b4fc18a

Please sign in to comment.