Skip to main content

muta_protocol/traits/
mempool.rs

1use async_trait::async_trait;
2use creep::Context;
3
4use crate::types::{Hash, SignedTransaction};
5use crate::ProtocolResult;
6
7#[allow(dead_code)]
8pub struct MixedTxHashes {
9    pub order_tx_hashes:   Vec<Hash>,
10    pub propose_tx_hashes: Vec<Hash>,
11}
12
13impl MixedTxHashes {
14    pub fn clap(self) -> (Vec<Hash>, Vec<Hash>) {
15        (self.order_tx_hashes, self.propose_tx_hashes)
16    }
17}
18
19#[async_trait]
20pub trait MemPool: Send + Sync {
21    async fn insert(&self, ctx: Context, tx: SignedTransaction) -> ProtocolResult<()>;
22
23    async fn package(&self, ctx: Context, cycle_limit: u64) -> ProtocolResult<MixedTxHashes>;
24
25    async fn flush(&self, ctx: Context, tx_hashes: Vec<Hash>) -> ProtocolResult<()>;
26
27    async fn get_full_txs(
28        &self,
29        ctx: Context,
30        tx_hashes: Vec<Hash>,
31    ) -> ProtocolResult<Vec<SignedTransaction>>;
32
33    async fn ensure_order_txs(
34        &self,
35        ctx: Context,
36        order_tx_hashes: Vec<Hash>,
37    ) -> ProtocolResult<()>;
38
39    async fn sync_propose_txs(
40        &self,
41        ctx: Context,
42        propose_tx_hashes: Vec<Hash>,
43    ) -> ProtocolResult<()>;
44}
45
46#[async_trait]
47pub trait MemPoolAdapter: Send + Sync {
48    async fn pull_txs(
49        &self,
50        ctx: Context,
51        tx_hashes: Vec<Hash>,
52    ) -> ProtocolResult<Vec<SignedTransaction>>;
53
54    async fn broadcast_tx(&self, ctx: Context, tx: SignedTransaction) -> ProtocolResult<()>;
55
56    async fn check_signature(&self, ctx: Context, tx: SignedTransaction) -> ProtocolResult<()>;
57
58    async fn check_transaction(&self, ctx: Context, tx: SignedTransaction) -> ProtocolResult<()>;
59
60    async fn check_storage_exist(&self, ctx: Context, tx_hash: Hash) -> ProtocolResult<()>;
61
62    async fn get_latest_epoch_id(&self, ctx: Context) -> ProtocolResult<u64>;
63}