feat: use alloy Signature type (#10758)

Co-authored-by: Emilia Hane <elsaemiliaevahane@gmail.com>
This commit is contained in:
Aurélien
2024-09-23 15:29:48 +02:00
committed by GitHub
parent fba837468c
commit 15aee9b144
30 changed files with 537 additions and 709 deletions

View File

@ -115,7 +115,8 @@ mod tests {
use alloy_primitives::{hex, TxKind, U256};
use alloy_rlp::{Decodable, Encodable};
use reth_primitives::{
BlockHashOrNumber, Header, Signature, Transaction, TransactionSigned, TxLegacy,
alloy_primitives::Parity, BlockHashOrNumber, Header, Signature, Transaction,
TransactionSigned, TxLegacy,
};
use std::str::FromStr;
@ -370,12 +371,11 @@ mod tests {
to: TxKind::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(),
}
}), Signature::new(
U256::from_str("0x64b1702d9298fee62dfeccc57d322a463ad55ca201256d01f62b45b2e1c21c12").unwrap(),
U256::from_str("0x64b1702d9298fee62dfeccc57d322a463ad55ca201256d01f62b45b2e1c21c10").unwrap(),
Parity::Parity(false),
),
),
TransactionSigned::from_transaction_and_signature(Transaction::Legacy(TxLegacy {
chain_id: Some(1),
@ -385,11 +385,11 @@ mod tests {
to: TxKind::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(),
},
}), Signature::new(
U256::from_str("0x52f8f61201b2b11a78d6e866abc9c3db2ae8631fa656bfe5cb53668255367afb").unwrap(),
U256::from_str("0x52f8f61201b2b11a78d6e866abc9c3db2ae8631fa656bfe5cb53668255367afb").unwrap(),
Parity::Parity(false),
),
),
],
ommers: vec![
@ -445,11 +445,11 @@ mod tests {
value: U256::from(0x200u64),
input: Default::default(),
}),
Signature {
odd_y_parity: false,
r: U256::from_str("0x64b1702d9298fee62dfeccc57d322a463ad55ca201256d01f62b45b2e1c21c12").unwrap(),
s: U256::from_str("0x64b1702d9298fee62dfeccc57d322a463ad55ca201256d01f62b45b2e1c21c10").unwrap(),
}
Signature::new(
U256::from_str("0x64b1702d9298fee62dfeccc57d322a463ad55ca201256d01f62b45b2e1c21c12").unwrap(),
U256::from_str("0x64b1702d9298fee62dfeccc57d322a463ad55ca201256d01f62b45b2e1c21c10").unwrap(),
Parity::Eip155(37),
),
),
TransactionSigned::from_transaction_and_signature(
Transaction::Legacy(TxLegacy {
@ -461,11 +461,11 @@ mod tests {
value: U256::from(0x2d9u64),
input: Default::default(),
}),
Signature {
odd_y_parity: false,
r: U256::from_str("0x52f8f61201b2b11a78d6e866abc9c3db2ae8631fa656bfe5cb53668255367afb").unwrap(),
s: U256::from_str("0x52f8f61201b2b11a78d6e866abc9c3db2ae8631fa656bfe5cb53668255367afb").unwrap(),
}
Signature::new(
U256::from_str("0x52f8f61201b2b11a78d6e866abc9c3db2ae8631fa656bfe5cb53668255367afb").unwrap(),
U256::from_str("0x52f8f61201b2b11a78d6e866abc9c3db2ae8631fa656bfe5cb53668255367afb").unwrap(),
Parity::Eip155(37),
),
),
],
ommers: vec![

View File

@ -81,7 +81,8 @@ mod tests {
use alloy_rlp::{Decodable, Encodable};
use reth_chainspec::MIN_TRANSACTION_GAS;
use reth_primitives::{
PooledTransactionsElement, Signature, Transaction, TransactionSigned, TxEip1559, TxLegacy,
alloy_primitives::Parity, PooledTransactionsElement, Signature, Transaction,
TransactionSigned, TxEip1559, TxLegacy,
};
use std::str::FromStr;
@ -134,17 +135,17 @@ mod tests {
value: U256::from(0x200u64),
input: Default::default(),
}),
Signature {
odd_y_parity: false,
r: U256::from_str(
Signature::new(
U256::from_str(
"0x64b1702d9298fee62dfeccc57d322a463ad55ca201256d01f62b45b2e1c21c12",
)
.unwrap(),
s: U256::from_str(
U256::from_str(
"0x64b1702d9298fee62dfeccc57d322a463ad55ca201256d01f62b45b2e1c21c10",
)
.unwrap(),
},
Parity::Parity(false),
),
),
TransactionSigned::from_transaction_and_signature(
Transaction::Legacy(TxLegacy {
@ -156,17 +157,17 @@ mod tests {
value: U256::from(0x2d9u64),
input: Default::default(),
}),
Signature {
odd_y_parity: false,
r: U256::from_str(
Signature::new(
U256::from_str(
"0x52f8f61201b2b11a78d6e866abc9c3db2ae8631fa656bfe5cb53668255367afb",
)
.unwrap(),
s: U256::from_str(
U256::from_str(
"0x52f8f61201b2b11a78d6e866abc9c3db2ae8631fa656bfe5cb53668255367afb",
)
.unwrap(),
},
Parity::Parity(false),
),
),
];
let message: Vec<PooledTransactionsElement> = txs
@ -200,17 +201,17 @@ mod tests {
value: U256::from(0x200u64),
input: Default::default(),
}),
Signature {
odd_y_parity: false,
r: U256::from_str(
Signature::new(
U256::from_str(
"0x64b1702d9298fee62dfeccc57d322a463ad55ca201256d01f62b45b2e1c21c12",
)
.unwrap(),
s: U256::from_str(
U256::from_str(
"0x64b1702d9298fee62dfeccc57d322a463ad55ca201256d01f62b45b2e1c21c10",
)
.unwrap(),
},
Parity::Eip155(37),
),
),
TransactionSigned::from_transaction_and_signature(
Transaction::Legacy(TxLegacy {
@ -222,17 +223,17 @@ mod tests {
value: U256::from(0x2d9u64),
input: Default::default(),
}),
Signature {
odd_y_parity: false,
r: U256::from_str(
Signature::new(
U256::from_str(
"0x52f8f61201b2b11a78d6e866abc9c3db2ae8631fa656bfe5cb53668255367afb",
)
.unwrap(),
s: U256::from_str(
U256::from_str(
"0x52f8f61201b2b11a78d6e866abc9c3db2ae8631fa656bfe5cb53668255367afb",
)
.unwrap(),
},
Parity::Eip155(37),
),
),
];
let message: Vec<PooledTransactionsElement> = txs
@ -267,17 +268,17 @@ mod tests {
value: U256::from(1234u64),
input: Default::default(),
}),
Signature {
odd_y_parity: true,
r: U256::from_str(
Signature::new(
U256::from_str(
"0x35b7bfeb9ad9ece2cbafaaf8e202e706b4cfaeb233f46198f00b44d4a566a981",
)
.unwrap(),
s: U256::from_str(
U256::from_str(
"0x612638fb29427ca33b9a3be2a0a561beecfe0269655be160d35e72d366a6a860",
)
.unwrap(),
},
Parity::Eip155(44),
),
),
TransactionSigned::from_transaction_and_signature(
Transaction::Eip1559(TxEip1559 {
@ -291,17 +292,17 @@ mod tests {
input: Default::default(),
access_list: Default::default(),
}),
Signature {
odd_y_parity: true,
r: U256::from_str(
Signature::new(
U256::from_str(
"0x59e6b67f48fb32e7e570dfb11e042b5ad2e55e3ce3ce9cd989c7e06e07feeafd",
)
.unwrap(),
s: U256::from_str(
U256::from_str(
"0x016b83f4f980694ed2eee4d10667242b1f40dc406901b34125b008d334d47469",
)
.unwrap(),
},
Parity::Parity(true),
),
),
TransactionSigned::from_transaction_and_signature(
Transaction::Legacy(TxLegacy {
@ -313,17 +314,17 @@ mod tests {
value: U256::from(1000000000000000u64),
input: Default::default(),
}),
Signature {
odd_y_parity: false,
r: U256::from_str(
Signature::new(
U256::from_str(
"0xce6834447c0a4193c40382e6c57ae33b241379c5418caac9cdc18d786fd12071",
)
.unwrap(),
s: U256::from_str(
U256::from_str(
"0x3ca3ae86580e94550d7c071e3a02eadb5a77830947c9225165cf9100901bee88",
)
.unwrap(),
},
Parity::Eip155(43),
),
),
TransactionSigned::from_transaction_and_signature(
Transaction::Legacy(TxLegacy {
@ -335,17 +336,17 @@ mod tests {
value: U256::from(693361000000000u64),
input: Default::default(),
}),
Signature {
odd_y_parity: false,
r: U256::from_str(
Signature::new(
U256::from_str(
"0xe24d8bd32ad906d6f8b8d7741e08d1959df021698b19ee232feba15361587d0a",
)
.unwrap(),
s: U256::from_str(
U256::from_str(
"0x5406ad177223213df262cb66ccbb2f46bfdccfdfbbb5ffdda9e2c02d977631da",
)
.unwrap(),
},
Parity::Eip155(43),
),
),
TransactionSigned::from_transaction_and_signature(
Transaction::Legacy(TxLegacy {
@ -357,17 +358,17 @@ mod tests {
value: U256::from(1000000000000000u64),
input: Default::default(),
}),
Signature {
odd_y_parity: false,
r: U256::from_str(
Signature::new(
U256::from_str(
"0xeb96ca19e8a77102767a41fc85a36afd5c61ccb09911cec5d3e86e193d9c5ae",
)
.unwrap(),
s: U256::from_str(
U256::from_str(
"0x3a456401896b1b6055311536bf00a718568c744d8c1f9df59879e8350220ca18",
)
.unwrap(),
},
Parity::Eip155(43),
),
),
];
let message: Vec<PooledTransactionsElement> = txs
@ -406,17 +407,17 @@ mod tests {
value: U256::from(1234u64),
input: Default::default(),
}),
Signature {
odd_y_parity: true,
r: U256::from_str(
Signature::new(
U256::from_str(
"0x35b7bfeb9ad9ece2cbafaaf8e202e706b4cfaeb233f46198f00b44d4a566a981",
)
.unwrap(),
s: U256::from_str(
U256::from_str(
"0x612638fb29427ca33b9a3be2a0a561beecfe0269655be160d35e72d366a6a860",
)
.unwrap(),
},
Parity::Parity(true),
),
),
TransactionSigned::from_transaction_and_signature(
Transaction::Eip1559(TxEip1559 {
@ -430,17 +431,17 @@ mod tests {
input: Default::default(),
access_list: Default::default(),
}),
Signature {
odd_y_parity: true,
r: U256::from_str(
Signature::new(
U256::from_str(
"0x59e6b67f48fb32e7e570dfb11e042b5ad2e55e3ce3ce9cd989c7e06e07feeafd",
)
.unwrap(),
s: U256::from_str(
U256::from_str(
"0x016b83f4f980694ed2eee4d10667242b1f40dc406901b34125b008d334d47469",
)
.unwrap(),
},
Parity::Parity(true),
),
),
TransactionSigned::from_transaction_and_signature(
Transaction::Legacy(TxLegacy {
@ -452,17 +453,17 @@ mod tests {
value: U256::from(1000000000000000u64),
input: Default::default(),
}),
Signature {
odd_y_parity: false,
r: U256::from_str(
Signature::new(
U256::from_str(
"0xce6834447c0a4193c40382e6c57ae33b241379c5418caac9cdc18d786fd12071",
)
.unwrap(),
s: U256::from_str(
U256::from_str(
"0x3ca3ae86580e94550d7c071e3a02eadb5a77830947c9225165cf9100901bee88",
)
.unwrap(),
},
Parity::Parity(false),
),
),
TransactionSigned::from_transaction_and_signature(
Transaction::Legacy(TxLegacy {
@ -474,17 +475,17 @@ mod tests {
value: U256::from(693361000000000u64),
input: Default::default(),
}),
Signature {
odd_y_parity: false,
r: U256::from_str(
Signature::new(
U256::from_str(
"0xe24d8bd32ad906d6f8b8d7741e08d1959df021698b19ee232feba15361587d0a",
)
.unwrap(),
s: U256::from_str(
U256::from_str(
"0x5406ad177223213df262cb66ccbb2f46bfdccfdfbbb5ffdda9e2c02d977631da",
)
.unwrap(),
},
Parity::Parity(false),
),
),
TransactionSigned::from_transaction_and_signature(
Transaction::Legacy(TxLegacy {
@ -496,17 +497,17 @@ mod tests {
value: U256::from(1000000000000000u64),
input: Default::default(),
}),
Signature {
odd_y_parity: false,
r: U256::from_str(
Signature::new(
U256::from_str(
"0xeb96ca19e8a77102767a41fc85a36afd5c61ccb09911cec5d3e86e193d9c5ae",
)
.unwrap(),
s: U256::from_str(
U256::from_str(
"0x3a456401896b1b6055311536bf00a718568c744d8c1f9df59879e8350220ca18",
)
.unwrap(),
},
Parity::Parity(false),
),
),
];
let message: Vec<PooledTransactionsElement> = txs

View File

@ -133,7 +133,7 @@ impl From<EthVersion> for &'static str {
/// RLPx `p2p` protocol version
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))]
#[add_arbitrary_tests(rlp)]
pub enum ProtocolVersion {
/// `p2p` version 4

View File

@ -28,7 +28,7 @@ async fn test_large_tx_req() {
let ts = TransactionSigned {
hash: Default::default(),
signature: Signature::default(),
signature: Signature::test_signature(),
transaction: tx.clone().into(),
};
tx.set_hash(ts.recalculate_hash());

View File

@ -16,7 +16,8 @@ use reth_network_p2p::{
headers::client::{HeadersClient, HeadersRequest},
};
use reth_primitives::{
Block, BlockBody, Header, Signature, Transaction, TransactionSigned, TxEip2930,
alloy_primitives::Parity, Block, BlockBody, Header, Signature, Transaction, TransactionSigned,
TxEip2930,
};
use reth_provider::test_utils::MockEthProvider;
@ -32,7 +33,7 @@ pub fn rng_transaction(rng: &mut impl rand::RngCore) -> TransactionSigned {
input: Bytes::from(vec![1, 2]),
access_list: Default::default(),
});
let signature = Signature { odd_y_parity: true, r: U256::default(), s: U256::default() };
let signature = Signature::new(U256::default(), U256::default(), Parity::Parity(true));
TransactionSigned::from_transaction_and_signature(request, signature)
}

View File

@ -7,7 +7,7 @@ use futures::StreamExt;
use rand::thread_rng;
use reth_network::{test_utils::Testnet, NetworkEvent, NetworkEventListenerProvider};
use reth_network_api::PeersInfo;
use reth_primitives::{TransactionSigned, TxLegacy};
use reth_primitives::{Signature, TransactionSigned, TxLegacy};
use reth_provider::test_utils::{ExtendedAccount, MockEthProvider};
use reth_transaction_pool::{test_utils::TransactionGenerator, PoolTransaction, TransactionPool};
@ -131,7 +131,10 @@ async fn test_sending_invalid_transactions() {
value: Default::default(),
input: Default::default(),
};
let tx = TransactionSigned::from_transaction_and_signature(tx.into(), Default::default());
let tx = TransactionSigned::from_transaction_and_signature(
tx.into(),
Signature::test_signature(),
);
peer0.network().send_transactions(*peer1.peer_id(), vec![Arc::new(tx)]);
}