cuprate-hinto-janai/consensus/src/context/tokens.rs
Boog900 889e15738b
Cleanup & Document consensus (#65)
* change monero-consensus to cuprate-consensus-rules

* document the context service

* remove the mutex on blockchain context

* comment the context caches

* add back tokio

* document block checks

* typo

* keep tha amount of outputs with a certain amount in the output cache

* typo

* nuke cross-block batch verification

* remove RPC scanner

* change how contextual data is got.

* fmt & clippy fixes

* typo

* cargo update

* restore Cargo.lock

* add a verify tx test.
+ fixes an issue with verifying signatures after BPs

* clippy

* remove bad test

* add mores tests and fix a couple bugs

* typos

* move tests and add some more

* typo

* remove scan_chain docs

* fix check for duplicate txs when duplicates are not sequential

* add a proptest for dup txs

* cache tx verification state

* doc updates + move `Vec` to `Arc<[]>`

* clippy

* misc changes

* Apply suggestions from code review

Co-authored-by: hinto-janai <hinto.janai@protonmail.com>
Co-authored-by: SyntheticBird <118022351+SyntheticBird45@users.noreply.github.com>

* fix fmt

* review changes

---------

Co-authored-by: hinto-janai <hinto.janai@protonmail.com>
Co-authored-by: SyntheticBird <118022351+SyntheticBird45@users.noreply.github.com>
2024-05-31 01:52:12 +01:00

33 lines
772 B
Rust

//! Tokens
//!
//! This module contains tokens which keep track of the validity of certain data.
//! Currently, there is 1 token:
//! - [`ValidityToken`]
//!
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 {
/// Creates a new [`ValidityToken`]
pub fn new() -> ValidityToken {
ValidityToken {
token: CancellationToken::new(),
}
}
/// Returns `true` if the data is still valid.
pub fn is_data_valid(&self) -> bool {
!self.token.is_cancelled()
}
/// Sets the data to invalid.
pub fn set_data_invalid(self) {
self.token.cancel()
}
}