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