Skip to content
Merged
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
5 changes: 3 additions & 2 deletions channelnotifier/channelnotifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -17,7 +18,7 @@ type ChannelNotifier struct {

ntfnServer *subscribe.Server

chanDB *channeldb.ChannelStateDB
chanDB chanstate.Store
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nits: the notifier only calls FetchChannel and FetchClosedChannel, so a narrower private interface would preserve the benefit of the sub-interface split without requiring the full chanstate.Store.

}

// PendingOpenChannelEvent represents a new event where a new channel has
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion chanrestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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

Expand Down
9 changes: 4 additions & 5 deletions contractcourt/breach_arbitrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions funding/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nits: this only appears to use open-channel reads plus channel setup methods. Could this field use a narrower private interface embedding chanstate.OpenChannelStore and chanstate.ChannelSetupStore instead of the full 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
Expand Down
6 changes: 3 additions & 3 deletions lnrpc/invoicesrpc/addinvoice.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions lnrpc/invoicesrpc/config_active.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions lnrpc/walletrpc/config_active.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
5 changes: 3 additions & 2 deletions peer/brontide.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nits: this only needs open-channel reads, closed-channel lookup, and initial forwarding policy access. Could this be narrowed to a small private interface rather than full chanstate.Store?


// ChannelGraph is a pointer to the channel graph which is used to
// query information about the set of known active channels.
Expand Down
14 changes: 8 additions & 6 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -325,7 +326,8 @@ type server struct {
graphDB *graphdb.ChannelGraph
v1Graph *graphdb.VersionedGraph

chanStateDB *channeldb.ChannelStateDB
chanStateDB chanstate.Store
linkNodeDB *channeldb.LinkNodeDB
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nits: since this only needs FetchAllLinkNodes, could this be a small private interface instead of storing the concrete *channeldb.LinkNodeDB? That keeps LinkNodeDB out of chanstate.Store while avoiding another concrete field on server.


addrSource channeldb.AddrSource

Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions subrpcserver_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down
Loading