From 5da2bcd24369c1bc32bb4bfb6dec0e3ad3145e9a Mon Sep 17 00:00:00 2001 From: tersec Date: Thu, 29 Feb 2024 12:37:08 +0000 Subject: [PATCH] rm Capella builder API REST calls (#5997) --- .../eth2_apis/eth2_rest_serialization.nim | 2 -- beacon_chain/spec/eth2_apis/rest_types.nim | 2 -- .../spec/mev/rest_capella_mev_calls.nim | 35 ------------------- .../spec/mev/rest_deneb_mev_calls.nim | 7 ++++ beacon_chain/spec/state_transition.nim | 24 ++----------- beacon_chain/validators/beacon_validators.nim | 23 ++---------- .../validators/message_router_mev.nim | 33 +++++------------ 7 files changed, 21 insertions(+), 105 deletions(-) delete mode 100644 beacon_chain/spec/mev/rest_capella_mev_calls.nim diff --git a/beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim b/beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim index efdcb41ea..f7cc3bdbf 100644 --- a/beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim +++ b/beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim @@ -84,7 +84,6 @@ RestJson.useDefaultSerializationFor( GetForkChoiceResponse, GetForkScheduleResponse, GetGenesisResponse, - GetHeaderResponseCapella, GetHeaderResponseDeneb, GetKeystoresResponse, GetNextWithdrawalsResponse, @@ -168,7 +167,6 @@ RestJson.useDefaultSerializationFor( SignedContributionAndProof, SignedValidatorRegistrationV1, SignedVoluntaryExit, - SubmitBlindedBlockResponseCapella, SubmitBlindedBlockResponseDeneb, SyncAggregate, SyncAggregatorSelectionData, diff --git a/beacon_chain/spec/eth2_apis/rest_types.nim b/beacon_chain/spec/eth2_apis/rest_types.nim index c328eb516..a611271c9 100644 --- a/beacon_chain/spec/eth2_apis/rest_types.nim +++ b/beacon_chain/spec/eth2_apis/rest_types.nim @@ -553,7 +553,6 @@ type GetEpochCommitteesResponse* = DataEnclosedObject[seq[RestBeaconStatesCommittees]] GetForkScheduleResponse* = DataEnclosedObject[seq[Fork]] GetGenesisResponse* = DataEnclosedObject[RestGenesis] - GetHeaderResponseCapella* = DataVersionEnclosedObject[capella_mev.SignedBuilderBid] GetHeaderResponseDeneb* = DataVersionEnclosedObject[deneb_mev.SignedBuilderBid] GetNetworkIdentityResponse* = DataEnclosedObject[RestNetworkIdentity] GetPeerCountResponse* = DataMetaEnclosedObject[RestPeerCount] @@ -580,7 +579,6 @@ type ProduceAttestationDataResponse* = DataEnclosedObject[AttestationData] ProduceBlindedBlockResponse* = ForkedBlindedBeaconBlock ProduceSyncCommitteeContributionResponse* = DataEnclosedObject[SyncCommitteeContribution] - SubmitBlindedBlockResponseCapella* = DataEnclosedObject[capella.ExecutionPayload] SubmitBlindedBlockResponseDeneb* = DataEnclosedObject[deneb_mev.ExecutionPayloadAndBlobsBundle] GetValidatorsActivityResponse* = DataEnclosedObject[seq[RestActivityItem]] GetValidatorsLivenessResponse* = DataEnclosedObject[seq[RestLivenessItem]] diff --git a/beacon_chain/spec/mev/rest_capella_mev_calls.nim b/beacon_chain/spec/mev/rest_capella_mev_calls.nim deleted file mode 100644 index e4e0132b2..000000000 --- a/beacon_chain/spec/mev/rest_capella_mev_calls.nim +++ /dev/null @@ -1,35 +0,0 @@ -# beacon_chain -# Copyright (c) 2023-2024 Status Research & Development GmbH -# Licensed and distributed under either of -# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT). -# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0). -# at your option. This file may not be copied, modified, or distributed except according to those terms. - -{.push raises: [].} - -import - chronos, presto/client, - ".."/eth2_apis/[rest_types, eth2_rest_serialization] - -export chronos, client, rest_types, eth2_rest_serialization - -proc registerValidator*(body: seq[SignedValidatorRegistrationV1] - ): RestPlainResponse {. - rest, endpoint: "/eth/v1/builder/validators", - meth: MethodPost, connection: {Dedicated, Close}.} - ## https://github.com/ethereum/builder-specs/blob/v0.4.0/apis/builder/validators.yaml - ## https://github.com/ethereum/beacon-APIs/blob/v2.3.0/apis/validator/register_validator.yaml - -proc getHeaderCapella*(slot: Slot, - parent_hash: Eth2Digest, - pubkey: ValidatorPubKey - ): RestPlainResponse {. - rest, endpoint: "/eth/v1/builder/header/{slot}/{parent_hash}/{pubkey}", - meth: MethodGet, connection: {Dedicated, Close}.} - ## https://github.com/ethereum/builder-specs/blob/v0.4.0/apis/builder/header.yaml - -proc submitBlindedBlock*(body: capella_mev.SignedBlindedBeaconBlock - ): RestPlainResponse {. - rest, endpoint: "/eth/v1/builder/blinded_blocks", - meth: MethodPost, connection: {Dedicated, Close}.} - ## https://github.com/ethereum/builder-specs/blob/v0.4.0/apis/builder/blinded_blocks.yaml diff --git a/beacon_chain/spec/mev/rest_deneb_mev_calls.nim b/beacon_chain/spec/mev/rest_deneb_mev_calls.nim index 1acb4f62f..36ebcb4a3 100644 --- a/beacon_chain/spec/mev/rest_deneb_mev_calls.nim +++ b/beacon_chain/spec/mev/rest_deneb_mev_calls.nim @@ -13,6 +13,13 @@ import export chronos, client, rest_types, eth2_rest_serialization +proc registerValidator*(body: seq[SignedValidatorRegistrationV1] + ): RestPlainResponse {. + rest, endpoint: "/eth/v1/builder/validators", + meth: MethodPost, connection: {Dedicated, Close}.} + ## https://github.com/ethereum/builder-specs/blob/v0.4.0/apis/builder/validators.yaml + ## https://github.com/ethereum/beacon-APIs/blob/v2.3.0/apis/validator/register_validator.yaml + proc getHeaderDeneb*(slot: Slot, parent_hash: Eth2Digest, pubkey: ValidatorPubKey diff --git a/beacon_chain/spec/state_transition.nim b/beacon_chain/spec/state_transition.nim index 65395ebf0..67a1c0008 100644 --- a/beacon_chain/spec/state_transition.nim +++ b/beacon_chain/spec/state_transition.nim @@ -429,29 +429,9 @@ proc makeBeaconBlock*( # Override for Builder API if transactions_root.isSome and execution_payload_root.isSome: withState(state): - when consensusFork < ConsensusFork.Capella: - # Nimbus doesn't support pre-Capella builder API + when consensusFork < ConsensusFork.Deneb: + # Nimbus doesn't support pre-Deneb builder API discard - elif consensusFork == ConsensusFork.Capella: - forkyState.data.latest_execution_payload_header.transactions_root = - transactions_root.get - - # https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.5/specs/capella/beacon-chain.md#beaconblockbody - # Effectively hash_tree_root(ExecutionPayload) with the beacon block - # body, with the execution payload replaced by the execution payload - # header. htr(payload) == htr(payload header), so substitute. - forkyState.data.latest_block_header.body_root = hash_tree_root( - [hash_tree_root(randao_reveal), - hash_tree_root(eth1_data), - hash_tree_root(graffiti), - hash_tree_root(validator_changes.proposer_slashings), - hash_tree_root(validator_changes.attester_slashings), - hash_tree_root(List[Attestation, Limit MAX_ATTESTATIONS](attestations)), - hash_tree_root(List[Deposit, Limit MAX_DEPOSITS](deposits)), - hash_tree_root(validator_changes.voluntary_exits), - hash_tree_root(sync_aggregate), - execution_payload_root.get, - hash_tree_root(validator_changes.bls_to_execution_changes)]) elif consensusFork == ConsensusFork.Deneb: forkyState.data.latest_execution_payload_header.transactions_root = transactions_root.get diff --git a/beacon_chain/validators/beacon_validators.nim b/beacon_chain/validators/beacon_validators.nim index c21dfa3d3..2912e3ca5 100644 --- a/beacon_chain/validators/beacon_validators.nim +++ b/beacon_chain/validators/beacon_validators.nim @@ -41,7 +41,7 @@ import ".."/[conf, beacon_clock, beacon_node], "."/[ keystore_management, slashing_protection, validator_duties, validator_pool], - ".."/spec/mev/[rest_capella_mev_calls, rest_deneb_mev_calls] + ".."/spec/mev/rest_deneb_mev_calls from std/sequtils import mapIt from eth/async_utils import awaitWithTimeout @@ -542,30 +542,13 @@ proc makeBeaconBlockForHeadAndSlot*( kzg_commitments = Opt.none(KzgCommitments)) proc getBlindedExecutionPayload[ - EPH: capella.ExecutionPayloadHeader | - deneb_mev.BlindedExecutionPayloadAndBlobsBundle]( + EPH: deneb_mev.BlindedExecutionPayloadAndBlobsBundle]( node: BeaconNode, payloadBuilderClient: RestClientRef, slot: Slot, executionBlockHash: Eth2Digest, pubkey: ValidatorPubKey): Future[BlindedBlockResult[EPH]] {.async: (raises: [CancelledError, RestError]).} = # Not ideal to use `when` where instead of splitting into separate functions, # but Nim doesn't overload on generic EPH type parameter. - when EPH is capella.ExecutionPayloadHeader: - let - response = awaitWithTimeout( - payloadBuilderClient.getHeaderCapella( - slot, executionBlockHash, pubkey), - BUILDER_PROPOSAL_DELAY_TOLERANCE): - return err "Timeout obtaining Capella blinded header from builder" - - res = decodeBytes( - GetHeaderResponseCapella, response.data, response.contentType) - - blindedHeader = res.valueOr: - return err( - "Unable to decode Capella blinded header: " & $res.error & - " with HTTP status " & $response.status & ", Content-Type " & - $response.contentType & " and content " & $response.data) - elif EPH is deneb_mev.BlindedExecutionPayloadAndBlobsBundle: + when EPH is deneb_mev.BlindedExecutionPayloadAndBlobsBundle: let response = awaitWithTimeout( payloadBuilderClient.getHeaderDeneb( diff --git a/beacon_chain/validators/message_router_mev.nim b/beacon_chain/validators/message_router_mev.nim index e93a0d935..2957bf01d 100644 --- a/beacon_chain/validators/message_router_mev.nim +++ b/beacon_chain/validators/message_router_mev.nim @@ -14,7 +14,6 @@ import ../beacon_node from eth/async_utils import awaitWithTimeout from ../spec/datatypes/bellatrix import SignedBeaconBlock -from ../spec/mev/rest_capella_mev_calls import submitBlindedBlock from ../spec/mev/rest_deneb_mev_calls import submitBlindedBlock const @@ -44,9 +43,7 @@ macro copyFields*( proc unblindAndRouteBlockMEV*( node: BeaconNode, payloadBuilderRestClient: RestClientRef, - blindedBlock: - capella_mev.SignedBlindedBeaconBlock | - deneb_mev.SignedBlindedBeaconBlock): + blindedBlock: deneb_mev.SignedBlindedBeaconBlock): Future[Result[Opt[BlockRef], string]] {.async: (raises: [CancelledError]).} = const consensusFork = typeof(blindedBlock).kind @@ -79,28 +76,16 @@ proc unblindAndRouteBlockMEV*( return err("submitBlindedBlock failed with HTTP error code " & $response.status & ": " & $shortLog(blindedBlock)) - when consensusFork >= ConsensusFork.Deneb: - let - res = decodeBytes( - SubmitBlindedBlockResponseDeneb, response.data, response.contentType) + let + res = decodeBytes( + SubmitBlindedBlockResponseDeneb, response.data, response.contentType) - bundle = res.valueOr: - return err("Could not decode Deneb blinded block: " & $res.error & - " with HTTP status " & $response.status & ", Content-Type " & - $response.contentType & " and content " & $response.data) + bundle = res.valueOr: + return err("Could not decode " & $consensusFork & " blinded block: " & $res.error & + " with HTTP status " & $response.status & ", Content-Type " & + $response.contentType & " and content " & $response.data) - template execution_payload: untyped = bundle.data.execution_payload - else: - let - res = decodeBytes( - SubmitBlindedBlockResponseCapella, response.data, response.contentType) - - bundle = res.valueOr: - return err("Could not decode Capella blinded block: " & $res.error & - " with HTTP status " & $response.status & ", Content-Type " & - $response.contentType & " and content " & $response.data) - - template execution_payload: untyped = bundle.data + template execution_payload: untyped = bundle.data.execution_payload if hash_tree_root(blindedBlock.message.body.execution_payload_header) != hash_tree_root(execution_payload):