mirror of
https://github.com/status-im/nim-eth.git
synced 2025-02-02 17:44:05 +00:00
Merge branch 'dev/etan/tx-pooled' into feat/eip-6493
This commit is contained in:
commit
34adff98a6
@ -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
|
# Licensed and distributed under either of
|
||||||
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
# * 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).
|
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
||||||
|
@ -287,6 +287,7 @@ proc read*(rlp: var Rlp, T: type Transaction): T =
|
|||||||
rlp.readTxTyped(result)
|
rlp.readTxTyped(result)
|
||||||
|
|
||||||
proc read(rlp: var Rlp, T: type NetworkPayload): T =
|
proc read(rlp: var Rlp, T: type NetworkPayload): T =
|
||||||
|
result = NetworkPayload()
|
||||||
rlp.read(result.blobs)
|
rlp.read(result.blobs)
|
||||||
rlp.read(result.commitments)
|
rlp.read(result.commitments)
|
||||||
rlp.read(result.proofs)
|
rlp.read(result.proofs)
|
||||||
@ -301,7 +302,7 @@ proc readTxTyped(rlp: var Rlp, tx: var PooledTransaction) =
|
|||||||
false
|
false
|
||||||
if hasNetworkPayload:
|
if hasNetworkPayload:
|
||||||
rlp.tryEnterList() # spec: rlp([tx_payload, blobs, commitments, proofs])
|
rlp.tryEnterList() # spec: rlp([tx_payload, blobs, commitments, proofs])
|
||||||
rlp.read(tx.tx)
|
rlp.readTxPayload(tx.tx, txType)
|
||||||
if hasNetworkPayload:
|
if hasNetworkPayload:
|
||||||
rlp.read(tx.networkPayload)
|
rlp.read(tx.networkPayload)
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
# Nimbus
|
# Nimbus
|
||||||
# Copyright (c) 2023 Status Research & Development GmbH
|
# Copyright (c) 2023-2024 Status Research & Development GmbH
|
||||||
# Licensed under either of
|
# Licensed under either of
|
||||||
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0)
|
# http://www.apache.org/licenses/LICENSE-2.0)
|
||||||
@ -26,26 +26,29 @@ const
|
|||||||
blob = default(NetworkBlob)
|
blob = default(NetworkBlob)
|
||||||
abcdef = hexToSeqByte("abcdef")
|
abcdef = hexToSeqByte("abcdef")
|
||||||
|
|
||||||
proc tx0(i: int): Transaction =
|
proc tx0(i: int): PooledTransaction =
|
||||||
Transaction(
|
PooledTransaction(
|
||||||
|
tx: Transaction(
|
||||||
txType: TxLegacy,
|
txType: TxLegacy,
|
||||||
nonce: i.AccountNonce,
|
nonce: i.AccountNonce,
|
||||||
to: recipient.some,
|
to: recipient.some,
|
||||||
gasLimit: 1.GasInt,
|
gasLimit: 1.GasInt,
|
||||||
gasPrice: 2.GasInt,
|
gasPrice: 2.GasInt,
|
||||||
payload: abcdef)
|
payload: abcdef))
|
||||||
|
|
||||||
proc tx1(i: int): Transaction =
|
proc tx1(i: int): PooledTransaction =
|
||||||
Transaction(
|
PooledTransaction(
|
||||||
|
tx: Transaction(
|
||||||
# Legacy tx contract creation.
|
# Legacy tx contract creation.
|
||||||
txType: TxLegacy,
|
txType: TxLegacy,
|
||||||
nonce: i.AccountNonce,
|
nonce: i.AccountNonce,
|
||||||
gasLimit: 1.GasInt,
|
gasLimit: 1.GasInt,
|
||||||
gasPrice: 2.GasInt,
|
gasPrice: 2.GasInt,
|
||||||
payload: abcdef)
|
payload: abcdef))
|
||||||
|
|
||||||
proc tx2(i: int): Transaction =
|
proc tx2(i: int): PooledTransaction =
|
||||||
Transaction(
|
PooledTransaction(
|
||||||
|
tx: Transaction(
|
||||||
# Tx with non-zero access list.
|
# Tx with non-zero access list.
|
||||||
txType: TxEip2930,
|
txType: TxEip2930,
|
||||||
chainId: 1.ChainId,
|
chainId: 1.ChainId,
|
||||||
@ -54,10 +57,11 @@ proc tx2(i: int): Transaction =
|
|||||||
gasLimit: 123457.GasInt,
|
gasLimit: 123457.GasInt,
|
||||||
gasPrice: 10.GasInt,
|
gasPrice: 10.GasInt,
|
||||||
accessList: accesses,
|
accessList: accesses,
|
||||||
payload: abcdef)
|
payload: abcdef))
|
||||||
|
|
||||||
proc tx3(i: int): Transaction =
|
proc tx3(i: int): PooledTransaction =
|
||||||
Transaction(
|
PooledTransaction(
|
||||||
|
tx: Transaction(
|
||||||
# Tx with empty access list.
|
# Tx with empty access list.
|
||||||
txType: TxEip2930,
|
txType: TxEip2930,
|
||||||
chainId: 1.ChainId,
|
chainId: 1.ChainId,
|
||||||
@ -65,33 +69,36 @@ proc tx3(i: int): Transaction =
|
|||||||
to: recipient.some,
|
to: recipient.some,
|
||||||
gasLimit: 123457.GasInt,
|
gasLimit: 123457.GasInt,
|
||||||
gasPrice: 10.GasInt,
|
gasPrice: 10.GasInt,
|
||||||
payload: abcdef)
|
payload: abcdef))
|
||||||
|
|
||||||
proc tx4(i: int): Transaction =
|
proc tx4(i: int): PooledTransaction =
|
||||||
Transaction(
|
PooledTransaction(
|
||||||
|
tx: Transaction(
|
||||||
# Contract creation with access list.
|
# Contract creation with access list.
|
||||||
txType: TxEip2930,
|
txType: TxEip2930,
|
||||||
chainId: 1.ChainId,
|
chainId: 1.ChainId,
|
||||||
nonce: i.AccountNonce,
|
nonce: i.AccountNonce,
|
||||||
gasLimit: 123457.GasInt,
|
gasLimit: 123457.GasInt,
|
||||||
gasPrice: 10.GasInt,
|
gasPrice: 10.GasInt,
|
||||||
accessList: accesses)
|
accessList: accesses))
|
||||||
|
|
||||||
proc tx5(i: int): Transaction =
|
proc tx5(i: int): PooledTransaction =
|
||||||
Transaction(
|
PooledTransaction(
|
||||||
|
tx: Transaction(
|
||||||
txType: TxEip1559,
|
txType: TxEip1559,
|
||||||
chainId: 1.ChainId,
|
chainId: 1.ChainId,
|
||||||
nonce: i.AccountNonce,
|
nonce: i.AccountNonce,
|
||||||
gasLimit: 123457.GasInt,
|
gasLimit: 123457.GasInt,
|
||||||
maxPriorityFee: 42.GasInt,
|
maxPriorityFee: 42.GasInt,
|
||||||
maxFee: 10.GasInt,
|
maxFee: 10.GasInt,
|
||||||
accessList: accesses)
|
accessList: accesses))
|
||||||
|
|
||||||
proc tx6(i: int): Transaction =
|
proc tx6(i: int): PooledTransaction =
|
||||||
const
|
const
|
||||||
digest = "010657f37554c781402a22917dee2f75def7ab966d7b770905398eba3c444014".toDigest
|
digest = "010657f37554c781402a22917dee2f75def7ab966d7b770905398eba3c444014".toDigest
|
||||||
|
|
||||||
Transaction(
|
PooledTransaction(
|
||||||
|
tx: Transaction(
|
||||||
txType: TxEip4844,
|
txType: TxEip4844,
|
||||||
chainId: 1.ChainId,
|
chainId: 1.ChainId,
|
||||||
nonce: i.AccountNonce,
|
nonce: i.AccountNonce,
|
||||||
@ -99,19 +106,18 @@ proc tx6(i: int): Transaction =
|
|||||||
maxPriorityFee: 42.GasInt,
|
maxPriorityFee: 42.GasInt,
|
||||||
maxFee: 10.GasInt,
|
maxFee: 10.GasInt,
|
||||||
accessList: accesses,
|
accessList: accesses,
|
||||||
versionedHashes: @[digest],
|
versionedHashes: @[digest]),
|
||||||
networkPayload: NetworkPayload(
|
networkPayload: NetworkPayload(
|
||||||
blobs: @[blob],
|
blobs: @[blob],
|
||||||
commitments: @[zeroG1],
|
commitments: @[zeroG1],
|
||||||
proofs: @[zeroG1],
|
proofs: @[zeroG1]))
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
proc tx7(i: int): Transaction =
|
proc tx7(i: int): PooledTransaction =
|
||||||
const
|
const
|
||||||
digest = "01624652859a6e98ffc1608e2af0147ca4e86e1ce27672d8d3f3c9d4ffd6ef7e".toDigest
|
digest = "01624652859a6e98ffc1608e2af0147ca4e86e1ce27672d8d3f3c9d4ffd6ef7e".toDigest
|
||||||
|
|
||||||
Transaction(
|
PooledTransaction(
|
||||||
|
tx: Transaction(
|
||||||
txType: TxEip4844,
|
txType: TxEip4844,
|
||||||
chainID: 1.ChainId,
|
chainID: 1.ChainId,
|
||||||
nonce: i.AccountNonce,
|
nonce: i.AccountNonce,
|
||||||
@ -120,14 +126,14 @@ proc tx7(i: int): Transaction =
|
|||||||
maxFee: 10.GasInt,
|
maxFee: 10.GasInt,
|
||||||
accessList: accesses,
|
accessList: accesses,
|
||||||
versionedHashes: @[digest],
|
versionedHashes: @[digest],
|
||||||
maxFeePerBlobGas: 10000000.u256,
|
maxFeePerBlobGas: 10000000.u256))
|
||||||
)
|
|
||||||
|
|
||||||
proc tx8(i: int): Transaction =
|
proc tx8(i: int): PooledTransaction =
|
||||||
const
|
const
|
||||||
digest = "01624652859a6e98ffc1608e2af0147ca4e86e1ce27672d8d3f3c9d4ffd6ef7e".toDigest
|
digest = "01624652859a6e98ffc1608e2af0147ca4e86e1ce27672d8d3f3c9d4ffd6ef7e".toDigest
|
||||||
|
|
||||||
Transaction(
|
PooledTransaction(
|
||||||
|
tx: Transaction(
|
||||||
txType: TxEip4844,
|
txType: TxEip4844,
|
||||||
chainID: 1.ChainId,
|
chainID: 1.ChainId,
|
||||||
nonce: i.AccountNonce,
|
nonce: i.AccountNonce,
|
||||||
@ -137,13 +143,12 @@ proc tx8(i: int): Transaction =
|
|||||||
maxFee: 10.GasInt,
|
maxFee: 10.GasInt,
|
||||||
accessList: accesses,
|
accessList: accesses,
|
||||||
versionedHashes: @[digest],
|
versionedHashes: @[digest],
|
||||||
maxFeePerBlobGas: 10000000.u256,
|
maxFeePerBlobGas: 10000000.u256))
|
||||||
)
|
|
||||||
|
|
||||||
template roundTrip(txFunc: untyped, i: int) =
|
template roundTrip(txFunc: untyped, i: int) =
|
||||||
let tx = txFunc(i)
|
let tx = txFunc(i)
|
||||||
let bytes = rlp.encode(tx)
|
let bytes = rlp.encode(tx)
|
||||||
let tx2 = rlp.decode(bytes, Transaction)
|
let tx2 = rlp.decode(bytes, PooledTransaction)
|
||||||
let bytes2 = rlp.encode(tx2)
|
let bytes2 = rlp.encode(tx2)
|
||||||
check bytes == bytes2
|
check bytes == bytes2
|
||||||
|
|
||||||
@ -178,7 +183,7 @@ suite "Transaction RLP Encoding":
|
|||||||
test "Network payload survive encode decode":
|
test "Network payload survive encode decode":
|
||||||
let tx = tx6(10)
|
let tx = tx6(10)
|
||||||
let bytes = rlp.encode(tx)
|
let bytes = rlp.encode(tx)
|
||||||
let zz = rlp.decode(bytes, Transaction)
|
let zz = rlp.decode(bytes, PooledTransaction)
|
||||||
check not zz.networkPayload.isNil
|
check not zz.networkPayload.isNil
|
||||||
check zz.networkPayload.proofs == tx.networkPayload.proofs
|
check zz.networkPayload.proofs == tx.networkPayload.proofs
|
||||||
check zz.networkPayload.blobs == tx.networkPayload.blobs
|
check zz.networkPayload.blobs == tx.networkPayload.blobs
|
||||||
@ -187,21 +192,21 @@ suite "Transaction RLP Encoding":
|
|||||||
test "No Network payload still no network payload":
|
test "No Network payload still no network payload":
|
||||||
let tx = tx7(11)
|
let tx = tx7(11)
|
||||||
let bytes = rlp.encode(tx)
|
let bytes = rlp.encode(tx)
|
||||||
let zz = rlp.decode(bytes, Transaction)
|
let zz = rlp.decode(bytes, PooledTransaction)
|
||||||
check zz.networkPayload.isNil
|
check zz.networkPayload.isNil
|
||||||
|
|
||||||
test "Minimal Blob tx recipient survive encode decode":
|
test "Minimal Blob tx recipient survive encode decode":
|
||||||
let tx = tx8(12)
|
let tx = tx8(12)
|
||||||
let bytes = rlp.encode(tx)
|
let bytes = rlp.encode(tx)
|
||||||
let zz = rlp.decode(bytes, Transaction)
|
let zz = rlp.decode(bytes, PooledTransaction)
|
||||||
check zz.to.isSome
|
check zz.tx.to.isSome
|
||||||
|
|
||||||
test "Tx List 0,1,2,3,4,5,6,7,8":
|
test "Tx List 0,1,2,3,4,5,6,7,8":
|
||||||
let txs = @[tx0(3), tx1(3), tx2(3), tx3(3), tx4(3),
|
let txs = @[tx0(3), tx1(3), tx2(3), tx3(3), tx4(3),
|
||||||
tx5(3), tx6(3), tx7(3), tx8(3)]
|
tx5(3), tx6(3), tx7(3), tx8(3)]
|
||||||
|
|
||||||
let bytes = rlp.encode(txs)
|
let bytes = rlp.encode(txs)
|
||||||
let zz = rlp.decode(bytes, seq[Transaction])
|
let zz = rlp.decode(bytes, seq[PooledTransaction])
|
||||||
let bytes2 = rlp.encode(zz)
|
let bytes2 = rlp.encode(zz)
|
||||||
check bytes2 == bytes
|
check bytes2 == bytes
|
||||||
|
|
||||||
@ -210,7 +215,7 @@ suite "Transaction RLP Encoding":
|
|||||||
tx3(3), tx2(3), tx1(3), tx0(3)]
|
tx3(3), tx2(3), tx1(3), tx0(3)]
|
||||||
|
|
||||||
let bytes = rlp.encode(txs)
|
let bytes = rlp.encode(txs)
|
||||||
let zz = rlp.decode(bytes, seq[Transaction])
|
let zz = rlp.decode(bytes, seq[PooledTransaction])
|
||||||
let bytes2 = rlp.encode(zz)
|
let bytes2 = rlp.encode(zz)
|
||||||
check bytes2 == bytes
|
check bytes2 == bytes
|
||||||
|
|
||||||
@ -219,7 +224,7 @@ suite "Transaction RLP Encoding":
|
|||||||
tx4(3), tx3(3), tx2(3), tx1(3)]
|
tx4(3), tx3(3), tx2(3), tx1(3)]
|
||||||
|
|
||||||
let bytes = rlp.encode(txs)
|
let bytes = rlp.encode(txs)
|
||||||
let zz = rlp.decode(bytes, seq[Transaction])
|
let zz = rlp.decode(bytes, seq[PooledTransaction])
|
||||||
let bytes2 = rlp.encode(zz)
|
let bytes2 = rlp.encode(zz)
|
||||||
check bytes2 == bytes
|
check bytes2 == bytes
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user