From eb17493295666a9ef54c336ffe7b19846710d69b Mon Sep 17 00:00:00 2001 From: tersec Date: Mon, 17 Jun 2024 11:28:06 +0000 Subject: [PATCH] update Pectra execution API types (#155) --- tests/test_execution_types.nim | 10 +++---- web3/conversions.nim | 2 +- web3/engine_api_types.nim | 51 ++++++++++++++++++---------------- web3/execution_types.nim | 8 +++--- 4 files changed, 37 insertions(+), 34 deletions(-) diff --git a/tests/test_execution_types.nim b/tests/test_execution_types.nim index 4ebbb7d..070cff3 100644 --- a/tests/test_execution_types.nim +++ b/tests/test_execution_types.nim @@ -64,7 +64,7 @@ suite "Execution types tests": shouldOverrideBuilder: Opt.some(false), ) - deposit = DepositReceiptV1( + deposit = DepositRequestV1( pubkey: FixedBytes[48].conv(1), withdrawalCredentials: FixedBytes[32].conv(3), amount: 5.Quantity, @@ -167,12 +167,12 @@ suite "Execution types tests": test "payload version 4": var v4 = payload - v4.depositReceipts = Opt.some(@[deposit]) + v4.depositRequests = Opt.some(@[deposit]) v4.exits = Opt.some(@[exit]) check v4.version == Version.V4 var bad41 = v4 - bad41.depositReceipts = Opt.none(seq[DepositReceiptV1]) + bad41.depositRequests = Opt.none(seq[DepositRequestV1]) check bad41.version == Version.V4 var bad42 = v4 @@ -180,11 +180,11 @@ suite "Execution types tests": check bad42.version == Version.V4 let v41 = bad41.V4 - check v41.depositRequests == newSeq[DepositReceiptV1]() + check v41.depositRequests == newSeq[DepositRequestV1]() check v41.withdrawalRequests == v4.exits.get let v42 = bad42.V4 - check v42.depositRequests == v4.depositReceipts.get + check v42.depositRequests == v4.depositRequests.get check v42.withdrawalRequests == newSeq[WithdrawalRequestV1]() # roundtrip diff --git a/web3/conversions.nim b/web3/conversions.nim index fea282c..be3e607 100644 --- a/web3/conversions.nim +++ b/web3/conversions.nim @@ -53,7 +53,7 @@ derefType(ReceiptObject).useDefaultSerializationIn JrpcConv #------------------------------------------------------------------------------ WithdrawalV1.useDefaultSerializationIn JrpcConv -DepositReceiptV1.useDefaultSerializationIn JrpcConv +DepositRequestV1.useDefaultSerializationIn JrpcConv WithdrawalRequestV1.useDefaultSerializationIn JrpcConv ExecutionPayloadV1.useDefaultSerializationIn JrpcConv ExecutionPayloadV2.useDefaultSerializationIn JrpcConv diff --git a/web3/engine_api_types.nim b/web3/engine_api_types.nim index 93a78fc..bb1ea7a 100644 --- a/web3/engine_api_types.nim +++ b/web3/engine_api_types.nim @@ -7,6 +7,8 @@ # This file may not be copied, modified, or distributed except according to # those terms. +{.push raises: [].} + import std/typetraits, stint, @@ -19,7 +21,7 @@ export type TypedTransaction* = distinct seq[byte] - # https://github.com/ethereum/execution-apis/blob/v1.0.0-beta.3/src/engine/shanghai.md#withdrawalv1 + # https://github.com/ethereum/execution-apis/blob/v1.0.0-beta.4/src/engine/shanghai.md#withdrawalv1 WithdrawalV1* = object index*: Quantity validatorIndex*: Quantity @@ -27,7 +29,7 @@ type amount*: Quantity # https://github.com/ethereum/execution-apis/blob/v1.0.0-beta.4/src/engine/prague.md#depositrequestv1 - DepositReceiptV1* = object + DepositRequestV1* = object pubkey*: FixedBytes[48] withdrawalCredentials*: FixedBytes[32] amount*: Quantity @@ -40,7 +42,13 @@ type validatorPublicKey*: FixedBytes[48] amount*: Quantity - # https://github.com/ethereum/execution-apis/blob/v1.0.0-beta.3/src/engine/paris.md#executionpayloadv1 + # https://github.com/ethereum/execution-apis/blob/3ae3d29fc9900e5c48924c238dff7643fdc3680e/src/engine/prague.md#consolidationrequestv1 + ConsolidationRequestV1* = object + sourceAddress*: Address + sourcePubkey*: FixedBytes[48] + targetPubkey*: FixedBytes[48] + + # https://github.com/ethereum/execution-apis/blob/v1.0.0-beta.4/src/engine/paris.md#executionpayloadv1 ExecutionPayloadV1* = object parentHash*: Hash256 feeRecipient*: Address @@ -57,7 +65,7 @@ type blockHash*: Hash256 transactions*: seq[TypedTransaction] - # https://github.com/ethereum/execution-apis/blob/v1.0.0-beta.3/src/engine/shanghai.md#executionpayloadv2 + # https://github.com/ethereum/execution-apis/blob/v1.0.0-beta.4/src/engine/shanghai.md#executionpayloadv2 ExecutionPayloadV2* = object parentHash*: Hash256 feeRecipient*: Address @@ -87,7 +95,7 @@ type # please fix this. (Maybe the RPC library does handle sum types? # Or maybe we can enhance it to do so?) --Adam # - # https://github.com/ethereum/execution-apis/blob/v1.0.0-beta.3/src/engine/shanghai.md + # https://github.com/ethereum/execution-apis/blob/v1.0.0-beta.4/src/engine/shanghai.md ExecutionPayloadV1OrV2* = object parentHash*: BlockHash feeRecipient*: Address @@ -105,7 +113,7 @@ type transactions*: seq[TypedTransaction] withdrawals*: Opt[seq[WithdrawalV1]] - # https://github.com/ethereum/execution-apis/blob/fe8e13c288c592ec154ce25c534e26cb7ce0530d/src/engine/cancun.md#executionpayloadv3 + # https://github.com/ethereum/execution-apis/blob/v1.0.0-beta.4/src/engine/cancun.md#executionpayloadv3 ExecutionPayloadV3* = object parentHash*: Hash256 feeRecipient*: Address @@ -125,7 +133,7 @@ type blobGasUsed*: Quantity excessBlobGas*: Quantity - # https://github.com/ethereum/execution-apis/blob/v1.0.0-beta.4/src/engine/prague.md#executionpayloadv4 + # https://github.com/ethereum/execution-apis/blob/3ae3d29fc9900e5c48924c238dff7643fdc3680e/src/engine/prague.md#executionpayloadv4 ExecutionPayloadV4* = object parentHash*: Hash256 feeRecipient*: Address @@ -144,13 +152,9 @@ type withdrawals*: seq[WithdrawalV1] blobGasUsed*: Quantity excessBlobGas*: Quantity - - # https://github.com/ethereum/consensus-specs/pull/3757 - # https://github.com/ethereum/execution-apis/pull/544 - # mainly for devnet-0 - depositRequests*: seq[DepositReceiptV1] - + depositRequests*: seq[DepositRequestV1] withdrawalRequests*: seq[WithdrawalRequestV1] + consolidationRequests*: seq[ConsolidationRequestV1] SomeExecutionPayload* = ExecutionPayloadV1 | @@ -158,34 +162,35 @@ type ExecutionPayloadV3 | ExecutionPayloadV4 - # https://github.com/ethereum/execution-apis/blob/ee3df5bc38f28ef35385cefc9d9ca18d5e502778/src/engine/cancun.md#blobsbundlev1 + # https://github.com/ethereum/execution-apis/blob/v1.0.0-beta.4/src/engine/cancun.md#blobsbundlev1 BlobsBundleV1* = object commitments*: seq[KZGCommitment] proofs*: seq[KZGProof] blobs*: seq[Blob] - # https://github.com/ethereum/execution-apis/blob/d03c193dc317538e2a1a098030c21bacc2fd1333/src/engine/shanghai.md#executionpayloadbodyv1 + # https://github.com/ethereum/execution-apis/blob/v1.0.0-beta.4/src/engine/shanghai.md#executionpayloadbodyv1 # For optional withdrawals field, see: - # https://github.com/ethereum/execution-apis/blob/main/src/engine/shanghai.md#engine_getpayloadbodiesbyhashv1 - # https://github.com/ethereum/execution-apis/blob/main/src/engine/shanghai.md#engine_getpayloadbodiesbyrangev1 + # https://github.com/ethereum/execution-apis/blob/v1.0.0-beta.4/src/engine/shanghai.md#engine_getpayloadbodiesbyhashv1 + # https://github.com/ethereum/execution-apis/blob/v1.0.0-beta.4/src/engine/shanghai.md#engine_getpayloadbodiesbyrangev1 + # "Client software MUST set withdrawals field to null for bodies of pre-Shanghai blocks." ExecutionPayloadBodyV1* = object transactions*: seq[TypedTransaction] withdrawals*: Opt[seq[WithdrawalV1]] - # https://github.com/ethereum/execution-apis/blob/v1.0.0-beta.3/src/engine/paris.md#payloadattributesv1 + # https://github.com/ethereum/execution-apis/blob/v1.0.0-beta.4/src/engine/paris.md#payloadattributesv1 PayloadAttributesV1* = object timestamp*: Quantity prevRandao*: FixedBytes[32] suggestedFeeRecipient*: Address - # https://github.com/ethereum/execution-apis/blob/v1.0.0-beta.3/src/engine/shanghai.md#payloadattributesv2 + # https://github.com/ethereum/execution-apis/blob/v1.0.0-beta.4/src/engine/shanghai.md#payloadattributesv2 PayloadAttributesV2* = object timestamp*: Quantity prevRandao*: FixedBytes[32] suggestedFeeRecipient*: Address withdrawals*: seq[WithdrawalV1] - # https://github.com/ethereum/execution-apis/blob/ee3df5bc38f28ef35385cefc9d9ca18d5e502778/src/engine/cancun.md#payloadattributesv3 + # https://github.com/ethereum/execution-apis/blob/v1.0.0-beta.4/src/engine/cancun.md#payloadattributesv3 PayloadAttributesV3* = object timestamp*: Quantity prevRandao*: FixedBytes[32] @@ -205,7 +210,7 @@ type PayloadAttributesV2 | PayloadAttributesV3 - # https://github.com/ethereum/execution-apis/blob/v1.0.0-beta.3/src/engine/paris.md#payloadstatusv1 + # https://github.com/ethereum/execution-apis/blob/v1.0.0-beta.4/src/engine/paris.md#payloadstatusv1 PayloadExecutionStatus* {.pure.} = enum syncing = "SYNCING" valid = "VALID" @@ -218,7 +223,7 @@ type latestValidHash*: Opt[BlockHash] validationError*: Opt[string] - # https://github.com/ethereum/execution-apis/blob/v1.0.0-beta.3/src/engine/paris.md#forkchoicestatev1 + # https://github.com/ethereum/execution-apis/blob/v1.0.0-beta.4/src/engine/paris.md#forkchoicestatev1 ForkchoiceStateV1* = object headBlockHash*: BlockHash safeBlockHash*: BlockHash @@ -287,7 +292,5 @@ const engineApiTooLargeRequest* = -38004 engineApiUnsupportedFork* = -38005 -{.push raises: [].} - template `==`*(a, b: TypedTransaction): bool = distinctBase(a) == distinctBase(b) \ No newline at end of file diff --git a/web3/execution_types.nim b/web3/execution_types.nim index dab800a..e254bd7 100644 --- a/web3/execution_types.nim +++ b/web3/execution_types.nim @@ -34,7 +34,7 @@ type withdrawals*: Opt[seq[WithdrawalV1]] blobGasUsed*: Opt[Quantity] excessBlobGas*: Opt[Quantity] - depositReceipts*: Opt[seq[DepositReceiptV1]] + depositRequests*: Opt[seq[DepositRequestV1]] exits*: Opt[seq[WithdrawalRequestV1]] PayloadAttributes* = object @@ -64,7 +64,7 @@ type {.push raises: [].} func version*(payload: ExecutionPayload): Version = - if payload.depositReceipts.isSome or payload.exits.isSome: + if payload.depositRequests.isSome or payload.exits.isSome: Version.V4 elif payload.blobGasUsed.isSome or payload.excessBlobGas.isSome: Version.V3 @@ -272,7 +272,7 @@ func V4*(p: ExecutionPayload): ExecutionPayloadV4 = withdrawals: p.withdrawals.get, blobGasUsed: p.blobGasUsed.get(0.Quantity), excessBlobGas: p.excessBlobGas.get(0.Quantity), - depositRequests: p.depositReceipts.get(newSeq[DepositReceiptV1]()), + depositRequests: p.depositRequests.get(newSeq[DepositRequestV1]()), withdrawalRequests: p.exits.get(newSeq[WithdrawalRequestV1]()) ) @@ -390,7 +390,7 @@ func executionPayload*(p: ExecutionPayloadV4): ExecutionPayload = withdrawals: Opt.some(p.withdrawals), blobGasUsed: Opt.some(p.blobGasUsed), excessBlobGas: Opt.some(p.excessBlobGas), - depositReceipts: Opt.some(p.depositRequests), + depositRequests: Opt.some(p.depositRequests), exits: Opt.some(p.withdrawalRequests) )