cuprate/consensus/src/context/tokens.rs
Boog900 fc7b676f7b
consensus: add a tx pool trait.
This means we don't have to rely on people giving the verifier the correct txs for a block.

Also allows some speedup as we can put the fetching of outputs on a different task.
2023-11-05 18:44:41 +00:00

45 lines
942 B
Rust

use tokio_util::sync::CancellationToken;
/// A token representing if a piece of data is valid.
#[derive(Debug, Clone, Default)]
pub struct ValidityToken {
token: CancellationToken,
}
impl ValidityToken {
pub fn new() -> ValidityToken {
ValidityToken {
token: CancellationToken::new(),
}
}
pub fn is_data_valid(&self) -> bool {
!self.token.is_cancelled()
}
pub fn set_data_invalid(self) {
self.token.cancel()
}
}
/// A token representing if a re-org has happened since it's creation.
#[derive(Debug, Clone, Default)]
pub struct ReOrgToken {
token: CancellationToken,
}
impl ReOrgToken {
pub fn new() -> ReOrgToken {
ReOrgToken {
token: CancellationToken::new(),
}
}
pub fn reorg_happened(&self) -> bool {
self.token.is_cancelled()
}
pub fn set_reorg_happened(self) {
self.token.cancel()
}
}