mirror of
https://github.com/Cuprate/cuprate.git
synced 2025-01-11 13:25:09 +00:00
sig docs, remove HardForks
request
This commit is contained in:
parent
98dfaa4870
commit
13eedc6d80
8 changed files with 36 additions and 52 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -1010,6 +1010,7 @@ dependencies = [
|
||||||
"serde",
|
"serde",
|
||||||
"serde_bytes",
|
"serde_bytes",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
"strum",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"thread_local",
|
"thread_local",
|
||||||
"tokio",
|
"tokio",
|
||||||
|
|
|
@ -65,6 +65,7 @@ rayon = { workspace = true }
|
||||||
serde_bytes = { workspace = true }
|
serde_bytes = { workspace = true }
|
||||||
serde_json = { workspace = true }
|
serde_json = { workspace = true }
|
||||||
serde = { workspace = true }
|
serde = { workspace = true }
|
||||||
|
strum = { workspace = true }
|
||||||
thiserror = { workspace = true }
|
thiserror = { workspace = true }
|
||||||
thread_local = { workspace = true }
|
thread_local = { workspace = true }
|
||||||
tokio-util = { workspace = true }
|
tokio-util = { workspace = true }
|
||||||
|
|
|
@ -5,7 +5,9 @@ use std::{
|
||||||
|
|
||||||
use anyhow::{anyhow, Error};
|
use anyhow::{anyhow, Error};
|
||||||
use cuprate_p2p_core::{client::handshaker::builder::DummyAddressBook, ClearNet};
|
use cuprate_p2p_core::{client::handshaker::builder::DummyAddressBook, ClearNet};
|
||||||
|
use futures::TryFutureExt;
|
||||||
use monero_serai::block::Block;
|
use monero_serai::block::Block;
|
||||||
|
use strum::{EnumCount, VariantArray};
|
||||||
use tower::{Service, ServiceExt};
|
use tower::{Service, ServiceExt};
|
||||||
|
|
||||||
use cuprate_consensus::{BlockchainReadRequest, BlockchainResponse};
|
use cuprate_consensus::{BlockchainReadRequest, BlockchainResponse};
|
||||||
|
@ -673,14 +675,20 @@ async fn get_version(
|
||||||
let current_height = helper::top_height(&mut state).await?.0;
|
let current_height = helper::top_height(&mut state).await?.0;
|
||||||
let target_height = blockchain_manager::target_height(&mut state.blockchain_manager).await?;
|
let target_height = blockchain_manager::target_height(&mut state.blockchain_manager).await?;
|
||||||
|
|
||||||
let hard_forks = blockchain::hard_forks(&mut state.blockchain_read)
|
let mut hard_forks = Vec::with_capacity(HardFork::COUNT);
|
||||||
.await?
|
|
||||||
.into_iter()
|
// FIXME: use an iterator `collect()` version.
|
||||||
.map(|(height, hf)| HardforkEntry {
|
for hf in HardFork::VARIANTS {
|
||||||
height: usize_to_u64(height),
|
if let Ok(hf) = blockchain_context::hard_fork_info(&mut state.blockchain_context, *hf).await
|
||||||
hf_version: hf.as_u8(),
|
{
|
||||||
})
|
let entry = HardforkEntry {
|
||||||
.collect();
|
height: hf.earliest_height,
|
||||||
|
hf_version: hf.version,
|
||||||
|
};
|
||||||
|
|
||||||
|
hard_forks.push(entry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Ok(GetVersionResponse {
|
Ok(GetVersionResponse {
|
||||||
base: ResponseBase::OK,
|
base: ResponseBase::OK,
|
||||||
|
|
|
@ -344,22 +344,6 @@ pub(crate) async fn coinbase_tx_sum(
|
||||||
Ok(sum)
|
Ok(sum)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// [`BlockchainReadRequest::HardForks`]
|
|
||||||
pub(crate) async fn hard_forks(
|
|
||||||
blockchain_read: &mut BlockchainReadHandle,
|
|
||||||
) -> Result<BTreeMap<usize, HardFork>, Error> {
|
|
||||||
let BlockchainResponse::HardForks(hfs) = blockchain_read
|
|
||||||
.ready()
|
|
||||||
.await?
|
|
||||||
.call(BlockchainReadRequest::HardForks)
|
|
||||||
.await?
|
|
||||||
else {
|
|
||||||
unreachable!();
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(hfs)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// [`BlockchainReadRequest::AltChains`]
|
/// [`BlockchainReadRequest::AltChains`]
|
||||||
pub(crate) async fn alt_chains(
|
pub(crate) async fn alt_chains(
|
||||||
blockchain_read: &mut BlockchainReadHandle,
|
blockchain_read: &mut BlockchainReadHandle,
|
||||||
|
|
|
@ -121,7 +121,6 @@ fn map_request(
|
||||||
R::DatabaseSize => database_size(env),
|
R::DatabaseSize => database_size(env),
|
||||||
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::HardForks => hard_forks(env),
|
|
||||||
R::AltChains => alt_chains(env),
|
R::AltChains => alt_chains(env),
|
||||||
R::AltChainCount => alt_chain_count(env),
|
R::AltChainCount => alt_chain_count(env),
|
||||||
}
|
}
|
||||||
|
@ -652,11 +651,6 @@ fn coinbase_tx_sum(env: &ConcreteEnv, height: usize, count: u64) -> ResponseResu
|
||||||
Ok(BlockchainResponse::CoinbaseTxSum(todo!()))
|
Ok(BlockchainResponse::CoinbaseTxSum(todo!()))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// [`BlockchainReadRequest::HardForks`]
|
|
||||||
fn hard_forks(env: &ConcreteEnv) -> ResponseResult {
|
|
||||||
Ok(BlockchainResponse::HardForks(todo!()))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// [`BlockchainReadRequest::AltChains`]
|
/// [`BlockchainReadRequest::AltChains`]
|
||||||
fn alt_chains(env: &ConcreteEnv) -> ResponseResult {
|
fn alt_chains(env: &ConcreteEnv) -> ResponseResult {
|
||||||
Ok(BlockchainResponse::AltChains(todo!()))
|
Ok(BlockchainResponse::AltChains(todo!()))
|
||||||
|
|
|
@ -22,12 +22,16 @@ pub enum TxpoolReadRequest {
|
||||||
/// Get information on all transactions in the pool.
|
/// Get information on all transactions in the pool.
|
||||||
Backlog,
|
Backlog,
|
||||||
|
|
||||||
/// TODO
|
/// Get information on all transactions in
|
||||||
|
/// the pool for block template purposes.
|
||||||
|
///
|
||||||
|
/// This is only slightly different to [`TxpoolReadRequest::Backlog`].
|
||||||
BlockTemplateBacklog,
|
BlockTemplateBacklog,
|
||||||
|
|
||||||
/// Get the number of transactions in the pool.
|
/// Get the number of transactions in the pool.
|
||||||
Size {
|
Size {
|
||||||
/// TODO
|
/// If this is [`true`], the size returned will
|
||||||
|
/// include private transactions in the pool.
|
||||||
include_sensitive_txs: bool,
|
include_sensitive_txs: bool,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -47,13 +51,13 @@ pub enum TxpoolReadResponse {
|
||||||
|
|
||||||
/// Response to [`TxpoolReadRequest::Backlog`].
|
/// Response to [`TxpoolReadRequest::Backlog`].
|
||||||
///
|
///
|
||||||
/// The inner `Vec` contains information on all
|
/// The inner [`Vec`] contains information on all
|
||||||
/// the transactions currently in the pool.
|
/// the transactions currently in the pool.
|
||||||
Backlog(Vec<TxEntry>),
|
Backlog(Vec<TxEntry>),
|
||||||
|
|
||||||
/// Response to [`TxpoolReadRequest::BlockTemplateBacklog`].
|
/// Response to [`TxpoolReadRequest::BlockTemplateBacklog`].
|
||||||
///
|
///
|
||||||
/// TODO
|
/// The inner [`Vec`] contains information on transactions
|
||||||
BlockTemplateBacklog(Vec<BlockTemplateTxEntry>),
|
BlockTemplateBacklog(Vec<BlockTemplateTxEntry>),
|
||||||
|
|
||||||
/// Response to [`TxpoolReadRequest::Size`].
|
/// Response to [`TxpoolReadRequest::Size`].
|
||||||
|
|
|
@ -13,15 +13,16 @@ pub struct TxEntry {
|
||||||
pub time_in_pool: std::time::Duration,
|
pub time_in_pool: std::time::Duration,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// TODO
|
/// Data about a transaction in the pool
|
||||||
|
/// for use in a block template.
|
||||||
///
|
///
|
||||||
/// Used in [`TxpoolReadResponse::BlockTemplateBacklog`](crate::service::interface::TxpoolReadResponse::BlockTemplateBacklog).
|
/// Used in [`TxpoolReadResponse::BlockTemplateBacklog`](crate::service::interface::TxpoolReadResponse::BlockTemplateBacklog).
|
||||||
#[derive(Copy, Clone, Debug, Ord, PartialOrd, Eq, PartialEq, Hash)]
|
#[derive(Copy, Clone, Debug, Ord, PartialOrd, Eq, PartialEq, Hash)]
|
||||||
pub struct BlockTemplateTxEntry {
|
pub struct BlockTemplateTxEntry {
|
||||||
/// TODO
|
/// The transaction's ID (hash).
|
||||||
pub id: [u8; 32],
|
pub id: [u8; 32],
|
||||||
/// TODO
|
/// The transaction's weight.
|
||||||
pub weight: u64,
|
pub weight: u64,
|
||||||
/// TODO
|
/// The transaction's fee.
|
||||||
pub fee: u64,
|
pub fee: u64,
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
//! responses are also tested in Cuprate's blockchain database crate.
|
//! responses are also tested in Cuprate's blockchain database crate.
|
||||||
//---------------------------------------------------------------------------------------------------- Import
|
//---------------------------------------------------------------------------------------------------- Import
|
||||||
use std::{
|
use std::{
|
||||||
collections::{BTreeMap, HashMap, HashSet},
|
collections::{HashMap, HashSet},
|
||||||
ops::Range,
|
ops::Range,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ use monero_serai::block::Block;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
types::{Chain, ExtendedBlockHeader, OutputOnChain, VerifiedBlockInformation},
|
types::{Chain, ExtendedBlockHeader, OutputOnChain, VerifiedBlockInformation},
|
||||||
AltBlockInformation, ChainId, ChainInfo, CoinbaseTxSum, HardFork, OutputHistogramEntry,
|
AltBlockInformation, ChainId, ChainInfo, CoinbaseTxSum, OutputHistogramEntry,
|
||||||
OutputHistogramInput,
|
OutputHistogramInput,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -130,13 +130,10 @@ pub enum BlockchainReadRequest {
|
||||||
/// TODO: document fields after impl.
|
/// TODO: document fields after impl.
|
||||||
CoinbaseTxSum { height: usize, count: u64 },
|
CoinbaseTxSum { height: usize, count: u64 },
|
||||||
|
|
||||||
/// TODO
|
/// Get information on all alternative chains.
|
||||||
HardForks,
|
|
||||||
|
|
||||||
/// TODO
|
|
||||||
AltChains,
|
AltChains,
|
||||||
|
|
||||||
/// TODO
|
/// Get the amount of alternative chains that exist.
|
||||||
AltChainCount,
|
AltChainCount,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -286,13 +283,7 @@ pub enum BlockchainResponse {
|
||||||
/// Response to [`BlockchainReadRequest::CoinbaseTxSum`].
|
/// Response to [`BlockchainReadRequest::CoinbaseTxSum`].
|
||||||
CoinbaseTxSum(CoinbaseTxSum),
|
CoinbaseTxSum(CoinbaseTxSum),
|
||||||
|
|
||||||
/// Response to [`BlockchainReadRequest::HardForks`].
|
/// Response to [`BlockchainReadRequest::AltChains`].
|
||||||
///
|
|
||||||
/// - Key = height at which the hardfork activated
|
|
||||||
/// - Value = hardfork version
|
|
||||||
HardForks(BTreeMap<usize, HardFork>),
|
|
||||||
|
|
||||||
/// TODO
|
|
||||||
AltChains(Vec<ChainInfo>),
|
AltChains(Vec<ChainInfo>),
|
||||||
|
|
||||||
/// Response to [`BlockchainReadRequest::AltChainCount`].
|
/// Response to [`BlockchainReadRequest::AltChainCount`].
|
||||||
|
|
Loading…
Reference in a new issue