Repository navigation
Watching compact block reconstructions via log-extractor - #420
Conversation
m4ycon
left a comment
There was a problem hiding this comment.
Some specific code comments that I would appreciate suggestions/opinions on it.
| check( | ||
| vec!["-debug=cmpctblock"], | ||
| |_node1, node2| { | ||
| node2.generate_to_address(1, ®TEST_ADDRESS).unwrap(); // this block will trigger SENDCMPCT trade between nodes | ||
| node2.generate_to_address(1, ®TEST_ADDRESS).unwrap(); // this block will trigger the actual CompactBlockReconstructedLog | ||
| }, | ||
| |event| match event { |
There was a problem hiding this comment.
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 🤔.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)", |
There was a problem hiding this comment.
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.
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. |
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 🤔. |
|
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,
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?
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.
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?
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). |
|
Answering @0xB10C
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.
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. |
376594e to
717b3a5
Compare
Updates:
WIP: I'm still working on this comment about intermitent errors that I've added in log extractor integration tests. Requested transactions stats
|
dee352c to
d40862c
Compare
|
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 async |node1, node2| {
// first chain tip
node2.generate_to_address(1, ®TEST_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, ®TEST_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 Fail case logs: Success case logs: |
|
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?. |
5e396da to
9777f8d
Compare
|
Updates: Rebased with main and prevented infinite verification loop in integration tests with a timeout. |
9777f8d to
3df5d71
Compare
|
Tested locally, log parsing and metrics emission working as expected. Dashboards looking good. |
3df5d71 to
8c848ab
Compare
|
Rebased with main. Also, I was about to run |
|
I'll have a look at this in details soon. It might also make sense to deploy on the demo hosts for now.
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 |
|
@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! |
1494d76 to
1620e37
Compare
|
Updates:
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. |
|
This is, overwhelmingly, pretty great work!! Nicely done @m4ycon However, I think there's one minor issue in that the
Then Example: suppose four compact-block reconstructions request The total, given by I tested this on a synced mainnet node by adding three temporary counters in the same
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:
I think the fix is to make these three aggregate stats counters and |
03fea35 to
172d30a
Compare
|
wow, thank you for the lesson/review @deadmanoz 😃! You dissected the problem very well. Updates (diff here):
|
|
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! |
172d30a to
1374c23
Compare
|
Updates:
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 🤔. |
1374c23 to
7ebb2a0
Compare
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`.
7ebb2a0 to
7ed4f4a
Compare
7ed4f4a to
a178e87
Compare
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
left a comment
There was a problem hiding this comment.
Re-reviewed the code. Thanks for the commit message, that makes it clear.
|
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 That said, I will remove the last commit that adds the dashboards and create a follow up with it. EDIT: updated description accordingly. |
a178e87 to
77e1033
Compare
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. |



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?
log_compact_block_reconstruction_requested_bytes,log_compact_block_reconstruction_countandlog_compact_block_reconstruction_time.What kind of question could this PR answer?
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=cmpctblockflag).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=1as 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
cmpctblockmessage orheaders/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_timemeasure 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
HashMapstate 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=cmpctblockflag as it will never receive the "end" log.