Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RPC: Set jsonrpc::Ratio as the type of threshold field for DeploymentsInfo and Deployment #3980

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions rpc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1692,8 +1692,8 @@ Response
"period": "0xa",
"start": "0x0",
"threshold": {
"denom": 4,
"numer": 3
"denom": "0x4",
"numer": "0x3"
},
"timeout": "0x0"
}
Expand Down Expand Up @@ -4730,8 +4730,8 @@ Response
"state": "failed",
"timeout": "0x0",
"threshold": {
"numer": 3,
"denom": 4
"numer": "0x3",
"denom": "0x4"
}
}
}
Expand Down Expand Up @@ -6494,6 +6494,13 @@ A non-cellbase transaction is committed at height h_c if all of the following co

Represents the ratio `numerator / denominator`, where `numerator` and `denominator` are both unsigned 64-bit integers.

#### Fields

`Ratio` is a JSON object with the following fields.

* `numer`: [`Uint64`](#type-uint64) - Numerator.

* `denom`: [`Uint64`](#type-uint64) - Denominator.


### Type `RationalU256`
Expand Down
4 changes: 2 additions & 2 deletions rpc/src/module/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1374,8 +1374,8 @@ pub trait ChainRpc {
/// "period": "0xa",
/// "start": "0x0",
/// "threshold": {
/// "denom": 4,
/// "numer": 3
/// "denom": "0x4",
/// "numer": "0x3"
/// },
/// "timeout": "0x0"
/// }
Expand Down
4 changes: 2 additions & 2 deletions rpc/src/module/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ pub trait StatsRpc {
/// "state": "failed",
/// "timeout": "0x0",
/// "threshold": {
/// "numer": 3,
/// "denom": 4
/// "numer": "0x3",
/// "denom": "0x4"
/// }
/// }
/// }
Expand Down
4 changes: 2 additions & 2 deletions spec/src/versionbits/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl From<Deployment> for DeploymentInfo {
timeout: deployment.timeout.into(),
min_activation_epoch: deployment.min_activation_epoch.into(),
period: deployment.period.into(),
threshold: deployment.threshold,
threshold: deployment.threshold.into(),
state: DeploymentState::Defined,
since: 0.into(),
}
Expand All @@ -38,7 +38,7 @@ impl From<Deployment> for ckb_jsonrpc_types::Deployment {
timeout: deployment.timeout.into(),
min_activation_epoch: deployment.min_activation_epoch.into(),
period: deployment.period.into(),
threshold: deployment.threshold,
threshold: deployment.threshold.into(),
}
}
}
Expand Down
21 changes: 20 additions & 1 deletion util/jsonrpc-types/src/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1438,6 +1438,25 @@ pub struct Rfc0043 {
pub rfc0043: Deployment,
}

/// Represents the ratio `numerator / denominator`, where `numerator` and `denominator` are both
/// unsigned 64-bit integers.
#[derive(Clone, Serialize, Deserialize, Debug)]
pub struct Ratio {
/// Numerator.
pub numer: Uint64,
/// Denominator.
pub denom: Uint64,
}

impl From<core::Ratio> for Ratio {
fn from(value: core::Ratio) -> Self {
Ratio {
numer: value.numer().into(),
denom: value.denom().into(),
}
}
}

/// RFC0043 deployment params
#[derive(Clone, Serialize, Deserialize, Debug)]
pub struct Deployment {
Expand All @@ -1456,7 +1475,7 @@ pub struct Deployment {
pub period: EpochNumber,
/// Specifies the minimum ratio of block per `period`,
/// which indicate the locked_in of the softfork during the `period`.
pub threshold: core::Ratio,
pub threshold: Ratio,
}

fn convert(number: core::EpochNumber) -> Option<EpochNumber> {
Expand Down
4 changes: 2 additions & 2 deletions util/jsonrpc-types/src/info.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{AlertMessage, EpochNumber, EpochNumberWithFraction, Timestamp};
use ckb_types::{core::Ratio, H256, U256};
use crate::{AlertMessage, EpochNumber, EpochNumberWithFraction, Ratio, Timestamp};
use ckb_types::{H256, U256};
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;

Expand Down
2 changes: 1 addition & 1 deletion util/jsonrpc-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub use self::blockchain::{
Block, BlockEconomicState, BlockFilter, BlockIssuance, BlockResponse, BlockView,
BlockWithCyclesResponse, CellDep, CellInput, CellOutput, Consensus, DepType, Deployment,
EpochView, FeeRateStatistics, HardForkFeature, Header, HeaderView, MerkleProof, MinerReward,
OutPoint, ProposalWindow, Script, ScriptHashType, SoftFork, Status, Transaction,
OutPoint, ProposalWindow, Ratio, Script, ScriptHashType, SoftFork, Status, Transaction,
TransactionAndWitnessProof, TransactionProof, TransactionView, TransactionWithStatusResponse,
TxStatus, UncleBlock, UncleBlockView,
};
Expand Down