diff --git a/prdoc/pr_5978.prdoc b/prdoc/pr_5978.prdoc index 14957ea5eff31c1d73799001d5e1901f9e3ebc58..9b545c20d664d1893d3ef654e53152c17de787df 100644 --- a/prdoc/pr_5978.prdoc +++ b/prdoc/pr_5978.prdoc @@ -1,7 +1,7 @@ title: `networking::TransactionPool` should accept `Arc` doc: - audience: Node Dev - description: The TransactionPool trait now accepts an `Arc` for transactions. + description: The `sc_network_transactions::config::TransactionPool` trait now accepts an `Arc` for transactions. crates: - name: sc-network-transactions bump: minor diff --git a/substrate/client/network/transactions/src/config.rs b/substrate/client/network/transactions/src/config.rs index e3b80ab7bc9da57999fe4680df8ddce5e2956edf..42a335d7041ad14363a82863238ee86f44b6e3f5 100644 --- a/substrate/client/network/transactions/src/config.rs +++ b/substrate/client/network/transactions/src/config.rs @@ -67,7 +67,7 @@ pub trait TransactionPool<H: ExHashT, B: BlockT>: Send + Sync { /// Notify the pool about transactions broadcast. fn on_broadcasted(&self, propagations: HashMap<H, Vec<String>>); /// Get transaction by hash. - fn transaction(&self, hash: &H) -> Option<B::Extrinsic>; + fn transaction(&self, hash: &H) -> Option<Arc<B::Extrinsic>>; } /// Dummy implementation of the [`TransactionPool`] trait for a transaction pool that is always @@ -93,7 +93,7 @@ impl<H: ExHashT + Default, B: BlockT> TransactionPool<H, B> for EmptyTransaction fn on_broadcasted(&self, _: HashMap<H, Vec<String>>) {} - fn transaction(&self, _h: &H) -> Option<B::Extrinsic> { + fn transaction(&self, _h: &H) -> Option<Arc<B::Extrinsic>> { None } } diff --git a/substrate/client/network/transactions/src/lib.rs b/substrate/client/network/transactions/src/lib.rs index f86ece0cfb0bb52424a6196b89ffc9e7c9455199..ae74effc1485ee4dd26796c4bf1b04e74e9e77bd 100644 --- a/substrate/client/network/transactions/src/lib.rs +++ b/substrate/client/network/transactions/src/lib.rs @@ -472,7 +472,7 @@ where debug!(target: LOG_TARGET, "Propagating transaction [{:?}]", hash); if let Some(transaction) = self.transaction_pool.transaction(hash) { let propagated_to = - self.do_propagate_transactions(&[(hash.clone(), Arc::new(transaction))]); + self.do_propagate_transactions(&[(hash.clone(), transaction)]); self.transaction_pool.on_broadcasted(propagated_to); } else { debug!(target: "sync", "Propagating transaction failure [{:?}]", hash); diff --git a/substrate/client/service/src/lib.rs b/substrate/client/service/src/lib.rs index 62f9dbba73d9b445ebeeb86d28fc671b77e53bc0..e631646a7b8487224989f4dbfb3461aef6db0f3a 100644 --- a/substrate/client/service/src/lib.rs +++ b/substrate/client/service/src/lib.rs @@ -559,10 +559,10 @@ where self.pool.on_broadcasted(propagations) } - fn transaction(&self, hash: &H) -> Option<B::Extrinsic> { + fn transaction(&self, hash: &H) -> Option<Arc<B::Extrinsic>> { self.pool.ready_transaction(hash).and_then( // Only propagable transactions should be resolved for network service. - |tx| if tx.is_propagable() { Some((**tx.data()).clone()) } else { None }, + |tx| if tx.is_propagable() { Some(Arc::new((**tx.data()).clone())) } else { None }, ) } }