Struct celestia_types::DataAvailabilityHeader

source ·
pub struct DataAvailabilityHeader { /* private fields */ }
Expand description

Header with commitments of the data availability.

It consists of the root hashes of the merkle trees created from each row and column of the ExtendedDataSquare. Those are used to prove the inclusion of the data in a block.

The hash of this header is a hash of all rows and columns and thus a data commitment of the block.

§Example

// fetch the block header and data for your namespace
let namespace = Namespace::new_v0(&[1, 2, 3, 4]).unwrap();
let eh = extended_header();
let (shares, proof) = shares_with_proof(eh.height(), &namespace);

// get the data commitment for a given row
let dah = eh.dah;
let root = dah.row_root(0).unwrap();

// verify a proof of the inclusion of the shares
assert!(proof.verify_complete_namespace(&root, &shares, *namespace).is_ok());

Implementations§

source§

impl DataAvailabilityHeader

source

pub fn new( row_roots: Vec<NamespacedHash>, column_roots: Vec<NamespacedHash>, ) -> Result<Self>

source

pub fn new_unchecked( row_roots: Vec<NamespacedHash>, column_roots: Vec<NamespacedHash>, ) -> Self

Create new non-validated DataAvailabilityHeader.

DataAvailabilityHeader::validate_basic can be used to check valitidy later on.

source

pub fn from_eds(eds: &ExtendedDataSquare) -> Self

Create a DataAvailabilityHeader by computing roots of a given ExtendedDataSquare.

source

pub fn root(&self, axis: AxisType, index: u16) -> Option<NamespacedHash>

Get the root from an axis at the given index.

source

pub fn row_roots(&self) -> &[NamespacedHash]

Merkle roots of the ExtendedDataSquare rows.

source

pub fn column_roots(&self) -> &[NamespacedHash]

Merkle roots of the ExtendedDataSquare columns.

source

pub fn row_root(&self, row: u16) -> Option<NamespacedHash>

Get a root of the row with the given index.

source

pub fn column_root(&self, column: u16) -> Option<NamespacedHash>

Get the a root of the column with the given index.

source

pub fn hash(&self) -> Hash

Compute the combined hash of all rows and columns.

This is the data commitment for the block.

§Example
let eh = get_extended_header();
let dah = eh.dah;

assert_eq!(dah.hash(), eh.header.data_hash);
source

pub fn square_width(&self) -> u16

Get the size of the ExtendedDataSquare for which this header was built.

Trait Implementations§

source§

impl Clone for DataAvailabilityHeader

source§

fn clone(&self) -> DataAvailabilityHeader

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for DataAvailabilityHeader

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'de> Deserialize<'de> for DataAvailabilityHeader

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl From<DataAvailabilityHeader> for DataAvailabilityHeader

source§

fn from(value: DataAvailabilityHeader) -> RawDataAvailabilityHeader

Converts to this type from the input type.
source§

impl PartialEq for DataAvailabilityHeader

source§

fn eq(&self, other: &DataAvailabilityHeader) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Protobuf<DataAvailabilityHeader> for DataAvailabilityHeader

source§

fn encode<B>(&self, buf: &mut B) -> Result<(), Error>
where B: BufMut,

Encode into a buffer in Protobuf format. Read more
source§

fn encode_length_delimited<B>(&self, buf: &mut B) -> Result<(), Error>
where B: BufMut,

Encode with a length-delimiter to a buffer in Protobuf format. Read more
source§

fn decode<B>(buf: B) -> Result<Self, Error>
where B: Buf,

Constructor that attempts to decode an instance from a buffer. Read more
source§

fn decode_length_delimited<B>(buf: B) -> Result<Self, Error>
where B: Buf,

Constructor that attempts to decode a length-delimited instance from the buffer. Read more
source§

fn encoded_len(&self) -> usize

Returns the encoded length of the message without a length delimiter. Read more
source§

fn encode_vec(&self) -> Result<Vec<u8>, Infallible>

Encodes into a Protobuf-encoded Vec<u8>.
source§

fn decode_vec(v: &[u8]) -> Result<Self, Error>

Constructor that attempts to decode a Protobuf-encoded instance from a Vec<u8> (or equivalent).
source§

fn encode_length_delimited_vec(&self) -> Result<Vec<u8>, Infallible>

Encode with a length-delimiter to a Vec<u8> Protobuf-encoded message.
source§

fn decode_length_delimited_vec(v: &[u8]) -> Result<Self, Error>

Constructor that attempts to decode a Protobuf-encoded instance with a length-delimiter from a Vec<u8> or equivalent.
source§

impl Serialize for DataAvailabilityHeader

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl TryFrom<DataAvailabilityHeader> for DataAvailabilityHeader

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(value: RawDataAvailabilityHeader) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl ValidateBasic for DataAvailabilityHeader

source§

fn validate_basic(&self) -> Result<(), ValidationError>

Perform a basic validation of the data consistency.
source§

impl Eq for DataAvailabilityHeader

source§

impl StructuralPartialEq for DataAvailabilityHeader

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<S> CondSend for S
where S: Send,

source§

impl<S> CondSync for S
where S: Send + Sync,

source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,