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: HeaderTendermint block header.
commit: CommitCommit metadata and signatures from validators committing the block.
validator_set: ValidatorSetInformation about the set of validators commiting the block.
dah: DataAvailabilityHeaderHeader of the block data availability.
Implementations§
source§impl ExtendedHeader
impl ExtendedHeader
sourcepub fn decode_and_validate(bytes: &[u8]) -> Result<Self>
pub fn decode_and_validate(bytes: &[u8]) -> Result<Self>
Decode protobuf encoded header and then validate it.
sourcepub fn last_header_hash(&self) -> Hash
pub fn last_header_hash(&self) -> Hash
Get the hash of the previous header.
sourcepub fn validate(&self) -> Result<()>
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());sourcepub fn verify(&self, untrusted: &ExtendedHeader) -> Result<()>
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.
sourcepub fn verify_range(&self, untrusted: &[ExtendedHeader]) -> Result<()>
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());sourcepub fn verify_adjacent_range(&self, untrusted: &[ExtendedHeader]) -> Result<()>
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
impl Clone for ExtendedHeader
source§fn clone(&self) -> ExtendedHeader
fn clone(&self) -> ExtendedHeader
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl Debug for ExtendedHeader
impl Debug for ExtendedHeader
source§impl<'de> Deserialize<'de> for ExtendedHeader
impl<'de> Deserialize<'de> for ExtendedHeader
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl Display for ExtendedHeader
impl Display for ExtendedHeader
source§impl From<ExtendedHeader> for ExtendedHeader
impl From<ExtendedHeader> for ExtendedHeader
source§fn from(value: ExtendedHeader) -> RawExtendedHeader
fn from(value: ExtendedHeader) -> RawExtendedHeader
source§impl PartialEq for ExtendedHeader
impl PartialEq for ExtendedHeader
source§impl Protobuf<ExtendedHeader> for ExtendedHeader
impl Protobuf<ExtendedHeader> for ExtendedHeader
source§fn encode<B>(&self, buf: &mut B) -> Result<(), Error>where
B: BufMut,
fn encode<B>(&self, buf: &mut B) -> Result<(), Error>where
B: BufMut,
source§fn encode_length_delimited<B>(&self, buf: &mut B) -> Result<(), Error>where
B: BufMut,
fn encode_length_delimited<B>(&self, buf: &mut B) -> Result<(), Error>where
B: BufMut,
source§fn decode<B>(buf: B) -> Result<Self, Error>where
B: Buf,
fn decode<B>(buf: B) -> Result<Self, Error>where
B: Buf,
source§fn decode_length_delimited<B>(buf: B) -> Result<Self, Error>where
B: Buf,
fn decode_length_delimited<B>(buf: B) -> Result<Self, Error>where
B: Buf,
source§fn encoded_len(&self) -> usize
fn encoded_len(&self) -> usize
source§fn encode_vec(&self) -> Result<Vec<u8>, Infallible>
fn encode_vec(&self) -> Result<Vec<u8>, Infallible>
Vec<u8>.source§fn decode_vec(v: &[u8]) -> Result<Self, Error>
fn decode_vec(v: &[u8]) -> Result<Self, Error>
Vec<u8> (or equivalent).source§fn encode_length_delimited_vec(&self) -> Result<Vec<u8>, Infallible>
fn encode_length_delimited_vec(&self) -> Result<Vec<u8>, Infallible>
Vec<u8> Protobuf-encoded message.source§impl Serialize for ExtendedHeader
impl Serialize for ExtendedHeader
source§impl TryFrom<ExtendedHeader> for ExtendedHeader
impl TryFrom<ExtendedHeader> for ExtendedHeader
impl Eq for ExtendedHeader
impl StructuralPartialEq for ExtendedHeader
Auto Trait Implementations§
impl Freeze for ExtendedHeader
impl RefUnwindSafe for ExtendedHeader
impl Send for ExtendedHeader
impl Sync for ExtendedHeader
impl Unpin for ExtendedHeader
impl UnwindSafe for ExtendedHeader
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§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)