@@ -31,7 +31,7 @@ use crate::ln::features::{ChannelFeatures, NodeFeatures};
31
31
use crate::ln::msgs;
32
32
use crate::ln::msgs::{ChannelMessageHandler, RoutingMessageHandler, ErrorAction};
33
33
use crate::util::enforcing_trait_impls::EnforcingSigner;
34
- use crate :: util:: test_utils;
34
+ use crate::util::test_utils::{self, WatchtowerPersister} ;
35
35
use crate::util::errors::APIError;
36
36
use crate::util::ser::{Writeable, ReadableArgs};
37
37
use crate::util::string::UntrustedString;
@@ -2540,6 +2540,57 @@ fn revoked_output_claim() {
2540
2540
check_closed_event!(nodes[0], 1, ClosureReason::CommitmentTxConfirmed);
2541
2541
}
2542
2542
2543
+ #[test]
2544
+ fn test_forming_justice_tx_from_monitor_updates() {
2545
+ // Simple test to make sure that the justice tx formed in WatchtowerPersister
2546
+ // is properly formed and can be broadcasted/confirmed successfully in the event
2547
+ // that a revoked commitment transaction is broadcasted
2548
+ // (Similar to `revoked_output_claim` test but we get the justice tx + broadcast manually)
2549
+ let chanmon_cfgs = create_chanmon_cfgs(2);
2550
+ let persisters = vec![WatchtowerPersister::new(), WatchtowerPersister::new()];
2551
+ let node_cfgs = create_node_cfgs_with_persisters(2, &chanmon_cfgs, persisters.iter().collect());
2552
+ let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
2553
+ let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
2554
+ let (_, _, channel_id, funding_tx) = create_announced_chan_between_nodes(&nodes, 0, 1);
2555
+ let funding_txo = OutPoint { txid: funding_tx.txid(), index: 0 };
2556
+
2557
+ send_payment(&nodes[0], &vec!(&nodes[1])[..], 5_000_000);
2558
+
2559
+ // node[0] is gonna to revoke an old state thus node[1] should be able to claim the revoked output.
2560
+ // We'll keep this commitment transaction to broadcast once it's revoked.
2561
+ let revoked_local_txn = get_local_commitment_txn!(nodes[0], channel_id);
2562
+ assert_eq!(revoked_local_txn.len(), 1);
2563
+ let revoked_commitment_tx = &revoked_local_txn[0];
2564
+
2565
+ // Send another payment, now revoking the previous commitment tx
2566
+ send_payment(&nodes[0], &vec!(&nodes[1])[..], 5_000_000);
2567
+
2568
+ let justice_tx = persisters[1].justice_tx(funding_txo, &revoked_commitment_tx.txid()).unwrap();
2569
+ check_spends!(justice_tx, revoked_commitment_tx);
2570
+
2571
+ mine_transactions(&nodes[1], &[revoked_commitment_tx, &justice_tx]);
2572
+ mine_transactions(&nodes[0], &[revoked_commitment_tx, &justice_tx]);
2573
+
2574
+ check_added_monitors!(nodes[1], 1);
2575
+ check_closed_event!(nodes[1], 1, ClosureReason::CommitmentTxConfirmed);
2576
+ get_announce_close_broadcast_events(&nodes, 1, 0);
2577
+
2578
+ check_added_monitors!(nodes[0], 1);
2579
+ check_closed_event!(nodes[0], 1, ClosureReason::CommitmentTxConfirmed);
2580
+
2581
+ // Check that the justice tx has sent the revoked output value to nodes[1]
2582
+ let monitor = get_monitor!(nodes[1], channel_id);
2583
+ let total_claimable_balance = monitor.get_claimable_balances().iter().fold(0, |sum, balance| {
2584
+ match balance {
2585
+ channelmonitor::Balance::ClaimableAwaitingConfirmations { claimable_amount_satoshis, .. } => sum + claimable_amount_satoshis,
2586
+ _ => panic!("Unexpected balance type"),
2587
+ }
2588
+ });
2589
+ let expected_claimable_balance = revoked_commitment_tx.output[0].value + justice_tx.output[0].value;
2590
+ assert!(total_claimable_balance == expected_claimable_balance);
2591
+ }
2592
+
2593
+
2543
2594
#[test]
2544
2595
fn claim_htlc_outputs_shared_tx() {
2545
2596
// Node revoked old state, htlcs haven't time out yet, claim them in shared justice tx
0 commit comments