Skip to content

Commit e6b8bc6

Browse files
authored
harden exchangeTransitionConfiguration retries (#4095)
`p.dataProvider` may become `nil` between individual attempts to exchange transition configuration with the EL. Harden by capturing the data provider on function start. Note that other functions are already hardened, or are unaffected. Only `close` transitions `p.dataProvider` to `nil`, and `close` is only called by the main deposits import sequence. During the deposits import, `close` is not called, so extra checks are not needed.
1 parent eb791cf commit e6b8bc6

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

beacon_chain/eth1/eth1_monitor.nim

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -554,8 +554,10 @@ proc exchangeTransitionConfiguration*(p: Eth1Monitor): Future[EtcStatus] {.async
554554
# don't crash.
555555
if p.isNil:
556556
debug "exchangeTransitionConfiguration: nil Eth1Monitor"
557+
return EtcStatus.exchangeError
557558

558-
if p.isNil or p.dataProvider.isNil:
559+
let dataProvider = p.dataProvider
560+
if dataProvider.isNil:
559561
return EtcStatus.exchangeError
560562

561563
let consensusCfg = TransitionConfigurationV1(
@@ -573,7 +575,7 @@ proc exchangeTransitionConfiguration*(p: Eth1Monitor): Future[EtcStatus] {.async
573575
let executionCfg =
574576
try:
575577
awaitWithRetries(
576-
p.dataProvider.web3.provider.engine_exchangeTransitionConfigurationV1(
578+
dataProvider.web3.provider.engine_exchangeTransitionConfigurationV1(
577579
consensusCfg),
578580
timeout = 1.seconds)
579581
except CatchableError as err:
@@ -1162,6 +1164,7 @@ func earliestBlockOfInterest(m: Eth1Monitor): Eth1BlockNumber =
11621164
proc syncBlockRange(m: Eth1Monitor,
11631165
fromBlock, toBlock,
11641166
fullSyncFromBlock: Eth1BlockNumber) {.gcsafe, async.} =
1167+
doAssert m.dataProvider != nil, "close not called concurrently"
11651168
doAssert m.depositsChain.blocks.len > 0
11661169

11671170
var currentBlock = fromBlock
@@ -1350,6 +1353,7 @@ proc startEth1Syncing(m: Eth1Monitor, delayBeforeStart: Duration) {.async.} =
13501353
await provider.close()
13511354

13521355
await m.ensureDataProvider()
1356+
doAssert m.dataProvider != nil, "close not called concurrently"
13531357

13541358
if m.currentEpoch >= m.cfg.BELLATRIX_FORK_EPOCH:
13551359
let status = await m.exchangeTransitionConfiguration()
@@ -1636,6 +1640,7 @@ when hasGenesisDetection:
16361640

16371641
proc findGenesisBlockInRange(m: Eth1Monitor, startBlock, endBlock: Eth1Block):
16381642
Future[Eth1Block] {.async.} =
1643+
doAssert m.dataProvider != nil, "close not called concurrently"
16391644
doAssert startBlock.timestamp != 0 and not m.isAfterMinGenesisTime(startBlock)
16401645
doAssert endBlock.timestamp != 0 and m.isAfterMinGenesisTime(endBlock)
16411646
doAssert m.hasEnoughValidators(startBlock)

0 commit comments

Comments
 (0)