ckb_jsonrpc_types/info.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
use crate::{AlertMessage, EpochNumber, EpochNumberWithFraction, Ratio, Timestamp};
use ckb_types::{H256, U256};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;
/// Deployment name
#[derive(
Clone, Hash, Deserialize, Serialize, Debug, Ord, PartialOrd, Eq, PartialEq, JsonSchema,
)]
#[serde(rename_all = "snake_case")]
pub enum DeploymentPos {
/// Dummy
Testdummy,
/// light client protocol
LightClient,
}
/// The possible softfork deployment state
#[derive(Deserialize, Serialize, Debug, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum DeploymentState {
/// First state that each softfork starts.
/// The 0 epoch is by definition in this state for each deployment.
Defined,
/// For epochs past the `start` epoch.
Started,
/// For one epoch after the first epoch period with STARTED epochs of
/// which at least `threshold` has the associated bit set in `version`.
LockedIn,
/// For all epochs after the LOCKED_IN epoch.
Active,
/// For one epoch period past the `timeout_epoch`, if LOCKED_IN was not reached.
Failed,
}
/// Chain information.
#[derive(Deserialize, Serialize, Debug, JsonSchema)]
pub struct DeploymentsInfo {
/// requested block hash
pub hash: H256,
/// requested block epoch
pub epoch: EpochNumber,
/// `{ [ key:` [`DeploymentPos`](#type-deploymentpos) `]: ` [`DeploymentInfo`](#type-deploymentinfo) `}`
/// deployments info
pub deployments: BTreeMap<DeploymentPos, DeploymentInfo>,
}
/// An object containing various state info regarding deployments of consensus changes
#[derive(Deserialize, Serialize, Debug, JsonSchema)]
pub struct DeploymentInfo {
/// determines which bit in the `version` field of the block is to be used to signal the softfork lock-in and activation.
/// It is chosen from the set {0,1,2,...,28}.
pub bit: u8,
/// specifies the first epoch in which the bit gains meaning.
pub start: EpochNumber,
/// specifies an epoch at which the miner signaling ends.
/// Once this epoch has been reached,
/// if the softfork has not yet locked_in (excluding this epoch block's bit state),
/// the deployment is considered failed on all descendants of the block.
pub timeout: EpochNumber,
/// specifies the epoch at which the softfork is allowed to become active.
pub min_activation_epoch: EpochNumber,
/// the length in epochs of the signalling period
pub period: EpochNumber,
/// the ratio of blocks with the version bit set required to activate the feature
pub threshold: Ratio,
/// The first epoch which the current state applies
pub since: EpochNumber,
/// With each epoch and softfork, we associate a deployment state. The possible states are:
///
/// * `DEFINED` is the first state that each softfork starts. The blocks of 0 epoch is by definition in this state for each deployment.
/// * `STARTED` for all blocks reach or past the start_epoch.
/// * `LOCKED_IN` for one period after the first period with STARTED blocks of which at least threshold has the associated bit set in version.
/// * `ACTIVE` for all blocks after the LOCKED_IN period.
/// * `FAILED` for all blocks after the timeout_epoch, if LOCKED_IN was not reached.
pub state: DeploymentState,
}
/// Chain information.
#[derive(Deserialize, Serialize, Debug, JsonSchema)]
pub struct ChainInfo {
/// The network name.
///
/// Examples:
///
/// * "ckb" - Mirana the mainnet.
/// * "ckb_testnet" - Pudge the testnet.
pub chain: String,
/// The median time of the last 37 blocks, including the tip block.
pub median_time: Timestamp,
/// The epoch information of tip block in the chain.
pub epoch: EpochNumberWithFraction,
/// Current difficulty.
///
/// Decoded from the epoch `compact_target`.
#[schemars(schema_with = "crate::json_schema::u256_json_schema")]
pub difficulty: U256,
/// Whether the local node is in IBD, Initial Block Download.
///
/// When a node starts and its chain tip timestamp is far behind the wall clock, it will enter
/// the IBD until it catches up the synchronization.
///
/// During IBD, the local node only synchronizes the chain with one selected remote node and
/// stops responding the most P2P requests.
pub is_initial_block_download: bool,
/// Active alerts stored in the local node.
pub alerts: Vec<AlertMessage>,
}