Skip to content

Watching compact block reconstructions via log-extractor - #420

Merged
0xB10C merged 5 commits into
peer-observer:masterfrom
m4ycon:feat/compact-block-reconstruction
Jun 30, 2026
Merged

0xB10C merged 5 commits into
peer-observer:masterfrom
m4ycon:feat/compact-block-reconstruction

Conversation

@m4ycon

@m4ycon m4ycon commented Apr 28, 2026 •

Copy link
Copy Markdown
Collaborator

No, this description wasn't AI generated, so don't simply skip it, it took quite some time :)

Inspired by @0xB10C post on delving Stats on compact block reconstructions.

What this PR does?

  • Add log matchers for "Saw new header..." and "Successfully reconstructed block..." logs, which are the "start" and "end" points for measuring time;
  • Add prometheus metrics for log_compact_block_reconstruction_requested_bytes, log_compact_block_reconstruction_count and log_compact_block_reconstruction_time.

What kind of question could this PR answer?

  • What is the proportion of compact block reconstructions that do not require transactions?
  • What is the average size of requested transactions?
  • What is the proportion of compact block reconstructions that happen in high-bandwidth connections?
  • Is something affecting the reconstruction time of compact blocks? (anomaly/attacks)

How reconstruction time is measured?

Bitcoin core outputs some logs when a block arrives, in this PR two of them are important for this, "Saw new header..." and "Successfully reconstructed block..." (with -debug=cmpctblock flag).

2026-04-06T15:02:09.010720Z Saw new header hash=00000000000000000001405ace6e6e4abd39fd1e13d1b3434468ba99986b6ad5 height=943929 peer=498
...
2026-04-06T15:02:09.404125Z [cmpctblock] Successfully reconstructed block 00000000000000000001405ace6e6e4abd39fd1e13d1b3434468ba99986b6ad5 with 1 txn prefilled, 2714 txn from mempool (incl at least 2 from extra pool) and 4 txn (886 bytes) requested

With them we know when the block was first seen and when our node have everything from that block. In that way we can take the diff between the dates and measure the elapsed time, a better measure is done with -logtimemicros=1 as it will log the timestamp in microseconds.

How do we know if the reconstruction was via low or high-bandwidth connection?

The heuristic here to know if it's a low or high bandwidth is if the "Saw new header..." has "cmpctblock" (core ref code). As BIP-152 illustrates, the difference is if we receive first a cmpctblock message or headers/inv, if it's the first one, we are in a high-bandwidth connection.

Using a gauge metric, how do we know if a new reconstruction happened?

As prometheus is a pull-based monitoring system, we can't just "emit" an event when a reconstruction happens, we'll update a value somewhere (gauge in this case). This generates a problem, what if log_compact_block_reconstruction_time measure the same time in a row, how do we know if it was the same reconstruction or a new one?

The solution for this is to use a counter metric, log_compact_block_reconstruction_count, that will be incremented every time we measure a reconstruction time, so if we see that the count increased, we know that the time measured is from a new reconstruction. This metric wasn't initially created to solve this problem, but it serves this purpose. It could be the block height but I saw some "zero" values on it (probably when I was messing with infra), so I sticked with a simple counter.

And of course, I consider this pretty rare, even more with the fact that we are measuring the time in microseconds, so the chances of two reconstructions taking the same microsecond time in a row are pretty low.

How do we measure elapsed time if logs can arrive in different timings or even out of order?

We use a HashMap state in metrics tool to store "start" timestamp, "end" timestamp, how many transactions were requested, bandwidth mode and when this record was created. When we see a "Saw new header..." log, we store the "start" timestamp and bandwidth mode. When we see a "Successfully reconstructed block..." log, we store the "end" timestamp and how many transactions were requested.

The key is the block hash, when all data is there (start and end logs arrived), we can calculate the elapsed time and emit some metrics, then we remove this record from the HashMap. Also, if a record is there for more than 5 minutes, we remove it as well, this could be common to happen if node doesn't have -debug=cmpctblock flag as it will never receive the "end" log.

@m4ycon m4ycon left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some specific code comments that I would appreciate suggestions/opinions on it.

