Skip to content

Commit 2872242

Browse files
cmd/era: fix iterator error source handling in checkAccumulator (ethereum#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>
1 parent 1597d58 commit 2872242

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

cmd/era/main.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,10 +274,10 @@ func checkAccumulator(e *era.Era) error {
274274
for it.Next() {
275275
// 1) next() walks the block index, so we're able to implicitly verify it.
276276
if it.Error() != nil {
277-
return fmt.Errorf("error reading block %d: %w", it.Number(), err)
277+
return fmt.Errorf("error reading block %d: %w", it.Number(), it.Error())
278278
}
279279
block, receipts, err := it.BlockAndReceipts()
280-
if it.Error() != nil {
280+
if err != nil {
281281
return fmt.Errorf("error reading block %d: %w", it.Number(), err)
282282
}
283283
// 2) recompute tx root and verify against header.
@@ -294,6 +294,9 @@ func checkAccumulator(e *era.Era) error {
294294
td.Add(td, block.Difficulty())
295295
tds = append(tds, new(big.Int).Set(td))
296296
}
297+
if it.Error() != nil {
298+
return fmt.Errorf("error reading block %d: %w", it.Number(), it.Error())
299+
}
297300
// 4+5) Verify accumulator and total difficulty.
298301
got, err := era.ComputeAccumulator(hashes, tds)
299302
if err != nil {

0 commit comments

Comments
 (0)