]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Remove genesis block hash from public API
authorMatt Corallo <git@bluematt.me>
Thu, 9 Feb 2023 19:20:22 +0000 (19:20 +0000)
committerMatt Corallo <git@bluematt.me>
Fri, 24 Feb 2023 00:22:58 +0000 (00:22 +0000)
Forcing users to pass a genesis block hash has ended up being
error-prone largely due to byte-swapping questions for bindings
users. Further, our API is currently inconsistent - in
`ChannelManager` we take a `Bitcoin::Network` but in `NetworkGraph`
we take the genesis block hash.

Luckily `NetworkGraph` is the only remaining place where we require
users pass the genesis block hash, so swapping it for a `Network`
is a simple change.

15 files changed:
fuzz/src/full_stack.rs
fuzz/src/process_network_graph.rs
fuzz/src/router.rs
lightning-background-processor/src/lib.rs
lightning-rapid-gossip-sync/src/lib.rs
lightning-rapid-gossip-sync/src/processing.rs
lightning/src/ln/channelmanager.rs
lightning/src/ln/functional_test_utils.rs
lightning/src/ln/functional_tests.rs
lightning/src/ln/outbound_payment.rs
lightning/src/routing/gossip.rs
lightning/src/routing/router.rs
lightning/src/routing/scoring.rs
lightning/src/routing/test_utils.rs
lightning/src/routing/utxo.rs

index ca42466880a110e3e0e24873efe85f377a4974ad..71fb26b6a7e61eb570721eeba19489435b726347 100644 (file)
@@ -450,7 +450,7 @@ pub fn do_test(data: &[u8], logger: &Arc<dyn Logger>) {
        // it's easier to just increment the counter here so the keys don't change.
        keys_manager.counter.fetch_sub(3, Ordering::AcqRel);
        let our_id = &keys_manager.get_node_id(Recipient::Node).unwrap();
-       let network_graph = Arc::new(NetworkGraph::new(genesis_block(network).block_hash(), Arc::clone(&logger)));
+       let network_graph = Arc::new(NetworkGraph::new(network, Arc::clone(&logger)));
        let gossip_sync = Arc::new(P2PGossipSync::new(Arc::clone(&network_graph), None, Arc::clone(&logger)));
        let scorer = FixedPenaltyScorer::with_penalty(0);
 
index 6615811512cb55f9007f0948305aea0651707c32..c900a7d38d5ac0529b0912e05717f9d0f0e4c693 100644 (file)
@@ -1,14 +1,12 @@
 // Imports that need to be added manually
 use lightning_rapid_gossip_sync::RapidGossipSync;
-use bitcoin::hashes::Hash as TraitImport;
 
 use crate::utils::test_logger;
 
 /// Actual fuzz test, method signature and name are fixed
 fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
-       let block_hash = bitcoin::BlockHash::all_zeros();
        let logger = test_logger::TestLogger::new("".to_owned(), out);
-       let network_graph = lightning::routing::gossip::NetworkGraph::new(block_hash, &logger);
+       let network_graph = lightning::routing::gossip::NetworkGraph::new(bitcoin::Network::Bitcoin, &logger);
        let rapid_sync = RapidGossipSync::new(&network_graph);
        let _ = rapid_sync.update_network_graph(data);
 }
index a7c50de4a471de122c501d8a5789aced9e76bf53..93de35c5d094783d8bdc4e9b6c6a935b39088f34 100644 (file)
@@ -24,7 +24,6 @@ use lightning::util::ser::Readable;
 use bitcoin::hashes::Hash;
 use bitcoin::secp256k1::PublicKey;
 use bitcoin::network::constants::Network;
-use bitcoin::blockdata::constants::genesis_block;
 
 use crate::utils::test_logger;
 
@@ -189,7 +188,7 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
        let logger = test_logger::TestLogger::new("".to_owned(), out);
 
        let our_pubkey = get_pubkey!();
