mirror of
https://github.com/hinto-janai/cuprate.git
synced 2024-12-23 03:59:37 +00:00
Compare commits
5 commits
e7f052f1d0
...
c886f807dd
Author | SHA1 | Date | |
---|---|---|---|
|
c886f807dd | ||
|
4f9c5f12ab | ||
|
aaed13ad69 | ||
|
d0888c8cf3 | ||
|
2228d4d741 |
11 changed files with 27 additions and 90 deletions
|
@ -102,17 +102,14 @@ pub struct CupratedRpcHandler {
|
|||
/// Read handle to the blockchain database.
|
||||
pub blockchain_read: BlockchainReadHandle,
|
||||
|
||||
/// Write handle to the blockchain database.
|
||||
pub blockchain_write: BlockchainWriteHandle,
|
||||
|
||||
/// Handle to the blockchain manager.
|
||||
pub blockchain_manager: BlockchainManagerHandle,
|
||||
|
||||
/// Read handle to the transaction pool database.
|
||||
pub txpool_read: TxpoolReadHandle,
|
||||
|
||||
/// Write handle to the transaction pool database.
|
||||
pub txpool_write: TxpoolWriteHandle,
|
||||
/// TODO: handle to txpool service.
|
||||
pub txpool_manager: std::convert::Infallible,
|
||||
}
|
||||
|
||||
impl CupratedRpcHandler {
|
||||
|
@ -120,18 +117,16 @@ impl CupratedRpcHandler {
|
|||
pub const fn new(
|
||||
restricted: bool,
|
||||
blockchain_read: BlockchainReadHandle,
|
||||
blockchain_write: BlockchainWriteHandle,
|
||||
blockchain_manager: BlockchainManagerHandle,
|
||||
txpool_read: TxpoolReadHandle,
|
||||
txpool_write: TxpoolWriteHandle,
|
||||
txpool_manager: std::convert::Infallible,
|
||||
) -> Self {
|
||||
Self {
|
||||
restricted,
|
||||
blockchain_read,
|
||||
blockchain_write,
|
||||
blockchain_manager,
|
||||
txpool_read,
|
||||
txpool_write,
|
||||
txpool_manager,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -269,25 +269,6 @@ pub(super) async fn database_size(
|
|||
Ok((database_size, free_space))
|
||||
}
|
||||
|
||||
/// [`BlockchainReadRequest::Difficulty`]
|
||||
pub(super) async fn difficulty(
|
||||
mut blockchain_read: BlockchainReadHandle,
|
||||
block_height: u64,
|
||||
) -> Result<u128, Error> {
|
||||
let BlockchainResponse::Difficulty(difficulty) = blockchain_read
|
||||
.ready()
|
||||
.await?
|
||||
.call(BlockchainReadRequest::Difficulty(u64_to_usize(
|
||||
block_height,
|
||||
)))
|
||||
.await?
|
||||
else {
|
||||
unreachable!();
|
||||
};
|
||||
|
||||
Ok(difficulty)
|
||||
}
|
||||
|
||||
/// [`BlockchainReadRequest::OutputHistogram`]
|
||||
pub(super) async fn output_histogram(
|
||||
mut blockchain_read: BlockchainReadHandle,
|
||||
|
@ -325,19 +306,3 @@ pub(super) async fn coinbase_tx_sum(
|
|||
|
||||
Ok(sum)
|
||||
}
|
||||
|
||||
/// [`BlockchainReadRequest::MinerData`]
|
||||
pub(super) async fn miner_data(
|
||||
mut blockchain_read: BlockchainReadHandle,
|
||||
) -> Result<MinerData, Error> {
|
||||
let BlockchainResponse::MinerData(data) = blockchain_read
|
||||
.ready()
|
||||
.await?
|
||||
.call(BlockchainReadRequest::MinerData)
|
||||
.await?
|
||||
else {
|
||||
unreachable!();
|
||||
};
|
||||
|
||||
Ok(data)
|
||||
}
|
||||
|
|
|
@ -360,7 +360,7 @@ where
|
|||
let BlockChainContextResponse::RxVms(rx_vms) = context_svc
|
||||
.ready()
|
||||
.await?
|
||||
.call(BlockChainContextRequest::CurrentRxVm)
|
||||
.call(BlockChainContextRequest::CurrentRxVms)
|
||||
.await?
|
||||
else {
|
||||
panic!("Blockchain context service returned wrong response!");
|
||||
|
|
|
@ -136,7 +136,7 @@ where
|
|||
let BlockChainContextResponse::RxVms(rx_vms) = context_svc
|
||||
.ready()
|
||||
.await?
|
||||
.call(BlockChainContextRequest::CurrentRxVm)
|
||||
.call(BlockChainContextRequest::CurrentRxVms)
|
||||
.await?
|
||||
else {
|
||||
panic!("Blockchain context service returned wrong response!");
|
||||
|
|
|
@ -223,8 +223,8 @@ pub enum BlockChainContextRequest {
|
|||
/// Get the current blockchain context.
|
||||
Context,
|
||||
|
||||
/// Gets the current `RandomX` VM.
|
||||
CurrentRxVm,
|
||||
/// Gets all the current `RandomX` VMs.
|
||||
CurrentRxVms,
|
||||
|
||||
/// Get the next difficulties for these blocks.
|
||||
///
|
||||
|
@ -346,7 +346,7 @@ pub enum BlockChainContextResponse {
|
|||
/// Response to [`BlockChainContextRequest::Context`]
|
||||
Context(BlockChainContext),
|
||||
|
||||
/// Response to [`BlockChainContextRequest::CurrentRxVm`]
|
||||
/// Response to [`BlockChainContextRequest::CurrentRxVms`]
|
||||
///
|
||||
/// A map of seed height to `RandomX` VMs.
|
||||
RxVms(HashMap<usize, Arc<RandomXVm>>),
|
||||
|
|
|
@ -183,7 +183,7 @@ impl<D: Database + Clone + Send + 'static> ContextTask<D> {
|
|||
},
|
||||
})
|
||||
}
|
||||
BlockChainContextRequest::CurrentRxVm => {
|
||||
BlockChainContextRequest::CurrentRxVms => {
|
||||
BlockChainContextResponse::RxVms(self.rx_vm_cache.get_vms().await)
|
||||
}
|
||||
BlockChainContextRequest::BatchGetDifficulties(blocks) => {
|
||||
|
|
|
@ -6,14 +6,18 @@ use crate::NetZoneAddress;
|
|||
|
||||
/// Data within [`crate::services::AddressBookRequest::SetBan`].
|
||||
pub struct SetBan<A: NetZoneAddress> {
|
||||
/// Address of the peer.
|
||||
pub address: A,
|
||||
pub ban: bool,
|
||||
pub duration: Duration,
|
||||
/// - If [`Some`], how long this peer should be banned for
|
||||
/// - If [`None`], the peer will be unbanned
|
||||
pub ban: Option<Duration>,
|
||||
}
|
||||
|
||||
/// Data within [`crate::services::AddressBookResponse::GetBans`].
|
||||
pub struct BanState<A: NetZoneAddress> {
|
||||
/// Address of the peer.
|
||||
pub address: A,
|
||||
pub banned: bool,
|
||||
pub unban_instant: Instant,
|
||||
/// - If [`Some`], when this peer will be unbanned
|
||||
/// - If [`None`], the peer is not currently banned
|
||||
pub unban_instant: Option<Instant>,
|
||||
}
|
||||
|
|
|
@ -21,6 +21,11 @@
|
|||
//!
|
||||
//! The 2nd allows any caller to send [`WriteRequest`][req_w]s.
|
||||
//!
|
||||
//! The [`BlockchainReadHandle`] can be shared as it is cheaply [`Clone`]able.
|
||||
//!
|
||||
//! Although [`BlockchainWriteHandle`] can also be cloned, there is only 1 place
|
||||
//! in Cuprate that writes (the blockchain manager), so it is passed there and used.
|
||||
//!
|
||||
//! ## Initialization
|
||||
//! The database & thread-pool system can be initialized with [`init()`].
|
||||
//!
|
||||
|
|
|
@ -119,10 +119,8 @@ fn map_request(
|
|||
R::BlockByHash(hash) => block_by_hash(env, hash),
|
||||
R::TotalTxCount => total_tx_count(env),
|
||||
R::DatabaseSize => database_size(env),
|
||||
R::Difficulty(height) => difficulty(env, height),
|
||||
R::OutputHistogram(input) => output_histogram(env, input),
|
||||
R::CoinbaseTxSum { height, count } => coinbase_tx_sum(env, height, count),
|
||||
R::MinerData => miner_data(env),
|
||||
}
|
||||
|
||||
/* SOMEDAY: post-request handling, run some code for each request? */
|
||||
|
@ -641,11 +639,6 @@ fn database_size(env: &ConcreteEnv) -> ResponseResult {
|
|||
})
|
||||
}
|
||||
|
||||
/// [`BlockchainReadRequest::Difficulty()`]
|
||||
fn difficulty(env: &ConcreteEnv, block_height: BlockHeight) -> ResponseResult {
|
||||
Ok(BlockchainResponse::Difficulty(todo!()))
|
||||
}
|
||||
|
||||
/// [`BlockchainReadRequest::OutputHistogram`]
|
||||
fn output_histogram(env: &ConcreteEnv, input: OutputHistogramInput) -> ResponseResult {
|
||||
Ok(BlockchainResponse::OutputHistogram(todo!()))
|
||||
|
@ -655,8 +648,3 @@ fn output_histogram(env: &ConcreteEnv, input: OutputHistogramInput) -> ResponseR
|
|||
fn coinbase_tx_sum(env: &ConcreteEnv, height: usize, count: u64) -> ResponseResult {
|
||||
Ok(BlockchainResponse::CoinbaseTxSum(todo!()))
|
||||
}
|
||||
|
||||
/// [`BlockchainReadRequest::MinerData`]
|
||||
fn miner_data(env: &ConcreteEnv) -> ResponseResult {
|
||||
Ok(BlockchainResponse::MinerData(todo!()))
|
||||
}
|
||||
|
|
|
@ -21,9 +21,7 @@
|
|||
//!
|
||||
//! The 2nd allows any caller to send [`WriteRequest`][req_w]s.
|
||||
//!
|
||||
//! The `DatabaseReadHandle` can be shared as it is cheaply [`Clone`]able, however,
|
||||
//! the `DatabaseWriteHandle` cannot be cloned. There is only 1 place in Cuprate that
|
||||
//! writes, so it is passed there and used.
|
||||
//! Both the handles are cheaply [`Clone`]able.
|
||||
//!
|
||||
//! ## Initialization
|
||||
//! The database & thread-pool system can be initialized with [`init()`].
|
||||
|
|
|
@ -12,8 +12,7 @@ use monero_serai::block::Block;
|
|||
|
||||
use crate::{
|
||||
types::{Chain, ExtendedBlockHeader, OutputOnChain, VerifiedBlockInformation},
|
||||
AltBlockInformation, ChainId, CoinbaseTxSum, MinerData, OutputHistogramEntry,
|
||||
OutputHistogramInput,
|
||||
AltBlockInformation, ChainId, CoinbaseTxSum, OutputHistogramEntry, OutputHistogramInput,
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- ReadRequest
|
||||
|
@ -108,9 +107,7 @@ pub enum BlockchainReadRequest {
|
|||
AltBlocksInChain(ChainId),
|
||||
|
||||
/// Get a [`Block`] by its height.
|
||||
Block {
|
||||
height: usize,
|
||||
},
|
||||
Block { height: usize },
|
||||
|
||||
/// Get a [`Block`] by its hash.
|
||||
BlockByHash([u8; 32]),
|
||||
|
@ -121,9 +118,6 @@ pub enum BlockchainReadRequest {
|
|||
/// Get the current size of the database.
|
||||
DatabaseSize,
|
||||
|
||||
// Get the difficulty for the next block in the chain.
|
||||
Difficulty(usize),
|
||||
|
||||
/// Get an output histogram.
|
||||
///
|
||||
/// TODO: document fields after impl.
|
||||
|
@ -133,13 +127,7 @@ pub enum BlockchainReadRequest {
|
|||
/// `N` last blocks starting at particular height.
|
||||
///
|
||||
/// TODO: document fields after impl.
|
||||
CoinbaseTxSum {
|
||||
height: usize,
|
||||
count: u64,
|
||||
},
|
||||
|
||||
/// Get the necessary data to create a custom block template.
|
||||
MinerData,
|
||||
CoinbaseTxSum { height: usize, count: u64 },
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- WriteRequest
|
||||
|
@ -282,18 +270,12 @@ pub enum BlockchainResponse {
|
|||
free_space: u64,
|
||||
},
|
||||
|
||||
/// Response to [`BlockchainReadRequest::Difficulty`].
|
||||
Difficulty(u128),
|
||||
|
||||
/// Response to [`BlockchainReadRequest::OutputHistogram`].
|
||||
OutputHistogram(Vec<OutputHistogramEntry>),
|
||||
|
||||
/// Response to [`BlockchainReadRequest::CoinbaseTxSum`].
|
||||
CoinbaseTxSum(CoinbaseTxSum),
|
||||
|
||||
/// Response to [`BlockchainReadRequest::MinerData`].
|
||||
MinerData(MinerData),
|
||||
|
||||
//------------------------------------------------------ Writes
|
||||
/// A generic Ok response to indicate a request was successfully handled.
|
||||
///
|
||||
|
|
Loading…
Reference in a new issue