Add persistent closed channel history and list_closed_channels()#882
Open
f3r10 wants to merge 1 commit intolightningdevkit:mainfrom
Open
Add persistent closed channel history and list_closed_channels()#882f3r10 wants to merge 1 commit intolightningdevkit:mainfrom
list_closed_channels()#882f3r10 wants to merge 1 commit intolightningdevkit:mainfrom
Conversation
Introduce `ClosedChannelDetails`, a new record type persisted to the KV store under the `"closed_channels"` namespace whenever a channel closes. Records are written in the `ChannelClosed` event handler and loaded back at startup in parallel with other stores via `tokio::join!`. Add `Node::list_closed_channels()` to expose the full history of closed channels across restarts. Track outbound channel direction via an in-memory `outbound_channel_ids` set seeded from `channel_manager.list_channels()` at startup and updated on `ChannelPending` events, since `ChannelClosed` does not carry that information directly.
|
I've assigned @tnull as a reviewer! |
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.
Summary
Closes #851.
Adds persistent historical closed channel records so applications can query all channels that have ever closed on this node, surviving restarts.
New public API
Node::list_closed_channels() -> Vec<ClosedChannelDetails>ClosedChannelDetailsstruct:channel_id,user_channel_id,counterparty_node_id,funding_txo,channel_capacity_sats,last_local_balance_msat,is_outbound,closure_reason,closed_atEvent::ChannelClosedgains three new fields:channel_capacity_sats,channel_funding_txo,last_local_balance_msatImplementation
Persistence (
src/closed_channel.rs,src/io/):ClosedChannelDetailsimplementsStorableObjectwith insert-only semantics (closed records are immutable). Records are stored under the"closed_channels"KV namespace keyed byUserChannelId.Startup (
src/builder.rs):read_closed_channels()joins the existingtokio::join!block so historical records are loaded in parallel with payments, pending payments, and node metrics — no added sequential startup cost as history gronws.Event handlinng (
src/event.rs): OnChannelClosed, the handler writes aClosedChannelDetailsrecord to the store and emits the enriched public event. Channel direction (is_outbound) is tracked via an in-memoryoutbound_channel_idsset, seeded fromchannel_manager.list_channels()at startup and updated onChannelPending, sinceChannelCloseddoes not carry that information directly.