mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
rm deposit from pooledtx (#6941)
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
@ -3,7 +3,9 @@
|
||||
use alloy_rlp::{RlpDecodableWrapper, RlpEncodableWrapper};
|
||||
use derive_more::{Constructor, Deref, IntoIterator};
|
||||
use reth_codecs::derive_arbitrary;
|
||||
use reth_primitives::{PooledTransactionsElement, TransactionSigned, B256};
|
||||
use reth_primitives::{
|
||||
transaction::TransactionConversionError, PooledTransactionsElement, TransactionSigned, B256,
|
||||
};
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
use serde::{Deserialize, Serialize};
|
||||
@ -59,9 +61,11 @@ impl PooledTransactions {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Vec<TransactionSigned>> for PooledTransactions {
|
||||
fn from(txs: Vec<TransactionSigned>) -> Self {
|
||||
PooledTransactions(txs.into_iter().map(Into::into).collect())
|
||||
impl TryFrom<Vec<TransactionSigned>> for PooledTransactions {
|
||||
type Error = TransactionConversionError;
|
||||
|
||||
fn try_from(txs: Vec<TransactionSigned>) -> Result<Self, Self::Error> {
|
||||
txs.into_iter().map(PooledTransactionsElement::try_from).collect()
|
||||
}
|
||||
}
|
||||
|
||||
@ -76,7 +80,8 @@ mod tests {
|
||||
use crate::{message::RequestPair, GetPooledTransactions, PooledTransactions};
|
||||
use alloy_rlp::{Decodable, Encodable};
|
||||
use reth_primitives::{
|
||||
hex, Signature, Transaction, TransactionKind, TransactionSigned, TxEip1559, TxLegacy, U256,
|
||||
hex, PooledTransactionsElement, Signature, Transaction, TransactionKind, TransactionSigned,
|
||||
TxEip1559, TxLegacy, U256,
|
||||
};
|
||||
use std::str::FromStr;
|
||||
|
||||
@ -118,59 +123,67 @@ mod tests {
|
||||
fn encode_pooled_transactions() {
|
||||
let expected = hex!("f8d7820457f8d2f867088504a817c8088302e2489435353535353535353535353535353535353535358202008025a064b1702d9298fee62dfeccc57d322a463ad55ca201256d01f62b45b2e1c21c12a064b1702d9298fee62dfeccc57d322a463ad55ca201256d01f62b45b2e1c21c10f867098504a817c809830334509435353535353535353535353535353535353535358202d98025a052f8f61201b2b11a78d6e866abc9c3db2ae8631fa656bfe5cb53668255367afba052f8f61201b2b11a78d6e866abc9c3db2ae8631fa656bfe5cb53668255367afb");
|
||||
let mut data = vec![];
|
||||
let txs = vec![
|
||||
TransactionSigned::from_transaction_and_signature(
|
||||
Transaction::Legacy(TxLegacy {
|
||||
chain_id: Some(1),
|
||||
nonce: 0x8u64,
|
||||
gas_price: 0x4a817c808,
|
||||
gas_limit: 0x2e248u64,
|
||||
to: TransactionKind::Call(
|
||||
hex!("3535353535353535353535353535353535353535").into(),
|
||||
),
|
||||
value: U256::from(0x200u64),
|
||||
input: Default::default(),
|
||||
}),
|
||||
Signature {
|
||||
odd_y_parity: false,
|
||||
r: U256::from_str(
|
||||
"0x64b1702d9298fee62dfeccc57d322a463ad55ca201256d01f62b45b2e1c21c12",
|
||||
)
|
||||
.unwrap(),
|
||||
s: U256::from_str(
|
||||
"0x64b1702d9298fee62dfeccc57d322a463ad55ca201256d01f62b45b2e1c21c10",
|
||||
)
|
||||
.unwrap(),
|
||||
},
|
||||
),
|
||||
TransactionSigned::from_transaction_and_signature(
|
||||
Transaction::Legacy(TxLegacy {
|
||||
chain_id: Some(1),
|
||||
nonce: 0x09u64,
|
||||
gas_price: 0x4a817c809,
|
||||
gas_limit: 0x33450u64,
|
||||
to: TransactionKind::Call(
|
||||
hex!("3535353535353535353535353535353535353535").into(),
|
||||
),
|
||||
value: U256::from(0x2d9u64),
|
||||
input: Default::default(),
|
||||
}),
|
||||
Signature {
|
||||
odd_y_parity: false,
|
||||
r: U256::from_str(
|
||||
"0x52f8f61201b2b11a78d6e866abc9c3db2ae8631fa656bfe5cb53668255367afb",
|
||||
)
|
||||
.unwrap(),
|
||||
s: U256::from_str(
|
||||
"0x52f8f61201b2b11a78d6e866abc9c3db2ae8631fa656bfe5cb53668255367afb",
|
||||
)
|
||||
.unwrap(),
|
||||
},
|
||||
),
|
||||
];
|
||||
let message: Vec<PooledTransactionsElement> = txs
|
||||
.into_iter()
|
||||
.map(|tx| {
|
||||
PooledTransactionsElement::try_from(tx)
|
||||
.expect("Failed to convert TransactionSigned to PooledTransactionsElement")
|
||||
})
|
||||
.collect();
|
||||
let request = RequestPair::<PooledTransactions> {
|
||||
request_id: 1111,
|
||||
message: vec![
|
||||
TransactionSigned::from_transaction_and_signature(
|
||||
Transaction::Legacy(TxLegacy {
|
||||
chain_id: Some(1),
|
||||
nonce: 0x8u64,
|
||||
gas_price: 0x4a817c808,
|
||||
gas_limit: 0x2e248u64,
|
||||
to: TransactionKind::Call(
|
||||
hex!("3535353535353535353535353535353535353535").into(),
|
||||
),
|
||||
value: U256::from(0x200u64),
|
||||
input: Default::default(),
|
||||
}),
|
||||
Signature {
|
||||
odd_y_parity: false,
|
||||
r: U256::from_str(
|
||||
"0x64b1702d9298fee62dfeccc57d322a463ad55ca201256d01f62b45b2e1c21c12",
|
||||
)
|
||||
.unwrap(),
|
||||
s: U256::from_str(
|
||||
"0x64b1702d9298fee62dfeccc57d322a463ad55ca201256d01f62b45b2e1c21c10",
|
||||
)
|
||||
.unwrap(),
|
||||
},
|
||||
),
|
||||
TransactionSigned::from_transaction_and_signature(
|
||||
Transaction::Legacy(TxLegacy {
|
||||
chain_id: Some(1),
|
||||
nonce: 0x09u64,
|
||||
gas_price: 0x4a817c809,
|
||||
gas_limit: 0x33450u64,
|
||||
to: TransactionKind::Call(
|
||||
hex!("3535353535353535353535353535353535353535").into(),
|
||||
),
|
||||
value: U256::from(0x2d9u64),
|
||||
input: Default::default(),
|
||||
}),
|
||||
Signature {
|
||||
odd_y_parity: false,
|
||||
r: U256::from_str(
|
||||
"0x52f8f61201b2b11a78d6e866abc9c3db2ae8631fa656bfe5cb53668255367afb",
|
||||
)
|
||||
.unwrap(),
|
||||
s: U256::from_str(
|
||||
"0x52f8f61201b2b11a78d6e866abc9c3db2ae8631fa656bfe5cb53668255367afb",
|
||||
)
|
||||
.unwrap(),
|
||||
},
|
||||
),
|
||||
]
|
||||
.into(),
|
||||
message: PooledTransactions(message), /* Assuming PooledTransactions wraps a
|
||||
* Vec<PooledTransactionsElement> */
|
||||
};
|
||||
request.encode(&mut data);
|
||||
assert_eq!(data, expected);
|
||||
@ -180,59 +193,66 @@ mod tests {
|
||||
// Test vector from: https://eips.ethereum.org/EIPS/eip-2481
|
||||
fn decode_pooled_transactions() {
|
||||
let data = hex!("f8d7820457f8d2f867088504a817c8088302e2489435353535353535353535353535353535353535358202008025a064b1702d9298fee62dfeccc57d322a463ad55ca201256d01f62b45b2e1c21c12a064b1702d9298fee62dfeccc57d322a463ad55ca201256d01f62b45b2e1c21c10f867098504a817c809830334509435353535353535353535353535353535353535358202d98025a052f8f61201b2b11a78d6e866abc9c3db2ae8631fa656bfe5cb53668255367afba052f8f61201b2b11a78d6e866abc9c3db2ae8631fa656bfe5cb53668255367afb");
|
||||
let txs = vec![
|
||||
TransactionSigned::from_transaction_and_signature(
|
||||
Transaction::Legacy(TxLegacy {
|
||||
chain_id: Some(1),
|
||||
nonce: 0x8u64,
|
||||
gas_price: 0x4a817c808,
|
||||
gas_limit: 0x2e248u64,
|
||||
to: TransactionKind::Call(
|
||||
hex!("3535353535353535353535353535353535353535").into(),
|
||||
),
|
||||
value: U256::from(0x200u64),
|
||||
input: Default::default(),
|
||||
}),
|
||||
Signature {
|
||||
odd_y_parity: false,
|
||||
r: U256::from_str(
|
||||
"0x64b1702d9298fee62dfeccc57d322a463ad55ca201256d01f62b45b2e1c21c12",
|
||||
)
|
||||
.unwrap(),
|
||||
s: U256::from_str(
|
||||
"0x64b1702d9298fee62dfeccc57d322a463ad55ca201256d01f62b45b2e1c21c10",
|
||||
)
|
||||
.unwrap(),
|
||||
},
|
||||
),
|
||||
TransactionSigned::from_transaction_and_signature(
|
||||
Transaction::Legacy(TxLegacy {
|
||||
chain_id: Some(1),
|
||||
nonce: 0x09u64,
|
||||
gas_price: 0x4a817c809,
|
||||
gas_limit: 0x33450u64,
|
||||
to: TransactionKind::Call(
|
||||
hex!("3535353535353535353535353535353535353535").into(),
|
||||
),
|
||||
value: U256::from(0x2d9u64),
|
||||
input: Default::default(),
|
||||
}),
|
||||
Signature {
|
||||
odd_y_parity: false,
|
||||
r: U256::from_str(
|
||||
"0x52f8f61201b2b11a78d6e866abc9c3db2ae8631fa656bfe5cb53668255367afb",
|
||||
)
|
||||
.unwrap(),
|
||||
s: U256::from_str(
|
||||
"0x52f8f61201b2b11a78d6e866abc9c3db2ae8631fa656bfe5cb53668255367afb",
|
||||
)
|
||||
.unwrap(),
|
||||
},
|
||||
),
|
||||
];
|
||||
let message: Vec<PooledTransactionsElement> = txs
|
||||
.into_iter()
|
||||
.map(|tx| {
|
||||
PooledTransactionsElement::try_from(tx)
|
||||
.expect("Failed to convert TransactionSigned to PooledTransactionsElement")
|
||||
})
|
||||
.collect();
|
||||
let expected = RequestPair::<PooledTransactions> {
|
||||
request_id: 1111,
|
||||
message: vec![
|
||||
TransactionSigned::from_transaction_and_signature(
|
||||
Transaction::Legacy(TxLegacy {
|
||||
chain_id: Some(1),
|
||||
nonce: 0x8u64,
|
||||
gas_price: 0x4a817c808,
|
||||
gas_limit: 0x2e248u64,
|
||||
to: TransactionKind::Call(
|
||||
hex!("3535353535353535353535353535353535353535").into(),
|
||||
),
|
||||
value: U256::from(0x200u64),
|
||||
input: Default::default(),
|
||||
}),
|
||||
Signature {
|
||||
odd_y_parity: false,
|
||||
r: U256::from_str(
|
||||
"0x64b1702d9298fee62dfeccc57d322a463ad55ca201256d01f62b45b2e1c21c12",
|
||||
)
|
||||
.unwrap(),
|
||||
s: U256::from_str(
|
||||
"0x64b1702d9298fee62dfeccc57d322a463ad55ca201256d01f62b45b2e1c21c10",
|
||||
)
|
||||
.unwrap(),
|
||||
},
|
||||
),
|
||||
TransactionSigned::from_transaction_and_signature(
|
||||
Transaction::Legacy(TxLegacy {
|
||||
chain_id: Some(1),
|
||||
nonce: 0x09u64,
|
||||
gas_price: 0x4a817c809,
|
||||
gas_limit: 0x33450u64,
|
||||
to: TransactionKind::Call(
|
||||
hex!("3535353535353535353535353535353535353535").into(),
|
||||
),
|
||||
value: U256::from(0x2d9u64),
|
||||
input: Default::default(),
|
||||
}),
|
||||
Signature {
|
||||
odd_y_parity: false,
|
||||
r: U256::from_str(
|
||||
"0x52f8f61201b2b11a78d6e866abc9c3db2ae8631fa656bfe5cb53668255367afb",
|
||||
)
|
||||
.unwrap(),
|
||||
s: U256::from_str(
|
||||
"0x52f8f61201b2b11a78d6e866abc9c3db2ae8631fa656bfe5cb53668255367afb",
|
||||
)
|
||||
.unwrap(),
|
||||
},
|
||||
),
|
||||
]
|
||||
.into(),
|
||||
message: PooledTransactions(message),
|
||||
};
|
||||
|
||||
let request = RequestPair::<PooledTransactions>::decode(&mut &data[..]).unwrap();
|
||||
@ -244,134 +264,140 @@ mod tests {
|
||||
let data = hex!("f9022980f90225f8650f84832156008287fb94cf7f9e66af820a19257a2108375b180b0ec491678204d2802ca035b7bfeb9ad9ece2cbafaaf8e202e706b4cfaeb233f46198f00b44d4a566a981a0612638fb29427ca33b9a3be2a0a561beecfe0269655be160d35e72d366a6a860b87502f872041a8459682f008459682f0d8252089461815774383099e24810ab832a5b2a5425c154d58829a2241af62c000080c001a059e6b67f48fb32e7e570dfb11e042b5ad2e55e3ce3ce9cd989c7e06e07feeafda0016b83f4f980694ed2eee4d10667242b1f40dc406901b34125b008d334d47469f86b0384773594008398968094d3e8763675e4c425df46cc3b5c0f6cbdac39604687038d7ea4c68000802ba0ce6834447c0a4193c40382e6c57ae33b241379c5418caac9cdc18d786fd12071a03ca3ae86580e94550d7c071e3a02eadb5a77830947c9225165cf9100901bee88f86b01843b9aca00830186a094d3e8763675e4c425df46cc3b5c0f6cbdac3960468702769bb01b2a00802ba0e24d8bd32ad906d6f8b8d7741e08d1959df021698b19ee232feba15361587d0aa05406ad177223213df262cb66ccbb2f46bfdccfdfbbb5ffdda9e2c02d977631daf86b02843b9aca00830186a094d3e8763675e4c425df46cc3b5c0f6cbdac39604687038d7ea4c68000802ba00eb96ca19e8a77102767a41fc85a36afd5c61ccb09911cec5d3e86e193d9c5aea03a456401896b1b6055311536bf00a718568c744d8c1f9df59879e8350220ca18");
|
||||
let decoded_transactions =
|
||||
RequestPair::<PooledTransactions>::decode(&mut &data[..]).unwrap();
|
||||
|
||||
let txs = vec![
|
||||
TransactionSigned::from_transaction_and_signature(
|
||||
Transaction::Legacy(TxLegacy {
|
||||
chain_id: Some(4),
|
||||
nonce: 15u64,
|
||||
gas_price: 2200000000,
|
||||
gas_limit: 34811u64,
|
||||
to: TransactionKind::Call(
|
||||
hex!("cf7f9e66af820a19257a2108375b180b0ec49167").into(),
|
||||
),
|
||||
value: U256::from(1234u64),
|
||||
input: Default::default(),
|
||||
}),
|
||||
Signature {
|
||||
odd_y_parity: true,
|
||||
r: U256::from_str(
|
||||
"0x35b7bfeb9ad9ece2cbafaaf8e202e706b4cfaeb233f46198f00b44d4a566a981",
|
||||
)
|
||||
.unwrap(),
|
||||
s: U256::from_str(
|
||||
"0x612638fb29427ca33b9a3be2a0a561beecfe0269655be160d35e72d366a6a860",
|
||||
)
|
||||
.unwrap(),
|
||||
},
|
||||
),
|
||||
TransactionSigned::from_transaction_and_signature(
|
||||
Transaction::Eip1559(TxEip1559 {
|
||||
chain_id: 4,
|
||||
nonce: 26u64,
|
||||
max_priority_fee_per_gas: 1500000000,
|
||||
max_fee_per_gas: 1500000013,
|
||||
gas_limit: 21000u64,
|
||||
to: TransactionKind::Call(
|
||||
hex!("61815774383099e24810ab832a5b2a5425c154d5").into(),
|
||||
),
|
||||
value: U256::from(3000000000000000000u64),
|
||||
input: Default::default(),
|
||||
access_list: Default::default(),
|
||||
}),
|
||||
Signature {
|
||||
odd_y_parity: true,
|
||||
r: U256::from_str(
|
||||
"0x59e6b67f48fb32e7e570dfb11e042b5ad2e55e3ce3ce9cd989c7e06e07feeafd",
|
||||
)
|
||||
.unwrap(),
|
||||
s: U256::from_str(
|
||||
"0x016b83f4f980694ed2eee4d10667242b1f40dc406901b34125b008d334d47469",
|
||||
)
|
||||
.unwrap(),
|
||||
},
|
||||
),
|
||||
TransactionSigned::from_transaction_and_signature(
|
||||
Transaction::Legacy(TxLegacy {
|
||||
chain_id: Some(4),
|
||||
nonce: 3u64,
|
||||
gas_price: 2000000000,
|
||||
gas_limit: 10000000u64,
|
||||
to: TransactionKind::Call(
|
||||
hex!("d3e8763675e4c425df46cc3b5c0f6cbdac396046").into(),
|
||||
),
|
||||
value: U256::from(1000000000000000u64),
|
||||
input: Default::default(),
|
||||
}),
|
||||
Signature {
|
||||
odd_y_parity: false,
|
||||
r: U256::from_str(
|
||||
"0xce6834447c0a4193c40382e6c57ae33b241379c5418caac9cdc18d786fd12071",
|
||||
)
|
||||
.unwrap(),
|
||||
s: U256::from_str(
|
||||
"0x3ca3ae86580e94550d7c071e3a02eadb5a77830947c9225165cf9100901bee88",
|
||||
)
|
||||
.unwrap(),
|
||||
},
|
||||
),
|
||||
TransactionSigned::from_transaction_and_signature(
|
||||
Transaction::Legacy(TxLegacy {
|
||||
chain_id: Some(4),
|
||||
nonce: 1u64,
|
||||
gas_price: 1000000000,
|
||||
gas_limit: 100000u64,
|
||||
to: TransactionKind::Call(
|
||||
hex!("d3e8763675e4c425df46cc3b5c0f6cbdac396046").into(),
|
||||
),
|
||||
value: U256::from(693361000000000u64),
|
||||
input: Default::default(),
|
||||
}),
|
||||
Signature {
|
||||
odd_y_parity: false,
|
||||
r: U256::from_str(
|
||||
"0xe24d8bd32ad906d6f8b8d7741e08d1959df021698b19ee232feba15361587d0a",
|
||||
)
|
||||
.unwrap(),
|
||||
s: U256::from_str(
|
||||
"0x5406ad177223213df262cb66ccbb2f46bfdccfdfbbb5ffdda9e2c02d977631da",
|
||||
)
|
||||
.unwrap(),
|
||||
},
|
||||
),
|
||||
TransactionSigned::from_transaction_and_signature(
|
||||
Transaction::Legacy(TxLegacy {
|
||||
chain_id: Some(4),
|
||||
nonce: 2u64,
|
||||
gas_price: 1000000000,
|
||||
gas_limit: 100000u64,
|
||||
to: TransactionKind::Call(
|
||||
hex!("d3e8763675e4c425df46cc3b5c0f6cbdac396046").into(),
|
||||
),
|
||||
value: U256::from(1000000000000000u64),
|
||||
input: Default::default(),
|
||||
}),
|
||||
Signature {
|
||||
odd_y_parity: false,
|
||||
r: U256::from_str(
|
||||
"0xeb96ca19e8a77102767a41fc85a36afd5c61ccb09911cec5d3e86e193d9c5ae",
|
||||
)
|
||||
.unwrap(),
|
||||
s: U256::from_str(
|
||||
"0x3a456401896b1b6055311536bf00a718568c744d8c1f9df59879e8350220ca18",
|
||||
)
|
||||
.unwrap(),
|
||||
},
|
||||
),
|
||||
];
|
||||
let message: Vec<PooledTransactionsElement> = txs
|
||||
.into_iter()
|
||||
.map(|tx| {
|
||||
PooledTransactionsElement::try_from(tx)
|
||||
.expect("Failed to convert TransactionSigned to PooledTransactionsElement")
|
||||
})
|
||||
.collect();
|
||||
let expected_transactions = RequestPair::<PooledTransactions> {
|
||||
request_id: 0,
|
||||
message: vec![
|
||||
TransactionSigned::from_transaction_and_signature(
|
||||
Transaction::Legacy(TxLegacy {
|
||||
chain_id: Some(4),
|
||||
nonce: 15u64,
|
||||
gas_price: 2200000000,
|
||||
gas_limit: 34811u64,
|
||||
to: TransactionKind::Call(
|
||||
hex!("cf7f9e66af820a19257a2108375b180b0ec49167").into(),
|
||||
),
|
||||
value: U256::from(1234u64),
|
||||
input: Default::default(),
|
||||
}),
|
||||
Signature {
|
||||
odd_y_parity: true,
|
||||
r: U256::from_str(
|
||||
"0x35b7bfeb9ad9ece2cbafaaf8e202e706b4cfaeb233f46198f00b44d4a566a981",
|
||||
)
|
||||
.unwrap(),
|
||||
s: U256::from_str(
|
||||
"0x612638fb29427ca33b9a3be2a0a561beecfe0269655be160d35e72d366a6a860",
|
||||
)
|
||||
.unwrap(),
|
||||
},
|
||||
),
|
||||
TransactionSigned::from_transaction_and_signature(
|
||||
Transaction::Eip1559(TxEip1559 {
|
||||
chain_id: 4,
|
||||
nonce: 26u64,
|
||||
max_priority_fee_per_gas: 1500000000,
|
||||
max_fee_per_gas: 1500000013,
|
||||
gas_limit: 21000u64,
|
||||
to: TransactionKind::Call(
|
||||
hex!("61815774383099e24810ab832a5b2a5425c154d5").into(),
|
||||
),
|
||||
value: U256::from(3000000000000000000u64),
|
||||
input: Default::default(),
|
||||
access_list: Default::default(),
|
||||
}),
|
||||
Signature {
|
||||
odd_y_parity: true,
|
||||
r: U256::from_str(
|
||||
"0x59e6b67f48fb32e7e570dfb11e042b5ad2e55e3ce3ce9cd989c7e06e07feeafd",
|
||||
)
|
||||
.unwrap(),
|
||||
s: U256::from_str(
|
||||
"0x016b83f4f980694ed2eee4d10667242b1f40dc406901b34125b008d334d47469",
|
||||
)
|
||||
.unwrap(),
|
||||
},
|
||||
),
|
||||
TransactionSigned::from_transaction_and_signature(
|
||||
Transaction::Legacy(TxLegacy {
|
||||
chain_id: Some(4),
|
||||
nonce: 3u64,
|
||||
gas_price: 2000000000,
|
||||
gas_limit: 10000000u64,
|
||||
to: TransactionKind::Call(
|
||||
hex!("d3e8763675e4c425df46cc3b5c0f6cbdac396046").into(),
|
||||
),
|
||||
value: U256::from(1000000000000000u64),
|
||||
input: Default::default(),
|
||||
}),
|
||||
Signature {
|
||||
odd_y_parity: false,
|
||||
r: U256::from_str(
|
||||
"0xce6834447c0a4193c40382e6c57ae33b241379c5418caac9cdc18d786fd12071",
|
||||
)
|
||||
.unwrap(),
|
||||
s: U256::from_str(
|
||||
"0x3ca3ae86580e94550d7c071e3a02eadb5a77830947c9225165cf9100901bee88",
|
||||
)
|
||||
.unwrap(),
|
||||
},
|
||||
),
|
||||
TransactionSigned::from_transaction_and_signature(
|
||||
Transaction::Legacy(TxLegacy {
|
||||
chain_id: Some(4),
|
||||
nonce: 1u64,
|
||||
gas_price: 1000000000,
|
||||
gas_limit: 100000u64,
|
||||
to: TransactionKind::Call(
|
||||
hex!("d3e8763675e4c425df46cc3b5c0f6cbdac396046").into(),
|
||||
),
|
||||
value: U256::from(693361000000000u64),
|
||||
input: Default::default(),
|
||||
}),
|
||||
Signature {
|
||||
odd_y_parity: false,
|
||||
r: U256::from_str(
|
||||
"0xe24d8bd32ad906d6f8b8d7741e08d1959df021698b19ee232feba15361587d0a",
|
||||
)
|
||||
.unwrap(),
|
||||
s: U256::from_str(
|
||||
"0x5406ad177223213df262cb66ccbb2f46bfdccfdfbbb5ffdda9e2c02d977631da",
|
||||
)
|
||||
.unwrap(),
|
||||
},
|
||||
),
|
||||
TransactionSigned::from_transaction_and_signature(
|
||||
Transaction::Legacy(TxLegacy {
|
||||
chain_id: Some(4),
|
||||
nonce: 2u64,
|
||||
gas_price: 1000000000,
|
||||
gas_limit: 100000u64,
|
||||
to: TransactionKind::Call(
|
||||
hex!("d3e8763675e4c425df46cc3b5c0f6cbdac396046").into(),
|
||||
),
|
||||
value: U256::from(1000000000000000u64),
|
||||
input: Default::default(),
|
||||
}),
|
||||
Signature {
|
||||
odd_y_parity: false,
|
||||
r: U256::from_str(
|
||||
"0xeb96ca19e8a77102767a41fc85a36afd5c61ccb09911cec5d3e86e193d9c5ae",
|
||||
)
|
||||
.unwrap(),
|
||||
s: U256::from_str(
|
||||
"0x3a456401896b1b6055311536bf00a718568c744d8c1f9df59879e8350220ca18",
|
||||
)
|
||||
.unwrap(),
|
||||
},
|
||||
),
|
||||
]
|
||||
.into(),
|
||||
message: PooledTransactions(message),
|
||||
};
|
||||
|
||||
// checking tx by tx for easier debugging if there are any regressions
|
||||
@ -387,134 +413,140 @@ mod tests {
|
||||
#[test]
|
||||
fn encode_pooled_transactions_network() {
|
||||
let expected = hex!("f9022980f90225f8650f84832156008287fb94cf7f9e66af820a19257a2108375b180b0ec491678204d2802ca035b7bfeb9ad9ece2cbafaaf8e202e706b4cfaeb233f46198f00b44d4a566a981a0612638fb29427ca33b9a3be2a0a561beecfe0269655be160d35e72d366a6a860b87502f872041a8459682f008459682f0d8252089461815774383099e24810ab832a5b2a5425c154d58829a2241af62c000080c001a059e6b67f48fb32e7e570dfb11e042b5ad2e55e3ce3ce9cd989c7e06e07feeafda0016b83f4f980694ed2eee4d10667242b1f40dc406901b34125b008d334d47469f86b0384773594008398968094d3e8763675e4c425df46cc3b5c0f6cbdac39604687038d7ea4c68000802ba0ce6834447c0a4193c40382e6c57ae33b241379c5418caac9cdc18d786fd12071a03ca3ae86580e94550d7c071e3a02eadb5a77830947c9225165cf9100901bee88f86b01843b9aca00830186a094d3e8763675e4c425df46cc3b5c0f6cbdac3960468702769bb01b2a00802ba0e24d8bd32ad906d6f8b8d7741e08d1959df021698b19ee232feba15361587d0aa05406ad177223213df262cb66ccbb2f46bfdccfdfbbb5ffdda9e2c02d977631daf86b02843b9aca00830186a094d3e8763675e4c425df46cc3b5c0f6cbdac39604687038d7ea4c68000802ba00eb96ca19e8a77102767a41fc85a36afd5c61ccb09911cec5d3e86e193d9c5aea03a456401896b1b6055311536bf00a718568c744d8c1f9df59879e8350220ca18");
|
||||
|
||||
let txs = vec![
|
||||
TransactionSigned::from_transaction_and_signature(
|
||||
Transaction::Legacy(TxLegacy {
|
||||
chain_id: Some(4),
|
||||
nonce: 15u64,
|
||||
gas_price: 2200000000,
|
||||
gas_limit: 34811u64,
|
||||
to: TransactionKind::Call(
|
||||
hex!("cf7f9e66af820a19257a2108375b180b0ec49167").into(),
|
||||
),
|
||||
value: U256::from(1234u64),
|
||||
input: Default::default(),
|
||||
}),
|
||||
Signature {
|
||||
odd_y_parity: true,
|
||||
r: U256::from_str(
|
||||
"0x35b7bfeb9ad9ece2cbafaaf8e202e706b4cfaeb233f46198f00b44d4a566a981",
|
||||
)
|
||||
.unwrap(),
|
||||
s: U256::from_str(
|
||||
"0x612638fb29427ca33b9a3be2a0a561beecfe0269655be160d35e72d366a6a860",
|
||||
)
|
||||
.unwrap(),
|
||||
},
|
||||
),
|
||||
TransactionSigned::from_transaction_and_signature(
|
||||
Transaction::Eip1559(TxEip1559 {
|
||||
chain_id: 4,
|
||||
nonce: 26u64,
|
||||
max_priority_fee_per_gas: 1500000000,
|
||||
max_fee_per_gas: 1500000013,
|
||||
gas_limit: 21000u64,
|
||||
to: TransactionKind::Call(
|
||||
hex!("61815774383099e24810ab832a5b2a5425c154d5").into(),
|
||||
),
|
||||
value: U256::from(3000000000000000000u64),
|
||||
input: Default::default(),
|
||||
access_list: Default::default(),
|
||||
}),
|
||||
Signature {
|
||||
odd_y_parity: true,
|
||||
r: U256::from_str(
|
||||
"0x59e6b67f48fb32e7e570dfb11e042b5ad2e55e3ce3ce9cd989c7e06e07feeafd",
|
||||
)
|
||||
.unwrap(),
|
||||
s: U256::from_str(
|
||||
"0x016b83f4f980694ed2eee4d10667242b1f40dc406901b34125b008d334d47469",
|
||||
)
|
||||
.unwrap(),
|
||||
},
|
||||
),
|
||||
TransactionSigned::from_transaction_and_signature(
|
||||
Transaction::Legacy(TxLegacy {
|
||||
chain_id: Some(4),
|
||||
nonce: 3u64,
|
||||
gas_price: 2000000000,
|
||||
gas_limit: 10000000u64,
|
||||
to: TransactionKind::Call(
|
||||
hex!("d3e8763675e4c425df46cc3b5c0f6cbdac396046").into(),
|
||||
),
|
||||
value: U256::from(1000000000000000u64),
|
||||
input: Default::default(),
|
||||
}),
|
||||
Signature {
|
||||
odd_y_parity: false,
|
||||
r: U256::from_str(
|
||||
"0xce6834447c0a4193c40382e6c57ae33b241379c5418caac9cdc18d786fd12071",
|
||||
)
|
||||
.unwrap(),
|
||||
s: U256::from_str(
|
||||
"0x3ca3ae86580e94550d7c071e3a02eadb5a77830947c9225165cf9100901bee88",
|
||||
)
|
||||
.unwrap(),
|
||||
},
|
||||
),
|
||||
TransactionSigned::from_transaction_and_signature(
|
||||
Transaction::Legacy(TxLegacy {
|
||||
chain_id: Some(4),
|
||||
nonce: 1u64,
|
||||
gas_price: 1000000000,
|
||||
gas_limit: 100000u64,
|
||||
to: TransactionKind::Call(
|
||||
hex!("d3e8763675e4c425df46cc3b5c0f6cbdac396046").into(),
|
||||
),
|
||||
value: U256::from(693361000000000u64),
|
||||
input: Default::default(),
|
||||
}),
|
||||
Signature {
|
||||
odd_y_parity: false,
|
||||
r: U256::from_str(
|
||||
"0xe24d8bd32ad906d6f8b8d7741e08d1959df021698b19ee232feba15361587d0a",
|
||||
)
|
||||
.unwrap(),
|
||||
s: U256::from_str(
|
||||
"0x5406ad177223213df262cb66ccbb2f46bfdccfdfbbb5ffdda9e2c02d977631da",
|
||||
)
|
||||
.unwrap(),
|
||||
},
|
||||
),
|
||||
TransactionSigned::from_transaction_and_signature(
|
||||
Transaction::Legacy(TxLegacy {
|
||||
chain_id: Some(4),
|
||||
nonce: 2u64,
|
||||
gas_price: 1000000000,
|
||||
gas_limit: 100000u64,
|
||||
to: TransactionKind::Call(
|
||||
hex!("d3e8763675e4c425df46cc3b5c0f6cbdac396046").into(),
|
||||
),
|
||||
value: U256::from(1000000000000000u64),
|
||||
input: Default::default(),
|
||||
}),
|
||||
Signature {
|
||||
odd_y_parity: false,
|
||||
r: U256::from_str(
|
||||
"0xeb96ca19e8a77102767a41fc85a36afd5c61ccb09911cec5d3e86e193d9c5ae",
|
||||
)
|
||||
.unwrap(),
|
||||
s: U256::from_str(
|
||||
"0x3a456401896b1b6055311536bf00a718568c744d8c1f9df59879e8350220ca18",
|
||||
)
|
||||
.unwrap(),
|
||||
},
|
||||
),
|
||||
];
|
||||
let message: Vec<PooledTransactionsElement> = txs
|
||||
.into_iter()
|
||||
.map(|tx| {
|
||||
PooledTransactionsElement::try_from(tx)
|
||||
.expect("Failed to convert TransactionSigned to PooledTransactionsElement")
|
||||
})
|
||||
.collect();
|
||||
let transactions = RequestPair::<PooledTransactions> {
|
||||
request_id: 0,
|
||||
message: vec![
|
||||
TransactionSigned::from_transaction_and_signature(
|
||||
Transaction::Legacy(TxLegacy {
|
||||
chain_id: Some(4),
|
||||
nonce: 15u64,
|
||||
gas_price: 2200000000,
|
||||
gas_limit: 34811u64,
|
||||
to: TransactionKind::Call(
|
||||
hex!("cf7f9e66af820a19257a2108375b180b0ec49167").into(),
|
||||
),
|
||||
value: U256::from(1234u64),
|
||||
input: Default::default(),
|
||||
}),
|
||||
Signature {
|
||||
odd_y_parity: true,
|
||||
r: U256::from_str(
|
||||
"0x35b7bfeb9ad9ece2cbafaaf8e202e706b4cfaeb233f46198f00b44d4a566a981",
|
||||
)
|
||||
.unwrap(),
|
||||
s: U256::from_str(
|
||||
"0x612638fb29427ca33b9a3be2a0a561beecfe0269655be160d35e72d366a6a860",
|
||||
)
|
||||
.unwrap(),
|
||||
},
|
||||
),
|
||||
TransactionSigned::from_transaction_and_signature(
|
||||
Transaction::Eip1559(TxEip1559 {
|
||||
chain_id: 4,
|
||||
nonce: 26u64,
|
||||
max_priority_fee_per_gas: 1500000000,
|
||||
max_fee_per_gas: 1500000013,
|
||||
gas_limit: 21000u64,
|
||||
to: TransactionKind::Call(
|
||||
hex!("61815774383099e24810ab832a5b2a5425c154d5").into(),
|
||||
),
|
||||
value: U256::from(3000000000000000000u64),
|
||||
input: Default::default(),
|
||||
access_list: Default::default(),
|
||||
}),
|
||||
Signature {
|
||||
odd_y_parity: true,
|
||||
r: U256::from_str(
|
||||
"0x59e6b67f48fb32e7e570dfb11e042b5ad2e55e3ce3ce9cd989c7e06e07feeafd",
|
||||
)
|
||||
.unwrap(),
|
||||
s: U256::from_str(
|
||||
"0x016b83f4f980694ed2eee4d10667242b1f40dc406901b34125b008d334d47469",
|
||||
)
|
||||
.unwrap(),
|
||||
},
|
||||
),
|
||||
TransactionSigned::from_transaction_and_signature(
|
||||
Transaction::Legacy(TxLegacy {
|
||||
chain_id: Some(4),
|
||||
nonce: 3u64,
|
||||
gas_price: 2000000000,
|
||||
gas_limit: 10000000u64,
|
||||
to: TransactionKind::Call(
|
||||
hex!("d3e8763675e4c425df46cc3b5c0f6cbdac396046").into(),
|
||||
),
|
||||
value: U256::from(1000000000000000u64),
|
||||
input: Default::default(),
|
||||
}),
|
||||
Signature {
|
||||
odd_y_parity: false,
|
||||
r: U256::from_str(
|
||||
"0xce6834447c0a4193c40382e6c57ae33b241379c5418caac9cdc18d786fd12071",
|
||||
)
|
||||
.unwrap(),
|
||||
s: U256::from_str(
|
||||
"0x3ca3ae86580e94550d7c071e3a02eadb5a77830947c9225165cf9100901bee88",
|
||||
)
|
||||
.unwrap(),
|
||||
},
|
||||
),
|
||||
TransactionSigned::from_transaction_and_signature(
|
||||
Transaction::Legacy(TxLegacy {
|
||||
chain_id: Some(4),
|
||||
nonce: 1u64,
|
||||
gas_price: 1000000000,
|
||||
gas_limit: 100000u64,
|
||||
to: TransactionKind::Call(
|
||||
hex!("d3e8763675e4c425df46cc3b5c0f6cbdac396046").into(),
|
||||
),
|
||||
value: U256::from(693361000000000u64),
|
||||
input: Default::default(),
|
||||
}),
|
||||
Signature {
|
||||
odd_y_parity: false,
|
||||
r: U256::from_str(
|
||||
"0xe24d8bd32ad906d6f8b8d7741e08d1959df021698b19ee232feba15361587d0a",
|
||||
)
|
||||
.unwrap(),
|
||||
s: U256::from_str(
|
||||
"0x5406ad177223213df262cb66ccbb2f46bfdccfdfbbb5ffdda9e2c02d977631da",
|
||||
)
|
||||
.unwrap(),
|
||||
},
|
||||
),
|
||||
TransactionSigned::from_transaction_and_signature(
|
||||
Transaction::Legacy(TxLegacy {
|
||||
chain_id: Some(4),
|
||||
nonce: 2u64,
|
||||
gas_price: 1000000000,
|
||||
gas_limit: 100000u64,
|
||||
to: TransactionKind::Call(
|
||||
hex!("d3e8763675e4c425df46cc3b5c0f6cbdac396046").into(),
|
||||
),
|
||||
value: U256::from(1000000000000000u64),
|
||||
input: Default::default(),
|
||||
}),
|
||||
Signature {
|
||||
odd_y_parity: false,
|
||||
r: U256::from_str(
|
||||
"0xeb96ca19e8a77102767a41fc85a36afd5c61ccb09911cec5d3e86e193d9c5ae",
|
||||
)
|
||||
.unwrap(),
|
||||
s: U256::from_str(
|
||||
"0x3a456401896b1b6055311536bf00a718568c744d8c1f9df59879e8350220ca18",
|
||||
)
|
||||
.unwrap(),
|
||||
},
|
||||
),
|
||||
]
|
||||
.into(),
|
||||
message: PooledTransactions(message),
|
||||
};
|
||||
|
||||
let mut encoded = vec![];
|
||||
|
||||
@ -1504,10 +1504,10 @@ mod test {
|
||||
fn verify_response_hashes() {
|
||||
let input = hex!("02f871018302a90f808504890aef60826b6c94ddf4c5025d1a5742cf12f74eec246d4432c295e487e09c3bbcc12b2b80c080a0f21a4eacd0bf8fea9c5105c543be5a1d8c796516875710fafafdf16d16d8ee23a001280915021bb446d1973501a67f93d2b38894a514b976e7b46dc2fe54598daa");
|
||||
let signed_tx_1: PooledTransactionsElement =
|
||||
TransactionSigned::decode(&mut &input[..]).unwrap().into();
|
||||
TransactionSigned::decode(&mut &input[..]).unwrap().try_into().unwrap();
|
||||
let input = hex!("02f871018302a90f808504890aef60826b6c94ddf4c5025d1a5742cf12f74eec246d4432c295e487e09c3bbcc12b2b80c080a0f21a4eacd0bf8fea9c5105c543be5a1d8c796516875710fafafdf16d16d8ee23a001280915021bb446d1973501a67f93d2b38894a514b976e7b46dc2fe54598d76");
|
||||
let signed_tx_2: PooledTransactionsElement =
|
||||
TransactionSigned::decode(&mut &input[..]).unwrap().into();
|
||||
TransactionSigned::decode(&mut &input[..]).unwrap().try_into().unwrap();
|
||||
|
||||
// only tx 1 is requested
|
||||
let request_hashes = [
|
||||
|
||||
@ -52,3 +52,14 @@ pub enum InvalidTransactionError {
|
||||
#[error("transaction signer has bytecode set")]
|
||||
SignerAccountHasBytecode,
|
||||
}
|
||||
|
||||
/// Represents error variants that can happen when trying to convert a transaction to
|
||||
/// [`PooledTransactionsElement`](crate::PooledTransactionsElement)
|
||||
#[derive(Debug, Clone, Eq, PartialEq, thiserror::Error)]
|
||||
pub enum TransactionConversionError {
|
||||
/// This error variant is used when a transaction cannot be converted into a
|
||||
/// [`PooledTransactionsElement`](crate::PooledTransactionsElement) because it is not supported
|
||||
/// for P2P network.
|
||||
#[error("Transaction is not supported for p2p")]
|
||||
UnsupportedForP2P,
|
||||
}
|
||||
|
||||
@ -18,7 +18,7 @@ pub use eip1559::TxEip1559;
|
||||
pub use eip2930::TxEip2930;
|
||||
pub use eip4844::TxEip4844;
|
||||
|
||||
pub use error::InvalidTransactionError;
|
||||
pub use error::{InvalidTransactionError, TransactionConversionError};
|
||||
pub use legacy::TxLegacy;
|
||||
pub use meta::TransactionMeta;
|
||||
#[cfg(feature = "c-kzg")]
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
#![cfg(feature = "c-kzg")]
|
||||
#![cfg_attr(docsrs, doc(cfg(feature = "c-kzg")))]
|
||||
|
||||
use super::error::TransactionConversionError;
|
||||
use crate::{
|
||||
Address, BlobTransaction, BlobTransactionSidecar, Bytes, Signature, Transaction,
|
||||
TransactionSigned, TransactionSignedEcRecovered, TxEip1559, TxEip2930, TxHash, TxLegacy, B256,
|
||||
@ -49,28 +50,31 @@ pub enum PooledTransactionsElement {
|
||||
},
|
||||
/// A blob transaction, which includes the transaction, blob data, commitments, and proofs.
|
||||
BlobTransaction(BlobTransaction),
|
||||
/// An Optimism deposit transaction
|
||||
#[cfg(feature = "optimism")]
|
||||
Deposit {
|
||||
/// The inner transaction
|
||||
transaction: crate::TxDeposit,
|
||||
/// The signature
|
||||
signature: Signature,
|
||||
/// The hash of the transaction
|
||||
hash: TxHash,
|
||||
},
|
||||
}
|
||||
|
||||
impl PooledTransactionsElement {
|
||||
/// Tries to convert a [TransactionSigned] into a [PooledTransactionsElement].
|
||||
///
|
||||
/// [BlobTransaction] are disallowed from being propagated, hence this returns an error if the
|
||||
/// `tx` is [Transaction::Eip4844]
|
||||
/// This function used as a helper to convert from a decoded p2p broadcast message to
|
||||
/// [PooledTransactionsElement]. Since [BlobTransaction] is disallowed to be broadcasted on
|
||||
/// p2p, return an err if `tx` is [Transaction::Eip4844].
|
||||
pub fn try_from_broadcast(tx: TransactionSigned) -> Result<Self, TransactionSigned> {
|
||||
if tx.is_eip4844() {
|
||||
return Err(tx)
|
||||
match tx {
|
||||
TransactionSigned { transaction: Transaction::Legacy(tx), signature, hash } => {
|
||||
Ok(PooledTransactionsElement::Legacy { transaction: tx, signature, hash })
|
||||
}
|
||||
TransactionSigned { transaction: Transaction::Eip2930(tx), signature, hash } => {
|
||||
Ok(PooledTransactionsElement::Eip2930 { transaction: tx, signature, hash })
|
||||
}
|
||||
TransactionSigned { transaction: Transaction::Eip1559(tx), signature, hash } => {
|
||||
Ok(PooledTransactionsElement::Eip1559 { transaction: tx, signature, hash })
|
||||
}
|
||||
// Not supported because missing blob sidecar
|
||||
tx @ TransactionSigned { transaction: Transaction::Eip4844(_), .. } => Err(tx),
|
||||
#[cfg(feature = "optimism")]
|
||||
// Not supported because deposit transactions are never pooled
|
||||
tx @ TransactionSigned { transaction: Transaction::Deposit(_), .. } => Err(tx),
|
||||
}
|
||||
Ok(tx.into())
|
||||
}
|
||||
|
||||
/// Converts from an EIP-4844 [TransactionSignedEcRecovered] to a
|
||||
@ -107,8 +111,6 @@ impl PooledTransactionsElement {
|
||||
Self::Eip2930 { transaction, .. } => transaction.signature_hash(),
|
||||
Self::Eip1559 { transaction, .. } => transaction.signature_hash(),
|
||||
Self::BlobTransaction(blob_tx) => blob_tx.transaction.signature_hash(),
|
||||
#[cfg(feature = "optimism")]
|
||||
Self::Deposit { .. } => B256::ZERO,
|
||||
}
|
||||
}
|
||||
|
||||
@ -119,8 +121,6 @@ impl PooledTransactionsElement {
|
||||
PooledTransactionsElement::Eip2930 { hash, .. } |
|
||||
PooledTransactionsElement::Eip1559 { hash, .. } => hash,
|
||||
PooledTransactionsElement::BlobTransaction(tx) => &tx.hash,
|
||||
#[cfg(feature = "optimism")]
|
||||
PooledTransactionsElement::Deposit { hash, .. } => hash,
|
||||
}
|
||||
}
|
||||
|
||||
@ -131,10 +131,6 @@ impl PooledTransactionsElement {
|
||||
Self::Eip2930 { signature, .. } |
|
||||
Self::Eip1559 { signature, .. } => signature,
|
||||
Self::BlobTransaction(blob_tx) => &blob_tx.signature,
|
||||
#[cfg(feature = "optimism")]
|
||||
Self::Deposit { .. } => {
|
||||
panic!("Deposit transactions do not have a signature! This is a bug.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -145,8 +141,6 @@ impl PooledTransactionsElement {
|
||||
Self::Eip2930 { transaction, .. } => transaction.nonce,
|
||||
Self::Eip1559 { transaction, .. } => transaction.nonce,
|
||||
Self::BlobTransaction(blob_tx) => blob_tx.transaction.nonce,
|
||||
#[cfg(feature = "optimism")]
|
||||
Self::Deposit { .. } => 0,
|
||||
}
|
||||
}
|
||||
|
||||
@ -250,11 +244,7 @@ impl PooledTransactionsElement {
|
||||
hash: typed_tx.hash,
|
||||
}),
|
||||
#[cfg(feature = "optimism")]
|
||||
Transaction::Deposit(tx) => Ok(PooledTransactionsElement::Deposit {
|
||||
transaction: tx,
|
||||
signature: typed_tx.signature,
|
||||
hash: typed_tx.hash,
|
||||
}),
|
||||
Transaction::Deposit(_) => Err(RlpError::Custom("Optimism deposit transaction cannot be decoded to PooledTransactionsElement"))
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -283,12 +273,6 @@ impl PooledTransactionsElement {
|
||||
hash,
|
||||
},
|
||||
Self::BlobTransaction(blob_tx) => blob_tx.into_parts().0,
|
||||
#[cfg(feature = "optimism")]
|
||||
Self::Deposit { transaction, signature, hash } => TransactionSigned {
|
||||
transaction: Transaction::Deposit(transaction),
|
||||
signature,
|
||||
hash,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@ -311,8 +295,6 @@ impl PooledTransactionsElement {
|
||||
// the encoding does not use a header, so we set `with_header` to false
|
||||
blob_tx.payload_len_with_type(false)
|
||||
}
|
||||
#[cfg(feature = "optimism")]
|
||||
Self::Deposit { transaction, .. } => transaction.payload_len_without_header(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -355,10 +337,6 @@ impl PooledTransactionsElement {
|
||||
// `tx_type || rlp([transaction_payload_body, blobs, commitments, proofs]))`
|
||||
blob_tx.encode_with_type_inner(out, false);
|
||||
}
|
||||
#[cfg(feature = "optimism")]
|
||||
Self::Deposit { transaction, .. } => {
|
||||
transaction.encode(out, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -395,10 +373,6 @@ impl Encodable for PooledTransactionsElement {
|
||||
// `rlp(tx_type || rlp([transaction_payload_body, blobs, commitments, proofs]))`
|
||||
blob_tx.encode_with_type_inner(out, true);
|
||||
}
|
||||
#[cfg(feature = "optimism")]
|
||||
Self::Deposit { transaction, .. } => {
|
||||
transaction.encode(out, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -420,11 +394,6 @@ impl Encodable for PooledTransactionsElement {
|
||||
// the encoding uses a header, so we set `with_header` to true
|
||||
blob_tx.payload_len_with_type(true)
|
||||
}
|
||||
#[cfg(feature = "optimism")]
|
||||
Self::Deposit { transaction, .. } => {
|
||||
// method computes the payload len with a RLP header
|
||||
transaction.payload_len()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -527,47 +496,19 @@ impl Decodable for PooledTransactionsElement {
|
||||
hash: typed_tx.hash,
|
||||
}),
|
||||
#[cfg(feature = "optimism")]
|
||||
Transaction::Deposit(tx) => Ok(PooledTransactionsElement::Deposit {
|
||||
transaction: tx,
|
||||
signature: typed_tx.signature,
|
||||
hash: typed_tx.hash,
|
||||
}),
|
||||
Transaction::Deposit(_) => Err(RlpError::Custom("Optimism deposit transaction cannot be decoded to PooledTransactionsElement"))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<TransactionSigned> for PooledTransactionsElement {
|
||||
/// Converts from a [TransactionSigned] to a [PooledTransactionsElement].
|
||||
///
|
||||
/// NOTE: For EIP-4844 transactions, this will return an empty sidecar.
|
||||
fn from(tx: TransactionSigned) -> Self {
|
||||
let TransactionSigned { transaction, signature, hash } = tx;
|
||||
match transaction {
|
||||
Transaction::Legacy(tx) => {
|
||||
PooledTransactionsElement::Legacy { transaction: tx, signature, hash }
|
||||
}
|
||||
Transaction::Eip2930(tx) => {
|
||||
PooledTransactionsElement::Eip2930 { transaction: tx, signature, hash }
|
||||
}
|
||||
Transaction::Eip1559(tx) => {
|
||||
PooledTransactionsElement::Eip1559 { transaction: tx, signature, hash }
|
||||
}
|
||||
Transaction::Eip4844(tx) => {
|
||||
PooledTransactionsElement::BlobTransaction(BlobTransaction {
|
||||
transaction: tx,
|
||||
signature,
|
||||
hash,
|
||||
// This is empty - just for the conversion!
|
||||
sidecar: Default::default(),
|
||||
})
|
||||
}
|
||||
#[cfg(feature = "optimism")]
|
||||
Transaction::Deposit(tx) => {
|
||||
PooledTransactionsElement::Deposit { transaction: tx, signature, hash }
|
||||
}
|
||||
}
|
||||
impl TryFrom<TransactionSigned> for PooledTransactionsElement {
|
||||
type Error = TransactionConversionError;
|
||||
|
||||
fn try_from(tx: TransactionSigned) -> Result<Self, Self::Error> {
|
||||
PooledTransactionsElement::try_from_broadcast(tx)
|
||||
.map_err(|_| TransactionConversionError::UnsupportedForP2P)
|
||||
}
|
||||
}
|
||||
|
||||
@ -582,43 +523,46 @@ impl<'a> arbitrary::Arbitrary<'a> for PooledTransactionsElement {
|
||||
/// `PooledTransactionsElement`.
|
||||
fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result<Self> {
|
||||
// Attempt to create a `TransactionSigned` with arbitrary data.
|
||||
Ok(match PooledTransactionsElement::from(TransactionSigned::arbitrary(u)?) {
|
||||
// If the generated `PooledTransactionsElement` is a blob transaction...
|
||||
PooledTransactionsElement::BlobTransaction(mut tx) => {
|
||||
// Generate a sidecar for the blob transaction using arbitrary data.
|
||||
let tx_signed = TransactionSigned::arbitrary(u)?;
|
||||
// Attempt to create a `PooledTransactionsElement` with arbitrary data, handling the Result.
|
||||
match PooledTransactionsElement::try_from(tx_signed) {
|
||||
Ok(PooledTransactionsElement::BlobTransaction(mut tx)) => {
|
||||
// Successfully converted to a BlobTransaction, now generate a sidecar.
|
||||
tx.sidecar = crate::BlobTransactionSidecar::arbitrary(u)?;
|
||||
// Return the blob transaction with the generated sidecar.
|
||||
PooledTransactionsElement::BlobTransaction(tx)
|
||||
Ok(PooledTransactionsElement::BlobTransaction(tx))
|
||||
}
|
||||
// If the generated `PooledTransactionsElement` is not a blob transaction...
|
||||
tx => tx,
|
||||
})
|
||||
Ok(tx) => Ok(tx), // Successfully converted, but not a BlobTransaction.
|
||||
Err(_) => Err(arbitrary::Error::IncorrectFormat), /* Conversion failed, return an
|
||||
* arbitrary error. */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(test, feature = "arbitrary"))]
|
||||
impl proptest::arbitrary::Arbitrary for PooledTransactionsElement {
|
||||
type Parameters = ();
|
||||
type Strategy = proptest::strategy::BoxedStrategy<PooledTransactionsElement>;
|
||||
|
||||
fn arbitrary_with(_: Self::Parameters) -> Self::Strategy {
|
||||
use proptest::prelude::{any, Strategy};
|
||||
|
||||
any::<(TransactionSigned, crate::BlobTransactionSidecar)>()
|
||||
.prop_map(move |(transaction, sidecar)| {
|
||||
// this will have an empty sidecar
|
||||
let pooled_txs_element = PooledTransactionsElement::from(transaction);
|
||||
|
||||
// generate a sidecar for blob txs
|
||||
if let PooledTransactionsElement::BlobTransaction(mut tx) = pooled_txs_element {
|
||||
tx.sidecar = sidecar;
|
||||
PooledTransactionsElement::BlobTransaction(tx)
|
||||
} else {
|
||||
pooled_txs_element
|
||||
match PooledTransactionsElement::try_from(transaction) {
|
||||
Ok(PooledTransactionsElement::BlobTransaction(mut tx)) => {
|
||||
tx.sidecar = sidecar;
|
||||
PooledTransactionsElement::BlobTransaction(tx)
|
||||
}
|
||||
Ok(tx) => tx,
|
||||
Err(_) => PooledTransactionsElement::Eip1559 {
|
||||
transaction: Default::default(),
|
||||
signature: Default::default(),
|
||||
hash: Default::default(),
|
||||
}, // Gen an Eip1559 as arbitrary for testing purpose
|
||||
}
|
||||
})
|
||||
.boxed()
|
||||
}
|
||||
|
||||
type Strategy = proptest::strategy::BoxedStrategy<PooledTransactionsElement>;
|
||||
}
|
||||
|
||||
/// A signed pooled transaction with recovered signer.
|
||||
@ -682,9 +626,16 @@ impl PooledTransactionsElementEcRecovered {
|
||||
}
|
||||
|
||||
/// Converts a `TransactionSignedEcRecovered` into a `PooledTransactionsElementEcRecovered`.
|
||||
impl From<TransactionSignedEcRecovered> for PooledTransactionsElementEcRecovered {
|
||||
fn from(tx: TransactionSignedEcRecovered) -> Self {
|
||||
Self { transaction: tx.signed_transaction.into(), signer: tx.signer }
|
||||
impl TryFrom<TransactionSignedEcRecovered> for PooledTransactionsElementEcRecovered {
|
||||
type Error = TransactionConversionError;
|
||||
|
||||
fn try_from(tx: TransactionSignedEcRecovered) -> Result<Self, Self::Error> {
|
||||
match PooledTransactionsElement::try_from(tx.signed_transaction) {
|
||||
Ok(pooled_transaction) => {
|
||||
Ok(Self { transaction: pooled_transaction, signer: tx.signer })
|
||||
}
|
||||
Err(_) => Err(TransactionConversionError::UnsupportedForP2P),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -756,8 +756,10 @@ where
|
||||
let recovered =
|
||||
signed_tx.into_ecrecovered().ok_or(EthApiError::InvalidTransactionSignature)?;
|
||||
|
||||
let pool_transaction =
|
||||
<Pool::Transaction>::from_recovered_pooled_transaction(recovered.into());
|
||||
let pool_transaction = match recovered.try_into() {
|
||||
Ok(converted) => <Pool::Transaction>::from_recovered_pooled_transaction(converted),
|
||||
Err(_) => return Err(EthApiError::TransactionConversionError),
|
||||
};
|
||||
|
||||
// submit the transaction to the pool with a `Local` origin
|
||||
let hash = self.pool().add_transaction(TransactionOrigin::Local, pool_transaction).await?;
|
||||
|
||||
@ -113,6 +113,9 @@ pub enum EthApiError {
|
||||
/// Evm generic purpose error.
|
||||
#[error("Revm error: {0}")]
|
||||
EvmCustom(String),
|
||||
/// Error encountered when converting a transaction type
|
||||
#[error("Transaction conversion error")]
|
||||
TransactionConversionError,
|
||||
}
|
||||
|
||||
/// Eth Optimism Api Error
|
||||
@ -146,7 +149,8 @@ impl From<EthApiError> for ErrorObject<'static> {
|
||||
EthApiError::ConflictingFeeFieldsInRequest |
|
||||
EthApiError::Signing(_) |
|
||||
EthApiError::BothStateAndStateDiffInOverride(_) |
|
||||
EthApiError::InvalidTracerConfig => invalid_params_rpc_err(error.to_string()),
|
||||
EthApiError::InvalidTracerConfig |
|
||||
EthApiError::TransactionConversionError => invalid_params_rpc_err(error.to_string()),
|
||||
EthApiError::InvalidTransaction(err) => err.into(),
|
||||
EthApiError::PoolError(err) => err.into(),
|
||||
EthApiError::PrevrandaoNotSet |
|
||||
|
||||
@ -321,13 +321,23 @@ where
|
||||
let encoded_len = transaction.encoded_length();
|
||||
let tx = transaction.to_recovered_transaction().into_signed();
|
||||
let pooled = if tx.is_eip4844() {
|
||||
// for EIP-4844 transactions, we need to fetch the blob sidecar from the blob store
|
||||
if let Some(blob) = self.get_blob_transaction(tx) {
|
||||
PooledTransactionsElement::BlobTransaction(blob)
|
||||
} else {
|
||||
continue
|
||||
}
|
||||
} else {
|
||||
PooledTransactionsElement::from(tx)
|
||||
match PooledTransactionsElement::try_from(tx) {
|
||||
Ok(element) => element,
|
||||
Err(err) => {
|
||||
debug!(
|
||||
target: "txpool", %err,
|
||||
"failed to convert transaction to pooled element; skipping",
|
||||
);
|
||||
continue
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
size += encoded_len;
|
||||
@ -351,7 +361,7 @@ where
|
||||
if tx.is_eip4844() {
|
||||
self.get_blob_transaction(tx).map(PooledTransactionsElement::BlobTransaction)
|
||||
} else {
|
||||
Some(PooledTransactionsElement::from(tx))
|
||||
PooledTransactionsElement::try_from(tx).ok()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@ -915,6 +915,9 @@ pub enum EthBlobTransactionSidecar {
|
||||
|
||||
impl EthPooledTransaction {
|
||||
/// Create new instance of [Self].
|
||||
///
|
||||
/// Caution: In case of blob transactions, this does marks the blob sidecar as
|
||||
/// [EthBlobTransactionSidecar::Missing]
|
||||
pub fn new(transaction: TransactionSignedEcRecovered, encoded_length: usize) -> Self {
|
||||
let mut blob_sidecar = EthBlobTransactionSidecar::None;
|
||||
let gas_cost = match &transaction.transaction {
|
||||
|
||||
Reference in New Issue
Block a user