From 6a7718d72436a09acd94a922b51550bf9dfc4237 Mon Sep 17 00:00:00 2001 From: Eval EXEC Date: Mon, 25 Dec 2023 11:32:14 +0800 Subject: [PATCH 1/8] Modify score_sortkey use AncestorsScoreSortKey instead of String --- util/types/src/core/tx_pool.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/util/types/src/core/tx_pool.rs b/util/types/src/core/tx_pool.rs index 5620c903ea..75b61934c1 100644 --- a/util/types/src/core/tx_pool.rs +++ b/util/types/src/core/tx_pool.rs @@ -345,6 +345,15 @@ 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 { + pub fee: Capacity, + pub weight: u64, + pub ancestors_fee: Capacity, + pub ancestors_weight: u64, +} + /// A Tx details info in tx-pool. #[derive(Clone, PartialEq, Eq, Debug, Default)] pub struct PoolTxDetailInfo { @@ -363,7 +372,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 { From 65e50db6f7fb7a6b8049de78dcfaff4952bd8c9a Mon Sep 17 00:00:00 2001 From: Eval EXEC Date: Mon, 25 Dec 2023 11:32:54 +0800 Subject: [PATCH 2/8] Add struct AncestorsScoreSortKey to jsonrpc-types --- util/jsonrpc-types/src/pool.rs | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/util/jsonrpc-types/src/pool.rs b/util/jsonrpc-types/src/pool.rs index 7a3a36f6df..7033f8793f 100644 --- a/util/jsonrpc-types/src/pool.rs +++ b/util/jsonrpc-types/src/pool.rs @@ -1,13 +1,14 @@ 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; use serde::{Deserialize, Serialize}; use std::collections::HashMap; +use std::path::Ancestors; /// Transaction pool information. #[derive(Clone, Default, Serialize, Deserialize, PartialEq, Eq, Hash, Debug)] @@ -215,6 +216,26 @@ pub enum RawTxPool { Verbose(TxPoolEntries), } +/// A struct as a sorted key for tx-pool +#[derive(Clone, Serialize, Deserialize, PartialEq, Eq, Debug)] +pub struct AncestorsScoreSortKey { + pub fee: Uint64, + pub weight: Uint64, + pub ancestors_fee: Uint64, + pub ancestors_weight: Uint64, +} + +impl From 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 { @@ -233,7 +254,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 for PoolTxDetailInfo { @@ -246,7 +267,7 @@ impl From 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(), } } } From fcac16bda767c7211da2ae0b8ae515c2938f7124 Mon Sep 17 00:00:00 2001 From: Eval EXEC Date: Mon, 25 Dec 2023 13:21:46 +0800 Subject: [PATCH 3/8] Remove useless import statements --- util/jsonrpc-types/src/pool.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/util/jsonrpc-types/src/pool.rs b/util/jsonrpc-types/src/pool.rs index 7033f8793f..f20283f733 100644 --- a/util/jsonrpc-types/src/pool.rs +++ b/util/jsonrpc-types/src/pool.rs @@ -8,7 +8,6 @@ use ckb_types::prelude::Unpack; use ckb_types::H256; use serde::{Deserialize, Serialize}; use std::collections::HashMap; -use std::path::Ancestors; /// Transaction pool information. #[derive(Clone, Default, Serialize, Deserialize, PartialEq, Eq, Hash, Debug)] From f09c4234381cdabed7d4139cc41c9aad7eddbc96 Mon Sep 17 00:00:00 2001 From: Eval EXEC Date: Mon, 25 Dec 2023 13:22:39 +0800 Subject: [PATCH 4/8] Assign AncestorsScoreSortKey to score_sortkey --- tx-pool/src/component/sort_key.rs | 15 ++++++++++++++- tx-pool/src/pool.rs | 2 +- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/tx-pool/src/component/sort_key.rs b/tx-pool/src/component/sort_key.rs index 2c1797d9d7..792dbe9170 100644 --- a/tx-pool/src/component/sort_key.rs +++ b/tx-pool/src/component/sort_key.rs @@ -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 @@ -47,6 +49,17 @@ impl Ord for AncestorsScoreSortKey { } } +impl Into for AncestorsScoreSortKey { + fn into(self) -> CoreAncestorsScoreSortKey { + CoreAncestorsScoreSortKey { + fee: self.fee, + weight: self.weight, + ancestors_fee: self.ancestors_fee, + ancestors_weight: self.ancestors_weight, + } + } +} + impl ToString for AncestorsScoreSortKey { fn to_string(&self) -> String { format!( diff --git a/tx-pool/src/pool.rs b/tx-pool/src/pool.rs index 2f2e5452df..3867f5bf59 100644 --- a/tx-pool/src/pool.rs +++ b/tx-pool/src/pool.rs @@ -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 { From 5e3cda2c6a40448d14bb6dbd1ef778ec0793ac54 Mon Sep 17 00:00:00 2001 From: Eval EXEC Date: Mon, 25 Dec 2023 13:52:30 +0800 Subject: [PATCH 5/8] Update rpc comment doc for get_pool_tx_detail_info --- rpc/src/module/pool.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/rpc/src/module/pool.rs b/rpc/src/module/pool.rs index 9f300116fc..cf9e67100c 100644 --- a/rpc/src/module/pool.rs +++ b/rpc/src/module/pool.rs @@ -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 From 8fa34e5050caa27315649cfb9983f3d5597574df Mon Sep 17 00:00:00 2001 From: Eval EXEC Date: Mon, 25 Dec 2023 14:44:29 +0800 Subject: [PATCH 6/8] Add doc comment for AncestorsScoreSortKey --- util/jsonrpc-types/src/lib.rs | 4 ++-- util/jsonrpc-types/src/pool.rs | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/util/jsonrpc-types/src/lib.rs b/util/jsonrpc-types/src/lib.rs index 4944ca8636..e35db6fdb2 100644 --- a/util/jsonrpc-types/src/lib.rs +++ b/util/jsonrpc-types/src/lib.rs @@ -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; diff --git a/util/jsonrpc-types/src/pool.rs b/util/jsonrpc-types/src/pool.rs index f20283f733..90e1351c73 100644 --- a/util/jsonrpc-types/src/pool.rs +++ b/util/jsonrpc-types/src/pool.rs @@ -218,9 +218,13 @@ pub enum RawTxPool { /// 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, } From 97e561ebd4f16935a916c765743e438c439f4ad3 Mon Sep 17 00:00:00 2001 From: Eval EXEC Date: Mon, 25 Dec 2023 14:44:40 +0800 Subject: [PATCH 7/8] Execute `make gen-rpc-doc` --- rpc/README.md | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/rpc/README.md b/rpc/README.md index 782b80f821..67d57f2d01 100644 --- a/rpc/README.md +++ b/rpc/README.md @@ -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) @@ -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 @@ -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. @@ -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` From 66424d4022b32e6ed29002bc21de729220ea57a7 Mon Sep 17 00:00:00 2001 From: Eval EXEC Date: Mon, 25 Dec 2023 15:03:07 +0800 Subject: [PATCH 8/8] Fix cargo clippy --- tx-pool/src/component/sort_key.rs | 12 ++++++------ util/types/src/core/tx_pool.rs | 4 ++++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/tx-pool/src/component/sort_key.rs b/tx-pool/src/component/sort_key.rs index 792dbe9170..e8b1c82830 100644 --- a/tx-pool/src/component/sort_key.rs +++ b/tx-pool/src/component/sort_key.rs @@ -49,13 +49,13 @@ impl Ord for AncestorsScoreSortKey { } } -impl Into for AncestorsScoreSortKey { - fn into(self) -> CoreAncestorsScoreSortKey { +impl From for CoreAncestorsScoreSortKey { + fn from(val: AncestorsScoreSortKey) -> Self { CoreAncestorsScoreSortKey { - fee: self.fee, - weight: self.weight, - ancestors_fee: self.ancestors_fee, - ancestors_weight: self.ancestors_weight, + fee: val.fee, + weight: val.weight, + ancestors_fee: val.ancestors_fee, + ancestors_weight: val.ancestors_weight, } } } diff --git a/util/types/src/core/tx_pool.rs b/util/types/src/core/tx_pool.rs index 75b61934c1..b41630461c 100644 --- a/util/types/src/core/tx_pool.rs +++ b/util/types/src/core/tx_pool.rs @@ -348,9 +348,13 @@ pub struct TxPoolInfo { /// 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, }