Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b1113aa

Browse files
authored
eth: fix crash on querying finalized block (ethereum#27162)
eth: fix crash on querying nil finalized block
1 parent 2f98dd3 commit b1113aa

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

eth/api_backend.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,19 @@ func (b *EthAPIBackend) BlockByNumber(ctx context.Context, number rpc.BlockNumbe
134134
return nil, errors.New("'finalized' tag not supported on pre-merge network")
135135
}
136136
header := b.eth.blockchain.CurrentFinalBlock()
137+
if header == nil {
138+
return nil, errors.New("finalized block not found")
139+
}
137140
return b.eth.blockchain.GetBlock(header.Hash(), header.Number.Uint64()), nil
138141
}
139142
if number == rpc.SafeBlockNumber {
140143
if !b.eth.Merger().TDDReached() {
141144
return nil, errors.New("'safe' tag not supported on pre-merge network")
142145
}
143146
header := b.eth.blockchain.CurrentSafeBlock()
147+
if header == nil {
148+
return nil, errors.New("safe block not found")
149+
}
144150
return b.eth.blockchain.GetBlock(header.Hash(), header.Number.Uint64()), nil
145151
}
146152
return b.eth.blockchain.GetBlockByNumber(uint64(number)), nil

0 commit comments

Comments
 (0)