@@ -1376,8 +1376,8 @@ impl NetworkGraph {
1376
1376
}
1377
1377
}
1378
1378
}
1379
- macro_rules! maybe_update_channel_info {
1380
- ( $target: expr , $src_node : expr) => {
1379
+ macro_rules! check_update_latest {
1380
+ ( $target: expr) => {
1381
1381
if let Some ( existing_chan_info) = $target. as_ref( ) {
1382
1382
// The timestamp field is somewhat of a misnomer - the BOLTs use it to
1383
1383
// order updates to ensure you always have the latest one, only
@@ -1394,7 +1394,11 @@ impl NetworkGraph {
1394
1394
} else {
1395
1395
chan_was_enabled = false ;
1396
1396
}
1397
+ }
1398
+ }
1397
1399
1400
+ macro_rules! get_new_channel_info {
1401
+ ( ) => { {
1398
1402
let last_update_message = if msg. excess_data. len( ) <= MAX_EXCESS_BYTES_FOR_RELAY
1399
1403
{ full_msg. cloned( ) } else { None } ;
1400
1404
@@ -1410,29 +1414,31 @@ impl NetworkGraph {
1410
1414
} ,
1411
1415
last_update_message
1412
1416
} ;
1413
- $target = Some ( updated_channel_update_info) ;
1414
- }
1417
+ Some ( updated_channel_update_info)
1418
+ } }
1415
1419
}
1416
1420
1417
1421
let msg_hash = hash_to_message ! ( & Sha256dHash :: hash( & msg. encode( ) [ ..] ) [ ..] ) ;
1418
1422
if msg. flags & 1 == 1 {
1419
1423
dest_node_id = channel. node_one . clone ( ) ;
1424
+ check_update_latest ! ( channel. two_to_one) ;
1420
1425
if let Some ( ( sig, ctx) ) = sig_info {
1421
1426
secp_verify_sig ! ( ctx, & msg_hash, & sig, & PublicKey :: from_slice( channel. node_two. as_slice( ) ) . map_err( |_| LightningError {
1422
1427
err: "Couldn't parse source node pubkey" . to_owned( ) ,
1423
1428
action: ErrorAction :: IgnoreAndLog ( Level :: Debug )
1424
1429
} ) ?, "channel_update" ) ;
1425
1430
}
1426
- maybe_update_channel_info ! ( channel. two_to_one, channel . node_two ) ;
1431
+ channel. two_to_one = get_new_channel_info ! ( ) ;
1427
1432
} else {
1428
1433
dest_node_id = channel. node_two . clone ( ) ;
1434
+ check_update_latest ! ( channel. one_to_two) ;
1429
1435
if let Some ( ( sig, ctx) ) = sig_info {
1430
1436
secp_verify_sig ! ( ctx, & msg_hash, & sig, & PublicKey :: from_slice( channel. node_one. as_slice( ) ) . map_err( |_| LightningError {
1431
1437
err: "Couldn't parse destination node pubkey" . to_owned( ) ,
1432
1438
action: ErrorAction :: IgnoreAndLog ( Level :: Debug )
1433
1439
} ) ?, "channel_update" ) ;
1434
1440
}
1435
- maybe_update_channel_info ! ( channel. one_to_two, channel . node_one ) ;
1441
+ channel. one_to_two = get_new_channel_info ! ( ) ;
1436
1442
}
1437
1443
}
1438
1444
}
0 commit comments