-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Gilad Chase
committed
Apr 11, 2024
1 parent
7d8faf1
commit 62b8414
Showing
3 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
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,2 @@ | ||
#[derive(Debug, Error)] | ||
pub enum MempoolError {} |
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,2 +1,4 @@ | ||
// TODO: change to pub(crate) once this is used by the (not yet implemented) mempool struct. | ||
pub mod errors; | ||
pub mod mempool; | ||
pub mod priority_queue; |
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,37 @@ | ||
use starknet_api::{internal_transaction::InternalTransaction, transaction::TransactionHash}; | ||
|
||
use crate::errors::MempoolError; | ||
|
||
pub type MempoolResult<T> = Result<T, MempoolError>; | ||
|
||
pub struct Mempool; | ||
|
||
impl Mempool { | ||
/// Retrieves up to `n_txs` transactions with the highest priority from the mempool. | ||
/// Transactions are guaranteed to be unique across calls until `commit_block` is invoked. | ||
// TODO: the last part about commit_block is incorrect if we delete txs in get_txs and then push back. | ||
pub fn get_txs(n_txs: u8) -> MempoolResult<Vec<InternalTransaction>> { | ||
todo!(); | ||
} | ||
|
||
/// Adds a new transaction to the mempool. | ||
/// TODO: support fee escalation and transactions with future nonces. | ||
pub fn add_tx(&mut self, tx: InternalTransaction) -> MempoolResult<()> { | ||
todo!(); | ||
} | ||
|
||
/// Update the mempool's internal state according to the committed block's transactions. | ||
/// This method also resolves nonce gaps and updates account balances. | ||
// TODO: the part about resolving nonce gaps is incorrect if we delete txs in get_txs and then | ||
// push back. | ||
pub fn commit_block( | ||
&mut self, | ||
block_number: u64, | ||
txs_in_block: &[TransactionHash], | ||
state_changes: StateChanges, | ||
) -> MempoolResult<()> { | ||
todo!() | ||
} | ||
} | ||
|
||
pub struct StateChanges; |