Repository navigation
cmpctblock: Cache serialized cmpctblock msg for relay [part of prefill series] - #36787
davidgumberg wants to merge 4 commits into
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. External sites
ReviewsSee the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
This commit is drawn from the closed bitcoin#26755. (bitcoin#26755) This also changes `std::launch::deferred` to `std::launch::async` since we are likely going to use this result very soon if someone has requested HB blocks from us, and if no one has, then performance here is not that critical. Co-authored-by: Andrew Toth <[email protected]>
Also one non-refactor change which is setting the `pIndexBestHeaderSent` on the `SendMessages` CMPCTBLOCK announcement fallback.
Noticed while making changes to compact blocks code, right now `PeerHasHeader` relies on callers to never make the mistake of calling it with a nullptr, `state` can be trivially made into a reference, and we can add an Assume for pindex being nullptr, and fall back to returning false.
9285ade to
d84a57a
Compare
| const std::shared_future<CSerializedNetMsg> lazy_ser{ | ||
| std::async(std::launch::deferred, [&] { return NetMsg::Make(NetMsgType::CMPCTBLOCK, *pcmpctblock); })}; | ||
| std::shared_future<CSerializedNetMsg> lazy_ser{ | ||
| std::async(std::launch::async, [pblock = pblock] { |
There was a problem hiding this comment.
for reference, the reason I didn't pick async was that this would create an unnamed/global/unscoped/hidden thread pool. I guess this should be fine, but the commit msg could say that this will introduce a new thread(pool) beside the named threads:
myprogram # main
myprogram # std::async worker, usually unnamed
initload ,... # named TraceThreads/ named Pools
edit: Also ralph says this, while it is likely ai slop, it highlights that this is not a trivial change and reviewers would have to look at the error handling path in this line
🟠 Minor · Thread-launch failure interrupts block acceptance before storage
Under local thread-resource exhaustion, the forced async launch can interrupt acceptance of a new tip-extending block before storage, although a retry can recover.
There was a problem hiding this comment.
Now that we have ThreadPool, could we instantiate one owned by, say, PeerManager, with a single thread that is then used here instead? That would alleviate the concerns about implicit thread lifecycle handling, and let us explicitly handle errors if we fail to submit the task.
There was a problem hiding this comment.
Looks like https://github.com/bitcoin/bitcoin/pull/36955/changes replaces this anyway
| }); | ||
| } | ||
|
|
||
| LogDebug(BCLog::NET, "%s sending header-and-ids %s to peer=%d\n", __func__, |
There was a problem hiding this comment.
nit: While changing the log output, could remove all the fluent/redundant __func__ or reword them to something hard-coded and unique. (Also, drop the trailing newlines, while touching.
|
Concept ACK |

This PR extends the optimization added in #23880 which applies to peers that have requested HB blocks from us to also cache the serialized blocks for low-bandwidth peers. The core change here comes from the closed #26755 made by andrewtoth, but also includes other refactors and type safety improvements.
Performance is less critical for low-bandwidth peers, so this change on its own should have little impact on block propagation, but these refactors are useful as part of #35558 which adds prefilling of compact blocks, and where we run the risk of potentially having to serialize more than one cmpctblock_msg (one prefilled and one not-prefilled).