Derive shutdown scripts without blocking on wallet persistence - #1011
Draft
jkczyz wants to merge 1 commit into
Draft
Derive shutdown scripts without blocking on wallet persistence#1011jkczyz wants to merge 1 commit into
jkczyz wants to merge 1 commit into
Conversation
LDK invokes the sync `SignerProvider::get_shutdown_scriptpubkey` and `get_destination_script` callbacks on runtime worker threads while holding channel locks, e.g. when accepting an inbound channel. Blocking there on wallet persistence could deadlock the runtime: the parked callback still held the channel locks, other tasks blocking synchronously on those locks captured the remaining worker cores, and the persistence future the callback waited on could then never be polled. Observed as a permanent hang of integration test runs. Instead, reveal the address without waiting and persist the staged change set in the background. A persistence failure therefore no longer rejects the channel; if the node crashes before the flush lands, the revealed index may be handed out again after restart, which BDK's keychain lookahead tolerates. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
👋 Hi! I see this is a draft PR. |
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.
Fixes #1010
LDK invokes the sync
SignerProvider::get_shutdown_scriptpubkeyandget_destination_scriptcallbacks on runtime worker threads while holding channel locks, e.g. from the event handler when accepting an inbound channel. These callbacks calledRuntime::block_onto await wallet persistence, which can deadlock the runtime:block_onwhile holding the per-peer channelMutex(its worker core is handed off viablock_in_place).lightning-net-tokiotask whosePeerManager::process_eventsblocks synchronously on that sameMutex, capturing the core.Observed as permanent hangs of
integration_tests_rustruns under load (the tests run the node on a single-worker runtime, where one captured core is fatal). See #1010 for full thread samples and analysis.Instead of waiting on persistence, the callbacks now reveal the address under the sync wallet lock and persist the staged change set from a background task, using the same persister-lock →
take_stagedordering as every other persist path.Two semantics changes worth calling out:
KeysManagerprovides for shutdown scripts.The new test gates the acceptor's
bdk_wallet-namespace store writes during a channel open: without the fix the acceptor wedges inget_shutdown_scriptpubkeyand the open times out (reproducing the deadlock deterministically); with it the open completes and the deferred persist lands once the store recovers.Drafted with the assistance of Claude Code.