@@ -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
@@ -1840,6 +1847,13 @@ impl<L: Deref> NetworkGraph<L> where L::Target: Logger {
1840
1847
return Err ( LightningError { err : "Couldn't find channel for update" . to_owned ( ) , action : ErrorAction :: IgnoreError } ) ;
1841
1848
} ,
1842
1849
Some ( channel) => {
1850
+ if msg. chain_hash != self . genesis_hash {
1851
+ return Err ( LightningError {
1852
+ err : "Channel update chain hash does not match genesis hash" . to_owned ( ) ,
1853
+ action : ErrorAction :: IgnoreAndLog ( Level :: Debug ) ,
1854
+ } ) ;
1855
+ }
1856
+
1843
1857
if msg. htlc_maximum_msat > MAX_VALUE_MSAT {
1844
1858
return Err ( LightningError { err :
1845
1859
"htlc_maximum_msat is larger than maximum possible msats" . to_owned ( ) ,
@@ -2311,6 +2325,15 @@ 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.
2330
+ let incorrect_chain_announcement = get_signed_channel_announcement ( |unsigned_announcement| {
2331
+ unsigned_announcement. chain_hash = genesis_block ( Network :: Bitcoin ) . header . block_hash ( ) ;
2332
+ } , node_1_privkey, node_2_privkey, & secp_ctx) ;
2333
+ match gossip_sync. handle_channel_announcement ( & incorrect_chain_announcement) {
2334
+ Ok ( _) => panic ! ( ) ,
2335
+ Err ( e) => assert_eq ! ( e. err, "Channel announcement chain hash does not match genesis hash" )
2336
+ } ;
2314
2337
}
2315
2338
2316
2339
#[ test]
@@ -2415,6 +2438,16 @@ pub(crate) mod tests {
2415
2438
Ok ( _) => panic ! ( ) ,
2416
2439
Err ( e) => assert_eq ! ( e. err, "Invalid signature on channel_update message" )
2417
2440
} ;
2441
+
2442
+ // Test that channel updates with the wrong chain hash are ignored.
2443
+ let incorrect_chain_hash = get_signed_channel_update ( |unsigned_channel_update| {
2444
+ unsigned_channel_update. chain_hash = genesis_block ( Network :: Bitcoin ) . header . block_hash ( ) ;
2445
+ } , node_1_privkey, & secp_ctx) ;
2446
+
2447
+ match gossip_sync. handle_channel_update ( & incorrect_chain_hash) {
2448
+ Ok ( _) => panic ! ( ) ,
2449
+ Err ( e) => assert_eq ! ( e. err, "Channel update chain hash does not match genesis hash" )
2450
+ } ;
2418
2451
}
2419
2452
2420
2453
#[ test]
0 commit comments