Skip to content

Commit a667976

Browse files
authored
feat: add Terminal module for CKB-TUI data provision (#4989)
<!-- Thank you for contributing to nervosnetwork/ckb! If you haven't already, please read [CONTRIBUTING](https://github.com/nervosnetwork/ckb/blob/develop/CONTRIBUTING.md) document. If you're unsure about anything, just ask; somebody should be along to answer within a day or two. PR Title Format: 1. module [, module2, module3]: what's changed 2. *: what's changed --> ### What problem does this PR solve? * Introduce a new Terminal module to supply essential data for CKB-TUI * Include system data and basic mining data in the current implementation ### Related changes - PR to update `owner/repo`: - Need to cherry-pick to the release branch ### Check List <!--REMOVE the items that are not applicable--> Tests <!-- At least one of them must be included. --> - Unit test - Integration test - Manual test (add detailed scripts or steps below) Side effects - Performance regression - Breaking backward compatibility ### Release note <!-- Choose from None, Title Only and Note. Bugfixes or new features need a release note. --> ```release-note Note: Add a note under the PR title in the release note. ```
1 parent 786efb2 commit a667976

File tree

19 files changed

+1736
-28
lines changed

19 files changed

+1736
-28
lines changed

Cargo.lock

Lines changed: 121 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ yansi = "0.5"
315315
seq-macro = "0.3"
316316
strum = { version = "0.27", default-features = false, features = ["derive"] }
317317
phf = { version = "0.12", features = ["macros"] }
318+
sysinfo = "0.37"
318319

319320
[profile.release]
320321
overflow-checks = true

db/src/db.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use ckb_app_config::DBConfig;
77
use ckb_db_schema::Col;
88
use ckb_logger::info;
99
use rocksdb::ops::{
10-
CompactRangeCF, CreateCF, DropCF, GetColumnFamilys, GetPinned, GetPinnedCF, IterateCF, OpenCF,
11-
Put, SetOptions, WriteOps,
10+
CompactRangeCF, CreateCF, DropCF, GetColumnFamilys, GetPinned, GetPinnedCF, GetPropertyCF,
11+
IterateCF, OpenCF, Put, SetOptions, WriteOps,
1212
};
1313
use rocksdb::{
1414
BlockBasedIndexType, BlockBasedOptions, Cache, ColumnFamily, ColumnFamilyDescriptor,
@@ -18,6 +18,8 @@ use rocksdb::{
1818
use std::path::Path;
1919
use std::sync::Arc;
2020

21+
const PROPERTY_NUM_KEYS: &str = "rocksdb.estimate-num-keys";
22+
2123
/// RocksDB wrapper base on OptimisticTransactionDB
2224
///
2325
/// <https://github.com/facebook/rocksdb/wiki/Transactions#optimistictransactiondb>
@@ -329,6 +331,15 @@ impl RocksDB {
329331
.ok_or_else(|| internal_error("drop_cf get_mut failed"))?;
330332
inner.drop_cf(col).map_err(internal_error)
331333
}
334+
335+
/// "rocksdb.estimate-num-keys" - returns estimated number of total keys in
336+
/// the active and unflushed immutable memtables and storage.
337+
pub fn estimate_num_keys_cf(&self, col: Col) -> Result<Option<u64>> {
338+
let cf = cf_handle(&self.inner, col)?;
339+
self.inner
340+
.property_int_value_cf(cf, PROPERTY_NUM_KEYS)
341+
.map_err(internal_error)
342+
}
332343
}
333344

334345
#[inline]

devtools/doc/rpc-gen/src/utils.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ pub(crate) fn all_rpc_docs() -> Vec<(String, Value)> {
3030
indexer_rpc_doc,
3131
rich_indexer_rpc_doc,
3232
experiment_rpc_doc,
33+
terminal_rpc_doc,
3334
)
3435
.into()
3536
}

resource/ckb.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,10 @@ listen_address = "127.0.0.1:8114" # {{
186186
# Default is 10MiB = 10 * 1024 * 1024
187187
max_request_body_size = 10485760
188188

189-
# List of API modules: ["Net", "Pool", "Miner", "Chain", "Stats", "Subscription", "Experiment", "Debug", "Indexer", "RichIndexer"]
190-
modules = ["Net", "Pool", "Miner", "Chain", "Stats", "Subscription", "Experiment"] # {{
191-
# dev => modules = ["Net", "Pool", "Miner", "Chain", "Stats", "Subscription", "Experiment", "Debug"]
192-
# integration => modules = ["Net", "Pool", "Miner", "Chain", "Experiment", "Stats", "IntegrationTest"]
189+
# List of API modules: ["Net", "Pool", "Miner", "Chain", "Stats", "Subscription", "Experiment", "Debug", "Indexer", "RichIndexer", "Terminal"]
190+
modules = ["Net", "Pool", "Miner", "Chain", "Stats", "Subscription", "Experiment", "Terminal"] # {{
191+
# dev => modules = ["Net", "Pool", "Miner", "Chain", "Stats", "Subscription", "Experiment", "Debug", "Terminal"]
192+
# integration => modules = ["Net", "Pool", "Miner", "Chain", "Experiment", "Stats", "IntegrationTest", "Terminal"]
193193
# }}
194194

195195
# By default RPC only binds to HTTP service, you can bind it to TCP and WebSocket.

rpc/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ ckb-indexer.workspace = true
4343
ckb-indexer-sync.workspace = true
4444
ckb-rich-indexer.workspace = true
4545
ckb-stop-handler.workspace = true
46+
ckb-dao-utils.workspace = true
47+
ckb-db-schema.workspace = true
4648
itertools.workspace = true
4749
tokio.workspace = true
4850
async-trait.workspace = true
@@ -53,6 +55,10 @@ tower-http = { workspace = true, features = ["timeout", "cors"] }
5355
async-stream.workspace = true
5456
ckb-async-runtime.workspace = true
5557
schemars.workspace = true
58+
sysinfo.workspace = true
59+
bitflags.workspace = true
60+
lru.workspace = true
61+
5662

5763
[dev-dependencies]
5864
reqwest = { workspace = true, features = ["blocking", "json"] }

0 commit comments

Comments
 (0)