@@ -241,6 +241,11 @@ type channelMapKey struct {
241
241
chanID [8 ]byte
242
242
}
243
243
244
+ // String returns a human-readable representation of the key.
245
+ func (c channelMapKey ) String () string {
246
+ return fmt .Sprintf ("node=%v, chanID=%x" , c .nodeKey , c .chanID )
247
+ }
248
+
244
249
// getChannelMap loads all channel edge policies from the database and stores
245
250
// them in a map.
246
251
func (c * KVStore ) getChannelMap (edges kvdb.RBucket ) (
@@ -501,20 +506,47 @@ func (c *KVStore) ForEachChannelCacheable(cb func(*models.CachedEdgeInfo,
501
506
return err
502
507
}
503
508
504
- policy1 := channelMap [ channelMapKey {
509
+ key1 := channelMapKey {
505
510
nodeKey : info .NodeKey1Bytes ,
506
511
chanID : chanID ,
507
- }]
512
+ }
513
+ policy1 := channelMap [key1 ]
508
514
509
- policy2 := channelMap [ channelMapKey {
515
+ key2 := channelMapKey {
510
516
nodeKey : info .NodeKey2Bytes ,
511
517
chanID : chanID ,
512
- }]
518
+ }
519
+ policy2 := channelMap [key2 ]
520
+
521
+ // We now create the cached edge policies, but
522
+ // only when the above policies are found in the
523
+ // `channelMap`.
524
+ var (
525
+ cachedPolicy1 * models.CachedEdgePolicy
526
+ cachedPolicy2 * models.CachedEdgePolicy
527
+ )
528
+
529
+ if policy1 != nil {
530
+ cachedPolicy1 = models .NewCachedPolicy (
531
+ policy1 ,
532
+ )
533
+ } else {
534
+ log .Warnf ("ChannelEdgePolicy not " +
535
+ "found using %v" , key1 )
536
+ }
537
+
538
+ if policy2 != nil {
539
+ cachedPolicy2 = models .NewCachedPolicy (
540
+ policy2 ,
541
+ )
542
+ } else {
543
+ log .Warnf ("ChannelEdgePolicy not " +
544
+ "found using %v" , key2 )
545
+ }
513
546
514
547
return cb (
515
548
models .NewCachedEdge (& info ),
516
- models .NewCachedPolicy (policy1 ),
517
- models .NewCachedPolicy (policy2 ),
549
+ cachedPolicy1 , cachedPolicy2 ,
518
550
)
519
551
},
520
552
)
0 commit comments