diff --git a/substrate/client/api/src/client.rs b/substrate/client/api/src/client.rs index 2de09840e4df..a683326bbbe7 100644 --- a/substrate/client/api/src/client.rs +++ b/substrate/client/api/src/client.rs @@ -410,7 +410,7 @@ impl TryFrom> for ChainEvent { if n.is_new_best { Ok(Self::NewBestBlock { hash: n.hash, tree_route: n.tree_route }) } else { - Err(()) + Ok(Self::NewBlock { hash: n.hash }) } } } diff --git a/substrate/client/transaction-pool/api/src/lib.rs b/substrate/client/transaction-pool/api/src/lib.rs index d5370bdf5fef..1e6213431bd0 100644 --- a/substrate/client/transaction-pool/api/src/lib.rs +++ b/substrate/client/transaction-pool/api/src/lib.rs @@ -350,6 +350,11 @@ impl ReadyTransactions for std::iter::Empty { /// Events that the transaction pool listens for. #[derive(Debug)] pub enum ChainEvent { + /// New block have been added to the chain. + NewBlock { + /// Hash of the block. + hash: B::Hash, + }, /// New best block have been added to the chain. NewBestBlock { /// Hash of the block. @@ -372,7 +377,9 @@ impl ChainEvent { /// Returns the block hash associated to the event. pub fn hash(&self) -> B::Hash { match self { - Self::NewBestBlock { hash, .. } | Self::Finalized { hash, .. } => *hash, + Self::NewBlock { hash, .. } | + Self::NewBestBlock { hash, .. } | + Self::Finalized { hash, .. } => *hash, } } diff --git a/substrate/client/transaction-pool/src/common/enactment_state.rs b/substrate/client/transaction-pool/src/common/enactment_state.rs index 85c572c127e8..1612b32d0911 100644 --- a/substrate/client/transaction-pool/src/common/enactment_state.rs +++ b/substrate/client/transaction-pool/src/common/enactment_state.rs @@ -177,7 +177,8 @@ where /// fallback when tree_route cannot be computed. pub fn force_update(&mut self, event: &ChainEvent) { match event { - ChainEvent::NewBestBlock { hash, .. } => self.recent_best_block = *hash, + ChainEvent::NewBlock { hash, .. } | ChainEvent::NewBestBlock { hash, .. } => + self.recent_best_block = *hash, ChainEvent::Finalized { hash, .. } => self.recent_finalized_block = *hash, }; log::debug!( diff --git a/substrate/client/transaction-pool/src/fork_aware_txpool/fork_aware_txpool.rs b/substrate/client/transaction-pool/src/fork_aware_txpool/fork_aware_txpool.rs index 2e4e2ef963a7..431a0e2534c2 100644 --- a/substrate/client/transaction-pool/src/fork_aware_txpool/fork_aware_txpool.rs +++ b/substrate/client/transaction-pool/src/fork_aware_txpool/fork_aware_txpool.rs @@ -1124,7 +1124,7 @@ where }; match event { - ChainEvent::NewBestBlock { .. } => {}, + ChainEvent::NewBestBlock { .. } | ChainEvent::NewBlock { .. }=> {}, ChainEvent::Finalized { hash, ref tree_route } => { self.handle_finalized(hash, tree_route).await; diff --git a/substrate/client/transaction-pool/src/single_state_txpool/single_state_txpool.rs b/substrate/client/transaction-pool/src/single_state_txpool/single_state_txpool.rs index cf7a55897fd4..19d9d2d0321d 100644 --- a/substrate/client/transaction-pool/src/single_state_txpool/single_state_txpool.rs +++ b/substrate/client/transaction-pool/src/single_state_txpool/single_state_txpool.rs @@ -718,6 +718,10 @@ where PoolApi: 'static + graph::ChainApi, { async fn maintain(&self, event: ChainEvent) { + if matches!(event, ChainEvent::NewBlock{..}) { + return + } + let prev_finalized_block = self.enactment_state.lock().recent_finalized_block(); let compute_tree_route = |from, to| -> Result, String> { match self.api.tree_route(from, to) {