diff --git a/crates/transaction-pool/src/identifier.rs b/crates/transaction-pool/src/identifier.rs index 9b28d3789c..2abbe0b589 100644 --- a/crates/transaction-pool/src/identifier.rs +++ b/crates/transaction-pool/src/identifier.rs @@ -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, + ) -> Vec { + 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; diff --git a/crates/transaction-pool/src/pool/mod.rs b/crates/transaction-pool/src/pool/mod.rs index 29a4ff8beb..968177a8ea 100644 --- a/crates/transaction-pool/src/pool/mod.rs +++ b/crates/transaction-pool/src/pool/mod.rs @@ -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) -> Vec { + self.identifiers.write().sender_ids_or_create(addrs) + } + /// Returns all senders in the pool pub fn unique_senders(&self) -> HashSet
{ 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)?;