cuprate/consensus/src/lib.rs

97 lines
2.7 KiB
Rust
Raw Normal View History

2023-10-20 00:04:26 +00:00
use std::collections::{HashMap, HashSet};
pub mod block;
2023-09-03 22:50:38 +00:00
pub mod genesis;
pub mod hardforks;
mod helper;
pub mod miner_tx;
#[cfg(feature = "binaries")]
2023-09-03 22:50:38 +00:00
pub mod rpc;
2023-10-20 00:04:26 +00:00
pub mod transactions;
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-10-20 00:04:26 +00:00
#[error("Transaction sig invalid: {0}")]
TransactionSignatureInvalid(&'static str),
#[error("Transaction inputs overflow")]
TransactionInputsOverflow,
#[error("Transaction outputs overflow")]
TransactionOutputsOverflow,
#[error("Transaction has an invalid output: {0}")]
TransactionInvalidOutput(&'static str),
#[error("Transaction has an invalid version")]
TransactionVersionInvalid,
#[error("Transaction an invalid input: {0}")]
TransactionHasInvalidInput(&'static str),
#[error("Transaction has invalid ring: {0}")]
TransactionHasInvalidRing(&'static str),
#[error("Block has an invalid proof of work")]
BlockPOWInvalid,
#[error("Block has a timestamp outside of the valid range")]
BlockTimestampInvalid,
#[error("Block is too large")]
BlockIsTooLarge,
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,
2023-10-20 00:04:26 +00:00
Outputs(HashMap<u64, HashSet<u64>>),
NumberOutputsWithAmount(u64),
#[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::BlockPOWInfo),
BlockWeights(block::weight::BlockWeightInfo),
2023-10-05 16:54:19 +00:00
BlockHash([u8; 32]),
BlockHfInfoInRange(Vec<hardforks::BlockHFInfo>),
BlockWeightsInRange(Vec<block::BlockWeightInfo>),
BlockPOWInfoInRange(Vec<block::BlockPOWInfo>),
2023-09-03 22:50:38 +00:00
ChainHeight(u64),
2023-10-20 00:04:26 +00:00
Outputs(HashMap<u64, HashMap<u64, [curve25519_dalek::EdwardsPoint; 2]>>),
NumberOutputsWithAmount(usize),
#[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
}