Skip to content

Commit 478e2ce

Browse files
committed
return specific error on hash mismatch
1 parent 040159c commit 478e2ce

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

writer_with_verify_hash.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@ package ethwal
22

33
import (
44
"context"
5+
"errors"
56
"fmt"
67

78
"github.com/0xsequence/ethkit/go-ethereum/common"
89
)
910

11+
var ErrParentHashMismatch = errors.New("parent hash mismatch")
12+
1013
type BlockHashGetter func(ctx context.Context, blockNum uint64) (common.Hash, error)
1114

1215
func BlockHashGetterFromReader[T any](options Options) BlockHashGetter {
@@ -72,8 +75,7 @@ func (w *writerWithVerifyHash[T]) Write(ctx context.Context, b Block[T]) error {
7275

7376
// Validate parent hash
7477
if b.Parent != w.prevHash {
75-
return fmt.Errorf("parent hash mismatch, expected %s, got %s",
76-
w.prevHash.String(), b.Parent.String())
78+
return fmt.Errorf("%w, expected %s, got %s", ErrParentHashMismatch, b.Parent.String(), w.prevHash.String())
7779
}
7880

7981
// Write block

0 commit comments

Comments
 (0)