mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-06-04 12:09:27 +02:00
graph/db: refactor to group all topology notification fields
A clean-up commit just to separate out all topology related fields in ChannelGraph into a dedicated struct that then gets mounted to the ChannelGraph.
This commit is contained in:
parent
2221aaa889
commit
878746c9c9
@ -12,7 +12,6 @@ import (
|
|||||||
"github.com/lightningnetwork/lnd/batch"
|
"github.com/lightningnetwork/lnd/batch"
|
||||||
"github.com/lightningnetwork/lnd/graph/db/models"
|
"github.com/lightningnetwork/lnd/graph/db/models"
|
||||||
"github.com/lightningnetwork/lnd/kvdb"
|
"github.com/lightningnetwork/lnd/kvdb"
|
||||||
"github.com/lightningnetwork/lnd/lnutils"
|
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
"github.com/lightningnetwork/lnd/routing/route"
|
"github.com/lightningnetwork/lnd/routing/route"
|
||||||
)
|
)
|
||||||
@ -50,26 +49,7 @@ type ChannelGraph struct {
|
|||||||
graphCache *GraphCache
|
graphCache *GraphCache
|
||||||
|
|
||||||
*KVStore
|
*KVStore
|
||||||
|
*topologyManager
|
||||||
// ntfnClientCounter is an atomic counter that's used to assign unique
|
|
||||||
// notification client IDs to new clients.
|
|
||||||
ntfnClientCounter atomic.Uint64
|
|
||||||
|
|
||||||
// topologyUpdate is a channel that carries new topology updates
|
|
||||||
// messages from outside the ChannelGraph to be processed by the
|
|
||||||
// networkHandler.
|
|
||||||
topologyUpdate chan any
|
|
||||||
|
|
||||||
// topologyClients maps a client's unique notification ID to a
|
|
||||||
// topologyClient client that contains its notification dispatch
|
|
||||||
// channel.
|
|
||||||
topologyClients *lnutils.SyncMap[uint64, *topologyClient]
|
|
||||||
|
|
||||||
// ntfnClientUpdates is a channel that's used to send new updates to
|
|
||||||
// topology notification clients to the ChannelGraph. Updates either
|
|
||||||
// add a new notification client, or cancel notifications for an
|
|
||||||
// existing client.
|
|
||||||
ntfnClientUpdates chan *topologyClientUpdate
|
|
||||||
|
|
||||||
quit chan struct{}
|
quit chan struct{}
|
||||||
wg sync.WaitGroup
|
wg sync.WaitGroup
|
||||||
@ -90,11 +70,9 @@ func NewChannelGraph(cfg *Config, options ...ChanGraphOption) (*ChannelGraph,
|
|||||||
}
|
}
|
||||||
|
|
||||||
g := &ChannelGraph{
|
g := &ChannelGraph{
|
||||||
KVStore: store,
|
KVStore: store,
|
||||||
topologyUpdate: make(chan any),
|
topologyManager: newTopologyManager(),
|
||||||
topologyClients: &lnutils.SyncMap[uint64, *topologyClient]{},
|
quit: make(chan struct{}),
|
||||||
ntfnClientUpdates: make(chan *topologyClientUpdate),
|
|
||||||
quit: make(chan struct{}),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// The graph cache can be turned off (e.g. for mobile users) for a
|
// The graph cache can be turned off (e.g. for mobile users) for a
|
||||||
|
@ -5,15 +5,50 @@ import (
|
|||||||
"image/color"
|
"image/color"
|
||||||
"net"
|
"net"
|
||||||
"sync"
|
"sync"
|
||||||
|
"sync/atomic"
|
||||||
|
|
||||||
"github.com/btcsuite/btcd/btcec/v2"
|
"github.com/btcsuite/btcd/btcec/v2"
|
||||||
"github.com/btcsuite/btcd/btcutil"
|
"github.com/btcsuite/btcd/btcutil"
|
||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/go-errors/errors"
|
"github.com/go-errors/errors"
|
||||||
"github.com/lightningnetwork/lnd/graph/db/models"
|
"github.com/lightningnetwork/lnd/graph/db/models"
|
||||||
|
"github.com/lightningnetwork/lnd/lnutils"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// topologyManager holds all the fields required to manage the network topology
|
||||||
|
// subscriptions and notifications.
|
||||||
|
type topologyManager struct {
|
||||||
|
// ntfnClientCounter is an atomic counter that's used to assign unique
|
||||||
|
// notification client IDs to new clients.
|
||||||
|
ntfnClientCounter atomic.Uint64
|
||||||
|
|
||||||
|
// topologyUpdate is a channel that carries new topology updates
|
||||||
|
// messages from outside the ChannelGraph to be processed by the
|
||||||
|
// networkHandler.
|
||||||
|
topologyUpdate chan any
|
||||||
|
|
||||||
|
// topologyClients maps a client's unique notification ID to a
|
||||||
|
// topologyClient client that contains its notification dispatch
|
||||||
|
// channel.
|
||||||
|
topologyClients *lnutils.SyncMap[uint64, *topologyClient]
|
||||||
|
|
||||||
|
// ntfnClientUpdates is a channel that's used to send new updates to
|
||||||
|
// topology notification clients to the ChannelGraph. Updates either
|
||||||
|
// add a new notification client, or cancel notifications for an
|
||||||
|
// existing client.
|
||||||
|
ntfnClientUpdates chan *topologyClientUpdate
|
||||||
|
}
|
||||||
|
|
||||||
|
// newTopologyManager creates a new instance of the topologyManager.
|
||||||
|
func newTopologyManager() *topologyManager {
|
||||||
|
return &topologyManager{
|
||||||
|
topologyUpdate: make(chan any),
|
||||||
|
topologyClients: &lnutils.SyncMap[uint64, *topologyClient]{},
|
||||||
|
ntfnClientUpdates: make(chan *topologyClientUpdate),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TopologyClient represents an intent to receive notifications from the
|
// TopologyClient represents an intent to receive notifications from the
|
||||||
// channel router regarding changes to the topology of the channel graph. The
|
// channel router regarding changes to the topology of the channel graph. The
|
||||||
// TopologyChanges channel will be sent upon with new updates to the channel
|
// TopologyChanges channel will be sent upon with new updates to the channel
|
||||||
|
Loading…
x
Reference in New Issue
Block a user