X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning-rapid-gossip-sync%2Fsrc%2Fprocessing.rs;h=fca318a5fa5f8cfac735ff8d3880819e8b6d93a0;hb=refs%2Fheads%2F2023-10-scanable-test-logs;hp=b387d49998e9a38d6f1693e1a18d05c4da57e675;hpb=c3de782a2baab0c742332bea4783c393edb83311;p=rust-lightning diff --git a/lightning-rapid-gossip-sync/src/processing.rs b/lightning-rapid-gossip-sync/src/processing.rs index b387d499..fca318a5 100644 --- a/lightning-rapid-gossip-sync/src/processing.rs +++ b/lightning-rapid-gossip-sync/src/processing.rs @@ -68,6 +68,16 @@ impl>, L: Deref> RapidGossipSync where L } let chain_hash: BlockHash = Readable::read(read_cursor)?; + let ng_genesis_hash = self.network_graph.get_genesis_hash(); + if chain_hash != ng_genesis_hash { + return Err( + LightningError { + err: "Rapid Gossip Sync data's chain hash does not match the network graph's".to_owned(), + action: ErrorAction::IgnoreError, + }.into() + ); + } + let latest_seen_timestamp: u32 = Readable::read(read_cursor)?; if let Some(time) = current_time_unix { @@ -667,4 +677,22 @@ mod tests { panic!("Unexpected update result: {:?}", update_result) } } + + #[test] + fn fails_early_on_chain_hash_mismatch() { + let logger = TestLogger::new(); + // Set to testnet so that the VALID_RGS_BINARY chain hash of mainnet does not match. + let network_graph = NetworkGraph::new(Network::Testnet, &logger); + + assert_eq!(network_graph.read_only().channels().len(), 0); + + let rapid_sync = RapidGossipSync::new(&network_graph, &logger); + let update_result = rapid_sync.update_network_graph_no_std(&VALID_RGS_BINARY, Some(0)); + assert!(update_result.is_err()); + if let Err(GraphSyncError::LightningError(err)) = update_result { + assert_eq!(err.err, "Rapid Gossip Sync data's chain hash does not match the network graph's"); + } else { + panic!("Unexpected update result: {:?}", update_result) + } + } }