Bitcoin full node and query server

Feb 23, 2023

View in context in the libbitcoin Slack #general mirror.

evoskuil10:19
Been working off some technical debt. We have three places where we fan out asynchronous operations and have to resynchronize them. This is a little different than startup/shutdown, because sessions and channels are never really recombined, they just are terminated and the process waits on threadpool join. When the threadpool is continuing it's a different model. I have dealt with this before, but never satisfactorily. Just finished up three small templates that provide similar but distinct capability for this. I call these racers. I have looked at boost asio tools for this in the past but never found anything that was quite right. These are tools that operate on a single common strand, with asynchronous events (like timer, connect, accept, cancel) moving handlers to a strand for ordered execution. So there's no issue with actual concurrency, just a need to convert multiple events into one handler invoke based on various criteria. Each accepts a hander on start and fires it upon being invoked with completion arguments a certain number of times and/or with certain values. So I have a "speed racer" that invokes the handler after template N finishes, passing the arguments of the first. IOW the first finisher wins (and should cancel the others) but the invoke doesn't occur until all are finished. Also a "quality racer" that invokes after parameter N finishes, with the first successful finisher winning (getting its arguments passed on). And finally a "volume racer", with a "complete" handler invoked when all N have finished, and a "sufficient" handler invoked as soon as a volume (such as count of connections) is reached. These are used in the connector (speed race between timer and socket connect), session_outbound (quality race between a set of connectors, with the first successful connection winning), and session_seed (volume race, completing when all seed nodes close and sufficient when a target number of addresses is obtained - or all nodes are closed). These then can be easily fully tested and reduced some longstanding complex code to trivial, just a couple lines in each usage. All working well, tests almost done.