pub struct BlockHeader { /* private fields */ }Expand description
The header of a block. It contains metadata about the block, commitments to the current state of the chain and the hash of the proof that attests to the integrity of the chain.
A block header includes the following fields:
versionspecifies the version of the protocol.prev_block_commitmentis the hash of the previous block header.block_numis a unique sequential number of the current block.chain_commitmentis a commitment to an MMR of the entire chain where each block is a leaf.account_rootis a commitment to account database.nullifier_rootis a commitment to the nullifier database.note_rootis a commitment to all notes created in the current block.tx_commitmentis a commitment to the set of transaction IDs which affected accounts in the block.tx_kernel_commitmenta commitment to all transaction kernels supported by this block.proof_commitmentis the commitment of the block’s STARK proof attesting to the correct state transition.timestampis the time when the block was created, in seconds since UNIX epoch. Current representation is sufficient to represent time up to year 2106.sub_commitmentis a sequential hash of all fields except the note_root.commitmentis a 2-to-1 hash of the sub_commitment and the note_root.
Implementations§
Source§impl BlockHeader
impl BlockHeader
Sourcepub fn new(
version: u32,
prev_block_commitment: RpoDigest,
block_num: BlockNumber,
chain_commitment: RpoDigest,
account_root: RpoDigest,
nullifier_root: RpoDigest,
note_root: RpoDigest,
tx_commitment: RpoDigest,
tx_kernel_commitment: RpoDigest,
proof_commitment: RpoDigest,
timestamp: u32,
) -> BlockHeader
pub fn new( version: u32, prev_block_commitment: RpoDigest, block_num: BlockNumber, chain_commitment: RpoDigest, account_root: RpoDigest, nullifier_root: RpoDigest, note_root: RpoDigest, tx_commitment: RpoDigest, tx_kernel_commitment: RpoDigest, proof_commitment: RpoDigest, timestamp: u32, ) -> BlockHeader
Creates a new block header.
Sourcepub fn commitment(&self) -> RpoDigest
pub fn commitment(&self) -> RpoDigest
Returns the commitment of the block header.
Sourcepub fn sub_commitment(&self) -> RpoDigest
pub fn sub_commitment(&self) -> RpoDigest
Returns the sub commitment of the block header.
The sub commitment is a sequential hash of all block header fields except the note root. This is used in the block commitment computation which is a 2-to-1 hash of the sub commitment and the note root [hash(sub_commitment, note_root)]. This procedure is used to make the note root easily accessible without having to unhash the entire header.
Sourcepub fn prev_block_commitment(&self) -> RpoDigest
pub fn prev_block_commitment(&self) -> RpoDigest
Returns the commitment to the previous block header.
Sourcepub fn block_num(&self) -> BlockNumber
pub fn block_num(&self) -> BlockNumber
Returns the block number.
Sourcepub fn block_epoch(&self) -> u16
pub fn block_epoch(&self) -> u16
Returns the epoch to which this block belongs.
This is the block number shifted right by BlockNumber::EPOCH_LENGTH_EXPONENT.
Sourcepub fn chain_commitment(&self) -> RpoDigest
pub fn chain_commitment(&self) -> RpoDigest
Returns the chain commitment.
Sourcepub fn account_root(&self) -> RpoDigest
pub fn account_root(&self) -> RpoDigest
Returns the account database root.
Sourcepub fn nullifier_root(&self) -> RpoDigest
pub fn nullifier_root(&self) -> RpoDigest
Returns the nullifier database root.
Sourcepub fn tx_commitment(&self) -> RpoDigest
pub fn tx_commitment(&self) -> RpoDigest
Returns the commitment to all transactions in this block.
The commitment is computed as sequential hash of (transaction_id, account_id) tuples.
This makes it possible for the verifier to link transaction IDs to the accounts which
they were executed against.
Sourcepub fn tx_kernel_commitment(&self) -> RpoDigest
pub fn tx_kernel_commitment(&self) -> RpoDigest
Returns the transaction kernel commitment.
The transaction kernel commitment is computed as a sequential hash of all transaction kernel hashes.
Sourcepub fn proof_commitment(&self) -> RpoDigest
pub fn proof_commitment(&self) -> RpoDigest
Returns the proof commitment.
Sourcepub fn timestamp(&self) -> u32
pub fn timestamp(&self) -> u32
Returns the timestamp at which the block was created, in seconds since UNIX epoch.
Sourcepub fn epoch_block_num(&self) -> BlockNumber
pub fn epoch_block_num(&self) -> BlockNumber
Returns the block number of the epoch block to which this block belongs.
Sourcepub fn compute_tx_commitment(
updated_accounts: impl Iterator<Item = (TransactionId, AccountId)>,
) -> RpoDigest
pub fn compute_tx_commitment( updated_accounts: impl Iterator<Item = (TransactionId, AccountId)>, ) -> RpoDigest
Computes a commitment to the provided list of transactions.
Trait Implementations§
Source§impl Clone for BlockHeader
impl Clone for BlockHeader
Source§fn clone(&self) -> BlockHeader
fn clone(&self) -> BlockHeader
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for BlockHeader
impl Debug for BlockHeader
Source§impl Deserializable for BlockHeader
impl Deserializable for BlockHeader
Source§fn read_from<R>(source: &mut R) -> Result<BlockHeader, DeserializationError>where
R: ByteReader,
fn read_from<R>(source: &mut R) -> Result<BlockHeader, DeserializationError>where
R: ByteReader,
source, attempts to deserialize these bytes
into Self, and returns the result. Read moreSource§fn read_from_bytes(bytes: &[u8]) -> Result<Self, DeserializationError>
fn read_from_bytes(bytes: &[u8]) -> Result<Self, DeserializationError>
Source§impl PartialEq for BlockHeader
impl PartialEq for BlockHeader
Source§impl Serializable for BlockHeader
impl Serializable for BlockHeader
Source§fn write_into<W>(&self, target: &mut W)where
W: ByteWriter,
fn write_into<W>(&self, target: &mut W)where
W: ByteWriter,
self into bytes and writes these bytes into the target.Source§fn get_size_hint(&self) -> usize
fn get_size_hint(&self) -> usize
impl Eq for BlockHeader
impl StructuralPartialEq for BlockHeader
Auto Trait Implementations§
impl Freeze for BlockHeader
impl RefUnwindSafe for BlockHeader
impl Send for BlockHeader
impl Sync for BlockHeader
impl Unpin for BlockHeader
impl UnwindSafe for BlockHeader
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<D> OwoColorize for D
impl<D> OwoColorize for D
Source§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
Source§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
Source§fn black(&self) -> FgColorDisplay<'_, Black, Self>
fn black(&self) -> FgColorDisplay<'_, Black, Self>
Source§fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
Source§fn red(&self) -> FgColorDisplay<'_, Red, Self>
fn red(&self) -> FgColorDisplay<'_, Red, Self>
Source§fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
Source§fn green(&self) -> FgColorDisplay<'_, Green, Self>
fn green(&self) -> FgColorDisplay<'_, Green, Self>
Source§fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
Source§fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
Source§fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
Source§fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
Source§fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
Source§fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
Source§fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
Source§fn white(&self) -> FgColorDisplay<'_, White, Self>
fn white(&self) -> FgColorDisplay<'_, White, Self>
Source§fn on_white(&self) -> BgColorDisplay<'_, White, Self>
fn on_white(&self) -> BgColorDisplay<'_, White, Self>
Source§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
Source§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
Source§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
Source§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
Source§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
Source§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
Source§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
Source§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
Source§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
Source§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
Source§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
Source§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
Source§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
Source§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
Source§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
Source§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
Source§fn bold(&self) -> BoldDisplay<'_, Self>
fn bold(&self) -> BoldDisplay<'_, Self>
Source§fn dimmed(&self) -> DimDisplay<'_, Self>
fn dimmed(&self) -> DimDisplay<'_, Self>
Source§fn italic(&self) -> ItalicDisplay<'_, Self>
fn italic(&self) -> ItalicDisplay<'_, Self>
Source§fn underline(&self) -> UnderlineDisplay<'_, Self>
fn underline(&self) -> UnderlineDisplay<'_, Self>
Source§fn blink(&self) -> BlinkDisplay<'_, Self>
fn blink(&self) -> BlinkDisplay<'_, Self>
Source§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
Source§fn reversed(&self) -> ReversedDisplay<'_, Self>
fn reversed(&self) -> ReversedDisplay<'_, Self>
Source§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
Source§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg or
a color-specific method, such as OwoColorize::green, Read moreSource§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg or
a color-specific method, such as OwoColorize::on_yellow, Read more