Struct celestia_types::ExtendedHeader

source ·
pub struct ExtendedHeader {
    pub header: Header,
    pub commit: Commit,
    pub validator_set: ValidatorSet,
    pub dah: DataAvailabilityHeader,
}
Expand description

Block header together with the relevant Data Availability metadata.

ExtendedHeaders are used to announce and describe the blocks in the Celestia network.

Before being used, each header should be validated and verified with a header you trust.

§Example

let genesis_header = trusted_genesis_header();

// fetch new header
let fetched_header = some_untrusted_header();

fetched_header.validate().expect("Invalid block header");
genesis_header.verify(&fetched_header).expect("Malicious header received");

Fields§

§header: Header

Tendermint block header.

§commit: Commit

Commit metadata and signatures from validators committing the block.

§validator_set: ValidatorSet

Information about the set of validators commiting the block.

§dah: DataAvailabilityHeader

Header of the block data availability.

Implementations§

source§

impl ExtendedHeader

source

pub fn decode_and_validate(bytes: &[u8]) -> Result<Self>

Decode protobuf encoded header and then validate it.

source

pub fn chain_id(&self) -> &Id

Get the block chain id.

source

pub fn height(&self) -> Height

Get the block height.

source

pub fn time(&self) -> Time

Get the block time.

source

pub fn hash(&self) -> Hash

Get the block hash.

source

pub fn last_header_hash(&self) -> Hash

Get the hash of the previous header.

source

pub fn validate(&self) -> Result<()>

Validate header.

Performs a consistency check of the data included in the header.

§Errors

If validation fails, this function will return an error with a reason of failure.

// fetch new header
let mut fetched_header = get_header(15);

assert!(fetched_header.validate().is_ok());

fetched_header.dah = DataAvailabilityHeader::new_unchecked(vec![], vec![]);

assert!(fetched_header.validate().is_err());
source

pub fn verify(&self, untrusted: &ExtendedHeader) -> Result<()>

Verify an untrusted header.

Ensures that the untrusted header can be trusted by verifying it against self.

§Errors

If validation fails, this function will return an error with a reason of failure.

Please note that if verifying unadjacent headers, the verification will always fail if the validator set commiting those blocks was changed. If that is the case, consider verifying the untrusted header with a more recent or even previous header.

source

pub fn verify_range(&self, untrusted: &[ExtendedHeader]) -> Result<()>

Verify a chain of adjacent untrusted headers.

§Note

This method does not do validation for optimization purposes. Validation should be done from before and ideally with ExtendedHeader::decode_and_validate.

§Errors

If verification fails, this function will return an error with a reason of failure. This function will also return an error if untrusted headers are not adjacent to each other.

§Example
let genesis_header = trusted_genesis();
let next_headers = get_headers_range(5..50);

assert!(genesis_header.verify_range(&next_headers).is_ok());
source

pub fn verify_adjacent_range(&self, untrusted: &[ExtendedHeader]) -> Result<()>

Verify a chain of adjacent untrusted headers and make sure they are adjacent to self.

§Note

This method does not do validation for optimization purposes. Validation should be done from before and ideally with ExtendedHeader::decode_and_validate.

§Errors

If verification fails, this function will return an error with a reason of failure. This function will also return an error if untrusted headers and self don’t form contiguous range

§Example
let genesis_header = trusted_genesis();
let next_headers = get_headers_range(5..50);

// fails, not adjacent to genesis
assert!(genesis_header.verify_adjacent_range(&next_headers).is_err());

let next_headers = get_headers_range(2..50);

// succeeds
genesis_header.verify_adjacent_range(&next_headers).unwrap();

Trait Implementations§

source§

impl Clone for ExtendedHeader

source§

fn clone(&self) -> ExtendedHeader

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 ExtendedHeader

source§

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

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

impl<'de> Deserialize<'de> for ExtendedHeader

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 Display for ExtendedHeader

source§

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

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

impl From<ExtendedHeader> for ExtendedHeader

source§

fn from(value: ExtendedHeader) -> RawExtendedHeader

Converts to this type from the input type.
source§

impl PartialEq for ExtendedHeader

source§

fn eq(&self, other: &ExtendedHeader) -> 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<ExtendedHeader> for ExtendedHeader

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 ExtendedHeader

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<ExtendedHeader> for ExtendedHeader

§

type Error = Error

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

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

Performs the conversion.
source§

impl Eq for ExtendedHeader

source§

impl StructuralPartialEq for ExtendedHeader

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> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. 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>,