Skip to content

Commit b409568

Browse files
authored
Merge pull request #4288 from eval-exec/exec/get_pool_tx_detail_info_rc
Backport #4273
2 parents 8ff0026 + 486b871 commit b409568

File tree

7 files changed

+90
-12
lines changed

7 files changed

+90
-12
lines changed

rpc/README.md

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ The crate `ckb-rpc`'s minimum supported rustc version is 1.71.1.
105105
* [Type `AlertId`](#type-alertid)
106106
* [Type `AlertMessage`](#type-alertmessage)
107107
* [Type `AlertPriority`](#type-alertpriority)
108+
* [Type `AncestorsScoreSortKey`](#type-ancestorsscoresortkey)
108109
* [Type `BannedAddr`](#type-bannedaddr)
109110
* [Type `Block`](#type-block)
110111
* [Type `BlockEconomicState`](#type-blockeconomicstate)
@@ -4701,7 +4702,12 @@ Response
47014702
"pending_count": "0x1",
47024703
"proposed_count": "0x0",
47034704
"rank_in_pending": "0x1",
4704-
"score_sortkey": "fee: 0x16923F7DCF, ancestors_fee: 0x16923F7DCF, weight: 0x112, ancestors_weight: 0x112",
4705+
"score_sortkey": {
4706+
"ancestors_fee": "0x16923f7dcf",
4707+
"ancestors_weight": "0x112",
4708+
"fee": "0x16923f7dcf",
4709+
"weight": "0x112"
4710+
},
47054711
"timestamp": "0x18aa1baa54c"
47064712
},
47074713
"id": 42
@@ -5250,6 +5256,23 @@ Alerts are sorted by priority. Greater integers mean higher priorities.
52505256

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

5259+
### Type `AncestorsScoreSortKey`
5260+
5261+
A struct as a sorted key for tx-pool
5262+
5263+
#### Fields
5264+
5265+
`AncestorsScoreSortKey` is a JSON object with the following fields.
5266+
5267+
* `fee`: [`Uint64`](#type-uint64) - Fee
5268+
5269+
* `weight`: [`Uint64`](#type-uint64) - Weight
5270+
5271+
* `ancestors_fee`: [`Uint64`](#type-uint64) - Ancestors fee
5272+
5273+
* `ancestors_weight`: [`Uint64`](#type-uint64) - Ancestors weight
5274+
5275+
52535276
### Type `BannedAddr`
52545277

52555278
A banned P2P address.
@@ -6565,7 +6588,7 @@ A Tx details info in tx-pool.
65656588

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

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

65706593

65716594
### Type `ProposalShortId`

rpc/src/module/pool.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,12 @@ pub trait PoolRpc {
289289
/// "pending_count": "0x1",
290290
/// "proposed_count": "0x0",
291291
/// "rank_in_pending": "0x1",
292-
/// "score_sortkey": "fee: 0x16923F7DCF, ancestors_fee: 0x16923F7DCF, weight: 0x112, ancestors_weight: 0x112",
292+
/// "score_sortkey": {
293+
/// "ancestors_fee": "0x16923f7dcf",
294+
/// "ancestors_weight": "0x112",
295+
/// "fee": "0x16923f7dcf",
296+
/// "weight": "0x112"
297+
/// },
293298
/// "timestamp": "0x18aa1baa54c"
294299
/// },
295300
/// "id": 42

tx-pool/src/component/sort_key.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
use ckb_types::core::{Capacity, FeeRate};
1+
use ckb_types::core::{
2+
tx_pool::AncestorsScoreSortKey as CoreAncestorsScoreSortKey, Capacity, FeeRate,
3+
};
24
use std::cmp::Ordering;
35

46
/// A struct to use as a sorted key
@@ -47,6 +49,17 @@ impl Ord for AncestorsScoreSortKey {
4749
}
4850
}
4951

52+
impl From<AncestorsScoreSortKey> for CoreAncestorsScoreSortKey {
53+
fn from(val: AncestorsScoreSortKey) -> Self {
54+
CoreAncestorsScoreSortKey {
55+
fee: val.fee,
56+
weight: val.weight,
57+
ancestors_fee: val.ancestors_fee,
58+
ancestors_weight: val.ancestors_weight,
59+
}
60+
}
61+
}
62+
5063
impl ToString for AncestorsScoreSortKey {
5164
fn to_string(&self) -> String {
5265
format!(

tx-pool/src/pool.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ impl TxPool {
652652
proposed_count: ids.proposed.len(),
653653
descendants_count: self.pool_map.calc_descendants(id).len(),
654654
ancestors_count: self.pool_map.calc_ancestors(id).len(),
655-
score_sortkey: entry.inner.as_score_key().to_string(),
655+
score_sortkey: entry.inner.as_score_key().into(),
656656
};
657657
Some(res)
658658
} else {

util/jsonrpc-types/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ pub use self::net::{
4444
RemoteNodeProtocol, SyncState,
4545
};
4646
pub use self::pool::{
47-
OutputsValidator, PoolTransactionEntry, PoolTransactionReject, PoolTxDetailInfo, RawTxPool,
48-
TxPoolEntries, TxPoolEntry, TxPoolIds, TxPoolInfo,
47+
AncestorsScoreSortKey, OutputsValidator, PoolTransactionEntry, PoolTransactionReject,
48+
PoolTxDetailInfo, RawTxPool, TxPoolEntries, TxPoolEntry, TxPoolIds, TxPoolInfo,
4949
};
5050
pub use self::proposal_short_id::ProposalShortId;
5151
pub use self::subscription::Topic;

util/jsonrpc-types/src/pool.rs

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use crate::{BlockNumber, Capacity, Cycle, Timestamp, TransactionView, Uint64};
22
use ckb_types::core::service::PoolTransactionEntry as CorePoolTransactionEntry;
33
use ckb_types::core::tx_pool::{
4-
PoolTxDetailInfo as CorePoolTxDetailInfo, Reject, TxEntryInfo, TxPoolEntryInfo,
5-
TxPoolIds as CoreTxPoolIds, TxPoolInfo as CoreTxPoolInfo,
4+
AncestorsScoreSortKey as CoreAncestorsScoreSortKey, PoolTxDetailInfo as CorePoolTxDetailInfo,
5+
Reject, TxEntryInfo, TxPoolEntryInfo, TxPoolIds as CoreTxPoolIds, TxPoolInfo as CoreTxPoolInfo,
66
};
77
use ckb_types::prelude::Unpack;
88
use ckb_types::H256;
@@ -215,6 +215,30 @@ pub enum RawTxPool {
215215
Verbose(TxPoolEntries),
216216
}
217217

218+
/// A struct as a sorted key for tx-pool
219+
#[derive(Clone, Serialize, Deserialize, PartialEq, Eq, Debug)]
220+
pub struct AncestorsScoreSortKey {
221+
/// Fee
222+
pub fee: Uint64,
223+
/// Weight
224+
pub weight: Uint64,
225+
/// Ancestors fee
226+
pub ancestors_fee: Uint64,
227+
/// Ancestors weight
228+
pub ancestors_weight: Uint64,
229+
}
230+
231+
impl From<CoreAncestorsScoreSortKey> for AncestorsScoreSortKey {
232+
fn from(value: CoreAncestorsScoreSortKey) -> Self {
233+
Self {
234+
fee: value.fee.into(),
235+
weight: value.weight.into(),
236+
ancestors_fee: value.ancestors_fee.into(),
237+
ancestors_weight: value.ancestors_weight.into(),
238+
}
239+
}
240+
}
241+
218242
/// A Tx details info in tx-pool.
219243
#[derive(Clone, Serialize, Deserialize, PartialEq, Eq, Debug)]
220244
pub struct PoolTxDetailInfo {
@@ -233,7 +257,7 @@ pub struct PoolTxDetailInfo {
233257
/// The ancestors count of tx
234258
pub ancestors_count: Uint64,
235259
/// The score key details, useful to debug
236-
pub score_sortkey: String,
260+
pub score_sortkey: AncestorsScoreSortKey,
237261
}
238262

239263
impl From<CorePoolTxDetailInfo> for PoolTxDetailInfo {
@@ -246,7 +270,7 @@ impl From<CorePoolTxDetailInfo> for PoolTxDetailInfo {
246270
proposed_count: (info.proposed_count as u64).into(),
247271
descendants_count: (info.descendants_count as u64).into(),
248272
ancestors_count: (info.ancestors_count as u64).into(),
249-
score_sortkey: info.score_sortkey,
273+
score_sortkey: info.score_sortkey.into(),
250274
}
251275
}
252276
}

util/types/src/core/tx_pool.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,19 @@ pub struct TxPoolInfo {
345345
pub max_tx_pool_size: u64,
346346
}
347347

348+
/// A struct as a sorted key in tx-pool
349+
#[derive(Eq, PartialEq, Clone, Debug, Default)]
350+
pub struct AncestorsScoreSortKey {
351+
/// fee
352+
pub fee: Capacity,
353+
/// weight
354+
pub weight: u64,
355+
/// ancestors_fee
356+
pub ancestors_fee: Capacity,
357+
/// ancestors_weight
358+
pub ancestors_weight: u64,
359+
}
360+
348361
/// A Tx details info in tx-pool.
349362
#[derive(Clone, PartialEq, Eq, Debug, Default)]
350363
pub struct PoolTxDetailInfo {
@@ -363,7 +376,7 @@ pub struct PoolTxDetailInfo {
363376
/// The ancestors count of tx
364377
pub ancestors_count: usize,
365378
/// The score key details, useful to debug
366-
pub score_sortkey: String,
379+
pub score_sortkey: AncestorsScoreSortKey,
367380
}
368381

369382
impl PoolTxDetailInfo {

0 commit comments

Comments
 (0)