From 0c59f31fd1219c974d57d8f1c04a8be55f8c741f Mon Sep 17 00:00:00 2001 From: Etan Kissling Date: Fri, 24 May 2024 00:32:22 +0200 Subject: [PATCH] latest EIP-6493 changes: switch to vector based fees Consolidate fees in vectors. --- beacon_chain/el/el_manager.nim | 84 +++++++++++++------ beacon_chain/spec/datatypes/electra.nim | 11 ++- .../eth2_apis/eth2_rest_serialization.nim | 1 + vendor/nim-web3 | 2 +- 4 files changed, 68 insertions(+), 30 deletions(-) diff --git a/beacon_chain/el/el_manager.nim b/beacon_chain/el/el_manager.nim index 7144fc17f..f5c68e1b4 100644 --- a/beacon_chain/el/el_manager.nim +++ b/beacon_chain/el/el_manager.nim @@ -518,11 +518,21 @@ func asConsensusType*(rpcExecutionPayload: ExecutionPayloadV4): Opt.some(tt.payload.nonce.get.uint64) else: Opt.none(uint64), - max_fee_per_gas: - if tt.payload.maxFeePerGas.isSome: - Opt.some(tt.payload.maxFeePerGas.get) + max_fees_per_gas: + if tt.payload.maxFeesPerGas.isSome: + Opt.some(Eip6493FeesPerGas( + regular: + if tt.payload.maxFeesPerGas.get.regular.isSome: + Opt.some(tt.payload.maxFeesPerGas.get.regular.get) + else: + Opt.none(Uint256), + blob: + if tt.payload.maxFeesPerGas.get.blob.isSome: + Opt.some(tt.payload.maxFeesPerGas.get.blob.get) + else: + Opt.none(Uint256))) else: - Opt.none(UInt256), + Opt.none(Eip6493FeesPerGas), gas: if tt.payload.gas.isSome: Opt.some(tt.payload.gas.get.uint64) @@ -556,16 +566,21 @@ func asConsensusType*(rpcExecutionPayload: ExecutionPayloadV4): Eth2Digest(data: distinctBase(it)))))))) else: Opt.none(List[Eip6493AccessTuple, Limit MAX_ACCESS_LIST_SIZE]), - max_priority_fee_per_gas: - if tt.payload.maxPriorityFeePerGas.isSome: - Opt.some(tt.payload.maxPriorityFeePerGas.get) + max_priority_fees_per_gas: + if tt.payload.maxPriorityFeesPerGas.isSome: + Opt.some(Eip6493FeesPerGas( + regular: + if tt.payload.maxPriorityFeesPerGas.get.regular.isSome: + Opt.some(tt.payload.maxPriorityFeesPerGas.get.regular.get) + else: + Opt.none(Uint256), + blob: + if tt.payload.maxPriorityFeesPerGas.get.blob.isSome: + Opt.some(tt.payload.maxPriorityFeesPerGas.get.blob.get) + else: + Opt.none(Uint256))) else: - Opt.none(UInt256), - max_fee_per_blob_gas: - if tt.payload.maxFeePerBlobGas.isSome: - Opt.some(tt.payload.maxFeePerBlobGas.get) - else: - Opt.none(UInt256), + Opt.none(Eip6493FeesPerGas), blob_versioned_hashes: if tt.payload.blobVersionedHashes.isSome: Opt.some( @@ -749,11 +764,21 @@ func asEngineExecutionPayload*(executionPayload: electra.ExecutionPayload): options.some(tt.payload.nonce.get.Quantity) else: options.none(Quantity), - maxFeePerGas: - if tt.payload.max_fee_per_gas.isSome: - options.some(tt.payload.max_fee_per_gas.get) + maxFeesPerGas: + if tt.payload.max_fees_per_gas.isSome: + options.some(engine_api_types.TransactionFeesPerGas( + regular: + if tt.payload.max_fees_per_gas.get.regular.isSome: + options.some(tt.payload.max_fees_per_gas.get.regular.get) + else: + options.none(UInt256), + blob: + if tt.payload.max_fees_per_gas.get.blob.isSome: + options.some(tt.payload.max_fees_per_gas.get.blob.get) + else: + options.none(UInt256))) else: - options.none(UInt256), + options.none(engine_api_types.TransactionFeesPerGas), gas: if tt.payload.gas.isSome: options.some(tt.payload.gas.get.Quantity) @@ -783,16 +808,23 @@ func asEngineExecutionPayload*(executionPayload: electra.ExecutionPayload): .mapIt(FixedBytes[32](it.data))))) else: options.none(seq[AccessTuple]), - maxPriorityFeePerGas: - if tt.payload.max_priority_fee_per_gas.isSome: - options.some(tt.payload.max_priority_fee_per_gas.get) + maxPriorityFeesPerGas: + if tt.payload.max_priority_fees_per_gas.isSome: + options.some(engine_api_types.TransactionFeesPerGas( + regular: + if tt.payload.max_priority_fees_per_gas.get.regular.isSome: + options.some( + tt.payload.max_priority_fees_per_gas.get.regular.get) + else: + options.none(UInt256), + blob: + if tt.payload.max_priority_fees_per_gas.get.blob.isSome: + options.some( + tt.payload.max_priority_fees_per_gas.get.blob.get) + else: + options.none(UInt256))) else: - options.none(UInt256), - maxFeePerBlobGas: - if tt.payload.max_fee_per_blob_gas.isSome: - options.some(tt.payload.max_fee_per_blob_gas.get) - else: - options.none(UInt256), + options.none(engine_api_types.TransactionFeesPerGas), blobVersionedHashes: if tt.payload.blob_versioned_hashes.isSome: options.some(distinctBase(tt.payload.blob_versioned_hashes.get) diff --git a/beacon_chain/spec/datatypes/electra.nim b/beacon_chain/spec/datatypes/electra.nim index 1d1a86a5b..e66171960 100644 --- a/beacon_chain/spec/datatypes/electra.nim +++ b/beacon_chain/spec/datatypes/electra.nim @@ -56,6 +56,12 @@ const type ChainId* = uint64 + Eip6493FeesPerGas* {.sszStableContainer: 16.} = object + regular*: Opt[UInt256] + + # EIP-4844 + blob*: Opt[UInt256] + Eip6493AccessTuple* = object address*: ExecutionAddress storage_keys*: List[Eth2Digest, Limit MAX_ACCESS_LIST_STORAGE_KEYS] @@ -68,7 +74,7 @@ type chain_id*: Opt[ChainId] nonce*: Opt[uint64] - max_fee_per_gas*: Opt[UInt256] + max_fees_per_gas*: Opt[Eip6493FeesPerGas] gas*: Opt[uint64] to*: Opt[ExecutionAddress] value*: Opt[UInt256] @@ -78,10 +84,9 @@ type access_list*: Opt[List[Eip6493AccessTuple, Limit MAX_ACCESS_LIST_SIZE]] # EIP-1559 - max_priority_fee_per_gas*: Opt[UInt256] + max_priority_fees_per_gas*: Opt[Eip6493FeesPerGas] # EIP-4844 - max_fee_per_blob_gas*: Opt[UInt256] blob_versioned_hashes*: Opt[List[deneb.VersionedHash, Limit MAX_BLOB_COMMITMENTS_PER_BLOCK]] diff --git a/beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim b/beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim index c298d6982..890fcdd18 100644 --- a/beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim +++ b/beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim @@ -69,6 +69,7 @@ RestJson.useDefaultSerializationFor( DepositTreeSnapshot, DistributedKeystoreInfo, Eip6493AccessTuple, + Eip6493FeesPerGas, Eip6493Transaction, Eip6493TransactionPayload, Eip6493TransactionSignature, diff --git a/vendor/nim-web3 b/vendor/nim-web3 index bf5e6aa63..2e4c259d1 160000 --- a/vendor/nim-web3 +++ b/vendor/nim-web3 @@ -1 +1 @@ -Subproject commit bf5e6aa63357bd6a099d0e2b0b5dc5c8865984d9 +Subproject commit 2e4c259d1bc6debc80ceff611e1ff6071af89ea9