Skip to content

Commit 0a43123

Browse files
Check chain hash for channel announcement and update
1 parent c182567 commit 0a43123

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

lightning/src/routing/gossip.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1573,6 +1573,13 @@ impl<L: Deref> NetworkGraph<L> where L::Target: Logger {
15731573
return Err(LightningError{err: "Channel announcement node had a channel with itself".to_owned(), action: ErrorAction::IgnoreError});
15741574
}
15751575

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+
15761583
{
15771584
let channels = self.channels.read().unwrap();
15781585

@@ -1840,6 +1847,13 @@ impl<L: Deref> NetworkGraph<L> where L::Target: Logger {
18401847
return Err(LightningError{err: "Couldn't find channel for update".to_owned(), action: ErrorAction::IgnoreError});
18411848
},
18421849
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+
18431857
if msg.htlc_maximum_msat > MAX_VALUE_MSAT {
18441858
return Err(LightningError{err:
18451859
"htlc_maximum_msat is larger than maximum possible msats".to_owned(),
@@ -2311,6 +2325,15 @@ pub(crate) mod tests {
23112325
Ok(_) => panic!(),
23122326
Err(e) => assert_eq!(e.err, "Channel announcement node had a channel with itself")
23132327
};
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+
};
23142337
}
23152338

23162339
#[test]
@@ -2415,6 +2438,16 @@ pub(crate) mod tests {
24152438
Ok(_) => panic!(),
24162439
Err(e) => assert_eq!(e.err, "Invalid signature on channel_update message")
24172440
};
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+
};
24182451
}
24192452

24202453
#[test]

0 commit comments

Comments
 (0)