use chain::transaction::OutPoint;
use ln::{PaymentPreimage, PaymentHash, PaymentSecret};
use ln::channelmanager::{ChainParameters, ChannelManager, ChannelManagerReadArgs, RAACommitmentOrder, PaymentSendFailure, PaymentId, MIN_CLTV_EXPIRY_DELTA};
-use routing::gossip::{P2PGossipSync, NetworkGraph};
+use routing::gossip::{P2PGossipSync, NetworkGraph, NetworkUpdate};
use routing::router::{PaymentParameters, Route, get_route};
use ln::features::{InitFeatures, InvoiceFeatures};
use ln::msgs;
use util::events::{Event, MessageSendEvent, MessageSendEventsProvider, PaymentPurpose};
use util::errors::APIError;
use util::config::UserConfig;
-use util::ser::{ReadableArgs, Writeable, Readable};
+use util::ser::{ReadableArgs, Writeable};
use bitcoin::blockdata::block::{Block, BlockHeader};
use bitcoin::blockdata::constants::genesis_block;
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 network_graph: NetworkGraph<&'a test_utils::TestLogger>,
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 network_graph: &'c NetworkGraph,
- pub gossip_sync: P2PGossipSync<&'c NetworkGraph, &'c test_utils::TestChainSource, &'c test_utils::TestLogger>,
+ pub network_graph: &'b NetworkGraph<&'c test_utils::TestLogger>,
+ pub gossip_sync: P2PGossipSync<&'b NetworkGraph<&'c test_utils::TestLogger>, &'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 mut w = test_utils::TestVecWriter(Vec::new());
self.network_graph.write(&mut w).unwrap();
- let network_graph_deser = <NetworkGraph>::read(&mut io::Cursor::new(&w.0)).unwrap();
+ let network_graph_deser = <NetworkGraph<_>>::read(&mut io::Cursor::new(&w.0), self.logger).unwrap();
assert!(network_graph_deser == *self.network_graph);
let gossip_sync = P2PGossipSync::new(
&network_graph_deser, Some(self.chain_source), self.logger
#[cfg(test)]
macro_rules! expect_payment_failed_with_update {
($node: expr, $expected_payment_hash: expr, $rejected_by_dest: expr, $scid: expr, $chan_closed: expr) => {
- expect_payment_failed_conditions!($node, $expected_payment_hash, $rejected_by_dest,
- $crate::ln::functional_test_utils::PaymentFailedConditions::new().blamed_scid($scid).blamed_chan_closed($chan_closed));
+ $crate::ln::functional_test_utils::expect_payment_failed_conditions(
+ &$node, $expected_payment_hash, $rejected_by_dest,
+ $crate::ln::functional_test_utils::PaymentFailedConditions::new()
+ .blamed_scid($scid).blamed_chan_closed($chan_closed));
}
}
$(
conditions = conditions.expected_htlc_error_data($expected_error_code, &$expected_error_data);
)*
- expect_payment_failed_conditions!($node, $expected_payment_hash, $rejected_by_dest, conditions);
+ $crate::ln::functional_test_utils::expect_payment_failed_conditions(&$node, $expected_payment_hash, $rejected_by_dest, conditions);
};
}
-#[cfg(test)]
-macro_rules! expect_payment_failed_conditions {
- ($node: expr, $expected_payment_hash: expr, $rejected_by_dest: expr, $conditions: expr) => {
- let events = $node.node.get_and_clear_pending_events();
- assert_eq!(events.len(), 1);
- let expected_payment_id = match events[0] {
- Event::PaymentPathFailed { ref payment_hash, rejected_by_dest, ref error_code, ref error_data, ref path, ref retry, ref payment_id, ref network_update, .. } => {
- assert_eq!(*payment_hash, $expected_payment_hash, "unexpected payment_hash");
- assert_eq!(rejected_by_dest, $rejected_by_dest, "unexpected rejected_by_dest value");
- assert!(retry.is_some(), "expected retry.is_some()");
- assert_eq!(retry.as_ref().unwrap().final_value_msat, path.last().unwrap().fee_msat, "Retry amount should match last hop in path");
- assert_eq!(retry.as_ref().unwrap().payment_params.payee_pubkey, path.last().unwrap().pubkey, "Retry payee node_id should match last hop in path");
-
+pub fn expect_payment_failed_conditions<'a, 'b, 'c, 'd, 'e>(
+ node: &'a Node<'b, 'c, 'd>, expected_payment_hash: PaymentHash, expected_rejected_by_dest: bool,
+ conditions: PaymentFailedConditions<'e>
+) {
+ let mut events = node.node.get_and_clear_pending_events();
+ assert_eq!(events.len(), 1);
+ let expected_payment_id = match events.pop().unwrap() {
+ Event::PaymentPathFailed { payment_hash, rejected_by_dest, path, retry, payment_id, network_update,
+ #[cfg(test)]
+ error_code,
+ #[cfg(test)]
+ error_data, .. } => {
+ assert_eq!(payment_hash, expected_payment_hash, "unexpected payment_hash");
+ assert_eq!(rejected_by_dest, expected_rejected_by_dest, "unexpected rejected_by_dest value");
+ assert!(retry.is_some(), "expected retry.is_some()");
+ assert_eq!(retry.as_ref().unwrap().final_value_msat, path.last().unwrap().fee_msat, "Retry amount should match last hop in path");
+ assert_eq!(retry.as_ref().unwrap().payment_params.payee_pubkey, path.last().unwrap().pubkey, "Retry payee node_id should match last hop in path");
+
+ #[cfg(test)]
+ {
assert!(error_code.is_some(), "expected error_code.is_some() = true");
assert!(error_data.is_some(), "expected error_data.is_some() = true");
- if let Some((code, data)) = $conditions.expected_htlc_error_data {
+ if let Some((code, data)) = conditions.expected_htlc_error_data {
assert_eq!(error_code.unwrap(), code, "unexpected error code");
assert_eq!(&error_data.as_ref().unwrap()[..], data, "unexpected error data");
}
+ }
- if let Some(chan_closed) = $conditions.expected_blamed_chan_closed {
- match network_update {
- &Some($crate::routing::gossip::NetworkUpdate::ChannelUpdateMessage { ref msg }) if !chan_closed => {
- if let Some(scid) = $conditions.expected_blamed_scid {
- assert_eq!(msg.contents.short_channel_id, scid);
- }
- assert_eq!(msg.contents.flags & 2, 0);
- },
- &Some($crate::routing::gossip::NetworkUpdate::ChannelFailure { short_channel_id, is_permanent }) if chan_closed => {
- if let Some(scid) = $conditions.expected_blamed_scid {
- assert_eq!(short_channel_id, scid);
- }
- assert!(is_permanent);
- },
- Some(_) => panic!("Unexpected update type"),
- None => panic!("Expected update"),
- }
+ if let Some(chan_closed) = conditions.expected_blamed_chan_closed {
+ match network_update {
+ Some(NetworkUpdate::ChannelUpdateMessage { ref msg }) if !chan_closed => {
+ if let Some(scid) = conditions.expected_blamed_scid {
+ assert_eq!(msg.contents.short_channel_id, scid);
+ }
+ const CHAN_DISABLED_FLAG: u8 = 2;
+ assert_eq!(msg.contents.flags & CHAN_DISABLED_FLAG, 0);
+ },
+ Some(NetworkUpdate::ChannelFailure { short_channel_id, is_permanent }) if chan_closed => {
+ if let Some(scid) = conditions.expected_blamed_scid {
+ assert_eq!(short_channel_id, scid);
+ }
+ assert!(is_permanent);
+ },
+ Some(_) => panic!("Unexpected update type"),
+ None => panic!("Expected update"),
}
+ }
- payment_id.unwrap()
- },
- _ => panic!("Unexpected event"),
- };
- if !$conditions.expected_mpp_parts_remain {
- $node.node.abandon_payment(expected_payment_id);
- let events = $node.node.get_and_clear_pending_events();
- assert_eq!(events.len(), 1);
- match events[0] {
- Event::PaymentFailed { ref payment_hash, ref payment_id } => {
- assert_eq!(*payment_hash, $expected_payment_hash, "unexpected second payment_hash");
- assert_eq!(*payment_id, expected_payment_id);
- }
- _ => panic!("Unexpected second event"),
+ payment_id.unwrap()
+ },
+ _ => panic!("Unexpected event"),
+ };
+ if !conditions.expected_mpp_parts_remain {
+ node.node.abandon_payment(expected_payment_id);
+ let events = node.node.get_and_clear_pending_events();
+ assert_eq!(events.len(), 1);
+ match events[0] {
+ Event::PaymentFailed { ref payment_hash, ref payment_id } => {
+ assert_eq!(*payment_hash, expected_payment_hash, "unexpected second payment_hash");
+ assert_eq!(*payment_id, expected_payment_id);
}
+ _ => panic!("Unexpected second event"),
}
}
}
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, network_graph });
+ chan_mon_cfgs.push(TestChanMonCfg{ tx_broadcaster, fee_estimator, chain_source, logger, persister, keys_manager });
}
chan_mon_cfgs
keys_manager: &chanmon_cfgs[i].keys_manager,
node_seed: seed,
features: InitFeatures::known(),
- network_graph: &chanmon_cfgs[i].network_graph,
+ network_graph: NetworkGraph::new(chanmon_cfgs[i].chain_source.genesis_hash, &chanmon_cfgs[i].logger),
});
}
let connect_style = Rc::new(RefCell::new(ConnectStyle::random_style()));
for i in 0..node_count {
- let gossip_sync = P2PGossipSync::new(cfgs[i].network_graph, None, cfgs[i].logger);
+ let gossip_sync = P2PGossipSync::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,