optimise TransactionFetcher (#6012)

Co-authored-by: zerosnacks <95942363+zerosnacks@users.noreply.github.com>
This commit is contained in:
Emilia Hane
2024-01-19 00:37:14 +01:00
committed by GitHub
parent 9300e53927
commit 8349cb3205
8 changed files with 1169 additions and 261 deletions

View File

@@ -144,6 +144,14 @@ impl NewPooledTransactionHashes {
}
}
/// Returns a mutable reference to transaction hashes.
pub fn hashes_mut(&mut self) -> &mut Vec<B256> {
match self {
NewPooledTransactionHashes::Eth66(msg) => &mut msg.0,
NewPooledTransactionHashes::Eth68(msg) => &mut msg.hashes,
}
}
/// Consumes the type and returns all hashes
pub fn into_hashes(self) -> Vec<B256> {
match self {
@@ -188,6 +196,15 @@ impl NewPooledTransactionHashes {
NewPooledTransactionHashes::Eth68(msg) => msg.hashes.len(),
}
}
/// Returns an iterator over tx hashes zipped with corresponding eth68 metadata if this is
/// an eth68 message.
pub fn as_eth68(&self) -> Option<&NewPooledTransactionHashes68> {
match self {
NewPooledTransactionHashes::Eth66(_) => None,
NewPooledTransactionHashes::Eth68(msg) => Some(msg),
}
}
}
impl From<NewPooledTransactionHashes> for EthMessage {
@@ -265,6 +282,13 @@ pub struct NewPooledTransactionHashes68 {
pub hashes: Vec<B256>,
}
impl NewPooledTransactionHashes68 {
/// Returns an iterator over tx hashes zipped with corresponding metadata.
pub fn metadata_iter(&self) -> impl Iterator<Item = (&B256, (u8, usize))> {
self.hashes.iter().zip(self.types.iter().copied().zip(self.sizes.iter().copied()))
}
}
impl Encodable for NewPooledTransactionHashes68 {
fn encode(&self, out: &mut dyn bytes::BufMut) {
#[derive(RlpEncodable)]