Compare commits

..

No commits in common. "bf07f2c84c196e46849c921fc0302692f751e8f6" and "e2f25bd52decba7716ddd588030f0caf6079ec47" have entirely different histories.

14 changed files with 46 additions and 264 deletions

View file

@ -69,48 +69,25 @@ pub enum BlockchainManagerRequest {
seed_hash: [u8; 32],
},
/// Add auxirilly proof-of-work to a block.
///
/// From the RPC `add_aux_pow` usecase's documentation:
/// ````
/// This enables merge mining with Monero without requiring
/// software that manually alters the extra field in the coinbase
/// tx to include the merkle root of the aux blocks.
/// ````
/// TODO
AddAuxPow {
/// The block template to add to.
block_template: Block,
/// The auxirilly proof-of-work to add.
/// TODO
blocktemplate_blob: Vec<u8>,
/// TODO
aux_pow: Vec<AuxPow>,
},
/// Generate new blocks.
///
/// This request is only for regtest, see RPC's `generateblocks`.
/// TODO
GenerateBlocks {
/// Number of the blocks to be generated.
/// TODO
amount_of_blocks: u64,
/// The previous block's hash.
/// TODO
prev_block: [u8; 32],
/// The starting value for the nonce.
/// TODO
starting_nonce: u32,
/// The address that will receive the coinbase reward.
/// TODO
wallet_address: String,
},
/// Get a visual [`String`] overview of blockchain progress.
///
/// This is a highly implementation specific format used by
/// `monerod` in the `sync_info` RPC call's `overview` field;
/// it is essentially an ASCII visual of blocks.
///
/// See also:
/// - <https://www.getmonero.org/resources/developer-guides/daemon-rpc.html#sync_info>
/// - <https://github.com/monero-project/monero/blob/master/src/cryptonote_protocol/block_queue.cpp#L178>
Overview {
/// TODO: the current blockchain height? do we need to pass this?
height: usize,
},
}
/// TODO: use real type when public.
@ -152,14 +129,11 @@ pub enum BlockchainManagerResponse {
/// Response to [`BlockchainManagerRequest::GenerateBlocks`]
GenerateBlocks {
/// Hashes of the blocks generated.
/// TODO
blocks: Vec<[u8; 32]>,
/// The new top height. (TODO: is this correct?)
/// TODO
height: usize,
},
/// Response to [`BlockchainManagerRequest::Overview`]
Overview(String),
}
/// TODO: use real type when public.

View file

