mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-05-14 20:16:36 +00:00
cmd/era: fix iterator error source handling in checkAccumulator (#32698)
This change replaces wrapping a stale outer err with the iterator’s own error after Next(), and switches the post-BlockAndReceipts() check to use the returned err. According to internal/era iterator contract, Error() should be consulted immediately after Next() to surface iteration errors, while decoding errors from Block/Receipts are returned directly. The previous code could hide the real failure (using nil or unrelated err), leading to misleading diagnostics and missed iteration errors. --------- Co-authored-by: lightclient <lightclient@protonmail.com>
This commit is contained in:
parent
1597d58fae
commit
2872242045
1 changed files with 5 additions and 2 deletions
|
|
@ -274,10 +274,10 @@ func checkAccumulator(e *era.Era) error {
|
||||||
for it.Next() {
|
for it.Next() {
|
||||||
// 1) next() walks the block index, so we're able to implicitly verify it.
|
// 1) next() walks the block index, so we're able to implicitly verify it.
|
||||||
if it.Error() != nil {
|
if it.Error() != nil {
|
||||||
return fmt.Errorf("error reading block %d: %w", it.Number(), err)
|
return fmt.Errorf("error reading block %d: %w", it.Number(), it.Error())
|
||||||
}
|
}
|
||||||
block, receipts, err := it.BlockAndReceipts()
|
block, receipts, err := it.BlockAndReceipts()
|
||||||
if it.Error() != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error reading block %d: %w", it.Number(), err)
|
return fmt.Errorf("error reading block %d: %w", it.Number(), err)
|
||||||
}
|
}
|
||||||
// 2) recompute tx root and verify against header.
|
// 2) recompute tx root and verify against header.
|
||||||
|
|
@ -294,6 +294,9 @@ func checkAccumulator(e *era.Era) error {
|
||||||
td.Add(td, block.Difficulty())
|
td.Add(td, block.Difficulty())
|
||||||
tds = append(tds, new(big.Int).Set(td))
|
tds = append(tds, new(big.Int).Set(td))
|
||||||
}
|
}
|
||||||
|
if it.Error() != nil {
|
||||||
|
return fmt.Errorf("error reading block %d: %w", it.Number(), it.Error())
|
||||||
|
}
|
||||||
// 4+5) Verify accumulator and total difficulty.
|
// 4+5) Verify accumulator and total difficulty.
|
||||||
got, err := era.ComputeAccumulator(hashes, tds)
|
got, err := era.ComputeAccumulator(hashes, tds)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue