Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
txpool: enactment state forced update (#12632)
Browse files Browse the repository at this point in the history
* txpool: enactment state forced update

When `tree_route` computation fails, we still need to update the
`enactment_state` to be aligned with last known finalized/best block.

We do not execute enactment phase of maintain procedure, but we do
update the state.

* error -> debug

* test added
  • Loading branch information
michalkucharczyk authored and coderobe committed Nov 8, 2022
1 parent 051e8a4 commit 1795966
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
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 @@ -746,8 +746,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

0 comments on commit 1795966

Please sign in to comment.