ckb_verification/
cache.rs

1//! TX verification cache
2
3use ckb_script::TransactionState;
4use ckb_types::{
5    core::{Capacity, Cycle, EntryCompleted},
6    packed::Byte32,
7};
8use std::sync::Arc;
9
10/// TX verification lru cache
11pub type TxVerificationCache = lru::LruCache<Byte32, CacheEntry>;
12
13const CACHE_SIZE: usize = 1000 * 30;
14
15/// Initialize cache
16pub fn init_cache() -> TxVerificationCache {
17    lru::LruCache::new(CACHE_SIZE)
18}
19
20/// TX verification lru entry
21pub type CacheEntry = Completed;
22
23/// Suspended state
24#[derive(Clone, Debug)]
25pub struct Suspended {
26    /// Cached tx fee
27    pub fee: Capacity,
28    /// State
29    pub state: Arc<TransactionState>,
30}
31
32/// Completed entry
33#[derive(Clone, Copy, Debug, PartialEq, Eq)]
34pub struct Completed {
35    /// Cached tx cycles
36    pub cycles: Cycle,
37    /// Cached tx fee
38    pub fee: Capacity,
39}
40
41impl From<Completed> for EntryCompleted {
42    fn from(value: Completed) -> Self {
43        EntryCompleted {
44            cycles: value.cycles,
45            fee: value.fee,
46        }
47    }
48}