1 //! A bunch of useful utilities for building networks of nodes and exchanging messages between
2 //! nodes for functional tests.
6 use chain::transaction::OutPoint;
7 use ln::channelmanager::{ChannelManager, ChannelManagerReadArgs, RAACommitmentOrder, PaymentPreimage, PaymentHash, PaymentSecret, PaymentSendFailure};
8 use ln::channelmonitor::ChannelMonitor;
9 use routing::router::{Route, get_route};
10 use routing::network_graph::{NetGraphMsgHandler, NetworkGraph};
11 use ln::features::InitFeatures;
13 use ln::msgs::{ChannelMessageHandler,RoutingMessageHandler};
14 use util::enforcing_trait_impls::EnforcingChannelKeys;
16 use util::test_utils::TestChainMonitor;
17 use util::events::{Event, EventsProvider, MessageSendEvent, MessageSendEventsProvider};
18 use util::errors::APIError;
19 use util::config::UserConfig;
20 use util::ser::{ReadableArgs, Writeable, Readable};
22 use bitcoin::util::hash::BitcoinHash;
23 use bitcoin::blockdata::block::{Block, BlockHeader};
24 use bitcoin::blockdata::transaction::{Transaction, TxOut};
25 use bitcoin::network::constants::Network;
27 use bitcoin::hashes::sha256::Hash as Sha256;
28 use bitcoin::hashes::Hash;
29 use bitcoin::hash_types::BlockHash;
31 use bitcoin::secp256k1::key::PublicKey;
33 use std::cell::RefCell;
37 use std::collections::HashMap;
39 pub const CHAN_CONFIRM_DEPTH: u32 = 100;
41 pub fn confirm_transaction<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, tx: &Transaction) {
42 let dummy_tx = Transaction { version: 0, lock_time: 0, input: Vec::new(), output: Vec::new() };
43 let dummy_tx_count = tx.version as usize;
44 let mut block = Block {
45 header: BlockHeader { version: 0x20000000, prev_blockhash: Default::default(), merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 },
46 txdata: vec![dummy_tx; dummy_tx_count],
48 block.txdata.push(tx.clone());
49 connect_block(node, &block, 1);
50 for i in 2..CHAN_CONFIRM_DEPTH {
52 header: BlockHeader { version: 0x20000000, prev_blockhash: block.header.bitcoin_hash(), merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 },
55 connect_block(node, &block, i);
59 pub fn connect_blocks<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, depth: u32, height: u32, parent: bool, prev_blockhash: BlockHash) -> BlockHash {
60 let mut block = Block {
61 header: BlockHeader { version: 0x2000000, prev_blockhash: if parent { prev_blockhash } else { Default::default() }, merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 },
64 connect_block(node, &block, height + 1);
65 for i in 2..depth + 1 {
67 header: BlockHeader { version: 0x20000000, prev_blockhash: block.header.bitcoin_hash(), merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 },
70 connect_block(node, &block, height + i);
72 block.header.bitcoin_hash()
75 pub fn connect_block<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, block: &Block, height: u32) {
76 use chain::WatchEventProvider;
78 let watch_events = node.chain_monitor.chain_monitor.release_pending_watch_events();
79 process_chain_watch_events(&watch_events);
81 let txdata: Vec<_> = block.txdata.iter().enumerate().collect();
83 node.chain_monitor.chain_monitor.block_connected(&block.header, &txdata, height);
85 let watch_events = node.chain_monitor.chain_monitor.release_pending_watch_events();
86 process_chain_watch_events(&watch_events);
88 if watch_events.is_empty() {
93 node.node.block_connected(&block.header, &txdata, height);
96 fn process_chain_watch_events(_events: &Vec<chain::WatchEvent>) {}
98 pub fn disconnect_block<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, header: &BlockHeader, height: u32) {
99 node.chain_monitor.chain_monitor.block_disconnected(header, height);
100 node.node.block_disconnected(header, height);
103 pub struct TestChanMonCfg {
104 pub tx_broadcaster: test_utils::TestBroadcaster,
105 pub fee_estimator: test_utils::TestFeeEstimator,
106 pub chain_source: test_utils::TestChainSource,
107 pub logger: test_utils::TestLogger,
110 pub struct NodeCfg<'a> {
111 pub chain_source: &'a test_utils::TestChainSource,
112 pub tx_broadcaster: &'a test_utils::TestBroadcaster,
113 pub fee_estimator: &'a test_utils::TestFeeEstimator,
114 pub chain_monitor: test_utils::TestChainMonitor<'a>,
115 pub keys_manager: test_utils::TestKeysInterface,
116 pub logger: &'a test_utils::TestLogger,
117 pub node_seed: [u8; 32],
120 pub struct Node<'a, 'b: 'a, 'c: 'b> {
121 pub chain_source: &'c test_utils::TestChainSource,
122 pub tx_broadcaster: &'c test_utils::TestBroadcaster,
123 pub chain_monitor: &'b test_utils::TestChainMonitor<'c>,
124 pub keys_manager: &'b test_utils::TestKeysInterface,
125 pub node: &'a ChannelManager<EnforcingChannelKeys, &'b TestChainMonitor<'c>, &'c test_utils::TestBroadcaster, &'b test_utils::TestKeysInterface, &'c test_utils::TestFeeEstimator, &'c test_utils::TestLogger>,
126 pub net_graph_msg_handler: NetGraphMsgHandler<&'c test_utils::TestChainSource, &'c test_utils::TestLogger>,
127 pub node_seed: [u8; 32],
128 pub network_payment_count: Rc<RefCell<u8>>,
129 pub network_chan_count: Rc<RefCell<u32>>,
130 pub logger: &'c test_utils::TestLogger,
133 impl<'a, 'b, 'c> Drop for Node<'a, 'b, 'c> {
135 if !::std::thread::panicking() {
136 // Check that we processed all pending events
137 assert!(self.node.get_and_clear_pending_msg_events().is_empty());
138 assert!(self.node.get_and_clear_pending_events().is_empty());
139 assert!(self.chain_monitor.added_monitors.lock().unwrap().is_empty());
141 // Check that if we serialize the Router, we can deserialize it again.
143 let mut w = test_utils::TestVecWriter(Vec::new());
144 let network_graph_ser = self.net_graph_msg_handler.network_graph.read().unwrap();
145 network_graph_ser.write(&mut w).unwrap();
146 let network_graph_deser = <NetworkGraph>::read(&mut ::std::io::Cursor::new(&w.0)).unwrap();
147 assert!(network_graph_deser == *self.net_graph_msg_handler.network_graph.read().unwrap());
148 let net_graph_msg_handler = NetGraphMsgHandler::from_net_graph(
149 Some(self.chain_source), self.logger, network_graph_deser
151 let mut chan_progress = 0;
153 let orig_announcements = self.net_graph_msg_handler.get_next_channel_announcements(chan_progress, 255);
154 let deserialized_announcements = net_graph_msg_handler.get_next_channel_announcements(chan_progress, 255);
155 assert!(orig_announcements == deserialized_announcements);
156 chan_progress = match orig_announcements.last() {
157 Some(announcement) => announcement.0.contents.short_channel_id + 1,
161 let mut node_progress = None;
163 let orig_announcements = self.net_graph_msg_handler.get_next_node_announcements(node_progress.as_ref(), 255);
164 let deserialized_announcements = net_graph_msg_handler.get_next_node_announcements(node_progress.as_ref(), 255);
165 assert!(orig_announcements == deserialized_announcements);
166 node_progress = match orig_announcements.last() {
167 Some(announcement) => Some(announcement.contents.node_id),
173 // Check that if we serialize and then deserialize all our channel monitors we get the
174 // same set of outputs to watch for on chain as we have now. Note that if we write
175 // tests that fully close channels and remove the monitors at some point this may break.
176 let feeest = test_utils::TestFeeEstimator { sat_per_kw: 253 };
177 let mut deserialized_monitors = Vec::new();
179 let old_monitors = self.chain_monitor.chain_monitor.monitors.lock().unwrap();
180 for (_, old_monitor) in old_monitors.iter() {
181 let mut w = test_utils::TestVecWriter(Vec::new());
182 old_monitor.write_for_disk(&mut w).unwrap();
183 let (_, deserialized_monitor) = <(BlockHash, ChannelMonitor<EnforcingChannelKeys>)>::read(
184 &mut ::std::io::Cursor::new(&w.0)).unwrap();
185 deserialized_monitors.push(deserialized_monitor);
189 // Before using all the new monitors to check the watch outpoints, use the full set of
190 // them to ensure we can write and reload our ChannelManager.
192 let mut channel_monitors = HashMap::new();
193 for monitor in deserialized_monitors.iter_mut() {
194 channel_monitors.insert(monitor.get_funding_txo().0, monitor);
197 let mut w = test_utils::TestVecWriter(Vec::new());
198 self.node.write(&mut w).unwrap();
199 <(BlockHash, ChannelManager<EnforcingChannelKeys, &test_utils::TestChainMonitor, &test_utils::TestBroadcaster, &test_utils::TestKeysInterface, &test_utils::TestFeeEstimator, &test_utils::TestLogger>)>::read(&mut ::std::io::Cursor::new(w.0), ChannelManagerReadArgs {
200 default_config: UserConfig::default(),
201 keys_manager: self.keys_manager,
202 fee_estimator: &test_utils::TestFeeEstimator { sat_per_kw: 253 },
203 chain_monitor: self.chain_monitor,
204 tx_broadcaster: self.tx_broadcaster.clone(),
205 logger: &test_utils::TestLogger::new(),
206 channel_monitors: &mut channel_monitors,
210 let channel_monitor = test_utils::TestChainMonitor::new(self.tx_broadcaster.clone(), &self.logger, &feeest);
211 for deserialized_monitor in deserialized_monitors.drain(..) {
212 if let Err(_) = channel_monitor.watch_channel(deserialized_monitor.get_funding_txo().0, deserialized_monitor) {
220 pub fn create_chan_between_nodes<'a, 'b, 'c, 'd>(node_a: &'a Node<'b, 'c, 'd>, node_b: &'a Node<'b, 'c, 'd>, a_flags: InitFeatures, b_flags: InitFeatures) -> (msgs::ChannelAnnouncement, msgs::ChannelUpdate, msgs::ChannelUpdate, [u8; 32], Transaction) {
221 create_chan_between_nodes_with_value(node_a, node_b, 100000, 10001, a_flags, b_flags)
224 pub fn create_chan_between_nodes_with_value<'a, 'b, 'c, 'd>(node_a: &'a Node<'b, 'c, 'd>, node_b: &'a Node<'b, 'c, 'd>, channel_value: u64, push_msat: u64, a_flags: InitFeatures, b_flags: InitFeatures) -> (msgs::ChannelAnnouncement, msgs::ChannelUpdate, msgs::ChannelUpdate, [u8; 32], Transaction) {
225 let (funding_locked, channel_id, tx) = create_chan_between_nodes_with_value_a(node_a, node_b, channel_value, push_msat, a_flags, b_flags);
226 let (announcement, as_update, bs_update) = create_chan_between_nodes_with_value_b(node_a, node_b, &funding_locked);
227 (announcement, as_update, bs_update, channel_id, tx)
230 macro_rules! get_revoke_commit_msgs {
231 ($node: expr, $node_id: expr) => {
233 let events = $node.node.get_and_clear_pending_msg_events();
234 assert_eq!(events.len(), 2);
236 MessageSendEvent::SendRevokeAndACK { ref node_id, ref msg } => {
237 assert_eq!(*node_id, $node_id);
240 _ => panic!("Unexpected event"),
242 MessageSendEvent::UpdateHTLCs { ref node_id, ref updates } => {
243 assert_eq!(*node_id, $node_id);
244 assert!(updates.update_add_htlcs.is_empty());
245 assert!(updates.update_fulfill_htlcs.is_empty());
246 assert!(updates.update_fail_htlcs.is_empty());
247 assert!(updates.update_fail_malformed_htlcs.is_empty());
248 assert!(updates.update_fee.is_none());
249 updates.commitment_signed.clone()
251 _ => panic!("Unexpected event"),
257 macro_rules! get_event_msg {
258 ($node: expr, $event_type: path, $node_id: expr) => {
260 let events = $node.node.get_and_clear_pending_msg_events();
261 assert_eq!(events.len(), 1);
263 $event_type { ref node_id, ref msg } => {
264 assert_eq!(*node_id, $node_id);
267 _ => panic!("Unexpected event"),
273 macro_rules! get_htlc_update_msgs {
274 ($node: expr, $node_id: expr) => {
276 let events = $node.node.get_and_clear_pending_msg_events();
277 assert_eq!(events.len(), 1);
279 MessageSendEvent::UpdateHTLCs { ref node_id, ref updates } => {
280 assert_eq!(*node_id, $node_id);
283 _ => panic!("Unexpected event"),
289 macro_rules! get_feerate {
290 ($node: expr, $channel_id: expr) => {
292 let chan_lock = $node.node.channel_state.lock().unwrap();
293 let chan = chan_lock.by_id.get(&$channel_id).unwrap();
299 macro_rules! get_local_commitment_txn {
300 ($node: expr, $channel_id: expr) => {
302 let mut monitors = $node.chain_monitor.chain_monitor.monitors.lock().unwrap();
303 let mut commitment_txn = None;
304 for (funding_txo, monitor) in monitors.iter_mut() {
305 if funding_txo.to_channel_id() == $channel_id {
306 commitment_txn = Some(monitor.unsafe_get_latest_local_commitment_txn(&$node.logger));
310 commitment_txn.unwrap()
315 macro_rules! unwrap_send_err {
316 ($res: expr, $all_failed: expr, $type: pat, $check: expr) => {
318 &Err(PaymentSendFailure::AllFailedRetrySafe(ref fails)) if $all_failed => {
319 assert_eq!(fails.len(), 1);
325 &Err(PaymentSendFailure::PartialFailure(ref fails)) if !$all_failed => {
326 assert_eq!(fails.len(), 1);
328 Err($type) => { $check },
337 macro_rules! check_added_monitors {
338 ($node: expr, $count: expr) => {
340 let mut added_monitors = $node.chain_monitor.added_monitors.lock().unwrap();
341 assert_eq!(added_monitors.len(), $count);
342 added_monitors.clear();
347 pub fn create_funding_transaction<'a, 'b, 'c>(node: &Node<'a, 'b, 'c>, expected_chan_value: u64, expected_user_chan_id: u64) -> ([u8; 32], Transaction, OutPoint) {
348 let chan_id = *node.network_chan_count.borrow();
350 let events = node.node.get_and_clear_pending_events();
351 assert_eq!(events.len(), 1);
353 Event::FundingGenerationReady { ref temporary_channel_id, ref channel_value_satoshis, ref output_script, user_channel_id } => {
354 assert_eq!(*channel_value_satoshis, expected_chan_value);
355 assert_eq!(user_channel_id, expected_user_chan_id);
357 let tx = Transaction { version: chan_id as u32, lock_time: 0, input: Vec::new(), output: vec![TxOut {
358 value: *channel_value_satoshis, script_pubkey: output_script.clone(),
360 let funding_outpoint = OutPoint { txid: tx.txid(), index: 0 };
361 (*temporary_channel_id, tx, funding_outpoint)
363 _ => panic!("Unexpected event"),
367 pub fn create_chan_between_nodes_with_value_init<'a, 'b, 'c>(node_a: &Node<'a, 'b, 'c>, node_b: &Node<'a, 'b, 'c>, channel_value: u64, push_msat: u64, a_flags: InitFeatures, b_flags: InitFeatures) -> Transaction {
368 node_a.node.create_channel(node_b.node.get_our_node_id(), channel_value, push_msat, 42, None).unwrap();
369 node_b.node.handle_open_channel(&node_a.node.get_our_node_id(), a_flags, &get_event_msg!(node_a, MessageSendEvent::SendOpenChannel, node_b.node.get_our_node_id()));
370 node_a.node.handle_accept_channel(&node_b.node.get_our_node_id(), b_flags, &get_event_msg!(node_b, MessageSendEvent::SendAcceptChannel, node_a.node.get_our_node_id()));
372 let (temporary_channel_id, tx, funding_output) = create_funding_transaction(node_a, channel_value, 42);
374 node_a.node.funding_transaction_generated(&temporary_channel_id, funding_output);
375 check_added_monitors!(node_a, 0);
377 node_b.node.handle_funding_created(&node_a.node.get_our_node_id(), &get_event_msg!(node_a, MessageSendEvent::SendFundingCreated, node_b.node.get_our_node_id()));
379 let mut added_monitors = node_b.chain_monitor.added_monitors.lock().unwrap();
380 assert_eq!(added_monitors.len(), 1);
381 assert_eq!(added_monitors[0].0, funding_output);
382 added_monitors.clear();
385 node_a.node.handle_funding_signed(&node_b.node.get_our_node_id(), &get_event_msg!(node_b, MessageSendEvent::SendFundingSigned, node_a.node.get_our_node_id()));
387 let mut added_monitors = node_a.chain_monitor.added_monitors.lock().unwrap();
388 assert_eq!(added_monitors.len(), 1);
389 assert_eq!(added_monitors[0].0, funding_output);
390 added_monitors.clear();
393 let events_4 = node_a.node.get_and_clear_pending_events();
394 assert_eq!(events_4.len(), 1);
396 Event::FundingBroadcastSafe { ref funding_txo, user_channel_id } => {
397 assert_eq!(user_channel_id, 42);
398 assert_eq!(*funding_txo, funding_output);
400 _ => panic!("Unexpected event"),
406 pub fn create_chan_between_nodes_with_value_confirm_first<'a, 'b, 'c, 'd>(node_recv: &'a Node<'b, 'c, 'c>, node_conf: &'a Node<'b, 'c, 'd>, tx: &Transaction) {
407 confirm_transaction(node_conf, tx);
408 node_recv.node.handle_funding_locked(&node_conf.node.get_our_node_id(), &get_event_msg!(node_conf, MessageSendEvent::SendFundingLocked, node_recv.node.get_our_node_id()));
411 pub fn create_chan_between_nodes_with_value_confirm_second<'a, 'b, 'c>(node_recv: &Node<'a, 'b, 'c>, node_conf: &Node<'a, 'b, 'c>) -> ((msgs::FundingLocked, msgs::AnnouncementSignatures), [u8; 32]) {
413 let events_6 = node_conf.node.get_and_clear_pending_msg_events();
414 assert_eq!(events_6.len(), 2);
415 ((match events_6[0] {
416 MessageSendEvent::SendFundingLocked { ref node_id, ref msg } => {
417 channel_id = msg.channel_id.clone();
418 assert_eq!(*node_id, node_recv.node.get_our_node_id());
421 _ => panic!("Unexpected event"),
422 }, match events_6[1] {
423 MessageSendEvent::SendAnnouncementSignatures { ref node_id, ref msg } => {
424 assert_eq!(*node_id, node_recv.node.get_our_node_id());
427 _ => panic!("Unexpected event"),
431 pub fn create_chan_between_nodes_with_value_confirm<'a, 'b, 'c, 'd>(node_a: &'a Node<'b, 'c, 'd>, node_b: &'a Node<'b, 'c, 'd>, tx: &Transaction) -> ((msgs::FundingLocked, msgs::AnnouncementSignatures), [u8; 32]) {
432 create_chan_between_nodes_with_value_confirm_first(node_a, node_b, tx);
433 confirm_transaction(node_a, tx);
434 create_chan_between_nodes_with_value_confirm_second(node_b, node_a)
437 pub fn create_chan_between_nodes_with_value_a<'a, 'b, 'c, 'd>(node_a: &'a Node<'b, 'c, 'd>, node_b: &'a Node<'b, 'c, 'd>, channel_value: u64, push_msat: u64, a_flags: InitFeatures, b_flags: InitFeatures) -> ((msgs::FundingLocked, msgs::AnnouncementSignatures), [u8; 32], Transaction) {
438 let tx = create_chan_between_nodes_with_value_init(node_a, node_b, channel_value, push_msat, a_flags, b_flags);
439 let (msgs, chan_id) = create_chan_between_nodes_with_value_confirm(node_a, node_b, &tx);
443 pub fn create_chan_between_nodes_with_value_b<'a, 'b, 'c>(node_a: &Node<'a, 'b, 'c>, node_b: &Node<'a, 'b, 'c>, as_funding_msgs: &(msgs::FundingLocked, msgs::AnnouncementSignatures)) -> (msgs::ChannelAnnouncement, msgs::ChannelUpdate, msgs::ChannelUpdate) {
444 node_b.node.handle_funding_locked(&node_a.node.get_our_node_id(), &as_funding_msgs.0);
445 let bs_announcement_sigs = get_event_msg!(node_b, MessageSendEvent::SendAnnouncementSignatures, node_a.node.get_our_node_id());
446 node_b.node.handle_announcement_signatures(&node_a.node.get_our_node_id(), &as_funding_msgs.1);
448 let events_7 = node_b.node.get_and_clear_pending_msg_events();
449 assert_eq!(events_7.len(), 1);
450 let (announcement, bs_update) = match events_7[0] {
451 MessageSendEvent::BroadcastChannelAnnouncement { ref msg, ref update_msg } => {
454 _ => panic!("Unexpected event"),
457 node_a.node.handle_announcement_signatures(&node_b.node.get_our_node_id(), &bs_announcement_sigs);
458 let events_8 = node_a.node.get_and_clear_pending_msg_events();
459 assert_eq!(events_8.len(), 1);
460 let as_update = match events_8[0] {
461 MessageSendEvent::BroadcastChannelAnnouncement { ref msg, ref update_msg } => {
462 assert!(*announcement == *msg);
463 assert_eq!(update_msg.contents.short_channel_id, announcement.contents.short_channel_id);
464 assert_eq!(update_msg.contents.short_channel_id, bs_update.contents.short_channel_id);
467 _ => panic!("Unexpected event"),
470 *node_a.network_chan_count.borrow_mut() += 1;
472 ((*announcement).clone(), (*as_update).clone(), (*bs_update).clone())
475 pub fn create_announced_chan_between_nodes<'a, 'b, 'c, 'd>(nodes: &'a Vec<Node<'b, 'c, 'd>>, a: usize, b: usize, a_flags: InitFeatures, b_flags: InitFeatures) -> (msgs::ChannelUpdate, msgs::ChannelUpdate, [u8; 32], Transaction) {
476 create_announced_chan_between_nodes_with_value(nodes, a, b, 100000, 10001, a_flags, b_flags)
479 pub fn create_announced_chan_between_nodes_with_value<'a, 'b, 'c, 'd>(nodes: &'a Vec<Node<'b, 'c, 'd>>, a: usize, b: usize, channel_value: u64, push_msat: u64, a_flags: InitFeatures, b_flags: InitFeatures) -> (msgs::ChannelUpdate, msgs::ChannelUpdate, [u8; 32], Transaction) {
480 let chan_announcement = create_chan_between_nodes_with_value(&nodes[a], &nodes[b], channel_value, push_msat, a_flags, b_flags);
482 nodes[a].node.broadcast_node_announcement([0, 0, 0], [0; 32], Vec::new());
483 let a_events = nodes[a].node.get_and_clear_pending_msg_events();
484 assert_eq!(a_events.len(), 1);
485 let a_node_announcement = match a_events[0] {
486 MessageSendEvent::BroadcastNodeAnnouncement { ref msg } => {
489 _ => panic!("Unexpected event"),
492 nodes[b].node.broadcast_node_announcement([1, 1, 1], [1; 32], Vec::new());
493 let b_events = nodes[b].node.get_and_clear_pending_msg_events();
494 assert_eq!(b_events.len(), 1);
495 let b_node_announcement = match b_events[0] {
496 MessageSendEvent::BroadcastNodeAnnouncement { ref msg } => {
499 _ => panic!("Unexpected event"),
503 assert!(node.net_graph_msg_handler.handle_channel_announcement(&chan_announcement.0).unwrap());
504 node.net_graph_msg_handler.handle_channel_update(&chan_announcement.1).unwrap();
505 node.net_graph_msg_handler.handle_channel_update(&chan_announcement.2).unwrap();
506 node.net_graph_msg_handler.handle_node_announcement(&a_node_announcement).unwrap();
507 node.net_graph_msg_handler.handle_node_announcement(&b_node_announcement).unwrap();
509 (chan_announcement.1, chan_announcement.2, chan_announcement.3, chan_announcement.4)
512 macro_rules! check_spends {
513 ($tx: expr, $($spends_txn: expr),*) => {
515 $tx.verify(|out_point| {
517 if out_point.txid == $spends_txn.txid() {
518 return $spends_txn.output.get(out_point.vout as usize).cloned()
527 macro_rules! get_closing_signed_broadcast {
528 ($node: expr, $dest_pubkey: expr) => {
530 let events = $node.get_and_clear_pending_msg_events();
531 assert!(events.len() == 1 || events.len() == 2);
532 (match events[events.len() - 1] {
533 MessageSendEvent::BroadcastChannelUpdate { ref msg } => {
534 assert_eq!(msg.contents.flags & 2, 2);
537 _ => panic!("Unexpected event"),
538 }, if events.len() == 2 {
540 MessageSendEvent::SendClosingSigned { ref node_id, ref msg } => {
541 assert_eq!(*node_id, $dest_pubkey);
544 _ => panic!("Unexpected event"),
551 macro_rules! check_closed_broadcast {
552 ($node: expr, $with_error_msg: expr) => {{
553 let events = $node.node.get_and_clear_pending_msg_events();
554 assert_eq!(events.len(), if $with_error_msg { 2 } else { 1 });
556 MessageSendEvent::BroadcastChannelUpdate { ref msg } => {
557 assert_eq!(msg.contents.flags & 2, 2);
559 _ => panic!("Unexpected event"),
563 MessageSendEvent::HandleError { action: ErrorAction::SendErrorMessage { ref msg }, node_id: _ } => {
564 // TODO: Check node_id
567 _ => panic!("Unexpected event"),
573 pub fn close_channel<'a, 'b, 'c>(outbound_node: &Node<'a, 'b, 'c>, inbound_node: &Node<'a, 'b, 'c>, channel_id: &[u8; 32], funding_tx: Transaction, close_inbound_first: bool) -> (msgs::ChannelUpdate, msgs::ChannelUpdate, Transaction) {
574 let (node_a, broadcaster_a, struct_a) = if close_inbound_first { (&inbound_node.node, &inbound_node.tx_broadcaster, inbound_node) } else { (&outbound_node.node, &outbound_node.tx_broadcaster, outbound_node) };
575 let (node_b, broadcaster_b) = if close_inbound_first { (&outbound_node.node, &outbound_node.tx_broadcaster) } else { (&inbound_node.node, &inbound_node.tx_broadcaster) };
578 node_a.close_channel(channel_id).unwrap();
579 node_b.handle_shutdown(&node_a.get_our_node_id(), &get_event_msg!(struct_a, MessageSendEvent::SendShutdown, node_b.get_our_node_id()));
581 let events_1 = node_b.get_and_clear_pending_msg_events();
582 assert!(events_1.len() >= 1);
583 let shutdown_b = match events_1[0] {
584 MessageSendEvent::SendShutdown { ref node_id, ref msg } => {
585 assert_eq!(node_id, &node_a.get_our_node_id());
588 _ => panic!("Unexpected event"),
591 let closing_signed_b = if !close_inbound_first {
592 assert_eq!(events_1.len(), 1);
595 Some(match events_1[1] {
596 MessageSendEvent::SendClosingSigned { ref node_id, ref msg } => {
597 assert_eq!(node_id, &node_a.get_our_node_id());
600 _ => panic!("Unexpected event"),
604 node_a.handle_shutdown(&node_b.get_our_node_id(), &shutdown_b);
605 let (as_update, bs_update) = if close_inbound_first {
606 assert!(node_a.get_and_clear_pending_msg_events().is_empty());
607 node_a.handle_closing_signed(&node_b.get_our_node_id(), &closing_signed_b.unwrap());
608 assert_eq!(broadcaster_a.txn_broadcasted.lock().unwrap().len(), 1);
609 tx_a = broadcaster_a.txn_broadcasted.lock().unwrap().remove(0);
610 let (as_update, closing_signed_a) = get_closing_signed_broadcast!(node_a, node_b.get_our_node_id());
612 node_b.handle_closing_signed(&node_a.get_our_node_id(), &closing_signed_a.unwrap());
613 let (bs_update, none_b) = get_closing_signed_broadcast!(node_b, node_a.get_our_node_id());
614 assert!(none_b.is_none());
615 assert_eq!(broadcaster_b.txn_broadcasted.lock().unwrap().len(), 1);
616 tx_b = broadcaster_b.txn_broadcasted.lock().unwrap().remove(0);
617 (as_update, bs_update)
619 let closing_signed_a = get_event_msg!(struct_a, MessageSendEvent::SendClosingSigned, node_b.get_our_node_id());
621 node_b.handle_closing_signed(&node_a.get_our_node_id(), &closing_signed_a);
622 assert_eq!(broadcaster_b.txn_broadcasted.lock().unwrap().len(), 1);
623 tx_b = broadcaster_b.txn_broadcasted.lock().unwrap().remove(0);
624 let (bs_update, closing_signed_b) = get_closing_signed_broadcast!(node_b, node_a.get_our_node_id());
626 node_a.handle_closing_signed(&node_b.get_our_node_id(), &closing_signed_b.unwrap());
627 let (as_update, none_a) = get_closing_signed_broadcast!(node_a, node_b.get_our_node_id());
628 assert!(none_a.is_none());
629 assert_eq!(broadcaster_a.txn_broadcasted.lock().unwrap().len(), 1);
630 tx_a = broadcaster_a.txn_broadcasted.lock().unwrap().remove(0);
631 (as_update, bs_update)
633 assert_eq!(tx_a, tx_b);
634 check_spends!(tx_a, funding_tx);
636 (as_update, bs_update, tx_a)
639 pub struct SendEvent {
640 pub node_id: PublicKey,
641 pub msgs: Vec<msgs::UpdateAddHTLC>,
642 pub commitment_msg: msgs::CommitmentSigned,
645 pub fn from_commitment_update(node_id: PublicKey, updates: msgs::CommitmentUpdate) -> SendEvent {
646 assert!(updates.update_fulfill_htlcs.is_empty());
647 assert!(updates.update_fail_htlcs.is_empty());
648 assert!(updates.update_fail_malformed_htlcs.is_empty());
649 assert!(updates.update_fee.is_none());
650 SendEvent { node_id: node_id, msgs: updates.update_add_htlcs, commitment_msg: updates.commitment_signed }
653 pub fn from_event(event: MessageSendEvent) -> SendEvent {
655 MessageSendEvent::UpdateHTLCs { node_id, updates } => SendEvent::from_commitment_update(node_id, updates),
656 _ => panic!("Unexpected event type!"),
660 pub fn from_node<'a, 'b, 'c>(node: &Node<'a, 'b, 'c>) -> SendEvent {
661 let mut events = node.node.get_and_clear_pending_msg_events();
662 assert_eq!(events.len(), 1);
663 SendEvent::from_event(events.pop().unwrap())
667 macro_rules! commitment_signed_dance {
668 ($node_a: expr, $node_b: expr, $commitment_signed: expr, $fail_backwards: expr, true /* skip last step */) => {
670 check_added_monitors!($node_a, 0);
671 assert!($node_a.node.get_and_clear_pending_msg_events().is_empty());
672 $node_a.node.handle_commitment_signed(&$node_b.node.get_our_node_id(), &$commitment_signed);
673 check_added_monitors!($node_a, 1);
674 commitment_signed_dance!($node_a, $node_b, (), $fail_backwards, true, false);
677 ($node_a: expr, $node_b: expr, (), $fail_backwards: expr, true /* skip last step */, true /* return extra message */, true /* return last RAA */) => {
679 let (as_revoke_and_ack, as_commitment_signed) = get_revoke_commit_msgs!($node_a, $node_b.node.get_our_node_id());
680 check_added_monitors!($node_b, 0);
681 assert!($node_b.node.get_and_clear_pending_msg_events().is_empty());
682 $node_b.node.handle_revoke_and_ack(&$node_a.node.get_our_node_id(), &as_revoke_and_ack);
683 assert!($node_b.node.get_and_clear_pending_msg_events().is_empty());
684 check_added_monitors!($node_b, 1);
685 $node_b.node.handle_commitment_signed(&$node_a.node.get_our_node_id(), &as_commitment_signed);
686 let (bs_revoke_and_ack, extra_msg_option) = {
687 let events = $node_b.node.get_and_clear_pending_msg_events();
688 assert!(events.len() <= 2);
690 MessageSendEvent::SendRevokeAndACK { ref node_id, ref msg } => {
691 assert_eq!(*node_id, $node_a.node.get_our_node_id());
694 _ => panic!("Unexpected event"),
695 }, events.get(1).map(|e| e.clone()))
697 check_added_monitors!($node_b, 1);
699 assert!($node_a.node.get_and_clear_pending_events().is_empty());
700 assert!($node_a.node.get_and_clear_pending_msg_events().is_empty());
702 (extra_msg_option, bs_revoke_and_ack)
705 ($node_a: expr, $node_b: expr, $commitment_signed: expr, $fail_backwards: expr, true /* skip last step */, false /* return extra message */, true /* return last RAA */) => {
707 check_added_monitors!($node_a, 0);
708 assert!($node_a.node.get_and_clear_pending_msg_events().is_empty());
709 $node_a.node.handle_commitment_signed(&$node_b.node.get_our_node_id(), &$commitment_signed);
710 check_added_monitors!($node_a, 1);
711 let (extra_msg_option, bs_revoke_and_ack) = commitment_signed_dance!($node_a, $node_b, (), $fail_backwards, true, true, true);
712 assert!(extra_msg_option.is_none());
716 ($node_a: expr, $node_b: expr, (), $fail_backwards: expr, true /* skip last step */, true /* return extra message */) => {
718 let (extra_msg_option, bs_revoke_and_ack) = commitment_signed_dance!($node_a, $node_b, (), $fail_backwards, true, true, true);
719 $node_a.node.handle_revoke_and_ack(&$node_b.node.get_our_node_id(), &bs_revoke_and_ack);
720 check_added_monitors!($node_a, 1);
724 ($node_a: expr, $node_b: expr, (), $fail_backwards: expr, true /* skip last step */, false /* no extra message */) => {
726 assert!(commitment_signed_dance!($node_a, $node_b, (), $fail_backwards, true, true).is_none());
729 ($node_a: expr, $node_b: expr, $commitment_signed: expr, $fail_backwards: expr) => {
731 commitment_signed_dance!($node_a, $node_b, $commitment_signed, $fail_backwards, true);
733 expect_pending_htlcs_forwardable!($node_a);
734 check_added_monitors!($node_a, 1);
736 let channel_state = $node_a.node.channel_state.lock().unwrap();
737 assert_eq!(channel_state.pending_msg_events.len(), 1);
738 if let MessageSendEvent::UpdateHTLCs { ref node_id, .. } = channel_state.pending_msg_events[0] {
739 assert_ne!(*node_id, $node_b.node.get_our_node_id());
740 } else { panic!("Unexpected event"); }
742 assert!($node_a.node.get_and_clear_pending_msg_events().is_empty());
748 macro_rules! get_payment_preimage_hash {
751 let payment_preimage = PaymentPreimage([*$node.network_payment_count.borrow(); 32]);
752 *$node.network_payment_count.borrow_mut() += 1;
753 let payment_hash = PaymentHash(Sha256::hash(&payment_preimage.0[..]).into_inner());
754 (payment_preimage, payment_hash)
759 macro_rules! expect_pending_htlcs_forwardable_ignore {
761 let events = $node.node.get_and_clear_pending_events();
762 assert_eq!(events.len(), 1);
764 Event::PendingHTLCsForwardable { .. } => { },
765 _ => panic!("Unexpected event"),
770 macro_rules! expect_pending_htlcs_forwardable {
772 expect_pending_htlcs_forwardable_ignore!($node);
773 $node.node.process_pending_htlc_forwards();
777 macro_rules! expect_payment_received {
778 ($node: expr, $expected_payment_hash: expr, $expected_recv_value: expr) => {
779 let events = $node.node.get_and_clear_pending_events();
780 assert_eq!(events.len(), 1);
782 Event::PaymentReceived { ref payment_hash, ref payment_secret, amt } => {
783 assert_eq!($expected_payment_hash, *payment_hash);
784 assert_eq!(None, *payment_secret);
785 assert_eq!($expected_recv_value, amt);
787 _ => panic!("Unexpected event"),
792 macro_rules! expect_payment_sent {
793 ($node: expr, $expected_payment_preimage: expr) => {
794 let events = $node.node.get_and_clear_pending_events();
795 assert_eq!(events.len(), 1);
797 Event::PaymentSent { ref payment_preimage } => {
798 assert_eq!($expected_payment_preimage, *payment_preimage);
800 _ => panic!("Unexpected event"),
805 macro_rules! expect_payment_failed {
806 ($node: expr, $expected_payment_hash: expr, $rejected_by_dest: expr $(, $expected_error_code: expr, $expected_error_data: expr)*) => {
807 let events = $node.node.get_and_clear_pending_events();
808 assert_eq!(events.len(), 1);
810 Event::PaymentFailed { ref payment_hash, rejected_by_dest, ref error_code, ref error_data } => {
811 assert_eq!(*payment_hash, $expected_payment_hash);
812 assert_eq!(rejected_by_dest, $rejected_by_dest);
813 assert!(error_code.is_some());
814 assert!(error_data.is_some());
816 assert_eq!(error_code.unwrap(), $expected_error_code);
817 assert_eq!(&error_data.as_ref().unwrap()[..], $expected_error_data);
820 _ => panic!("Unexpected event"),
825 pub fn send_along_route_with_secret<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, route: Route, expected_paths: &[&[&Node<'a, 'b, 'c>]], recv_value: u64, our_payment_hash: PaymentHash, our_payment_secret: Option<PaymentSecret>) {
826 origin_node.node.send_payment(&route, our_payment_hash, &our_payment_secret).unwrap();
827 check_added_monitors!(origin_node, expected_paths.len());
828 pass_along_route(origin_node, expected_paths, recv_value, our_payment_hash, our_payment_secret);
831 pub fn pass_along_path<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_path: &[&Node<'a, 'b, 'c>], recv_value: u64, our_payment_hash: PaymentHash, our_payment_secret: Option<PaymentSecret>, ev: MessageSendEvent, payment_received_expected: bool) {
832 let mut payment_event = SendEvent::from_event(ev);
833 let mut prev_node = origin_node;
835 for (idx, &node) in expected_path.iter().enumerate() {
836 assert_eq!(node.node.get_our_node_id(), payment_event.node_id);
838 node.node.handle_update_add_htlc(&prev_node.node.get_our_node_id(), &payment_event.msgs[0]);
839 check_added_monitors!(node, 0);
840 commitment_signed_dance!(node, prev_node, payment_event.commitment_msg, false);
842 expect_pending_htlcs_forwardable!(node);
844 if idx == expected_path.len() - 1 {
845 let events_2 = node.node.get_and_clear_pending_events();
846 if payment_received_expected {
847 assert_eq!(events_2.len(), 1);
849 Event::PaymentReceived { ref payment_hash, ref payment_secret, amt } => {
850 assert_eq!(our_payment_hash, *payment_hash);
851 assert_eq!(our_payment_secret, *payment_secret);
852 assert_eq!(amt, recv_value);
854 _ => panic!("Unexpected event"),
857 assert!(events_2.is_empty());
860 let mut events_2 = node.node.get_and_clear_pending_msg_events();
861 assert_eq!(events_2.len(), 1);
862 check_added_monitors!(node, 1);
863 payment_event = SendEvent::from_event(events_2.remove(0));
864 assert_eq!(payment_event.msgs.len(), 1);
871 pub fn pass_along_route<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_route: &[&[&Node<'a, 'b, 'c>]], recv_value: u64, our_payment_hash: PaymentHash, our_payment_secret: Option<PaymentSecret>) {
872 let mut events = origin_node.node.get_and_clear_pending_msg_events();
873 assert_eq!(events.len(), expected_route.len());
874 for (path_idx, (ev, expected_path)) in events.drain(..).zip(expected_route.iter()).enumerate() {
875 // Once we've gotten through all the HTLCs, the last one should result in a
876 // PaymentReceived (but each previous one should not!), .
877 let expect_payment = path_idx == expected_route.len() - 1;
878 pass_along_path(origin_node, expected_path, recv_value, our_payment_hash.clone(), our_payment_secret, ev, expect_payment);
882 pub fn send_along_route_with_hash<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, route: Route, expected_route: &[&Node<'a, 'b, 'c>], recv_value: u64, our_payment_hash: PaymentHash) {
883 send_along_route_with_secret(origin_node, route, &[expected_route], recv_value, our_payment_hash, None);
886 pub fn send_along_route<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, route: Route, expected_route: &[&Node<'a, 'b, 'c>], recv_value: u64) -> (PaymentPreimage, PaymentHash) {
887 let (our_payment_preimage, our_payment_hash) = get_payment_preimage_hash!(origin_node);
888 send_along_route_with_hash(origin_node, route, expected_route, recv_value, our_payment_hash);
889 (our_payment_preimage, our_payment_hash)
892 pub fn claim_payment_along_route_with_secret<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_paths: &[&[&Node<'a, 'b, 'c>]], skip_last: bool, our_payment_preimage: PaymentPreimage, our_payment_secret: Option<PaymentSecret>, expected_amount: u64) {
893 for path in expected_paths.iter() {
894 assert_eq!(path.last().unwrap().node.get_our_node_id(), expected_paths[0].last().unwrap().node.get_our_node_id());
896 assert!(expected_paths[0].last().unwrap().node.claim_funds(our_payment_preimage, &our_payment_secret, expected_amount));
897 check_added_monitors!(expected_paths[0].last().unwrap(), expected_paths.len());
899 macro_rules! msgs_from_ev {
902 &MessageSendEvent::UpdateHTLCs { ref node_id, updates: msgs::CommitmentUpdate { ref update_add_htlcs, ref update_fulfill_htlcs, ref update_fail_htlcs, ref update_fail_malformed_htlcs, ref update_fee, ref commitment_signed } } => {
903 assert!(update_add_htlcs.is_empty());
904 assert_eq!(update_fulfill_htlcs.len(), 1);
905 assert!(update_fail_htlcs.is_empty());
906 assert!(update_fail_malformed_htlcs.is_empty());
907 assert!(update_fee.is_none());
908 ((update_fulfill_htlcs[0].clone(), commitment_signed.clone()), node_id.clone())
910 _ => panic!("Unexpected event"),
914 let mut per_path_msgs: Vec<((msgs::UpdateFulfillHTLC, msgs::CommitmentSigned), PublicKey)> = Vec::with_capacity(expected_paths.len());
915 let events = expected_paths[0].last().unwrap().node.get_and_clear_pending_msg_events();
916 assert_eq!(events.len(), expected_paths.len());
917 for ev in events.iter() {
918 per_path_msgs.push(msgs_from_ev!(ev));
921 for (expected_route, (path_msgs, next_hop)) in expected_paths.iter().zip(per_path_msgs.drain(..)) {
922 let mut next_msgs = Some(path_msgs);
923 let mut expected_next_node = next_hop;
925 macro_rules! last_update_fulfill_dance {
926 ($node: expr, $prev_node: expr) => {
928 $node.node.handle_update_fulfill_htlc(&$prev_node.node.get_our_node_id(), &next_msgs.as_ref().unwrap().0);
929 check_added_monitors!($node, 0);
930 assert!($node.node.get_and_clear_pending_msg_events().is_empty());
931 commitment_signed_dance!($node, $prev_node, next_msgs.as_ref().unwrap().1, false);
935 macro_rules! mid_update_fulfill_dance {
936 ($node: expr, $prev_node: expr, $new_msgs: expr) => {
938 $node.node.handle_update_fulfill_htlc(&$prev_node.node.get_our_node_id(), &next_msgs.as_ref().unwrap().0);
939 check_added_monitors!($node, 1);
940 let new_next_msgs = if $new_msgs {
941 let events = $node.node.get_and_clear_pending_msg_events();
942 assert_eq!(events.len(), 1);
943 let (res, nexthop) = msgs_from_ev!(&events[0]);
944 expected_next_node = nexthop;
947 assert!($node.node.get_and_clear_pending_msg_events().is_empty());
950 commitment_signed_dance!($node, $prev_node, next_msgs.as_ref().unwrap().1, false);
951 next_msgs = new_next_msgs;
956 let mut prev_node = expected_route.last().unwrap();
957 for (idx, node) in expected_route.iter().rev().enumerate().skip(1) {
958 assert_eq!(expected_next_node, node.node.get_our_node_id());
959 let update_next_msgs = !skip_last || idx != expected_route.len() - 1;
960 if next_msgs.is_some() {
961 mid_update_fulfill_dance!(node, prev_node, update_next_msgs);
963 assert!(!update_next_msgs);
964 assert!(node.node.get_and_clear_pending_msg_events().is_empty());
966 if !skip_last && idx == expected_route.len() - 1 {
967 assert_eq!(expected_next_node, origin_node.node.get_our_node_id());
974 last_update_fulfill_dance!(origin_node, expected_route.first().unwrap());
975 expect_payment_sent!(origin_node, our_payment_preimage);
980 pub fn claim_payment_along_route<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_route: &[&Node<'a, 'b, 'c>], skip_last: bool, our_payment_preimage: PaymentPreimage, expected_amount: u64) {
981 claim_payment_along_route_with_secret(origin_node, &[expected_route], skip_last, our_payment_preimage, None, expected_amount);
984 pub fn claim_payment<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_route: &[&Node<'a, 'b, 'c>], our_payment_preimage: PaymentPreimage, expected_amount: u64) {
985 claim_payment_along_route(origin_node, expected_route, false, our_payment_preimage, expected_amount);
988 pub const TEST_FINAL_CLTV: u32 = 32;
990 pub fn route_payment<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_route: &[&Node<'a, 'b, 'c>], recv_value: u64) -> (PaymentPreimage, PaymentHash) {
991 let net_graph_msg_handler = &origin_node.net_graph_msg_handler;
992 let logger = test_utils::TestLogger::new();
993 let route = get_route(&origin_node.node.get_our_node_id(), &net_graph_msg_handler.network_graph.read().unwrap(), &expected_route.last().unwrap().node.get_our_node_id(), None, &Vec::new(), recv_value, TEST_FINAL_CLTV, &logger).unwrap();
994 assert_eq!(route.paths.len(), 1);
995 assert_eq!(route.paths[0].len(), expected_route.len());
996 for (node, hop) in expected_route.iter().zip(route.paths[0].iter()) {
997 assert_eq!(hop.pubkey, node.node.get_our_node_id());
1000 send_along_route(origin_node, route, expected_route, recv_value)
1003 pub fn route_over_limit<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_route: &[&Node<'a, 'b, 'c>], recv_value: u64) {
1004 let logger = test_utils::TestLogger::new();
1005 let net_graph_msg_handler = &origin_node.net_graph_msg_handler;
1006 let route = get_route(&origin_node.node.get_our_node_id(), &net_graph_msg_handler.network_graph.read().unwrap(), &expected_route.last().unwrap().node.get_our_node_id(), None, &Vec::new(), recv_value, TEST_FINAL_CLTV, &logger).unwrap();
1007 assert_eq!(route.paths.len(), 1);
1008 assert_eq!(route.paths[0].len(), expected_route.len());
1009 for (node, hop) in expected_route.iter().zip(route.paths[0].iter()) {
1010 assert_eq!(hop.pubkey, node.node.get_our_node_id());
1013 let (_, our_payment_hash) = get_payment_preimage_hash!(origin_node);
1014 unwrap_send_err!(origin_node.node.send_payment(&route, our_payment_hash, &None), true, APIError::ChannelUnavailable { ref err },
1015 assert!(err.contains("Cannot send value that would put us over the max HTLC value in flight our peer will accept")));
1018 pub fn send_payment<'a, 'b, 'c>(origin: &Node<'a, 'b, 'c>, expected_route: &[&Node<'a, 'b, 'c>], recv_value: u64, expected_value: u64) {
1019 let our_payment_preimage = route_payment(&origin, expected_route, recv_value).0;
1020 claim_payment(&origin, expected_route, our_payment_preimage, expected_value);
1023 pub fn fail_payment_along_route<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_route: &[&Node<'a, 'b, 'c>], skip_last: bool, our_payment_hash: PaymentHash) {
1024 assert!(expected_route.last().unwrap().node.fail_htlc_backwards(&our_payment_hash, &None));
1025 expect_pending_htlcs_forwardable!(expected_route.last().unwrap());
1026 check_added_monitors!(expected_route.last().unwrap(), 1);
1028 let mut next_msgs: Option<(msgs::UpdateFailHTLC, msgs::CommitmentSigned)> = None;
1029 macro_rules! update_fail_dance {
1030 ($node: expr, $prev_node: expr, $last_node: expr) => {
1032 $node.node.handle_update_fail_htlc(&$prev_node.node.get_our_node_id(), &next_msgs.as_ref().unwrap().0);
1033 commitment_signed_dance!($node, $prev_node, next_msgs.as_ref().unwrap().1, !$last_node);
1034 if skip_last && $last_node {
1035 expect_pending_htlcs_forwardable!($node);
1041 let mut expected_next_node = expected_route.last().unwrap().node.get_our_node_id();
1042 let mut prev_node = expected_route.last().unwrap();
1043 for (idx, node) in expected_route.iter().rev().enumerate() {
1044 assert_eq!(expected_next_node, node.node.get_our_node_id());
1045 if next_msgs.is_some() {
1046 // We may be the "last node" for the purpose of the commitment dance if we're
1047 // skipping the last node (implying it is disconnected) and we're the
1048 // second-to-last node!
1049 update_fail_dance!(node, prev_node, skip_last && idx == expected_route.len() - 1);
1052 let events = node.node.get_and_clear_pending_msg_events();
1053 if !skip_last || idx != expected_route.len() - 1 {
1054 assert_eq!(events.len(), 1);
1056 MessageSendEvent::UpdateHTLCs { ref node_id, updates: msgs::CommitmentUpdate { ref update_add_htlcs, ref update_fulfill_htlcs, ref update_fail_htlcs, ref update_fail_malformed_htlcs, ref update_fee, ref commitment_signed } } => {
1057 assert!(update_add_htlcs.is_empty());
1058 assert!(update_fulfill_htlcs.is_empty());
1059 assert_eq!(update_fail_htlcs.len(), 1);
1060 assert!(update_fail_malformed_htlcs.is_empty());
1061 assert!(update_fee.is_none());
1062 expected_next_node = node_id.clone();
1063 next_msgs = Some((update_fail_htlcs[0].clone(), commitment_signed.clone()));
1065 _ => panic!("Unexpected event"),
1068 assert!(events.is_empty());
1070 if !skip_last && idx == expected_route.len() - 1 {
1071 assert_eq!(expected_next_node, origin_node.node.get_our_node_id());
1078 update_fail_dance!(origin_node, expected_route.first().unwrap(), true);
1080 let events = origin_node.node.get_and_clear_pending_events();
1081 assert_eq!(events.len(), 1);
1083 Event::PaymentFailed { payment_hash, rejected_by_dest, .. } => {
1084 assert_eq!(payment_hash, our_payment_hash);
1085 assert!(rejected_by_dest);
1087 _ => panic!("Unexpected event"),
1092 pub fn fail_payment<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_route: &[&Node<'a, 'b, 'c>], our_payment_hash: PaymentHash) {
1093 fail_payment_along_route(origin_node, expected_route, false, our_payment_hash);
1096 pub fn create_chanmon_cfgs(node_count: usize) -> Vec<TestChanMonCfg> {
1097 let mut chan_mon_cfgs = Vec::new();
1098 for i in 0..node_count {
1099 let tx_broadcaster = test_utils::TestBroadcaster{txn_broadcasted: Mutex::new(Vec::new())};
1100 let fee_estimator = test_utils::TestFeeEstimator { sat_per_kw: 253 };
1101 let chain_source = test_utils::TestChainSource::new(Network::Testnet);
1102 let logger = test_utils::TestLogger::with_id(format!("node {}", i));
1103 chan_mon_cfgs.push(TestChanMonCfg{ tx_broadcaster, fee_estimator, chain_source, logger });
1109 pub fn create_node_cfgs<'a>(node_count: usize, chanmon_cfgs: &'a Vec<TestChanMonCfg>) -> Vec<NodeCfg<'a>> {
1110 let mut nodes = Vec::new();
1112 for i in 0..node_count {
1113 let seed = [i as u8; 32];
1114 let keys_manager = test_utils::TestKeysInterface::new(&seed, Network::Testnet);
1115 let chain_monitor = test_utils::TestChainMonitor::new(&chanmon_cfgs[i].tx_broadcaster, &chanmon_cfgs[i].logger, &chanmon_cfgs[i].fee_estimator);
1116 nodes.push(NodeCfg { chain_source: &chanmon_cfgs[i].chain_source, logger: &chanmon_cfgs[i].logger, tx_broadcaster: &chanmon_cfgs[i].tx_broadcaster, fee_estimator: &chanmon_cfgs[i].fee_estimator, chain_monitor, keys_manager, node_seed: seed });
1122 pub fn create_node_chanmgrs<'a, 'b>(node_count: usize, cfgs: &'a Vec<NodeCfg<'b>>, node_config: &[Option<UserConfig>]) -> Vec<ChannelManager<EnforcingChannelKeys, &'a TestChainMonitor<'b>, &'b test_utils::TestBroadcaster, &'a test_utils::TestKeysInterface, &'b test_utils::TestFeeEstimator, &'b test_utils::TestLogger>> {
1123 let mut chanmgrs = Vec::new();
1124 for i in 0..node_count {
1125 let mut default_config = UserConfig::default();
1126 default_config.channel_options.announced_channel = true;
1127 default_config.peer_channel_config_limits.force_announced_channel_preference = false;
1128 default_config.own_channel_config.our_htlc_minimum_msat = 1000; // sanitization being done by the sender, to exerce receiver logic we need to lift of limit
1129 let node = ChannelManager::new(Network::Testnet, cfgs[i].fee_estimator, &cfgs[i].chain_monitor, cfgs[i].tx_broadcaster, cfgs[i].logger.clone(), &cfgs[i].keys_manager, if node_config[i].is_some() { node_config[i].clone().unwrap() } else { default_config }, 0);
1130 chanmgrs.push(node);
1136 pub fn create_network<'a, 'b: 'a, 'c: 'b>(node_count: usize, cfgs: &'b Vec<NodeCfg<'c>>, chan_mgrs: &'a Vec<ChannelManager<EnforcingChannelKeys, &'b TestChainMonitor<'c>, &'c test_utils::TestBroadcaster, &'b test_utils::TestKeysInterface, &'c test_utils::TestFeeEstimator, &'c test_utils::TestLogger>>) -> Vec<Node<'a, 'b, 'c>> {
1137 let mut nodes = Vec::new();
1138 let chan_count = Rc::new(RefCell::new(0));
1139 let payment_count = Rc::new(RefCell::new(0));
1141 for i in 0..node_count {
1142 let net_graph_msg_handler = NetGraphMsgHandler::new(None, cfgs[i].logger);
1143 nodes.push(Node{ chain_source: cfgs[i].chain_source,
1144 tx_broadcaster: cfgs[i].tx_broadcaster, chain_monitor: &cfgs[i].chain_monitor,
1145 keys_manager: &cfgs[i].keys_manager, node: &chan_mgrs[i], net_graph_msg_handler,
1146 node_seed: cfgs[i].node_seed, network_chan_count: chan_count.clone(),
1147 network_payment_count: payment_count.clone(), logger: cfgs[i].logger,
1154 pub const ACCEPTED_HTLC_SCRIPT_WEIGHT: usize = 138; //Here we have a diff due to HTLC CLTV expiry being < 2^15 in test
1155 pub const OFFERED_HTLC_SCRIPT_WEIGHT: usize = 133;
1157 #[derive(PartialEq)]
1158 pub enum HTLCType { NONE, TIMEOUT, SUCCESS }
1159 /// Tests that the given node has broadcast transactions for the given Channel
1161 /// First checks that the latest local commitment tx has been broadcast, unless an explicit
1162 /// commitment_tx is provided, which may be used to test that a remote commitment tx was
1163 /// broadcast and the revoked outputs were claimed.
1165 /// Next tests that there is (or is not) a transaction that spends the commitment transaction
1166 /// that appears to be the type of HTLC transaction specified in has_htlc_tx.
1168 /// All broadcast transactions must be accounted for in one of the above three types of we'll
1170 pub fn test_txn_broadcast<'a, 'b, 'c>(node: &Node<'a, 'b, 'c>, chan: &(msgs::ChannelUpdate, msgs::ChannelUpdate, [u8; 32], Transaction), commitment_tx: Option<Transaction>, has_htlc_tx: HTLCType) -> Vec<Transaction> {
1171 let mut node_txn = node.tx_broadcaster.txn_broadcasted.lock().unwrap();
1172 assert!(node_txn.len() >= if commitment_tx.is_some() { 0 } else { 1 } + if has_htlc_tx == HTLCType::NONE { 0 } else { 1 });
1174 let mut res = Vec::with_capacity(2);
1175 node_txn.retain(|tx| {
1176 if tx.input.len() == 1 && tx.input[0].previous_output.txid == chan.3.txid() {
1177 check_spends!(tx, chan.3);
1178 if commitment_tx.is_none() {
1179 res.push(tx.clone());
1184 if let Some(explicit_tx) = commitment_tx {
1185 res.push(explicit_tx.clone());
1188 assert_eq!(res.len(), 1);
1190 if has_htlc_tx != HTLCType::NONE {
1191 node_txn.retain(|tx| {
1192 if tx.input.len() == 1 && tx.input[0].previous_output.txid == res[0].txid() {
1193 check_spends!(tx, res[0]);
1194 if has_htlc_tx == HTLCType::TIMEOUT {
1195 assert!(tx.lock_time != 0);
1197 assert!(tx.lock_time == 0);
1199 res.push(tx.clone());
1203 assert!(res.len() == 2 || res.len() == 3);
1205 assert_eq!(res[1], res[2]);
1209 assert!(node_txn.is_empty());
1213 /// Tests that the given node has broadcast a claim transaction against the provided revoked
1214 /// HTLC transaction.
1215 pub fn test_revoked_htlc_claim_txn_broadcast<'a, 'b, 'c>(node: &Node<'a, 'b, 'c>, revoked_tx: Transaction, commitment_revoked_tx: Transaction) {
1216 let mut node_txn = node.tx_broadcaster.txn_broadcasted.lock().unwrap();
1217 // We may issue multiple claiming transaction on revoked outputs due to block rescan
1218 // for revoked htlc outputs
1219 if node_txn.len() != 1 && node_txn.len() != 2 && node_txn.len() != 3 { assert!(false); }
1220 node_txn.retain(|tx| {
1221 if tx.input.len() == 1 && tx.input[0].previous_output.txid == revoked_tx.txid() {
1222 check_spends!(tx, revoked_tx);
1226 node_txn.retain(|tx| {
1227 check_spends!(tx, commitment_revoked_tx);
1230 assert!(node_txn.is_empty());
1233 pub fn check_preimage_claim<'a, 'b, 'c>(node: &Node<'a, 'b, 'c>, prev_txn: &Vec<Transaction>) -> Vec<Transaction> {
1234 let mut node_txn = node.tx_broadcaster.txn_broadcasted.lock().unwrap();
1236 assert!(node_txn.len() >= 1);
1237 assert_eq!(node_txn[0].input.len(), 1);
1238 let mut found_prev = false;
1240 for tx in prev_txn {
1241 if node_txn[0].input[0].previous_output.txid == tx.txid() {
1242 check_spends!(node_txn[0], tx);
1243 assert!(node_txn[0].input[0].witness[2].len() > 106); // must spend an htlc output
1244 assert_eq!(tx.input.len(), 1); // must spend a commitment tx
1250 assert!(found_prev);
1252 let mut res = Vec::new();
1253 mem::swap(&mut *node_txn, &mut res);
1257 pub fn get_announce_close_broadcast_events<'a, 'b, 'c>(nodes: &Vec<Node<'a, 'b, 'c>>, a: usize, b: usize) {
1258 let events_1 = nodes[a].node.get_and_clear_pending_msg_events();
1259 assert_eq!(events_1.len(), 1);
1260 let as_update = match events_1[0] {
1261 MessageSendEvent::BroadcastChannelUpdate { ref msg } => {
1264 _ => panic!("Unexpected event"),
1267 let events_2 = nodes[b].node.get_and_clear_pending_msg_events();
1268 assert_eq!(events_2.len(), 1);
1269 let bs_update = match events_2[0] {
1270 MessageSendEvent::BroadcastChannelUpdate { ref msg } => {
1273 _ => panic!("Unexpected event"),
1277 node.net_graph_msg_handler.handle_channel_update(&as_update).unwrap();
1278 node.net_graph_msg_handler.handle_channel_update(&bs_update).unwrap();
1282 macro_rules! get_channel_value_stat {
1283 ($node: expr, $channel_id: expr) => {{
1284 let chan_lock = $node.node.channel_state.lock().unwrap();
1285 let chan = chan_lock.by_id.get(&$channel_id).unwrap();
1286 chan.get_value_stat()
1290 macro_rules! get_chan_reestablish_msgs {
1291 ($src_node: expr, $dst_node: expr) => {
1293 let mut res = Vec::with_capacity(1);
1294 for msg in $src_node.node.get_and_clear_pending_msg_events() {
1295 if let MessageSendEvent::SendChannelReestablish { ref node_id, ref msg } = msg {
1296 assert_eq!(*node_id, $dst_node.node.get_our_node_id());
1297 res.push(msg.clone());
1299 panic!("Unexpected event")
1307 macro_rules! handle_chan_reestablish_msgs {
1308 ($src_node: expr, $dst_node: expr) => {
1310 let msg_events = $src_node.node.get_and_clear_pending_msg_events();
1312 let funding_locked = if let Some(&MessageSendEvent::SendFundingLocked { ref node_id, ref msg }) = msg_events.get(0) {
1314 assert_eq!(*node_id, $dst_node.node.get_our_node_id());
1320 let mut revoke_and_ack = None;
1321 let mut commitment_update = None;
1322 let order = if let Some(ev) = msg_events.get(idx) {
1325 &MessageSendEvent::SendRevokeAndACK { ref node_id, ref msg } => {
1326 assert_eq!(*node_id, $dst_node.node.get_our_node_id());
1327 revoke_and_ack = Some(msg.clone());
1328 RAACommitmentOrder::RevokeAndACKFirst
1330 &MessageSendEvent::UpdateHTLCs { ref node_id, ref updates } => {
1331 assert_eq!(*node_id, $dst_node.node.get_our_node_id());
1332 commitment_update = Some(updates.clone());
1333 RAACommitmentOrder::CommitmentFirst
1335 _ => panic!("Unexpected event"),
1338 RAACommitmentOrder::CommitmentFirst
1341 if let Some(ev) = msg_events.get(idx) {
1343 &MessageSendEvent::SendRevokeAndACK { ref node_id, ref msg } => {
1344 assert_eq!(*node_id, $dst_node.node.get_our_node_id());
1345 assert!(revoke_and_ack.is_none());
1346 revoke_and_ack = Some(msg.clone());
1348 &MessageSendEvent::UpdateHTLCs { ref node_id, ref updates } => {
1349 assert_eq!(*node_id, $dst_node.node.get_our_node_id());
1350 assert!(commitment_update.is_none());
1351 commitment_update = Some(updates.clone());
1353 _ => panic!("Unexpected event"),
1357 (funding_locked, revoke_and_ack, commitment_update, order)
1362 /// pending_htlc_adds includes both the holding cell and in-flight update_add_htlcs, whereas
1363 /// for claims/fails they are separated out.
1364 pub fn reconnect_nodes<'a, 'b, 'c>(node_a: &Node<'a, 'b, 'c>, node_b: &Node<'a, 'b, 'c>, send_funding_locked: (bool, bool), pending_htlc_adds: (i64, i64), pending_htlc_claims: (usize, usize), pending_cell_htlc_claims: (usize, usize), pending_cell_htlc_fails: (usize, usize), pending_raa: (bool, bool)) {
1365 node_a.node.peer_connected(&node_b.node.get_our_node_id(), &msgs::Init { features: InitFeatures::empty() });
1366 let reestablish_1 = get_chan_reestablish_msgs!(node_a, node_b);
1367 node_b.node.peer_connected(&node_a.node.get_our_node_id(), &msgs::Init { features: InitFeatures::empty() });
1368 let reestablish_2 = get_chan_reestablish_msgs!(node_b, node_a);
1370 if send_funding_locked.0 {
1371 // If a expects a funding_locked, it better not think it has received a revoke_and_ack
1373 for reestablish in reestablish_1.iter() {
1374 assert_eq!(reestablish.next_remote_commitment_number, 0);
1377 if send_funding_locked.1 {
1378 // If b expects a funding_locked, it better not think it has received a revoke_and_ack
1380 for reestablish in reestablish_2.iter() {
1381 assert_eq!(reestablish.next_remote_commitment_number, 0);
1384 if send_funding_locked.0 || send_funding_locked.1 {
1385 // If we expect any funding_locked's, both sides better have set
1386 // next_local_commitment_number to 1
1387 for reestablish in reestablish_1.iter() {
1388 assert_eq!(reestablish.next_local_commitment_number, 1);
1390 for reestablish in reestablish_2.iter() {
1391 assert_eq!(reestablish.next_local_commitment_number, 1);
1395 let mut resp_1 = Vec::new();
1396 for msg in reestablish_1 {
1397 node_b.node.handle_channel_reestablish(&node_a.node.get_our_node_id(), &msg);
1398 resp_1.push(handle_chan_reestablish_msgs!(node_b, node_a));
1400 if pending_cell_htlc_claims.0 != 0 || pending_cell_htlc_fails.0 != 0 {
1401 check_added_monitors!(node_b, 1);
1403 check_added_monitors!(node_b, 0);
1406 let mut resp_2 = Vec::new();
1407 for msg in reestablish_2 {
1408 node_a.node.handle_channel_reestablish(&node_b.node.get_our_node_id(), &msg);
1409 resp_2.push(handle_chan_reestablish_msgs!(node_a, node_b));
1411 if pending_cell_htlc_claims.1 != 0 || pending_cell_htlc_fails.1 != 0 {
1412 check_added_monitors!(node_a, 1);
1414 check_added_monitors!(node_a, 0);
1417 // We don't yet support both needing updates, as that would require a different commitment dance:
1418 assert!((pending_htlc_adds.0 == 0 && pending_htlc_claims.0 == 0 && pending_cell_htlc_claims.0 == 0 && pending_cell_htlc_fails.0 == 0) ||
1419 (pending_htlc_adds.1 == 0 && pending_htlc_claims.1 == 0 && pending_cell_htlc_claims.1 == 0 && pending_cell_htlc_fails.1 == 0));
1421 for chan_msgs in resp_1.drain(..) {
1422 if send_funding_locked.0 {
1423 node_a.node.handle_funding_locked(&node_b.node.get_our_node_id(), &chan_msgs.0.unwrap());
1424 let announcement_event = node_a.node.get_and_clear_pending_msg_events();
1425 if !announcement_event.is_empty() {
1426 assert_eq!(announcement_event.len(), 1);
1427 if let MessageSendEvent::SendAnnouncementSignatures { .. } = announcement_event[0] {
1428 //TODO: Test announcement_sigs re-sending
1429 } else { panic!("Unexpected event!"); }
1432 assert!(chan_msgs.0.is_none());
1435 assert!(chan_msgs.3 == RAACommitmentOrder::RevokeAndACKFirst);
1436 node_a.node.handle_revoke_and_ack(&node_b.node.get_our_node_id(), &chan_msgs.1.unwrap());
1437 assert!(node_a.node.get_and_clear_pending_msg_events().is_empty());
1438 check_added_monitors!(node_a, 1);
1440 assert!(chan_msgs.1.is_none());
1442 if pending_htlc_adds.0 != 0 || pending_htlc_claims.0 != 0 || pending_cell_htlc_claims.0 != 0 || pending_cell_htlc_fails.0 != 0 {
1443 let commitment_update = chan_msgs.2.unwrap();
1444 if pending_htlc_adds.0 != -1 { // We use -1 to denote a response commitment_signed
1445 assert_eq!(commitment_update.update_add_htlcs.len(), pending_htlc_adds.0 as usize);
1447 assert!(commitment_update.update_add_htlcs.is_empty());
1449 assert_eq!(commitment_update.update_fulfill_htlcs.len(), pending_htlc_claims.0 + pending_cell_htlc_claims.0);
1450 assert_eq!(commitment_update.update_fail_htlcs.len(), pending_cell_htlc_fails.0);
1451 assert!(commitment_update.update_fail_malformed_htlcs.is_empty());
1452 for update_add in commitment_update.update_add_htlcs {
1453 node_a.node.handle_update_add_htlc(&node_b.node.get_our_node_id(), &update_add);
1455 for update_fulfill in commitment_update.update_fulfill_htlcs {
1456 node_a.node.handle_update_fulfill_htlc(&node_b.node.get_our_node_id(), &update_fulfill);
1458 for update_fail in commitment_update.update_fail_htlcs {
1459 node_a.node.handle_update_fail_htlc(&node_b.node.get_our_node_id(), &update_fail);
1462 if pending_htlc_adds.0 != -1 { // We use -1 to denote a response commitment_signed
1463 commitment_signed_dance!(node_a, node_b, commitment_update.commitment_signed, false);
1465 node_a.node.handle_commitment_signed(&node_b.node.get_our_node_id(), &commitment_update.commitment_signed);
1466 check_added_monitors!(node_a, 1);
1467 let as_revoke_and_ack = get_event_msg!(node_a, MessageSendEvent::SendRevokeAndACK, node_b.node.get_our_node_id());
1468 // No commitment_signed so get_event_msg's assert(len == 1) passes
1469 node_b.node.handle_revoke_and_ack(&node_a.node.get_our_node_id(), &as_revoke_and_ack);
1470 assert!(node_b.node.get_and_clear_pending_msg_events().is_empty());
1471 check_added_monitors!(node_b, 1);
1474 assert!(chan_msgs.2.is_none());
1478 for chan_msgs in resp_2.drain(..) {
1479 if send_funding_locked.1 {
1480 node_b.node.handle_funding_locked(&node_a.node.get_our_node_id(), &chan_msgs.0.unwrap());
1481 let announcement_event = node_b.node.get_and_clear_pending_msg_events();
1482 if !announcement_event.is_empty() {
1483 assert_eq!(announcement_event.len(), 1);
1484 if let MessageSendEvent::SendAnnouncementSignatures { .. } = announcement_event[0] {
1485 //TODO: Test announcement_sigs re-sending
1486 } else { panic!("Unexpected event!"); }
1489 assert!(chan_msgs.0.is_none());
1492 assert!(chan_msgs.3 == RAACommitmentOrder::RevokeAndACKFirst);
1493 node_b.node.handle_revoke_and_ack(&node_a.node.get_our_node_id(), &chan_msgs.1.unwrap());
1494 assert!(node_b.node.get_and_clear_pending_msg_events().is_empty());
1495 check_added_monitors!(node_b, 1);
1497 assert!(chan_msgs.1.is_none());
1499 if pending_htlc_adds.1 != 0 || pending_htlc_claims.1 != 0 || pending_cell_htlc_claims.1 != 0 || pending_cell_htlc_fails.1 != 0 {
1500 let commitment_update = chan_msgs.2.unwrap();
1501 if pending_htlc_adds.1 != -1 { // We use -1 to denote a response commitment_signed
1502 assert_eq!(commitment_update.update_add_htlcs.len(), pending_htlc_adds.1 as usize);
1504 assert_eq!(commitment_update.update_fulfill_htlcs.len(), pending_htlc_claims.0 + pending_cell_htlc_claims.0);
1505 assert_eq!(commitment_update.update_fail_htlcs.len(), pending_cell_htlc_fails.0);
1506 assert!(commitment_update.update_fail_malformed_htlcs.is_empty());
1507 for update_add in commitment_update.update_add_htlcs {
1508 node_b.node.handle_update_add_htlc(&node_a.node.get_our_node_id(), &update_add);
1510 for update_fulfill in commitment_update.update_fulfill_htlcs {
1511 node_b.node.handle_update_fulfill_htlc(&node_a.node.get_our_node_id(), &update_fulfill);
1513 for update_fail in commitment_update.update_fail_htlcs {
1514 node_b.node.handle_update_fail_htlc(&node_a.node.get_our_node_id(), &update_fail);
1517 if pending_htlc_adds.1 != -1 { // We use -1 to denote a response commitment_signed
1518 commitment_signed_dance!(node_b, node_a, commitment_update.commitment_signed, false);
1520 node_b.node.handle_commitment_signed(&node_a.node.get_our_node_id(), &commitment_update.commitment_signed);
1521 check_added_monitors!(node_b, 1);
1522 let bs_revoke_and_ack = get_event_msg!(node_b, MessageSendEvent::SendRevokeAndACK, node_a.node.get_our_node_id());
1523 // No commitment_signed so get_event_msg's assert(len == 1) passes
1524 node_a.node.handle_revoke_and_ack(&node_b.node.get_our_node_id(), &bs_revoke_and_ack);
1525 assert!(node_a.node.get_and_clear_pending_msg_events().is_empty());
1526 check_added_monitors!(node_a, 1);
1529 assert!(chan_msgs.2.is_none());