fuel_core_compression/
config.rs

1use core::time::Duration;
2
3use fuel_core_types::tai64::{
4    Tai64,
5    Tai64N,
6};
7
8#[derive(Debug, Clone, Copy)]
9pub struct Config {
10    /// How long entries in the temporal registry are valid.
11    /// After this time has passed, the entry is considered stale and must not be used.
12    /// If the value is needed again, it must be re-registered.
13    pub temporal_registry_retention: Duration,
14}
15
16impl Config {
17    /// Given timestamp of the current block and a key in an older block,
18    /// is the key is still accessible?
19    /// Returns error if the arguments are not valid block timestamps,
20    /// or if the block is older than the key.
21    pub fn is_timestamp_accessible(
22        &self,
23        block_timestamp: Tai64,
24        key_timestamp: Tai64,
25    ) -> anyhow::Result<bool> {
26        let block = Tai64N(block_timestamp, 0);
27        let key = Tai64N(key_timestamp, 0);
28        let duration = block
29            .duration_since(&key)
30            .map_err(|_| anyhow::anyhow!("Invalid timestamp ordering"))?;
31        Ok(duration <= self.temporal_registry_retention)
32    }
33}