Skip to content

Commit d899a6a

Browse files
committed
Prevent a potential panic on dereferencing a 'none' value
1 parent 46f4826 commit d899a6a

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

beacon_chain/eth1/eth1_monitor.nim

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1987,6 +1987,15 @@ proc syncEth1Chain(m: ELManager, connection: ELConnection) {.async.} =
19871987
let rpcClient = awaitOrRaiseOnTimeout(connection.connectedRpcClient(),
19881988
1.seconds)
19891989
let
1990+
# BEWARE
1991+
# `connectedRpcClient` guarantees that connection.web3 will not be
1992+
# `none` here, but it's not safe to initialize this later (e.g closer
1993+
# to where it's used) because `connection.web3` may be set to `none`
1994+
# at any time after a failed request. Luckily, the `contractSender`
1995+
# object is very cheap to create.
1996+
depositContract = connection.web3.get.contractSender(
1997+
DepositContract, m.depositContractAddress)
1998+
19901999
shouldProcessDeposits = not (
19912000
m.depositContractAddress.isZeroMemory or
19922001
m.eth1Chain.finalizedBlockHash.data.isZeroMemory)
@@ -2085,8 +2094,6 @@ proc syncEth1Chain(m: ELManager, connection: ELConnection) {.async.} =
20852094

20862095
if shouldProcessDeposits and
20872096
latestBlock.number.uint64 > m.cfg.ETH1_FOLLOW_DISTANCE:
2088-
let depositContract = connection.web3.get.contractSender(
2089-
DepositContract, m.depositContractAddress)
20902097
await m.syncBlockRange(connection,
20912098
rpcClient,
20922099
depositContract,

0 commit comments

Comments
 (0)