From e120110470f5eb132da44f0fcd724e1e17a982e1 Mon Sep 17 00:00:00 2001 From: ziggie Date: Fri, 1 Aug 2025 18:07:41 +0200 Subject: [PATCH] lnd: introduce separate key-value payment db We also addd this new db on the server level to use it in the following commit to do all the payment related queries of the rpcserver. We add a new payment db instance on the server level. Which we will you for the payment related queries in a following commit. --- config_builder.go | 12 ++++++++++++ server.go | 11 ++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/config_builder.go b/config_builder.go index 3c8b122a8..35a44e2c6 100644 --- a/config_builder.go +++ b/config_builder.go @@ -924,6 +924,10 @@ type DatabaseInstances struct { // InvoiceDB is the database that stores information about invoices. InvoiceDB invoices.InvoiceDB + // KVPaymentsDB is the database that stores all payment related + // information. + KVPaymentsDB *channeldb.KVPaymentsDB + // MacaroonDB is the database that stores macaroon root keys. MacaroonDB kvdb.Backend @@ -1215,6 +1219,14 @@ func (d *DefaultDatabaseBuilder) BuildDatabase( return nil, nil, err } + // Mount the payments DB which is only KV for now. + // + // TODO(ziggie): Add support for SQL payments DB. + kvPaymentsDB := channeldb.NewKVPaymentsDB( + dbs.ChanStateDB, + ) + dbs.KVPaymentsDB = kvPaymentsDB + // Wrap the watchtower client DB and make sure we clean up. if cfg.WtClient.Active { dbs.TowerClientDB, err = wtdb.OpenClientDB( diff --git a/server.go b/server.go index ebc513fdd..a84642f1f 100644 --- a/server.go +++ b/server.go @@ -335,6 +335,12 @@ type server struct { invoicesDB invoices.InvoiceDB + // kvPaymentsDB is the DB that contains all functions for managing + // payments. + // + // TODO(ziggie): Replace with interface. + kvPaymentsDB *channeldb.KVPaymentsDB + aliasMgr *aliasmgr.Manager htlcSwitch *htlcswitch.Switch @@ -678,6 +684,7 @@ func newServer(ctx context.Context, cfg *Config, listenAddrs []net.Addr, addrSource: addrSource, miscDB: dbs.ChanStateDB, invoicesDB: dbs.InvoiceDB, + kvPaymentsDB: dbs.KVPaymentsDB, cc: cc, sigPool: lnwallet.NewSigPool(cfg.Workers.Sig, cc.Signer), writePool: writePool, @@ -1127,9 +1134,7 @@ func newServer(ctx context.Context, cfg *Config, listenAddrs []net.Addr, PathFindingConfig: pathFindingConfig, } - paymentControl := channeldb.NewKVPaymentsDB(dbs.ChanStateDB) - - s.controlTower = routing.NewControlTower(paymentControl) + s.controlTower = routing.NewControlTower(dbs.KVPaymentsDB) strictPruning := cfg.Bitcoin.Node == "neutrino" || cfg.Routing.StrictZombiePruning