Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions client/transaction-pool/src/enactment_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,16 @@ where

Ok(Some(tree_route))
}

/// Forces update of the state according to the given `ChainEvent`. Intended to be used as a
/// fallback when tree_route cannot be computed.
pub fn force_update(&mut self, event: &ChainEvent<Block>) {
match event {
ChainEvent::NewBestBlock { hash, .. } => self.recent_best_block = *hash,
ChainEvent::Finalized { hash, .. } => self.recent_finalized_block = *hash,
};
log::debug!(target: "txpool", "forced update: {:?}, {:?}", self.recent_best_block, self.recent_finalized_block);
}
}

#[cfg(test)]
Expand Down Expand Up @@ -576,4 +586,22 @@ mod enactment_state_tests {
assert_eq!(result, false);
assert_es_eq(&es, e1(), d1());
}

#[test]
fn test_enactment_forced_update_best_block() {
sp_tracing::try_init_simple();
let mut es = EnactmentState::new(a().hash, a().hash);

es.force_update(&ChainEvent::NewBestBlock { hash: b1().hash, tree_route: None });
assert_es_eq(&es, b1(), a());
}

#[test]
fn test_enactment_forced_update_finalize() {
sp_tracing::try_init_simple();
let mut es = EnactmentState::new(a().hash, a().hash);

es.force_update(&ChainEvent::Finalized { hash: b1().hash, tree_route: Arc::from([]) });
assert_es_eq(&es, a(), b1());
}
}
4 changes: 2 additions & 2 deletions client/transaction-pool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -748,8 +748,8 @@ where

match result {
Err(msg) => {
log::warn!(target: "txpool", "{msg}");
return
log::debug!(target: "txpool", "{msg}");
self.enactment_state.lock().force_update(&event);
},
Ok(None) => {},
Ok(Some(tree_route)) => {
Expand Down