cuprate-hinto-janai/consensus/src/lib.rs
2023-10-15 20:35:33 +01:00

71 lines
1.8 KiB
Rust

pub mod block;
pub mod genesis;
pub mod hardforks;
mod helper;
pub mod miner_tx;
#[cfg(feature = "binaries")]
pub mod rpc;
pub mod verifier;
#[derive(Debug, thiserror::Error)]
pub enum ConsensusError {
#[error("Block has a timestamp outside of the valid range")]
BlockTimestampInvalid,
#[error("Block is too large")]
BlockIsTooLarge,
#[error("Invalid hard fork version: {0}")]
InvalidHardForkVersion(&'static str),
#[error("The block has a different previous hash than expected")]
BlockIsNotApartOfChain,
#[error("Database error: {0}")]
Database(#[from] tower::BoxError),
}
pub trait Database:
tower::Service<DatabaseRequest, Response = DatabaseResponse, Error = tower::BoxError>
{
}
impl<T: tower::Service<DatabaseRequest, Response = DatabaseResponse, Error = tower::BoxError>>
Database for T
{
}
#[derive(Debug, Clone)]
pub enum DatabaseRequest {
BlockHFInfo(cuprate_common::BlockID),
BlockPOWInfo(cuprate_common::BlockID),
BlockWeights(cuprate_common::BlockID),
BlockHash(u64),
BlockHfInfoInRange(std::ops::Range<u64>),
BlockWeightsInRange(std::ops::Range<u64>),
BlockPOWInfoInRange(std::ops::Range<u64>),
ChainHeight,
#[cfg(feature = "binaries")]
BlockBatchInRange(std::ops::Range<u64>),
}
#[derive(Debug)]
pub enum DatabaseResponse {
BlockHFInfo(hardforks::BlockHFInfo),
BlockPOWInfo(block::BlockPOWInfo),
BlockWeights(block::weight::BlockWeightInfo),
BlockHash([u8; 32]),
BlockHfInfoInRange(Vec<hardforks::BlockHFInfo>),
BlockWeightsInRange(Vec<block::BlockWeightInfo>),
BlockPOWInfoInRange(Vec<block::BlockPOWInfo>),
ChainHeight(u64),
#[cfg(feature = "binaries")]
BlockBatchInRange(
Vec<(
monero_serai::block::Block,
Vec<monero_serai::transaction::Transaction>,
)>,
),
}