@@ -1845,14 +1845,14 @@ impl<L: Deref> NetworkGraph<L> where L::Target: Logger {
1845
1845
/// For an already known (from announcement) channel, update info about one of the directions
1846
1846
/// of the channel.
1847
1847
///
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
1850
1850
/// routing messages from a source using a protocol other than the lightning P2P protocol.
1851
1851
///
1852
1852
/// If built with `no-std`, any updates with a timestamp more than two weeks in the past or
1853
1853
/// materially in the future will be rejected.
1854
1854
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 )
1856
1856
}
1857
1857
1858
1858
/// 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 {
1862
1862
/// If built with `no-std`, any updates with a timestamp more than two weeks in the past or
1863
1863
/// materially in the future will be rejected.
1864
1864
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 )
1866
1866
}
1867
1867
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
+ {
1869
1882
let chan_enabled = msg. flags & ( 1 << 1 ) != ( 1 << 1 ) ;
1870
1883
1871
1884
if msg. chain_hash != self . genesis_hash {
@@ -1961,7 +1974,9 @@ impl<L: Deref> NetworkGraph<L> where L::Target: Logger {
1961
1974
action: ErrorAction :: IgnoreAndLog ( Level :: Debug )
1962
1975
} ) ?, "channel_update" ) ;
1963
1976
}
1964
- channel. two_to_one = get_new_channel_info ! ( ) ;
1977
+ if !only_verify {
1978
+ channel. two_to_one = get_new_channel_info ! ( ) ;
1979
+ }
1965
1980
} else {
1966
1981
check_update_latest ! ( channel. one_to_two) ;
1967
1982
if let Some ( sig) = sig {
@@ -1970,7 +1985,9 @@ impl<L: Deref> NetworkGraph<L> where L::Target: Logger {
1970
1985
action: ErrorAction :: IgnoreAndLog ( Level :: Debug )
1971
1986
} ) ?, "channel_update" ) ;
1972
1987
}
1973
- channel. one_to_two = get_new_channel_info ! ( ) ;
1988
+ if !only_verify {
1989
+ channel. one_to_two = get_new_channel_info ! ( ) ;
1990
+ }
1974
1991
}
1975
1992
}
1976
1993
}
0 commit comments