mirror of
https://github.com/hinto-janai/cuprate.git
synced 2025-02-04 04:06:29 +00:00
Compare commits
No commits in common. "e2f25bd52decba7716ddd588030f0caf6079ec47" and "d7d8b3509e1ca94b19062a9407f4ab24d4422e0e" have entirely different histories.
e2f25bd52d
...
d7d8b3509e
11 changed files with 69 additions and 386 deletions
|
@ -3,13 +3,13 @@
|
||||||
use std::task::{Context, Poll};
|
use std::task::{Context, Poll};
|
||||||
|
|
||||||
use anyhow::Error;
|
use anyhow::Error;
|
||||||
|
use cuprate_consensus::BlockChainContextService;
|
||||||
|
use cuprate_pruning::PruningSeed;
|
||||||
use futures::future::BoxFuture;
|
use futures::future::BoxFuture;
|
||||||
use monero_serai::block::Block;
|
use monero_serai::block::Block;
|
||||||
use tower::Service;
|
use tower::Service;
|
||||||
|
|
||||||
use cuprate_blockchain::service::{BlockchainReadHandle, BlockchainWriteHandle};
|
use cuprate_blockchain::service::{BlockchainReadHandle, BlockchainWriteHandle};
|
||||||
use cuprate_consensus::BlockChainContextService;
|
|
||||||
use cuprate_pruning::PruningSeed;
|
|
||||||
use cuprate_rpc_interface::RpcHandler;
|
use cuprate_rpc_interface::RpcHandler;
|
||||||
use cuprate_rpc_types::{
|
use cuprate_rpc_types::{
|
||||||
bin::{BinRequest, BinResponse},
|
bin::{BinRequest, BinResponse},
|
||||||
|
@ -17,12 +17,12 @@ use cuprate_rpc_types::{
|
||||||
other::{OtherRequest, OtherResponse},
|
other::{OtherRequest, OtherResponse},
|
||||||
};
|
};
|
||||||
use cuprate_txpool::service::{TxpoolReadHandle, TxpoolWriteHandle};
|
use cuprate_txpool::service::{TxpoolReadHandle, TxpoolWriteHandle};
|
||||||
use cuprate_types::{AddAuxPow, AuxPow, HardFork};
|
|
||||||
|
|
||||||
use crate::rpc::{bin, json, other};
|
use crate::rpc::{bin, json, other};
|
||||||
|
|
||||||
/// TODO: use real type when public.
|
/// TODO: use real type when public.
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
#[expect(clippy::large_enum_variant)]
|
||||||
pub enum BlockchainManagerRequest {
|
pub enum BlockchainManagerRequest {
|
||||||
/// Pop blocks off the top of the blockchain.
|
/// Pop blocks off the top of the blockchain.
|
||||||
///
|
///
|
||||||
|
@ -56,38 +56,6 @@ pub enum BlockchainManagerRequest {
|
||||||
|
|
||||||
/// The height of the next block in the chain.
|
/// The height of the next block in the chain.
|
||||||
TargetHeight,
|
TargetHeight,
|
||||||
|
|
||||||
/// Calculate proof-of-work for this block.
|
|
||||||
CalculatePow {
|
|
||||||
/// The hardfork of the protocol at this block height.
|
|
||||||
hardfork: HardFork,
|
|
||||||
/// The height of the block.
|
|
||||||
height: usize,
|
|
||||||
/// The block data.
|
|
||||||
block: Block,
|
|
||||||
/// The seed hash for the proof-of-work.
|
|
||||||
seed_hash: [u8; 32],
|
|
||||||
},
|
|
||||||
|
|
||||||
/// TODO
|
|
||||||
AddAuxPow {
|
|
||||||
/// TODO
|
|
||||||
blocktemplate_blob: Vec<u8>,
|
|
||||||
/// TODO
|
|
||||||
aux_pow: Vec<AuxPow>,
|
|
||||||
},
|
|
||||||
|
|
||||||
/// TODO
|
|
||||||
GenerateBlocks {
|
|
||||||
/// TODO
|
|
||||||
amount_of_blocks: u64,
|
|
||||||
/// TODO
|
|
||||||
prev_block: [u8; 32],
|
|
||||||
/// TODO
|
|
||||||
starting_nonce: u32,
|
|
||||||
/// TODO
|
|
||||||
wallet_address: String,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// TODO: use real type when public.
|
/// TODO: use real type when public.
|
||||||
|
@ -120,20 +88,6 @@ pub enum BlockchainManagerResponse {
|
||||||
|
|
||||||
/// Response to [`BlockchainManagerRequest::TargetHeight`]
|
/// Response to [`BlockchainManagerRequest::TargetHeight`]
|
||||||
TargetHeight { height: usize },
|
TargetHeight { height: usize },
|
||||||
|
|
||||||
/// Response to [`BlockchainManagerRequest::CalculatePow`]
|
|
||||||
CalculatePow([u8; 32]),
|
|
||||||
|
|
||||||
/// Response to [`BlockchainManagerRequest::AddAuxPow`]
|
|
||||||
AddAuxPow(AddAuxPow),
|
|
||||||
|
|
||||||
/// Response to [`BlockchainManagerRequest::GenerateBlocks`]
|
|
||||||
GenerateBlocks {
|
|
||||||
/// TODO
|
|
||||||
blocks: Vec<[u8; 32]>,
|
|
||||||
/// TODO
|
|
||||||
height: usize,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// TODO: use real type when public.
|
/// TODO: use real type when public.
|
||||||
|
|
|
@ -40,22 +40,15 @@ use cuprate_rpc_types::{
|
||||||
SetBansRequest, SetBansResponse, SubmitBlockRequest, SubmitBlockResponse, SyncInfoRequest,
|
SetBansRequest, SetBansResponse, SubmitBlockRequest, SubmitBlockResponse, SyncInfoRequest,
|
||||||
SyncInfoResponse,
|
SyncInfoResponse,
|
||||||
},
|
},
|
||||||
misc::{
|
misc::{BlockHeader, ChainInfo, GetBan, HardforkEntry, HistogramEntry, Status, TxBacklogEntry},
|
||||||
AuxPow, BlockHeader, ChainInfo, GetBan, HardforkEntry, HistogramEntry, Status,
|
|
||||||
TxBacklogEntry,
|
|
||||||
},
|
|
||||||
CORE_RPC_VERSION,
|
CORE_RPC_VERSION,
|
||||||
};
|
};
|
||||||
use cuprate_types::{Chain, HardFork};
|
use cuprate_types::HardFork;
|
||||||
|
|
||||||
use crate::{
|
use crate::rpc::{
|
||||||
constants::VERSION_BUILD,
|
|
||||||
rpc::{
|
|
||||||
helper,
|
helper,
|
||||||
request::{address_book, blockchain, blockchain_context, blockchain_manager, txpool},
|
request::{address_book, blockchain, blockchain_context, blockchain_manager, txpool},
|
||||||
CupratedRpcHandler,
|
CupratedRpcHandler,
|
||||||
},
|
|
||||||
statics::START_INSTANT_UNIX,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Map a [`JsonRpcRequest`] to the function that will lead to a [`JsonRpcResponse`].
|
/// Map a [`JsonRpcRequest`] to the function that will lead to a [`JsonRpcResponse`].
|
||||||
|
@ -165,29 +158,10 @@ async fn generate_blocks(
|
||||||
state: CupratedRpcHandler,
|
state: CupratedRpcHandler,
|
||||||
request: GenerateBlocksRequest,
|
request: GenerateBlocksRequest,
|
||||||
) -> Result<GenerateBlocksResponse, Error> {
|
) -> Result<GenerateBlocksResponse, Error> {
|
||||||
if todo!("active cuprated chain") != todo!("regtest chain") {
|
|
||||||
return Err(anyhow!("Regtest required when generating blocks"));
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: is this value only used as a local variable in the handler?
|
|
||||||
// it may not be needed in the request type.
|
|
||||||
let prev_block = helper::hex_to_hash(request.prev_block)?;
|
|
||||||
|
|
||||||
let (blocks, height) = blockchain_manager::generate_blocks(
|
|
||||||
&mut state.blockchain_manager,
|
|
||||||
request.amount_of_blocks,
|
|
||||||
prev_block,
|
|
||||||
request.starting_nonce,
|
|
||||||
request.wallet_address,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
let blocks = blocks.into_iter().map(hex::encode).collect();
|
|
||||||
|
|
||||||
Ok(GenerateBlocksResponse {
|
Ok(GenerateBlocksResponse {
|
||||||
base: ResponseBase::OK,
|
base: ResponseBase::OK,
|
||||||
blocks,
|
blocks: todo!(),
|
||||||
height,
|
height: todo!(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -357,120 +331,50 @@ async fn get_connections(
|
||||||
|
|
||||||
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L501-L582>
|
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L501-L582>
|
||||||
async fn get_info(
|
async fn get_info(
|
||||||
mut state: CupratedRpcHandler,
|
state: CupratedRpcHandler,
|
||||||
request: GetInfoRequest,
|
request: GetInfoRequest,
|
||||||
) -> Result<GetInfoResponse, Error> {
|
) -> Result<GetInfoResponse, Error> {
|
||||||
let restricted = state.restricted();
|
|
||||||
let context = blockchain_context::context(&mut state.blockchain_context).await?;
|
|
||||||
|
|
||||||
let c = context.unchecked_blockchain_context();
|
|
||||||
let cumulative_difficulty = c.cumulative_difficulty;
|
|
||||||
let adjusted_time = c.current_adjusted_timestamp_for_time_lock(); // TODO: is this correct?
|
|
||||||
|
|
||||||
let c = &c.context_to_verify_block;
|
|
||||||
|
|
||||||
let alt_blocks_count = if restricted {
|
|
||||||
0
|
|
||||||
} else {
|
|
||||||
blockchain::alt_chain_count(&mut state.blockchain_read).await?
|
|
||||||
};
|
|
||||||
let block_weight_limit = usize_to_u64(c.effective_median_weight); // TODO: is this correct?
|
|
||||||
let block_weight_median = usize_to_u64(c.median_weight_for_block_reward); // TODO: is this correct?
|
|
||||||
let block_size_limit = block_weight_limit;
|
|
||||||
let block_size_median = block_weight_median;
|
|
||||||
let (bootstrap_daemon_address, was_bootstrap_ever_used) = if restricted {
|
|
||||||
(String::new(), false)
|
|
||||||
} else {
|
|
||||||
todo!()
|
|
||||||
};
|
|
||||||
let busy_syncing = blockchain_manager::syncing(&mut state.blockchain_manager).await?;
|
|
||||||
let (cumulative_difficulty, cumulative_difficulty_top64) =
|
|
||||||
split_u128_into_low_high_bits(cumulative_difficulty);
|
|
||||||
let (database_size, free_space) = blockchain::database_size(&mut state.blockchain_read).await?;
|
|
||||||
let (database_size, free_space) = if restricted {
|
|
||||||
let database_size = todo!(); // round_up(res.database_size, 5ull* 1024 * 1024 * 1024) */
|
|
||||||
(database_size, u64::MAX)
|
|
||||||
} else {
|
|
||||||
(database_size, free_space)
|
|
||||||
};
|
|
||||||
let (difficulty, difficulty_top64) = split_u128_into_low_high_bits(c.next_difficulty);
|
|
||||||
let height = usize_to_u64(c.chain_height);
|
|
||||||
let height_without_bootstrap = if restricted { 0 } else { height };
|
|
||||||
let (incoming_connections_count, outgoing_connections_count) = if restricted {
|
|
||||||
(0, 0)
|
|
||||||
} else {
|
|
||||||
address_book::connection_count::<ClearNet>(&mut DummyAddressBook).await?
|
|
||||||
};
|
|
||||||
let mainnet = todo!();
|
|
||||||
let nettype = todo!();
|
|
||||||
let offline = todo!();
|
|
||||||
let rpc_connections_count = if restricted { 0 } else { todo!() };
|
|
||||||
let stagenet = todo!();
|
|
||||||
let start_time = if restricted { 0 } else { *START_INSTANT_UNIX };
|
|
||||||
let synchronized = blockchain_manager::synced(&mut state.blockchain_manager).await?;
|
|
||||||
let target_height = blockchain_manager::target_height(&mut state.blockchain_manager).await?;
|
|
||||||
let target = blockchain_manager::target(&mut state.blockchain_manager)
|
|
||||||
.await?
|
|
||||||
.as_secs();
|
|
||||||
let testnet = todo!();
|
|
||||||
let top_block_hash = hex::encode(c.top_hash);
|
|
||||||
let tx_count = blockchain::total_tx_count(&mut state.blockchain_read).await?;
|
|
||||||
let tx_pool_size = txpool::size(&mut state.txpool_read, !restricted).await?;
|
|
||||||
let update_available = if restricted { false } else { todo!() };
|
|
||||||
let version = if restricted {
|
|
||||||
String::new()
|
|
||||||
} else {
|
|
||||||
VERSION_BUILD.to_string()
|
|
||||||
};
|
|
||||||
let (white_peerlist_size, grey_peerlist_size) = if restricted {
|
|
||||||
(0, 0)
|
|
||||||
} else {
|
|
||||||
address_book::peerlist_size::<ClearNet>(&mut DummyAddressBook).await?
|
|
||||||
};
|
|
||||||
let wide_cumulative_difficulty = format!("{cumulative_difficulty:#x}");
|
|
||||||
let wide_difficulty = format!("{:#x}", c.next_difficulty);
|
|
||||||
|
|
||||||
Ok(GetInfoResponse {
|
Ok(GetInfoResponse {
|
||||||
base: AccessResponseBase::OK,
|
base: AccessResponseBase::OK,
|
||||||
adjusted_time,
|
adjusted_time: todo!(),
|
||||||
alt_blocks_count,
|
alt_blocks_count: todo!(),
|
||||||
block_size_limit,
|
block_size_limit: todo!(),
|
||||||
block_size_median,
|
block_size_median: todo!(),
|
||||||
block_weight_limit,
|
block_weight_limit: todo!(),
|
||||||
block_weight_median,
|
block_weight_median: todo!(),
|
||||||
bootstrap_daemon_address,
|
bootstrap_daemon_address: todo!(),
|
||||||
busy_syncing,
|
busy_syncing: todo!(),
|
||||||
cumulative_difficulty_top64,
|
cumulative_difficulty_top64: todo!(),
|
||||||
cumulative_difficulty,
|
cumulative_difficulty: todo!(),
|
||||||
database_size,
|
database_size: todo!(),
|
||||||
difficulty_top64,
|
difficulty_top64: todo!(),
|
||||||
difficulty,
|
difficulty: todo!(),
|
||||||
free_space,
|
free_space: todo!(),
|
||||||
grey_peerlist_size,
|
grey_peerlist_size: todo!(),
|
||||||
height,
|
height: todo!(),
|
||||||
height_without_bootstrap,
|
height_without_bootstrap: todo!(),
|
||||||
incoming_connections_count,
|
incoming_connections_count: todo!(),
|
||||||
mainnet,
|
mainnet: todo!(),
|
||||||
nettype,
|
nettype: todo!(),
|
||||||
offline,
|
offline: todo!(),
|
||||||
outgoing_connections_count,
|
outgoing_connections_count: todo!(),
|
||||||
restricted,
|
restricted: todo!(),
|
||||||
rpc_connections_count,
|
rpc_connections_count: todo!(),
|
||||||
stagenet,
|
stagenet: todo!(),
|
||||||
start_time,
|
start_time: todo!(),
|
||||||
synchronized,
|
synchronized: todo!(),
|
||||||
target_height,
|
target_height: todo!(),
|
||||||
target,
|
target: todo!(),
|
||||||
testnet,
|
testnet: todo!(),
|
||||||
top_block_hash,
|
top_block_hash: todo!(),
|
||||||
tx_count,
|
tx_count: todo!(),
|
||||||
tx_pool_size,
|
tx_pool_size: todo!(),
|
||||||
update_available,
|
update_available: todo!(),
|
||||||
version,
|
version: todo!(),
|
||||||
was_bootstrap_ever_used,
|
was_bootstrap_ever_used: todo!(),
|
||||||
white_peerlist_size,
|
white_peerlist_size: todo!(),
|
||||||
wide_cumulative_difficulty,
|
wide_cumulative_difficulty: todo!(),
|
||||||
wide_difficulty,
|
wide_difficulty: todo!(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -830,26 +734,10 @@ async fn prune_blockchain(
|
||||||
|
|
||||||
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L2035-L2070>
|
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L2035-L2070>
|
||||||
async fn calc_pow(
|
async fn calc_pow(
|
||||||
mut state: CupratedRpcHandler,
|
state: CupratedRpcHandler,
|
||||||
mut request: CalcPowRequest,
|
request: CalcPowRequest,
|
||||||
) -> Result<CalcPowResponse, Error> {
|
) -> Result<CalcPowResponse, Error> {
|
||||||
let hardfork = HardFork::from_version(request.major_version)?;
|
Ok(CalcPowResponse { pow_hash: todo!() })
|
||||||
let mut block_blob: Vec<u8> = hex::decode(request.block_blob)?;
|
|
||||||
let block = Block::read(&mut block_blob.as_slice())?;
|
|
||||||
let seed_hash = helper::hex_to_hash(request.seed_hash)?;
|
|
||||||
|
|
||||||
let pow_hash = blockchain_manager::calculate_pow(
|
|
||||||
&mut state.blockchain_manager,
|
|
||||||
hardfork,
|
|
||||||
request.height,
|
|
||||||
block,
|
|
||||||
seed_hash,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
let hex = hex::encode(pow_hash);
|
|
||||||
|
|
||||||
Ok(CalcPowResponse { pow_hash: hex })
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L3542-L3551>
|
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L3542-L3551>
|
||||||
|
@ -857,7 +745,7 @@ async fn flush_cache(
|
||||||
state: CupratedRpcHandler,
|
state: CupratedRpcHandler,
|
||||||
request: FlushCacheRequest,
|
request: FlushCacheRequest,
|
||||||
) -> Result<FlushCacheResponse, Error> {
|
) -> Result<FlushCacheResponse, Error> {
|
||||||
// TODO: cuprated doesn't need this call; decide behavior.
|
todo!();
|
||||||
|
|
||||||
Ok(FlushCacheResponse {
|
Ok(FlushCacheResponse {
|
||||||
base: ResponseBase::OK,
|
base: ResponseBase::OK,
|
||||||
|
@ -866,43 +754,16 @@ async fn flush_cache(
|
||||||
|
|
||||||
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L2072-L2207>
|
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L2072-L2207>
|
||||||
async fn add_aux_pow(
|
async fn add_aux_pow(
|
||||||
mut state: CupratedRpcHandler,
|
state: CupratedRpcHandler,
|
||||||
request: AddAuxPowRequest,
|
request: AddAuxPowRequest,
|
||||||
) -> Result<AddAuxPowResponse, Error> {
|
) -> Result<AddAuxPowResponse, Error> {
|
||||||
let blocktemplate_blob = hex::decode(request.blocktemplate_blob)?;
|
|
||||||
let aux_pow = request
|
|
||||||
.aux_pow
|
|
||||||
.into_iter()
|
|
||||||
.map(|aux| {
|
|
||||||
let id = helper::hex_to_hash(aux.id)?;
|
|
||||||
let hash = helper::hex_to_hash(aux.hash)?;
|
|
||||||
Ok(cuprate_types::AuxPow { id, hash })
|
|
||||||
})
|
|
||||||
.collect::<Result<Vec<_>, Error>>()?;
|
|
||||||
|
|
||||||
let resp =
|
|
||||||
blockchain_manager::add_aux_pow(&mut state.blockchain_manager, blocktemplate_blob, aux_pow)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
let blocktemplate_blob = hex::encode(resp.blocktemplate_blob);
|
|
||||||
let blockhashing_blob = hex::encode(resp.blockhashing_blob);
|
|
||||||
let merkle_root = hex::encode(resp.merkle_root);
|
|
||||||
let aux_pow = resp
|
|
||||||
.aux_pow
|
|
||||||
.into_iter()
|
|
||||||
.map(|aux| AuxPow {
|
|
||||||
id: hex::encode(aux.id),
|
|
||||||
hash: hex::encode(aux.hash),
|
|
||||||
})
|
|
||||||
.collect::<Vec<AuxPow>>();
|
|
||||||
|
|
||||||
Ok(AddAuxPowResponse {
|
Ok(AddAuxPowResponse {
|
||||||
base: ResponseBase::OK,
|
base: ResponseBase::OK,
|
||||||
blocktemplate_blob,
|
blocktemplate_blob: todo!(),
|
||||||
blockhashing_blob,
|
blockhashing_blob: todo!(),
|
||||||
merkle_root,
|
merkle_root: todo!(),
|
||||||
merkle_tree_depth: resp.merkle_tree_depth,
|
merkle_tree_depth: todo!(),
|
||||||
aux_pow,
|
aux_pow: todo!(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -911,9 +772,6 @@ async fn get_tx_ids_loose(
|
||||||
state: CupratedRpcHandler,
|
state: CupratedRpcHandler,
|
||||||
request: GetTxIdsLooseRequest,
|
request: GetTxIdsLooseRequest,
|
||||||
) -> Result<GetTxIdsLooseResponse, Error> {
|
) -> Result<GetTxIdsLooseResponse, Error> {
|
||||||
// TODO: this RPC call is not yet in the v0.18 branch.
|
|
||||||
return Err(anyhow!("not implemented"));
|
|
||||||
|
|
||||||
Ok(GetTxIdsLooseResponse {
|
Ok(GetTxIdsLooseResponse {
|
||||||
base: ResponseBase::OK,
|
base: ResponseBase::OK,
|
||||||
txids: todo!(),
|
txids: todo!(),
|
||||||
|
|
|
@ -375,19 +375,3 @@ pub(crate) async fn alt_chains(
|
||||||
|
|
||||||
Ok(vec)
|
Ok(vec)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// [`BlockchainReadRequest::AltChainCount`]
|
|
||||||
pub(crate) async fn alt_chain_count(
|
|
||||||
blockchain_read: &mut BlockchainReadHandle,
|
|
||||||
) -> Result<u64, Error> {
|
|
||||||
let BlockchainResponse::AltChainCount(count) = blockchain_read
|
|
||||||
.ready()
|
|
||||||
.await?
|
|
||||||
.call(BlockchainReadRequest::AltChainCount)
|
|
||||||
.await?
|
|
||||||
else {
|
|
||||||
unreachable!();
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(usize_to_u64(count))
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
//! Functions for [`BlockchainManagerRequest`] & [`BlockchainManagerResponse`].
|
//! Functions for [`BlockchainManagerRequest`] & [`BlockchainManagerResponse`].
|
||||||
|
|
||||||
use anyhow::Error;
|
use anyhow::Error;
|
||||||
use cuprate_types::{AddAuxPow, AuxPow, HardFork};
|
|
||||||
use monero_serai::block::Block;
|
use monero_serai::block::Block;
|
||||||
use tower::{Service, ServiceExt};
|
use tower::{Service, ServiceExt};
|
||||||
|
|
||||||
|
@ -143,74 +142,3 @@ pub(crate) async fn target_height(
|
||||||
|
|
||||||
Ok(usize_to_u64(height))
|
Ok(usize_to_u64(height))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// [`BlockchainManagerRequest::CalculatePow`]
|
|
||||||
pub(crate) async fn calculate_pow(
|
|
||||||
blockchain_manager: &mut BlockchainManagerHandle,
|
|
||||||
hardfork: HardFork,
|
|
||||||
height: u64,
|
|
||||||
block: Block,
|
|
||||||
seed_hash: [u8; 32],
|
|
||||||
) -> Result<[u8; 32], Error> {
|
|
||||||
let BlockchainManagerResponse::CalculatePow(hash) = blockchain_manager
|
|
||||||
.ready()
|
|
||||||
.await?
|
|
||||||
.call(BlockchainManagerRequest::CalculatePow {
|
|
||||||
hardfork,
|
|
||||||
height: u64_to_usize(height),
|
|
||||||
block,
|
|
||||||
seed_hash,
|
|
||||||
})
|
|
||||||
.await?
|
|
||||||
else {
|
|
||||||
unreachable!();
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(hash)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// [`BlockchainManagerRequest::AddAuxPow`]
|
|
||||||
pub(crate) async fn add_aux_pow(
|
|
||||||
blockchain_manager: &mut BlockchainManagerHandle,
|
|
||||||
blocktemplate_blob: Vec<u8>,
|
|
||||||
aux_pow: Vec<AuxPow>,
|
|
||||||
) -> Result<AddAuxPow, Error> {
|
|
||||||
let BlockchainManagerResponse::AddAuxPow(response) = blockchain_manager
|
|
||||||
.ready()
|
|
||||||
.await?
|
|
||||||
.call(BlockchainManagerRequest::AddAuxPow {
|
|
||||||
blocktemplate_blob,
|
|
||||||
aux_pow,
|
|
||||||
})
|
|
||||||
.await?
|
|
||||||
else {
|
|
||||||
unreachable!();
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(response)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// [`BlockchainManagerRequest::GenerateBlocks`]
|
|
||||||
pub(crate) async fn generate_blocks(
|
|
||||||
blockchain_manager: &mut BlockchainManagerHandle,
|
|
||||||
amount_of_blocks: u64,
|
|
||||||
prev_block: [u8; 32],
|
|
||||||
starting_nonce: u32,
|
|
||||||
wallet_address: String,
|
|
||||||
) -> Result<(Vec<[u8; 32]>, u64), Error> {
|
|
||||||
let BlockchainManagerResponse::GenerateBlocks { blocks, height } = blockchain_manager
|
|
||||||
.ready()
|
|
||||||
.await?
|
|
||||||
.call(BlockchainManagerRequest::GenerateBlocks {
|
|
||||||
amount_of_blocks,
|
|
||||||
prev_block,
|
|
||||||
starting_nonce,
|
|
||||||
wallet_address,
|
|
||||||
})
|
|
||||||
.await?
|
|
||||||
else {
|
|
||||||
unreachable!();
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok((blocks, usize_to_u64(height)))
|
|
||||||
}
|
|
||||||
|
|
|
@ -33,17 +33,12 @@ pub(crate) async fn backlog(txpool_read: &mut TxpoolReadHandle) -> Result<Vec<Tx
|
||||||
}
|
}
|
||||||
|
|
||||||
/// [`TxpoolReadRequest::Size`]
|
/// [`TxpoolReadRequest::Size`]
|
||||||
pub(crate) async fn size(
|
pub(crate) async fn size(txpool_read: &mut TxpoolReadHandle) -> Result<u64, Error> {
|
||||||
txpool_read: &mut TxpoolReadHandle,
|
|
||||||
include_sensitive_txs: bool,
|
|
||||||
) -> Result<u64, Error> {
|
|
||||||
let TxpoolReadResponse::Size(size) = txpool_read
|
let TxpoolReadResponse::Size(size) = txpool_read
|
||||||
.ready()
|
.ready()
|
||||||
.await
|
.await
|
||||||
.map_err(|e| anyhow!(e))?
|
.map_err(|e| anyhow!(e))?
|
||||||
.call(TxpoolReadRequest::Size {
|
.call(TxpoolReadRequest::Size)
|
||||||
include_sensitive_txs,
|
|
||||||
})
|
|
||||||
.await
|
.await
|
||||||
.map_err(|e| anyhow!(e))?
|
.map_err(|e| anyhow!(e))?
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -123,7 +123,6 @@ fn map_request(
|
||||||
R::CoinbaseTxSum { height, count } => coinbase_tx_sum(env, height, count),
|
R::CoinbaseTxSum { height, count } => coinbase_tx_sum(env, height, count),
|
||||||
R::HardForks => hard_forks(env),
|
R::HardForks => hard_forks(env),
|
||||||
R::AltChains => alt_chains(env),
|
R::AltChains => alt_chains(env),
|
||||||
R::AltChainCount => alt_chain_count(env),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* SOMEDAY: post-request handling, run some code for each request? */
|
/* SOMEDAY: post-request handling, run some code for each request? */
|
||||||
|
@ -661,8 +660,3 @@ fn hard_forks(env: &ConcreteEnv) -> ResponseResult {
|
||||||
fn alt_chains(env: &ConcreteEnv) -> ResponseResult {
|
fn alt_chains(env: &ConcreteEnv) -> ResponseResult {
|
||||||
Ok(BlockchainResponse::AltChains(todo!()))
|
Ok(BlockchainResponse::AltChains(todo!()))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// [`BlockchainReadRequest::AltChainCount`]
|
|
||||||
fn alt_chain_count(env: &ConcreteEnv) -> ResponseResult {
|
|
||||||
Ok(BlockchainResponse::AltChainCount(todo!()))
|
|
||||||
}
|
|
||||||
|
|
|
@ -20,10 +20,7 @@ pub enum TxpoolReadRequest {
|
||||||
Backlog,
|
Backlog,
|
||||||
|
|
||||||
/// Get the number of transactions in the pool.
|
/// Get the number of transactions in the pool.
|
||||||
Size {
|
Size,
|
||||||
/// TODO
|
|
||||||
include_sensitive_txs: bool,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------- TxpoolReadResponse
|
//---------------------------------------------------------------------------------------------------- TxpoolReadResponse
|
||||||
|
|
|
@ -66,9 +66,7 @@ fn map_request(
|
||||||
TxpoolReadRequest::TxBlob(tx_hash) => tx_blob(env, &tx_hash),
|
TxpoolReadRequest::TxBlob(tx_hash) => tx_blob(env, &tx_hash),
|
||||||
TxpoolReadRequest::TxVerificationData(tx_hash) => tx_verification_data(env, &tx_hash),
|
TxpoolReadRequest::TxVerificationData(tx_hash) => tx_verification_data(env, &tx_hash),
|
||||||
TxpoolReadRequest::Backlog => backlog(env),
|
TxpoolReadRequest::Backlog => backlog(env),
|
||||||
TxpoolReadRequest::Size {
|
TxpoolReadRequest::Size => size(env),
|
||||||
include_sensitive_txs,
|
|
||||||
} => size(env, include_sensitive_txs),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,6 +119,6 @@ fn backlog(env: &ConcreteEnv) -> ReadResponseResult {
|
||||||
|
|
||||||
/// [`TxpoolReadRequest::Size`].
|
/// [`TxpoolReadRequest::Size`].
|
||||||
#[inline]
|
#[inline]
|
||||||
fn size(env: &ConcreteEnv, include_sensitive_txs: bool) -> ReadResponseResult {
|
fn size(env: &ConcreteEnv) -> ReadResponseResult {
|
||||||
Ok(TxpoolReadResponse::Size(todo!()))
|
Ok(TxpoolReadResponse::Size(todo!()))
|
||||||
}
|
}
|
||||||
|
|
|
@ -135,9 +135,6 @@ pub enum BlockchainReadRequest {
|
||||||
|
|
||||||
/// TODO
|
/// TODO
|
||||||
AltChains,
|
AltChains,
|
||||||
|
|
||||||
/// TODO
|
|
||||||
AltChainCount,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------- WriteRequest
|
//---------------------------------------------------------------------------------------------------- WriteRequest
|
||||||
|
@ -292,12 +289,8 @@ pub enum BlockchainResponse {
|
||||||
/// - Value = hardfork version
|
/// - Value = hardfork version
|
||||||
HardForks(BTreeMap<usize, HardFork>),
|
HardForks(BTreeMap<usize, HardFork>),
|
||||||
|
|
||||||
/// TODO
|
|
||||||
AltChains(Vec<ChainInfo>),
|
AltChains(Vec<ChainInfo>),
|
||||||
|
|
||||||
/// Response to [`BlockchainReadRequest::AltChainCount`].
|
|
||||||
AltChainCount(usize),
|
|
||||||
|
|
||||||
//------------------------------------------------------ Writes
|
//------------------------------------------------------ Writes
|
||||||
/// A generic Ok response to indicate a request was successfully handled.
|
/// A generic Ok response to indicate a request was successfully handled.
|
||||||
///
|
///
|
||||||
|
|
|
@ -20,10 +20,9 @@ pub use transaction_verification_data::{
|
||||||
CachedVerificationState, TransactionVerificationData, TxVersion,
|
CachedVerificationState, TransactionVerificationData, TxVersion,
|
||||||
};
|
};
|
||||||
pub use types::{
|
pub use types::{
|
||||||
AddAuxPow, AltBlockInformation, AuxPow, Chain, ChainId, ChainInfo, CoinbaseTxSum,
|
AltBlockInformation, Chain, ChainId, ChainInfo, CoinbaseTxSum, ExtendedBlockHeader,
|
||||||
ExtendedBlockHeader, FeeEstimate, HardForkInfo, MinerData, MinerDataTxBacklogEntry,
|
FeeEstimate, HardForkInfo, MinerData, MinerDataTxBacklogEntry, OutputHistogramEntry,
|
||||||
OutputHistogramEntry, OutputHistogramInput, OutputOnChain, VerifiedBlockInformation,
|
OutputHistogramInput, OutputOnChain, VerifiedBlockInformation, VerifiedTransactionInformation,
|
||||||
VerifiedTransactionInformation,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------- Feature-gated
|
//---------------------------------------------------------------------------------------------------- Feature-gated
|
||||||
|
|
|
@ -242,23 +242,6 @@ pub struct ChainInfo {
|
||||||
pub main_chain_parent_block: [u8; 32],
|
pub main_chain_parent_block: [u8; 32],
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Used in RPC's `add_aux_pow`.
|
|
||||||
#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
|
||||||
pub struct AuxPow {
|
|
||||||
pub id: [u8; 32],
|
|
||||||
pub hash: [u8; 32],
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Used in RPC's `add_aux_pow`.
|
|
||||||
#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
|
||||||
pub struct AddAuxPow {
|
|
||||||
pub blocktemplate_blob: Vec<u8>,
|
|
||||||
pub blockhashing_blob: Vec<u8>,
|
|
||||||
pub merkle_root: [u8; 32],
|
|
||||||
pub merkle_tree_depth: u64,
|
|
||||||
pub aux_pow: Vec<AuxPow>,
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------- Tests
|
//---------------------------------------------------------------------------------------------------- Tests
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
|
|
Loading…
Reference in a new issue