Merge branch 'dev/etan/tx-pooled' into feat/eip-6493

This commit is contained in:
Etan Kissling 2024-05-06 23:27:52 +02:00
commit 34adff98a6
No known key found for this signature in database
GPG Key ID: B21DA824C5A3D03D
3 changed files with 112 additions and 106 deletions

View File

@ -1,4 +1,4 @@
# Copyright (c) 2022-2023 Status Research & Development GmbH
# Copyright (c) 2022-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).

View File

@ -287,6 +287,7 @@ proc read*(rlp: var Rlp, T: type Transaction): T =
rlp.readTxTyped(result)
proc read(rlp: var Rlp, T: type NetworkPayload): T =
result = NetworkPayload()
rlp.read(result.blobs)
rlp.read(result.commitments)
rlp.read(result.proofs)
@ -301,7 +302,7 @@ proc readTxTyped(rlp: var Rlp, tx: var PooledTransaction) =
false
if hasNetworkPayload:
rlp.tryEnterList() # spec: rlp([tx_payload, blobs, commitments, proofs])
rlp.read(tx.tx)
rlp.readTxPayload(tx.tx, txType)
if hasNetworkPayload:
rlp.read(tx.networkPayload)

View File

@ -1,5 +1,5 @@
# Nimbus
# Copyright (c) 2023 Status Research & Development GmbH
# Copyright (c) 2023-2024 Status Research & Development GmbH
# Licensed under either of
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
# http://www.apache.org/licenses/LICENSE-2.0)
@ -26,124 +26,129 @@ const
blob = default(NetworkBlob)
abcdef = hexToSeqByte("abcdef")
proc tx0(i: int): Transaction =
Transaction(
txType: TxLegacy,
nonce: i.AccountNonce,
to: recipient.some,
gasLimit: 1.GasInt,
gasPrice: 2.GasInt,
payload: abcdef)
proc tx0(i: int): PooledTransaction =
PooledTransaction(
tx: Transaction(
txType: TxLegacy,
nonce: i.AccountNonce,
to: recipient.some,
gasLimit: 1.GasInt,
gasPrice: 2.GasInt,
payload: abcdef))
proc tx1(i: int): Transaction =
Transaction(
# Legacy tx contract creation.
txType: TxLegacy,
nonce: i.AccountNonce,
gasLimit: 1.GasInt,
gasPrice: 2.GasInt,
payload: abcdef)
proc tx1(i: int): PooledTransaction =
PooledTransaction(
tx: Transaction(
# Legacy tx contract creation.
txType: TxLegacy,
nonce: i.AccountNonce,
gasLimit: 1.GasInt,
gasPrice: 2.GasInt,
payload: abcdef))
proc tx2(i: int): Transaction =
Transaction(
# Tx with non-zero access list.
txType: TxEip2930,
chainId: 1.ChainId,
nonce: i.AccountNonce,
to: recipient.some,
gasLimit: 123457.GasInt,
gasPrice: 10.GasInt,
accessList: accesses,
payload: abcdef)
proc tx2(i: int): PooledTransaction =
PooledTransaction(
tx: Transaction(
# Tx with non-zero access list.
txType: TxEip2930,
chainId: 1.ChainId,
nonce: i.AccountNonce,
to: recipient.some,
gasLimit: 123457.GasInt,
gasPrice: 10.GasInt,
accessList: accesses,
payload: abcdef))
proc tx3(i: int): Transaction =
Transaction(
# Tx with empty access list.
txType: TxEip2930,
chainId: 1.ChainId,
nonce: i.AccountNonce,
to: recipient.some,
gasLimit: 123457.GasInt,
gasPrice: 10.GasInt,
payload: abcdef)
proc tx3(i: int): PooledTransaction =
PooledTransaction(
tx: Transaction(
# Tx with empty access list.
txType: TxEip2930,
chainId: 1.ChainId,
nonce: i.AccountNonce,
to: recipient.some,
gasLimit: 123457.GasInt,
gasPrice: 10.GasInt,
payload: abcdef))
proc tx4(i: int): Transaction =
Transaction(
# Contract creation with access list.
txType: TxEip2930,
chainId: 1.ChainId,
nonce: i.AccountNonce,
gasLimit: 123457.GasInt,
gasPrice: 10.GasInt,
accessList: accesses)
proc tx4(i: int): PooledTransaction =
PooledTransaction(
tx: Transaction(
# Contract creation with access list.
txType: TxEip2930,
chainId: 1.ChainId,
nonce: i.AccountNonce,
gasLimit: 123457.GasInt,
gasPrice: 10.GasInt,
accessList: accesses))
proc tx5(i: int): Transaction =
Transaction(
txType: TxEip1559,
chainId: 1.ChainId,
nonce: i.AccountNonce,
gasLimit: 123457.GasInt,
maxPriorityFee: 42.GasInt,
maxFee: 10.GasInt,
accessList: accesses)
proc tx5(i: int): PooledTransaction =
PooledTransaction(
tx: Transaction(
txType: TxEip1559,
chainId: 1.ChainId,
nonce: i.AccountNonce,
gasLimit: 123457.GasInt,
maxPriorityFee: 42.GasInt,
maxFee: 10.GasInt,
accessList: accesses))
proc tx6(i: int): Transaction =
proc tx6(i: int): PooledTransaction =
const
digest = "010657f37554c781402a22917dee2f75def7ab966d7b770905398eba3c444014".toDigest
Transaction(
txType: TxEip4844,
chainId: 1.ChainId,
nonce: i.AccountNonce,
gasLimit: 123457.GasInt,
maxPriorityFee: 42.GasInt,
maxFee: 10.GasInt,
accessList: accesses,
versionedHashes: @[digest],
PooledTransaction(
tx: Transaction(
txType: TxEip4844,
chainId: 1.ChainId,
nonce: i.AccountNonce,
gasLimit: 123457.GasInt,
maxPriorityFee: 42.GasInt,
maxFee: 10.GasInt,
accessList: accesses,
versionedHashes: @[digest]),
networkPayload: NetworkPayload(
blobs: @[blob],
commitments: @[zeroG1],
proofs: @[zeroG1],
)
)
blobs: @[blob],
commitments: @[zeroG1],
proofs: @[zeroG1]))
proc tx7(i: int): Transaction =
proc tx7(i: int): PooledTransaction =
const
digest = "01624652859a6e98ffc1608e2af0147ca4e86e1ce27672d8d3f3c9d4ffd6ef7e".toDigest
Transaction(
txType: TxEip4844,
chainID: 1.ChainId,
nonce: i.AccountNonce,
gasLimit: 123457.GasInt,
maxPriorityFee: 42.GasInt,
maxFee: 10.GasInt,
accessList: accesses,
versionedHashes: @[digest],
maxFeePerBlobGas: 10000000.u256,
)
PooledTransaction(
tx: Transaction(
txType: TxEip4844,
chainID: 1.ChainId,
nonce: i.AccountNonce,
gasLimit: 123457.GasInt,
maxPriorityFee: 42.GasInt,
maxFee: 10.GasInt,
accessList: accesses,
versionedHashes: @[digest],
maxFeePerBlobGas: 10000000.u256))
proc tx8(i: int): Transaction =
proc tx8(i: int): PooledTransaction =
const
digest = "01624652859a6e98ffc1608e2af0147ca4e86e1ce27672d8d3f3c9d4ffd6ef7e".toDigest
Transaction(
txType: TxEip4844,
chainID: 1.ChainId,
nonce: i.AccountNonce,
to: some(recipient),
gasLimit: 123457.GasInt,
maxPriorityFee: 42.GasInt,
maxFee: 10.GasInt,
accessList: accesses,
versionedHashes: @[digest],
maxFeePerBlobGas: 10000000.u256,
)
PooledTransaction(
tx: Transaction(
txType: TxEip4844,
chainID: 1.ChainId,
nonce: i.AccountNonce,
to: some(recipient),
gasLimit: 123457.GasInt,
maxPriorityFee: 42.GasInt,
maxFee: 10.GasInt,
accessList: accesses,
versionedHashes: @[digest],
maxFeePerBlobGas: 10000000.u256))
template roundTrip(txFunc: untyped, i: int) =
let tx = txFunc(i)
let bytes = rlp.encode(tx)
let tx2 = rlp.decode(bytes, Transaction)
let tx2 = rlp.decode(bytes, PooledTransaction)
let bytes2 = rlp.encode(tx2)
check bytes == bytes2
@ -178,7 +183,7 @@ suite "Transaction RLP Encoding":
test "Network payload survive encode decode":
let tx = tx6(10)
let bytes = rlp.encode(tx)
let zz = rlp.decode(bytes, Transaction)
let zz = rlp.decode(bytes, PooledTransaction)
check not zz.networkPayload.isNil
check zz.networkPayload.proofs == tx.networkPayload.proofs
check zz.networkPayload.blobs == tx.networkPayload.blobs
@ -187,21 +192,21 @@ suite "Transaction RLP Encoding":
test "No Network payload still no network payload":
let tx = tx7(11)
let bytes = rlp.encode(tx)
let zz = rlp.decode(bytes, Transaction)
let zz = rlp.decode(bytes, PooledTransaction)
check zz.networkPayload.isNil
test "Minimal Blob tx recipient survive encode decode":
let tx = tx8(12)
let bytes = rlp.encode(tx)
let zz = rlp.decode(bytes, Transaction)
check zz.to.isSome
let zz = rlp.decode(bytes, PooledTransaction)
check zz.tx.to.isSome
test "Tx List 0,1,2,3,4,5,6,7,8":
let txs = @[tx0(3), tx1(3), tx2(3), tx3(3), tx4(3),
tx5(3), tx6(3), tx7(3), tx8(3)]
let bytes = rlp.encode(txs)
let zz = rlp.decode(bytes, seq[Transaction])
let zz = rlp.decode(bytes, seq[PooledTransaction])
let bytes2 = rlp.encode(zz)
check bytes2 == bytes
@ -210,7 +215,7 @@ suite "Transaction RLP Encoding":
tx3(3), tx2(3), tx1(3), tx0(3)]
let bytes = rlp.encode(txs)
let zz = rlp.decode(bytes, seq[Transaction])
let zz = rlp.decode(bytes, seq[PooledTransaction])
let bytes2 = rlp.encode(zz)
check bytes2 == bytes
@ -219,7 +224,7 @@ suite "Transaction RLP Encoding":
tx4(3), tx3(3), tx2(3), tx1(3)]
let bytes = rlp.encode(txs)
let zz = rlp.decode(bytes, seq[Transaction])
let zz = rlp.decode(bytes, seq[PooledTransaction])
let bytes2 = rlp.encode(zz)
check bytes2 == bytes