From c8083f2c3206dbf6da34ce59a6703a367333956e Mon Sep 17 00:00:00 2001 From: tersec Date: Thu, 24 Nov 2022 07:53:04 +0000 Subject: [PATCH] implement more missing capella functionality (#4344) --- beacon_chain/beacon_chain_db.nim | 2 +- beacon_chain/eth1/eth1_monitor.nim | 28 +++++++++++++++++++ .../gossip_processing/block_processor.nim | 25 ++++------------- beacon_chain/spec/forks.nim | 6 ++++ .../validator_client/fallback_service.nim | 6 ++-- beacon_chain/validators/validator_duties.nim | 6 +--- beacon_chain/validators/validator_pool.nim | 2 +- 7 files changed, 46 insertions(+), 29 deletions(-) diff --git a/beacon_chain/beacon_chain_db.nim b/beacon_chain/beacon_chain_db.nim index 5b62e10f0..a4a4ee3ee 100644 --- a/beacon_chain/beacon_chain_db.nim +++ b/beacon_chain/beacon_chain_db.nim @@ -966,7 +966,7 @@ proc getBlockSZ*( of BeaconBlockFork.Bellatrix: getBlockSZ(db, key, data, bellatrix.TrustedSignedBeaconBlock) of BeaconBlockFork.Capella: - raiseAssert $capellaImplementationMissing + getBlockSZ(db, key, data, capella.TrustedSignedBeaconBlock) proc getStateOnlyMutableValidators( immutableValidators: openArray[ImmutableValidatorData2], diff --git a/beacon_chain/eth1/eth1_monitor.nim b/beacon_chain/eth1/eth1_monitor.nim index e1f2e4105..48c4445eb 100644 --- a/beacon_chain/eth1/eth1_monitor.nim +++ b/beacon_chain/eth1/eth1_monitor.nim @@ -369,6 +369,34 @@ func asEngineExecutionPayload*(executionPayload: bellatrix.ExecutionPayload): blockHash: executionPayload.block_hash.asBlockHash, transactions: mapIt(executionPayload.transactions, it.getTypedTransaction)) +from ../spec/datatypes/capella import ExecutionPayload + +func asEngineExecutionPayload*(executionPayload: capella.ExecutionPayload): + ExecutionPayloadV1 = + template getTypedTransaction(tt: bellatrix.Transaction): TypedTransaction = + TypedTransaction(tt.distinctBase) + + if true: + raiseAssert $capellaImplementationMissing & ": needs nim-web3 support for ExecutionPayloadV2" + + engine_api.ExecutionPayloadV1( + parentHash: executionPayload.parent_hash.asBlockHash, + feeRecipient: Address(executionPayload.fee_recipient.data), + stateRoot: executionPayload.state_root.asBlockHash, + receiptsRoot: executionPayload.receipts_root.asBlockHash, + logsBloom: + FixedBytes[BYTES_PER_LOGS_BLOOM](executionPayload.logs_bloom.data), + prevRandao: executionPayload.prev_randao.asBlockHash, + blockNumber: Quantity(executionPayload.block_number), + gasLimit: Quantity(executionPayload.gas_limit), + gasUsed: Quantity(executionPayload.gas_used), + timestamp: Quantity(executionPayload.timestamp), + extraData: + DynamicBytes[0, MAX_EXTRA_DATA_BYTES](executionPayload.extra_data), + baseFeePerGas: executionPayload.base_fee_per_gas, + blockHash: executionPayload.block_hash.asBlockHash, + transactions: mapIt(executionPayload.transactions, it.getTypedTransaction)) + func shortLog*(b: Eth1Block): string = try: &"{b.number}:{shortLog b.hash}(deposits = {b.depositCount})" diff --git a/beacon_chain/gossip_processing/block_processor.nim b/beacon_chain/gossip_processing/block_processor.nim index f19b3af56..e9e248438 100644 --- a/beacon_chain/gossip_processing/block_processor.nim +++ b/beacon_chain/gossip_processing/block_processor.nim @@ -236,9 +236,12 @@ from ../spec/datatypes/bellatrix import SignedBeaconBlock from eth/async_utils import awaitWithTimeout from ../spec/datatypes/bellatrix import ExecutionPayload, SignedBeaconBlock +from ../spec/datatypes/capella import + ExecutionPayload, SignedBeaconBlock, asTrusted, shortLog proc newExecutionPayload*( - eth1Monitor: Eth1Monitor, executionPayload: bellatrix.ExecutionPayload): + eth1Monitor: Eth1Monitor, + executionPayload: bellatrix.ExecutionPayload | capella.ExecutionPayload): Future[Opt[PayloadExecutionStatus]] {.async.} = if eth1Monitor.isNil: warn "newPayload: attempting to process execution payload without Eth1Monitor. Ensure --web3-url setting is correct and JWT is configured." @@ -287,14 +290,6 @@ proc newExecutionPayload*( error "newPayload failed", msg = err.msg return Opt.none PayloadExecutionStatus -# TODO when forks re-exports this, remove -from ../spec/datatypes/capella import ExecutionPayload - -proc newExecutionPayload*( - eth1Monitor: Eth1Monitor, executionPayload: capella.ExecutionPayload): - Future[Opt[PayloadExecutionStatus]] {.async.} = - raiseAssert $capellaImplementationMissing - proc getExecutionValidity( eth1Monitor: Eth1Monitor, blck: phase0.SignedBeaconBlock | altair.SignedBeaconBlock): @@ -302,7 +297,8 @@ proc getExecutionValidity( return NewPayloadStatus.valid # vacuously proc getExecutionValidity( - eth1Monitor: Eth1Monitor, blck: bellatrix.SignedBeaconBlock): + eth1Monitor: Eth1Monitor, + blck: bellatrix.SignedBeaconBlock | capella.SignedBeaconBlock): Future[NewPayloadStatus] {.async.} = # Eth1 syncing is asynchronous from this # TODO self.consensusManager.eth1Monitor.ttdReached @@ -336,15 +332,6 @@ proc getExecutionValidity( error "getExecutionValidity: newPayload failed", err = err.msg return NewPayloadStatus.noResponse -# TODO drop when forks re-exports all this -from ../spec/datatypes/capella import SignedBeaconBlock, asTrusted, shortLog - -proc getExecutionValidity( - eth1Monitor: Eth1Monitor, - blck: capella.SignedBeaconBlock): - Future[NewPayloadStatus] {.async.} = - raiseAssert $capellaImplementationMissing - proc storeBlock*( self: ref BlockProcessor, src: MsgSource, wallTime: BeaconTime, signedBlock: ForkySignedBeaconBlock, queueTick: Moment = Moment.now(), diff --git a/beacon_chain/spec/forks.nim b/beacon_chain/spec/forks.nim index 779e6da91..fd2555382 100644 --- a/beacon_chain/spec/forks.nim +++ b/beacon_chain/spec/forks.nim @@ -235,6 +235,8 @@ template toFork*[T: capella.BeaconState | capella.HashedBeaconState]( # T(kind: BeaconStateFork.Altair, altairData: data) # template init*(T: type ForkedHashedBeaconState, data: bellatrix.HashedBeaconState): T = # T(kind: BeaconStateFork.Bellatrix, bellatrixData: data) +# template init*(T: type ForkedHashedBeaconState, data: capella.HashedBeaconState): T = +# T(kind: BeaconStateFork.Capella, capellaData: data) template init*(T: type ForkedBeaconBlock, blck: phase0.BeaconBlock): T = T(kind: BeaconBlockFork.Phase0, phase0Data: blck) @@ -242,6 +244,8 @@ template init*(T: type ForkedBeaconBlock, blck: altair.BeaconBlock): T = T(kind: BeaconBlockFork.Altair, altairData: blck) template init*(T: type ForkedBeaconBlock, blck: bellatrix.BeaconBlock): T = T(kind: BeaconBlockFork.Bellatrix, bellatrixData: blck) +template init*(T: type ForkedBeaconBlock, blck: capella.BeaconBlock): T = + T(kind: BeaconBlockFork.Capella, capellaData: blck) template init*(T: type ForkedTrustedBeaconBlock, blck: phase0.TrustedBeaconBlock): T = T(kind: BeaconBlockFork.Phase0, phase0Data: blck) @@ -249,6 +253,8 @@ template init*(T: type ForkedTrustedBeaconBlock, blck: altair.TrustedBeaconBlock T(kind: BeaconBlockFork.Altair, altairData: blck) template init*(T: type ForkedTrustedBeaconBlock, blck: bellatrix.TrustedBeaconBlock): T = T(kind: BeaconBlockFork.Bellatrix, bellatrixData: blck) +template init*(T: type ForkedTrustedBeaconBlock, blck: capella.TrustedBeaconBlock): T = + T(kind: BeaconBlockFork.Capella, capellaData: blck) template init*(T: type ForkedSignedBeaconBlock, blck: phase0.SignedBeaconBlock): T = T(kind: BeaconBlockFork.Phase0, phase0Data: blck) diff --git a/beacon_chain/validator_client/fallback_service.nim b/beacon_chain/validator_client/fallback_service.nim index 5c2da8860..034514551 100644 --- a/beacon_chain/validator_client/fallback_service.nim +++ b/beacon_chain/validator_client/fallback_service.nim @@ -204,16 +204,16 @@ proc checkSync(vc: ValidatorClientRef, if not(syncInfo.is_syncing) or (syncInfo.sync_distance < SYNC_TOLERANCE): if not(syncInfo.is_optimistic.get(false)): info "Beacon node is in sync", sync_distance = syncInfo.sync_distance, - head_slot = syncInfo.head_slot, is_opimistic = optimistic + head_slot = syncInfo.head_slot, is_optimistic = optimistic RestBeaconNodeStatus.Online else: warn "Execution client not in sync (beacon node optimistically synced)", sync_distance = syncInfo.sync_distance, - head_slot = syncInfo.head_slot, is_opimistic = optimistic + head_slot = syncInfo.head_slot, is_optimistic = optimistic RestBeaconNodeStatus.NotSynced else: warn "Beacon node not in sync", sync_distance = syncInfo.sync_distance, - head_slot = syncInfo.head_slot, is_opimistic = optimistic + head_slot = syncInfo.head_slot, is_optimistic = optimistic RestBeaconNodeStatus.NotSynced proc checkOnline(node: BeaconNodeServerRef) {.async.} = diff --git a/beacon_chain/validators/validator_duties.nim b/beacon_chain/validators/validator_duties.nim index 1620f4c71..938390765 100644 --- a/beacon_chain/validators/validator_duties.nim +++ b/beacon_chain/validators/validator_duties.nim @@ -389,7 +389,7 @@ proc getExecutionPayload[T]( template empty_execution_payload(): auto = withState(proposalState[]): when stateFork >= BeaconStateFork.Capella: - raiseAssert $capellaImplementationMissing + raiseAssert $capellaImplementationMissing & ": beacon_chain/validators/validator_duties.nim: getExecutionPayload" elif stateFork >= BeaconStateFork.Bellatrix: build_empty_execution_payload(forkyState.data, feeRecipient) else: @@ -475,10 +475,6 @@ proc makeBeaconBlockForHeadAndSlot*( var cache = StateCache() - # Execution payload handling will need a review post-Bellatrix - if slot.epoch >= node.dag.cfg.CAPELLA_FORK_EPOCH: - raiseAssert $capellaImplementationMissing - let # The clearance state already typically sits at the right slot per # `advanceClearanceState` diff --git a/beacon_chain/validators/validator_pool.nim b/beacon_chain/validators/validator_pool.nim index 3b7353d5d..d703aa64c 100644 --- a/beacon_chain/validators/validator_pool.nim +++ b/beacon_chain/validators/validator_pool.nim @@ -360,7 +360,7 @@ proc getBlockSignature*(v: AttachedValidator, fork: Fork, kind: BeaconBlockFork.Bellatrix, bellatrixData: blck.bellatrixData.toBeaconBlockHeader) of BeaconBlockFork.Capella: - raiseAssert $capellaImplementationMissing + raiseAssert $capellaImplementationMissing & "beacon_chain/validators/validator_pool.nim: getBlockSignature" request = Web3SignerRequest.init( fork, genesis_validators_root, web3SignerBlock)