Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/.vitepress/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const docsSidebar: DefaultTheme.SidebarItem[] = [
{ text: 'Sending Payments', link: '/building-a-node-with-ldk/sending-payments' },
{ text: 'Receiving Payments', link: '/building-a-node-with-ldk/receiving-payments' },
{ text: 'Closing a Channel', link: '/building-a-node-with-ldk/closing-a-channel' },
{ text: 'Shutting Down a Node', link: '/building-a-node-with-ldk/shutting-down-a-node' },
],
},
{ text: 'Running a sample LDK node', link: '/running-a-sample-ldk-node' },
Expand Down
36 changes: 36 additions & 0 deletions docs/building-a-node-with-ldk/shutting-down-a-node.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Shutting Down a Node

An orderly shutdown stops node activity and saves the state needed for the next
start. Open channels can stay open while the node is offline.

## LDK Node

Stop accepting new application requests and call
[`Node::stop`](https://docs.rs/ldk-node/latest/ldk_node/struct.Node.html#method.stop).
Check the result and wait for the call to finish before exiting the process.

## Custom integrations

1. Stop accepting new requests that change Lightning state, such as sending
payments or opening channels. Stop delivering new peer messages and chain
notifications to LDK, and let callbacks already in progress finish.
2. Keep persistence available while the node winds down. If your channel
monitor persister completes writes asynchronously, wait for outstanding
writes and deliver their completion notifications to LDK before shutting
down the event loop. Follow the requirements in the
[`Persist` trait](https://docs.rs/lightning/latest/lightning/chain/chainmonitor/trait.Persist.html).
3. Stop background processing and wait for the result. With
[`BackgroundProcessor::stop`](https://docs.rs/lightning-background-processor/latest/lightning_background_processor/struct.BackgroundProcessor.html#method.stop),
check the returned persistence error, if any. With
[`process_events_async`](https://docs.rs/lightning-background-processor/latest/lightning_background_processor/fn.process_events_async.html),
signal the sleeper to return `true` and await the processing future. If your
integration drives LDK itself, finish processing pending events and persist
the latest channel manager state before releasing the store.
4. Close remaining peer connections and storage resources after processing and
persistence have finished. Report persistence errors before treating the
shutdown as successful.

On startup, reload the persisted channel manager and channel monitors and bring
them up to date with the chain before resuming Lightning activity. See
[Setting up a Channel Manager](/building-a-node-with-ldk/setting-up-a-channel-manager)
for the components involved in loading and persisting channel state.
Loading