From 2872242045377abe1ec9a54b8bc874dc2bb4febd Mon Sep 17 00:00:00 2001 From: MozirDmitriy Date: Mon, 22 Sep 2025 23:27:54 +0300 Subject: [PATCH] cmd/era: fix iterator error source handling in checkAccumulator (#32698) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- cmd/era/main.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cmd/era/main.go b/cmd/era/main.go index 8b57fd695c..35a889d4dc 100644 --- a/cmd/era/main.go +++ b/cmd/era/main.go @@ -274,10 +274,10 @@ func checkAccumulator(e *era.Era) error { for it.Next() { // 1) next() walks the block index, so we're able to implicitly verify it. 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() - if it.Error() != nil { + if err != nil { return fmt.Errorf("error reading block %d: %w", it.Number(), err) } // 2) recompute tx root and verify against header. @@ -294,6 +294,9 @@ func checkAccumulator(e *era.Era) error { td.Add(td, block.Difficulty()) 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. got, err := era.ComputeAccumulator(hashes, tds) if err != nil {