From 3011d499469e1e317c2461a95aa0d42d28061447 Mon Sep 17 00:00:00 2001 From: tersec Date: Tue, 14 Feb 2023 06:48:39 +0000 Subject: [PATCH] refactor fcU sending and rename EL-side root to hash (#4614) --- beacon_chain/beacon_node_light_client.nim | 6 ++-- .../consensus_manager.nim | 28 ++++++++----------- .../gossip_processing/block_processor.nim | 7 ++--- beacon_chain/nimbus_light_client.nim | 6 ++-- .../eth2_apis/eth2_rest_serialization.nim | 4 +-- 5 files changed, 22 insertions(+), 29 deletions(-) diff --git a/beacon_chain/beacon_node_light_client.nim b/beacon_chain/beacon_node_light_client.nim index 0b00d5315..f01e4e9ce 100644 --- a/beacon_chain/beacon_node_light_client.nim +++ b/beacon_chain/beacon_node_light_client.nim @@ -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( diff --git a/beacon_chain/consensus_object_pools/consensus_manager.nim b/beacon_chain/consensus_object_pools/consensus_manager.nim index 6988d0785..b82e33825 100644 --- a/beacon_chain/consensus_object_pools/consensus_manager.nim +++ b/beacon_chain/consensus_object_pools/consensus_manager.nim @@ -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 diff --git a/beacon_chain/gossip_processing/block_processor.nim b/beacon_chain/gossip_processing/block_processor.nim index 1e2ed96c9..2c511f5fd 100644 --- a/beacon_chain/gossip_processing/block_processor.nim +++ b/beacon_chain/gossip_processing/block_processor.nim @@ -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) diff --git a/beacon_chain/nimbus_light_client.nim b/beacon_chain/nimbus_light_client.nim index 3a907d434..aa274b627 100644 --- a/beacon_chain/nimbus_light_client.nim +++ b/beacon_chain/nimbus_light_client.nim @@ -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) diff --git a/beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim b/beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim index e4f311dff..161464f22 100644 --- a/beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim +++ b/beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim @@ -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)