X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fln%2Fmonitor_tests.rs;h=5bd2e87ba5c15ca3f1ef998bafc15b92e5c88c68;hb=ba1349982ba28657c9e2d03a5b02c3ecc054b5cc;hp=f4dedd89eb907dcf557161737c054cb78f8f75d1;hpb=369eea45a1efadda2dc1fe6496dfdcaad0c4d1e1;p=rust-lightning diff --git a/lightning/src/ln/monitor_tests.rs b/lightning/src/ln/monitor_tests.rs index f4dedd89..5bd2e87b 100644 --- a/lightning/src/ln/monitor_tests.rs +++ b/lightning/src/ln/monitor_tests.rs @@ -1775,7 +1775,7 @@ fn test_yield_anchors_events() { let mut htlc_txs = Vec::with_capacity(2); for event in holder_events { match event { - Event::BumpTransaction(BumpTransactionEvent::HTLCResolution { htlc_descriptors, .. }) => { + Event::BumpTransaction(BumpTransactionEvent::HTLCResolution { htlc_descriptors, tx_lock_time, .. }) => { assert_eq!(htlc_descriptors.len(), 1); let htlc_descriptor = &htlc_descriptors[0]; let signer = nodes[0].keys_manager.derive_channel_keys( @@ -1784,11 +1784,7 @@ fn test_yield_anchors_events() { let per_commitment_point = signer.get_per_commitment_point(htlc_descriptor.per_commitment_number, &secp); let mut htlc_tx = Transaction { version: 2, - lock_time: if htlc_descriptor.htlc.offered { - PackedLockTime(htlc_descriptor.htlc.cltv_expiry) - } else { - PackedLockTime::ZERO - }, + lock_time: tx_lock_time, input: vec![ htlc_descriptor.unsigned_tx_input(), // HTLC input TxIn { ..Default::default() } // Fee input @@ -1859,15 +1855,18 @@ fn test_anchors_aggregated_revoked_htlc_tx() { let chan_a = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1_000_000, 20_000_000); let chan_b = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1_000_000, 20_000_000); + // Serialize Bob with the initial state of both channels, which we'll use later. + let bob_serialized = nodes[1].node.encode(); + // Route two payments for each channel from Alice to Bob to lock in the HTLCs. let payment_a = route_payment(&nodes[0], &[&nodes[1]], 50_000_000); let payment_b = route_payment(&nodes[0], &[&nodes[1]], 50_000_000); let payment_c = route_payment(&nodes[0], &[&nodes[1]], 50_000_000); let payment_d = route_payment(&nodes[0], &[&nodes[1]], 50_000_000); - // Serialize Bob with the HTLCs locked in. We'll restart Bob later on with the state at this - // point such that he broadcasts a revoked commitment transaction. - let bob_serialized = nodes[1].node.encode(); + // Serialize Bob's monitors with the HTLCs locked in. We'll restart Bob later on with the state + // at this point such that he broadcasts a revoked commitment transaction with the HTLCs + // present. let bob_serialized_monitor_a = get_monitor!(nodes[1], chan_a.2).encode(); let bob_serialized_monitor_b = get_monitor!(nodes[1], chan_b.2).encode(); @@ -1897,30 +1896,26 @@ fn test_anchors_aggregated_revoked_htlc_tx() { } } - // Bob force closes by broadcasting his revoked state for each channel. - nodes[1].node.force_close_broadcasting_latest_txn(&chan_a.2, &nodes[0].node.get_our_node_id()).unwrap(); - check_added_monitors(&nodes[1], 1); - check_closed_broadcast(&nodes[1], 1, true); - check_closed_event!(&nodes[1], 1, ClosureReason::HolderForceClosed); - let revoked_commitment_a = { - let mut txn = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0); - assert_eq!(txn.len(), 1); - let revoked_commitment = txn.pop().unwrap(); - assert_eq!(revoked_commitment.output.len(), 6); // 2 HTLC outputs + 1 to_self output + 1 to_remote output + 2 anchor outputs - check_spends!(revoked_commitment, chan_a.3); - revoked_commitment - }; - nodes[1].node.force_close_broadcasting_latest_txn(&chan_b.2, &nodes[0].node.get_our_node_id()).unwrap(); - check_added_monitors(&nodes[1], 1); - check_closed_broadcast(&nodes[1], 1, true); - check_closed_event!(&nodes[1], 1, ClosureReason::HolderForceClosed); - let revoked_commitment_b = { - let mut txn = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0); - assert_eq!(txn.len(), 1); - let revoked_commitment = txn.pop().unwrap(); - assert_eq!(revoked_commitment.output.len(), 6); // 2 HTLC outputs + 1 to_self output + 1 to_remote output + 2 anchor outputs - check_spends!(revoked_commitment, chan_b.3); - revoked_commitment + // Bob force closes by restarting with the outdated state, prompting the ChannelMonitors to + // broadcast the latest commitment transaction known to them, which in our case is the one with + // the HTLCs still pending. + nodes[1].node.timer_tick_occurred(); + check_added_monitors(&nodes[1], 2); + check_closed_event!(&nodes[1], 2, ClosureReason::OutdatedChannelManager); + let (revoked_commitment_a, revoked_commitment_b) = { + let txn = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0); + assert_eq!(txn.len(), 2); + assert_eq!(txn[0].output.len(), 6); // 2 HTLC outputs + 1 to_self output + 1 to_remote output + 2 anchor outputs + assert_eq!(txn[1].output.len(), 6); // 2 HTLC outputs + 1 to_self output + 1 to_remote output + 2 anchor outputs + if txn[0].input[0].previous_output.txid == chan_a.3.txid() { + check_spends!(&txn[0], &chan_a.3); + check_spends!(&txn[1], &chan_b.3); + (txn[0].clone(), txn[1].clone()) + } else { + check_spends!(&txn[1], &chan_a.3); + check_spends!(&txn[0], &chan_b.3); + (txn[1].clone(), txn[0].clone()) + } }; // Bob should now receive two events to bump his revoked commitment transaction fees. @@ -2064,7 +2059,7 @@ fn test_anchors_aggregated_revoked_htlc_tx() { }; let mut descriptors = Vec::with_capacity(4); for event in events { - if let Event::BumpTransaction(BumpTransactionEvent::HTLCResolution { mut htlc_descriptors, .. }) = event { + if let Event::BumpTransaction(BumpTransactionEvent::HTLCResolution { mut htlc_descriptors, tx_lock_time, .. }) = event { assert_eq!(htlc_descriptors.len(), 2); for htlc_descriptor in &htlc_descriptors { assert!(!htlc_descriptor.htlc.offered); @@ -2076,6 +2071,7 @@ fn test_anchors_aggregated_revoked_htlc_tx() { htlc_tx.output.push(htlc_descriptor.tx_output(&per_commitment_point, &secp)); } descriptors.append(&mut htlc_descriptors); + htlc_tx.lock_time = tx_lock_time; } else { panic!("Unexpected event"); }