ckb_jsonrpc_types/
info.rs

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