Repository navigation
Add getchaintxstats RPC to rpc-extractor, expose metrics - #312
Conversation
|
Looks good to me! Could add integration tests for:
feel free to add them in the same commit as the new feature I think rust-bitcoin/corepc#430 isn't far from being merged. Going to wait until that's merged until I set this up for testing |
|
I think this RPC is fetched every 10s, right? Not sure if it's needed that frequently. It will return the same result at the same height anyway? Could add a factor of 60 or so, so that it's only fetched every 10 minutes.. |
|
yes, RPC fetchs every 10s, maybe other solution could be check last height |
e58629b to
f991fd6
Compare
Added a metrics integration test, there was already an RPC integration test. Both in the same commit. Here's the output from running them with RPC integration test: 2025-12-18T02:50:39.030Z INFO [rpc_extractor] Querying getchaintxstats enabled: true
2025-12-18T02:50:39.031Z DEBUG [corepc] request: getchaintxstats []
2025-12-18T02:50:39.033Z TRACE [corepc] response for getchaintxstats: {"time":1296688602,"txcount":1,"window_final_block_hash":"0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206","window_final_block_height":0,"window_block_count":0}
2025-12-18T02:50:39.033Z TRACE [shared::protobuf::event] creating new Event: RpcExtractor(Rpc { rpc_event: Some(ChainTxStats(ChainTxStats { time: 1296688602, tx_count: 1, window_final_block_hash: "0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206", window_final_block_height: 0, window_block_count: 0, window_tx_count: None, window_interval: None, tx_rate: None })) })
2025-12-18T02:50:39.034Z INFO [rpc_extractor] rpc_extractor received shutdown signal.Metrics integration test: test that the chaintxstats metrics work
2025-12-18T02:55:10.679Z TRACE [shared::protobuf::event] creating new Event: RpcExtractor(Rpc { rpc_event: Some(ChainTxStats(ChainTxStats { time: 1766024797, tx_count: 1285474630, window_final_block_hash: "00000000000000000001df7f8bf0eb2f537e6f1b4ddd54afa52279dc894fb451", window_final_block_height: 928348, window_block_count: 4320, window_tx_count: Some(2635071), window_interval: Some(13305840), tx_rate: Some(5.049518589821679) })) })
...
2025-12-18T02:55:11.693Z DEBUG [integration] publishing: Event { timestamp: 1766026510679, peer_observer_event: Some(RpcExtractor(Rpc { rpc_event: Some(ChainTxStats(ChainTxStats { time: 1766024797, tx_count: 1285474630, window_final_block_hash: "00000000000000000001df7f8bf0eb2f537e6f1b4ddd54afa52279dc894fb451", window_final_block_height: 928348, window_block_count: 4320, window_tx_count: Some(2635071), window_interval: Some(13305840), tx_rate: Some(5.049518589821679) })) })) } |
Yeah, fair point. I think having a slower rate (e.g. the multiplier) rather than some event (e.g. block hash/height change) is the way to go, we have a more deterministic data source. So I'll propose this! |
f991fd6 to
c98d84a
Compare
|
Confirmed queries are ~10min apart. Currently erroring because of upstream bug: Metrics are available, again currently empty due to bug: ❯ curl -s http://127.0.0.1:8282/metrics | grep chaintxstats
# HELP peerobserver_rpc_chaintxstats_tx_count Total number of transactions in the chain up to the final block in the window.
# TYPE peerobserver_rpc_chaintxstats_tx_count gauge
peerobserver_rpc_chaintxstats_tx_count 0
# HELP peerobserver_rpc_chaintxstats_tx_rate Average rate of transactions per second in the window.
# TYPE peerobserver_rpc_chaintxstats_tx_rate gauge
peerobserver_rpc_chaintxstats_tx_rate 0
# HELP peerobserver_rpc_chaintxstats_window_block_count Size of the window in number of blocks.
# TYPE peerobserver_rpc_chaintxstats_window_block_count gauge
peerobserver_rpc_chaintxstats_window_block_count 0
# HELP peerobserver_rpc_chaintxstats_window_final_block_height Height of the final block in the window.
# TYPE peerobserver_rpc_chaintxstats_window_final_block_height gauge
peerobserver_rpc_chaintxstats_window_final_block_height 0
# HELP peerobserver_rpc_chaintxstats_window_interval Elapsed time in the window in seconds.
# TYPE peerobserver_rpc_chaintxstats_window_interval gauge
peerobserver_rpc_chaintxstats_window_interval 0
# HELP peerobserver_rpc_chaintxstats_window_tx_count Number of transactions in the window.
# TYPE peerobserver_rpc_chaintxstats_window_tx_count gauge
peerobserver_rpc_chaintxstats_window_tx_count 0 |
Agree, that works too. I think if we find our self to add a few more custom intervals, we could also have them as configuration arguments with reasonable defaults. This could replace the disable args, and setting the interval to 0s would disable them. But this is not needed for now. |
c98d84a to
8b3a3a8
Compare
This makes corepc support: - cpu_load and inv_to_send in getpeerinfo (as before) - addconnection - getorphantxs and includes rust-bitcoin/corepc#430 for #312 as well as other improvements in corepc master. Also upgrading the node version feature to v30 from v29.
This makes corepc support: - cpu_load and inv_to_send in getpeerinfo (as before) - addconnection - getorphantxs and includes rust-bitcoin/corepc#430 for #312 as well as other improvements in corepc master. Also upgrading the node version feature to v30 from v29.
|
With #323, your fix is now included in master. Feel free to rebase and undraft. |
43da236 to
3030c92
Compare
All good, whenever you've got capacity (happy new year!!) |
| // Note: Bitcoin Core returns txrate as a float, | ||
| // but corepc deserialises it as i64! | ||
| // The following will be changed once the upstream PR is merged: | ||
| // https://github.com/rust-bitcoin/corepc/pull/430 | ||
| tx_rate: stats.tx_rate.map(|r| r as f64), |
There was a problem hiding this comment.
This comment can be removed now?
There was a problem hiding this comment.
Ah I see you're doing this in 3030c92.
Please squash this fixup commit with the one introducing it.
There was a problem hiding this comment.
Can also squash 5ffc28e with the first commit.
| assert!(stats.window_tx_count.is_some()); | ||
| assert!(stats.window_interval.is_some()); | ||
| // And tx_rate is only present if window_interval > 0 | ||
| if stats.window_interval.unwrap_or(0) > 0 { | ||
| assert!(stats.tx_rate.is_some()); | ||
| } |
There was a problem hiding this comment.
I was wondering if we hit this in the test?
There was a problem hiding this comment.
Hm doesn't seem like it. Inserting an assert doesn't fail the test. So probably best to either leave it out, or mine a few blocks to make sure it's executed.
There was a problem hiding this comment.
Went with leave it out
Add support for the `getchaintxstats` Bitcoin Core RPC, which provides statistics about transaction counts and rates in the chain. - Add ChainTxStats protobuf message with fields: time, tx_count, window_final_block_hash, window_final_block_height, window_block_count, window_tx_count, window_interval, tx_rate - Add chain_tx_stats variant to RPCEvent oneof - Add From<RPCGetChainTxStats> and Display impls for ChainTxStats - Add --disable-getchaintxstats CLI flag - Add getchaintxstats() fetch function in main loop
getchaintxstats doesn't need to be queried at the default interval, use a dedicated tokio interval at 60x the base query_interval.
3030c92 to
c5af96b
Compare
|
FWIW here's a visualisation of the
Is the build error transient? Or did they pull 30.0 and 30.1 because of the legacy wallet bug? Edit: looks like 30.0 and 30.1 have been pulled: e.g. 404 on |
|
Yeah, I think we can ignore the Ubuntu job for now. Could also add in our own binary again |


DRAFT REASON: This PR requires rust-bitcoin/corepc#430 which fixes the
tx_ratefield type fromi64tof64to match Bitcoin Core's actual return type. So this is currently draft - a small change torpc_extractor.rsis required once upstream changes are merged (to removetx_ratevalues being truncated to integers).Add support for the
getchaintxstatsRPC to therpc-extractorand expose the data as Prometheus metrics. This RPC allows for the below new metrics.The
getchaintxstatsRPC computes statistics about the total number and rate of transactions in the chain. We use the Bitcoin Core defaults:See: Bitcoin Core RPC documentation
rpc_chaintxstats_tx_countrpc_chaintxstats_window_final_block_heightrpc_chaintxstats_window_block_countrpc_chaintxstats_window_tx_countrpc_chaintxstats_window_intervalrpc_chaintxstats_tx_rateNote:
window_final_block_hashis included in the protobuf event but not exposed as a Prometheus metric (block hashes are strings, not numeric values). I don't think a hash/string is a meaningful metric.Changes include:
getchaintxstatsRPC polling to rpc-extractor with--disable-getchaintxstatsflagChainTxStatsprotobuf message definition