-       let net_graph = NetworkGraph::new(genesis_block(Network::Bitcoin).header.block_hash(), &logger);
+       let net_graph = NetworkGraph::new(Network::Bitcoin, &logger);
        let chain_source = FuzzChainSource {
                input: Arc::clone(&input),
                net_graph: &net_graph,
index 97d0462eb5010980850c64b53dc37a07c512f476..ce94f0107a3213e652b70275bba3543b70568854 100644 (file)
@@ -941,7 +941,7 @@ mod tests {
                        let logger = Arc::new(test_utils::TestLogger::with_id(format!("node {}", i)));
                        let network = Network::Testnet;
                        let genesis_block = genesis_block(network);
-                       let network_graph = Arc::new(NetworkGraph::new(genesis_block.header.block_hash(), logger.clone()));
+                       let network_graph = Arc::new(NetworkGraph::new(network, logger.clone()));
                        let scorer = Arc::new(Mutex::new(TestScorer::new()));
                        let seed = [i as u8; 32];
                        let router = Arc::new(DefaultRouter::new(network_graph.clone(), logger.clone(), seed, scorer.clone()));
index ff0e481b39711cdb41166f2627d23d322838064a..3bceb2e28e9239c0a7e8b34790275d4f51f064e2 100644 (file)
@@ -53,8 +53,7 @@
 //! # }
 //! # let logger = FakeLogger {};
 //!
-//! let block_hash = genesis_block(Network::Bitcoin).header.block_hash();
-//! let network_graph = NetworkGraph::new(block_hash, &logger);
+//! let network_graph = NetworkGraph::new(Network::Bitcoin, &logger);
 //! let rapid_sync = RapidGossipSync::new(&network_graph);
 //! let snapshot_contents: &[u8] = &[0; 0];
 //! let new_last_sync_timestamp_result = rapid_sync.update_network_graph(snapshot_contents);
@@ -161,7 +160,6 @@ impl<NG: Deref<Target=NetworkGraph<L>>, L: Deref> RapidGossipSync<NG, L> where L
 mod tests {
        use std::fs;
 
-       use bitcoin::blockdata::constants::genesis_block;
        use bitcoin::Network;
 
        use lightning::ln::msgs::DecodeError;
@@ -225,9 +223,8 @@ mod tests {
                let sync_test = FileSyncTest::new(tmp_directory, &valid_response);
                let graph_sync_test_file = sync_test.get_test_file_path();
 
-               let block_hash = genesis_block(Network::Bitcoin).block_hash();
                let logger = TestLogger::new();
-               let network_graph = NetworkGraph::new(block_hash, &logger);
+               let network_graph = NetworkGraph::new(Network::Bitcoin, &logger);
 
                assert_eq!(network_graph.read_only().channels().len(), 0);
 
@@ -258,9 +255,8 @@ mod tests {
 
        #[test]
        fn measure_native_read_from_file() {
-               let block_hash = genesis_block(Network::Bitcoin).block_hash();
                let logger = TestLogger::new();
-               let network_graph = NetworkGraph::new(block_hash, &logger);
+               let network_graph = NetworkGraph::new(Network::Bitcoin, &logger);
 
                assert_eq!(network_graph.read_only().channels().len(), 0);
 
@@ -290,7 +286,6 @@ mod tests {
 pub mod bench {
        use test::Bencher;
 
-       use bitcoin::blockdata::constants::genesis_block;
        use bitcoin::Network;
 
        use lightning::ln::msgs::DecodeError;
@@ -301,10 +296,9 @@ pub mod bench {
 
        #[bench]
        fn bench_reading_full_graph_from_file(b: &mut Bencher) {
-               let block_hash = genesis_block(Network::Bitcoin).block_hash();
                let logger = TestLogger::new();
                b.iter(|| {
-                       let network_graph = NetworkGraph::new(block_hash, &logger);
+                       let network_graph = NetworkGraph::new(Network::Bitcoin, &logger);
                        let rapid_sync = RapidGossipSync::new(&network_graph);
                        let sync_result = rapid_sync.sync_network_graph_with_file_path("./res/full_graph.lngossip");
                        if let Err(crate::error::GraphSyncError::DecodeError(DecodeError::Io(io_error))) = &sync_result {
index f84f205c9b56f324838240a1be7d07162655f32d..4b6de04c6556a5ef302d4dced78f1b833f5e5380 100644 (file)
@@ -237,7 +237,6 @@ impl<NG: Deref<Target=NetworkGraph<L>>, L: Deref> RapidGossipSync<NG, L> where L
 
 #[cfg(test)]
 mod tests {
-       use bitcoin::blockdata::constants::genesis_block;
        use bitcoin::Network;
 
        use lightning::ln::msgs::DecodeError;
@@ -269,9 +268,8 @@ mod tests {
 
        #[test]
        fn network_graph_fails_to_update_from_clipped_input() {
-               let block_hash = genesis_block(Network::Bitcoin).block_hash();
                let logger = TestLogger::new();
-               let network_graph = NetworkGraph::new(block_hash, &logger);
+               let network_graph = NetworkGraph::new(Network::Bitcoin, &logger);
 
                let example_input = vec![
                        76, 68, 75, 1, 111, 226, 140, 10, 182, 241, 179, 114, 193, 166, 162, 70, 174, 99, 247,
@@ -309,9 +307,8 @@ mod tests {
                        68, 226, 0, 6, 11, 0, 1, 128,
                ];
 
-               let block_hash = genesis_block(Network::Bitcoin).block_hash();
                let logger = TestLogger::new();
-               let network_graph = NetworkGraph::new(block_hash, &logger);
+               let network_graph = NetworkGraph::new(Network::Bitcoin, &logger);
 
                assert_eq!(network_graph.read_only().channels().len(), 0);
 
@@ -338,9 +335,8 @@ mod tests {
                        2, 68, 226, 0, 6, 11, 0, 1, 128,
                ];
 
-               let block_hash = genesis_block(Network::Bitcoin).block_hash();
                let logger = TestLogger::new();
-               let network_graph = NetworkGraph::new(block_hash, &logger);
+               let network_graph = NetworkGraph::new(Network::Bitcoin, &logger);
 
                assert_eq!(network_graph.read_only().channels().len(), 0);
 
@@ -375,9 +371,8 @@ mod tests {
                        0, 1, 0, 0, 0, 125, 255, 2, 68, 226, 0, 6, 11, 0, 1, 5, 0, 0, 0, 0, 29, 129, 25, 192,
                ];
 
-               let block_hash = genesis_block(Network::Bitcoin).block_hash();
                let logger = TestLogger::new();
-               let network_graph = NetworkGraph::new(block_hash, &logger);
+               let network_graph = NetworkGraph::new(Network::Bitcoin, &logger);
 
                assert_eq!(network_graph.read_only().channels().len(), 0);
 
@@ -442,9 +437,8 @@ mod tests {
                        25, 192,
                ];
 
-               let block_hash = genesis_block(Network::Bitcoin).block_hash();
                let logger = TestLogger::new();
-               let network_graph = NetworkGraph::new(block_hash, &logger);
+               let network_graph = NetworkGraph::new(Network::Bitcoin, &logger);
 
                assert_eq!(network_graph.read_only().channels().len(), 0);
 
@@ -502,9 +496,8 @@ mod tests {
                        25, 192,
                ];
 
-               let block_hash = genesis_block(Network::Bitcoin).block_hash();
                let logger = TestLogger::new();
-               let network_graph = NetworkGraph::new(block_hash, &logger);
+               let network_graph = NetworkGraph::new(Network::Bitcoin, &logger);
 
                assert_eq!(network_graph.read_only().channels().len(), 0);
 
@@ -528,9 +521,8 @@ mod tests {
 
        #[test]
        fn full_update_succeeds() {
-               let block_hash = genesis_block(Network::Bitcoin).block_hash();
                let logger = TestLogger::new();
-               let network_graph = NetworkGraph::new(block_hash, &logger);
+               let network_graph = NetworkGraph::new(Network::Bitcoin, &logger);
 
                assert_eq!(network_graph.read_only().channels().len(), 0);
 
@@ -560,9 +552,8 @@ mod tests {
 
        #[test]
        fn full_update_succeeds_at_the_beginning_of_the_unix_era() {
-               let block_hash = genesis_block(Network::Bitcoin).block_hash();
                let logger = TestLogger::new();
-               let network_graph = NetworkGraph::new(block_hash, &logger);
+               let network_graph = NetworkGraph::new(Network::Bitcoin, &logger);
 
                assert_eq!(network_graph.read_only().channels().len(), 0);
 
@@ -576,14 +567,13 @@ mod tests {
        #[test]
        fn timestamp_edge_cases_are_handled_correctly() {
                // this is the timestamp encoded in the binary data of valid_input below
-               let block_hash = genesis_block(Network::Bitcoin).block_hash();
                let logger = TestLogger::new();
 
                let latest_succeeding_time = VALID_BINARY_TIMESTAMP + STALE_RGS_UPDATE_AGE_LIMIT_SECS;
                let earliest_failing_time = latest_succeeding_time + 1;
 
                {
-                       let network_graph = NetworkGraph::new(block_hash, &logger);
+                       let network_graph = NetworkGraph::new(Network::Bitcoin, &logger);
                        assert_eq!(network_graph.read_only().channels().len(), 0);
 
                        let rapid_sync = RapidGossipSync::new(&network_graph);
@@ -593,7 +583,7 @@ mod tests {
                }
 
                {
-                       let network_graph = NetworkGraph::new(block_hash, &logger);
+                       let network_graph = NetworkGraph::new(Network::Bitcoin, &logger);
                        assert_eq!(network_graph.read_only().channels().len(), 0);
 
                        let rapid_sync = RapidGossipSync::new(&network_graph);
@@ -630,9 +620,8 @@ mod tests {
                        0, 0, 1,
                ];
 
-               let block_hash = genesis_block(Network::Bitcoin).block_hash();
                let logger = TestLogger::new();
-               let network_graph = NetworkGraph::new(block_hash, &logger);
+               let network_graph = NetworkGraph::new(Network::Bitcoin, &logger);
                let rapid_sync = RapidGossipSync::new(&network_graph);
                let update_result = rapid_sync.update_network_graph(&unknown_version_input[..]);
 
index 61de296c1442f3096fcb8b88efbd341157c4de6d..3ee4dc2fe221df16481432315e0f1d02e2b8c087 100644 (file)
@@ -8672,13 +8672,12 @@ pub mod bench {
                // Note that this is unrealistic as each payment send will require at least two fsync
                // calls per node.
                let network = bitcoin::Network::Testnet;
-               let genesis_hash = bitcoin::blockdata::constants::genesis_block(network).header.block_hash();
 
                let tx_broadcaster = test_utils::TestBroadcaster{txn_broadcasted: Mutex::new(Vec::new()), blocks: Arc::new(Mutex::new(Vec::new()))};
                let fee_estimator = test_utils::TestFeeEstimator { sat_per_kw: Mutex::new(253) };
                let logger_a = test_utils::TestLogger::with_id("node a".to_owned());
                let scorer = Mutex::new(test_utils::TestScorer::new());
-               let router = test_utils::TestRouter::new(Arc::new(NetworkGraph::new(genesis_hash, &logger_a)), &scorer);
+               let router = test_utils::TestRouter::new(Arc::new(NetworkGraph::new(network, &logger_a)), &scorer);
 
                let mut config: UserConfig = Default::default();
                config.channel_handshake_config.minimum_depth = 1;
@@ -8722,7 +8721,7 @@ pub mod bench {
                assert_eq!(&tx_broadcaster.txn_broadcasted.lock().unwrap()[..], &[tx.clone()]);
 
                let block = Block {
-                       header: BlockHeader { version: 0x20000000, prev_blockhash: genesis_hash, merkle_root: TxMerkleNode::all_zeros(), time: 42, bits: 42, nonce: 42 },
+                       header: BlockHeader { version: 0x20000000, prev_blockhash: BestBlock::from_genesis(network), merkle_root: TxMerkleNode::all_zeros(), time: 42, bits: 42, nonce: 42 },
                        txdata: vec![tx],
                };
                Listen::block_connected(&node_a, &block, 1);
@@ -8761,7 +8760,7 @@ pub mod bench {
                        _ => panic!("Unexpected event"),
                }
 
-               let dummy_graph = NetworkGraph::new(genesis_hash, &logger_a);
+               let dummy_graph = NetworkGraph::new(network, &logger_a);
 
                let mut payment_count: u64 = 0;
                macro_rules! send_payment {
index fd867bc6ab7e07287c0572ae1cdb577e9e290ab8..6274c8bf6e987af88c1be334fa715ffd7ad50ff6 100644 (file)
@@ -2300,7 +2300,7 @@ pub fn create_node_cfgs<'a>(node_count: usize, chanmon_cfgs: &'a Vec<TestChanMon
 
        for i in 0..node_count {
                let chain_monitor = test_utils::TestChainMonitor::new(Some(&chanmon_cfgs[i].chain_source), &chanmon_cfgs[i].tx_broadcaster, &chanmon_cfgs[i].logger, &chanmon_cfgs[i].fee_estimator, &chanmon_cfgs[i].persister, &chanmon_cfgs[i].keys_manager);
-               let network_graph = Arc::new(NetworkGraph::new(chanmon_cfgs[i].chain_source.genesis_hash, &chanmon_cfgs[i].logger));
+               let network_graph = Arc::new(NetworkGraph::new(Network::Testnet, &chanmon_cfgs[i].logger));
                let seed = [i as u8; 32];
                nodes.push(NodeCfg {
                        chain_source: &chanmon_cfgs[i].chain_source,
index d6d2972d0736e3ec642fccee7363e44329560584..25781f36f237ed26cb495c305797091aba100789 100644 (file)
@@ -5280,7 +5280,7 @@ fn test_key_derivation_params() {
        let seed = [42; 32];
        let keys_manager = test_utils::TestKeysInterface::new(&seed, Network::Testnet);
        let chain_monitor = test_utils::TestChainMonitor::new(Some(&chanmon_cfgs[0].chain_source), &chanmon_cfgs[0].tx_broadcaster, &chanmon_cfgs[0].logger, &chanmon_cfgs[0].fee_estimator, &chanmon_cfgs[0].persister, &keys_manager);
-       let network_graph = Arc::new(NetworkGraph::new(chanmon_cfgs[0].chain_source.genesis_hash, &chanmon_cfgs[0].logger));
+       let network_graph = Arc::new(NetworkGraph::new(Network::Testnet, &chanmon_cfgs[0].logger));
        let scorer = Mutex::new(test_utils::TestScorer::new());
        let router = test_utils::TestRouter::new(network_graph.clone(), &scorer);
        let node = NodeCfg { chain_source: &chanmon_cfgs[0].chain_source, logger: &chanmon_cfgs[0].logger, tx_broadcaster: &chanmon_cfgs[0].tx_broadcaster, fee_estimator: &chanmon_cfgs[0].fee_estimator, router, chain_monitor, keys_manager: &keys_manager, network_graph, node_seed: seed, override_init_features: alloc::rc::Rc::new(core::cell::RefCell::new(None)) };
index f252d88ac364e87947ed42c31bef96b5c276375f..361adfaf66c3eab2b4a78678a6d7b5ffe5dfb81c 100644 (file)
@@ -1236,7 +1236,6 @@ impl_writeable_tlv_based_enum_upgradable!(PendingOutboundPayment,
 
 #[cfg(test)]
 mod tests {
-       use bitcoin::blockdata::constants::genesis_block;
        use bitcoin::network::constants::Network;
        use bitcoin::secp256k1::{PublicKey, Secp256k1, SecretKey};
 
@@ -1260,8 +1259,7 @@ mod tests {
        fn do_fails_paying_after_expiration(on_retry: bool) {
                let outbound_payments = OutboundPayments::new();
                let logger = test_utils::TestLogger::new();
-               let genesis_hash = genesis_block(Network::Testnet).header.block_hash();
-               let network_graph = Arc::new(NetworkGraph::new(genesis_hash, &logger));
+               let network_graph = Arc::new(NetworkGraph::new(Network::Testnet, &logger));
                let scorer = Mutex::new(test_utils::TestScorer::new());
                let router = test_utils::TestRouter::new(network_graph, &scorer);
                let secp_ctx = Secp256k1::new();
@@ -1300,8 +1298,7 @@ mod tests {
        fn do_find_route_error(on_retry: bool) {
                let outbound_payments = OutboundPayments::new();
                let logger = test_utils::TestLogger::new();
-               let genesis_hash = genesis_block(Network::Testnet).header.block_hash();
-               let network_graph = Arc::new(NetworkGraph::new(genesis_hash, &logger));
+               let network_graph = Arc::new(NetworkGraph::new(Network::Testnet, &logger));
                let scorer = Mutex::new(test_utils::TestScorer::new());
                let router = test_utils::TestRouter::new(network_graph, &scorer);
                let secp_ctx = Secp256k1::new();
index cf51b6ab52827943626ede2cbc5d0e87e1f95366..2b4ece0ba6bd02d523acd234468f6277d0c73c8e 100644 (file)
@@ -18,6 +18,9 @@ use bitcoin::hashes::sha256d::Hash as Sha256dHash;
 use bitcoin::hashes::Hash;
 use bitcoin::hash_types::BlockHash;
 
+use bitcoin::network::constants::Network;
+use bitcoin::blockdata::constants::genesis_block;
+
 use crate::ln::features::{ChannelFeatures, NodeFeatures, InitFeatures};
 use crate::ln::msgs::{DecodeError, ErrorAction, Init, LightningError, RoutingMessageHandler, NetAddress, MAX_VALUE_MSAT};
 use crate::ln::msgs::{ChannelAnnouncement, ChannelUpdate, NodeAnnouncement, GossipTimestampFilter};
@@ -1265,10 +1268,10 @@ impl<L: Deref> PartialEq for NetworkGraph<L> where L::Target: Logger {
 
 impl<L: Deref> NetworkGraph<L> where L::Target: Logger {
        /// Creates a new, empty, network graph.
-       pub fn new(genesis_hash: BlockHash, logger: L) -> NetworkGraph<L> {
+       pub fn new(network: Network, logger: L) -> NetworkGraph<L> {
                Self {
                        secp_ctx: Secp256k1::verification_only(),
-                       genesis_hash,
+                       genesis_hash: genesis_block(network).header.block_hash(),
                        logger,
                        channels: RwLock::new(IndexedMap::new()),
                        nodes: RwLock::new(IndexedMap::new()),
@@ -1960,9 +1963,8 @@ pub(crate) mod tests {
        use crate::sync::Arc;
 
        fn create_network_graph() -> NetworkGraph<Arc<test_utils::TestLogger>> {
-               let genesis_hash = genesis_block(Network::Testnet).header.block_hash();
                let logger = Arc::new(test_utils::TestLogger::new());
-               NetworkGraph::new(genesis_hash, logger)
+               NetworkGraph::new(Network::Testnet, logger)
        }
 
        fn create_gossip_sync(network_graph: &NetworkGraph<Arc<test_utils::TestLogger>>) -> (
@@ -2137,8 +2139,7 @@ pub(crate) mod tests {
                let valid_announcement = get_signed_channel_announcement(|_| {}, node_1_privkey, node_2_privkey, &secp_ctx);
 
                // Test if the UTXO lookups were not supported
-               let genesis_hash = genesis_block(Network::Testnet).header.block_hash();
-               let network_graph = NetworkGraph::new(genesis_hash, &logger);
+               let network_graph = NetworkGraph::new(Network::Testnet, &logger);
                let mut gossip_sync = P2PGossipSync::new(&network_graph, None, &logger);
                match gossip_sync.handle_channel_announcement(&valid_announcement) {
                        Ok(res) => assert!(res),
@@ -2162,7 +2163,7 @@ pub(crate) mod tests {
                // Test if an associated transaction were not on-chain (or not confirmed).
                let chain_source = test_utils::TestChainSource::new(Network::Testnet);
                *chain_source.utxo_ret.lock().unwrap() = UtxoResult::Sync(Err(UtxoLookupError::UnknownTx));
-               let network_graph = NetworkGraph::new(genesis_hash, &logger);
+               let network_graph = NetworkGraph::new(Network::Testnet, &logger);
                gossip_sync = P2PGossipSync::new(&network_graph, Some(&chain_source), &logger);
 
                let valid_announcement = get_signed_channel_announcement(|unsigned_announcement| {
@@ -2255,8 +2256,7 @@ pub(crate) mod tests {
                let secp_ctx = Secp256k1::new();
                let logger = test_utils::TestLogger::new();
                let chain_source = test_utils::TestChainSource::new(Network::Testnet);
-               let genesis_hash = genesis_block(Network::Testnet).header.block_hash();
-               let network_graph = NetworkGraph::new(genesis_hash, &logger);
+               let network_graph = NetworkGraph::new(Network::Testnet, &logger);
                let gossip_sync = P2PGossipSync::new(&network_graph, Some(&chain_source), &logger);
 
                let node_1_privkey = &SecretKey::from_slice(&[42; 32]).unwrap();
@@ -2358,8 +2358,7 @@ pub(crate) mod tests {
        #[test]
        fn handling_network_update() {
                let logger = test_utils::TestLogger::new();
-               let genesis_hash = genesis_block(Network::Testnet).header.block_hash();
-               let network_graph = NetworkGraph::new(genesis_hash, &logger);
+               let network_graph = NetworkGraph::new(Network::Testnet, &logger);
                let secp_ctx = Secp256k1::new();
 
                let node_1_privkey = &SecretKey::from_slice(&[42; 32]).unwrap();
@@ -2424,7 +2423,7 @@ pub(crate) mod tests {
 
                {
                        // Get a new network graph since we don't want to track removed nodes in this test with "std"
-                       let network_graph = NetworkGraph::new(genesis_hash, &logger);
+                       let network_graph = NetworkGraph::new(Network::Testnet, &logger);
 
                        // Announce a channel to test permanent node failure
                        let valid_channel_announcement = get_signed_channel_announcement(|_| {}, node_1_privkey, node_2_privkey, &secp_ctx);
@@ -2459,8 +2458,7 @@ pub(crate) mod tests {
                // Test the removal of channels with `remove_stale_channels_and_tracking`.
                let logger = test_utils::TestLogger::new();
                let chain_source = test_utils::TestChainSource::new(Network::Testnet);
-               let genesis_hash = genesis_block(Network::Testnet).header.block_hash();
-               let network_graph = NetworkGraph::new(genesis_hash, &logger);
+               let network_graph = NetworkGraph::new(Network::Testnet, &logger);
                let gossip_sync = P2PGossipSync::new(&network_graph, Some(&chain_source), &logger);
                let secp_ctx = Secp256k1::new();
 
index b4e2b138433648d9218ce0e8977cb85f4d9197a8..b456e15a2d13cdce9b6090889e1e886ae17a997c 100644 (file)
@@ -3256,9 +3256,8 @@ mod tests {
                let scorer = ln_test_utils::TestScorer::new();
                let keys_manager = ln_test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
                let random_seed_bytes = keys_manager.get_secure_random_bytes();
-               let genesis_hash = genesis_block(Network::Testnet).header.block_hash();
                let logger = ln_test_utils::TestLogger::new();
-               let network_graph = NetworkGraph::new(genesis_hash, &logger);
+               let network_graph = NetworkGraph::new(Network::Testnet, &logger);
                let route = get_route(&source_node_id, &payment_params, &network_graph.read_only(),
                                Some(&our_chans.iter().collect::<Vec<_>>()), route_val, 42, &logger, &scorer, &random_seed_bytes);
                route
@@ -4690,9 +4689,8 @@ mod tests {
                // payment) htlc_minimum_msat. In the original algorithm, this resulted in node4's
                // "previous hop" being set to node 3, creating a loop in the path.
                let secp_ctx = Secp256k1::new();
-               let genesis_hash = genesis_block(Network::Testnet).header.block_hash();
                let logger = Arc::new(ln_test_utils::TestLogger::new());
-               let network = Arc::new(NetworkGraph::new(genesis_hash, Arc::clone(&logger)));
+               let network = Arc::new(NetworkGraph::new(Network::Testnet, Arc::clone(&logger)));
                let gossip_sync = P2PGossipSync::new(Arc::clone(&network), None, Arc::clone(&logger));
                let (our_privkey, our_id, privkeys, nodes) = get_nodes(&secp_ctx);
                let scorer = ln_test_utils::TestScorer::new();
@@ -4958,9 +4956,8 @@ mod tests {
                // route over multiple channels with the same first hop.
                let secp_ctx = Secp256k1::new();
                let (_, our_id, _, nodes) = get_nodes(&secp_ctx);
-               let genesis_hash = genesis_block(Network::Testnet).header.block_hash();
                let logger = Arc::new(ln_test_utils::TestLogger::new());
-               let network_graph = NetworkGraph::new(genesis_hash, Arc::clone(&logger));
+               let network_graph = NetworkGraph::new(Network::Testnet, Arc::clone(&logger));
                let scorer = ln_test_utils::TestScorer::new();
                let config = UserConfig::default();
                let payment_params = PaymentParameters::from_node_id(nodes[0], 42).with_features(channelmanager::provided_invoice_features(&config));
index 7504e0840d2683125cf75144fd445b070c6f08da..31158d41bc37570b7f95a98b5fb48bb9b68ea52d 100644 (file)
@@ -1759,8 +1759,7 @@ mod tests {
        }
 
        fn network_graph(logger: &TestLogger) -> NetworkGraph<&TestLogger> {
-               let genesis_hash = genesis_block(Network::Testnet).header.block_hash();
-               let mut network_graph = NetworkGraph::new(genesis_hash, logger);
+               let mut network_graph = NetworkGraph::new(Network::Testnet, logger);
                add_channel(&mut network_graph, 42, source_privkey(), target_privkey());
                add_channel(&mut network_graph, 43, target_privkey(), recipient_privkey());
 
@@ -2226,8 +2225,7 @@ mod tests {
                // we do not score such channels.
                let secp_ctx = Secp256k1::new();
                let logger = TestLogger::new();
-               let genesis_hash = genesis_block(Network::Testnet).header.block_hash();
-               let mut network_graph = NetworkGraph::new(genesis_hash, &logger);
+               let mut network_graph = NetworkGraph::new(Network::Testnet, &logger);
                let secret_a = SecretKey::from_slice(&[42; 32]).unwrap();
                let secret_b = SecretKey::from_slice(&[43; 32]).unwrap();
                let secret_c = SecretKey::from_slice(&[44; 32]).unwrap();
index b737bab352441a1b2a9289cc143e078ba6384c97..68264207f589e249fd90bde0a6d00298c2621b74 100644 (file)
@@ -141,8 +141,7 @@ pub(super) fn build_line_graph() -> (
        let secp_ctx = Secp256k1::new();
        let logger = Arc::new(test_utils::TestLogger::new());
        let chain_monitor = Arc::new(test_utils::TestChainSource::new(Network::Testnet));
-       let genesis_hash = genesis_block(Network::Testnet).header.block_hash();
-       let network_graph = Arc::new(NetworkGraph::new(genesis_hash, Arc::clone(&logger)));
+       let network_graph = Arc::new(NetworkGraph::new(Network::Testnet, Arc::clone(&logger)));
        let gossip_sync = P2PGossipSync::new(Arc::clone(&network_graph), None, Arc::clone(&logger));
 
        // Build network from our_id to node 19:
@@ -195,8 +194,7 @@ pub(super) fn build_graph() -> (
        let secp_ctx = Secp256k1::new();
        let logger = Arc::new(test_utils::TestLogger::new());
        let chain_monitor = Arc::new(test_utils::TestChainSource::new(Network::Testnet));
-       let genesis_hash = genesis_block(Network::Testnet).header.block_hash();
-       let network_graph = Arc::new(NetworkGraph::new(genesis_hash, Arc::clone(&logger)));
+       let network_graph = Arc::new(NetworkGraph::new(Network::Testnet, Arc::clone(&logger)));
        let gossip_sync = P2PGossipSync::new(Arc::clone(&network_graph), None, Arc::clone(&logger));
        // Build network from our_id to node6:
        //
index 020993f23fb809c250084afe78ec9fad19fbbaad..0e5bd8d64f78a48a9ec5b808aa200a022167edb6 100644 (file)
@@ -561,16 +561,14 @@ mod tests {
        use crate::util::test_utils::{TestChainSource, TestLogger};
        use crate::ln::msgs;
 
-       use bitcoin::blockdata::constants::genesis_block;
        use bitcoin::secp256k1::{Secp256k1, SecretKey};
 
        use core::sync::atomic::Ordering;
 
        fn get_network() -> (TestChainSource, NetworkGraph<Box<TestLogger>>) {
                let logger = Box::new(TestLogger::new());
-               let genesis_hash = genesis_block(bitcoin::Network::Testnet).header.block_hash();
                let chain_source = TestChainSource::new(bitcoin::Network::Testnet);
-               let network_graph = NetworkGraph::new(genesis_hash, logger);
+               let network_graph = NetworkGraph::new(bitcoin::Network::Testnet, logger);
 
                (chain_source, network_graph)
        }