mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-26 21:46:37 +02:00
graph/db: let GraghCache.AddChannel take CachedEdgeInfo
Define a new CachedEdgeInfo type and let the graph cache's AddChannel use this. This will let us later on (for the SQL impl of the graph db) only load from the DB what we actually need for the graph cache.
This commit is contained in:
@@ -178,7 +178,7 @@ func (c *ChannelGraph) populateCache() error {
|
||||
policy1, policy2 *models.ChannelEdgePolicy) error {
|
||||
|
||||
c.graphCache.AddChannel(
|
||||
info,
|
||||
models.NewCachedEdge(info),
|
||||
models.NewCachedPolicy(policy1),
|
||||
models.NewCachedPolicy(policy2),
|
||||
)
|
||||
@@ -316,7 +316,7 @@ func (c *ChannelGraph) AddChannelEdge(edge *models.ChannelEdgeInfo,
|
||||
}
|
||||
|
||||
if c.graphCache != nil {
|
||||
c.graphCache.AddChannel(edge, nil, nil)
|
||||
c.graphCache.AddChannel(models.NewCachedEdge(edge), nil, nil)
|
||||
}
|
||||
|
||||
select {
|
||||
@@ -352,7 +352,7 @@ func (c *ChannelGraph) MarkEdgeLive(chanID uint64) error {
|
||||
info := infos[0]
|
||||
|
||||
c.graphCache.AddChannel(
|
||||
info.Info,
|
||||
models.NewCachedEdge(info.Info),
|
||||
models.NewCachedPolicy(info.Policy1),
|
||||
models.NewCachedPolicy(info.Policy2),
|
||||
)
|
||||
|
@@ -114,7 +114,7 @@ func (c *GraphCache) AddNodeFeatures(node route.Vertex,
|
||||
// and policy 2 does not matter, the directionality is extracted from the info
|
||||
// and policy flags automatically. The policy will be set as the outgoing policy
|
||||
// on one node and the incoming policy on the peer's side.
|
||||
func (c *GraphCache) AddChannel(info *models.ChannelEdgeInfo,
|
||||
func (c *GraphCache) AddChannel(info *models.CachedEdgeInfo,
|
||||
policy1, policy2 *models.CachedEdgePolicy) {
|
||||
|
||||
if info == nil {
|
||||
|
@@ -61,7 +61,7 @@ func TestGraphCacheAddNode(t *testing.T) {
|
||||
}
|
||||
cache := NewGraphCache(10)
|
||||
cache.AddNodeFeatures(nodeA, lnwire.EmptyFeatureVector())
|
||||
cache.AddChannel(&models.ChannelEdgeInfo{
|
||||
cache.AddChannel(&models.CachedEdgeInfo{
|
||||
ChannelID: 1000,
|
||||
// Those are direction independent!
|
||||
NodeKey1Bytes: pubKey1,
|
||||
|
33
graph/db/models/cached_edge_info.go
Normal file
33
graph/db/models/cached_edge_info.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package models
|
||||
|
||||
import "github.com/btcsuite/btcd/btcutil"
|
||||
|
||||
// CachedEdgeInfo is a struct that only caches the information of a
|
||||
// ChannelEdgeInfo that we actually use for pathfinding and therefore need to
|
||||
// store in the cache.
|
||||
type CachedEdgeInfo struct {
|
||||
// ChannelID is the unique channel ID for the channel. The first 3
|
||||
// bytes are the block height, the next 3 the index within the block,
|
||||
// and the last 2 bytes are the output index for the channel.
|
||||
ChannelID uint64
|
||||
|
||||
// NodeKey1Bytes is the raw public key of the first node.
|
||||
NodeKey1Bytes [33]byte
|
||||
|
||||
// NodeKey2Bytes is the raw public key of the second node.
|
||||
NodeKey2Bytes [33]byte
|
||||
|
||||
// Capacity is the total capacity of the channel, this is determined by
|
||||
// the value output in the outpoint that created this channel.
|
||||
Capacity btcutil.Amount
|
||||
}
|
||||
|
||||
// NewCachedEdge creates a new CachedEdgeInfo from the provided ChannelEdgeInfo.
|
||||
func NewCachedEdge(edgeInfo *ChannelEdgeInfo) *CachedEdgeInfo {
|
||||
return &CachedEdgeInfo{
|
||||
ChannelID: edgeInfo.ChannelID,
|
||||
NodeKey1Bytes: edgeInfo.NodeKey1Bytes,
|
||||
NodeKey2Bytes: edgeInfo.NodeKey2Bytes,
|
||||
Capacity: edgeInfo.Capacity,
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user