pub struct Mempool {
transactions: HashMap<u64, MempoolTransaction>,
mempool_size: usize,
max_mempool_size: usize,
queue: Vec<Txid>,
hasher: RandomState,
}Expand description
Holds the transactions that we broadcasted and are still in the mempool.
Fields§
§transactions: HashMap<u64, MempoolTransaction>A list of all transactions we currently have in the mempool.
Transactions are kept as a map of their transaction id to the transaction itself, we also keep track of when we added the transaction to the mempool to be able to remove stale transactions.
mempool_size: usizeHow much memory (in bytes) does the mempool currently use.
max_mempool_size: usizeThe maximum size of the mempool in bytes.
queue: Vec<Txid>A queue of transaction we know about, but we haven’t downloaded yet
hasher: RandomStateA hasher that we use to compute the short transaction ids.
Implementations§
Source§impl Mempool
impl Mempool
Sourcepub fn list_unprocessed(&self) -> Vec<Txid>
pub fn list_unprocessed(&self) -> Vec<Txid>
List transactions we are pending to process.
Sourcepub fn list_mempool(&self) -> Vec<Txid>
pub fn list_mempool(&self) -> Vec<Txid>
List all transactions we’ve accepted to the mempool.
This won’t count transactions that are still in the queue.
Sourcepub fn get_block_template(
&self,
version: Version,
prev_blockhash: BlockHash,
time: u32,
bits: CompactTarget,
max_block_weight: u64,
) -> Block
pub fn get_block_template( &self, version: Version, prev_blockhash: BlockHash, time: u32, bits: CompactTarget, max_block_weight: u64, ) -> Block
Returns an unsolved block (with nonce 0) with as many transactions as we can fit into a block (up to max_block_weight).
Sourcefn add_transaction_to_block(
&self,
block_transactions: &mut Vec<Transaction>,
short_txid: u64,
)
fn add_transaction_to_block( &self, block_transactions: &mut Vec<Transaction>, short_txid: u64, )
Utility method that grabs one transaction and all its dependencies, then adds them to a tx list.
Sourcepub fn consume_block(&mut self, block: &Block) -> Vec<Txid>
pub fn consume_block(&mut self, block: &Block) -> Vec<Txid>
Consume a block and remove all transactions that were included in it.
Sourcefn is_already_spent(&self, outpoint: &OutPoint) -> bool
fn is_already_spent(&self, outpoint: &OutPoint) -> bool
Checks if an outpoint is already spent in the mempool.
This can be used to find conflicts before adding a transaction to the mempool.
Sourcefn check_for_conflicts(
&self,
transaction: &Transaction,
) -> Result<(), AcceptToMempoolError>
fn check_for_conflicts( &self, transaction: &Transaction, ) -> Result<(), AcceptToMempoolError>
Checks if the transaction doesn’t have conflicting inputs or spends the same input twice.
Sourcepub fn accept_to_mempool(
&mut self,
transaction: Transaction,
) -> Result<(), AcceptToMempoolError>
pub fn accept_to_mempool( &mut self, transaction: Transaction, ) -> Result<(), AcceptToMempoolError>
Accepts a transaction to mempool
This method will perform some context-less validations on a transaction, and then accept to our mempool. It assumes that we have validated this transaction’s proof.
§Errors
- If we don’t have space left in our mempool
- If the transaction conflicts with another mempool transaction
- If it sepends the same input twice
- If any amount check fails: if input amounts are less than output amounts or if it spends more than the theoretical maximum amount of Bitcoins
- If either vIn or vOut are empty
- If any script is larger than the maximum allowed size
Sourcefn find_mempool_depends(&self, tx: &Transaction) -> Vec<u64>
fn find_mempool_depends(&self, tx: &Transaction) -> Vec<u64>
From a transaction that is already in the mempool, computes which transaction it depends.
Sourcepub fn get_from_mempool<'a>(&'a self, id: &Txid) -> Option<&'a Transaction>
pub fn get_from_mempool<'a>(&'a self, id: &Txid) -> Option<&'a Transaction>
Get a transaction from the mempool.