mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-01 17:43:45 +00:00
fix: Validator list could be invalid making the node crash (2.13)
This commit is contained in:
parent
122a2304db
commit
b00299ca13
2 changed files with 18 additions and 6 deletions
|
|
@ -346,12 +346,9 @@ func (c *Bor) verifyHeader(chain consensus.ChainReader, header *types.Header, pa
|
|||
if header.Time > uint64(time.Now().Unix()) {
|
||||
return consensus.ErrFutureBlock
|
||||
}
|
||||
// Check that the extra-data contains both the vanity and signature
|
||||
if len(header.Extra) < extraVanity {
|
||||
return errMissingVanity
|
||||
}
|
||||
if len(header.Extra) < extraVanity+extraSeal {
|
||||
return errMissingSignature
|
||||
|
||||
if err := validateHeaderExtraField(header.Extra); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// check extr adata
|
||||
|
|
@ -387,6 +384,18 @@ func (c *Bor) verifyHeader(chain consensus.ChainReader, header *types.Header, pa
|
|||
return c.verifyCascadingFields(chain, header, parents)
|
||||
}
|
||||
|
||||
// validateHeaderExtraField validates that the extra-data contains both the vanity and signature.
|
||||
// header.Extra = header.Vanity + header.ProducerBytes (optional) + header.Seal
|
||||
func validateHeaderExtraField(extraBytes []byte) error {
|
||||
if len(extraBytes) < extraVanity {
|
||||
return errMissingVanity
|
||||
}
|
||||
if len(extraBytes) < extraVanity+extraSeal {
|
||||
return errMissingSignature
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// verifyCascadingFields verifies all the header fields that are not standalone,
|
||||
// rather depend on a batch of previous headers. The caller may optionally pass
|
||||
// in a batch of parents (ascending order) to avoid looking those up from the
|
||||
|
|
|
|||
|
|
@ -185,6 +185,9 @@ func (s *Snapshot) apply(headers []*types.Header) (*Snapshot, error) {
|
|||
|
||||
// change validator set and change proposer
|
||||
if number > 0 && (number+1)%s.config.Sprint == 0 {
|
||||
if err := validateHeaderExtraField(header.Extra); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
validatorBytes := header.Extra[extraVanity : len(header.Extra)-extraSeal]
|
||||
|
||||
// get validators from headers and use that for new validator set
|
||||
|
|
|
|||
Loading…
Reference in a new issue