diff --git a/crates/types/src/data.rs b/crates/types/src/data.rs index 03738c1407..e84b2f03c1 100644 --- a/crates/types/src/data.rs +++ b/crates/types/src/data.rs @@ -997,6 +997,20 @@ impl Leaf2 { Ok(()) } + + /// Converts a `Leaf2` to a `Leaf`. This operation is fundamentally unsafe and should not be used. + pub fn to_leaf_unsafe(self) -> Leaf { + let bytes: [u8; 32] = self.parent_commitment.into(); + + Leaf { + view_number: self.view_number, + justify_qc: self.justify_qc.to_qc(), + parent_commitment: Commitment::from_raw(bytes), + block_header: self.block_header, + upgrade_certificate: self.upgrade_certificate, + block_payload: self.block_payload, + } + } } impl Committable for Leaf2 { diff --git a/crates/types/src/traits/storage.rs b/crates/types/src/traits/storage.rs index 5a4fdb4586..b52de7c66a 100644 --- a/crates/types/src/traits/storage.rs +++ b/crates/types/src/traits/storage.rs @@ -13,6 +13,7 @@ use std::collections::BTreeMap; use anyhow::Result; use async_trait::async_trait; +use committable::Commitment; use jf_vid::VidScheme; use super::node_implementation::NodeType; @@ -23,7 +24,7 @@ use crate::{ VidDisperseShare2, }, event::HotShotAction, - message::Proposal, + message::{convert_proposal, Proposal}, simple_certificate::{ NextEpochQuorumCertificate2, QuorumCertificate, QuorumCertificate2, UpgradeCertificate, }, @@ -36,8 +37,12 @@ pub trait Storage: Send + Sync + Clone { /// Add a proposal to the stored VID proposals. async fn append_vid(&self, proposal: &Proposal>) -> Result<()>; /// Add a proposal to the stored VID proposals. - async fn append_vid2(&self, proposal: &Proposal>) - -> Result<()>; + async fn append_vid2( + &self, + proposal: &Proposal>, + ) -> Result<()> { + self.append_vid2(&convert_proposal(proposal.clone())).await + } /// Add a proposal to the stored DA proposals. async fn append_da( &self, @@ -49,7 +54,10 @@ pub trait Storage: Send + Sync + Clone { &self, proposal: &Proposal>, vid_commit: ::Commit, - ) -> Result<()>; + ) -> Result<()> { + self.append_da(&convert_proposal(proposal.clone()), vid_commit) + .await + } /// Add a proposal we sent to the store async fn append_proposal( &self, @@ -59,18 +67,25 @@ pub trait Storage: Send + Sync + Clone { async fn append_proposal2( &self, proposal: &Proposal>, - ) -> Result<()>; + ) -> Result<()> { + self.append_proposal(&convert_proposal(proposal.clone())) + .await + } /// Record a HotShotAction taken. async fn record_action(&self, view: TYPES::View, action: HotShotAction) -> Result<()>; /// Update the current high QC in storage. async fn update_high_qc(&self, high_qc: QuorumCertificate) -> Result<()>; /// Update the current high QC in storage. - async fn update_high_qc2(&self, high_qc: QuorumCertificate2) -> Result<()>; + async fn update_high_qc2(&self, high_qc: QuorumCertificate2) -> Result<()> { + self.update_high_qc(high_qc.to_qc()).await + } /// Update the current high QC in storage. async fn update_next_epoch_high_qc2( &self, - next_epoch_high_qc: NextEpochQuorumCertificate2, - ) -> Result<()>; + _next_epoch_high_qc: NextEpochQuorumCertificate2, + ) -> Result<()> { + Ok(()) + } /// Update the currently undecided state of consensus. This includes the undecided leaf chain, /// and the undecided state. async fn update_undecided_state( @@ -84,7 +99,21 @@ pub trait Storage: Send + Sync + Clone { &self, leaves: CommitmentMap>, state: BTreeMap>, - ) -> Result<()>; + ) -> Result<()> { + self.update_undecided_state( + leaves + .iter() + .map(|(&commitment, &ref leaf)| { + ( + Commitment::from_raw(commitment.into()), + leaf.clone().to_leaf_unsafe(), + ) + }) + .collect(), + state, + ) + .await + } /// Upgrade the current decided upgrade certificate in storage. async fn update_decided_upgrade_certificate( &self, @@ -93,9 +122,11 @@ pub trait Storage: Send + Sync + Clone { /// Migrate leaves from `Leaf` to `Leaf2`, and proposals from `QuorumProposal` to `QuorumProposal2` async fn migrate_consensus( &self, - convert_leaf: fn(Leaf) -> Leaf2, - convert_proposal: fn( + _convert_leaf: fn(Leaf) -> Leaf2, + _convert_proposal: fn( Proposal>, ) -> Proposal>, - ) -> Result<()>; + ) -> Result<()> { + Ok(()) + } }