pub struct Mempool { /* private fields */ }Expand description
Holds the transactions that we broadcasted and are still in the mempool.
Implementations§
Source§impl Mempool
impl Mempool
Sourcepub fn new(acc: Pollard<BitcoinNodeHash>, max_mempool_size: usize) -> Mempool
pub fn new(acc: Pollard<BitcoinNodeHash>, max_mempool_size: usize) -> Mempool
Creates a new mempool with a given maximum size and accumulator.
The acculator should have the same roots as the one inside our chainstate, or we won’t be able to validate proofs.
Sourcepub fn list_unprocessed(&self) -> Vec<Txid>
pub fn list_unprocessed(&self) -> Vec<Txid>
List transactions we are pending to process.
Usually, we don’t have a proof for these transactions, so we can’t add them to the mempool, a wire implementation should call this method and try to get a proof for these transactions.
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_prevouts(&self, tx: &Transaction) -> Vec<TxOut>
pub fn get_prevouts(&self, tx: &Transaction) -> Vec<TxOut>
Returns the data of the prevouts that are being spent by a transaction.
This data isn’t part of the actual transaction, usually we would fetch it from the UTXO set, but we don’t have one. Instead, we keep track of the prevouts that are being spent by transactions in the mempool and use this method to get the data.
Sourcepub fn try_prove(
&self,
tx: &Transaction,
block_hash: &impl BlockHashOracle,
) -> Result<MempoolProof, AcceptToMempoolError>
pub fn try_prove( &self, tx: &Transaction, block_hash: &impl BlockHashOracle, ) -> Result<MempoolProof, AcceptToMempoolError>
Proves that a mempool transaction is valid for the latest accumulator state.
This should return a proof that the transaction is valid, and the data for the prevouts that are being spent by the transaction.
Sourcepub fn get_block_template(
&self,
version: Version,
prev_blockhash: BlockHash,
time: u32,
bits: CompactTarget,
) -> Block
pub fn get_block_template( &self, version: Version, prev_blockhash: BlockHash, time: u32, bits: CompactTarget, ) -> Block
Returns a list of transactions that are in the mempool up to the block weight limit.
Returns a candidate block to be mined.
Sourcepub fn consume_block(
&mut self,
block: &Block,
proof: Proof,
adds: &[PollardAddition<BitcoinNodeHash>],
del_hashes: &[BitcoinNodeHash],
block_height: u32,
remember_all: bool,
) -> Result<Vec<Txid>, AcceptToMempoolError>
pub fn consume_block( &mut self, block: &Block, proof: Proof, adds: &[PollardAddition<BitcoinNodeHash>], del_hashes: &[BitcoinNodeHash], block_height: u32, remember_all: bool, ) -> Result<Vec<Txid>, AcceptToMempoolError>
Consume a block and remove all transactions that were included in it.
This method will remove all transactions that is in the block from the mempool, update the local accumulator and return the txids that were included in the block.
Sourcepub fn get_block_proof(
&self,
block: &Block,
get_block_hash: impl BlockHashOracle,
) -> Result<MempoolProof, AcceptToMempoolError>
pub fn get_block_proof( &self, block: &Block, get_block_hash: impl BlockHashOracle, ) -> Result<MempoolProof, AcceptToMempoolError>
Proves all transactions included in a block.
Sourcepub fn accept_to_mempool_no_acc(
&mut self,
transaction: Transaction,
) -> Result<(), AcceptToMempoolError>
pub fn accept_to_mempool_no_acc( &mut self, transaction: Transaction, ) -> Result<(), AcceptToMempoolError>
Internal utility to add a transaction to the mempool.
This method should never be called for transactions coming from the wire, since it doesn’t
check if the transaction is valid other than basic constraint checks. This method is used
by the mempool itself to add transactions that are already known to be valid, such as
wallet transactions. For transactions coming from the wire, use accept_to_mempool.
Sourcepub fn accept_to_mempool(
&mut self,
transaction: Transaction,
proof: Proof,
prevouts: &[(OutPoint, CompactLeafData)],
del_hashes: &[BitcoinNodeHash],
remembers: &[u64],
) -> Result<(), AcceptToMempoolError>
pub fn accept_to_mempool( &mut self, transaction: Transaction, proof: Proof, prevouts: &[(OutPoint, CompactLeafData)], del_hashes: &[BitcoinNodeHash], remembers: &[u64], ) -> Result<(), AcceptToMempoolError>
Add a transaction to the mempool.
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.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Mempool
impl !RefUnwindSafe for Mempool
impl !Sync for Mempool
impl Unpin for Mempool
impl !UnwindSafe for Mempool
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more