cuprate/consensus/src/lib.rs

67 lines
1.7 KiB
Rust
Raw Normal View History

pub mod block;
2023-09-03 22:50:38 +00:00
pub mod genesis;
pub mod hardforks;
pub mod miner_tx;
#[cfg(feature = "binaries")]
2023-09-03 22:50:38 +00:00
pub mod rpc;
2023-10-04 13:50:13 +00:00
pub mod verifier;
2023-09-03 22:50:38 +00:00
#[derive(Debug, thiserror::Error)]
pub enum ConsensusError {
2023-09-03 22:50:38 +00:00
#[error("Invalid hard fork version: {0}")]
InvalidHardForkVersion(&'static str),
2023-10-05 16:54:19 +00:00
#[error("The block has a different previous hash than expected")]
BlockIsNotApartOfChain,
2023-09-03 22:50:38 +00:00
#[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)]
2023-09-03 22:50:38 +00:00
pub enum DatabaseRequest {
BlockHFInfo(cuprate_common::BlockID),
2023-09-06 14:54:49 +00:00
BlockPOWInfo(cuprate_common::BlockID),
BlockWeights(cuprate_common::BlockID),
2023-10-05 16:54:19 +00:00
BlockHash(u64),
BlockHfInfoInRange(std::ops::Range<u64>),
BlockWeightsInRange(std::ops::Range<u64>),
BlockPOWInfoInRange(std::ops::Range<u64>),
2023-09-03 22:50:38 +00:00
ChainHeight,
#[cfg(feature = "binaries")]
BlockBatchInRange(std::ops::Range<u64>),
2023-09-03 22:50:38 +00:00
}
#[derive(Debug)]
pub enum DatabaseResponse {
BlockHFInfo(hardforks::BlockHFInfo),
BlockPOWInfo(block::pow::BlockPOWInfo),
BlockWeights(block::weight::BlockWeightInfo),
2023-10-05 16:54:19 +00:00
BlockHash([u8; 32]),
BlockHfInfoInRange(Vec<hardforks::BlockHFInfo>),
BlockWeightsInRange(Vec<block::weight::BlockWeightInfo>),
BlockPOWInfoInRange(Vec<block::pow::BlockPOWInfo>),
2023-09-03 22:50:38 +00:00
ChainHeight(u64),
#[cfg(feature = "binaries")]
2023-10-05 16:54:19 +00:00
BlockBatchInRange(
Vec<(
monero_serai::block::Block,
Vec<monero_serai::transaction::Transaction>,
)>,
),
2023-09-03 22:50:38 +00:00
}