EnforcingSigner,
Arc<chainmonitor::ChainMonitor<EnforcingSigner, Arc<dyn chain::Filter>, Arc<TestBroadcaster>, Arc<FuzzEstimator>, Arc<dyn Logger>, Arc<TestPersister>>>,
Arc<TestBroadcaster>, Arc<KeyProvider>, Arc<FuzzEstimator>, Arc<dyn Logger>>;
-type PeerMan<'a> = PeerManager<Peer<'a>, Arc<ChannelMan>, Arc<NetGraphMsgHandler<Arc<dyn chain::Access>, Arc<dyn Logger>>>, Arc<dyn Logger>, IgnoringMessageHandler>;
+type PeerMan<'a> = PeerManager<Peer<'a>, Arc<ChannelMan>, Arc<NetGraphMsgHandler<Arc<NetworkGraph>, Arc<dyn chain::Access>, Arc<dyn Logger>>>, Arc<dyn Logger>, IgnoringMessageHandler>;
struct MoneyLossDetector<'a> {
manager: Arc<ChannelMan>,
};
let channelmanager = Arc::new(ChannelManager::new(fee_est.clone(), monitor.clone(), broadcast.clone(), Arc::clone(&logger), keys_manager.clone(), config, params));
let our_id = PublicKey::from_secret_key(&Secp256k1::signing_only(), &keys_manager.get_node_secret());
- let network_graph = NetworkGraph::new(genesis_block(network).block_hash());
+ let network_graph = Arc::new(NetworkGraph::new(genesis_block(network).block_hash()));
let net_graph_msg_handler = Arc::new(NetGraphMsgHandler::new(network_graph, None, Arc::clone(&logger)));
let scorer = Scorer::with_fixed_penalty(0);
use lightning::ln::channelmanager::ChannelManager;
use lightning::ln::msgs::{ChannelMessageHandler, RoutingMessageHandler};
use lightning::ln::peer_handler::{CustomMessageHandler, PeerManager, SocketDescriptor};
-use lightning::routing::network_graph::NetGraphMsgHandler;
+use lightning::routing::network_graph::{NetworkGraph, NetGraphMsgHandler};
use lightning::util::events::{Event, EventHandler, EventsProvider};
use lightning::util::logger::Logger;
use std::sync::Arc;
/// Decorates an [`EventHandler`] with common functionality provided by standard [`EventHandler`]s.
struct DecoratingEventHandler<
E: EventHandler,
- N: Deref<Target = NetGraphMsgHandler<A, L>>,
+ N: Deref<Target = NetGraphMsgHandler<G, A, L>>,
+ G: Deref<Target = NetworkGraph>,
A: Deref,
L: Deref,
>
impl<
E: EventHandler,
- N: Deref<Target = NetGraphMsgHandler<A, L>>,
+ N: Deref<Target = NetGraphMsgHandler<G, A, L>>,
+ G: Deref<Target = NetworkGraph>,
A: Deref,
L: Deref,
-> EventHandler for DecoratingEventHandler<E, N, A, L>
+> EventHandler for DecoratingEventHandler<E, N, G, A, L>
where A::Target: chain::Access, L::Target: Logger {
fn handle_event(&self, event: &Event) {
if let Some(event_handler) = &self.net_graph_msg_handler {
T: 'static + Deref + Send + Sync,
K: 'static + Deref + Send + Sync,
F: 'static + Deref + Send + Sync,
+ G: 'static + Deref<Target = NetworkGraph> + Send + Sync,
L: 'static + Deref + Send + Sync,
P: 'static + Deref + Send + Sync,
Descriptor: 'static + SocketDescriptor + Send + Sync,
CMP: 'static + Send + ChannelManagerPersister<Signer, CW, T, K, F, L>,
M: 'static + Deref<Target = ChainMonitor<Signer, CF, T, F, L, P>> + Send + Sync,
CM: 'static + Deref<Target = ChannelManager<Signer, CW, T, K, F, L>> + Send + Sync,
- NG: 'static + Deref<Target = NetGraphMsgHandler<CA, L>> + Send + Sync,
+ NG: 'static + Deref<Target = NetGraphMsgHandler<G, CA, L>> + Send + Sync,
UMH: 'static + Deref + Send + Sync,
PM: 'static + Deref<Target = PeerManager<Descriptor, CMH, RMH, L, UMH>> + Send + Sync,
>(
struct Node {
node: Arc<SimpleArcChannelManager<ChainMonitor, test_utils::TestBroadcaster, test_utils::TestFeeEstimator, test_utils::TestLogger>>,
- net_graph_msg_handler: Option<Arc<NetGraphMsgHandler<Arc<test_utils::TestChainSource>, Arc<test_utils::TestLogger>>>>,
+ net_graph_msg_handler: Option<Arc<NetGraphMsgHandler<Arc<NetworkGraph>, Arc<test_utils::TestChainSource>, Arc<test_utils::TestLogger>>>>,
peer_manager: Arc<PeerManager<TestDescriptor, Arc<test_utils::TestChannelMessageHandler>, Arc<test_utils::TestRoutingMessageHandler>, Arc<test_utils::TestLogger>, IgnoringMessageHandler>>,
chain_monitor: Arc<ChainMonitor>,
persister: Arc<FilesystemPersister>,
tx_broadcaster: Arc<test_utils::TestBroadcaster>,
+ network_graph: Arc<NetworkGraph>,
logger: Arc<test_utils::TestLogger>,
best_block: BestBlock,
}
let best_block = BestBlock::from_genesis(network);
let params = ChainParameters { network, best_block };
let manager = Arc::new(ChannelManager::new(fee_estimator.clone(), chain_monitor.clone(), tx_broadcaster.clone(), logger.clone(), keys_manager.clone(), UserConfig::default(), params));
- let network_graph = NetworkGraph::new(genesis_block.header.block_hash());
- let net_graph_msg_handler = Some(Arc::new(NetGraphMsgHandler::new(network_graph, Some(chain_source.clone()), logger.clone())));
+ let network_graph = Arc::new(NetworkGraph::new(genesis_block.header.block_hash()));
+ let net_graph_msg_handler = Some(Arc::new(NetGraphMsgHandler::new(network_graph.clone(), Some(chain_source.clone()), logger.clone())));
let msg_handler = MessageHandler { chan_handler: Arc::new(test_utils::TestChannelMessageHandler::new()), route_handler: Arc::new(test_utils::TestRoutingMessageHandler::new() )};
let peer_manager = Arc::new(PeerManager::new(msg_handler, keys_manager.get_node_secret(), &seed, logger.clone(), IgnoringMessageHandler{}));
- let node = Node { node: manager, net_graph_msg_handler, peer_manager, chain_monitor, persister, tx_broadcaster, logger, best_block };
+ let node = Node { node: manager, net_graph_msg_handler, peer_manager, chain_monitor, persister, tx_broadcaster, network_graph, logger, best_block };
nodes.push(node);
}
// Initiate the background processors to watch each node.
let data_dir = nodes[0].persister.get_data_dir();
let persister = move |node: &ChannelManager<InMemorySigner, Arc<ChainMonitor>, Arc<test_utils::TestBroadcaster>, Arc<KeysManager>, Arc<test_utils::TestFeeEstimator>, Arc<test_utils::TestLogger>>| FilesystemPersister::persist_manager(data_dir.clone(), node);
- let network_graph = Arc::new(NetworkGraph::new(genesis_block(Network::Testnet).header.block_hash()));
- let router = DefaultRouter::new(network_graph, Arc::clone(&nodes[0].logger));
+ let router = DefaultRouter::new(Arc::clone(&nodes[0].network_graph), Arc::clone(&nodes[0].logger));
let scorer = Arc::new(Mutex::new(Scorer::default()));
let invoice_payer = Arc::new(InvoicePayer::new(Arc::clone(&nodes[0].node), router, scorer, Arc::clone(&nodes[0].logger), |_: &_| {}, RetryAttempts(2)));
let event_handler = Arc::clone(&invoice_payer);
pub persister: test_utils::TestPersister,
pub logger: test_utils::TestLogger,
pub keys_manager: test_utils::TestKeysInterface,
+ pub network_graph: NetworkGraph,
}
pub struct NodeCfg<'a> {
pub chain_monitor: test_utils::TestChainMonitor<'a>,
pub keys_manager: &'a test_utils::TestKeysInterface,
pub logger: &'a test_utils::TestLogger,
+ pub network_graph: &'a NetworkGraph,
pub node_seed: [u8; 32],
pub features: InitFeatures,
}
pub chain_monitor: &'b test_utils::TestChainMonitor<'c>,
pub keys_manager: &'b test_utils::TestKeysInterface,
pub node: &'a ChannelManager<EnforcingSigner, &'b TestChainMonitor<'c>, &'c test_utils::TestBroadcaster, &'b test_utils::TestKeysInterface, &'c test_utils::TestFeeEstimator, &'c test_utils::TestLogger>,
- pub net_graph_msg_handler: NetGraphMsgHandler<&'c test_utils::TestChainSource, &'c test_utils::TestLogger>,
+ pub network_graph: &'c NetworkGraph,
+ pub net_graph_msg_handler: NetGraphMsgHandler<&'c NetworkGraph, &'c test_utils::TestChainSource, &'c test_utils::TestLogger>,
pub node_seed: [u8; 32],
pub network_payment_count: Rc<RefCell<u8>>,
pub network_chan_count: Rc<RefCell<u32>>,
let network_graph_ser = &self.net_graph_msg_handler.network_graph;
network_graph_ser.write(&mut w).unwrap();
let network_graph_deser = <NetworkGraph>::read(&mut io::Cursor::new(&w.0)).unwrap();
- assert!(network_graph_deser == self.net_graph_msg_handler.network_graph);
+ assert!(network_graph_deser == *self.net_graph_msg_handler.network_graph);
let net_graph_msg_handler = NetGraphMsgHandler::new(
- network_graph_deser, Some(self.chain_source), self.logger
+ &network_graph_deser, Some(self.chain_source), self.logger
);
let mut chan_progress = 0;
loop {
let persister = test_utils::TestPersister::new();
let seed = [i as u8; 32];
let keys_manager = test_utils::TestKeysInterface::new(&seed, Network::Testnet);
+ let network_graph = NetworkGraph::new(chain_source.genesis_hash);
- chan_mon_cfgs.push(TestChanMonCfg{ tx_broadcaster, fee_estimator, chain_source, logger, persister, keys_manager });
+ chan_mon_cfgs.push(TestChanMonCfg{ tx_broadcaster, fee_estimator, chain_source, logger, persister, keys_manager, network_graph });
}
chan_mon_cfgs
keys_manager: &chanmon_cfgs[i].keys_manager,
node_seed: seed,
features: InitFeatures::known(),
+ network_graph: &chanmon_cfgs[i].network_graph,
});
}
let connect_style = Rc::new(RefCell::new(ConnectStyle::FullBlockViaListen));
for i in 0..node_count {
- let network_graph = NetworkGraph::new(cfgs[i].chain_source.genesis_hash);
- let net_graph_msg_handler = NetGraphMsgHandler::new(network_graph, None, cfgs[i].logger);
- nodes.push(Node{ chain_source: cfgs[i].chain_source,
- tx_broadcaster: cfgs[i].tx_broadcaster, chain_monitor: &cfgs[i].chain_monitor,
- keys_manager: &cfgs[i].keys_manager, node: &chan_mgrs[i], net_graph_msg_handler,
- node_seed: cfgs[i].node_seed, network_chan_count: chan_count.clone(),
- network_payment_count: payment_count.clone(), logger: cfgs[i].logger,
- blocks: Arc::clone(&cfgs[i].tx_broadcaster.blocks),
- connect_style: Rc::clone(&connect_style),
+ let net_graph_msg_handler = NetGraphMsgHandler::new(cfgs[i].network_graph, None, cfgs[i].logger);
+ nodes.push(Node{
+ chain_source: cfgs[i].chain_source, tx_broadcaster: cfgs[i].tx_broadcaster,
+ chain_monitor: &cfgs[i].chain_monitor, keys_manager: &cfgs[i].keys_manager,
+ node: &chan_mgrs[i], network_graph: &cfgs[i].network_graph, net_graph_msg_handler,
+ node_seed: cfgs[i].node_seed, network_chan_count: chan_count.clone(),
+ network_payment_count: payment_count.clone(), logger: cfgs[i].logger,
+ blocks: Arc::clone(&cfgs[i].tx_broadcaster.blocks),
+ connect_style: Rc::clone(&connect_style),
})
}
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 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, chain_monitor, keys_manager: &keys_manager, node_seed: seed, features: InitFeatures::known() };
+ 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, chain_monitor, keys_manager: &keys_manager, network_graph: &chanmon_cfgs[0].network_graph, node_seed: seed, features: InitFeatures::known() };
let mut node_cfgs = create_node_cfgs(3, &chanmon_cfgs);
node_cfgs.remove(0);
node_cfgs.insert(0, node);
use util::atomic_counter::AtomicCounter;
use util::events::{MessageSendEvent, MessageSendEventsProvider};
use util::logger::Logger;
-use routing::network_graph::NetGraphMsgHandler;
+use routing::network_graph::{NetworkGraph, NetGraphMsgHandler};
use prelude::*;
use io;
/// lifetimes). Other times you can afford a reference, which is more efficient, in which case
/// SimpleRefPeerManager is the more appropriate type. Defining these type aliases prevents
/// issues such as overly long function definitions.
-pub type SimpleArcPeerManager<SD, M, T, F, C, L> = PeerManager<SD, Arc<SimpleArcChannelManager<M, T, F, L>>, Arc<NetGraphMsgHandler<Arc<C>, Arc<L>>>, Arc<L>, Arc<IgnoringMessageHandler>>;
+pub type SimpleArcPeerManager<SD, M, T, F, C, L> = PeerManager<SD, Arc<SimpleArcChannelManager<M, T, F, L>>, Arc<NetGraphMsgHandler<Arc<NetworkGraph>, Arc<C>, Arc<L>>>, Arc<L>, Arc<IgnoringMessageHandler>>;
/// SimpleRefPeerManager is a type alias for a PeerManager reference, and is the reference
/// counterpart to the SimpleArcPeerManager type alias. Use this type by default when you don't
/// usage of lightning-net-tokio (since tokio::spawn requires parameters with static lifetimes).
/// But if this is not necessary, using a reference is more efficient. Defining these type aliases
/// helps with issues such as long function definitions.
-pub type SimpleRefPeerManager<'a, 'b, 'c, 'd, 'e, 'f, 'g, SD, M, T, F, C, L> = PeerManager<SD, SimpleRefChannelManager<'a, 'b, 'c, 'd, 'e, M, T, F, L>, &'e NetGraphMsgHandler<&'g C, &'f L>, &'f L, IgnoringMessageHandler>;
+pub type SimpleRefPeerManager<'a, 'b, 'c, 'd, 'e, 'f, 'g, 'h, SD, M, T, F, C, L> = PeerManager<SD, SimpleRefChannelManager<'a, 'b, 'c, 'd, 'e, M, T, F, L>, &'e NetGraphMsgHandler<&'g NetworkGraph, &'h C, &'f L>, &'f L, IgnoringMessageHandler>;
/// A PeerManager manages a set of peers, described by their [`SocketDescriptor`] and marshalls
/// socket events into messages which it passes on to its [`MessageHandler`].
},
);
-impl<C: Deref, L: Deref> EventHandler for NetGraphMsgHandler<C, L>
+impl<G: Deref<Target=NetworkGraph>, C: Deref, L: Deref> EventHandler for NetGraphMsgHandler<G, C, L>
where C::Target: chain::Access, L::Target: Logger {
fn handle_event(&self, event: &Event) {
if let Event::PaymentPathFailed { payment_hash: _, rejected_by_dest: _, network_update, .. } = event {
///
/// Serves as an [`EventHandler`] for applying updates from [`Event::PaymentPathFailed`] to the
/// [`NetworkGraph`].
-pub struct NetGraphMsgHandler<C: Deref, L: Deref>
+pub struct NetGraphMsgHandler<G: Deref<Target=NetworkGraph>, C: Deref, L: Deref>
where C::Target: chain::Access, L::Target: Logger
{
secp_ctx: Secp256k1<secp256k1::VerifyOnly>,
/// Representation of the payment channel network
- pub network_graph: NetworkGraph,
+ pub network_graph: G,
chain_access: Option<C>,
full_syncs_requested: AtomicUsize,
pending_events: Mutex<Vec<MessageSendEvent>>,
logger: L,
}
-impl<C: Deref, L: Deref> NetGraphMsgHandler<C, L>
+impl<G: Deref<Target=NetworkGraph>, C: Deref, L: Deref> NetGraphMsgHandler<G, C, L>
where C::Target: chain::Access, L::Target: Logger
{
/// Creates a new tracker of the actual state of the network of channels and nodes,
/// Chain monitor is used to make sure announced channels exist on-chain,
/// channel data is correct, and that the announcement is signed with
/// channel owners' keys.
- pub fn new(network_graph: NetworkGraph, chain_access: Option<C>, logger: L) -> Self {
+ pub fn new(network_graph: G, chain_access: Option<C>, logger: L) -> Self {
NetGraphMsgHandler {
secp_ctx: Secp256k1::verification_only(),
network_graph,
};
}
-impl<C: Deref, L: Deref> RoutingMessageHandler for NetGraphMsgHandler<C, L>
+impl<G: Deref<Target=NetworkGraph>, C: Deref, L: Deref> RoutingMessageHandler for NetGraphMsgHandler<G, C, L>
where C::Target: chain::Access, L::Target: Logger
{
fn handle_node_announcement(&self, msg: &msgs::NodeAnnouncement) -> Result<bool, LightningError> {
}
}
-impl<C: Deref, L: Deref> MessageSendEventsProvider for NetGraphMsgHandler<C, L>
+impl<G: Deref<Target=NetworkGraph>, C: Deref, L: Deref> MessageSendEventsProvider for NetGraphMsgHandler<G, C, L>
where
C::Target: chain::Access,
L::Target: Logger,
use prelude::*;
use sync::Arc;
- fn create_net_graph_msg_handler() -> (Secp256k1<All>, NetGraphMsgHandler<Arc<test_utils::TestChainSource>, Arc<test_utils::TestLogger>>) {
+ fn create_network_graph() -> NetworkGraph {
+ let genesis_hash = genesis_block(Network::Testnet).header.block_hash();
+ NetworkGraph::new(genesis_hash)
+ }
+
+ fn create_net_graph_msg_handler(network_graph: &NetworkGraph) -> (
+ Secp256k1<All>, NetGraphMsgHandler<&NetworkGraph, Arc<test_utils::TestChainSource>, Arc<test_utils::TestLogger>>
+ ) {
let secp_ctx = Secp256k1::new();
let logger = Arc::new(test_utils::TestLogger::new());
- let genesis_hash = genesis_block(Network::Testnet).header.block_hash();
- let network_graph = NetworkGraph::new(genesis_hash);
let net_graph_msg_handler = NetGraphMsgHandler::new(network_graph, None, Arc::clone(&logger));
(secp_ctx, net_graph_msg_handler)
}
#[test]
fn request_full_sync_finite_times() {
- let (secp_ctx, net_graph_msg_handler) = create_net_graph_msg_handler();
+ let network_graph = create_network_graph();
+ let (secp_ctx, net_graph_msg_handler) = create_net_graph_msg_handler(&network_graph);
let node_id = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&hex::decode("0202020202020202020202020202020202020202020202020202020202020202").unwrap()[..]).unwrap());
assert!(net_graph_msg_handler.should_request_full_sync(&node_id));
#[test]
fn handling_node_announcements() {
- let (secp_ctx, net_graph_msg_handler) = create_net_graph_msg_handler();
+ let network_graph = create_network_graph();
+ let (secp_ctx, net_graph_msg_handler) = create_net_graph_msg_handler(&network_graph);
let node_1_privkey = &SecretKey::from_slice(&[42; 32]).unwrap();
let node_2_privkey = &SecretKey::from_slice(&[41; 32]).unwrap();
// Test if the UTXO lookups were not supported
let network_graph = NetworkGraph::new(genesis_block(Network::Testnet).header.block_hash());
- let mut net_graph_msg_handler = NetGraphMsgHandler::new(network_graph, None, Arc::clone(&logger));
+ let mut net_graph_msg_handler = NetGraphMsgHandler::new(&network_graph, None, Arc::clone(&logger));
match net_graph_msg_handler.handle_channel_announcement(&valid_announcement) {
Ok(res) => assert!(res),
_ => panic!()
};
{
- let network = &net_graph_msg_handler.network_graph;
- match network.read_only().channels().get(&unsigned_announcement.short_channel_id) {
+ match network_graph.read_only().channels().get(&unsigned_announcement.short_channel_id) {
None => panic!(),
Some(_) => ()
};
let chain_source = Arc::new(test_utils::TestChainSource::new(Network::Testnet));
*chain_source.utxo_ret.lock().unwrap() = Err(chain::AccessError::UnknownTx);
let network_graph = NetworkGraph::new(genesis_block(Network::Testnet).header.block_hash());
- net_graph_msg_handler = NetGraphMsgHandler::new(network_graph, Some(chain_source.clone()), Arc::clone(&logger));
+ net_graph_msg_handler = NetGraphMsgHandler::new(&network_graph, Some(chain_source.clone()), Arc::clone(&logger));
unsigned_announcement.short_channel_id += 1;
msghash = hash_to_message!(&Sha256dHash::hash(&unsigned_announcement.encode()[..])[..]);
};
{
- let network = &net_graph_msg_handler.network_graph;
- match network.read_only().channels().get(&unsigned_announcement.short_channel_id) {
+ match network_graph.read_only().channels().get(&unsigned_announcement.short_channel_id) {
None => panic!(),
Some(_) => ()
};
_ => panic!()
};
{
- let network = &net_graph_msg_handler.network_graph;
- match network.read_only().channels().get(&unsigned_announcement.short_channel_id) {
+ match network_graph.read_only().channels().get(&unsigned_announcement.short_channel_id) {
Some(channel_entry) => {
assert_eq!(channel_entry.features, ChannelFeatures::empty());
},
let logger: Arc<Logger> = Arc::new(test_utils::TestLogger::new());
let chain_source = Arc::new(test_utils::TestChainSource::new(Network::Testnet));
let network_graph = NetworkGraph::new(genesis_block(Network::Testnet).header.block_hash());
- let net_graph_msg_handler = NetGraphMsgHandler::new(network_graph, Some(chain_source.clone()), Arc::clone(&logger));
+ let net_graph_msg_handler = NetGraphMsgHandler::new(&network_graph, Some(chain_source.clone()), Arc::clone(&logger));
let node_1_privkey = &SecretKey::from_slice(&[42; 32]).unwrap();
let node_2_privkey = &SecretKey::from_slice(&[41; 32]).unwrap();
};
{
- let network = &net_graph_msg_handler.network_graph;
- match network.read_only().channels().get(&short_channel_id) {
+ match network_graph.read_only().channels().get(&short_channel_id) {
None => panic!(),
Some(channel_info) => {
assert_eq!(channel_info.one_to_two.as_ref().unwrap().cltv_expiry_delta, 144);
let chain_source = Arc::new(test_utils::TestChainSource::new(Network::Testnet));
let genesis_hash = genesis_block(Network::Testnet).header.block_hash();
let network_graph = NetworkGraph::new(genesis_hash);
- let net_graph_msg_handler = NetGraphMsgHandler::new(network_graph, Some(chain_source.clone()), &logger);
+ let net_graph_msg_handler = NetGraphMsgHandler::new(&network_graph, Some(chain_source.clone()), &logger);
let secp_ctx = Secp256k1::new();
let node_1_privkey = &SecretKey::from_slice(&[42; 32]).unwrap();
let short_channel_id = 0;
let chain_hash = genesis_block(Network::Testnet).header.block_hash();
- let network_graph = &net_graph_msg_handler.network_graph;
{
// There is no nodes in the table at the beginning.
#[test]
fn getting_next_channel_announcements() {
- let (secp_ctx, net_graph_msg_handler) = create_net_graph_msg_handler();
+ let network_graph = create_network_graph();
+ let (secp_ctx, net_graph_msg_handler) = create_net_graph_msg_handler(&network_graph);
let node_1_privkey = &SecretKey::from_slice(&[42; 32]).unwrap();
let node_2_privkey = &SecretKey::from_slice(&[41; 32]).unwrap();
let node_id_1 = PublicKey::from_secret_key(&secp_ctx, node_1_privkey);
#[test]
fn getting_next_node_announcements() {
- let (secp_ctx, net_graph_msg_handler) = create_net_graph_msg_handler();
+ let network_graph = create_network_graph();
+ let (secp_ctx, net_graph_msg_handler) = create_net_graph_msg_handler(&network_graph);
let node_1_privkey = &SecretKey::from_slice(&[42; 32]).unwrap();
let node_2_privkey = &SecretKey::from_slice(&[41; 32]).unwrap();
let node_id_1 = PublicKey::from_secret_key(&secp_ctx, node_1_privkey);
#[test]
fn network_graph_serialization() {
- let (secp_ctx, net_graph_msg_handler) = create_net_graph_msg_handler();
+ let network_graph = create_network_graph();
+ let (secp_ctx, net_graph_msg_handler) = create_net_graph_msg_handler(&network_graph);
let node_1_privkey = &SecretKey::from_slice(&[42; 32]).unwrap();
let node_2_privkey = &SecretKey::from_slice(&[41; 32]).unwrap();
Err(_) => panic!()
};
- let network = &net_graph_msg_handler.network_graph;
let mut w = test_utils::TestVecWriter(Vec::new());
- assert!(!network.read_only().nodes().is_empty());
- assert!(!network.read_only().channels().is_empty());
- network.write(&mut w).unwrap();
- assert!(<NetworkGraph>::read(&mut io::Cursor::new(&w.0)).unwrap() == *network);
+ assert!(!network_graph.read_only().nodes().is_empty());
+ assert!(!network_graph.read_only().channels().is_empty());
+ network_graph.write(&mut w).unwrap();
+ assert!(<NetworkGraph>::read(&mut io::Cursor::new(&w.0)).unwrap() == network_graph);
}
#[test]
fn calling_sync_routing_table() {
- let (secp_ctx, net_graph_msg_handler) = create_net_graph_msg_handler();
+ let network_graph = create_network_graph();
+ let (secp_ctx, net_graph_msg_handler) = create_net_graph_msg_handler(&network_graph);
let node_privkey_1 = &SecretKey::from_slice(&[42; 32]).unwrap();
let node_id_1 = PublicKey::from_secret_key(&secp_ctx, node_privkey_1);
// The initial implementation allows syncing with the first 5 peers after
// which should_request_full_sync will return false
{
- let (secp_ctx, net_graph_msg_handler) = create_net_graph_msg_handler();
+ let network_graph = create_network_graph();
+ let (secp_ctx, net_graph_msg_handler) = create_net_graph_msg_handler(&network_graph);
let init_msg = Init { features: InitFeatures::known() };
for n in 1..7 {
let node_privkey = &SecretKey::from_slice(&[n; 32]).unwrap();
#[test]
fn handling_reply_channel_range() {
- let (secp_ctx, net_graph_msg_handler) = create_net_graph_msg_handler();
+ let network_graph = create_network_graph();
+ let (secp_ctx, net_graph_msg_handler) = create_net_graph_msg_handler(&network_graph);
let node_privkey_1 = &SecretKey::from_slice(&[42; 32]).unwrap();
let node_id_1 = PublicKey::from_secret_key(&secp_ctx, node_privkey_1);
#[test]
fn handling_reply_short_channel_ids() {
- let (secp_ctx, net_graph_msg_handler) = create_net_graph_msg_handler();
+ let network_graph = create_network_graph();
+ let (secp_ctx, net_graph_msg_handler) = create_net_graph_msg_handler(&network_graph);
let node_privkey = &SecretKey::from_slice(&[41; 32]).unwrap();
let node_id = PublicKey::from_secret_key(&secp_ctx, node_privkey);
#[test]
fn handling_query_channel_range() {
- let (secp_ctx, net_graph_msg_handler) = create_net_graph_msg_handler();
+ let network_graph = create_network_graph();
+ let (secp_ctx, net_graph_msg_handler) = create_net_graph_msg_handler(&network_graph);
let chain_hash = genesis_block(Network::Testnet).header.block_hash();
let node_1_privkey = &SecretKey::from_slice(&[42; 32]).unwrap();
}
fn do_handling_query_channel_range(
- net_graph_msg_handler: &NetGraphMsgHandler<Arc<test_utils::TestChainSource>, Arc<test_utils::TestLogger>>,
+ net_graph_msg_handler: &NetGraphMsgHandler<&NetworkGraph, Arc<test_utils::TestChainSource>, Arc<test_utils::TestLogger>>,
test_node_id: &PublicKey,
msg: QueryChannelRange,
expected_ok: bool,
#[test]
fn handling_query_short_channel_ids() {
- let (secp_ctx, net_graph_msg_handler) = create_net_graph_msg_handler();
+ let network_graph = create_network_graph();
+ let (secp_ctx, net_graph_msg_handler) = create_net_graph_msg_handler(&network_graph);
let node_privkey = &SecretKey::from_slice(&[41; 32]).unwrap();
let node_id = PublicKey::from_secret_key(&secp_ctx, node_privkey);
// Using the same keys for LN and BTC ids
fn add_channel(
- net_graph_msg_handler: &NetGraphMsgHandler<Arc<test_utils::TestChainSource>, Arc<test_utils::TestLogger>>,
+ net_graph_msg_handler: &NetGraphMsgHandler<Arc<NetworkGraph>, Arc<test_utils::TestChainSource>, Arc<test_utils::TestLogger>>,
secp_ctx: &Secp256k1<All>, node_1_privkey: &SecretKey, node_2_privkey: &SecretKey, features: ChannelFeatures, short_channel_id: u64
) {
let node_id_1 = PublicKey::from_secret_key(&secp_ctx, node_1_privkey);
}
fn update_channel(
- net_graph_msg_handler: &NetGraphMsgHandler<Arc<test_utils::TestChainSource>, Arc<test_utils::TestLogger>>,
+ net_graph_msg_handler: &NetGraphMsgHandler<Arc<NetworkGraph>, Arc<test_utils::TestChainSource>, Arc<test_utils::TestLogger>>,
secp_ctx: &Secp256k1<All>, node_privkey: &SecretKey, update: UnsignedChannelUpdate
) {
let msghash = hash_to_message!(&Sha256dHash::hash(&update.encode()[..])[..]);
}
fn add_or_update_node(
- net_graph_msg_handler: &NetGraphMsgHandler<Arc<test_utils::TestChainSource>, Arc<test_utils::TestLogger>>,
+ net_graph_msg_handler: &NetGraphMsgHandler<Arc<NetworkGraph>, Arc<test_utils::TestChainSource>, Arc<test_utils::TestLogger>>,
secp_ctx: &Secp256k1<All>, node_privkey: &SecretKey, features: NodeFeatures, timestamp: u32
) {
let node_id = PublicKey::from_secret_key(&secp_ctx, node_privkey);
}
}
- fn build_graph() -> (Secp256k1<All>, NetGraphMsgHandler<sync::Arc<test_utils::TestChainSource>, sync::Arc<crate::util::test_utils::TestLogger>>, sync::Arc<test_utils::TestChainSource>, sync::Arc<test_utils::TestLogger>) {
+ fn build_graph() -> (Secp256k1<All>, NetGraphMsgHandler<sync::Arc<NetworkGraph>, sync::Arc<test_utils::TestChainSource>, sync::Arc<crate::util::test_utils::TestLogger>>, sync::Arc<test_utils::TestChainSource>, sync::Arc<test_utils::TestLogger>) {
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 network_graph = NetworkGraph::new(genesis_block(Network::Testnet).header.block_hash());
+ let network_graph = Arc::new(NetworkGraph::new(genesis_block(Network::Testnet).header.block_hash()));
let net_graph_msg_handler = NetGraphMsgHandler::new(network_graph, None, Arc::clone(&logger));
// Build network from our_id to node6:
//
// "previous hop" being set to node 3, creating a loop in the path.
let secp_ctx = Secp256k1::new();
let logger = Arc::new(test_utils::TestLogger::new());
- let network_graph = NetworkGraph::new(genesis_block(Network::Testnet).header.block_hash());
+ let network_graph = Arc::new(NetworkGraph::new(genesis_block(Network::Testnet).header.block_hash()));
let net_graph_msg_handler = NetGraphMsgHandler::new(network_graph, None, Arc::clone(&logger));
let (our_privkey, our_id, privkeys, nodes) = get_nodes(&secp_ctx);
let scorer = Scorer::with_fixed_penalty(0);