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

BREAK CHANGE for RPC get_pool_tx_detail_info: Change score_sortkey's type from String to struct AncestorsScoreSortKey #4273

Merged
27 changes: 25 additions & 2 deletions rpc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ The crate `ckb-rpc`'s minimum supported rustc version is 1.71.1.
* [Type `AlertId`](#type-alertid)
* [Type `AlertMessage`](#type-alertmessage)
* [Type `AlertPriority`](#type-alertpriority)
* [Type `AncestorsScoreSortKey`](#type-ancestorsscoresortkey)
* [Type `BannedAddr`](#type-bannedaddr)
* [Type `Block`](#type-block)
* [Type `BlockEconomicState`](#type-blockeconomicstate)
Expand Down Expand Up @@ -4701,7 +4702,12 @@ Response
"pending_count": "0x1",
"proposed_count": "0x0",
"rank_in_pending": "0x1",
"score_sortkey": "fee: 0x16923F7DCF, ancestors_fee: 0x16923F7DCF, weight: 0x112, ancestors_weight: 0x112",
"score_sortkey": {
"ancestors_fee": "0x16923f7dcf",
"ancestors_weight": "0x112",
"fee": "0x16923f7dcf",
"weight": "0x112"
},
"timestamp": "0x18aa1baa54c"
},
"id": 42
Expand Down Expand Up @@ -5250,6 +5256,23 @@ Alerts are sorted by priority. Greater integers mean higher priorities.

This is a 32-bit unsigned integer type encoded as the 0x-prefixed hex string in JSON. See examples of [Uint32](#type-uint32).

### Type `AncestorsScoreSortKey`

A struct as a sorted key for tx-pool

#### Fields

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

* `fee`: [`Uint64`](#type-uint64) - Fee

* `weight`: [`Uint64`](#type-uint64) - Weight

* `ancestors_fee`: [`Uint64`](#type-uint64) - Ancestors fee

* `ancestors_weight`: [`Uint64`](#type-uint64) - Ancestors weight


### Type `BannedAddr`

A banned P2P address.
Expand Down Expand Up @@ -6565,7 +6588,7 @@ A Tx details info in tx-pool.

* `ancestors_count`: [`Uint64`](#type-uint64) - The ancestors count of tx

* `score_sortkey`: `string` - The score key details, useful to debug
* `score_sortkey`: [`AncestorsScoreSortKey`](#type-ancestorsscoresortkey) - The score key details, useful to debug


### Type `ProposalShortId`
Expand Down
7 changes: 6 additions & 1 deletion rpc/src/module/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,12 @@ pub trait PoolRpc {
/// "pending_count": "0x1",
/// "proposed_count": "0x0",
/// "rank_in_pending": "0x1",
/// "score_sortkey": "fee: 0x16923F7DCF, ancestors_fee: 0x16923F7DCF, weight: 0x112, ancestors_weight: 0x112",
/// "score_sortkey": {
/// "ancestors_fee": "0x16923f7dcf",
/// "ancestors_weight": "0x112",
/// "fee": "0x16923f7dcf",
/// "weight": "0x112"
/// },
/// "timestamp": "0x18aa1baa54c"
/// },
/// "id": 42
Expand Down
15 changes: 14 additions & 1 deletion tx-pool/src/component/sort_key.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use ckb_types::core::{Capacity, FeeRate};
use ckb_types::core::{
tx_pool::AncestorsScoreSortKey as CoreAncestorsScoreSortKey, Capacity, FeeRate,
};
use std::cmp::Ordering;

/// A struct to use as a sorted key
Expand Down Expand Up @@ -47,6 +49,17 @@ impl Ord for AncestorsScoreSortKey {
}
}

impl From<AncestorsScoreSortKey> for CoreAncestorsScoreSortKey {
fn from(val: AncestorsScoreSortKey) -> Self {
CoreAncestorsScoreSortKey {
fee: val.fee,
weight: val.weight,
ancestors_fee: val.ancestors_fee,
ancestors_weight: val.ancestors_weight,
}
}
}

impl ToString for AncestorsScoreSortKey {
fn to_string(&self) -> String {
format!(
Expand Down
2 changes: 1 addition & 1 deletion tx-pool/src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ impl TxPool {
proposed_count: ids.proposed.len(),
descendants_count: self.pool_map.calc_descendants(id).len(),
ancestors_count: self.pool_map.calc_ancestors(id).len(),
score_sortkey: entry.inner.as_score_key().to_string(),
score_sortkey: entry.inner.as_score_key().into(),
};
Some(res)
} else {
Expand Down
4 changes: 2 additions & 2 deletions util/jsonrpc-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ pub use self::net::{
RemoteNodeProtocol, SyncState,
};
pub use self::pool::{
OutputsValidator, PoolTransactionEntry, PoolTransactionReject, PoolTxDetailInfo, RawTxPool,
TxPoolEntries, TxPoolEntry, TxPoolIds, TxPoolInfo,
AncestorsScoreSortKey, OutputsValidator, PoolTransactionEntry, PoolTransactionReject,
PoolTxDetailInfo, RawTxPool, TxPoolEntries, TxPoolEntry, TxPoolIds, TxPoolInfo,
};
pub use self::proposal_short_id::ProposalShortId;
pub use self::subscription::Topic;
Expand Down
32 changes: 28 additions & 4 deletions util/jsonrpc-types/src/pool.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::{BlockNumber, Capacity, Cycle, Timestamp, TransactionView, Uint64};
use ckb_types::core::service::PoolTransactionEntry as CorePoolTransactionEntry;
use ckb_types::core::tx_pool::{
PoolTxDetailInfo as CorePoolTxDetailInfo, Reject, TxEntryInfo, TxPoolEntryInfo,
TxPoolIds as CoreTxPoolIds, TxPoolInfo as CoreTxPoolInfo,
AncestorsScoreSortKey as CoreAncestorsScoreSortKey, PoolTxDetailInfo as CorePoolTxDetailInfo,
Reject, TxEntryInfo, TxPoolEntryInfo, TxPoolIds as CoreTxPoolIds, TxPoolInfo as CoreTxPoolInfo,
};
use ckb_types::prelude::Unpack;
use ckb_types::H256;
Expand Down Expand Up @@ -215,6 +215,30 @@ pub enum RawTxPool {
Verbose(TxPoolEntries),
}

/// A struct as a sorted key for tx-pool
#[derive(Clone, Serialize, Deserialize, PartialEq, Eq, Debug)]
pub struct AncestorsScoreSortKey {
/// Fee
pub fee: Uint64,
/// Weight
pub weight: Uint64,
/// Ancestors fee
pub ancestors_fee: Uint64,
/// Ancestors weight
pub ancestors_weight: Uint64,
}

impl From<CoreAncestorsScoreSortKey> for AncestorsScoreSortKey {
fn from(value: CoreAncestorsScoreSortKey) -> Self {
Self {
fee: value.fee.into(),
weight: value.weight.into(),
ancestors_fee: value.ancestors_fee.into(),
ancestors_weight: value.ancestors_weight.into(),
}
}
}

/// A Tx details info in tx-pool.
#[derive(Clone, Serialize, Deserialize, PartialEq, Eq, Debug)]
pub struct PoolTxDetailInfo {
Expand All @@ -233,7 +257,7 @@ pub struct PoolTxDetailInfo {
/// The ancestors count of tx
pub ancestors_count: Uint64,
/// The score key details, useful to debug
pub score_sortkey: String,
pub score_sortkey: AncestorsScoreSortKey,
}

impl From<CorePoolTxDetailInfo> for PoolTxDetailInfo {
Expand All @@ -246,7 +270,7 @@ impl From<CorePoolTxDetailInfo> for PoolTxDetailInfo {
proposed_count: (info.proposed_count as u64).into(),
descendants_count: (info.descendants_count as u64).into(),
ancestors_count: (info.ancestors_count as u64).into(),
score_sortkey: info.score_sortkey,
score_sortkey: info.score_sortkey.into(),
}
}
}
Expand Down
15 changes: 14 additions & 1 deletion util/types/src/core/tx_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,19 @@ pub struct TxPoolInfo {
pub max_tx_pool_size: u64,
}

/// A struct as a sorted key in tx-pool
#[derive(Eq, PartialEq, Clone, Debug, Default)]
pub struct AncestorsScoreSortKey {
/// fee
pub fee: Capacity,
/// weight
pub weight: u64,
/// ancestors_fee
pub ancestors_fee: Capacity,
/// ancestors_weight
pub ancestors_weight: u64,
}

/// A Tx details info in tx-pool.
#[derive(Clone, PartialEq, Eq, Debug, Default)]
pub struct PoolTxDetailInfo {
Expand All @@ -363,7 +376,7 @@ pub struct PoolTxDetailInfo {
/// The ancestors count of tx
pub ancestors_count: usize,
/// The score key details, useful to debug
pub score_sortkey: String,
pub score_sortkey: AncestorsScoreSortKey,
}

impl PoolTxDetailInfo {
Expand Down
Loading