@@ -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,13 +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
- err := c .graphCache .AddNode (tx , cNode )
908
- if err != nil {
909
- return err
910
- }
911
907
}
912
908
913
909
return addLightningNode (tx , node )
@@ -3059,50 +3055,6 @@ func (c *ChannelGraph) fetchLightningNode(tx kvdb.RTx,
3059
3055
return node , nil
3060
3056
}
3061
3057
3062
- // graphCacheNode is a struct that wraps a LightningNode in a way that it can be
3063
- // cached in the graph cache.
3064
- type graphCacheNode struct {
3065
- pubKeyBytes route.Vertex
3066
- features * lnwire.FeatureVector
3067
- }
3068
-
3069
- // newGraphCacheNode returns a new cache optimized node.
3070
- func newGraphCacheNode (pubKey route.Vertex ,
3071
- features * lnwire.FeatureVector ) * graphCacheNode {
3072
-
3073
- return & graphCacheNode {
3074
- pubKeyBytes : pubKey ,
3075
- features : features ,
3076
- }
3077
- }
3078
-
3079
- // PubKey returns the node's public identity key.
3080
- func (n * graphCacheNode ) PubKey () route.Vertex {
3081
- return n .pubKeyBytes
3082
- }
3083
-
3084
- // Features returns the node's features.
3085
- func (n * graphCacheNode ) Features () * lnwire.FeatureVector {
3086
- return n .features
3087
- }
3088
-
3089
- // ForEachChannel iterates through all channels of this node, executing the
3090
- // passed callback with an edge info structure and the policies of each end
3091
- // of the channel. The first edge policy is the outgoing edge *to* the
3092
- // connecting node, while the second is the incoming edge *from* the
3093
- // connecting node. If the callback returns an error, then the iteration is
3094
- // halted with the error propagated back up to the caller.
3095
- //
3096
- // Unknown policies are passed into the callback as nil values.
3097
- func (n * graphCacheNode ) ForEachChannel (tx kvdb.RTx ,
3098
- cb func (kvdb.RTx , * models.ChannelEdgeInfo , * models.ChannelEdgePolicy ,
3099
- * models.ChannelEdgePolicy ) error ) error {
3100
-
3101
- return nodeTraversal (tx , n .pubKeyBytes [:], nil , cb )
3102
- }
3103
-
3104
- var _ GraphCacheNode = (* graphCacheNode )(nil )
3105
-
3106
3058
// HasLightningNode determines if the graph has a vertex identified by the
3107
3059
// target node identity public key. If the node exists in the database, a
3108
3060
// timestamp of when the data for the node was lasted updated is returned along
@@ -4062,60 +4014,59 @@ func fetchLightningNode(nodeBucket kvdb.RBucket,
4062
4014
return deserializeLightningNode (nodeReader )
4063
4015
}
4064
4016
4065
- func deserializeLightningNodeCacheable (r io.Reader ) (* graphCacheNode , error ) {
4066
- // Always populate a feature vector, even if we don't have a node
4067
- // announcement and short circuit below.
4068
- node := newGraphCacheNode (
4069
- route.Vertex {},
4070
- lnwire .EmptyFeatureVector (),
4071
- )
4017
+ func deserializeLightningNodeCacheable (r io.Reader ) (route.Vertex ,
4018
+ * lnwire.FeatureVector , error ) {
4072
4019
4073
- var nodeScratch [8 ]byte
4020
+ var (
4021
+ pubKey route.Vertex
4022
+ features = lnwire .EmptyFeatureVector ()
4023
+ nodeScratch [8 ]byte
4024
+ )
4074
4025
4075
4026
// Skip ahead:
4076
4027
// - LastUpdate (8 bytes)
4077
4028
if _ , err := r .Read (nodeScratch [:]); err != nil {
4078
- return nil , err
4029
+ return pubKey , nil , err
4079
4030
}
4080
4031
4081
- if _ , err := io .ReadFull (r , node . pubKeyBytes [:]); err != nil {
4082
- return nil , err
4032
+ if _ , err := io .ReadFull (r , pubKey [:]); err != nil {
4033
+ return pubKey , nil , err
4083
4034
}
4084
4035
4085
4036
// Read the node announcement flag.
4086
4037
if _ , err := r .Read (nodeScratch [:2 ]); err != nil {
4087
- return nil , err
4038
+ return pubKey , nil , err
4088
4039
}
4089
4040
hasNodeAnn := byteOrder .Uint16 (nodeScratch [:2 ])
4090
4041
4091
4042
// The rest of the data is optional, and will only be there if we got a
4092
4043
// node announcement for this node.
4093
4044
if hasNodeAnn == 0 {
4094
- return node , nil
4045
+ return pubKey , features , nil
4095
4046
}
4096
4047
4097
4048
// We did get a node announcement for this node, so we'll have the rest
4098
4049
// of the data available.
4099
4050
var rgb uint8
4100
4051
if err := binary .Read (r , byteOrder , & rgb ); err != nil {
4101
- return nil , err
4052
+ return pubKey , nil , err
4102
4053
}
4103
4054
if err := binary .Read (r , byteOrder , & rgb ); err != nil {
4104
- return nil , err
4055
+ return pubKey , nil , err
4105
4056
}
4106
4057
if err := binary .Read (r , byteOrder , & rgb ); err != nil {
4107
- return nil , err
4058
+ return pubKey , nil , err
4108
4059
}
4109
4060
4110
4061
if _ , err := wire .ReadVarString (r , 0 ); err != nil {
4111
- return nil , err
4062
+ return pubKey , nil , err
4112
4063
}
4113
4064
4114
- if err := node . features .Decode (r ); err != nil {
4115
- return nil , err
4065
+ if err := features .Decode (r ); err != nil {
4066
+ return pubKey , nil , err
4116
4067
}
4117
4068
4118
- return node , nil
4069
+ return pubKey , features , nil
4119
4070
}
4120
4071
4121
4072
func deserializeLightningNode (r io.Reader ) (models.LightningNode , error ) {
0 commit comments