use std::{
collections::HashSet,
fmt::Debug,
hash::Hash,
time::SystemTime,
};
use crate::{
error::{
Error,
InputValidationErrorType,
},
extracted_outputs::ExtractedOutputs,
ports::TxPoolPersistentStorage,
spent_inputs::SpentInputs,
};
use fuel_core_types::services::txpool::{
ArcPoolTx,
PoolTransaction,
};
pub mod checked_collision;
pub mod graph;
#[derive(Debug, Clone)]
pub struct StorageData {
pub transaction: ArcPoolTx,
pub dependents_cumulative_tip: u64,
pub dependents_cumulative_gas: u64,
pub dependents_cumulative_bytes_size: usize,
pub number_dependents_in_chain: usize,
pub creation_instant: SystemTime,
}
pub type RemovedTransactions = Vec<StorageData>;
pub trait CheckedTransaction<StorageIndex> {
fn tx(&self) -> &ArcPoolTx;
fn all_dependencies(&self) -> &HashSet<StorageIndex>;
}
pub trait Storage {
type StorageIndex: Copy + Debug + Eq + Hash;
type CheckedTransaction: CheckedTransaction<Self::StorageIndex>;
fn store_transaction(
&mut self,
checked_transaction: Self::CheckedTransaction,
creation_instant: SystemTime,
) -> Self::StorageIndex;
fn can_store_transaction(
&self,
transaction: ArcPoolTx,
) -> Result<Self::CheckedTransaction, Error>;
fn get(&self, index: &Self::StorageIndex) -> Option<&StorageData>;
fn get_direct_dependents(
&self,
index: Self::StorageIndex,
) -> impl Iterator<Item = Self::StorageIndex>;
fn has_dependencies(&self, index: &Self::StorageIndex) -> bool;
fn validate_inputs(
&self,
transaction: &PoolTransaction,
persistent_storage: &impl TxPoolPersistentStorage,
extracted_outputs: &ExtractedOutputs,
spent_inputs: &SpentInputs,
utxo_validation: bool,
) -> Result<(), InputValidationErrorType>;
fn remove_transaction_and_dependents_subtree(
&mut self,
index: Self::StorageIndex,
) -> RemovedTransactions;
fn remove_transaction(&mut self, index: Self::StorageIndex) -> Option<StorageData>;
}