Offload blocking wallet calls to spawn_blocking#18
Merged
amackillop merged 1 commit intolsp-0.7.0from Apr 15, 2026
Merged
Conversation
BDK wallet operations (apply_update, create_funding_transaction, get_spendable_amount_sats) internally acquire a mutex and walk the checkpoint chain, giving O(T*C) runtime where T is the number of transactions and C is the number of checkpoints. Running these on a tokio worker thread blocks the entire async executor during sync-heavy workloads. Move these calls to spawn_blocking so they run on the tokio blocking threadpool instead. This is a stopgap until the underlying issue is addressed in BDK. JoinError (panic or runtime shutdown) is mapped into the existing error paths at each call site: WalletOperationFailed for esplora sync and funding tx creation, unwrap_or(0) for spendable balance checks (conservative default that skips channel opens).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
BDK wallet operations (apply_update, create_funding_transaction, get_spendable_amount_sats) internally acquire a mutex and walk the checkpoint chain, giving O(T*C) runtime where T is the number of transactions and C is the number of checkpoints. Running these on a tokio worker thread blocks the entire async executor during sync-heavy workloads.
Move these calls to spawn_blocking so they run on the tokio blocking threadpool instead. This is a stopgap until BDK lands their height-indexed checkpoint work upstream.
JoinError (panic or runtime shutdown) is mapped into the existing error paths at each call site: WalletOperationFailed for esplora sync and funding tx creation, unwrap_or(0) for spendable balance checks (conservative default that skips channel opens).