use std::collections::BTreeMap;
use anyhow::Result;
use async_trait::async_trait;
use jf_vid::VidScheme;
use super::node_implementation::NodeType;
use crate::{
consensus::{CommitmentMap, View},
data::{
DaProposal, DaProposal2, Leaf, Leaf2, QuorumProposal, QuorumProposal2, VidDisperseShare,
VidDisperseShare2,
},
event::HotShotAction,
message::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<()>;
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<()>;
async fn append_proposal(
&self,
proposal: &Proposal<TYPES, QuorumProposal<TYPES>>,
) -> Result<()>;
async fn append_proposal2(
&self,
proposal: &Proposal<TYPES, QuorumProposal2<TYPES>>,
) -> Result<()>;
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<()>;
async fn update_next_epoch_high_qc2(
&self,
next_epoch_high_qc: NextEpochQuorumCertificate2<TYPES>,
) -> Result<()>;
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<()>;
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<()>;
}