From 1c62a5eb24b09cc339a70d104dfc2ff587cad217 Mon Sep 17 00:00:00 2001 From: tersec Date: Fri, 3 Feb 2023 16:12:11 +0100 Subject: [PATCH] capella VC support (#4586) --- beacon_chain/rpc/rest_beacon_api.nim | 1 + .../eth2_apis/eth2_rest_serialization.nim | 63 ++++++++++++++++--- beacon_chain/spec/eth2_apis/rest_types.nim | 21 ++++++- config.nims | 3 +- scripts/launch_local_testnet.sh | 1 + 5 files changed, 79 insertions(+), 10 deletions(-) diff --git a/beacon_chain/rpc/rest_beacon_api.nim b/beacon_chain/rpc/rest_beacon_api.nim index c84a09699..e3709ce38 100644 --- a/beacon_chain/rpc/rest_beacon_api.nim +++ b/beacon_chain/rpc/rest_beacon_api.nim @@ -798,6 +798,7 @@ proc installBeaconApiHandlers*(router: var RestRouter, node: BeaconNode) = if forked.kind != node.dag.cfg.blockForkAtEpoch( getForkedBlockField(forked, slot).epoch): + doAssert strictVerification notin node.dag.updateFlags return RestApiResponse.jsonError(Http400, InvalidBlockObjectError) withBlck(forked): diff --git a/beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim b/beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim index 54fed4b47..a4bc3dbb9 100644 --- a/beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim +++ b/beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim @@ -925,7 +925,9 @@ template prepareForkedBlockReading( of "bellatrix": version = some(ConsensusFork.Bellatrix) of "capella": - version = some(ConsensusFork.Bellatrix) + version = some(ConsensusFork.Capella) + of "eip4844": + version = some(ConsensusFork.EIP4844) else: reader.raiseUnexpectedValue("Incorrect version field value") of "block", "block_header", "data": @@ -1200,7 +1202,8 @@ proc readValue*(reader: var JsonReader[RestJson], voluntary_exits: Option[ List[SignedVoluntaryExit, Limit MAX_VOLUNTARY_EXITS]] sync_aggregate: Option[SyncAggregate] - execution_payload: Option[bellatrix.ExecutionPayload] + execution_payload: Option[RestExecutionPayload] + bls_to_execution_changes: Option[SignedBLSToExecutionChangeList] for fieldName in readObjectFields(reader): case fieldName @@ -1259,7 +1262,12 @@ proc readValue*(reader: var JsonReader[RestJson], if execution_payload.isSome(): reader.raiseUnexpectedField("Multiple `execution_payload` fields found", "RestPublishedBeaconBlockBody") - execution_payload = some(reader.readValue(bellatrix.ExecutionPayload)) + execution_payload = some(reader.readValue(RestExecutionPayload)) + of "bls_to_execution_changes": + if bls_to_execution_changes.isSome(): + reader.raiseUnexpectedField("Multiple `bls_to_execution_changes` fields found", + "RestPublishedBeaconBlockBody") + bls_to_execution_changes = some(reader.readValue(SignedBLSToExecutionChangeList)) else: unrecognizedFieldWarning() @@ -1280,15 +1288,36 @@ proc readValue*(reader: var JsonReader[RestJson], if voluntary_exits.isNone(): reader.raiseUnexpectedValue("Field `voluntary_exits` is missing") - discard $capellaImplementationMissing & ": autodetect via added field" let bodyKind = - if execution_payload.isSome() and sync_aggregate.isSome(): + if execution_payload.isSome() and + execution_payload.get().withdrawals.isSome() and + bls_to_execution_changes.isSome() and + sync_aggregate.isSome(): + ConsensusFork.Capella + elif execution_payload.isSome() and sync_aggregate.isSome(): ConsensusFork.Bellatrix elif execution_payload.isNone() and sync_aggregate.isSome(): ConsensusFork.Altair else: ConsensusFork.Phase0 + template ep_src: auto = execution_payload.get() + template copy_ep_bellatrix(ep_dst: auto) = + assign(ep_dst.parent_hash, ep_src.parent_hash) + assign(ep_dst.fee_recipient, ep_src.fee_recipient) + assign(ep_dst.state_root, ep_src.state_root) + assign(ep_dst.receipts_root, ep_src.receipts_root) + assign(ep_dst.logs_bloom, ep_src.logs_bloom) + assign(ep_dst.prev_randao, ep_src.prev_randao) + assign(ep_dst.block_number, ep_src.block_number) + 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.block_hash, ep_src.block_hash) + assign(ep_dst.transactions, ep_src.transactions) + case bodyKind of ConsensusFork.Phase0: value = RestPublishedBeaconBlockBody( @@ -1332,11 +1361,29 @@ proc readValue*(reader: var JsonReader[RestJson], deposits: deposits.get(), voluntary_exits: voluntary_exits.get(), sync_aggregate: sync_aggregate.get(), - execution_payload: execution_payload.get() ) ) + copy_ep_bellatrix(value.bellatrixBody.execution_payload) of ConsensusFork.Capella: - reader.raiseUnexpectedValue($capellaImplementationMissing) + value = RestPublishedBeaconBlockBody( + kind: ConsensusFork.Capella, + capellaBody: capella.BeaconBlockBody( + randao_reveal: randao_reveal.get(), + eth1_data: eth1_data.get(), + graffiti: graffiti.get(), + proposer_slashings: proposer_slashings.get(), + attester_slashings: attester_slashings.get(), + attestations: attestations.get(), + deposits: deposits.get(), + voluntary_exits: voluntary_exits.get(), + sync_aggregate: sync_aggregate.get(), + bls_to_execution_changes: bls_to_execution_changes.get() + ) + ) + copy_ep_bellatrix(value.capellaBody.execution_payload) + assign( + value.capellaBody.execution_payload.withdrawals, + ep_src.withdrawals.get()) of ConsensusFork.EIP4844: reader.raiseUnexpectedValue($eip4844ImplementationMissing) @@ -1524,6 +1571,8 @@ proc readValue*(reader: var JsonReader[RestJson], version = some(ConsensusFork.Bellatrix) of "capella": version = some(ConsensusFork.Capella) + of "eip4844": + version = some(ConsensusFork.EIP4844) else: reader.raiseUnexpectedValue("Incorrect version field value") of "data": diff --git a/beacon_chain/spec/eth2_apis/rest_types.nim b/beacon_chain/spec/eth2_apis/rest_types.nim index 038e4c84d..042db48cf 100644 --- a/beacon_chain/spec/eth2_apis/rest_types.nim +++ b/beacon_chain/spec/eth2_apis/rest_types.nim @@ -277,6 +277,26 @@ type index*: ValidatorIndex is_live*: bool + # https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.2/specs/capella/beacon-chain.md#executionpayload + RestExecutionPayload* = object + parent_hash*: Eth2Digest + fee_recipient*: ExecutionAddress # 'beneficiary' in the yellow paper + state_root*: Eth2Digest + receipts_root*: Eth2Digest # 'receipts root' in the yellow paper + logs_bloom*: BloomLogs + prev_randao*: Eth2Digest # 'difficulty' in the yellow paper + block_number*: uint64 # 'number' in the yellow paper + gas_limit*: uint64 + gas_used*: uint64 + timestamp*: uint64 + extra_data*: List[byte, MAX_EXTRA_DATA_BYTES] + base_fee_per_gas*: UInt256 + + # Extra payload fields + block_hash*: Eth2Digest # Hash of execution block + transactions*: List[Transaction, MAX_TRANSACTIONS_PER_PAYLOAD] + withdrawals*: Option[List[Withdrawal, MAX_WITHDRAWALS_PER_PAYLOAD]] # [New in Capella] + PrepareBeaconProposer* = object validator_index*: ValidatorIndex fee_recipient*: Eth1Address @@ -636,7 +656,6 @@ type GetVersionResponse* = DataEnclosedObject[RestNodeVersion] GetEpochSyncCommitteesResponse* = DataEnclosedObject[RestEpochSyncCommittee] ProduceAttestationDataResponse* = DataEnclosedObject[AttestationData] - ProduceBlockResponse* = DataEnclosedObject[phase0.BeaconBlock] ProduceBlockResponseV2* = ForkedBeaconBlock ProduceBlindedBlockResponse* = ForkedBlindedBeaconBlock ProduceSyncCommitteeContributionResponse* = DataEnclosedObject[SyncCommitteeContribution] diff --git a/config.nims b/config.nims index 3ceb27ad8..de36c2f11 100644 --- a/config.nims +++ b/config.nims @@ -183,8 +183,7 @@ switch("warning", "ObservableStores:off") switch("warning", "LockLevel:off") # Too many of these because of Defect compat in 1.2 -if (NimMajor, NimMinor) >= (1, 6): - switch("hint", "XCannotRaiseY:off") +switch("hint", "XCannotRaiseY:off") # Useful for Chronos metrics. #--define:chronosFutureTracking diff --git a/scripts/launch_local_testnet.sh b/scripts/launch_local_testnet.sh index e0e0e70d3..24f1a7bf4 100755 --- a/scripts/launch_local_testnet.sh +++ b/scripts/launch_local_testnet.sh @@ -785,6 +785,7 @@ DEPOSIT_CONTRACT_ADDRESS: ${DEPOSIT_CONTRACT_ADDRESS} ETH1_FOLLOW_DISTANCE: 1 ALTAIR_FORK_EPOCH: 1 BELLATRIX_FORK_EPOCH: 2 +CAPELLA_FORK_EPOCH: 3 TERMINAL_TOTAL_DIFFICULTY: 0 EOF