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.
ExtendedHeader
s 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
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 app_version(&self) -> Result<AppVersion>
pub fn app_version(&self) -> Result<AppVersion>
Get the app version.
§Errors
This function returns an error if the app version set in header is not currently supported.
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
.
§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.
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_adjacent(&self, untrusted: &ExtendedHeader) -> Result<()>
pub fn verify_adjacent(&self, untrusted: &ExtendedHeader) -> Result<()>
Verify an untrusted header and make sure they are adjacent to self
.
Ensures that the untrusted header is adjacent and can be trusted
by verifying it against 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.
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 decode_vec(v: &[u8]) -> Result<Self, Error>
fn decode_vec(v: &[u8]) -> Result<Self, Error>
Vec<u8>
(or equivalent).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§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self
to use its Binary
implementation when Debug
-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self
to use its Display
implementation when
Debug
-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self
to use its LowerExp
implementation when
Debug
-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self
to use its LowerHex
implementation when
Debug
-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self
to use its Octal
implementation when Debug
-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self
to use its Pointer
implementation when
Debug
-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self
to use its UpperExp
implementation when
Debug
-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self
to use its UpperHex
implementation when
Debug
-formatted.Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self
, then passes self.as_ref()
into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self
, then passes self.as_mut()
into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self
, then passes self.deref()
into the pipe function.Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B>
of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B>
of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R>
view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R>
view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target
of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target
of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow()
only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref()
only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref()
only in debug builds, and is erased in release
builds.