From ae9de8d0786fe66344199c67ed31c6ab22ac4cc7 Mon Sep 17 00:00:00 2001 From: ziggie Date: Tue, 5 May 2026 12:26:11 -0300 Subject: [PATCH 1/7] funding: depend on chanstate Store Replace the funding manager's concrete *channeldb.ChannelStateDB dependency with chanstate.Store. The manager only uses methods covered by the store contract, including channel opening state and initial forwarding policy persistence. --- funding/manager.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/funding/manager.go b/funding/manager.go index 417ad9cff19..8d511741dff 100644 --- a/funding/manager.go +++ b/funding/manager.go @@ -23,6 +23,7 @@ import ( "github.com/lightningnetwork/lnd/chainntnfs" "github.com/lightningnetwork/lnd/chanacceptor" "github.com/lightningnetwork/lnd/channeldb" + "github.com/lightningnetwork/lnd/chanstate" "github.com/lightningnetwork/lnd/discovery" "github.com/lightningnetwork/lnd/fn/v2" "github.com/lightningnetwork/lnd/graph" @@ -384,8 +385,9 @@ type Config struct { // so that the channel creation process can be completed. Notifier chainntnfs.ChainNotifier - // ChannelDB is the database that keeps track of all channel state. - ChannelDB *channeldb.ChannelStateDB + // ChannelDB is the database that keeps track of channel state used by + // the funding flow. + ChannelDB chanstate.Store // SignMessage signs an arbitrary message with a given public key. The // actual digest signed is the double sha-256 of the message. In the From d08b1b07c77d43e131b00a94bb1797bb3e82d197 Mon Sep 17 00:00:00 2001 From: ziggie Date: Tue, 5 May 2026 12:26:24 -0300 Subject: [PATCH 2/7] peer: depend on chanstate Store Replace the peer config's concrete channel state DB dependency with chanstate.Store. Brontide only needs channel lookups, closed-channel lookup, and initial forwarding policy access from the channel-state store. --- peer/brontide.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/peer/brontide.go b/peer/brontide.go index 01d948beb4b..f7a01cd11f5 100644 --- a/peer/brontide.go +++ b/peer/brontide.go @@ -26,6 +26,7 @@ import ( "github.com/lightningnetwork/lnd/chainntnfs" "github.com/lightningnetwork/lnd/channeldb" "github.com/lightningnetwork/lnd/channelnotifier" + "github.com/lightningnetwork/lnd/chanstate" "github.com/lightningnetwork/lnd/contractcourt" "github.com/lightningnetwork/lnd/discovery" "github.com/lightningnetwork/lnd/feature" @@ -259,8 +260,8 @@ type Config struct { // ChannelLinkConfig. InterceptSwitch *htlcswitch.InterceptableSwitch - // ChannelDB is used to fetch opened channels, and closed channels. - ChannelDB *channeldb.ChannelStateDB + // ChannelDB is used to fetch channel state needed by the peer. + ChannelDB chanstate.Store // ChannelGraph is a pointer to the channel graph which is used to // query information about the set of known active channels. From 1f4a756f5ec1ec61495365388d75c45a8d68599e Mon Sep 17 00:00:00 2001 From: ziggie Date: Tue, 5 May 2026 12:28:38 -0300 Subject: [PATCH 3/7] channelnotifier: depend on chanstate Store Accept chanstate.Store in ChannelNotifier instead of the concrete ChannelStateDB. The notifier only fetches open and closed channel records to populate channel event payloads. --- channelnotifier/channelnotifier.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/channelnotifier/channelnotifier.go b/channelnotifier/channelnotifier.go index e7b815b301a..06f3e67c0c7 100644 --- a/channelnotifier/channelnotifier.go +++ b/channelnotifier/channelnotifier.go @@ -5,6 +5,7 @@ import ( "github.com/btcsuite/btcd/wire" "github.com/lightningnetwork/lnd/channeldb" + "github.com/lightningnetwork/lnd/chanstate" "github.com/lightningnetwork/lnd/subscribe" ) @@ -17,7 +18,7 @@ type ChannelNotifier struct { ntfnServer *subscribe.Server - chanDB *channeldb.ChannelStateDB + chanDB chanstate.Store } // PendingOpenChannelEvent represents a new event where a new channel has @@ -97,7 +98,7 @@ type FundingTimeoutEvent struct { // New creates a new channel notifier. The ChannelNotifier gets channel // events from peers and from the chain arbitrator, and dispatches them to // its clients. -func New(chanDB *channeldb.ChannelStateDB) *ChannelNotifier { +func New(chanDB chanstate.Store) *ChannelNotifier { return &ChannelNotifier{ ntfnServer: subscribe.NewServer(), chanDB: chanDB, From 8f10cf54126d7a02925842a8d1e2fcf6a290c178 Mon Sep 17 00:00:00 2001 From: ziggie Date: Tue, 5 May 2026 12:28:59 -0300 Subject: [PATCH 4/7] contractcourt: use chanstate Store in breach arb Replace BreachConfig's concrete ChannelStateDB dependency with chanstate.Store. The breach arbitrator only needs closed-channel reads and MarkChanFullyClosed from the channel-state store. --- contractcourt/breach_arbitrator.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/contractcourt/breach_arbitrator.go b/contractcourt/breach_arbitrator.go index 6e12086008a..2c12f25598b 100644 --- a/contractcourt/breach_arbitrator.go +++ b/contractcourt/breach_arbitrator.go @@ -14,7 +14,7 @@ import ( "github.com/btcsuite/btcd/txscript" "github.com/btcsuite/btcd/wire" "github.com/lightningnetwork/lnd/chainntnfs" - "github.com/lightningnetwork/lnd/channeldb" + "github.com/lightningnetwork/lnd/chanstate" "github.com/lightningnetwork/lnd/fn/v2" graphdb "github.com/lightningnetwork/lnd/graph/db" "github.com/lightningnetwork/lnd/input" @@ -140,10 +140,9 @@ type BreachConfig struct { // a close type to be included in the channel close summary. CloseLink func(*wire.OutPoint, ChannelCloseType) - // DB provides access to the user's channels, allowing the breach - // arbiter to determine the current state of a user's channels, and how - // it should respond to channel closure. - DB *channeldb.ChannelStateDB + // DB provides access to the user's closed channels, allowing the breach + // arbiter to determine how it should respond to channel closure. + DB chanstate.ClosedChannelStore // Estimator is used by the breach arbiter to determine an appropriate // fee level when generating, signing, and broadcasting sweep From 2e7a1d8aac64debaafc09a2db891ffacac21180a Mon Sep 17 00:00:00 2001 From: ziggie Date: Tue, 5 May 2026 12:31:52 -0300 Subject: [PATCH 5/7] lnd: use chanstate Store for channel restore Make chanDBRestorer persist restored channel shells through chanstate.Store instead of the concrete ChannelStateDB. The restorer still builds channeldb channel shell values, but only needs RestoreChannelShells from the store. --- chanrestore.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/chanrestore.go b/chanrestore.go index 1f506cc2781..407cdfbc7ad 100644 --- a/chanrestore.go +++ b/chanrestore.go @@ -11,6 +11,7 @@ import ( "github.com/btcsuite/btcd/wire" "github.com/lightningnetwork/lnd/chanbackup" "github.com/lightningnetwork/lnd/channeldb" + "github.com/lightningnetwork/lnd/chanstate" "github.com/lightningnetwork/lnd/contractcourt" "github.com/lightningnetwork/lnd/keychain" "github.com/lightningnetwork/lnd/lnwire" @@ -35,7 +36,7 @@ const ( // need the secret key chain in order obtain the prior shachain root so we can // verify the DLP protocol as initiated by the remote node. type chanDBRestorer struct { - db *channeldb.ChannelStateDB + db chanstate.OpenChannelStore secretKeys keychain.SecretKeyRing From 186ea36f37b469b646f49ff6427a8ab76a40da82 Mon Sep 17 00:00:00 2001 From: ziggie Date: Tue, 5 May 2026 12:34:43 -0300 Subject: [PATCH 6/7] lnrpc: depend on chanstate Store Replace concrete ChannelStateDB fields in the invoices and wallet RPC configs with chanstate.Store, and update the subserver dependency wiring to pass the interface. The affected RPC paths only need channel-state store methods for hop hints and waiting-close channel queries. --- lnrpc/invoicesrpc/addinvoice.go | 6 +++--- lnrpc/invoicesrpc/config_active.go | 8 ++++---- lnrpc/walletrpc/config_active.go | 6 +++--- subrpcserver_config.go | 4 ++-- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lnrpc/invoicesrpc/addinvoice.go b/lnrpc/invoicesrpc/addinvoice.go index 9afba767811..b4d39a99c58 100644 --- a/lnrpc/invoicesrpc/addinvoice.go +++ b/lnrpc/invoicesrpc/addinvoice.go @@ -18,6 +18,7 @@ import ( "github.com/btcsuite/btcd/chaincfg/chainhash" "github.com/btcsuite/btcd/wire" "github.com/lightningnetwork/lnd/channeldb" + "github.com/lightningnetwork/lnd/chanstate" "github.com/lightningnetwork/lnd/graph/db/models" "github.com/lightningnetwork/lnd/invoices" "github.com/lightningnetwork/lnd/lntypes" @@ -70,9 +71,8 @@ type AddInvoiceConfig struct { // specified. DefaultCLTVExpiry uint32 - // ChanDB is a global boltdb instance which is needed to access the - // channel graph. - ChanDB *channeldb.ChannelStateDB + // ChanDB is used to access open channel state. + ChanDB chanstate.OpenChannelStore // Graph gives the invoice server access to various graph related // queries. diff --git a/lnrpc/invoicesrpc/config_active.go b/lnrpc/invoicesrpc/config_active.go index f2d2b04bb0c..233aa59275e 100644 --- a/lnrpc/invoicesrpc/config_active.go +++ b/lnrpc/invoicesrpc/config_active.go @@ -5,7 +5,7 @@ package invoicesrpc import ( "github.com/btcsuite/btcd/chaincfg" - "github.com/lightningnetwork/lnd/channeldb" + "github.com/lightningnetwork/lnd/chanstate" "github.com/lightningnetwork/lnd/invoices" "github.com/lightningnetwork/lnd/lnwire" "github.com/lightningnetwork/lnd/macaroons" @@ -55,9 +55,9 @@ type Config struct { // graph. Graph GraphSource - // ChanStateDB is a possibly replicated db instance which contains the - // channel state - ChanStateDB *channeldb.ChannelStateDB + // ChanStateDB is a possibly replicated db instance which contains open + // channel state. + ChanStateDB chanstate.OpenChannelStore // GenInvoiceFeatures returns a feature containing feature bits that // should be advertised on freshly generated invoices. diff --git a/lnrpc/walletrpc/config_active.go b/lnrpc/walletrpc/config_active.go index 4636473f0b5..e0c9c684a4f 100644 --- a/lnrpc/walletrpc/config_active.go +++ b/lnrpc/walletrpc/config_active.go @@ -6,7 +6,7 @@ package walletrpc import ( "github.com/btcsuite/btcd/chaincfg" "github.com/btcsuite/btcwallet/wallet" - "github.com/lightningnetwork/lnd/channeldb" + "github.com/lightningnetwork/lnd/chanstate" "github.com/lightningnetwork/lnd/keychain" "github.com/lightningnetwork/lnd/lnwallet" "github.com/lightningnetwork/lnd/lnwallet/chainfee" @@ -78,6 +78,6 @@ type Config struct { // coins when funding a transaction. CoinSelectionStrategy wallet.CoinSelectionStrategy - // ChanStateDB is the reference to the channel db. - ChanStateDB *channeldb.ChannelStateDB + // ChanStateDB is the reference to the open channel store. + ChanStateDB chanstate.OpenChannelStore } diff --git a/subrpcserver_config.go b/subrpcserver_config.go index 8b3641d2410..856553c38fd 100644 --- a/subrpcserver_config.go +++ b/subrpcserver_config.go @@ -11,7 +11,7 @@ import ( "github.com/lightningnetwork/lnd/aliasmgr" "github.com/lightningnetwork/lnd/autopilot" "github.com/lightningnetwork/lnd/chainreg" - "github.com/lightningnetwork/lnd/channeldb" + "github.com/lightningnetwork/lnd/chanstate" "github.com/lightningnetwork/lnd/fn/v2" graphdb "github.com/lightningnetwork/lnd/graph/db" "github.com/lightningnetwork/lnd/htlcswitch" @@ -115,7 +115,7 @@ func (s *subRPCServerConfigs) PopulateDependencies(cfg *Config, routerBackend *routerrpc.RouterBackend, nodeSigner *netann.NodeSigner, graphDB *graphdb.ChannelGraph, - chanStateDB *channeldb.ChannelStateDB, + chanStateDB chanstate.Store, sweeper *sweep.UtxoSweeper, tower *watchtower.Standalone, towerClientMgr *wtclient.Manager, From 0376270e5ca94b4e89eb1e7fe76db6018fcd9220 Mon Sep 17 00:00:00 2001 From: ziggie Date: Tue, 5 May 2026 12:34:52 -0300 Subject: [PATCH 7/7] server: depend on chanstate Store Store channel-state access on server as chanstate.Store instead of *channeldb.ChannelStateDB. Keep link-node access as a separate concrete *channeldb.LinkNodeDB field so LinkNodeDB does not leak into the channel-state store contract. --- server.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/server.go b/server.go index c2b7ea673ad..45992c464cb 100644 --- a/server.go +++ b/server.go @@ -38,6 +38,7 @@ import ( "github.com/lightningnetwork/lnd/chanfitness" "github.com/lightningnetwork/lnd/channeldb" "github.com/lightningnetwork/lnd/channelnotifier" + "github.com/lightningnetwork/lnd/chanstate" "github.com/lightningnetwork/lnd/clock" "github.com/lightningnetwork/lnd/cluster" "github.com/lightningnetwork/lnd/contractcourt" @@ -325,7 +326,8 @@ type server struct { graphDB *graphdb.ChannelGraph v1Graph *graphdb.VersionedGraph - chanStateDB *channeldb.ChannelStateDB + chanStateDB chanstate.Store + linkNodeDB *channeldb.LinkNodeDB addrSource channeldb.AddrSource @@ -728,13 +730,15 @@ func newServer(ctx context.Context, cfg *Config, listenAddrs []net.Addr, ) addrSource := channeldb.NewMultiAddrSource(dbs.ChanStateDB, v1Graph) + chanStateDB := dbs.ChanStateDB.ChannelStateDB() s := &server{ cfg: cfg, implCfg: implCfg, graphDB: dbs.GraphDB, v1Graph: v1Graph, - chanStateDB: dbs.ChanStateDB.ChannelStateDB(), + chanStateDB: chanStateDB, + linkNodeDB: chanStateDB.LinkNodeDB(), addrSource: addrSource, miscDB: dbs.ChanStateDB, invoicesDB: dbs.InvoiceDB, @@ -748,9 +752,7 @@ func newServer(ctx context.Context, cfg *Config, listenAddrs []net.Addr, blockbeatDispatcher: chainio.NewBlockbeatDispatcher( cc.ChainNotifier, ), - channelNotifier: channelnotifier.New( - dbs.ChanStateDB.ChannelStateDB(), - ), + channelNotifier: channelnotifier.New(chanStateDB), identityECDH: nodeKeyECDH, identityKeyLoc: nodeKeyDesc.KeyLocator, @@ -3610,7 +3612,7 @@ func (s *server) establishPersistentConnections(ctx context.Context) error { // Iterate through the list of LinkNodes to find addresses we should // attempt to connect to based on our set of previous connections. Set // the reconnection port to the default peer port. - linkNodes, err := s.chanStateDB.LinkNodeDB().FetchAllLinkNodes() + linkNodes, err := s.linkNodeDB.FetchAllLinkNodes() if err != nil && !errors.Is(err, channeldb.ErrLinkNodesNotFound) { return fmt.Errorf("failed to fetch all link nodes: %w", err) }