Struct miden_objects::transaction::ChainMmr
source · pub struct ChainMmr { /* private fields */ }Expand description
A struct that represents the chain Merkle Mountain Range (MMR).
The MMR allows for efficient authentication of input notes during transaction execution. Authentication is achieved by providing inclusion proofs for the notes consumed in the transaction against the chain MMR root associated with the latest block known at the time of transaction execution.
ChainMmr represents a partial view into the actual MMR and contains authentication paths for a limited set of blocks. The intent is to include only the blocks relevant for execution of a specific transaction (i.e., the blocks corresponding to all input notes).
Implementations§
source§impl ChainMmr
impl ChainMmr
sourcepub fn new(
mmr: PartialMmr,
blocks: Vec<BlockHeader>
) -> Result<Self, ChainMmrError>
pub fn new( mmr: PartialMmr, blocks: Vec<BlockHeader> ) -> Result<Self, ChainMmrError>
Returns a new ChainMmr instantiated from the provided partial MMR and a list of block headers.
§Errors
Returns an error if:
- block_num for any of the blocks is greater than the chain length implied by the provided partial MMR.
- The same block appears more than once in the provided list of block headers.
- The partial MMR does not track authentication paths for any of the specified blocks.
sourcepub fn chain_length(&self) -> usize
pub fn chain_length(&self) -> usize
Returns total number of blocks contain in the chain described by this MMR.
sourcepub fn contains_block(&self, block_num: u32) -> bool
pub fn contains_block(&self, block_num: u32) -> bool
Returns true if the block is present in this chain MMR.
sourcepub fn get_block(&self, block_num: u32) -> Option<&BlockHeader>
pub fn get_block(&self, block_num: u32) -> Option<&BlockHeader>
Returns the block header for the specified block, or None if the block is not present in this chain MMR.
sourcepub fn add_block(&mut self, block_header: BlockHeader, track: bool)
pub fn add_block(&mut self, block_header: BlockHeader, track: bool)
Appends the provided block header to this chain MMR. This method assumes that the provided block header is for the next block in the chain.
If track parameter is set to true, the authentication path for the provided block header
will be added to this chain MMR.
§Panics
Panics if the block_header.block_num is not equal to the current chain length (i.e., the
provided block header is not the next block in the chain).
sourcepub fn inner_nodes(&self) -> impl Iterator<Item = InnerNodeInfo> + '_
pub fn inner_nodes(&self) -> impl Iterator<Item = InnerNodeInfo> + '_
Returns an iterator over the inner nodes of authentication paths contained in this chain MMR.