-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add missing header type + conversions
- Loading branch information
Showing
5 changed files
with
126 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
use crate::NsTable; | ||
|
||
use super::{ | ||
BlockMerkleCommitment, BuilderSignature, FeeInfo, FeeMerkleCommitment, L1BlockInfo, | ||
ResolvableChainConfig, | ||
}; | ||
use ark_serialize::CanonicalSerialize; | ||
use committable::{Commitment, Committable, RawCommitmentBuilder}; | ||
use hotshot_types::{utils::BuilderCommitment, vid::VidCommitment}; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
/// A header is like a [`Block`] with the body replaced by a digest. | ||
#[derive(Clone, Debug, Deserialize, Serialize, Hash, PartialEq, Eq)] | ||
pub struct Header { | ||
/// A commitment to a ChainConfig or a full ChainConfig. | ||
pub(crate) chain_config: ResolvableChainConfig, | ||
pub(crate) height: u64, | ||
pub(crate) timestamp: u64, | ||
pub(crate) l1_head: u64, | ||
pub(crate) l1_finalized: Option<L1BlockInfo>, | ||
pub(crate) payload_commitment: VidCommitment, | ||
pub(crate) builder_commitment: BuilderCommitment, | ||
pub(crate) ns_table: NsTable, | ||
pub(crate) block_merkle_tree_root: BlockMerkleCommitment, | ||
pub(crate) fee_merkle_tree_root: FeeMerkleCommitment, | ||
pub(crate) fee_info: FeeInfo, | ||
pub(crate) builder_signature: Option<BuilderSignature>, | ||
} | ||
|
||
impl Committable for Header { | ||
fn commit(&self) -> Commitment<Self> { | ||
let mut bmt_bytes = vec![]; | ||
self.block_merkle_tree_root | ||
.serialize_with_mode(&mut bmt_bytes, ark_serialize::Compress::Yes) | ||
.unwrap(); | ||
let mut fmt_bytes = vec![]; | ||
self.fee_merkle_tree_root | ||
.serialize_with_mode(&mut fmt_bytes, ark_serialize::Compress::Yes) | ||
.unwrap(); | ||
|
||
RawCommitmentBuilder::new(&Self::tag()) | ||
.field("chain_config", self.chain_config.commit()) | ||
.u64_field("height", self.height) | ||
.u64_field("timestamp", self.timestamp) | ||
.u64_field("l1_head", self.l1_head) | ||
.optional("l1_finalized", &self.l1_finalized) | ||
.constant_str("payload_commitment") | ||
.fixed_size_bytes(self.payload_commitment.as_ref().as_ref()) | ||
.constant_str("builder_commitment") | ||
.fixed_size_bytes(self.builder_commitment.as_ref()) | ||
.field("ns_table", self.ns_table.commit()) | ||
.var_size_field("block_merkle_tree_root", &bmt_bytes) | ||
.var_size_field("fee_merkle_tree_root", &fmt_bytes) | ||
.field("fee_info", self.fee_info.commit()) | ||
.finalize() | ||
} | ||
|
||
fn tag() -> String { | ||
crate::v0_1::Header::tag() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters