Skip to content

Commit 5d307a6

Browse files
committed
add tx-pool metrics data
1 parent 2fc401a commit 5d307a6

File tree

12 files changed

+84
-14
lines changed

12 files changed

+84
-14
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,13 @@ clippy: setup-ckb-test ## Run linter to examine Rust source codes.
180180
cargo clippy ${VERBOSE} --all --all-targets --features ${ALL_FEATURES} -- ${CLIPPY_OPTS} -D missing_docs
181181
cd test && cargo clippy ${VERBOSE} --all --all-targets --all-features -- ${CLIPPY_OPTS}
182182

183+
.PHONY: bless
184+
bless: setup-ckb-test
185+
cargo clippy --fix --allow-dirty ${VERBOSE} --all --all-targets --features ${ALL_FEATURES} -- ${CLIPPY_OPTS} -D missing_docs
186+
cd test && cargo clippy --fix --allow-dirty ${VERBOSE} --all --all-targets --all-features -- ${CLIPPY_OPTS}
187+
cargo fmt ${VERBOSE} --all
188+
cd test && cargo fmt ${VERBOSE} --all
189+
183190
.PHONY: security-audit
184191
security-audit: ## Use cargo-deny to audit Cargo.lock for crates with security vulnerabilities.
185192
cargo deny check --hide-inclusion-graph --show-stats advisories sources

rpc/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4698,11 +4698,11 @@ Response
46984698
"result": {
46994699
"ancestors_count": "0x0",
47004700
"descendants_count": "0x0",
4701-
"entry_status": "Pending",
4701+
"entry_status": "pending",
47024702
"pending_count": "0x1",
47034703
"proposed_count": "0x0",
47044704
"rank_in_pending": "0x1",
4705-
"score_sortkey": "AncestorsScoreSortKey { fee: Capacity(96942915023), weight: 274, ancestors_fee: Capacity(96942915023), ancestors_weight: 274 }",
4705+
"score_sortkey": "fee: 0x16923F7DCF, ancestors_fee: 0x16923F7DCF, weight: 0x112, ancestors_weight: 0x112",
47064706
"timestamp": "0x18aa1baa54c"
47074707
},
47084708
"id": 42
@@ -6567,11 +6567,11 @@ A Tx details info in tx-pool.
65676567

