ckb_verification/
cache.rs1use ckb_script::TransactionState;
4use ckb_types::{
5 core::{Capacity, Cycle, EntryCompleted},
6 packed::Byte32,
7};
8use std::sync::Arc;
9
10pub type TxVerificationCache = lru::LruCache<Byte32, CacheEntry>;
12
13const CACHE_SIZE: usize = 1000 * 30;
14
15pub fn init_cache() -> TxVerificationCache {
17 lru::LruCache::new(CACHE_SIZE)
18}
19
20pub type CacheEntry = Completed;
22
23#[derive(Clone, Debug)]
25pub struct Suspended {
26 pub fee: Capacity,
28 pub state: Arc<TransactionState>,
30}
31
32#[derive(Clone, Copy, Debug, PartialEq, Eq)]
34pub struct Completed {
35 pub cycles: Cycle,
37 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}