@@ -231,13 +231,13 @@ func NewChannelGraph(db kvdb.Backend, options ...OptionModifier) (*ChannelGraph,
231
231
log .Debugf ("Populating in-memory channel graph, this might " +
232
232
"take a while..." )
233
233
234
- err := g .ForEachNodeCacheable (
235
- func (tx kvdb.RTx , node GraphCacheNode ) error {
236
- g .graphCache .AddNodeFeatures (node )
234
+ err := g .ForEachNodeCacheable (func (node route.Vertex ,
235
+ features * lnwire.FeatureVector ) error {
237
236
238
- return nil
239
- },
240
- )
237
+ g .graphCache .AddNodeFeatures (node , features )
238
+
239
+ return nil
240
+ })
241
241
if err != nil {
242
242
return nil , err
243
243
}
@@ -772,8 +772,8 @@ func (c *ChannelGraph) forEachNode(
772
772
// graph, executing the passed callback with each node encountered. If the
773
773
// callback returns an error, then the transaction is aborted and the iteration
774
774
// stops early.
775
- func (c * ChannelGraph ) ForEachNodeCacheable (cb func (kvdb. RTx ,
776
- GraphCacheNode ) error ) error {
775
+ func (c * ChannelGraph ) ForEachNodeCacheable (cb func (route. Vertex ,
776
+ * lnwire. FeatureVector ) error ) error {
777
777
778
778
traversal := func (tx kvdb.RTx ) error {
779
779
// First grab the nodes bucket which stores the mapping from
@@ -792,7 +792,7 @@ func (c *ChannelGraph) ForEachNodeCacheable(cb func(kvdb.RTx,
792
792
}
793
793
794
794
nodeReader := bytes .NewReader (nodeBytes )
795
- cacheableNode , err := deserializeLightningNodeCacheable (
795
+ node , features , err := deserializeLightningNodeCacheable ( //nolint:ll
796
796
nodeReader ,
797
797
)
798
798
if err != nil {
@@ -801,7 +801,7 @@ func (c *ChannelGraph) ForEachNodeCacheable(cb func(kvdb.RTx,
801
801
802
802
// Execute the callback, the transaction will abort if
803
803
// this returns an error.
804
- return cb (tx , cacheableNode )
804
+ return cb (node , features )
805
805
})
806
806
}
807
807
@@ -901,10 +901,9 @@ func (c *ChannelGraph) AddLightningNode(node *models.LightningNode,
901
901
r := & batch.Request {
902
902
Update : func (tx kvdb.RwTx ) error {
903
903
if c .graphCache != nil {
904
- cNode := newGraphCacheNode (
904
+ c . graphCache . AddNodeFeatures (
905
905
node .PubKeyBytes , node .Features ,
906
906
)
907
- c .graphCache .AddNodeFeatures (cNode )
908
907
}
909
908
910
909
return addLightningNode (tx , node )
@@ -3056,50 +3055,6 @@ func (c *ChannelGraph) fetchLightningNode(tx kvdb.RTx,
3056
3055
return node , nil
3057
3056
}
3058
3057
3059
- // graphCacheNode is a struct that wraps a LightningNode in a way that it can be
3060
- // cached in the graph cache.
3061
- type graphCacheNode struct {
3062
- pubKeyBytes route.Vertex
3063
- features * lnwire.FeatureVector
3064
- }
3065
-
3066
- // newGraphCacheNode returns a new cache optimized node.
3067
- func newGraphCacheNode (pubKey route.Vertex ,
3068
- features * lnwire.FeatureVector ) * graphCacheNode {
3069
-
3070
- return & graphCacheNode {
3071
- pubKeyBytes : pubKey ,
3072
- features : features ,
3073
- }
3074
- }
3075
-
3076
- // PubKey returns the node's public identity key.
3077
- func (n * graphCacheNode ) PubKey () route.Vertex {
3078
- return n .pubKeyBytes
3079
- }
3080
-
3081
- // Features returns the node's features.
3082
- func (n * graphCacheNode ) Features () * lnwire.FeatureVector {
3083
- return n .features
3084
- }
3085
-
3086
- // ForEachChannel iterates through all channels of this node, executing the
3087
- // passed callback with an edge info structure and the policies of each end
3088
- // of the channel. The first edge policy is the outgoing edge *to* the
3089
- // connecting node, while the second is the incoming edge *from* the
3090
- // connecting node. If the callback returns an error, then the iteration is
3091
- // halted with the error propagated back up to the caller.
3092
- //
3093
- // Unknown policies are passed into the callback as nil values.
3094
- func (n * graphCacheNode ) ForEachChannel (tx kvdb.RTx ,
3095
- cb func (kvdb.RTx , * models.ChannelEdgeInfo , * models.ChannelEdgePolicy ,
3096
- * models.ChannelEdgePolicy ) error ) error {
3097
-
3098
- return nodeTraversal (tx , n .pubKeyBytes [:], nil , cb )
3099
- }
3100
-
3101
- var _ GraphCacheNode = (* graphCacheNode )(nil )
3102
-
3103
3058
// HasLightningNode determines if the graph has a vertex identified by the
3104
3059
// target node identity public key. If the node exists in the database, a
3105
3060
// timestamp of when the data for the node was lasted updated is returned along
@@ -4059,60 +4014,59 @@ func fetchLightningNode(nodeBucket kvdb.RBucket,
4059
4014
return deserializeLightningNode (nodeReader )
4060
4015
}
4061
4016
4062
- func deserializeLightningNodeCacheable (r io.Reader ) (* graphCacheNode , error ) {
4063
- // Always populate a feature vector, even if we don't have a node
4064
- // announcement and short circuit below.
4065
- node := newGraphCacheNode (
4066
- route.Vertex {},
4067
- lnwire .EmptyFeatureVector (),
4068
- )
4017
+ func deserializeLightningNodeCacheable (r io.Reader ) (route.Vertex ,
4018
+ * lnwire.FeatureVector , error ) {
4069
4019
4070
- var nodeScratch [8 ]byte
4020
+ var (
4021
+ pubKey route.Vertex
4022
+ features = lnwire .EmptyFeatureVector ()
4023
+ nodeScratch [8 ]byte
4024
+ )
4071
4025
4072
4026
// Skip ahead:
4073
4027
// - LastUpdate (8 bytes)
4074
4028
if _ , err := r .Read (nodeScratch [:]); err != nil {
4075
- return nil , err
4029
+ return pubKey , nil , err
4076
4030
}
4077
4031
4078
- if _ , err := io .ReadFull (r , node . pubKeyBytes [:]); err != nil {
4079
- return nil , err
4032
+ if _ , err := io .ReadFull (r , pubKey [:]); err != nil {
4033
+ return pubKey , nil , err
4080
4034
}
4081
4035
4082
4036
// Read the node announcement flag.
4083
4037
if _ , err := r .Read (nodeScratch [:2 ]); err != nil {
4084
- return nil , err
4038
+ return pubKey , nil , err
4085
4039
}
4086
4040
hasNodeAnn := byteOrder .Uint16 (nodeScratch [:2 ])
4087
4041
4088
4042
// The rest of the data is optional, and will only be there if we got a
4089
4043
// node announcement for this node.
4090
4044
if hasNodeAnn == 0 {
4091
- return node , nil
4045
+ return pubKey , features , nil
4092
4046
}
4093
4047
4094
4048
// We did get a node announcement for this node, so we'll have the rest
4095
4049
// of the data available.
4096
4050
var rgb uint8
4097
4051
if err := binary .Read (r , byteOrder , & rgb ); err != nil {
4098
- return nil , err
4052
+ return pubKey , nil , err
4099
4053
}
4100
4054
if err := binary .Read (r , byteOrder , & rgb ); err != nil {
4101
- return nil , err
4055
+ return pubKey , nil , err
4102
4056
}
4103
4057
if err := binary .Read (r , byteOrder , & rgb ); err != nil {
4104
- return nil , err
4058
+ return pubKey , nil , err
4105
4059
}
4106
4060
4107
4061
if _ , err := wire .ReadVarString (r , 0 ); err != nil {
4108
- return nil , err
4062
+ return pubKey , nil , err
4109
4063
}
4110
4064
4111
- if err := node . features .Decode (r ); err != nil {
4112
- return nil , err
4065
+ if err := features .Decode (r ); err != nil {
4066
+ return pubKey , nil , err
4113
4067
}
4114
4068
4115
- return node , nil
4069
+ return pubKey , features , nil
4116
4070
}
4117
4071
4118
4072
func deserializeLightningNode (r io.Reader ) (models.LightningNode , error ) {
0 commit comments