X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=fuzz%2Fsrc%2Fchanmon_consistency.rs;h=b879ec9b2fcb82c61c78ae95cf4c02efdd15f7bd;hb=306e9a5acf7553b966030cc0ba177d2743675ea5;hp=3e205c07183d402fe045110d562f94b084224155;hpb=b5d88a5422913a0a8950455c5f86764a042429d7;p=rust-lightning diff --git a/fuzz/src/chanmon_consistency.rs b/fuzz/src/chanmon_consistency.rs index 3e205c07..b879ec9b 100644 --- a/fuzz/src/chanmon_consistency.rs +++ b/fuzz/src/chanmon_consistency.rs @@ -30,23 +30,22 @@ use bitcoin::hashes::sha256::Hash as Sha256; use bitcoin::hash_types::{BlockHash, WPubkeyHash}; use lightning::chain; -use lightning::chain::chainmonitor; -use lightning::chain::channelmonitor; +use lightning::chain::{BestBlock, chainmonitor, channelmonitor, Confirm, Watch}; use lightning::chain::channelmonitor::{ChannelMonitor, ChannelMonitorUpdateErr, MonitorEvent}; use lightning::chain::transaction::OutPoint; use lightning::chain::chaininterface::{BroadcasterInterface, ConfirmationTarget, FeeEstimator}; use lightning::chain::keysinterface::{KeysInterface, InMemorySigner}; -use lightning::ln::channelmanager::{ChainParameters, ChannelManager, PaymentHash, PaymentPreimage, PaymentSecret, PaymentSendFailure, ChannelManagerReadArgs}; +use lightning::ln::{PaymentHash, PaymentPreimage, PaymentSecret}; +use lightning::ln::channelmanager::{ChainParameters, ChannelManager, PaymentSendFailure, ChannelManagerReadArgs}; use lightning::ln::features::{ChannelFeatures, InitFeatures, NodeFeatures}; -use lightning::ln::msgs::{CommitmentUpdate, ChannelMessageHandler, DecodeError, ErrorAction, UpdateAddHTLC, Init}; +use lightning::ln::msgs::{CommitmentUpdate, ChannelMessageHandler, DecodeError, UpdateAddHTLC, Init}; use lightning::util::enforcing_trait_impls::{EnforcingSigner, INITIAL_REVOKED_COMMITMENT_NUMBER}; use lightning::util::errors::APIError; use lightning::util::events; use lightning::util::logger::Logger; use lightning::util::config::UserConfig; -use lightning::util::events::{EventsProvider, MessageSendEventsProvider}; +use lightning::util::events::MessageSendEventsProvider; use lightning::util::ser::{Readable, ReadableArgs, Writeable, Writer}; -use lightning::util::test_utils::OnlyReadsKeysInterface; use lightning::routing::router::{Route, RouteHop}; @@ -54,6 +53,7 @@ use utils::test_logger; use utils::test_persister::TestPersister; use bitcoin::secp256k1::key::{PublicKey,SecretKey}; +use bitcoin::secp256k1::recovery::RecoverableSignature; use bitcoin::secp256k1::Secp256k1; use std::mem; @@ -88,6 +88,7 @@ impl Writer for VecWriter { struct TestChainMonitor { pub logger: Arc, + pub keys: Arc, pub chain_monitor: Arc, Arc, Arc, Arc, Arc>>, pub update_ret: Mutex>, // If we reload a node with an old copy of ChannelMonitors, the ChannelManager deserialization @@ -99,10 +100,11 @@ struct TestChainMonitor { pub should_update_manager: atomic::AtomicBool, } impl TestChainMonitor { - pub fn new(broadcaster: Arc, logger: Arc, feeest: Arc, persister: Arc) -> Self { + pub fn new(broadcaster: Arc, logger: Arc, feeest: Arc, persister: Arc, keys: Arc) -> Self { Self { chain_monitor: Arc::new(chainmonitor::ChainMonitor::new(None, broadcaster, logger.clone(), feeest, persister)), logger, + keys, update_ret: Mutex::new(Ok(())), latest_monitors: Mutex::new(HashMap::new()), should_update_manager: atomic::AtomicBool::new(false), @@ -128,12 +130,13 @@ impl chain::Watch for TestChainMonitor { hash_map::Entry::Vacant(_) => panic!("Didn't have monitor on update call"), }; let deserialized_monitor = <(BlockHash, channelmonitor::ChannelMonitor)>:: - read(&mut Cursor::new(&map_entry.get().1), &OnlyReadsKeysInterface {}).unwrap().1; + read(&mut Cursor::new(&map_entry.get().1), &*self.keys).unwrap().1; deserialized_monitor.update_monitor(&update, &&TestBroadcaster{}, &&FuzzEstimator{}, &self.logger).unwrap(); let mut ser = VecWriter(Vec::new()); deserialized_monitor.write(&mut ser).unwrap(); map_entry.insert((update.update_id, ser.0)); self.should_update_manager.store(true, atomic::Ordering::Relaxed); + assert!(self.chain_monitor.update_channel(funding_txo, update).is_ok()); self.update_ret.lock().unwrap().clone() } @@ -144,7 +147,7 @@ impl chain::Watch for TestChainMonitor { struct KeyProvider { node_id: u8, - rand_bytes_id: atomic::AtomicU8, + rand_bytes_id: atomic::AtomicU32, revoked_commitments: Mutex>>>, } impl KeysInterface for KeyProvider { @@ -176,7 +179,7 @@ impl KeysInterface for KeyProvider { SecretKey::from_slice(&[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, self.node_id]).unwrap(), SecretKey::from_slice(&[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, self.node_id]).unwrap(), SecretKey::from_slice(&[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, self.node_id]).unwrap(), - [id, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, self.node_id], + [id as u8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, self.node_id], channel_value_satoshis, [0; 32], ); @@ -186,7 +189,9 @@ impl KeysInterface for KeyProvider { fn get_secure_random_bytes(&self) -> [u8; 32] { let id = self.rand_bytes_id.fetch_add(1, atomic::Ordering::Relaxed); - [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, id, 11, self.node_id] + let mut res = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, self.node_id]; + res[30-4..30].copy_from_slice(&id.to_le_bytes()); + res } fn read_chan_signer(&self, buffer: &[u8]) -> Result { @@ -204,6 +209,10 @@ impl KeysInterface for KeyProvider { disable_revocation_policy_check: false, }) } + + fn sign_invoice(&self, _invoice_preimage: Vec) -> Result { + unreachable!() + } } impl KeyProvider { @@ -232,9 +241,10 @@ fn check_api_err(api_err: APIError) { _ if err.starts_with("Cannot push more than their max accepted HTLCs ") => {}, _ if err.starts_with("Cannot send value that would put us over the max HTLC value in flight our peer will accept ") => {}, _ if err.starts_with("Cannot send value that would put our balance under counterparty-announced channel reserve value") => {}, + _ if err.starts_with("Cannot send value that would put counterparty balance under holder-announced channel reserve value") => {}, _ if err.starts_with("Cannot send value that would overdraw remaining funds.") => {}, _ if err.starts_with("Cannot send value that would not leave enough to pay for fees.") => {}, - _ => panic!(err), + _ => panic!("{}", err), } }, APIError::MonitorUpdateFailed => { @@ -260,45 +270,58 @@ fn check_payment_err(send_err: PaymentSendFailure) { type ChanMan = ChannelManager, Arc, Arc, Arc, Arc>; +#[inline] +fn get_payment_secret_hash(dest: &ChanMan, payment_id: &mut u8) -> Option<(PaymentSecret, PaymentHash)> { + let mut payment_hash; + for _ in 0..256 { + payment_hash = PaymentHash(Sha256::hash(&[*payment_id; 1]).into_inner()); + if let Ok(payment_secret) = dest.create_inbound_payment_for_hash(payment_hash, None, 3600, 0) { + return Some((payment_secret, payment_hash)); + } + *payment_id = payment_id.wrapping_add(1); + } + None +} + #[inline] fn send_payment(source: &ChanMan, dest: &ChanMan, dest_chan_id: u64, amt: u64, payment_id: &mut u8) -> bool { - let payment_hash = Sha256::hash(&[*payment_id; 1]); - *payment_id = payment_id.wrapping_add(1); + let (payment_secret, payment_hash) = + if let Some((secret, hash)) = get_payment_secret_hash(dest, payment_id) { (secret, hash) } else { return true; }; if let Err(err) = source.send_payment(&Route { paths: vec![vec![RouteHop { pubkey: dest.get_our_node_id(), - node_features: NodeFeatures::empty(), + node_features: NodeFeatures::known(), short_channel_id: dest_chan_id, - channel_features: ChannelFeatures::empty(), + channel_features: ChannelFeatures::known(), fee_msat: amt, cltv_expiry_delta: 200, }]], - }, PaymentHash(payment_hash.into_inner()), &None) { + }, payment_hash, &Some(payment_secret)) { check_payment_err(err); false } else { true } } #[inline] fn send_hop_payment(source: &ChanMan, middle: &ChanMan, middle_chan_id: u64, dest: &ChanMan, dest_chan_id: u64, amt: u64, payment_id: &mut u8) -> bool { - let payment_hash = Sha256::hash(&[*payment_id; 1]); - *payment_id = payment_id.wrapping_add(1); + let (payment_secret, payment_hash) = + if let Some((secret, hash)) = get_payment_secret_hash(dest, payment_id) { (secret, hash) } else { return true; }; if let Err(err) = source.send_payment(&Route { paths: vec![vec![RouteHop { pubkey: middle.get_our_node_id(), - node_features: NodeFeatures::empty(), + node_features: NodeFeatures::known(), short_channel_id: middle_chan_id, - channel_features: ChannelFeatures::empty(), + channel_features: ChannelFeatures::known(), fee_msat: 50000, cltv_expiry_delta: 100, },RouteHop { pubkey: dest.get_our_node_id(), - node_features: NodeFeatures::empty(), + node_features: NodeFeatures::known(), short_channel_id: dest_chan_id, - channel_features: ChannelFeatures::empty(), + channel_features: ChannelFeatures::known(), fee_msat: amt, cltv_expiry_delta: 200, }]], - }, PaymentHash(payment_hash.into_inner()), &None) { + }, payment_hash, &Some(payment_secret)) { check_payment_err(err); false } else { true } @@ -312,18 +335,16 @@ pub fn do_test(data: &[u8], out: Out) { macro_rules! make_node { ($node_id: expr) => { { let logger: Arc = Arc::new(test_logger::TestLogger::new($node_id.to_string(), out.clone())); - let monitor = Arc::new(TestChainMonitor::new(broadcast.clone(), logger.clone(), fee_est.clone(), Arc::new(TestPersister{}))); + let keys_manager = Arc::new(KeyProvider { node_id: $node_id, rand_bytes_id: atomic::AtomicU32::new(0), revoked_commitments: Mutex::new(HashMap::new()) }); + let monitor = Arc::new(TestChainMonitor::new(broadcast.clone(), logger.clone(), fee_est.clone(), Arc::new(TestPersister{}), Arc::clone(&keys_manager))); - let keys_manager = Arc::new(KeyProvider { node_id: $node_id, rand_bytes_id: atomic::AtomicU8::new(0), revoked_commitments: Mutex::new(HashMap::new()) }); let mut config = UserConfig::default(); - config.channel_options.fee_proportional_millionths = 0; + config.channel_options.forwarding_fee_proportional_millionths = 0; config.channel_options.announced_channel = true; - config.peer_channel_config_limits.min_dust_limit_satoshis = 0; let network = Network::Bitcoin; let params = ChainParameters { network, - latest_hash: genesis_block(network).block_hash(), - latest_height: 0, + best_block: BestBlock::from_genesis(network), }; (ChannelManager::new(fee_est.clone(), monitor.clone(), broadcast.clone(), Arc::clone(&logger), keys_manager.clone(), config, params), monitor, keys_manager) @@ -334,17 +355,16 @@ pub fn do_test(data: &[u8], out: Out) { ($ser: expr, $node_id: expr, $old_monitors: expr, $keys_manager: expr) => { { let keys_manager = Arc::clone(& $keys_manager); let logger: Arc = Arc::new(test_logger::TestLogger::new($node_id.to_string(), out.clone())); - let chain_monitor = Arc::new(TestChainMonitor::new(broadcast.clone(), logger.clone(), fee_est.clone(), Arc::new(TestPersister{}))); + let chain_monitor = Arc::new(TestChainMonitor::new(broadcast.clone(), logger.clone(), fee_est.clone(), Arc::new(TestPersister{}), Arc::clone(& $keys_manager))); let mut config = UserConfig::default(); - config.channel_options.fee_proportional_millionths = 0; + config.channel_options.forwarding_fee_proportional_millionths = 0; config.channel_options.announced_channel = true; - config.peer_channel_config_limits.min_dust_limit_satoshis = 0; let mut monitors = HashMap::new(); let mut old_monitors = $old_monitors.latest_monitors.lock().unwrap(); for (outpoint, (update_id, monitor_ser)) in old_monitors.drain() { - monitors.insert(outpoint, <(BlockHash, ChannelMonitor)>::read(&mut Cursor::new(&monitor_ser), &OnlyReadsKeysInterface {}).expect("Failed to read monitor").1); + monitors.insert(outpoint, <(BlockHash, ChannelMonitor)>::read(&mut Cursor::new(&monitor_ser), &*$keys_manager).expect("Failed to read monitor").1); chain_monitor.latest_monitors.lock().unwrap().insert(outpoint, (update_id, monitor_ser)); } let mut monitor_refs = HashMap::new(); @@ -362,7 +382,11 @@ pub fn do_test(data: &[u8], out: Out) { channel_monitors: monitor_refs, }; - (<(BlockHash, ChanMan)>::read(&mut Cursor::new(&$ser.0), read_args).expect("Failed to read manager").1, chain_monitor) + let res = (<(BlockHash, ChanMan)>::read(&mut Cursor::new(&$ser.0), read_args).expect("Failed to read manager").1, chain_monitor.clone()); + for (funding_txo, mon) in monitors.drain() { + assert!(chain_monitor.chain_monitor.watch_channel(funding_txo, mon).is_ok()); + } + res } } } @@ -397,7 +421,7 @@ pub fn do_test(data: &[u8], out: Out) { value: *channel_value_satoshis, script_pubkey: output_script.clone(), }]}; funding_output = OutPoint { txid: tx.txid(), index: 0 }; - $source.funding_transaction_generated(&temporary_channel_id, funding_output); + $source.funding_transaction_generated(&temporary_channel_id, tx.clone()).unwrap(); channel_txn.push(tx); } else { panic!("Wrong event type"); } } @@ -420,25 +444,20 @@ pub fn do_test(data: &[u8], out: Out) { }; $source.handle_funding_signed(&$dest.get_our_node_id(), &funding_signed); - { - let events = $source.get_and_clear_pending_events(); - assert_eq!(events.len(), 1); - if let events::Event::FundingBroadcastSafe { .. } = events[0] { - } else { panic!("Wrong event type"); } - } funding_output } } } macro_rules! confirm_txn { ($node: expr) => { { - let mut header = BlockHeader { version: 0x20000000, prev_blockhash: Default::default(), merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 }; + let chain_hash = genesis_block(Network::Bitcoin).block_hash(); + let mut header = BlockHeader { version: 0x20000000, prev_blockhash: chain_hash, merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 }; let txdata: Vec<_> = channel_txn.iter().enumerate().map(|(i, tx)| (i + 1, tx)).collect(); - $node.block_connected(&header, &txdata, 1); - for i in 2..100 { + $node.transactions_confirmed(&header, &txdata, 1); + for _ in 2..100 { header = BlockHeader { version: 0x20000000, prev_blockhash: header.block_hash(), merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 }; - $node.block_connected(&header, &[], i); } + $node.best_block_updated(&header, 99); } } } @@ -494,8 +513,10 @@ pub fn do_test(data: &[u8], out: Out) { let mut chan_a_disconnected = false; let mut chan_b_disconnected = false; + let mut ab_events = Vec::new(); let mut ba_events = Vec::new(); let mut bc_events = Vec::new(); + let mut cb_events = Vec::new(); let mut node_a_ser = VecWriter(Vec::new()); nodes[0].write(&mut node_a_ser).unwrap(); @@ -528,68 +549,92 @@ pub fn do_test(data: &[u8], out: Out) { } loop { - macro_rules! send_payment_with_secret { - ($source: expr, $middle: expr, $dest: expr) => { { - let payment_hash = Sha256::hash(&[payment_id; 1]); - payment_id = payment_id.wrapping_add(1); - let payment_secret = Sha256::hash(&[payment_id; 1]); - payment_id = payment_id.wrapping_add(1); - if let Err(err) = $source.send_payment(&Route { - paths: vec![vec![RouteHop { - pubkey: $middle.0.get_our_node_id(), - node_features: NodeFeatures::empty(), - short_channel_id: $middle.1, - channel_features: ChannelFeatures::empty(), - fee_msat: 50_000, - cltv_expiry_delta: 100, - },RouteHop { - pubkey: $dest.0.get_our_node_id(), - node_features: NodeFeatures::empty(), - short_channel_id: $dest.1, - channel_features: ChannelFeatures::empty(), - fee_msat: 10_000_000, - cltv_expiry_delta: 200, - }],vec![RouteHop { - pubkey: $middle.0.get_our_node_id(), - node_features: NodeFeatures::empty(), - short_channel_id: $middle.1, - channel_features: ChannelFeatures::empty(), - fee_msat: 50_000, - cltv_expiry_delta: 100, - },RouteHop { - pubkey: $dest.0.get_our_node_id(), - node_features: NodeFeatures::empty(), - short_channel_id: $dest.1, - channel_features: ChannelFeatures::empty(), - fee_msat: 10_000_000, - cltv_expiry_delta: 200, - }]], - }, PaymentHash(payment_hash.into_inner()), &Some(PaymentSecret(payment_secret.into_inner()))) { - check_payment_err(err); + // Push any events from Node B onto ba_events and bc_events + macro_rules! push_excess_b_events { + ($excess_events: expr, $expect_drop_node: expr) => { { + let a_id = nodes[0].get_our_node_id(); + let expect_drop_node: Option = $expect_drop_node; + let expect_drop_id = if let Some(id) = expect_drop_node { Some(nodes[id].get_our_node_id()) } else { None }; + for event in $excess_events { + let push_a = match event { + events::MessageSendEvent::UpdateHTLCs { ref node_id, .. } => { + if Some(*node_id) == expect_drop_id { panic!("peer_disconnected should drop msgs bound for the disconnected peer"); } + *node_id == a_id + }, + events::MessageSendEvent::SendRevokeAndACK { ref node_id, .. } => { + if Some(*node_id) == expect_drop_id { panic!("peer_disconnected should drop msgs bound for the disconnected peer"); } + *node_id == a_id + }, + events::MessageSendEvent::SendChannelReestablish { ref node_id, .. } => { + if Some(*node_id) == expect_drop_id { panic!("peer_disconnected should drop msgs bound for the disconnected peer"); } + *node_id == a_id + }, + events::MessageSendEvent::SendFundingLocked { .. } => continue, + events::MessageSendEvent::SendAnnouncementSignatures { .. } => continue, + events::MessageSendEvent::PaymentFailureNetworkUpdate { .. } => continue, + events::MessageSendEvent::SendChannelUpdate { ref node_id, ref msg } => { + assert_eq!(msg.contents.flags & 2, 0); // The disable bit must never be set! + if Some(*node_id) == expect_drop_id { panic!("peer_disconnected should drop msgs bound for the disconnected peer"); } + *node_id == a_id + }, + _ => panic!("Unhandled message event {:?}", event), + }; + if push_a { ba_events.push(event); } else { bc_events.push(event); } } } } } + // While delivering messages, we select across three possible message selection processes + // to ensure we get as much coverage as possible. See the individual enum variants for more + // details. + #[derive(PartialEq)] + enum ProcessMessages { + /// Deliver all available messages, including fetching any new messages from + /// `get_and_clear_pending_msg_events()` (which may have side effects). + AllMessages, + /// Call `get_and_clear_pending_msg_events()` first, and then deliver up to one + /// message (which may already be queued). + OneMessage, + /// Deliver up to one already-queued message. This avoids any potential side-effects + /// of `get_and_clear_pending_msg_events()` (eg freeing the HTLC holding cell), which + /// provides potentially more coverage. + OnePendingMessage, + } + macro_rules! process_msg_events { - ($node: expr, $corrupt_forward: expr) => { { - let events = if $node == 1 { + ($node: expr, $corrupt_forward: expr, $limit_events: expr) => { { + let mut events = if $node == 1 { let mut new_events = Vec::new(); mem::swap(&mut new_events, &mut ba_events); new_events.extend_from_slice(&bc_events[..]); bc_events.clear(); new_events - } else { Vec::new() }; + } else if $node == 0 { + let mut new_events = Vec::new(); + mem::swap(&mut new_events, &mut ab_events); + new_events + } else { + let mut new_events = Vec::new(); + mem::swap(&mut new_events, &mut cb_events); + new_events + }; + let mut new_events = Vec::new(); + if $limit_events != ProcessMessages::OnePendingMessage { + new_events = nodes[$node].get_and_clear_pending_msg_events(); + } let mut had_events = false; - for event in events.iter().chain(nodes[$node].get_and_clear_pending_msg_events().iter()) { + let mut events_iter = events.drain(..).chain(new_events.drain(..)); + let mut extra_ev = None; + for event in &mut events_iter { had_events = true; match event { - events::MessageSendEvent::UpdateHTLCs { ref node_id, updates: CommitmentUpdate { ref update_add_htlcs, ref update_fail_htlcs, ref update_fulfill_htlcs, ref update_fail_malformed_htlcs, ref update_fee, ref commitment_signed } } => { + events::MessageSendEvent::UpdateHTLCs { node_id, updates: CommitmentUpdate { update_add_htlcs, update_fail_htlcs, update_fulfill_htlcs, update_fail_malformed_htlcs, update_fee, commitment_signed } } => { for dest in nodes.iter() { - if dest.get_our_node_id() == *node_id { + if dest.get_our_node_id() == node_id { assert!(update_fee.is_none()); - for update_add in update_add_htlcs { + for update_add in update_add_htlcs.iter() { if !$corrupt_forward { - dest.handle_update_add_htlc(&nodes[$node].get_our_node_id(), &update_add); + dest.handle_update_add_htlc(&nodes[$node].get_our_node_id(), update_add); } else { // Corrupt the update_add_htlc message so that its HMAC // check will fail and we generate a @@ -601,16 +646,31 @@ pub fn do_test(data: &[u8], out: Out) { dest.handle_update_add_htlc(&nodes[$node].get_our_node_id(), &new_msg); } } - for update_fulfill in update_fulfill_htlcs { - dest.handle_update_fulfill_htlc(&nodes[$node].get_our_node_id(), &update_fulfill); + for update_fulfill in update_fulfill_htlcs.iter() { + dest.handle_update_fulfill_htlc(&nodes[$node].get_our_node_id(), update_fulfill); } - for update_fail in update_fail_htlcs { - dest.handle_update_fail_htlc(&nodes[$node].get_our_node_id(), &update_fail); + for update_fail in update_fail_htlcs.iter() { + dest.handle_update_fail_htlc(&nodes[$node].get_our_node_id(), update_fail); } - for update_fail_malformed in update_fail_malformed_htlcs { - dest.handle_update_fail_malformed_htlc(&nodes[$node].get_our_node_id(), &update_fail_malformed); + for update_fail_malformed in update_fail_malformed_htlcs.iter() { + dest.handle_update_fail_malformed_htlc(&nodes[$node].get_our_node_id(), update_fail_malformed); + } + let processed_change = !update_add_htlcs.is_empty() || !update_fulfill_htlcs.is_empty() || + !update_fail_htlcs.is_empty() || !update_fail_malformed_htlcs.is_empty(); + if $limit_events != ProcessMessages::AllMessages && processed_change { + // If we only want to process some messages, don't deliver the CS until later. + extra_ev = Some(events::MessageSendEvent::UpdateHTLCs { node_id, updates: CommitmentUpdate { + update_add_htlcs: Vec::new(), + update_fail_htlcs: Vec::new(), + update_fulfill_htlcs: Vec::new(), + update_fail_malformed_htlcs: Vec::new(), + update_fee: None, + commitment_signed + } }); + break; } dest.handle_commitment_signed(&nodes[$node].get_our_node_id(), &commitment_signed); + break; } } }, @@ -631,13 +691,37 @@ pub fn do_test(data: &[u8], out: Out) { events::MessageSendEvent::SendFundingLocked { .. } => { // Can be generated as a reestablish response }, + events::MessageSendEvent::SendAnnouncementSignatures { .. } => { + // Can be generated as a reestablish response + }, events::MessageSendEvent::PaymentFailureNetworkUpdate { .. } => { // Can be generated due to a payment forward being rejected due to a // channel having previously failed a monitor update }, - _ => panic!("Unhandled message event"), + events::MessageSendEvent::SendChannelUpdate { ref msg, .. } => { + // When we reconnect we will resend a channel_update to make sure our + // counterparty has the latest parameters for receiving payments + // through us. We do, however, check that the message does not include + // the "disabled" bit, as we should never ever have a channel which is + // disabled when we send such an update (or it may indicate channel + // force-close which we should detect as an error). + assert_eq!(msg.contents.flags & 2, 0); + }, + _ => panic!("Unhandled message event {:?}", event), + } + if $limit_events != ProcessMessages::AllMessages { + break; } } + if $node == 1 { + push_excess_b_events!(extra_ev.into_iter().chain(events_iter), None); + } else if $node == 0 { + if let Some(ev) = extra_ev { ab_events.push(ev); } + for event in events_iter { ab_events.push(event); } + } else { + if let Some(ev) = extra_ev { cb_events.push(ev); } + for event in events_iter { cb_events.push(event); } + } had_events } } } @@ -651,11 +735,16 @@ pub fn do_test(data: &[u8], out: Out) { events::MessageSendEvent::SendRevokeAndACK { .. } => {}, events::MessageSendEvent::SendChannelReestablish { .. } => {}, events::MessageSendEvent::SendFundingLocked { .. } => {}, + events::MessageSendEvent::SendAnnouncementSignatures { .. } => {}, events::MessageSendEvent::PaymentFailureNetworkUpdate { .. } => {}, - events::MessageSendEvent::HandleError { action: ErrorAction::IgnoreError, .. } => {}, + events::MessageSendEvent::SendChannelUpdate { ref msg, .. } => { + assert_eq!(msg.contents.flags & 2, 0); // The disable bit must never be set! + }, _ => panic!("Unhandled message event"), } } + push_excess_b_events!(nodes[1].get_and_clear_pending_msg_events().drain(..), Some(0)); + ab_events.clear(); ba_events.clear(); } else { for event in nodes[2].get_and_clear_pending_msg_events() { @@ -664,33 +753,17 @@ pub fn do_test(data: &[u8], out: Out) { events::MessageSendEvent::SendRevokeAndACK { .. } => {}, events::MessageSendEvent::SendChannelReestablish { .. } => {}, events::MessageSendEvent::SendFundingLocked { .. } => {}, + events::MessageSendEvent::SendAnnouncementSignatures { .. } => {}, events::MessageSendEvent::PaymentFailureNetworkUpdate { .. } => {}, - events::MessageSendEvent::HandleError { action: ErrorAction::IgnoreError, .. } => {}, + events::MessageSendEvent::SendChannelUpdate { ref msg, .. } => { + assert_eq!(msg.contents.flags & 2, 0); // The disable bit must never be set! + }, _ => panic!("Unhandled message event"), } } + push_excess_b_events!(nodes[1].get_and_clear_pending_msg_events().drain(..), Some(2)); bc_events.clear(); - } - let mut events = nodes[1].get_and_clear_pending_msg_events(); - let drop_node_id = if $counterparty_id == 0 { nodes[0].get_our_node_id() } else { nodes[2].get_our_node_id() }; - let msg_sink = if $counterparty_id == 0 { &mut bc_events } else { &mut ba_events }; - for event in events.drain(..) { - let push = match event { - events::MessageSendEvent::UpdateHTLCs { ref node_id, .. } => { - if *node_id != drop_node_id { true } else { false } - }, - events::MessageSendEvent::SendRevokeAndACK { ref node_id, .. } => { - if *node_id != drop_node_id { true } else { false } - }, - events::MessageSendEvent::SendChannelReestablish { ref node_id, .. } => { - if *node_id != drop_node_id { true } else { false } - }, - events::MessageSendEvent::SendFundingLocked { .. } => false, - events::MessageSendEvent::PaymentFailureNetworkUpdate { .. } => false, - events::MessageSendEvent::HandleError { action: ErrorAction::IgnoreError, .. } => false, - _ => panic!("Unhandled message event"), - }; - if push { msg_sink.push(event); } + cb_events.clear(); } } } } @@ -721,12 +794,12 @@ pub fn do_test(data: &[u8], out: Out) { let had_events = !events.is_empty(); for event in events.drain(..) { match event { - events::Event::PaymentReceived { payment_hash, payment_secret, amt } => { + events::Event::PaymentReceived { payment_hash, .. } => { if claim_set.insert(payment_hash.0) { if $fail { - assert!(nodes[$node].fail_htlc_backwards(&payment_hash, &payment_secret)); + assert!(nodes[$node].fail_htlc_backwards(&payment_hash)); } else { - assert!(nodes[$node].claim_funds(PaymentPreimage(payment_hash.0), &payment_secret, amt)); + assert!(nodes[$node].claim_funds(PaymentPreimage(payment_hash.0))); } } }, @@ -793,47 +866,69 @@ pub fn do_test(data: &[u8], out: Out) { }, 0x0e => { if chan_a_disconnected { - nodes[0].peer_connected(&nodes[1].get_our_node_id(), &Init { features: InitFeatures::empty() }); - nodes[1].peer_connected(&nodes[0].get_our_node_id(), &Init { features: InitFeatures::empty() }); + nodes[0].peer_connected(&nodes[1].get_our_node_id(), &Init { features: InitFeatures::known() }); + nodes[1].peer_connected(&nodes[0].get_our_node_id(), &Init { features: InitFeatures::known() }); chan_a_disconnected = false; } }, 0x0f => { if chan_b_disconnected { - nodes[1].peer_connected(&nodes[2].get_our_node_id(), &Init { features: InitFeatures::empty() }); - nodes[2].peer_connected(&nodes[1].get_our_node_id(), &Init { features: InitFeatures::empty() }); + nodes[1].peer_connected(&nodes[2].get_our_node_id(), &Init { features: InitFeatures::known() }); + nodes[2].peer_connected(&nodes[1].get_our_node_id(), &Init { features: InitFeatures::known() }); chan_b_disconnected = false; } }, - 0x10 => { process_msg_events!(0, true); }, - 0x11 => { process_msg_events!(0, false); }, - 0x12 => { process_events!(0, true); }, - 0x13 => { process_events!(0, false); }, - 0x14 => { process_msg_events!(1, true); }, - 0x15 => { process_msg_events!(1, false); }, - 0x16 => { process_events!(1, true); }, - 0x17 => { process_events!(1, false); }, - 0x18 => { process_msg_events!(2, true); }, - 0x19 => { process_msg_events!(2, false); }, - 0x1a => { process_events!(2, true); }, - 0x1b => { process_events!(2, false); }, - - 0x1c => { + 0x10 => { process_msg_events!(0, true, ProcessMessages::AllMessages); }, + 0x11 => { process_msg_events!(0, false, ProcessMessages::AllMessages); }, + 0x12 => { process_msg_events!(0, true, ProcessMessages::OneMessage); }, + 0x13 => { process_msg_events!(0, false, ProcessMessages::OneMessage); }, + 0x14 => { process_msg_events!(0, true, ProcessMessages::OnePendingMessage); }, + 0x15 => { process_msg_events!(0, false, ProcessMessages::OnePendingMessage); }, + + 0x16 => { process_events!(0, true); }, + 0x17 => { process_events!(0, false); }, + + 0x18 => { process_msg_events!(1, true, ProcessMessages::AllMessages); }, + 0x19 => { process_msg_events!(1, false, ProcessMessages::AllMessages); }, + 0x1a => { process_msg_events!(1, true, ProcessMessages::OneMessage); }, + 0x1b => { process_msg_events!(1, false, ProcessMessages::OneMessage); }, + 0x1c => { process_msg_events!(1, true, ProcessMessages::OnePendingMessage); }, + 0x1d => { process_msg_events!(1, false, ProcessMessages::OnePendingMessage); }, + + 0x1e => { process_events!(1, true); }, + 0x1f => { process_events!(1, false); }, + + 0x20 => { process_msg_events!(2, true, ProcessMessages::AllMessages); }, + 0x21 => { process_msg_events!(2, false, ProcessMessages::AllMessages); }, + 0x22 => { process_msg_events!(2, true, ProcessMessages::OneMessage); }, + 0x23 => { process_msg_events!(2, false, ProcessMessages::OneMessage); }, + 0x24 => { process_msg_events!(2, true, ProcessMessages::OnePendingMessage); }, + 0x25 => { process_msg_events!(2, false, ProcessMessages::OnePendingMessage); }, + + 0x26 => { process_events!(2, true); }, + 0x27 => { process_events!(2, false); }, + + 0x2c => { if !chan_a_disconnected { nodes[1].peer_disconnected(&nodes[0].get_our_node_id(), false); chan_a_disconnected = true; drain_msg_events_on_disconnect!(0); } + if monitor_a.should_update_manager.load(atomic::Ordering::Relaxed) { + node_a_ser.0.clear(); + nodes[0].write(&mut node_a_ser).unwrap(); + } let (new_node_a, new_monitor_a) = reload_node!(node_a_ser, 0, monitor_a, keys_manager_a); nodes[0] = new_node_a; monitor_a = new_monitor_a; }, - 0x1d => { + 0x2d => { if !chan_a_disconnected { nodes[0].peer_disconnected(&nodes[1].get_our_node_id(), false); chan_a_disconnected = true; nodes[0].get_and_clear_pending_msg_events(); + ab_events.clear(); ba_events.clear(); } if !chan_b_disconnected { @@ -841,81 +936,83 @@ pub fn do_test(data: &[u8], out: Out) { chan_b_disconnected = true; nodes[2].get_and_clear_pending_msg_events(); bc_events.clear(); + cb_events.clear(); } let (new_node_b, new_monitor_b) = reload_node!(node_b_ser, 1, monitor_b, keys_manager_b); nodes[1] = new_node_b; monitor_b = new_monitor_b; }, - 0x1e => { + 0x2e => { if !chan_b_disconnected { nodes[1].peer_disconnected(&nodes[2].get_our_node_id(), false); chan_b_disconnected = true; drain_msg_events_on_disconnect!(2); } + if monitor_c.should_update_manager.load(atomic::Ordering::Relaxed) { + node_c_ser.0.clear(); + nodes[2].write(&mut node_c_ser).unwrap(); + } let (new_node_c, new_monitor_c) = reload_node!(node_c_ser, 2, monitor_c, keys_manager_c); nodes[2] = new_node_c; monitor_c = new_monitor_c; }, // 1/10th the channel size: - 0x20 => { send_payment(&nodes[0], &nodes[1], chan_a, 10_000_000, &mut payment_id); }, - 0x21 => { send_payment(&nodes[1], &nodes[0], chan_a, 10_000_000, &mut payment_id); }, - 0x22 => { send_payment(&nodes[1], &nodes[2], chan_b, 10_000_000, &mut payment_id); }, - 0x23 => { send_payment(&nodes[2], &nodes[1], chan_b, 10_000_000, &mut payment_id); }, - 0x24 => { send_hop_payment(&nodes[0], &nodes[1], chan_a, &nodes[2], chan_b, 10_000_000, &mut payment_id); }, - 0x25 => { send_hop_payment(&nodes[2], &nodes[1], chan_b, &nodes[0], chan_a, 10_000_000, &mut payment_id); }, - - 0x26 => { send_payment_with_secret!(nodes[0], (&nodes[1], chan_a), (&nodes[2], chan_b)); }, - 0x27 => { send_payment_with_secret!(nodes[2], (&nodes[1], chan_b), (&nodes[0], chan_a)); }, - - 0x28 => { send_payment(&nodes[0], &nodes[1], chan_a, 1_000_000, &mut payment_id); }, - 0x29 => { send_payment(&nodes[1], &nodes[0], chan_a, 1_000_000, &mut payment_id); }, - 0x2a => { send_payment(&nodes[1], &nodes[2], chan_b, 1_000_000, &mut payment_id); }, - 0x2b => { send_payment(&nodes[2], &nodes[1], chan_b, 1_000_000, &mut payment_id); }, - 0x2c => { send_hop_payment(&nodes[0], &nodes[1], chan_a, &nodes[2], chan_b, 1_000_000, &mut payment_id); }, - 0x2d => { send_hop_payment(&nodes[2], &nodes[1], chan_b, &nodes[0], chan_a, 1_000_000, &mut payment_id); }, - - 0x30 => { send_payment(&nodes[0], &nodes[1], chan_a, 100_000, &mut payment_id); }, - 0x31 => { send_payment(&nodes[1], &nodes[0], chan_a, 100_000, &mut payment_id); }, - 0x32 => { send_payment(&nodes[1], &nodes[2], chan_b, 100_000, &mut payment_id); }, - 0x33 => { send_payment(&nodes[2], &nodes[1], chan_b, 100_000, &mut payment_id); }, - 0x34 => { send_hop_payment(&nodes[0], &nodes[1], chan_a, &nodes[2], chan_b, 100_000, &mut payment_id); }, - 0x35 => { send_hop_payment(&nodes[2], &nodes[1], chan_b, &nodes[0], chan_a, 100_000, &mut payment_id); }, - - 0x38 => { send_payment(&nodes[0], &nodes[1], chan_a, 10_000, &mut payment_id); }, - 0x39 => { send_payment(&nodes[1], &nodes[0], chan_a, 10_000, &mut payment_id); }, - 0x3a => { send_payment(&nodes[1], &nodes[2], chan_b, 10_000, &mut payment_id); }, - 0x3b => { send_payment(&nodes[2], &nodes[1], chan_b, 10_000, &mut payment_id); }, - 0x3c => { send_hop_payment(&nodes[0], &nodes[1], chan_a, &nodes[2], chan_b, 10_000, &mut payment_id); }, - 0x3d => { send_hop_payment(&nodes[2], &nodes[1], chan_b, &nodes[0], chan_a, 10_000, &mut payment_id); }, - - 0x40 => { send_payment(&nodes[0], &nodes[1], chan_a, 1_000, &mut payment_id); }, - 0x41 => { send_payment(&nodes[1], &nodes[0], chan_a, 1_000, &mut payment_id); }, - 0x42 => { send_payment(&nodes[1], &nodes[2], chan_b, 1_000, &mut payment_id); }, - 0x43 => { send_payment(&nodes[2], &nodes[1], chan_b, 1_000, &mut payment_id); }, - 0x44 => { send_hop_payment(&nodes[0], &nodes[1], chan_a, &nodes[2], chan_b, 1_000, &mut payment_id); }, - 0x45 => { send_hop_payment(&nodes[2], &nodes[1], chan_b, &nodes[0], chan_a, 1_000, &mut payment_id); }, - - 0x48 => { send_payment(&nodes[0], &nodes[1], chan_a, 100, &mut payment_id); }, - 0x49 => { send_payment(&nodes[1], &nodes[0], chan_a, 100, &mut payment_id); }, - 0x4a => { send_payment(&nodes[1], &nodes[2], chan_b, 100, &mut payment_id); }, - 0x4b => { send_payment(&nodes[2], &nodes[1], chan_b, 100, &mut payment_id); }, - 0x4c => { send_hop_payment(&nodes[0], &nodes[1], chan_a, &nodes[2], chan_b, 100, &mut payment_id); }, - 0x4d => { send_hop_payment(&nodes[2], &nodes[1], chan_b, &nodes[0], chan_a, 100, &mut payment_id); }, - - 0x50 => { send_payment(&nodes[0], &nodes[1], chan_a, 10, &mut payment_id); }, - 0x51 => { send_payment(&nodes[1], &nodes[0], chan_a, 10, &mut payment_id); }, - 0x52 => { send_payment(&nodes[1], &nodes[2], chan_b, 10, &mut payment_id); }, - 0x53 => { send_payment(&nodes[2], &nodes[1], chan_b, 10, &mut payment_id); }, - 0x54 => { send_hop_payment(&nodes[0], &nodes[1], chan_a, &nodes[2], chan_b, 10, &mut payment_id); }, - 0x55 => { send_hop_payment(&nodes[2], &nodes[1], chan_b, &nodes[0], chan_a, 10, &mut payment_id); }, - - 0x58 => { send_payment(&nodes[0], &nodes[1], chan_a, 1, &mut payment_id); }, - 0x59 => { send_payment(&nodes[1], &nodes[0], chan_a, 1, &mut payment_id); }, - 0x5a => { send_payment(&nodes[1], &nodes[2], chan_b, 1, &mut payment_id); }, - 0x5b => { send_payment(&nodes[2], &nodes[1], chan_b, 1, &mut payment_id); }, - 0x5c => { send_hop_payment(&nodes[0], &nodes[1], chan_a, &nodes[2], chan_b, 1, &mut payment_id); }, - 0x5d => { send_hop_payment(&nodes[2], &nodes[1], chan_b, &nodes[0], chan_a, 1, &mut payment_id); }, + 0x30 => { send_payment(&nodes[0], &nodes[1], chan_a, 10_000_000, &mut payment_id); }, + 0x31 => { send_payment(&nodes[1], &nodes[0], chan_a, 10_000_000, &mut payment_id); }, + 0x32 => { send_payment(&nodes[1], &nodes[2], chan_b, 10_000_000, &mut payment_id); }, + 0x33 => { send_payment(&nodes[2], &nodes[1], chan_b, 10_000_000, &mut payment_id); }, + 0x34 => { send_hop_payment(&nodes[0], &nodes[1], chan_a, &nodes[2], chan_b, 10_000_000, &mut payment_id); }, + 0x35 => { send_hop_payment(&nodes[2], &nodes[1], chan_b, &nodes[0], chan_a, 10_000_000, &mut payment_id); }, + + 0x38 => { send_payment(&nodes[0], &nodes[1], chan_a, 1_000_000, &mut payment_id); }, + 0x39 => { send_payment(&nodes[1], &nodes[0], chan_a, 1_000_000, &mut payment_id); }, + 0x3a => { send_payment(&nodes[1], &nodes[2], chan_b, 1_000_000, &mut payment_id); }, + 0x3b => { send_payment(&nodes[2], &nodes[1], chan_b, 1_000_000, &mut payment_id); }, + 0x3c => { send_hop_payment(&nodes[0], &nodes[1], chan_a, &nodes[2], chan_b, 1_000_000, &mut payment_id); }, + 0x3d => { send_hop_payment(&nodes[2], &nodes[1], chan_b, &nodes[0], chan_a, 1_000_000, &mut payment_id); }, + + 0x40 => { send_payment(&nodes[0], &nodes[1], chan_a, 100_000, &mut payment_id); }, + 0x41 => { send_payment(&nodes[1], &nodes[0], chan_a, 100_000, &mut payment_id); }, + 0x42 => { send_payment(&nodes[1], &nodes[2], chan_b, 100_000, &mut payment_id); }, + 0x43 => { send_payment(&nodes[2], &nodes[1], chan_b, 100_000, &mut payment_id); }, + 0x44 => { send_hop_payment(&nodes[0], &nodes[1], chan_a, &nodes[2], chan_b, 100_000, &mut payment_id); }, + 0x45 => { send_hop_payment(&nodes[2], &nodes[1], chan_b, &nodes[0], chan_a, 100_000, &mut payment_id); }, + + 0x48 => { send_payment(&nodes[0], &nodes[1], chan_a, 10_000, &mut payment_id); }, + 0x49 => { send_payment(&nodes[1], &nodes[0], chan_a, 10_000, &mut payment_id); }, + 0x4a => { send_payment(&nodes[1], &nodes[2], chan_b, 10_000, &mut payment_id); }, + 0x4b => { send_payment(&nodes[2], &nodes[1], chan_b, 10_000, &mut payment_id); }, + 0x4c => { send_hop_payment(&nodes[0], &nodes[1], chan_a, &nodes[2], chan_b, 10_000, &mut payment_id); }, + 0x4d => { send_hop_payment(&nodes[2], &nodes[1], chan_b, &nodes[0], chan_a, 10_000, &mut payment_id); }, + + 0x50 => { send_payment(&nodes[0], &nodes[1], chan_a, 1_000, &mut payment_id); }, + 0x51 => { send_payment(&nodes[1], &nodes[0], chan_a, 1_000, &mut payment_id); }, + 0x52 => { send_payment(&nodes[1], &nodes[2], chan_b, 1_000, &mut payment_id); }, + 0x53 => { send_payment(&nodes[2], &nodes[1], chan_b, 1_000, &mut payment_id); }, + 0x54 => { send_hop_payment(&nodes[0], &nodes[1], chan_a, &nodes[2], chan_b, 1_000, &mut payment_id); }, + 0x55 => { send_hop_payment(&nodes[2], &nodes[1], chan_b, &nodes[0], chan_a, 1_000, &mut payment_id); }, + + 0x58 => { send_payment(&nodes[0], &nodes[1], chan_a, 100, &mut payment_id); }, + 0x59 => { send_payment(&nodes[1], &nodes[0], chan_a, 100, &mut payment_id); }, + 0x5a => { send_payment(&nodes[1], &nodes[2], chan_b, 100, &mut payment_id); }, + 0x5b => { send_payment(&nodes[2], &nodes[1], chan_b, 100, &mut payment_id); }, + 0x5c => { send_hop_payment(&nodes[0], &nodes[1], chan_a, &nodes[2], chan_b, 100, &mut payment_id); }, + 0x5d => { send_hop_payment(&nodes[2], &nodes[1], chan_b, &nodes[0], chan_a, 100, &mut payment_id); }, + + 0x60 => { send_payment(&nodes[0], &nodes[1], chan_a, 10, &mut payment_id); }, + 0x61 => { send_payment(&nodes[1], &nodes[0], chan_a, 10, &mut payment_id); }, + 0x62 => { send_payment(&nodes[1], &nodes[2], chan_b, 10, &mut payment_id); }, + 0x63 => { send_payment(&nodes[2], &nodes[1], chan_b, 10, &mut payment_id); }, + 0x64 => { send_hop_payment(&nodes[0], &nodes[1], chan_a, &nodes[2], chan_b, 10, &mut payment_id); }, + 0x65 => { send_hop_payment(&nodes[2], &nodes[1], chan_b, &nodes[0], chan_a, 10, &mut payment_id); }, + + 0x68 => { send_payment(&nodes[0], &nodes[1], chan_a, 1, &mut payment_id); }, + 0x69 => { send_payment(&nodes[1], &nodes[0], chan_a, 1, &mut payment_id); }, + 0x6a => { send_payment(&nodes[1], &nodes[2], chan_b, 1, &mut payment_id); }, + 0x6b => { send_payment(&nodes[2], &nodes[1], chan_b, 1, &mut payment_id); }, + 0x6c => { send_hop_payment(&nodes[0], &nodes[1], chan_a, &nodes[2], chan_b, 1, &mut payment_id); }, + 0x6d => { send_hop_payment(&nodes[2], &nodes[1], chan_b, &nodes[0], chan_a, 1, &mut payment_id); }, 0xff => { // Test that no channel is in a stuck state where neither party can send funds even @@ -941,22 +1038,22 @@ pub fn do_test(data: &[u8], out: Out) { // Next, make sure peers are all connected to each other if chan_a_disconnected { - nodes[0].peer_connected(&nodes[1].get_our_node_id(), &Init { features: InitFeatures::empty() }); - nodes[1].peer_connected(&nodes[0].get_our_node_id(), &Init { features: InitFeatures::empty() }); + nodes[0].peer_connected(&nodes[1].get_our_node_id(), &Init { features: InitFeatures::known() }); + nodes[1].peer_connected(&nodes[0].get_our_node_id(), &Init { features: InitFeatures::known() }); chan_a_disconnected = false; } if chan_b_disconnected { - nodes[1].peer_connected(&nodes[2].get_our_node_id(), &Init { features: InitFeatures::empty() }); - nodes[2].peer_connected(&nodes[1].get_our_node_id(), &Init { features: InitFeatures::empty() }); + nodes[1].peer_connected(&nodes[2].get_our_node_id(), &Init { features: InitFeatures::known() }); + nodes[2].peer_connected(&nodes[1].get_our_node_id(), &Init { features: InitFeatures::known() }); chan_b_disconnected = false; } for i in 0..std::usize::MAX { if i == 100 { panic!("It may take may iterations to settle the state, but it should not take forever"); } // Then, make sure any current forwards make their way to their destination - if process_msg_events!(0, false) { continue; } - if process_msg_events!(1, false) { continue; } - if process_msg_events!(2, false) { continue; } + if process_msg_events!(0, false, ProcessMessages::AllMessages) { continue; } + if process_msg_events!(1, false, ProcessMessages::AllMessages) { continue; } + if process_msg_events!(2, false, ProcessMessages::AllMessages) { continue; } // ...making sure any pending PendingHTLCsForwardable events are handled and // payments claimed. if process_events!(0, false) { continue; }