Comment thread tools/metrics/src/lib.rs Resolved
Comment on lines +732 to +738
check(
vec!["-debug=cmpctblock"],
|_node1, node2| {
node2.generate_to_address(1, &REGTEST_ADDRESS).unwrap(); // this block will trigger SENDCMPCT trade between nodes
node2.generate_to_address(1, &REGTEST_ADDRESS).unwrap(); // this block will trigger the actual CompactBlockReconstructedLog
},
|event| match event {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both tests here cause intermitent errors and I don't wanna increase #405 list. I think a sleep could solve that but I would prefer to solve this in another way. Sometimes "SENDCMPCT trade" doesn't happen, which is a p2p message that I think I can't trigger it specifically via corepc 🤔.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I've understood why you need to generate two blocks.

Does this test only work if a node is considered high-bandwidth?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is supposed to work for either but I can only trigger high-bandwidth, and sometimes not even that, maybe nodes are using headers/inv trade initially, maybe it take some time to SENDCMPCT trade happen (?). Or are nodes low-bandwidth by default and I'm missing something here?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this happens to be a high-bandwidth relay (you can find out the status via getpeerinfo), then the node1 might first need to tell node2 that node2 should give node blocks in high-bandwidth. We could mock this by sending a sendcmpct(1) via the hidden sendmsgtopeer RPC (rust-bitcoin/corepc#333) - but I'm not sure if node1 receiving a high-bandwidth compact block without requesting one (sendmsgtopeer is not setting it in node1's state), is going to cause problems.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tested sendmsgtopeer but it didn't seem to work, so I went deeper on core code around this and it is solved, explanation in #420 (comment).

And about bandwidth, in my last tests, the second block is relayed via low-band, I guess that a third block would be high-band -- as seen in success case logs, the sendcmpct message is only sent after the second block.

"uid": "P1809F7CD0C75ACF3"
},
"editorMode": "code",
"expr": "avg_over_time(\r\n (\r\n peerobserver_log_compact_block_reconstruction_requested_bytes\r\n and\r\n changes(peerobserver_log_compact_block_reconstruction_requested_bytes[1d]) > 0\r\n )[1d:]\r\n)",

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, it would be interesting if you guys could review those promql queries, just search for "expr" on these .json files that you find them.

@edilmedeiros

Copy link
Copy Markdown
Contributor

As prometheus is a pull-based monitoring system, we can't just "emit" an event when a reconstruction happens, we'll update a value somewhere (gauge in this case).

Just a quick comment about this for future self. I've been planning to experiment with InfluxDB which is a push-based alternative to Prometheus and there are native plugins for Grafana. That would allow us to have more precise timestamps for events, that we have discussed as desirable in a recent call.

@edilmedeiros

Copy link
Copy Markdown
Contributor
  • Second panel line show them aggregated in a histogram;

I would love to have them in a common scale, but not sure this is possible in Grafana since they are independent sources.

@m4ycon

m4ycon commented Apr 28, 2026

Copy link
Copy Markdown
Collaborator Author

I would love to have them in a common scale, but not sure this is possible in Grafana since they are independent sources.

I had an idea to use a query to define those min/max values but grafana doesn't let me use them on "soft min" and "soft max" fields, only a static value (those are the ones that define the scales). I don't know if there's another way 🤔.

Comment thread protobuf/log_extractor.proto Resolved
Comment thread shared/src/log_matchers.rs Resolved
@0xB10C

0xB10C commented Apr 29, 2026

Copy link
Copy Markdown
Collaborator

Gave this a first read, thank you @m4ycon - I think having real-time stats on compact-block reconstructions is very nice. I haven't looked at your comments in detail yet,

This generates a problem, what if log_compact_block_reconstruction_time measure the same time in a row, how do we know if it was the same reconstruction or a new one?
The solution for this is to use a counter metric, log_compact_block_reconstruction_count, that will be incremented every time we measure a reconstruction time, so if we see that the count increased, we know that the time measured is from a new reconstruction.

If I'm not misunderstanding you, I think the Prometheus has a primitive for this https://prometheus.io/docs/practices/histograms/ - does this do the same thing you've implemented?

Just a quick comment about this for future self. I've been planning to experiment with InfluxDB which is a push-based alternative to Prometheus and there are native plugins for Grafana. That would allow us to have more precise timestamps for events, that we have discussed as desirable in a recent call.

Let's explore a influx tool (in general, not part of this PR!). I agree that Prometheus, while it works well for most counters and gauges, doesn't really work well for individual measurements.

Average size of requested transactions per day

As you show in the screenshot, is average might hide that there were a bunch of blocks were we had to request 4 MB. Maybe we can also have additional metrics on median, and 25th/75th percentile? Maybe also a histogram?

First panel line shows each reconstruction measure over time, its averages and the block height;
Second panel line show them aggregated in a histogram;
Third panel line show them in a heatmap. I'm leaning to remove this one;
The last ones are candlesticks showing the distribution of reconstruction times per day, with the mean, 25th and 75th percentiles (open/close) and the min/max values. That's another one I'm leaning to remove but not so much, I want opinions on it.

I agree. Keep the scatterplot, histogram. Drop heatmap. I'm leaning towards keeping the candlestick one too.

Additionally, it might be interesting to have metrics on number of transaction requested an number of transactions we had in our extra pool (when we reject a transaction from mempool, we briefly store it in the extra pool and use this pool when trying to reconstruct a block).

Comment thread extractors/log/tests/integration.rs Resolved
Comment thread tools/metrics/src/lib.rs Resolved
Comment thread tools/metrics/src/lib.rs Resolved
@m4ycon

m4ycon commented Apr 29, 2026

Copy link
Copy Markdown
Collaborator Author

Answering @0xB10C

If I'm not misunderstanding you, I think the Prometheus has a primitive for this https://prometheus.io/docs/practices/histograms/ - does this do the same thing you've implemented?

Yes, it does. Initially I was using it but after some problems with grafana I decided to abandon it. It was very limiting to do time range filtering in grafana histogram, in the other hand, a gauge did solve this problem and gave the possibility to build a scatterplot one, which I think it's the most cool/interesting one.

As you show in the screenshot, is average might hide that there were a bunch of blocks were we had to request 4 MB. Maybe we can also have additional metrics on median, and 25th/75th percentile? Maybe also a histogram?

Something similar to the time measuring one, right? Yeah agreed, I even have a hidden query in that panel showing the exact measures, with the intention to debug, but I think it was a signal that it was a bad view for it.

@m4ycon
m4ycon force-pushed the feat/compact-block-reconstruction branch 2 times, most recently from 376594e to 717b3a5 Compare May 5, 2026 17:22
@m4ycon

m4ycon commented May 5, 2026 •

Copy link
Copy Markdown
Collaborator Author

Updates:

  • Solved the "mock now problem" with Instant and Advance from tokio::time;
  • Added sample of "saw new header..." compact block version log in log_extractor.proto;
  • Added BandwidthMode enum;
  • Dropped heatmap panel on "Compact block reconstruction time" dashboard;
  • Refactored "Average size of requested transactions per day" to "Requested transactions stats":
    • Including size, number of transactions requested and number of transactions in extra pool;
    • For those I thought that it was better to see the sum of a period than the "single" points of each event -- most of them are low values but when a "outlier" appears, it messes up the view;
    • But there's also the panel with each event separated, similar to "Compact block reconstruction time" first panels;
    • The histogram for size of transactions requested also suffers from the same "outlier" problem.

WIP: I'm still working on this comment about intermitent errors that I've added in log extractor integration tests.

Requested transactions stats

Captura de tela_5-5-2026_145039_5 189 165 114

@m4ycon
m4ycon force-pushed the feat/compact-block-reconstruction branch 2 times, most recently from dee352c to d40862c Compare May 7, 2026 14:04
@m4ycon

m4ycon commented May 7, 2026

Copy link
Copy Markdown
Collaborator Author

Solved last pending fix about intermitent errors on log extractor integration tests (comment).

In "Saw new..." log case, it happened that if node was still doing IBD, this would only be logged if -debug=validation was activated (core ref), so I wait for IBD to complete.

async |node1, node2| {
    // first chain tip
    node2.generate_to_address(1, &REGTEST_ADDRESS).unwrap();
    // wait for node1 to finish IBD
    while node1.get_blockchain_info().unwrap().initial_block_download {
      sleep(Duration::from_millis(50)).await;
    }
    // this block should trigger the SawNewHeaderLog
    node2.generate_to_address(1, &REGTEST_ADDRESS).unwrap();
},

And for "Succesfully reconstructed...", it seems to be also related to IBD but in a more complex way, it depends on how fast node1 requests for blocks, the first one will arrive as a BLOCK message and the node must mark IBD as completed, so it won't have a tip that is too old from the actual one (which is actually none), then it asks for the second block and this one will arrive as a CMPCTBLOCK message. Much of it relates to CanDirectFetch response.

Fail case logs:

2026-05-07T14:36:41Z [net] received: getheaders (69 bytes) peer=0
2026-05-07T14:36:41Z [net] getheaders -1 to end from peer=0
2026-05-07T14:36:41Z [net] sending headers (1 bytes) peer=0
2026-05-07T14:36:41Z [net] received: feefilter (8 bytes) peer=0
2026-05-07T14:36:41Z [net] received: feefilter of 0.09936506 BTC/kvB from peer=0
2026-05-07T14:36:41Z [net] received: pong (8 bytes) peer=0
2026-05-07T14:36:41Z [net] received: headers (1 bytes) peer=0
2026-05-07T14:36:41Z [net] pcp: Timeout
2026-05-07T14:36:41Z [net] pcp: Retrying (1)
2026-01-01T00:00:00Z PIPELINE_READY:1778164601876751855
2026-05-07T14:36:41Z [net] received: inv (37 bytes) peer=0
2026-05-07T14:36:41Z [net] got inv: block 1e10c9d427f153f00678a5822ba959c70138105eff9bf2e8d3953fa2c7efe9d3  new peer=0
2026-05-07T14:36:41Z [net] sending getheaders (69 bytes) peer=0
2026-05-07T14:36:41Z [net] getheaders (0) 1e10c9d427f153f00678a5822ba959c70138105eff9bf2e8d3953fa2c7efe9d3 to peer=0
2026-05-07T14:36:41Z [net] received: feefilter (8 bytes) peer=0
2026-05-07T14:36:41Z [net] received: feefilter of 0.00000100 BTC/kvB from peer=0
2026-05-07T14:36:41Z [net] received: headers (82 bytes) peer=0
2026-05-07T14:36:41Z Synchronizing blockheaders, height: 1 (~100.00%)
2026-05-07T14:36:41Z [net] sending sendheaders (0 bytes) peer=0
2026-05-07T14:36:41Z [net] Requesting block 1e10c9d427f153f00678a5822ba959c70138105eff9bf2e8d3953fa2c7efe9d3 (1) peer=0
2026-05-07T14:36:41Z [net] sending getdata (37 bytes) peer=0
2026-05-07T14:36:41Z [net] received: headers (82 bytes) peer=0
2026-05-07T14:36:41Z Synchronizing blockheaders, height: 2 (~100.00%)
2026-05-07T14:36:41Z [net] Requesting block 207db7d3380b6eafcc4afdf3630f6ee0d3c720eeb70109711172057f9ef59fc5 (2) peer=0
2026-05-07T14:36:41Z [net] sending getdata (37 bytes) peer=0
2026-05-07T14:36:41Z [net] received: block (248 bytes) peer=0
2026-05-07T14:36:41Z [net] received block 1e10c9d427f153f00678a5822ba959c70138105eff9bf2e8d3953fa2c7efe9d3 peer=0
2026-05-07T14:36:41Z Leaving InitialBlockDownload (latching to false)
2026-05-07T14:36:41Z UpdateTip: new best=1e10c9d427f153f00678a5822ba959c70138105eff9bf2e8d3953fa2c7efe9d3 height=1 version=0x20000000 log2_work=2.000000 tx=2 date='2026-05-07T14:36:41Z' progress=0.769231 cache=0.3MiB(1txo)
2026-05-07T14:36:41Z [net] sending feefilter (8 bytes) peer=0
2026-05-07T14:36:41Z [net] received: block (248 bytes) peer=0
2026-05-07T14:36:41Z [net] received block 207db7d3380b6eafcc4afdf3630f6ee0d3c720eeb70109711172057f9ef59fc5 peer=0
2026-05-07T14:36:41Z [net] sending sendcmpct (9 bytes) peer=0
2026-05-07T14:36:41Z UpdateTip: new best=207db7d3380b6eafcc4afdf3630f6ee0d3c720eeb70109711172057f9ef59fc5 height=2 version=0x20000000 log2_work=2.584963 tx=3 date='2026-05-07T14:36:42Z' progress=1.000000 cache=0.3MiB(2txo)
2026-05-07T14:36:42Z [net] pcp: Timeout
2026-05-07T14:36:42Z [net] pcp: Retrying (2)
2026-05-07T14:36:43Z [net] pcp: Timeout
2026-05-07T14:36:43Z [net] pcp: Giving up after 3 tries
2026-05-07T14:36:43Z [net] portmap: Could not determine IPv6 default gateway

Success case logs:

2026-05-07T14:40:01Z [net] received: ping (8 bytes) peer=0
2026-05-07T14:40:01Z [net] sending pong (8 bytes) peer=0
2026-05-07T14:40:01Z [net] received: getheaders (69 bytes) peer=0
2026-05-07T14:40:01Z [net] getheaders -1 to end from peer=0
2026-05-07T14:40:01Z [net] sending headers (1 bytes) peer=0
2026-05-07T14:40:01Z [net] received: feefilter (8 bytes) peer=0
2026-05-07T14:40:01Z [net] received: feefilter of 0.09936506 BTC/kvB from peer=0
2026-05-07T14:40:01Z [net] received: pong (8 bytes) peer=0
2026-05-07T14:40:01Z [net] received: headers (1 bytes) peer=0
2026-01-01T00:00:00Z PIPELINE_READY:1778164802299061689
2026-05-07T14:40:02Z [net] pcp: Timeout
2026-05-07T14:40:02Z [net] pcp: Retrying (1)
2026-05-07T14:40:02Z [net] received: inv (37 bytes) peer=0
2026-05-07T14:40:02Z [net] got inv: block 0f00027dc2cf7d93e9680ed33c15446a7c08a4d2984773beda547e16dda08a92  new peer=0
2026-05-07T14:40:02Z [net] sending getheaders (69 bytes) peer=0
2026-05-07T14:40:02Z [net] getheaders (0) 0f00027dc2cf7d93e9680ed33c15446a7c08a4d2984773beda547e16dda08a92 to peer=0
2026-05-07T14:40:02Z [net] received: feefilter (8 bytes) peer=0
2026-05-07T14:40:02Z [net] received: feefilter of 0.00000100 BTC/kvB from peer=0
2026-05-07T14:40:02Z [net] received: headers (82 bytes) peer=0
2026-05-07T14:40:02Z Synchronizing blockheaders, height: 1 (~100.00%)
2026-05-07T14:40:02Z [net] sending sendheaders (0 bytes) peer=0
2026-05-07T14:40:02Z [net] Requesting block 0f00027dc2cf7d93e9680ed33c15446a7c08a4d2984773beda547e16dda08a92 (1) peer=0
2026-05-07T14:40:02Z [net] sending getdata (37 bytes) peer=0
2026-05-07T14:40:02Z [net] received: block (248 bytes) peer=0
2026-05-07T14:40:02Z [net] received block 0f00027dc2cf7d93e9680ed33c15446a7c08a4d2984773beda547e16dda08a92 peer=0
2026-05-07T14:40:02Z Leaving InitialBlockDownload (latching to false)
2026-05-07T14:40:02Z UpdateTip: new best=0f00027dc2cf7d93e9680ed33c15446a7c08a4d2984773beda547e16dda08a92 height=1 version=0x20000000 log2_work=2.000000 tx=2 date='2026-05-07T14:40:02Z' progress=1.000000 cache=0.3MiB(1txo)
2026-05-07T14:40:02Z [net] sending feefilter (8 bytes) peer=0
2026-05-07T14:40:02Z [net] received: headers (82 bytes) peer=0
2026-05-07T14:40:02Z Saw new header hash=5e40f7271d321566afc89fc9bdfc30f6ba498b563b3572d77e40ceeb5b8885bb height=2 peer=0
2026-05-07T14:40:02Z [net] Requesting block 5e40f7271d321566afc89fc9bdfc30f6ba498b563b3572d77e40ceeb5b8885bb from  peer=0
2026-05-07T14:40:02Z [net] sending getdata (37 bytes) peer=0
2026-05-07T14:40:02Z [net] received: cmpctblock (258 bytes) peer=0
2026-05-07T14:40:02Z [cmpctblock] Initializing PartiallyDownloadedBlock for block 5e40f7271d321566afc89fc9bdfc30f6ba498b563b3572d77e40ceeb5b8885bb using a cmpctblock of 258 bytes
2026-05-07T14:40:02Z [cmpctblock] Initialized PartiallyDownloadedBlock for block 5e40f7271d321566afc89fc9bdfc30f6ba498b563b3572d77e40ceeb5b8885bb using a cmpctblock of 258 bytes
2026-05-07T14:40:02Z [cmpctblock] Successfully reconstructed block 5e40f7271d321566afc89fc9bdfc30f6ba498b563b3572d77e40ceeb5b8885bb with 1 txn prefilled, 0 txn from mempool (incl at least 0 from extra pool) and 0 txn (0 bytes) requested
2026-05-07T14:40:02Z [net] sending sendcmpct (9 bytes) peer=0
2026-05-07T14:40:02Z UpdateTip: new best=5e40f7271d321566afc89fc9bdfc30f6ba498b563b3572d77e40ceeb5b8885bb height=2 version=0x20000000 log2_work=2.584963 tx=3 date='2026-05-07T14:40:03Z' progress=1.000000 cache=0.3MiB(2txo)

@m4ycon

m4ycon commented May 7, 2026

Copy link
Copy Markdown
Collaborator Author

I think I've solved the main issues here, I'll mark it as ready for review.

And I would like more opinions about the dashboards, more specifically about the recent one Requested transactions stats, maybe it has too much info on it? Do you guys agree with the way I'm showing data? Is there a better one?

And just a reminder, it would be good if reviewers could take a look at dashboard expressions, because of Using a gauge metric, how do we know if a new reconstruction happened?.

@m4ycon
m4ycon marked this pull request as ready for review May 7, 2026 15:35
Comment thread extractors/log/tests/integration.rs Resolved
@m4ycon
m4ycon force-pushed the feat/compact-block-reconstruction branch 2 times, most recently from 5e396da to 9777f8d Compare May 11, 2026 18:00
@m4ycon

m4ycon commented May 11, 2026

Copy link
Copy Markdown
Collaborator Author

Updates: Rebased with main and prevented infinite verification loop in integration tests with a timeout.

@m4ycon
m4ycon force-pushed the feat/compact-block-reconstruction branch from 9777f8d to 3df5d71 Compare May 11, 2026 18:09
@octaviolucca

Copy link
Copy Markdown
Collaborator

Tested locally, log parsing and metrics emission working as expected. Dashboards looking good.

@m4ycon
m4ycon force-pushed the feat/compact-block-reconstruction branch from 3df5d71 to 8c848ab Compare May 21, 2026 19:50
@m4ycon

m4ycon commented May 21, 2026

Copy link
Copy Markdown
Collaborator Author

Rebased with main.

Also, I was about to run cargo build to check if I didn't break anything before push -f, but IPC extractor wasn't building because I didn't have its libs installed, I took a look at its readme and there wasn't anything saying that I was supposed to run sudo apt-get install libcapnp-dev capnproto to get it to work. Which leads me to think if that kind of information is really meant to be implicit -- same for ebpf extractor. Any thoughts on this @0xB10C? Maybe that's not the better place to talk about it, a issue maybe, idk...

@0xB10C

0xB10C commented May 22, 2026

Copy link
Copy Markdown
Collaborator

I'll have a look at this in details soon. It might also make sense to deploy on the demo hosts for now.

Also, I was about to run cargo build to check if I didn't break anything before push -f, but IPC extractor wasn't building because I didn't have its libs installed, I took a look at its readme and there wasn't anything saying that I was supposed to run sudo apt-get install libcapnp-dev capnproto to get it to work. Which leads me to think if that kind of information is really meant to be implicit -- same for ebpf extractor. Any thoughts on this @0xB10C? Maybe that's not the better place to talk about it, a issue maybe, idk...

Maybe having a setup documentation for common OS is reasonable, yes. A place that might give a hint on what's needed is what the CI is installing on each run. I feel a docs section might get outdated fast and I'm not sure yet how to best check this yet. Could we improve the documentation on what the CI installs and why, and then link to it?

@m4ycon

m4ycon commented May 22, 2026

Copy link
Copy Markdown
Collaborator Author

Maybe having a setup documentation for common OS is reasonable, yes. A place that might give a hint on what's needed is what the CI is installing on each run. I feel a docs section might get outdated fast and I'm not sure yet how to best check this yet. Could we improve the documentation on what the CI installs and why, and then link to it?

I agree that creating two places with an information that must be synced is pretty bad and hard to maintain. CI is a good source, we don't have to detail too much about it on readmes, a simple link works fine. If necessary we could let a comment in the CI file, after each package and if that package is needed for a specific case we have something pointing that out. e.g.

        sudo apt-get install -y \
          protobuf-compiler \
          ...
          elfutils \
          gcc-multilib \
          libcapnp-dev \ # ipc-extractor
          capnproto # ipc-extractor

@deadmanoz

Copy link
Copy Markdown
Collaborator

@m4ycon I will get this up and running on one of my VPSs so I can thoroughly review. Apologies it has taken me so long to get around to looking at this!

@m4ycon

m4ycon commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator Author

I don't know - maybe hide it by default (if that's possible). Or remove it, and we'll see if we need it again. Maybe something like this?

I'll "remove" it, it will be hidden but the query will still exists (Hide response from grafana).

However, I'm not actually sure what you are trying to show with this chart. What do you mean by "dispersion"? Is there a better name for it?

Dispersion, I was thinking more about the dots, but it's just a fancy name, it doesn't add nothing to the understanding. I guess that just removing it already makes it better (i.e. "Reconstruction time" or "Block reconstruction time").

And what does the chart tell us, I'm not sure. It's the top chart, so I assume it's the most important one? If not, what is the most important one?

I think it is, but the dots were misleading what could draw attention, even more if there were more nodes in the panel.

You mentioned median, do you think median over average is better in this case? IMO average seems to be better 🤔.

Sure, I think the problem is that I don't yet fully understand the chart. See above. It's not clear to me: What does this show? What happens if there's a big spike (is it a problem)?

Some strange behaviors happened to me (not sure why, maybe bad vps neighbors), I can test what would have draw our attention more on those cases (median or average). About spikes, well, I think after sometime we can realize what is "normal" or not.

image

Maybe a panel with "median block reconstruction time by host" would be the most important one at the top. This one would mix together high- and low-bandwidth and tx-requested and not-requested. The others are for "more information" and drilling down.

Might also make sense to have this split by bandwidth AND tx-requested. So essentially have four charts.

ACK for both.

For this PR, it might actually have made sense to PR the metrics first, show a minimal PoC dashboard to test it, and then iterate on a dashboard. With +2450 added lines this PR is quite big, and will naturally take longer to be merged.

I don't think the number of added lines is such a problem as ~1700 of it are from dashboards and maybe we only really care for ~100 of it (?), but of course, 850 still big haha. I agree, this is a really good idea, most of the recent discussions are about the dashboards.

I'll push here a simple version of these dashboards (at some point), then create a follow up PR for the "complex" ones. Btw the code isn't supposed to change at all, if anyone wants to review while it.

@m4ycon
m4ycon force-pushed the feat/compact-block-reconstruction branch from 1494d76 to 1620e37 Compare June 11, 2026 22:42
@m4ycon

m4ycon commented Jun 11, 2026 •

Copy link
Copy Markdown
Collaborator Author

Updates:

  • Simplified "Compact block reconstruction time", it just shows the average of those measures with no filters (btw median didn't seems to be too different, even for my weird cases);
  • Also remove some panels from "Requested transactions stats", there's only number/size of requested txs, and number of txs from extra pool.

I think this is enough to test the PR, probably tomorrow I open other PR (pointing to this one) with the complex/detailed dashboards as a follow up, also with the adjustments pointed by b10c.

@deadmanoz

Copy link
Copy Markdown
Collaborator

This is, overwhelmingly, pretty great work!! Nicely done @m4ycon

However, I think there's one minor issue in that the requested-tx stats dashboard is using the wrong metric type for its interval totals.

peerobserver_log_compact_block_reconstruction_requested_bytes, peerobserver_log_compact_block_reconstruction_txs_requested, and peerobserver_log_compact_block_reconstruction_txs_extra_pool are registered as IntGauges. This means that each scrape records whichever value was set most recently, not an accumulated interval total.

Then increase(...[$__interval]) is used on those gauges. increase calculates the increase over a range, with counter-reset handling. The docs also say that increase "should only be used with counters." It does not sum the per-event values in that range; it treats the sample stream as monotonic, with decreases interpreted as counter resets. This is decrease-is-effectively-a-reset, is the issue.

Example: suppose four compact-block reconstructions request 777, 0, 444, and 886 bytes. The gauge series stores the current value after each .set(...), while a counter keeps the running total:

gauge:   0 -> 777 -> 0 -> 444 -> 886
counter: 0 -> 777 -> 777 -> 1221 -> 2107

The total, given by increase(counter[...]), is 2107. increase(gauge[...]) sees the 777 -> 0 drop as a counter reset, then counts only the upward steps (0 -> 777, 0 -> 444, 444 -> 886), which is 1663, not the sum of the reconstruction values.

I tested this on a synced mainnet node by adding three temporary counters in the same CompactBlockReconstructedLog arm and incrementing them from the exact same event fields. After roughly 75 compact-block reconstruction events in the last ~24h, the dashboard-style gauge query was already below the counter-backed value:

series increase(gauge[24h]) increase(counter[24h]) undercount
requested_bytes 210,937.05 257,140.94 17.97%
txs_requested 751.19 838.22 10.38%
txs_extra_pool 787.20 1,028.26 23.44%

There were no counter resets in that window, so this is not a restart artefact. Also, here's a screenshot to show what the differences look like:

Screenshot 2026-06-12 at 4 21 18 pm

I think the fix is to make these three aggregate stats counters and inc_by(...) them per reconstruction. The existing log_compact_block_reconstruction_count metric already has the right counter use for event counts; these requested-tx aggregate fields seem like the same kind of interval-total metric?

@m4ycon
m4ycon force-pushed the feat/compact-block-reconstruction branch 2 times, most recently from 03fea35 to 172d30a Compare June 12, 2026 23:51
@m4ycon

m4ycon commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator Author

wow, thank you for the lesson/review @deadmanoz 😃! You dissected the problem very well.

Updates (diff here):

  • log_compact_block_reconstruction_requested_bytes, log_compact_block_reconstruction_txs_requested and log_compact_block_reconstruction_txs_extra_pool were updated to be a counter instead of a gauge, as pointed out in his comment, increase is not supposed to be used with a gauge.
  • Also, simplified "Requested transactions stats" queries.

Comment thread tools/metrics/src/lib.rs Resolved
Comment thread shared/src/lib.rs Resolved
Comment thread shared/Cargo.toml Resolved
Comment thread tools/metrics/tests/integration.rs Resolved
@0xB10C

0xB10C commented Jun 27, 2026

Copy link
Copy Markdown
Collaborator

I've code-reviewed the Rust changes. I haven't looked at the changed dashboards (as I don't have this deployed anywhere) nor re-tested this. If you want, we can split out and merge the Rust code change (once comments are addressed) and then merge this PR with the dashboard. What do you think?

Additionally, I can recommend https://cbea.ms/git-commit/ for have slightly more context (what and why) in commit messages. These make the life of a reviewer easier and result in this getting merged faster!

@m4ycon
m4ycon force-pushed the feat/compact-block-reconstruction branch from 172d30a to 1374c23 Compare June 29, 2026 18:22
@m4ycon

m4ycon commented Jun 29, 2026 •

Copy link
Copy Markdown
Collaborator Author

Updates:

  • Removed pub extern crate time; from shared;
  • Updated 7ee9cb7 description about test-util and why publish_and_check was refactored;
  • 7ee9cb7 and 77e1033 tries to folllow more cbeams git recommendations.

I've code-reviewed the Rust changes. I haven't looked at the changed dashboards (as I don't have this deployed anywhere) nor re-tested this. If you want, we can split out and merge the Rust code change (once comments are addressed) and then merge this PR with the dashboard. What do you think?

Regarding this, I think I've simplified dashboards enough for a POC as you suggested in a past comment -- they are more straightfoward now. I was thinking about introducing those "complex/detailed" dashboards in a follow-up PR and keeping this one with the minimun or simplier dashs that wouldn't require a deep review.

Do you think that keeping these dashboards here, would require a long "observe window" in your demo nodes? Or maybe a deep review? I think that most, if not all, of the problems that it had people already commented idk 🤔.

@m4ycon
m4ycon force-pushed the feat/compact-block-reconstruction branch from 1374c23 to 7ebb2a0 Compare June 29, 2026 18:50
Refactored `publish_and_check` to separate metrics startup from its
execution and assertion. This was required as a new test needed send
some events, advance time, send some extra events, and finally the
assertions.

To simulate time passage, tokio `test-util` was added to use
`tokio::time::advance`.
@m4ycon
m4ycon force-pushed the feat/compact-block-reconstruction branch from 7ebb2a0 to 7ed4f4a Compare June 29, 2026 19:37
@m4ycon
m4ycon force-pushed the feat/compact-block-reconstruction branch from 7ed4f4a to a178e87 Compare June 29, 2026 19:39
@0xB10C

0xB10C commented Jun 30, 2026

Copy link
Copy Markdown
Collaborator

Do you think that keeping these dashboards here, would require a long "observe window" in your demo nodes? Or maybe a deep review?

It would be nice to have a look at the dashboards before merging them. While I was running this PR for a while on the demo nodes, it's a lot of work to do this for me on every change here:

While running this (possibly for multiple weeks to collect data for the dashboards to fill up), I can't run anything else on there, and can't test any other PRs or infrastructure upgrades. While I abuse them as dev nodes, these are actually demo nodes.

Merging the backend changes without the dashboards, would allow me to just run peer-observer master, which does require a lot less of my time to setup and run than running a PR. We can then collect data and add temporary (as in: not tracked in Git, but stored on Grafana) dashboards there. Once we merged a dashboard, they are "provisioned" and can't be changed on my nodes (provisioning makes them immutable). That's why I've been reviewing and merging backend/metric changes first, then collecting data, and then finalizing the dashboards. See for example #257 and #334.

That's why I've been suggesting to split this up and merge the backend first. It would be a big time saver for me, and allow me to get back to more meaning full work than keeping the dev-branches of the infrastructure rebased each time there's a change here...

@0xB10C 0xB10C left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed the code. Thanks for the commit message, that makes it clear.

@m4ycon

m4ycon commented Jun 30, 2026 •

Copy link
Copy Markdown
Collaborator Author

I see... I didn't imagine the ton of work to setup a single PR on one of yours demo nodes. I think that's the kind of info that would be good to have in a CONTRIBUTING.md or maybe a little section on readme, it's a very strong argument in favor of faster review/merges.

That said, I will remove the last commit that adds the dashboards and create a follow up with it.

EDIT: updated description accordingly.

@m4ycon
m4ycon force-pushed the feat/compact-block-reconstruction branch from a178e87 to 77e1033 Compare June 30, 2026 17:12
@0xB10C

0xB10C commented Jun 30, 2026

Copy link
Copy Markdown
Collaborator

I see... I didn't imagine the ton of work to setup a single PR on one of yours demo nodes.

Maybe that's also an area where I can improve. Or maybe it makes sense to have an dev-instance that we can use for something like this.. Maybe not even using nix, so it's faster to switch out commits.

Since last review, this only removed the dashboards. So this is ready to merge! Thanks for hanging in here. Feel free to open the PR for the dashboards right away. I'll try to deploy the metrics changes tonight or tomorrow so we can start collecting this data.

@0xB10C
0xB10C merged commit ee8bb22 into peer-observer:master Jun 30, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants