mirror of
https://github.com/hinto-janai/cuprate.git
synced 2024-11-16 15:58:14 +00:00
get_miner_data
This commit is contained in:
parent
4b1d7bc897
commit
bd3a844cc5
7 changed files with 88 additions and 20 deletions
|
@ -41,8 +41,8 @@ use cuprate_rpc_types::{
|
|||
SyncInfoResponse,
|
||||
},
|
||||
misc::{
|
||||
AuxPow, BlockHeader, ChainInfo, GetBan, HardforkEntry, HistogramEntry, Status,
|
||||
SyncInfoPeer, TxBacklogEntry,
|
||||
AuxPow, BlockHeader, ChainInfo, GetBan, GetMinerDataTxBacklogEntry, HardforkEntry,
|
||||
HistogramEntry, Status, SyncInfoPeer, TxBacklogEntry,
|
||||
},
|
||||
CORE_RPC_VERSION,
|
||||
};
|
||||
|
@ -817,19 +817,38 @@ 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(
|
||||
state: CupratedRpcHandler,
|
||||
mut 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: todo!(),
|
||||
height: todo!(),
|
||||
prev_id: todo!(),
|
||||
seed_hash: todo!(),
|
||||
difficulty: todo!(),
|
||||
median_weight: todo!(),
|
||||
already_generated_coins: todo!(),
|
||||
tx_backlog: todo!(),
|
||||
major_version,
|
||||
height,
|
||||
prev_id,
|
||||
seed_hash,
|
||||
difficulty,
|
||||
median_weight,
|
||||
already_generated_coins,
|
||||
tx_backlog,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -15,9 +15,9 @@ use cuprate_types::{FeeEstimate, HardFork, HardForkInfo};
|
|||
|
||||
/// [`BlockChainContextRequest::Context`].
|
||||
pub(crate) async fn context(
|
||||
service: &mut BlockChainContextService,
|
||||
blockchain_context: &mut BlockChainContextService,
|
||||
) -> Result<BlockChainContext, Error> {
|
||||
let BlockChainContextResponse::Context(context) = service
|
||||
let BlockChainContextResponse::Context(context) = blockchain_context
|
||||
.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(
|
||||
service: &mut BlockChainContextService,
|
||||
blockchain_context: &mut BlockChainContextService,
|
||||
hard_fork: HardFork,
|
||||
) -> Result<HardForkInfo, Error> {
|
||||
let BlockChainContextResponse::HardForkInfo(hf_info) = service
|
||||
let BlockChainContextResponse::HardForkInfo(hf_info) = blockchain_context
|
||||
.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(
|
||||
service: &mut BlockChainContextService,
|
||||
blockchain_context: &mut BlockChainContextService,
|
||||
grace_blocks: u64,
|
||||
) -> Result<FeeEstimate, Error> {
|
||||
let BlockChainContextResponse::FeeEstimate(fee) = service
|
||||
let BlockChainContextResponse::FeeEstimate(fee) = blockchain_context
|
||||
.ready()
|
||||
.await
|
||||
.map_err(|e| anyhow!(e))?
|
||||
|
|
|
@ -11,7 +11,7 @@ use cuprate_txpool::{
|
|||
interface::{TxpoolReadRequest, TxpoolReadResponse},
|
||||
TxpoolReadHandle,
|
||||
},
|
||||
TxEntry,
|
||||
BlockTemplateTxEntry, TxEntry,
|
||||
};
|
||||
|
||||
// FIXME: use `anyhow::Error` over `tower::BoxError` in txpool.
|
||||
|
@ -32,6 +32,24 @@ 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,
|
||||
|
|
|
@ -15,7 +15,7 @@ pub mod types;
|
|||
|
||||
pub use config::Config;
|
||||
pub use free::open;
|
||||
pub use tx::TxEntry;
|
||||
pub use tx::{BlockTemplateTxEntry, TxEntry};
|
||||
|
||||
//re-exports
|
||||
pub use cuprate_database;
|
||||
|
|
|
@ -5,7 +5,10 @@ use std::sync::Arc;
|
|||
|
||||
use cuprate_types::TransactionVerificationData;
|
||||
|
||||
use crate::{tx::TxEntry, types::TransactionHash};
|
||||
use crate::{
|
||||
tx::{BlockTemplateTxEntry, TxEntry},
|
||||
types::TransactionHash,
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- TxpoolReadRequest
|
||||
/// The transaction pool [`tower::Service`] read request type.
|
||||
|
@ -19,6 +22,9 @@ pub enum TxpoolReadRequest {
|
|||
/// Get information on all transactions in the pool.
|
||||
Backlog,
|
||||
|
||||
/// TODO
|
||||
BlockTemplateBacklog,
|
||||
|
||||
/// Get the number of transactions in the pool.
|
||||
Size {
|
||||
/// TODO
|
||||
|
@ -45,6 +51,11 @@ 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
|
||||
|
|
|
@ -66,6 +66,7 @@ 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),
|
||||
|
@ -119,6 +120,12 @@ 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 {
|
||||
|
|
|
@ -12,3 +12,16 @@ 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,
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue