@@ -1573,6 +1573,13 @@ impl<L: Deref> NetworkGraph<L> where L::Target: Logger {
1573
1573
return Err ( LightningError { err : "Channel announcement node had a channel with itself" . to_owned ( ) , action : ErrorAction :: IgnoreError } ) ;
1574
1574
}
1575
1575
1576
+ if msg. chain_hash != self . genesis_hash {
1577
+ return Err ( LightningError {
1578
+ err : "Channel announcement chain hash does not match genesis hash" . to_owned ( ) ,
1579
+ action : ErrorAction :: IgnoreAndLog ( Level :: Debug ) ,
1580
+ } ) ;
1581
+ }
1582
+
1576
1583
{
1577
1584
let channels = self . channels . read ( ) . unwrap ( ) ;
1578
1585
@@ -1819,6 +1826,13 @@ impl<L: Deref> NetworkGraph<L> where L::Target: Logger {
1819
1826
fn update_channel_intern ( & self , msg : & msgs:: UnsignedChannelUpdate , full_msg : Option < & msgs:: ChannelUpdate > , sig : Option < & secp256k1:: ecdsa:: Signature > ) -> Result < ( ) , LightningError > {
1820
1827
let chan_enabled = msg. flags & ( 1 << 1 ) != ( 1 << 1 ) ;
1821
1828
1829
+ if msg. chain_hash != self . genesis_hash {
1830
+ return Err ( LightningError {
1831
+ err : "Channel update chain hash does not match genesis hash" . to_owned ( ) ,
1832
+ action : ErrorAction :: IgnoreAndLog ( Level :: Debug ) ,
1833
+ } ) ;
1834
+ }
1835
+
1822
1836
#[ cfg( all( feature = "std" , not( test) , not( feature = "_test_utils" ) ) ) ]
1823
1837
{
1824
1838
// Note that many tests rely on being able to set arbitrarily old timestamps, thus we
@@ -2311,6 +2325,16 @@ pub(crate) mod tests {
2311
2325
Ok ( _) => panic ! ( ) ,
2312
2326
Err ( e) => assert_eq ! ( e. err, "Channel announcement node had a channel with itself" )
2313
2327
} ;
2328
+
2329
+ // Test that channel announcements with the wrong chain hash are ignored (network graph is testnet,
2330
+ // announcement is mainnet).
2331
+ let incorrect_chain_announcement = get_signed_channel_announcement ( |unsigned_announcement| {
2332
+ unsigned_announcement. chain_hash = genesis_block ( Network :: Bitcoin ) . header . block_hash ( ) ;
2333
+ } , node_1_privkey, node_2_privkey, & secp_ctx) ;
2334
+ match gossip_sync. handle_channel_announcement ( & incorrect_chain_announcement) {
2335
+ Ok ( _) => panic ! ( ) ,
2336
+ Err ( e) => assert_eq ! ( e. err, "Channel announcement chain hash does not match genesis hash" )
2337
+ } ;
2314
2338
}
2315
2339
2316
2340
#[ test]
@@ -2415,6 +2439,17 @@ pub(crate) mod tests {
2415
2439
Ok ( _) => panic ! ( ) ,
2416
2440
Err ( e) => assert_eq ! ( e. err, "Invalid signature on channel_update message" )
2417
2441
} ;
2442
+
2443
+ // Test that channel updates with the wrong chain hash are ignored (network graph is testnet, channel
2444
+ // update is mainet).
2445
+ let incorrect_chain_update = get_signed_channel_update ( |unsigned_channel_update| {
2446
+ unsigned_channel_update. chain_hash = genesis_block ( Network :: Bitcoin ) . header . block_hash ( ) ;
2447
+ } , node_1_privkey, & secp_ctx) ;
2448
+
2449
+ match gossip_sync. handle_channel_update ( & incorrect_chain_update) {
2450
+ Ok ( _) => panic ! ( ) ,
2451
+ Err ( e) => assert_eq ! ( e. err, "Channel update chain hash does not match genesis hash" )
2452
+ } ;
2418
2453
}
2419
2454
2420
2455
#[ test]
0 commit comments