Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #730.
An actor that manages the
bdk::Wallet
resource. It allows us to use the wallet whilst the inevitably expensive on-chain sync is happening in the background. But only for those things that can be cached, such as the balance, wallet history and addresses.We would like to use the async version of
EsploraBlockchain
, but bitcoindevkit/bdk#165 is still an issue.The only hacky bit stems from the fact that we still have to implement certain non-async foreign traits and to access any
bdk::Wallet
resource we now have to go via async methods, since the actor is async.To do so, at some point we have to call an async function "from a sync context". The natural way to do so (for me) would be to use
runtime.block_on
, which schedules an async task and waits for it to resolve, blocking the thread. But, these non-async foreign trait methods are actually called elswhere in async contexts. This leads toruntime.block_on
panicking becausetokio
is trying to prevent us from blocking a thread in an async context. This is analogous to us misusing async and doing an expensive CPU-bound computation in an async context, but heretokio
is able to "aid" us sinceblock_on
is provided bytokio
.The solution is to use the following pattern:
From the documentation of
block_in_place
, we are able to run "the provided blocking function on the current thread without blocking the executor". We therefore avoid the panic, as we no longer block the executor when callingblock_on
.This has one final side-effect, which is that all
ln-dlc-node
async tests now need to go back to using themulti_thread
flavour.block_in_place
works by moving all scheduled tasks to a different worker thread and withoutmulti_thread
there is only one worker thread, so it just panics.