@ -41,8 +41,8 @@ use cuprate_rpc_types::{
SyncInfoResponse,
},
misc::{
AuxPow, BlockHeader, ChainInfo, GetBan, GetMinerDataTxBacklogEntry, HardforkEntry,
HistogramEntry, Status, SyncInfoPeer, TxBacklogEntry,
AuxPow, BlockHeader, ChainInfo, GetBan, HardforkEntry, HistogramEntry, Status,
TxBacklogEntry,
},
CORE_RPC_VERSION,
};
@ -758,39 +758,17 @@ async fn relay_tx(
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L3306-L3330>
async fn sync_info(
mut state: CupratedRpcHandler,
state: CupratedRpcHandler,
request: SyncInfoRequest,
) -> Result<SyncInfoResponse, Error> {
let height = usize_to_u64(
blockchain_context::context(&mut state.blockchain_context)
.await?
.unchecked_blockchain_context()
.chain_height,
);
let target_height = blockchain_manager::target_height(&mut state.blockchain_manager).await?;
let peers = address_book::connection_info::<ClearNet>(&mut DummyAddressBook)
.await?
.into_iter()
.map(|info| SyncInfoPeer { info })
.collect();
let next_needed_pruning_seed =
address_book::next_needed_pruning_seed::<ClearNet>(&mut DummyAddressBook)
.await?
.compress();
let overview = blockchain_manager::overview(&mut state.blockchain_manager, height).await?;
let spans = address_book::spans::<ClearNet>(&mut DummyAddressBook).await?;
Ok(SyncInfoResponse {
base: AccessResponseBase::OK,
height,
next_needed_pruning_seed,
overview,
peers,
spans,
target_height,
height: todo!(),
next_needed_pruning_seed: todo!(),
overview: todo!(),
peers: todo!(),
spans: todo!(),
target_height: todo!(),
})
}
@ -817,38 +795,19 @@ async fn get_transaction_pool_backlog(
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L1998-L2033>
async fn get_miner_data(
mut state: CupratedRpcHandler,
state: CupratedRpcHandler,
request: GetMinerDataRequest,
) -> Result<GetMinerDataResponse, Error> {
let context = blockchain_context::context(&mut state.blockchain_context).await?;
let context = context.unchecked_blockchain_context();
let major_version = context.current_hf.as_u8();
let height = usize_to_u64(context.chain_height);
let prev_id = hex::encode(context.top_hash);
let seed_hash = todo!();
let difficulty = format!("{:#x}", context.next_difficulty);
let median_weight = usize_to_u64(context.median_weight_for_block_reward);
let already_generated_coins = context.already_generated_coins;
let tx_backlog = txpool::block_template_backlog(&mut state.txpool_read)
.await?
.into_iter()
.map(|entry| GetMinerDataTxBacklogEntry {
id: hex::encode(entry.id),
weight: entry.weight,
fee: entry.fee,
})
.collect();
Ok(GetMinerDataResponse {
base: ResponseBase::OK,
major_version,
height,
prev_id,
seed_hash,
difficulty,
median_weight,
already_generated_coins,
tx_backlog,
major_version: todo!(),
height: todo!(),
prev_id: todo!(),
seed_hash: todo!(),
difficulty: todo!(),
median_weight: todo!(),
already_generated_coins: todo!(),
tx_backlog: todo!(),
})
}
@ -910,9 +869,7 @@ async fn add_aux_pow(
mut state: CupratedRpcHandler,
request: AddAuxPowRequest,
) -> Result<AddAuxPowResponse, Error> {
let hex = hex::decode(request.blocktemplate_blob)?;
let block_template = Block::read(&mut hex.as_slice())?;
let blocktemplate_blob = hex::decode(request.blocktemplate_blob)?;
let aux_pow = request
.aux_pow
.into_iter()
@ -924,7 +881,7 @@ async fn add_aux_pow(
.collect::<Result<Vec<_>, Error>>()?;
let resp =
blockchain_manager::add_aux_pow(&mut state.blockchain_manager, block_template, aux_pow)
blockchain_manager::add_aux_pow(&mut state.blockchain_manager, blocktemplate_blob, aux_pow)
.await?;
let blocktemplate_blob = hex::encode(resp.blocktemplate_blob);

View file

@ -3,8 +3,7 @@
use std::convert::Infallible;
use anyhow::{anyhow, Error};
use cuprate_pruning::PruningSeed;
use cuprate_rpc_types::misc::{ConnectionInfo, Span};
use cuprate_rpc_types::misc::ConnectionInfo;
use tower::ServiceExt;
use cuprate_helper::cast::usize_to_u64;
@ -157,53 +156,3 @@ pub(crate) async fn get_bans<Z: NetworkZone>(
Ok(bans)
}
/// [`AddressBookRequest::Spans`]
pub(crate) async fn spans<Z: NetworkZone>(
address_book: &mut impl AddressBook<Z>,
) -> Result<Vec<Span>, Error> {
let AddressBookResponse::Spans(vec) = address_book
.ready()
.await
.map_err(|e| anyhow!(e))?
.call(AddressBookRequest::Spans)
.await
.map_err(|e| anyhow!(e))?
else {
unreachable!();
};
// FIXME: impl this map somewhere instead of inline.
let vec = vec
.into_iter()
.map(|span| Span {
connection_id: span.connection_id,
nblocks: span.nblocks,
rate: span.rate,
remote_address: span.remote_address,
size: span.size,
speed: span.speed,
start_block_height: span.start_block_height,
})
.collect();
Ok(vec)
}
/// [`AddressBookRequest::NextNeededPruningSeed`]
pub(crate) async fn next_needed_pruning_seed<Z: NetworkZone>(
address_book: &mut impl AddressBook<Z>,
) -> Result<PruningSeed, Error> {
let AddressBookResponse::NextNeededPruningSeed(seed) = address_book
.ready()
.await
.map_err(|e| anyhow!(e))?
.call(AddressBookRequest::NextNeededPruningSeed)
.await
.map_err(|e| anyhow!(e))?
else {
unreachable!();
};
Ok(seed)
}

View file

@ -15,9 +15,9 @@ use cuprate_types::{FeeEstimate, HardFork, HardForkInfo};
/// [`BlockChainContextRequest::Context`].
pub(crate) async fn context(
blockchain_context: &mut BlockChainContextService,
service: &mut BlockChainContextService,
) -> Result<BlockChainContext, Error> {
let BlockChainContextResponse::Context(context) = blockchain_context
let BlockChainContextResponse::Context(context) = service
.ready()
.await
.map_err(|e| anyhow!(e))?
@ -33,10 +33,10 @@ pub(crate) async fn context(
/// [`BlockChainContextRequest::HardForkInfo`].
pub(crate) async fn hard_fork_info(
blockchain_context: &mut BlockChainContextService,
service: &mut BlockChainContextService,
hard_fork: HardFork,
) -> Result<HardForkInfo, Error> {
let BlockChainContextResponse::HardForkInfo(hf_info) = blockchain_context
let BlockChainContextResponse::HardForkInfo(hf_info) = service
.ready()
.await
.map_err(|e| anyhow!(e))?
@ -52,10 +52,10 @@ pub(crate) async fn hard_fork_info(
/// [`BlockChainContextRequest::FeeEstimate`].
pub(crate) async fn fee_estimate(
blockchain_context: &mut BlockChainContextService,
service: &mut BlockChainContextService,
grace_blocks: u64,
) -> Result<FeeEstimate, Error> {
let BlockChainContextResponse::FeeEstimate(fee) = blockchain_context
let BlockChainContextResponse::FeeEstimate(fee) = service
.ready()
.await
.map_err(|e| anyhow!(e))?

View file

@ -172,14 +172,14 @@ pub(crate) async fn calculate_pow(
/// [`BlockchainManagerRequest::AddAuxPow`]
pub(crate) async fn add_aux_pow(
blockchain_manager: &mut BlockchainManagerHandle,
block_template: Block,
blocktemplate_blob: Vec<u8>,
aux_pow: Vec<AuxPow>,
) -> Result<AddAuxPow, Error> {
let BlockchainManagerResponse::AddAuxPow(response) = blockchain_manager
.ready()
.await?
.call(BlockchainManagerRequest::AddAuxPow {
block_template,
blocktemplate_blob,
aux_pow,
})
.await?
@ -214,22 +214,3 @@ pub(crate) async fn generate_blocks(
Ok((blocks, usize_to_u64(height)))
}
/// [`BlockchainManagerRequest::Overview`]
pub(crate) async fn overview(
blockchain_manager: &mut BlockchainManagerHandle,
height: u64,
) -> Result<String, Error> {
let BlockchainManagerResponse::Overview(overview) = blockchain_manager
.ready()
.await?
.call(BlockchainManagerRequest::Overview {
height: u64_to_usize(height),
})
.await?
else {
unreachable!();
};
Ok(overview)
}

View file

@ -11,7 +11,7 @@ use cuprate_txpool::{
interface::{TxpoolReadRequest, TxpoolReadResponse},
TxpoolReadHandle,
},
BlockTemplateTxEntry, TxEntry,
TxEntry,
};
// FIXME: use `anyhow::Error` over `tower::BoxError` in txpool.
@ -32,24 +32,6 @@ pub(crate) async fn backlog(txpool_read: &mut TxpoolReadHandle) -> Result<Vec<Tx
Ok(tx_entries)
}
/// [`TxpoolReadRequest::BlockTemplateBacklog`]
pub(crate) async fn block_template_backlog(
txpool_read: &mut TxpoolReadHandle,
) -> Result<Vec<BlockTemplateTxEntry>, Error> {
let TxpoolReadResponse::BlockTemplateBacklog(tx_entries) = txpool_read
.ready()
.await
.map_err(|e| anyhow!(e))?
.call(TxpoolReadRequest::BlockTemplateBacklog)
.await
.map_err(|e| anyhow!(e))?
else {
unreachable!();
};
Ok(tx_entries)
}
/// [`TxpoolReadRequest::Size`]
pub(crate) async fn size(
txpool_read: &mut TxpoolReadHandle,

View file

@ -424,9 +424,7 @@ impl<Z: BorshNetworkZone> Service<AddressBookRequest<Z>> for AddressBook<Z> {
| AddressBookRequest::ConnectionCount
| AddressBookRequest::SetBan(_)
| AddressBookRequest::GetBans
| AddressBookRequest::ConnectionInfo
| AddressBookRequest::NextNeededPruningSeed
| AddressBookRequest::Spans => {
| AddressBookRequest::ConnectionInfo => {
todo!("finish https://github.com/Cuprate/cuprate/pull/297")
}
};

View file

@ -112,9 +112,7 @@ impl<N: NetworkZone> Service<AddressBookRequest<N>> for DummyAddressBook {
| AddressBookRequest::ConnectionCount
| AddressBookRequest::SetBan(_)
| AddressBookRequest::GetBans
| AddressBookRequest::ConnectionInfo
| AddressBookRequest::NextNeededPruningSeed
| AddressBookRequest::Spans => {
| AddressBookRequest::ConnectionInfo => {
todo!("finish https://github.com/Cuprate/cuprate/pull/297")
}
}))

View file

@ -6,7 +6,7 @@ use cuprate_wire::{CoreSyncData, PeerListEntryBase};
use crate::{
client::InternalPeerID,
handles::ConnectionHandle,
types::{BanState, ConnectionInfo, SetBan, Span},
types::{BanState, ConnectionInfo, SetBan},
NetZoneAddress, NetworkAddressIncorrectZone, NetworkZone,
};
@ -132,12 +132,6 @@ pub enum AddressBookRequest<Z: NetworkZone> {
/// Get the state of all bans.
GetBans,
/// TODO
Spans,
/// TODO
NextNeededPruningSeed,
}
/// A response from the address book service.
@ -175,10 +169,4 @@ pub enum AddressBookResponse<Z: NetworkZone> {
/// Response to [`AddressBookRequest::GetBans`].
GetBans(Vec<BanState<Z::Addr>>),
/// Response to [`AddressBookRequest::Spans`].
Spans(Vec<Span>),
/// Response to [`AddressBookRequest::NextNeededPruningSeed`].
NextNeededPruningSeed(PruningSeed),
}

View file

@ -52,17 +52,3 @@ pub struct ConnectionInfo<A: NetZoneAddress> {
pub state: String,
pub support_flags: u32,
}
/// Used in RPC's `sync_info`.
///
/// Data within [`crate::services::AddressBookResponse::Spans`].
#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Span {
pub connection_id: String,
pub nblocks: u64,
pub rate: u32,
pub remote_address: String,
pub size: u64,
pub speed: u32,
pub start_block_height: u64,
}

View file

@ -15,7 +15,7 @@ pub mod types;
pub use config::Config;
pub use free::open;
pub use tx::{BlockTemplateTxEntry, TxEntry};
pub use tx::TxEntry;
//re-exports
pub use cuprate_database;

View file

@ -5,10 +5,7 @@ use std::sync::Arc;
use cuprate_types::TransactionVerificationData;
use crate::{
tx::{BlockTemplateTxEntry, TxEntry},
types::TransactionHash,
};
use crate::{tx::TxEntry, types::TransactionHash};
//---------------------------------------------------------------------------------------------------- TxpoolReadRequest
/// The transaction pool [`tower::Service`] read request type.
@ -22,9 +19,6 @@ pub enum TxpoolReadRequest {
/// Get information on all transactions in the pool.
Backlog,
/// TODO
BlockTemplateBacklog,
/// Get the number of transactions in the pool.
Size {
/// TODO
@ -51,11 +45,6 @@ pub enum TxpoolReadResponse {
/// the transactions currently in the pool.
Backlog(Vec<TxEntry>),
/// Response to [`TxpoolReadRequest::BlockTemplateBacklog`].
///
/// TODO
BlockTemplateBacklog(Vec<BlockTemplateTxEntry>),
/// Response to [`TxpoolReadRequest::Size`].
///
/// The inner value is the amount of

View file

@ -66,7 +66,6 @@ fn map_request(
TxpoolReadRequest::TxBlob(tx_hash) => tx_blob(env, &tx_hash),
TxpoolReadRequest::TxVerificationData(tx_hash) => tx_verification_data(env, &tx_hash),
TxpoolReadRequest::Backlog => backlog(env),
TxpoolReadRequest::BlockTemplateBacklog => block_template_backlog(env),
TxpoolReadRequest::Size {
include_sensitive_txs,
} => size(env, include_sensitive_txs),
@ -120,12 +119,6 @@ fn backlog(env: &ConcreteEnv) -> ReadResponseResult {
Ok(TxpoolReadResponse::Backlog(todo!()))
}
/// [`TxpoolReadRequest::BlockTemplateBacklog`].
#[inline]
fn block_template_backlog(env: &ConcreteEnv) -> ReadResponseResult {
Ok(TxpoolReadResponse::BlockTemplateBacklog(todo!()))
}
/// [`TxpoolReadRequest::Size`].
#[inline]
fn size(env: &ConcreteEnv, include_sensitive_txs: bool) -> ReadResponseResult {

View file

@ -12,16 +12,3 @@ pub struct TxEntry {
/// How long the transaction has been in the pool.
pub time_in_pool: std::time::Duration,
}
/// TODO
///
/// Used in [`TxpoolReadResponse::BlockTemplateBacklog`](crate::service::interface::TxpoolReadResponse::BlockTemplateBacklog).
#[derive(Copy, Clone, Debug, Ord, PartialOrd, Eq, PartialEq, Hash)]
pub struct BlockTemplateTxEntry {
/// TODO
pub id: [u8; 32],
/// TODO
pub weight: u64,
/// TODO
pub fee: u64,
}