// 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);
// 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);
}
use bitcoin::hashes::Hash;
use bitcoin::secp256k1::PublicKey;
use bitcoin::network::constants::Network;
-use bitcoin::blockdata::constants::genesis_block;
use crate::utils::test_logger;
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,
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()));
//! # }
//! # 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);
mod tests {
use std::fs;
- use bitcoin::blockdata::constants::genesis_block;
use bitcoin::Network;
use lightning::ln::msgs::DecodeError;
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);
#[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);
pub mod bench {
use test::Bencher;
- use bitcoin::blockdata::constants::genesis_block;
use bitcoin::Network;
use lightning::ln::msgs::DecodeError;
#[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 {
#[cfg(test)]
mod tests {
- use bitcoin::blockdata::constants::genesis_block;
use bitcoin::Network;
use lightning::ln::msgs::DecodeError;
#[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,
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);
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);
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);
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);
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);
#[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);
#[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);
#[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);
}
{
- 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);
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[..]);
// 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;
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);
_ => 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 {
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,
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)) };
#[cfg(test)]
mod tests {
- use bitcoin::blockdata::constants::genesis_block;
use bitcoin::network::constants::Network;
use bitcoin::secp256k1::{PublicKey, Secp256k1, SecretKey};
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();
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();
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};
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()),
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>>) -> (
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),
// 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| {
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();
#[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();
{
// 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);
// 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();
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
// 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();
// 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));
}
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());
// 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();
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:
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:
//
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)
}