Skip to content

Commit 895120c

Browse files
authored
Add reorg block check (#892)
1 parent 8c00f42 commit 895120c

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

tx-submitter/services/reorg.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ func (r *ReorgDetector) DetectReorg(ctx context.Context) (bool, uint64, error) {
5353
if err != nil {
5454
return false, 0, fmt.Errorf("failed to get latest block: %w", err)
5555
}
56+
if latestBlock == nil {
57+
return false, 0, fmt.Errorf("latest block is nil")
58+
}
5659

5760
// Check each block in history to find reorg point
5861
reorgDepth := uint64(0)
@@ -61,6 +64,9 @@ func (r *ReorgDetector) DetectReorg(ctx context.Context) (bool, uint64, error) {
6164
if err != nil {
6265
return false, 0, fmt.Errorf("failed to get block %d: %w", info.number, err)
6366
}
67+
if block == nil {
68+
return false, 0, fmt.Errorf("block %d is nil", info.number)
69+
}
6470

6571
if block.Hash() != info.hash {
6672
// Reorg detected
@@ -92,6 +98,9 @@ func (r *ReorgDetector) updateHistory(ctx context.Context) error {
9298
if err != nil {
9399
return fmt.Errorf("failed to get latest block: %w", err)
94100
}
101+
if latest == nil {
102+
return fmt.Errorf("latest block is nil")
103+
}
95104

96105
// Add new blocks to history
97106
currentNum := latest.NumberU64()
@@ -105,6 +114,9 @@ func (r *ReorgDetector) updateHistory(ctx context.Context) error {
105114
if err != nil {
106115
return fmt.Errorf("failed to get block %d: %w", num, err)
107116
}
117+
if block == nil {
118+
return fmt.Errorf("block %d is nil", num)
119+
}
108120

109121
r.blockHistory = append(r.blockHistory, blockInfo{
110122
number: num,

0 commit comments

Comments
 (0)