@@ -40,8 +40,7 @@ impl NetworkGraph {
40
40
let mut nodes = BTreeMap :: new ( ) ;
41
41
nodes. insert ( our_pubkey. clone ( ) , NodeInfo {
42
42
channels : Vec :: new ( ) ,
43
- lowest_inbound_channel_fee_base_msat : u32:: max_value ( ) ,
44
- lowest_inbound_channel_fee_proportional_millionths : u32:: max_value ( ) ,
43
+ lowest_inbound_channel_fees : None ,
45
44
features : NodeFeatures :: empty ( ) ,
46
45
last_update : None ,
47
46
rgb : [ 0 ; 3 ] ,
@@ -229,15 +228,43 @@ impl_writeable!(ChannelInfo, 0, {
229
228
announcement_message
230
229
} ) ;
231
230
231
+
232
+ /// Fees for routing via a given channel or a node
233
+ #[ derive( Eq , PartialEq , Copy , Clone , Debug ) ]
234
+ pub struct RoutingFees {
235
+ /// Flat routing fee
236
+ pub base_msat : u32 ,
237
+ /// Liquidity-based routing fee
238
+ pub proportional_millionths : u32 ,
239
+ }
240
+
241
+ impl Readable for RoutingFees {
242
+ fn read < R : :: std:: io:: Read > ( reader : & mut R ) -> Result < RoutingFees , DecodeError > {
243
+ let base_msat: u32 = Readable :: read ( reader) ?;
244
+ let proportional_millionths: u32 = Readable :: read ( reader) ?;
245
+ Ok ( RoutingFees {
246
+ base_msat,
247
+ proportional_millionths,
248
+ } )
249
+ }
250
+ }
251
+
252
+ impl Writeable for RoutingFees {
253
+ fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , :: std:: io:: Error > {
254
+ self . base_msat . write ( writer) ?;
255
+ self . proportional_millionths . write ( writer) ?;
256
+ Ok ( ( ) )
257
+ }
258
+ }
259
+
260
+
232
261
#[ derive( PartialEq ) ]
233
262
/// Details regarding a node in the network
234
263
pub struct NodeInfo {
235
264
/// All valid channels a node has announced
236
265
pub channels : Vec < u64 > ,
237
- /// Lowest flat routing fee of all known channels to the node
238
- pub lowest_inbound_channel_fee_base_msat : u32 ,
239
- /// Lowest liquidity-based routing fee of all known channels to the node
240
- pub lowest_inbound_channel_fee_proportional_millionths : u32 ,
266
+ /// Lowest fees enabling routing via any of the known channels to a node
267
+ pub lowest_inbound_channel_fees : Option < RoutingFees > ,
241
268
/// Protocol features the node announced support for
242
269
pub features : NodeFeatures ,
243
270
/// When the last known update to the node state was issued
@@ -259,7 +286,7 @@ pub struct NodeInfo {
259
286
260
287
impl std:: fmt:: Display for NodeInfo {
261
288
fn fmt ( & self , f : & mut std:: fmt:: Formatter ) -> Result < ( ) , std:: fmt:: Error > {
262
- write ! ( f, "features: {}, last_update: {:?}, lowest_inbound_channel_fee_base_msat : {}, lowest_inbound_channel_fee_proportional_millionths: { }, channels: {:?}" , log_bytes!( self . features. encode( ) ) , self . last_update, self . lowest_inbound_channel_fee_base_msat , self . lowest_inbound_channel_fee_proportional_millionths , & self . channels[ ..] ) ?;
289
+ write ! ( f, "features: {}, last_update: {:?}, lowest_inbound_channel_fees : {:? }, channels: {:?}" , log_bytes!( self . features. encode( ) ) , self . last_update, self . lowest_inbound_channel_fees , & self . channels[ ..] ) ?;
263
290
Ok ( ( ) )
264
291
}
265
292
}
@@ -270,8 +297,7 @@ impl Writeable for NodeInfo {
270
297
for ref chan in self . channels . iter ( ) {
271
298
chan. write ( writer) ?;
272
299
}
273
- self . lowest_inbound_channel_fee_base_msat . write ( writer) ?;
274
- self . lowest_inbound_channel_fee_proportional_millionths . write ( writer) ?;
300
+ self . lowest_inbound_channel_fees . write ( writer) ?;
275
301
self . features . write ( writer) ?;
276
302
self . last_update . write ( writer) ?;
277
303
self . rgb . write ( writer) ?;
@@ -294,8 +320,7 @@ impl Readable for NodeInfo {
294
320
for _ in 0 ..channels_count {
295
321
channels. push ( Readable :: read ( reader) ?) ;
296
322
}
297
- let lowest_inbound_channel_fee_base_msat = Readable :: read ( reader) ?;
298
- let lowest_inbound_channel_fee_proportional_millionths = Readable :: read ( reader) ?;
323
+ let lowest_inbound_channel_fees = Readable :: read ( reader) ?;
299
324
let features = Readable :: read ( reader) ?;
300
325
let last_update = Readable :: read ( reader) ?;
301
326
let rgb = Readable :: read ( reader) ?;
@@ -313,8 +338,7 @@ impl Readable for NodeInfo {
313
338
let announcement_message = Readable :: read ( reader) ?;
314
339
Ok ( NodeInfo {
315
340
channels,
316
- lowest_inbound_channel_fee_base_msat,
317
- lowest_inbound_channel_fee_proportional_millionths,
341
+ lowest_inbound_channel_fees,
318
342
features,
319
343
last_update,
320
344
rgb,
@@ -538,8 +562,7 @@ impl RoutingMessageHandler for NetworkGraph {
538
562
BtreeEntry :: Vacant ( node_entry) => {
539
563
node_entry. insert( NodeInfo {
540
564
channels: vec!( NetworkMap :: get_key( msg. contents. short_channel_id, msg. contents. chain_hash) ) ,
541
- lowest_inbound_channel_fee_base_msat: u32 :: max_value( ) ,
542
- lowest_inbound_channel_fee_proportional_millionths: u32 :: max_value( ) ,
565
+ lowest_inbound_channel_fees: None ,
543
566
features: NodeFeatures :: empty( ) ,
544
567
last_update: None ,
545
568
rgb: [ 0 ; 3 ] ,
@@ -630,8 +653,16 @@ impl RoutingMessageHandler for NetworkGraph {
630
653
631
654
if chan_enabled {
632
655
let node = network. nodes . get_mut ( & dest_node_id) . unwrap ( ) ;
633
- node. lowest_inbound_channel_fee_base_msat = cmp:: min ( node. lowest_inbound_channel_fee_base_msat , msg. contents . fee_base_msat ) ;
634
- node. lowest_inbound_channel_fee_proportional_millionths = cmp:: min ( node. lowest_inbound_channel_fee_proportional_millionths , msg. contents . fee_proportional_millionths ) ;
656
+ let mut base_msat = msg. contents . fee_base_msat ;
657
+ let mut proportional_millionths = msg. contents . fee_proportional_millionths ;
658
+ if let Some ( fees) = node. lowest_inbound_channel_fees {
659
+ base_msat = cmp:: min ( base_msat, fees. base_msat ) ;
660
+ proportional_millionths = cmp:: min ( proportional_millionths, fees. proportional_millionths ) ;
661
+ }
662
+ node. lowest_inbound_channel_fees = Some ( RoutingFees {
663
+ base_msat,
664
+ proportional_millionths
665
+ } ) ;
635
666
} else if chan_was_enabled {
636
667
let mut lowest_inbound_channel_fee_base_msat = u32:: max_value ( ) ;
637
668
let mut lowest_inbound_channel_fee_proportional_millionths = u32:: max_value ( ) ;
@@ -653,8 +684,12 @@ impl RoutingMessageHandler for NetworkGraph {
653
684
654
685
//TODO: satisfy the borrow-checker without a double-map-lookup :(
655
686
let mut_node = network. nodes . get_mut ( & dest_node_id) . unwrap ( ) ;
656
- mut_node. lowest_inbound_channel_fee_base_msat = lowest_inbound_channel_fee_base_msat;
657
- mut_node. lowest_inbound_channel_fee_proportional_millionths = lowest_inbound_channel_fee_proportional_millionths;
687
+ if mut_node. channels . len ( ) > 0 {
688
+ mut_node. lowest_inbound_channel_fees = Some ( RoutingFees {
689
+ base_msat : lowest_inbound_channel_fee_base_msat,
690
+ proportional_millionths : lowest_inbound_channel_fee_proportional_millionths
691
+ } ) ;
692
+ }
658
693
}
659
694
660
695
Ok ( msg. contents . excess_data . is_empty ( ) )
@@ -720,7 +755,7 @@ impl RoutingMessageHandler for NetworkGraph {
720
755
mod tests {
721
756
use chain:: chaininterface;
722
757
use ln:: features:: { ChannelFeatures , NodeFeatures } ;
723
- use ln:: network_graph:: { NetworkGraph , NetworkMap , DirectionalChannelInfo , ChannelInfo , NodeInfo } ;
758
+ use ln:: network_graph:: { NetworkGraph , NetworkMap , DirectionalChannelInfo , ChannelInfo , NodeInfo , RoutingFees } ;
724
759
use ln:: msgs:: { RoutingMessageHandler , UnsignedNodeAnnouncement , NodeAnnouncement ,
725
760
UnsignedChannelAnnouncement , ChannelAnnouncement , UnsignedChannelUpdate , ChannelUpdate , HTLCFailChannelUpdate } ;
726
761
use util:: test_utils;
@@ -1541,10 +1576,14 @@ mod tests {
1541
1576
let mut network = network_graph. network_map . write ( ) . unwrap ( ) ;
1542
1577
let zero_hash = Sha256dHash :: hash ( & [ 0 ; 32 ] ) ;
1543
1578
1579
+
1580
+ let node_routing_fees = RoutingFees {
1581
+ base_msat : 100 ,
1582
+ proportional_millionths : 0 ,
1583
+ } ;
1544
1584
network. nodes . insert ( node1. clone ( ) , NodeInfo {
1545
1585
channels : vec ! ( NetworkMap :: get_key( 1 , zero_hash. clone( ) ) , NetworkMap :: get_key( 3 , zero_hash. clone( ) ) ) ,
1546
- lowest_inbound_channel_fee_base_msat : 100 ,
1547
- lowest_inbound_channel_fee_proportional_millionths : 0 ,
1586
+ lowest_inbound_channel_fees : Some ( node_routing_fees) ,
1548
1587
features : NodeFeatures :: supported ( ) ,
1549
1588
last_update : Some ( 1 ) ,
1550
1589
rgb : [ 0 ; 3 ] ,
0 commit comments