Skip to content

Commit

Permalink
Don't search for the TTD block after the merge (#4152)
Browse files Browse the repository at this point in the history
  • Loading branch information
zah authored Sep 20, 2022
1 parent bed8318 commit 1547239
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 15 deletions.
15 changes: 12 additions & 3 deletions beacon_chain/eth1/eth1_monitor.nim
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ type
stopFut: Future[void]
getBeaconTime: GetBeaconTimeFn

ttdReachedField: bool

when hasGenesisDetection:
genesisValidators: seq[ImmutableValidatorData]
genesisValidatorKeyToIndex: Table[ValidatorPubKey, ValidatorIndex]
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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):
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion beacon_chain/gossip_processing/block_processor.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions beacon_chain/nimbus_beacon_node.nim
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,8 @@ proc init*(T: type BeaconNode,
getDepositContractSnapshot(),
eth1Network,
config.web3ForcePolling,
optJwtSecret)
optJwtSecret,
ttdReached = false)

eth1Monitor.loadPersistedDeposits()

Expand Down Expand Up @@ -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."
Expand Down
5 changes: 4 additions & 1 deletion beacon_chain/nimbus_light_client.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 4 additions & 8 deletions beacon_chain/validators/validator_duties.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 1547239

Please sign in to comment.