refactor fcU sending and rename EL-side root to hash (#4614)

This commit is contained in:
tersec 2023-02-14 06:48:39 +00:00 committed by GitHub
parent 07ccd3fa6e
commit 3011d49946
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 22 additions and 29 deletions

View File

@ -68,9 +68,9 @@ proc initLightClient*(
# engine_forkchoiceUpdatedV1
let beaconHead = node.attestationPool[].getBeaconHead(nil)
discard await eth1Monitor.runForkchoiceUpdated(
headBlockRoot = payload.block_hash,
safeBlockRoot = beaconHead.safeExecutionPayloadHash,
finalizedBlockRoot = beaconHead.finalizedExecutionPayloadHash)
headBlockHash = payload.block_hash,
safeBlockHash = beaconHead.safeExecutionPayloadHash,
finalizedBlockHash = beaconHead.finalizedExecutionPayloadHash)
else: discard
optimisticProcessor = initOptimisticProcessor(

View File

@ -166,9 +166,9 @@ func setOptimisticHead*(
proc runForkchoiceUpdated*(
eth1Monitor: Eth1Monitor,
headBlockRoot, safeBlockRoot, finalizedBlockRoot: Eth2Digest):
headBlockHash, safeBlockHash, finalizedBlockHash: Eth2Digest):
Future[(PayloadExecutionStatus, Option[BlockHash])] {.async.} =
# Allow finalizedBlockRoot to be 0 to avoid sync deadlocks.
# Allow finalizedBlockHash to be 0 to avoid sync deadlocks.
#
# https://github.com/ethereum/EIPs/blob/master/EIPS/eip-3675.md#pos-events
# has "Before the first finalized block occurs in the system the finalized
@ -178,7 +178,7 @@ proc runForkchoiceUpdated*(
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.2/specs/bellatrix/validator.md#executionpayload
# notes "`finalized_block_hash` is the hash of the latest finalized execution
# payload (`Hash32()` if none yet finalized)"
doAssert not headBlockRoot.isZero
doAssert not headBlockHash.isZero
try:
# Minimize window for Eth1 monitor to shut down connection
@ -186,18 +186,18 @@ proc runForkchoiceUpdated*(
let fcuR = awaitWithTimeout(
forkchoiceUpdated(
eth1Monitor, headBlockRoot, safeBlockRoot, finalizedBlockRoot),
eth1Monitor, headBlockHash, safeBlockHash, finalizedBlockHash),
FORKCHOICEUPDATED_TIMEOUT):
debug "runForkchoiceUpdated: forkchoiceUpdated timed out",
headBlockRoot = shortLog(headBlockRoot),
safeBlockRoot = shortLog(safeBlockRoot),
finalizedBlockRoot = shortLog(finalizedBlockRoot)
headBlockHash = shortLog(headBlockHash),
safeBlockHash = shortLog(safeBlockHash),
finalizedBlockHash = shortLog(finalizedBlockHash)
ForkchoiceUpdatedResponse(
payloadStatus: PayloadStatusV1(
status: PayloadExecutionStatus.syncing))
debug "runForkchoiceUpdated: ran forkchoiceUpdated",
headBlockRoot, safeBlockRoot, finalizedBlockRoot,
headBlockHash, safeBlockHash, finalizedBlockHash,
payloadStatus = $fcuR.payloadStatus.status,
latestValidHash = $fcuR.payloadStatus.latestValidHash,
validationError = $fcuR.payloadStatus.validationError
@ -206,17 +206,11 @@ proc runForkchoiceUpdated*(
except CatchableError as err:
warn "forkchoiceUpdated failed - check execution client",
err = err.msg,
headBlockRoot = shortLog(headBlockRoot),
safeBlockRoot = shortLog(safeBlockRoot),
finalizedBlockRoot = shortLog(finalizedBlockRoot)
headBlockHash = shortLog(headBlockHash),
safeBlockHash = shortLog(safeBlockHash),
finalizedBlockHash = shortLog(finalizedBlockHash)
return (PayloadExecutionStatus.syncing, none BlockHash)
proc runForkchoiceUpdatedDiscardResult*(
eth1Monitor: Eth1Monitor,
headBlockHash, safeBlockHash, finalizedBlockHash: Eth2Digest) {.async.} =
discard await eth1Monitor.runForkchoiceUpdated(
headBlockHash, safeBlockHash, finalizedBlockHash)
from ../beacon_clock import GetBeaconTimeFn
from ../fork_choice/fork_choice import mark_root_invalid

View File

@ -15,9 +15,8 @@ import
from ../consensus_object_pools/consensus_manager import
ConsensusManager, checkNextProposer, optimisticExecutionPayloadHash,
runForkchoiceUpdated, runForkchoiceUpdatedDiscardResult,
runProposalForkchoiceUpdated, shouldSyncOptimistically, updateHead,
updateHeadWithExecution
runForkchoiceUpdated, runProposalForkchoiceUpdated, shouldSyncOptimistically,
updateHead, updateHeadWithExecution
from ../beacon_clock import GetBeaconTimeFn, toFloatSeconds
from ../consensus_object_pools/block_dag import BlockRef, root, shortLog, slot
from ../consensus_object_pools/block_pools_types import
@ -549,7 +548,7 @@ proc storeBlock*(
# - "Beacon chain gapped" from DAG head to optimistic head,
# - followed by "Beacon chain reorged" from optimistic head back to DAG.
self.consensusManager[].updateHead(newHead.get.blck)
await eth1Monitor.runForkchoiceUpdatedDiscardResult(
discard await eth1Monitor.runForkchoiceUpdated(
headBlockHash = self.consensusManager[].optimisticExecutionPayloadHash,
safeBlockHash = newHead.get.safeExecutionPayloadHash,
finalizedBlockHash = newHead.get.finalizedExecutionPayloadHash)

View File

@ -123,9 +123,9 @@ programMain:
# engine_forkchoiceUpdatedV1
discard await eth1Monitor.runForkchoiceUpdated(
headBlockRoot = payload.block_hash,
safeBlockRoot = payload.block_hash, # stub value
finalizedBlockRoot = ZERO_HASH)
headBlockHash = payload.block_hash,
safeBlockHash = payload.block_hash, # stub value
finalizedBlockHash = ZERO_HASH)
else: discard
optimisticProcessor = initOptimisticProcessor(
getBeaconTime, optimisticHandler)

View File

@ -1310,8 +1310,8 @@ proc readValue*(reader: var JsonReader[RestJson],
assign(ep_dst.gas_limit, ep_src.gas_limit)
assign(ep_dst.gas_used, ep_src.gas_used)
assign(ep_dst.timestamp, ep_src.timestamp)
assign(ep_dst.extra_Data, ep_src.extra_Data)
assign(ep_dst.base_fee_per_Gas, ep_src.base_fee_per_Gas)
assign(ep_dst.extra_data, ep_src.extra_data)
assign(ep_dst.base_fee_per_gas, ep_src.base_fee_per_gas)
assign(ep_dst.block_hash, ep_src.block_hash)
assign(ep_dst.transactions, ep_src.transactions)