From 27921406e9872d1cc0ebb9e0348f614f556a916d Mon Sep 17 00:00:00 2001 From: tersec Date: Sat, 6 Apr 2024 13:11:47 +0000 Subject: [PATCH] remove some debugRaiseAsserts and fill in Electra functionality (#6179) --- .../consensus_object_pools/blockchain_dag.nim | 7 +++++-- .../consensus_object_pools/consensus_manager.nim | 6 +++--- beacon_chain/el/el_manager.nim | 8 ++++---- beacon_chain/nimbus_signing_node.nim | 3 +-- .../spec/eth2_apis/eth2_rest_serialization.nim | 12 ++++++++++-- beacon_chain/spec/forks.nim | 4 +++- beacon_chain/spec/state_transition.nim | 11 ++++++----- beacon_chain/spec/state_transition_block.nim | 6 +++--- 8 files changed, 35 insertions(+), 22 deletions(-) diff --git a/beacon_chain/consensus_object_pools/blockchain_dag.nim b/beacon_chain/consensus_object_pools/blockchain_dag.nim index 8fa5808a8..5502d7f7b 100644 --- a/beacon_chain/consensus_object_pools/blockchain_dag.nim +++ b/beacon_chain/consensus_object_pools/blockchain_dag.nim @@ -1005,8 +1005,11 @@ proc applyBlock( dag.cfg, state, data, cache, info, dag.updateFlags + {slotProcessed}, noRollback) of ConsensusFork.Electra: - debugRaiseAssert "electra applyblock missing" - return ok() + let data = getBlock(dag, bid, electra.TrustedSignedBeaconBlock).valueOr: + return err("Block load failed") + ? state_transition( + dag.cfg, state, data, cache, info, + dag.updateFlags + {slotProcessed}, noRollback) ok() diff --git a/beacon_chain/consensus_object_pools/consensus_manager.nim b/beacon_chain/consensus_object_pools/consensus_manager.nim index 0480673eb..3502c4398 100644 --- a/beacon_chain/consensus_object_pools/consensus_manager.nim +++ b/beacon_chain/consensus_object_pools/consensus_manager.nim @@ -380,9 +380,9 @@ proc runProposalForkchoiceUpdated*( debug "Fork-choice updated for proposal", status static: doAssert high(ConsensusFork) == ConsensusFork.Electra - when consensusFork >= ConsensusFork.Electra: - debugRaiseAssert "foobar" - elif consensusFork >= ConsensusFork.Deneb: + when consensusFork >= ConsensusFork.Deneb: + # https://github.com/ethereum/execution-apis/blob/90a46e9137c89d58e818e62fa33a0347bba50085/src/engine/prague.md + # does not define any new forkchoiceUpdated, so reuse V3 from Dencun callForkchoiceUpdated(PayloadAttributesV3( timestamp: Quantity timestamp, prevRandao: FixedBytes[32] randomData, diff --git a/beacon_chain/el/el_manager.nim b/beacon_chain/el/el_manager.nim index 28a6d7c87..ed4f93994 100644 --- a/beacon_chain/el/el_manager.nim +++ b/beacon_chain/el/el_manager.nim @@ -794,7 +794,10 @@ proc getPayloadFromSingleEL( prevRandao: FixedBytes[32] randomData.data, suggestedFeeRecipient: suggestedFeeRecipient, withdrawals: withdrawals)) - elif GetPayloadResponseType is engine_api.GetPayloadV3Response: + elif GetPayloadResponseType is engine_api.GetPayloadV3Response or + GetPayloadResponseType is engine_api.GetPayloadV4Response: + # https://github.com/ethereum/execution-apis/blob/90a46e9137c89d58e818e62fa33a0347bba50085/src/engine/prague.md + # does not define any new forkchoiceUpdated, so reuse V3 from Dencun let response = await rpcClient.forkchoiceUpdated( ForkchoiceStateV1( headBlockHash: headBlock.asBlockHash, @@ -806,9 +809,6 @@ proc getPayloadFromSingleEL( suggestedFeeRecipient: suggestedFeeRecipient, withdrawals: withdrawals, parentBeaconBlockRoot: consensusHead.asBlockHash)) - elif GetPayloadResponseType is engine_api.GetPayloadV4Response: - debugRaiseAssert "electra" - let response = default(ForkchoiceUpdatedResponse) else: static: doAssert false diff --git a/beacon_chain/nimbus_signing_node.nim b/beacon_chain/nimbus_signing_node.nim index e5951ae47..5c4beeff2 100644 --- a/beacon_chain/nimbus_signing_node.nim +++ b/beacon_chain/nimbus_signing_node.nim @@ -238,8 +238,7 @@ proc installApiHandlers*(node: SigningNodeRef) = of ConsensusFork.Deneb: (GeneralizedIndex(801), request.beaconBlockHeader.data) of ConsensusFork.Electra: - debugRaiseAssert "electra signing node missing" - (GeneralizedIndex(801*42), request.beaconBlockHeader.data) + (GeneralizedIndex(801), request.beaconBlockHeader.data) if request.proofs.isNone() or len(request.proofs.get()) == 0: return errorResponse(Http400, MissingMerkleProofError) diff --git a/beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim b/beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim index c2161ba6b..de6c84f04 100644 --- a/beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim +++ b/beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim @@ -3525,8 +3525,16 @@ proc decodeBody*( [version, $exc.msg])) ok(RestPublishedSignedBeaconBlock(ForkedSignedBeaconBlock.init(blck))) of ConsensusFork.Electra: - debugRaiseAssert "electra" - return err(RestErrorMessage.init(Http400, UnexpectedDecodeError)) + let blck = + try: + SSZ.decode(body.data, electra.SignedBeaconBlock) + except SerializationError as exc: + return err(RestErrorMessage.init(Http400, UnableDecodeError, + [version, exc.formatMsg("")])) + except CatchableError as exc: + return err(RestErrorMessage.init(Http400, UnexpectedDecodeError, + [version, $exc.msg])) + ok(RestPublishedSignedBeaconBlock(ForkedSignedBeaconBlock.init(blck))) else: err(RestErrorMessage.init(Http415, "Invalid content type", [version, $body.contentType])) diff --git a/beacon_chain/spec/forks.nim b/beacon_chain/spec/forks.nim index 34d83fc2a..10336e761 100644 --- a/beacon_chain/spec/forks.nim +++ b/beacon_chain/spec/forks.nim @@ -412,7 +412,9 @@ template BeaconState*(kind: static ConsensusFork): auto = static: raiseAssert "Unreachable" template BeaconBlock*(kind: static ConsensusFork): auto = - when kind == ConsensusFork.Deneb: + when kind == ConsensusFork.Electra: + typedesc[electra.BeaconBlock] + elif kind == ConsensusFork.Deneb: typedesc[deneb.BeaconBlock] elif kind == ConsensusFork.Capella: typedesc[capella.BeaconBlock] diff --git a/beacon_chain/spec/state_transition.nim b/beacon_chain/spec/state_transition.nim index 27622b574..c5f9feab3 100644 --- a/beacon_chain/spec/state_transition.nim +++ b/beacon_chain/spec/state_transition.nim @@ -295,10 +295,7 @@ proc state_transition_block*( doAssert not rollback.isNil, "use noRollback if it's ok to mess up state" let res = withState(state): - when consensusFork == ConsensusFork.Electra: - debugRaiseAssert "electra state_transition_block" - err("no") - elif consensusFork == type(signedBlock).kind: + when consensusFork == type(signedBlock).kind: state_transition_block_aux(cfg, forkyState, signedBlock, cache, flags) else: err("State/block fork mismatch") @@ -383,6 +380,8 @@ func partialBeaconBlock*( when consensusFork >= ConsensusFork.Deneb: res.body.blob_kzg_commitments = execution_payload.blobsBundle.commitments + debugRaiseAssert "check for new fields or conditions to ensure in electra" + res proc makeBeaconBlockWithRewards*( @@ -486,7 +485,9 @@ proc makeBeaconBlockWithRewards*( of ConsensusFork.Deneb: makeBeaconBlock(deneb) else: raiseAssert "Attempt to use Deneb payload with non-Deneb state" elif payloadFork == ConsensusFork.Electra: - debugRaiseAssert "Electra block production missing" + case state.kind + of ConsensusFork.Electra: makeBeaconBlock(electra) + else: raiseAssert "Attempt to use Electra payload with non-Electra state" else: {.error: "Unsupported fork".} diff --git a/beacon_chain/spec/state_transition_block.nim b/beacon_chain/spec/state_transition_block.nim index dd51aadbb..17982be42 100644 --- a/beacon_chain/spec/state_transition_block.nim +++ b/beacon_chain/spec/state_transition_block.nim @@ -1025,9 +1025,9 @@ proc process_block*( total_active_balance = get_total_active_balance(state, cache) base_reward_per_increment = get_base_reward_per_increment(total_active_balance) - operations_rewards = ? process_operations( - cfg, state, blck.body, base_reward_per_increment, flags, cache) - ? process_sync_aggregate( + var operations_rewards = ? process_operations( + cfg, state, blck.body, base_reward_per_increment, flags, cache) + operations_rewards.sync_aggregate = ? process_sync_aggregate( state, blck.body.sync_aggregate, total_active_balance, flags, cache) ok(operations_rewards)