Skip to content

Commit

Permalink
fix: add special logic to handle ancestor errors (bnb-chain#14)
Browse files Browse the repository at this point in the history
Co-authored-by: Welkin <[email protected]>
Co-authored-by: Owen <[email protected]>
  • Loading branch information
3 people authored Jan 5, 2024
1 parent 0eb8a65 commit a6996ab
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion core/block_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package core

import (
"errors"
"fmt"

"github.com/ethereum/go-ethereum/common/gopool"
Expand Down Expand Up @@ -106,12 +107,26 @@ func (v *BlockValidator) ValidateBody(block *types.Block) error {
validateRes <- tmpFunc()
})
}
errs := make([]error, 0, len(validateFuns))
for i := 0; i < len(validateFuns); i++ {
err := <-validateRes
errs = append(errs, err)
}
var ancestorErr error
for _, err := range errs {
if err != nil {
return err
if !errors.Is(err, consensus.ErrUnknownAncestor) && !errors.Is(err, consensus.ErrPrunedAncestor) {
//Other errors are returned first.
return err
} else {
ancestorErr = err
}
}
}
//If there are no other errors, but an ancestorErr, return it.
if ancestorErr != nil {
return ancestorErr
}

return nil
}
Expand Down

0 comments on commit a6996ab

Please sign in to comment.