fuel_core_compression/
config.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
use core::time::Duration;

use fuel_core_types::tai64::{
    Tai64,
    Tai64N,
};

#[derive(Debug, Clone, Copy)]
pub struct Config {
    /// How long entries in the temporal registry are valid.
    /// After this time has passed, the entry is considered stale and must not be used.
    /// If the value is needed again, it must be re-registered.
    pub temporal_registry_retention: Duration,
}

impl Config {
    /// Given timestamp of the current block and a key in an older block,
    /// is the key is still accessible?
    /// Returns error if the arguments are not valid block timestamps,
    /// or if the block is older than the key.
    pub fn is_timestamp_accessible(
        &self,
        block_timestamp: Tai64,
        key_timestamp: Tai64,
    ) -> anyhow::Result<bool> {
        let block = Tai64N(block_timestamp, 0);
        let key = Tai64N(key_timestamp, 0);
        let duration = block
            .duration_since(&key)
            .map_err(|_| anyhow::anyhow!("Invalid timestamp ordering"))?;
        Ok(duration <= self.temporal_registry_retention)
    }
}