@@ -1376,8 +1376,8 @@ impl NetworkGraph {
13761376 }
13771377 }
13781378 }
1379- macro_rules! maybe_update_channel_info {
1380- ( $target: expr , $src_node : expr) => {
1379+ macro_rules! check_update_latest {
1380+ ( $target: expr) => {
13811381 if let Some ( existing_chan_info) = $target. as_ref( ) {
13821382 // The timestamp field is somewhat of a misnomer - the BOLTs use it to
13831383 // order updates to ensure you always have the latest one, only
@@ -1394,7 +1394,11 @@ impl NetworkGraph {
13941394 } else {
13951395 chan_was_enabled = false ;
13961396 }
1397+ }
1398+ }
13971399
1400+ macro_rules! get_new_channel_info {
1401+ ( ) => { {
13981402 let last_update_message = if msg. excess_data. len( ) <= MAX_EXCESS_BYTES_FOR_RELAY
13991403 { full_msg. cloned( ) } else { None } ;
14001404
@@ -1410,29 +1414,31 @@ impl NetworkGraph {
14101414 } ,
14111415 last_update_message
14121416 } ;
1413- $target = Some ( updated_channel_update_info) ;
1414- }
1417+ Some ( updated_channel_update_info)
1418+ } }
14151419 }
14161420
14171421 let msg_hash = hash_to_message ! ( & Sha256dHash :: hash( & msg. encode( ) [ ..] ) [ ..] ) ;
14181422 if msg. flags & 1 == 1 {
14191423 dest_node_id = channel. node_one . clone ( ) ;
1424+ check_update_latest ! ( channel. two_to_one) ;
14201425 if let Some ( ( sig, ctx) ) = sig_info {
14211426 secp_verify_sig ! ( ctx, & msg_hash, & sig, & PublicKey :: from_slice( channel. node_two. as_slice( ) ) . map_err( |_| LightningError {
14221427 err: "Couldn't parse source node pubkey" . to_owned( ) ,
14231428 action: ErrorAction :: IgnoreAndLog ( Level :: Debug )
14241429 } ) ?, "channel_update" ) ;
14251430 }
1426- maybe_update_channel_info ! ( channel. two_to_one, channel . node_two ) ;
1431+ channel. two_to_one = get_new_channel_info ! ( ) ;
14271432 } else {
14281433 dest_node_id = channel. node_two . clone ( ) ;
1434+ check_update_latest ! ( channel. one_to_two) ;
14291435 if let Some ( ( sig, ctx) ) = sig_info {
14301436 secp_verify_sig ! ( ctx, & msg_hash, & sig, & PublicKey :: from_slice( channel. node_one. as_slice( ) ) . map_err( |_| LightningError {
14311437 err: "Couldn't parse destination node pubkey" . to_owned( ) ,
14321438 action: ErrorAction :: IgnoreAndLog ( Level :: Debug )
14331439 } ) ?, "channel_update" ) ;
14341440 }
1435- maybe_update_channel_info ! ( channel. one_to_two, channel . node_one ) ;
1441+ channel. one_to_two = get_new_channel_info ! ( ) ;
14361442 }
14371443 }
14381444 }
0 commit comments