mirror of
https://github.com/hinto-janai/cuprate.git
synced 2025-02-03 19:56:35 +00:00
AlternateChains
, docs
This commit is contained in:
parent
64a3e5d5e9
commit
42d6f97847
5 changed files with 78 additions and 26 deletions
|
@ -9,7 +9,7 @@ use cuprate_consensus::context::{
|
|||
BlockChainContext, BlockChainContextRequest, BlockChainContextResponse,
|
||||
BlockChainContextService,
|
||||
};
|
||||
use cuprate_types::HardFork;
|
||||
use cuprate_types::{FeeEstimate, HardFork, HardForkInfo};
|
||||
|
||||
/// [`BlockChainContextRequest::Context`].
|
||||
pub(super) async fn context(
|
||||
|
@ -34,7 +34,7 @@ pub(super) async fn context(
|
|||
pub(super) async fn hard_fork_info(
|
||||
service: &mut BlockChainContextService,
|
||||
hard_fork: HardFork,
|
||||
) -> Result<Infallible, Error> {
|
||||
) -> Result<HardForkInfo, Error> {
|
||||
let BlockChainContextResponse::HardForkInfo(hf_info) = service
|
||||
.ready()
|
||||
.await
|
||||
|
@ -53,8 +53,8 @@ pub(super) async fn hard_fork_info(
|
|||
pub(super) async fn fee_estimate(
|
||||
service: &mut BlockChainContextService,
|
||||
grace_blocks: u64,
|
||||
) -> Result<Infallible, Error> {
|
||||
let BlockChainContextResponse::FeeEstimate(hf_info) = service
|
||||
) -> Result<FeeEstimate, Error> {
|
||||
let BlockChainContextResponse::FeeEstimate(fee) = service
|
||||
.ready()
|
||||
.await
|
||||
.expect("TODO")
|
||||
|
@ -65,5 +65,5 @@ pub(super) async fn fee_estimate(
|
|||
unreachable!();
|
||||
};
|
||||
|
||||
Ok(hf_info)
|
||||
Ok(fee)
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ mod alt_chains;
|
|||
mod task;
|
||||
mod tokens;
|
||||
|
||||
use cuprate_types::Chain;
|
||||
use cuprate_types::{Chain, ChainInfo, FeeEstimate, HardForkInfo};
|
||||
use difficulty::DifficultyCache;
|
||||
use rx_vms::RandomXVm;
|
||||
use weight::BlockWeightsCache;
|
||||
|
@ -319,14 +319,17 @@ pub enum BlockChainContextRequest {
|
|||
_token: AltChainRequestToken,
|
||||
},
|
||||
|
||||
/// TODO
|
||||
/// Get information on a certain hardfork.
|
||||
HardForkInfo(HardFork),
|
||||
|
||||
/// TODO
|
||||
/// Get the current fee estimate.
|
||||
FeeEstimate {
|
||||
/// TODO
|
||||
grace_blocks: u64,
|
||||
},
|
||||
|
||||
/// Get information on all the current alternate chains.
|
||||
AlternateChains,
|
||||
}
|
||||
|
||||
pub enum BlockChainContextResponse {
|
||||
|
@ -365,14 +368,15 @@ pub enum BlockChainContextResponse {
|
|||
AltChainWeightCache(BlockWeightsCache),
|
||||
|
||||
/// Response to [`BlockChainContextRequest::HardForkInfo`]
|
||||
///
|
||||
/// TODO
|
||||
HardForkInfo(std::convert::Infallible /* TODO */),
|
||||
HardForkInfo(HardForkInfo),
|
||||
|
||||
/// Response to [`BlockChainContextRequest::FeeEstimate`]
|
||||
FeeEstimate(FeeEstimate),
|
||||
|
||||
/// Response to [`BlockChainContextRequest::AlternateChains`]
|
||||
///
|
||||
/// TODO
|
||||
FeeEstimate(std::convert::Infallible /* TODO */),
|
||||
/// If the inner [`Vec::is_empty`], there were no alternate chains.
|
||||
AlternateChains(Vec<ChainInfo>),
|
||||
}
|
||||
|
||||
/// The blockchain context service.
|
||||
|
|
|
@ -326,7 +326,8 @@ impl<D: Database + Clone + Send + 'static> ContextTask<D> {
|
|||
BlockChainContextResponse::Ok
|
||||
}
|
||||
BlockChainContextRequest::HardForkInfo(_)
|
||||
| BlockChainContextRequest::FeeEstimate { .. } => {
|
||||
| BlockChainContextRequest::FeeEstimate { .. }
|
||||
| BlockChainContextRequest::AlternateChains => {
|
||||
todo!("finish https://github.com/Cuprate/cuprate/pull/297")
|
||||
}
|
||||
})
|
||||
|
|
|
@ -20,9 +20,9 @@ pub use transaction_verification_data::{
|
|||
CachedVerificationState, TransactionVerificationData, TxVersion,
|
||||
};
|
||||
pub use types::{
|
||||
AltBlockInformation, Chain, ChainId, CoinbaseTxSum, ExtendedBlockHeader, MinerData,
|
||||
MinerDataTxBacklogEntry, OutputHistogramEntry, OutputHistogramInput, OutputOnChain,
|
||||
VerifiedBlockInformation, VerifiedTransactionInformation,
|
||||
AltBlockInformation, Chain, ChainId, ChainInfo, CoinbaseTxSum, ExtendedBlockHeader,
|
||||
FeeEstimate, HardForkInfo, MinerData, MinerDataTxBacklogEntry, OutputHistogramEntry,
|
||||
OutputHistogramInput, OutputOnChain, VerifiedBlockInformation, VerifiedTransactionInformation,
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- Feature-gated
|
||||
|
|
|
@ -147,7 +147,9 @@ pub struct OutputOnChain {
|
|||
pub commitment: EdwardsPoint,
|
||||
}
|
||||
|
||||
/// TODO
|
||||
/// Input required to generate an output histogram.
|
||||
///
|
||||
/// Used in RPC's `get_output_histogram`.
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub struct OutputHistogramInput {
|
||||
pub amounts: Vec<u64>,
|
||||
|
@ -157,7 +159,9 @@ pub struct OutputHistogramInput {
|
|||
pub recent_cutoff: u64,
|
||||
}
|
||||
|
||||
/// TODO
|
||||
/// A single entry in an output histogram.
|
||||
///
|
||||
/// Used in RPC's `get_output_histogram`.
|
||||
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub struct OutputHistogramEntry {
|
||||
pub amount: u64,
|
||||
|
@ -166,18 +170,20 @@ pub struct OutputHistogramEntry {
|
|||
pub recent_instances: u64,
|
||||
}
|
||||
|
||||
/// TODO
|
||||
/// Data of summed coinbase transactions.
|
||||
///
|
||||
/// Used in RPC's `get_coinbase_tx_sum`.
|
||||
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub struct CoinbaseTxSum {
|
||||
pub emission_amount: u64,
|
||||
pub emission_amount_top64: u64,
|
||||
pub fee_amount: u64,
|
||||
pub fee_amount_top64: u64,
|
||||
pub emission_amount: u128,
|
||||
pub fee_amount: u128,
|
||||
pub wide_emission_amount: u128,
|
||||
pub wide_fee_amount: u128,
|
||||
}
|
||||
|
||||
/// TODO
|
||||
/// Data to create a custom block template.
|
||||
///
|
||||
/// Used in RPC's `get_miner_data`.
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub struct MinerData {
|
||||
pub major_version: u8,
|
||||
|
@ -190,7 +196,9 @@ pub struct MinerData {
|
|||
pub tx_backlog: Vec<MinerDataTxBacklogEntry>,
|
||||
}
|
||||
|
||||
/// TODO
|
||||
/// A transaction in the txpool.
|
||||
///
|
||||
/// Used in [`MinerData::tx_backlog`].
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub struct MinerDataTxBacklogEntry {
|
||||
pub id: [u8; 32],
|
||||
|
@ -198,6 +206,45 @@ pub struct MinerDataTxBacklogEntry {
|
|||
pub fee: u64,
|
||||
}
|
||||
|
||||
/// Information on a [`HardFork`].
|
||||
///
|
||||
/// Used in RPC's `hard_fork_info`.
|
||||
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub struct HardForkInfo {
|
||||
pub earliest_height: u64,
|
||||
pub enabled: bool,
|
||||
pub state: u32,
|
||||
pub threshold: u32,
|
||||
pub version: u8,
|
||||
pub votes: u32,
|
||||
pub voting: u8,
|
||||
pub window: u32,
|
||||
}
|
||||
|
||||
/// Estimated fee data.
|
||||
///
|
||||
/// Used in RPC's `get_fee_estimate`.
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub struct FeeEstimate {
|
||||
pub fee: u64,
|
||||
pub fees: Vec<u64>,
|
||||
pub quantization_mask: u64,
|
||||
}
|
||||
|
||||
/// Information on a (maybe alternate) chain.
|
||||
///
|
||||
/// Used in RPC's `get_alternate_chains`.
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub struct ChainInfo {
|
||||
pub block_hash: [u8; 32],
|
||||
pub block_hashes: Vec<[u8; 32]>,
|
||||
pub difficulty: u128,
|
||||
pub height: u64,
|
||||
pub length: u64,
|
||||
pub main_chain_parent_block: [u8; 32],
|
||||
pub wide_difficulty: u128,
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- Tests
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
|
|
Loading…
Reference in a new issue