65686568
* `timestamp`: [`Uint64`](#type-uint64) - The time added into tx-pool
65696569

6570-
* `entry_status`: `string` - The detailed status in tx-pool, `Pending`, `Gap`, `Proposed`
6570+
* `entry_status`: `string` - The detailed status in tx-pool, `pending`, `gap`, `proposed`
65716571

65726572
* `rank_in_pending`: [`Uint64`](#type-uint64) - The rank in pending, starting from 0
65736573

6574-
* `pending_count`: [`Uint64`](#type-uint64) - The pending(`Pending` and `Gap`) count
6574+
* `pending_count`: [`Uint64`](#type-uint64) - The pending(`pending` and `gap`) count
65756575

65766576
* `proposed_count`: [`Uint64`](#type-uint64) - The proposed count
65776577

rpc/src/module/pool.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,11 +283,11 @@ pub trait PoolRpc {
283283
/// "result": {
284284
/// "ancestors_count": "0x0",
285285
/// "descendants_count": "0x0",
286-
/// "entry_status": "Pending",
286+
/// "entry_status": "pending",
287287
/// "pending_count": "0x1",
288288
/// "proposed_count": "0x0",
289289
/// "rank_in_pending": "0x1",
290-
/// "score_sortkey": "AncestorsScoreSortKey { fee: Capacity(96942915023), weight: 274, ancestors_fee: Capacity(96942915023), ancestors_weight: 274 }",
290+
/// "score_sortkey": "fee: 0x16923F7DCF, ancestors_fee: 0x16923F7DCF, weight: 0x112, ancestors_weight: 0x112",
291291
/// "timestamp": "0x18aa1baa54c"
292292
/// },
293293
/// "id": 42

rpc/src/tests/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ struct RpcTestSuite {
8989

9090
impl RpcTestSuite {
9191
fn rpc(&self, request: &RpcTestRequest) -> RpcTestResponse {
92-
self.rpc_client
92+
self.rpc_client
9393
.post(&self.rpc_uri)
9494
.json(&request)
9595
.send()

test/src/specs/rpc/get_pool.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ impl Spec for TxPoolEntryStatus {
1111
let tx_hash_0 = node0.generate_transaction();
1212
let tx = node0.new_transaction(tx_hash_0.clone());
1313
node0.rpc_client().send_transaction(tx.data().into());
14-
node0.assert_pool_entry_status(tx_hash_0.clone(), "Pending");
14+
node0.assert_pool_entry_status(tx_hash_0.clone(), "pending");
1515
node0.mine(1);
16-
node0.assert_pool_entry_status(tx_hash_0.clone(), "Gap");
16+
node0.assert_pool_entry_status(tx_hash_0.clone(), "gap");
1717
node0.mine(1);
18-
node0.assert_pool_entry_status(tx_hash_0, "Proposed");
18+
node0.assert_pool_entry_status(tx_hash_0, "proposed");
1919
}
2020
}

tx-pool/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@ ckb-logger = { path = "../util/logger", version = "= 0.113.0-pre" }
1616
ckb-verification = { path = "../verification", version = "= 0.113.0-pre" }
1717
ckb-systemtime = { path = "../util/systemtime", version = "= 0.113.0-pre" }
1818
lru = "0.7.1"
19+
1920
ckb-dao = { path = "../util/dao", version = "= 0.113.0-pre" }
2021
ckb-reward-calculator = { path = "../util/reward-calculator", version = "= 0.113.0-pre" }
2122
ckb-store = { path = "../store", version = "= 0.113.0-pre" }
2223
ckb-util = { path = "../util", version = "= 0.113.0-pre" }
2324
ckb-jsonrpc-types = { path = "../util/jsonrpc-types", version = "= 0.113.0-pre" }
2425
ckb-chain-spec = { path = "../spec", version = "= 0.113.0-pre" }
2526
ckb-snapshot = { path = "../util/snapshot", version = "= 0.113.0-pre" }
27+
ckb-metrics = {path = "../util/metrics", version = "= 0.113.0-pre"}
2628
ckb-error = { path = "../error", version = "= 0.113.0-pre" }
2729
tokio = { version = "1", features = ["sync", "process"] }
2830
ckb-async-runtime = { path = "../util/runtime", version = "= 0.113.0-pre" }

tx-pool/src/component/pool_map.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@ pub enum Status {
2828
Proposed,
2929
}
3030

31+
impl ToString for Status {
32+
fn to_string(&self) -> String {
33+
match self {
34+
Status::Pending => "pending".to_string(),
35+
Status::Gap => "gap".to_string(),
36+
Status::Proposed => "proposed".to_string(),
37+
}
38+
}
39+
}
40+
3141
#[derive(Copy, Clone)]
3242
enum EntryOp {
3343
Add,
@@ -182,6 +192,7 @@ impl PoolMap {
182192
self.insert_entry(&entry, status);
183193
self.record_entry_edges(&entry);
184194
self.record_entry_descendants(&entry);
195+
self.track_entry_statics();
185196
Ok(true)
186197
}
187198

@@ -192,6 +203,7 @@ impl PoolMap {
192203
e.status = status;
193204
})
194205
.expect("unconsistent pool");
206+
self.track_entry_statics();
195207
}
196208

197209
pub(crate) fn remove_entry(&mut self, id: &ProposalShortId) -> Option<TxEntry> {
@@ -509,4 +521,21 @@ impl PoolMap {
509521
evict_key,
510522
});
511523
}
524+
525+
fn track_entry_statics(&self) {
526+
if let Some(metrics) = ckb_metrics::handle() {
527+
metrics
528+
.ckb_tx_pool_entry
529+
.pending
530+
.set(self.entries.get_by_status(&Status::Pending).len() as i64);
531+
metrics
532+
.ckb_tx_pool_entry
533+
.gap
534+
.set(self.entries.get_by_status(&Status::Gap).len() as i64);
535+
metrics
536+
.ckb_tx_pool_entry
537+
.proposed
538+
.set(self.proposed_size() as i64);
539+
}
540+
}
512541
}

tx-pool/src/component/sort_key.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,18 @@ impl Ord for AncestorsScoreSortKey {
4747
}
4848
}
4949

50+
impl ToString for AncestorsScoreSortKey {
51+
fn to_string(&self) -> String {
52+
format!(
53+
"fee: {:#02X}, ancestors_fee: {:#02X}, weight: {:#02X}, ancestors_weight: {:#02X}",
54+
self.fee.as_u64(),
55+
self.ancestors_fee.as_u64(),
56+
self.weight,
57+
self.ancestors_weight
58+
)
59+
}
60+
}
61+
5062
/// First compare fee_rate, select the smallest fee_rate,
5163
/// and then select the latest timestamp, for eviction,
5264
/// the latest timestamp which also means that the fewer descendants may exist.

tx-pool/src/pool.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -645,13 +645,13 @@ impl TxPool {
645645
};
646646
let res = PoolTxDetailInfo {
647647
timestamp: entry.inner.timestamp,
648-
entry_status: format!("{:?}", entry.status),
648+
entry_status: entry.status.to_string(),
649649
pending_count: self.pool_map.pending_size(),
650650
rank_in_pending,
651651
proposed_count: ids.proposed.len(),
652652
descendants_count: self.pool_map.calc_descendants(id).len(),
653653
ancestors_count: self.pool_map.calc_ancestors(id).len(),
654-
score_sortkey: format!("{:?}", entry.inner.as_score_key()),
654+
score_sortkey: entry.inner.as_score_key().to_string(),
655655
};
656656
Some(res)
657657
} else {

util/jsonrpc-types/src/pool.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,11 @@ pub enum RawTxPool {
220220
pub struct PoolTxDetailInfo {
221221
/// The time added into tx-pool
222222
pub timestamp: Uint64,
223-
/// The detailed status in tx-pool, `Pending`, `Gap`, `Proposed`
223+
/// The detailed status in tx-pool, `pending`, `gap`, `proposed`
224224
pub entry_status: String,
225225
/// The rank in pending, starting from 0
226226
pub rank_in_pending: Uint64,
227-
/// The pending(`Pending` and `Gap`) count
227+
/// The pending(`pending` and `gap`) count
228228
pub pending_count: Uint64,
229229
/// The proposed count
230230
pub proposed_count: Uint64,

util/metrics/src/lib.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ make_static_metric! {
3737
metadata,
3838
},
3939
}
40+
41+
// Struct for CKB tx-pool entry status statistics type label
42+
struct CkbTxPoolEntryStatistics: IntGauge{
43+
"type" => {
44+
pending,
45+
gap,
46+
proposed,
47+
},
48+
}
4049
}
4150

4251
pub struct Metrics {
@@ -64,6 +73,8 @@ pub struct Metrics {
6473
pub ckb_sys_mem_process: CkbSysMemProcessStatistics,
6574
// GaugeVec for CKB system memory jemalloc statistics
6675
pub ckb_sys_mem_jemalloc: CkbSysMemJemallocStatistics,
76+
// GaugeVec for CKB tx-pool tx entry status statistics
77+
pub ckb_tx_pool_entry: CkbTxPoolEntryStatistics,
6778
/// Histogram for CKB network connections
6879
pub ckb_message_bytes: HistogramVec,
6980
/// Gauge for CKB rocksdb statistics
@@ -127,6 +138,14 @@ static METRICS: once_cell::sync::Lazy<Metrics> = once_cell::sync::Lazy::new(|| M
127138
)
128139
.unwrap(),
129140
),
141+
ckb_tx_pool_entry: CkbTxPoolEntryStatistics::from(
142+
&register_int_gauge_vec!(
143+
"ckb_tx_pool_entry",
144+
"CKB tx-pool entry status statistics",
145+
&["type"]
146+
)
147+
.unwrap(),
148+
),
130149
ckb_message_bytes: register_histogram_vec!(
131150
"ckb_message_bytes",
132151
"The CKB message bytes",

0 commit comments

Comments
 (0)