consensus_core/storage/
mod.rspub(crate) mod mem_store;
pub(crate) mod rocksdb_store;
#[cfg(test)]
mod store_tests;
use consensus_config::AuthorityIndex;
use crate::{
block::{BlockRef, Round, Slot, VerifiedBlock},
commit::{CommitInfo, CommitRange, CommitRef, TrustedCommit},
error::ConsensusResult,
CommitIndex,
};
#[allow(unused)]
pub(crate) trait Store: Send + Sync {
fn write(&self, write_batch: WriteBatch) -> ConsensusResult<()>;
fn read_blocks(&self, refs: &[BlockRef]) -> ConsensusResult<Vec<Option<VerifiedBlock>>>;
fn contains_blocks(&self, refs: &[BlockRef]) -> ConsensusResult<Vec<bool>>;
fn contains_block_at_slot(&self, slot: Slot) -> ConsensusResult<bool>;
fn scan_blocks_by_author(
&self,
authority: AuthorityIndex,
start_round: Round,
) -> ConsensusResult<Vec<VerifiedBlock>>;
fn scan_last_blocks_by_author(
&self,
author: AuthorityIndex,
num_of_rounds: u64,
before_round: Option<Round>,
) -> ConsensusResult<Vec<VerifiedBlock>>;
fn read_last_commit(&self) -> ConsensusResult<Option<TrustedCommit>>;
fn scan_commits(&self, range: CommitRange) -> ConsensusResult<Vec<TrustedCommit>>;
fn read_commit_votes(&self, commit_index: CommitIndex) -> ConsensusResult<Vec<BlockRef>>;
fn read_last_commit_info(&self) -> ConsensusResult<Option<(CommitRef, CommitInfo)>>;
}
#[derive(Debug, Default)]
pub(crate) struct WriteBatch {
pub(crate) blocks: Vec<VerifiedBlock>,
pub(crate) commits: Vec<TrustedCommit>,
pub(crate) commit_info: Vec<(CommitRef, CommitInfo)>,
}
impl WriteBatch {
pub(crate) fn new(
blocks: Vec<VerifiedBlock>,
commits: Vec<TrustedCommit>,
commit_info: Vec<(CommitRef, CommitInfo)>,
) -> Self {
WriteBatch {
blocks,
commits,
commit_info,
}
}
#[cfg(test)]
pub(crate) fn blocks(mut self, blocks: Vec<VerifiedBlock>) -> Self {
self.blocks = blocks;
self
}
#[cfg(test)]
pub(crate) fn commits(mut self, commits: Vec<TrustedCommit>) -> Self {
self.commits = commits;
self
}
#[cfg(test)]
pub(crate) fn commit_info(mut self, commit_info: Vec<(CommitRef, CommitInfo)>) -> Self {
self.commit_info = commit_info;
self
}
}