Skip to content

Commit

Permalink
4093 add epoch and friends to commitments of new x2 objects (#4094)
Browse files Browse the repository at this point in the history
  • Loading branch information
pls148 authored Jan 30, 2025
1 parent 927084b commit b59bb78
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 32 deletions.
40 changes: 33 additions & 7 deletions crates/types/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1076,13 +1076,39 @@ impl<TYPES: NodeType> Leaf2<TYPES> {

impl<TYPES: NodeType> Committable for Leaf2<TYPES> {
fn commit(&self) -> committable::Commitment<Self> {
RawCommitmentBuilder::new("leaf commitment")
.u64_field("view number", *self.view_number)
.field("parent leaf commitment", self.parent_commitment)
.field("block header", self.block_header.commit())
.field("justify qc", self.justify_qc.commit())
.optional("upgrade certificate", &self.upgrade_certificate)
.finalize()
let Leaf2 {
view_number,
justify_qc,
next_epoch_justify_qc,
parent_commitment,
block_header,
upgrade_certificate,
block_payload: _,
view_change_evidence: _,
next_drb_result,
with_epoch,
} = self;

let mut cb = RawCommitmentBuilder::new("leaf commitment")
.u64_field("view number", **view_number)
.field("parent leaf commitment", *parent_commitment)
.field("block header", block_header.commit())
.field("justify qc", justify_qc.commit())
.optional("upgrade certificate", upgrade_certificate);

if *with_epoch {
cb = cb
.constant_str("with_epoch")
.optional("next_epoch_justify_qc", next_epoch_justify_qc);

if let Some(next_drb_result) = next_drb_result {
cb = cb
.constant_str("next_drb_result")
.fixed_size_bytes(next_drb_result);
}
}

cb.finalize()
}
}

Expand Down
71 changes: 46 additions & 25 deletions crates/types/src/simple_vote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,22 +355,31 @@ impl<TYPES: NodeType> Committable for QuorumData<TYPES> {

impl<TYPES: NodeType> Committable for QuorumData2<TYPES> {
fn commit(&self) -> Commitment<Self> {
let QuorumData2 {
leaf_commit,
epoch: _,
} = self;
let QuorumData2 { leaf_commit, epoch } = self;

committable::RawCommitmentBuilder::new("Quorum data")
.var_size_bytes(leaf_commit.as_ref())
.finalize()
let mut cb = committable::RawCommitmentBuilder::new("Quorum data")
.var_size_bytes(leaf_commit.as_ref());

if let Some(ref epoch) = *epoch {
cb = cb.u64_field("epoch number", **epoch);
}

cb.finalize()
}
}

impl<TYPES: NodeType> Committable for NextEpochQuorumData2<TYPES> {
fn commit(&self) -> Commitment<Self> {
committable::RawCommitmentBuilder::new("Quorum data")
.var_size_bytes(self.leaf_commit.as_ref())
.finalize()
let NextEpochQuorumData2(QuorumData2 { leaf_commit, epoch }) = self;

let mut cb = committable::RawCommitmentBuilder::new("Quorum data")
.var_size_bytes(leaf_commit.as_ref());

if let Some(ref epoch) = *epoch {
cb = cb.u64_field("epoch number", **epoch);
}

cb.finalize()
}
}

Expand Down Expand Up @@ -404,12 +413,17 @@ impl<TYPES: NodeType> Committable for DaData2<TYPES> {
fn commit(&self) -> Commitment<Self> {
let DaData2 {
payload_commit,
epoch: _,
epoch,
} = self;

committable::RawCommitmentBuilder::new("DA data")
.var_size_bytes(payload_commit.as_ref())
.finalize()
let mut cb = committable::RawCommitmentBuilder::new("DA data")
.var_size_bytes(payload_commit.as_ref());

if let Some(ref epoch) = *epoch {
cb = cb.u64_field("epoch number", **epoch);
}

cb.finalize()
}
}

Expand Down Expand Up @@ -446,7 +460,7 @@ impl<TYPES: NodeType> Committable for UpgradeData2<TYPES> {
.var_size_bytes(hash.as_slice());

if let Some(ref epoch) = *epoch {
cb = cb.u64(**epoch);
cb = cb.u64_field("epoch number", **epoch);
}

cb.finalize()
Expand All @@ -457,15 +471,22 @@ impl<TYPES: NodeType> Committable for UpgradeData2<TYPES> {
fn view_and_relay_commit<TYPES: NodeType, T: Committable>(
view: TYPES::View,
relay: u64,
epoch: Option<TYPES::Epoch>,
tag: &str,
) -> Commitment<T> {
let builder = committable::RawCommitmentBuilder::new(tag);
builder.u64(*view).u64(relay).finalize()
let mut cb = builder.u64(*view).u64(relay);

if let Some(epoch) = epoch {
cb = cb.u64_field("epoch number", *epoch);
}

cb.finalize()
}

impl<TYPES: NodeType> Committable for ViewSyncPreCommitData<TYPES> {
fn commit(&self) -> Commitment<Self> {
view_and_relay_commit::<TYPES, Self>(self.round, self.relay, "View Sync Precommit")
view_and_relay_commit::<TYPES, Self>(self.round, self.relay, None, "View Sync Precommit")
}
}

Expand All @@ -474,16 +495,16 @@ impl<TYPES: NodeType> Committable for ViewSyncPreCommitData2<TYPES> {
let ViewSyncPreCommitData2 {
relay,
round,
epoch: _,
epoch,
} = self;

view_and_relay_commit::<TYPES, Self>(*round, *relay, "View Sync Precommit")
view_and_relay_commit::<TYPES, Self>(*round, *relay, *epoch, "View Sync Precommit")
}
}

impl<TYPES: NodeType> Committable for ViewSyncFinalizeData<TYPES> {
fn commit(&self) -> Commitment<Self> {
view_and_relay_commit::<TYPES, Self>(self.round, self.relay, "View Sync Finalize")
view_and_relay_commit::<TYPES, Self>(self.round, self.relay, None, "View Sync Finalize")
}
}

Expand All @@ -492,16 +513,16 @@ impl<TYPES: NodeType> Committable for ViewSyncFinalizeData2<TYPES> {
let ViewSyncFinalizeData2 {
relay,
round,
epoch: _,
epoch,
} = self;

view_and_relay_commit::<TYPES, Self>(*round, *relay, "View Sync Finalize")
view_and_relay_commit::<TYPES, Self>(*round, *relay, *epoch, "View Sync Finalize")
}
}

impl<TYPES: NodeType> Committable for ViewSyncCommitData<TYPES> {
fn commit(&self) -> Commitment<Self> {
view_and_relay_commit::<TYPES, Self>(self.round, self.relay, "View Sync Commit")
view_and_relay_commit::<TYPES, Self>(self.round, self.relay, None, "View Sync Commit")
}
}

Expand All @@ -510,10 +531,10 @@ impl<TYPES: NodeType> Committable for ViewSyncCommitData2<TYPES> {
let ViewSyncCommitData2 {
relay,
round,
epoch: _,
epoch,
} = self;

view_and_relay_commit::<TYPES, Self>(*round, *relay, "View Sync Commit")
view_and_relay_commit::<TYPES, Self>(*round, *relay, *epoch, "View Sync Commit")
}
}

Expand Down

0 comments on commit b59bb78

Please sign in to comment.