cmd/era: also check iterator error after loop

This commit is contained in:
lightclient 2025-09-22 11:48:58 -06:00
parent d367576093
commit dccb358660
No known key found for this signature in database
GPG key ID: 657913021EF45A6A

View file

@ -273,8 +273,8 @@ func checkAccumulator(e *era.Era) error {
// accumulation across the entire set and are verified at the end.
for it.Next() {
// 1) next() walks the block index, so we're able to implicitly verify it.
if itErr := it.Error(); itErr != nil {
return fmt.Errorf("error reading block %d: %w", it.Number(), itErr)
if it.Error() != nil {
return fmt.Errorf("error reading block %d: %w", it.Number(), it.Error())
}
block, receipts, err := it.BlockAndReceipts()
if err != nil {
@ -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 {