From 154723947b3f86b2c563d7118306c337ae25f232 Mon Sep 17 00:00:00 2001 From: zah Date: Tue, 20 Sep 2022 09:17:25 +0300 Subject: [PATCH] Don't search for the TTD block after the merge (#4152) --- beacon_chain/eth1/eth1_monitor.nim | 15 ++++++++++++--- .../gossip_processing/block_processor.nim | 2 +- beacon_chain/nimbus_beacon_node.nim | 6 ++++-- beacon_chain/nimbus_light_client.nim | 5 ++++- beacon_chain/validators/validator_duties.nim | 12 ++++-------- 5 files changed, 25 insertions(+), 15 deletions(-) diff --git a/beacon_chain/eth1/eth1_monitor.nim b/beacon_chain/eth1/eth1_monitor.nim index db36398e2..285876549 100644 --- a/beacon_chain/eth1/eth1_monitor.nim +++ b/beacon_chain/eth1/eth1_monitor.nim @@ -141,6 +141,8 @@ type stopFut: Future[void] getBeaconTime: GetBeaconTimeFn + ttdReachedField: bool + when hasGenesisDetection: genesisValidators: seq[ImmutableValidatorData] genesisValidatorKeyToIndex: Table[ValidatorPubKey, ValidatorIndex] @@ -196,6 +198,9 @@ declareGauge eth1_finalized_deposits, declareGauge eth1_chain_len, "The length of the in-memory chain of Eth1 blocks" +func ttdReached*(m: Eth1Monitor): bool = + m.ttdReachedField + template cfg(m: Eth1Monitor): auto = m.depositsChain.cfg @@ -1039,7 +1044,8 @@ proc init*(T: type Eth1Monitor, depositContractSnapshot: Option[DepositContractSnapshot], eth1Network: Option[Eth1Network], forcePolling: bool, - jwtSecret: Option[seq[byte]]): T = + jwtSecret: Option[seq[byte]], + ttdReached: bool): T = doAssert web3Urls.len > 0 var web3Urls = web3Urls for url in mitems(web3Urls): @@ -1057,7 +1063,8 @@ proc init*(T: type Eth1Monitor, eth1Progress: newAsyncEvent(), forcePolling: forcePolling, jwtSecret: jwtSecret, - blocksPerLogsRequest: targetBlocksPerLogsRequest) + blocksPerLogsRequest: targetBlocksPerLogsRequest, + ttdReachedField: ttdReached) proc safeCancel(fut: var Future[void]) = if not fut.isNil and not fut.finished: @@ -1450,7 +1457,8 @@ proc startEth1Syncing(m: Eth1Monitor, delayBeforeStart: Duration) {.async.} = let shouldCheckForMergeTransition = block: const FAR_FUTURE_TOTAL_DIFFICULTY = u256"115792089237316195423570985008687907853269984665640564039457584007913129638912" - m.cfg.TERMINAL_TOTAL_DIFFICULTY != FAR_FUTURE_TOTAL_DIFFICULTY + (not m.ttdReachedField) and + (m.cfg.TERMINAL_TOTAL_DIFFICULTY != FAR_FUTURE_TOTAL_DIFFICULTY) var didPollOnce = false while true: @@ -1519,6 +1527,7 @@ proc startEth1Syncing(m: Eth1Monitor, delayBeforeStart: Duration) {.async.} = break terminalBlockCandidate = parentBlock m.terminalBlockHash = some terminalBlockCandidate.hash + m.ttdReachedField = true debug "startEth1Syncing: found merge terminal block", currentEpoch = m.currentEpoch, diff --git a/beacon_chain/gossip_processing/block_processor.nim b/beacon_chain/gossip_processing/block_processor.nim index 31694ff91..e8338f8d6 100644 --- a/beacon_chain/gossip_processing/block_processor.nim +++ b/beacon_chain/gossip_processing/block_processor.nim @@ -503,7 +503,7 @@ proc runQueueProcessingLoop*(self: ref BlockProcessor) {.async.} = executionPayloadStatus = if hasExecutionPayload: # Eth1 syncing is asynchronous from this - # TODO self.consensusManager.eth1Monitor.terminalBlockHash.isSome + # TODO self.consensusManager.eth1Monitor.ttdReached # should gate this when it works more reliably # TODO detect have-TTD-but-not-is_execution_block case, and where # execution payload was non-zero when TTD detection more reliable diff --git a/beacon_chain/nimbus_beacon_node.nim b/beacon_chain/nimbus_beacon_node.nim index 245f7b0e6..d12796c63 100644 --- a/beacon_chain/nimbus_beacon_node.nim +++ b/beacon_chain/nimbus_beacon_node.nim @@ -541,7 +541,8 @@ proc init*(T: type BeaconNode, getDepositContractSnapshot(), eth1Network, config.web3ForcePolling, - optJwtSecret) + optJwtSecret, + ttdReached = false) eth1Monitor.loadPersistedDeposits() @@ -642,7 +643,8 @@ proc init*(T: type BeaconNode, getDepositContractSnapshot(), eth1Network, config.web3ForcePolling, - optJwtSecret) + optJwtSecret, + ttdReached = not dag.loadExecutionBlockRoot(dag.finalizedHead.blck).isZero) if config.rpcEnabled: warn "Nimbus's JSON-RPC server has been removed. This includes the --rpc, --rpc-port, and --rpc-address configuration options. https://nimbus.guide/rest-api.html shows how to enable and configure the REST Beacon API server which replaces it." diff --git a/beacon_chain/nimbus_light_client.nim b/beacon_chain/nimbus_light_client.nim index d16f29168..346c3046f 100644 --- a/beacon_chain/nimbus_light_client.nim +++ b/beacon_chain/nimbus_light_client.nim @@ -64,7 +64,10 @@ programMain: cfg, db = nil, getBeaconTime, config.web3Urls, none(DepositContractSnapshot), metadata.eth1Network, forcePolling = false, - rng[].loadJwtSecret(config, allowCreate = false)) + rng[].loadJwtSecret(config, allowCreate = false), + # TTD is not relevant for the light client, so it's safe + # to assume that the TTD has been reached. + ttdReached = true) waitFor res.ensureDataProvider() res else: diff --git a/beacon_chain/validators/validator_duties.nim b/beacon_chain/validators/validator_duties.nim index 777b6863b..68501b27b 100644 --- a/beacon_chain/validators/validator_duties.nim +++ b/beacon_chain/validators/validator_duties.nim @@ -373,18 +373,15 @@ proc getExecutionPayload[T]( const GETPAYLOAD_TIMEOUT = 1.seconds let - terminalBlockHash = - if node.eth1Monitor.terminalBlockHash.isSome: - node.eth1Monitor.terminalBlockHash.get.asEth2Digest - else: - default(Eth2Digest) beaconHead = node.attestationPool[].getBeaconHead(node.dag.head) executionBlockRoot = node.dag.loadExecutionBlockRoot(beaconHead.blck) latestHead = if not executionBlockRoot.isZero: executionBlockRoot + elif node.eth1Monitor.terminalBlockHash.isSome: + node.eth1Monitor.terminalBlockHash.get.asEth2Digest else: - terminalBlockHash + default(Eth2Digest) latestSafe = beaconHead.safeExecutionPayloadHash latestFinalized = beaconHead.finalizedExecutionPayloadHash feeRecipient = node.getFeeRecipient(pubkey, validator_index, epoch) @@ -489,8 +486,7 @@ proc makeBeaconBlockForHeadAndSlot*( elif slot.epoch < node.dag.cfg.BELLATRIX_FORK_EPOCH or not ( is_merge_transition_complete(proposalState[]) or - ((not node.eth1Monitor.isNil) and - node.eth1Monitor.terminalBlockHash.isSome)): + ((not node.eth1Monitor.isNil) and node.eth1Monitor.ttdReached)): # https://github.com/nim-lang/Nim/issues/19802 (static(default(bellatrix.ExecutionPayload))) else: