forked from nervosnetwork/muta
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(protocol): Add the mempool traits (#7)
* define transaction-pool trait * rename transaction_pool to mempool * derive PartialEq, Eq, Hash for Hash, Address, AccountAddress * add check_transaction interface * reorder crate ref
- Loading branch information
Showing
4 changed files
with
69 additions
and
3 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
use std::collections::HashMap; | ||
|
||
use async_trait::async_trait; | ||
|
||
use crate::types::{Hash, SignedTransaction}; | ||
use crate::ProtocolResult; | ||
|
||
#[allow(dead_code)] | ||
pub type Context = HashMap<String, String>; | ||
|
||
#[allow(dead_code)] | ||
pub struct MixedTxHashes { | ||
pub order_tx_hashes: Vec<Hash>, | ||
pub propose_tx_hashes: Vec<Hash>, | ||
} | ||
|
||
#[async_trait] | ||
pub trait MemPool<Adapter: MemPoolAdapter>: Send + Sync { | ||
async fn insert(&self, ctx: Context, tx: SignedTransaction) -> ProtocolResult<()>; | ||
|
||
async fn package( | ||
&self, | ||
ctx: Context, | ||
count: u64, | ||
cycle_limit: u64, | ||
) -> ProtocolResult<MixedTxHashes>; | ||
|
||
async fn flush(&self, ctx: Context, tx_hashes: Vec<Hash>) -> ProtocolResult<()>; | ||
|
||
async fn get_full_txs( | ||
&self, | ||
ctx: Context, | ||
tx_hashes: Vec<Hash>, | ||
) -> ProtocolResult<Vec<SignedTransaction>>; | ||
|
||
async fn ensure_order_txs( | ||
&self, | ||
ctx: Context, | ||
order_tx_hashes: Vec<Hash>, | ||
) -> ProtocolResult<()>; | ||
|
||
async fn sync_propose_txs( | ||
&self, | ||
ctx: Context, | ||
propose_tx_hashes: Vec<Hash>, | ||
) -> ProtocolResult<()>; | ||
} | ||
|
||
#[async_trait] | ||
pub trait MemPoolAdapter: Send + Sync { | ||
async fn pull_txs( | ||
&self, | ||
ctx: Context, | ||
tx_hashes: Vec<Hash>, | ||
) -> ProtocolResult<SignedTransaction>; | ||
|
||
async fn broadcast_txs(&self, ctx: Context, txs: Vec<SignedTransaction>) -> ProtocolResult<()>; | ||
|
||
async fn check_signature(&self, ctx: Context, tx: SignedTransaction) -> ProtocolResult<()>; | ||
|
||
async fn check_transaction(&self, ctx: Context, tx: SignedTransaction) -> ProtocolResult<()>; | ||
|
||
async fn check_storage_exist(&self, ctx: Context, tx_hash: Hash) -> ProtocolResult<()>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
mod executor; | ||
mod mempool; | ||
mod storage; | ||
|
||
pub use executor::{Executor, ExecutorAdapter}; | ||
pub use mempool::{Context, MemPool, MemPoolAdapter, MixedTxHashes}; | ||
pub use storage::{Storage, StorageAdapter, StorageCategory}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters