@@ -1845,14 +1845,14 @@ impl<L: Deref> NetworkGraph<L> where L::Target: Logger {
18451845 /// For an already known (from announcement) channel, update info about one of the directions
18461846 /// of the channel.
18471847 ///
1848- /// You probably don't want to call this directly, instead relying on a P2PGossipSync's
1849- /// RoutingMessageHandler implementation to call it indirectly. This may be useful to accept
1848+ /// You probably don't want to call this directly, instead relying on a [` P2PGossipSync`] 's
1849+ /// [` RoutingMessageHandler`] implementation to call it indirectly. This may be useful to accept
18501850 /// routing messages from a source using a protocol other than the lightning P2P protocol.
18511851 ///
18521852 /// If built with `no-std`, any updates with a timestamp more than two weeks in the past or
18531853 /// materially in the future will be rejected.
18541854 pub fn update_channel ( & self , msg : & msgs:: ChannelUpdate ) -> Result < ( ) , LightningError > {
1855- self . update_channel_intern ( & msg. contents , Some ( & msg) , Some ( & msg. signature ) )
1855+ self . update_channel_internal ( & msg. contents , Some ( & msg) , Some ( & msg. signature ) , false )
18561856 }
18571857
18581858 /// For an already known (from announcement) channel, update info about one of the directions
@@ -1862,10 +1862,23 @@ impl<L: Deref> NetworkGraph<L> where L::Target: Logger {
18621862 /// If built with `no-std`, any updates with a timestamp more than two weeks in the past or
18631863 /// materially in the future will be rejected.
18641864 pub fn update_channel_unsigned ( & self , msg : & msgs:: UnsignedChannelUpdate ) -> Result < ( ) , LightningError > {
1865- self . update_channel_intern ( msg, None , None )
1865+ self . update_channel_internal ( msg, None , None , false )
18661866 }
18671867
1868- fn update_channel_intern ( & self , msg : & msgs:: UnsignedChannelUpdate , full_msg : Option < & msgs:: ChannelUpdate > , sig : Option < & secp256k1:: ecdsa:: Signature > ) -> Result < ( ) , LightningError > {
1868+ /// For an already known (from announcement) channel, verify the given [`ChannelUpdate`].
1869+ ///
1870+ /// This checks whether the update currently is applicable by [`Self::update_channel`].
1871+ ///
1872+ /// If built with `no-std`, any updates with a timestamp more than two weeks in the past or
1873+ /// materially in the future will be rejected.
1874+ pub fn verify_channel_update ( & self , msg : & msgs:: ChannelUpdate ) -> Result < ( ) , LightningError > {
1875+ self . update_channel_internal ( & msg. contents , Some ( & msg) , Some ( & msg. signature ) , true )
1876+ }
1877+
1878+ fn update_channel_internal ( & self , msg : & msgs:: UnsignedChannelUpdate ,
1879+ full_msg : Option < & msgs:: ChannelUpdate > , sig : Option < & secp256k1:: ecdsa:: Signature > ,
1880+ only_verify : bool ) -> Result < ( ) , LightningError >
1881+ {
18691882 let chan_enabled = msg. flags & ( 1 << 1 ) != ( 1 << 1 ) ;
18701883
18711884 if msg. chain_hash != self . chain_hash {
@@ -1961,7 +1974,9 @@ impl<L: Deref> NetworkGraph<L> where L::Target: Logger {
19611974 action: ErrorAction :: IgnoreAndLog ( Level :: Debug )
19621975 } ) ?, "channel_update" ) ;
19631976 }
1964- channel. two_to_one = get_new_channel_info ! ( ) ;
1977+ if !only_verify {
1978+ channel. two_to_one = get_new_channel_info ! ( ) ;
1979+ }
19651980 } else {
19661981 check_update_latest ! ( channel. one_to_two) ;
19671982 if let Some ( sig) = sig {
@@ -1970,7 +1985,9 @@ impl<L: Deref> NetworkGraph<L> where L::Target: Logger {
19701985 action: ErrorAction :: IgnoreAndLog ( Level :: Debug )
19711986 } ) ?, "channel_update" ) ;
19721987 }
1973- channel. one_to_two = get_new_channel_info ! ( ) ;
1988+ if !only_verify {
1989+ channel. one_to_two = get_new_channel_info ! ( ) ;
1990+ }
19741991 }
19751992 }
19761993 }
@@ -2411,6 +2428,7 @@ pub(crate) mod tests {
24112428 }
24122429
24132430 let valid_channel_update = get_signed_channel_update ( |_| { } , node_1_privkey, & secp_ctx) ;
2431+ network_graph. verify_channel_update ( & valid_channel_update) . unwrap ( ) ;
24142432 match gossip_sync. handle_channel_update ( & valid_channel_update) {
24152433 Ok ( res) => assert ! ( res) ,
24162434 _ => panic ! ( ) ,
0 commit comments