use std::collections::BTreeMap;
use anyhow::Result;
use async_trait::async_trait;
use committable::Commitment;
use jf_vid::VidScheme;
use super::node_implementation::NodeType;
use crate::{
consensus::{CommitmentMap, View},
data::{
DaProposal, DaProposal2, Leaf, Leaf2, QuorumProposal, QuorumProposal2,
QuorumProposalWrapper, VidDisperseShare, VidDisperseShare2,
},
event::HotShotAction,
message::{convert_proposal, Proposal},
simple_certificate::{
NextEpochQuorumCertificate2, QuorumCertificate, QuorumCertificate2, UpgradeCertificate,
},
vid::VidSchemeType,
};
#[async_trait]
pub trait Storage<TYPES: NodeType>: Send + Sync + Clone {
async fn append_vid(&self, proposal: &Proposal<TYPES, VidDisperseShare<TYPES>>) -> Result<()>;
async fn append_vid2(
&self,
proposal: &Proposal<TYPES, VidDisperseShare2<TYPES>>,
) -> Result<()> {
self.append_vid(&convert_proposal(proposal.clone())).await
}
async fn append_da(
&self,
proposal: &Proposal<TYPES, DaProposal<TYPES>>,
vid_commit: <VidSchemeType as VidScheme>::Commit,
) -> Result<()>;
async fn append_da2(
&self,
proposal: &Proposal<TYPES, DaProposal2<TYPES>>,
vid_commit: <VidSchemeType as VidScheme>::Commit,
) -> Result<()> {
self.append_da(&convert_proposal(proposal.clone()), vid_commit)
.await
}
async fn append_proposal(
&self,
proposal: &Proposal<TYPES, QuorumProposal<TYPES>>,
) -> Result<()>;
async fn append_proposal2(
&self,
proposal: &Proposal<TYPES, QuorumProposal2<TYPES>>,
) -> Result<()> {
self.append_proposal(&convert_proposal(proposal.clone()))
.await
}
async fn append_proposal_wrapper(
&self,
proposal: &Proposal<TYPES, QuorumProposalWrapper<TYPES>>,
) -> Result<()> {
self.append_proposal(&convert_proposal(proposal.clone()))
.await
}
async fn record_action(&self, view: TYPES::View, action: HotShotAction) -> Result<()>;
async fn update_high_qc(&self, high_qc: QuorumCertificate<TYPES>) -> Result<()>;
async fn update_high_qc2(&self, high_qc: QuorumCertificate2<TYPES>) -> Result<()> {
self.update_high_qc(high_qc.to_qc()).await
}
async fn update_next_epoch_high_qc2(
&self,
_next_epoch_high_qc: NextEpochQuorumCertificate2<TYPES>,
) -> Result<()> {
Ok(())
}
async fn update_undecided_state(
&self,
leaves: CommitmentMap<Leaf<TYPES>>,
state: BTreeMap<TYPES::View, View<TYPES>>,
) -> Result<()>;
async fn update_undecided_state2(
&self,
leaves: CommitmentMap<Leaf2<TYPES>>,
state: BTreeMap<TYPES::View, View<TYPES>>,
) -> Result<()> {
self.update_undecided_state(
leaves
.iter()
.map(|(&commitment, leaf)| {
(
Commitment::from_raw(commitment.into()),
leaf.clone().to_leaf_unsafe(),
)
})
.collect(),
state,
)
.await
}
async fn update_decided_upgrade_certificate(
&self,
decided_upgrade_certificate: Option<UpgradeCertificate<TYPES>>,
) -> Result<()>;
async fn migrate_consensus(
&self,
_convert_leaf: fn(Leaf<TYPES>) -> Leaf2<TYPES>,
_convert_proposal: fn(
Proposal<TYPES, QuorumProposal<TYPES>>,
) -> Proposal<TYPES, QuorumProposal2<TYPES>>,
) -> Result<()> {
Ok(())
}
}