perf: batch create sender ids (#16134)

This commit is contained in:
Matthias Seitz
2025-05-12 13:11:07 +02:00
committed by GitHub
parent 6250f65120
commit a12a296eba
2 changed files with 14 additions and 2 deletions

View File

@@ -38,6 +38,14 @@ impl SenderIdentifiers {
})
}
/// Returns the existing [`SenderId`] or assigns a new one if it's missing
pub fn sender_ids_or_create(
&mut self,
addrs: impl IntoIterator<Item = Address>,
) -> Vec<SenderId> {
addrs.into_iter().filter_map(|addr| self.sender_id(&addr)).collect()
}
/// Returns the current identifier and increments the counter.
fn next_id(&mut self) -> SenderId {
let id = self.id;

View File

@@ -201,6 +201,11 @@ where
self.identifiers.write().sender_id_or_create(addr)
}
/// Returns the internal [`SenderId`]s for the given addresses.
pub fn get_sender_ids(&self, addrs: impl IntoIterator<Item = Address>) -> Vec<SenderId> {
self.identifiers.write().sender_ids_or_create(addrs)
}
/// Returns all senders in the pool
pub fn unique_senders(&self) -> HashSet<Address> {
self.get_pool_data().unique_senders()
@@ -463,8 +468,7 @@ where
propagate,
timestamp: Instant::now(),
origin,
authority_ids: authorities
.map(|auths| auths.iter().map(|auth| self.get_sender_id(*auth)).collect()),
authority_ids: authorities.map(|auths| self.get_sender_ids(auths)),
};
let added = pool.add_transaction(tx, balance, state_nonce, bytecode_hash)?;