use std::collections::BTreeMap;
use derive_where::derive_where;
use malachitebft_core_types::Context;
pub mod types {
pub use malachitebft_core_consensus::full_proposal::{
Entry as FullProposalEntry, FullProposal, FullProposalKeeper,
};
pub use malachitebft_core_consensus::util::bounded_queue::BoundedQueue;
pub use malachitebft_core_consensus::Input as ConsensusInput;
pub use malachitebft_core_consensus::Params as ConsensusParams;
pub use malachitebft_core_driver::proposal_keeper::EvidenceMap as ProposalEvidenceMap;
pub use malachitebft_core_driver::proposal_keeper::PerRound as ProposalPerRound;
pub use malachitebft_core_state_machine::state::State;
pub use malachitebft_core_state_machine::state::Step;
pub use malachitebft_core_types::EnterRoundCertificate;
pub use malachitebft_core_types::ValuePayload;
pub use malachitebft_core_types::{Round, SignedVote, ThresholdParams};
pub use malachitebft_core_votekeeper::evidence::EvidenceMap as VoteEvidenceMap;
pub use malachitebft_core_votekeeper::keeper::PerRound as VotePerRound;
}
use self::types::*;
#[derive_where(Debug, Clone)]
pub struct VoteKeeperState<Ctx: Context> {
pub votes: BTreeMap<Round, VotePerRound<Ctx>>,
pub evidence: VoteEvidenceMap<Ctx>,
}
#[derive_where(Debug, Clone)]
pub struct ProposalKeeperState<Ctx: Context> {
pub proposals: BTreeMap<Round, ProposalPerRound<Ctx>>,
pub evidence: ProposalEvidenceMap<Ctx>,
}
#[derive_where(Debug, Clone)]
pub struct StateDump<Ctx: Context> {
pub consensus: State<Ctx>,
pub address: Ctx::Address,
pub proposer: Option<Ctx::Address>,
pub params: ConsensusParams<Ctx>,
pub validator_set: Ctx::ValidatorSet,
pub vote_keeper: VoteKeeperState<Ctx>,
pub proposal_keeper: ProposalKeeperState<Ctx>,
pub full_proposal_keeper: FullProposalKeeper<Ctx>,
pub last_signed_prevote: Option<SignedVote<Ctx>>,
pub last_signed_precommit: Option<SignedVote<Ctx>>,
pub round_certificate: Option<EnterRoundCertificate<Ctx>>,
pub input_queue: BoundedQueue<Ctx::Height, ConsensusInput<Ctx>>,
}
impl<Ctx: Context> StateDump<Ctx> {
pub fn new(state: &super::ConsensusState<Ctx>) -> Self {
Self {
consensus: state.driver.round_state().clone(),
address: state.address().clone(),
proposer: state.driver.proposer_address().cloned(),
params: state.params.clone(),
validator_set: state.validator_set().clone(),
vote_keeper: VoteKeeperState {
votes: state.driver.votes().all_rounds().clone(),
evidence: state.driver.votes().evidence().clone(),
},
proposal_keeper: ProposalKeeperState {
proposals: state.driver.proposals().all_rounds().clone(),
evidence: state.driver.proposals().evidence().clone(),
},
full_proposal_keeper: state.full_proposal_keeper.clone(),
last_signed_prevote: state.last_signed_prevote.clone(),
last_signed_precommit: state.last_signed_precommit.clone(),
round_certificate: state.driver.round_certificate().cloned(),
input_queue: state.input_queue.clone(),
}
}
}