@@ -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