Merge pull request #1055 from lightning-signer/2021-08-anchor-tx
[rust-lightning] / lightning / src / ln / functional_tests.rs
index 980c6ea40f1f0e812d99fbeca432421cf9cc5744..06cc80cc18b0a5b770be83ce25cbb82535d932ba 100644 (file)
@@ -1297,22 +1297,27 @@ fn test_fee_spike_violation_fails_htlc() {
 
        // Get the EnforcingSigner for each channel, which will be used to (1) get the keys
        // needed to sign the new commitment tx and (2) sign the new commitment tx.
-       let (local_revocation_basepoint, local_htlc_basepoint, local_secret, next_local_point) = {
+       let (local_revocation_basepoint, local_htlc_basepoint, local_secret, next_local_point, local_funding) = {
                let chan_lock = nodes[0].node.channel_state.lock().unwrap();
                let local_chan = chan_lock.by_id.get(&chan.2).unwrap();
                let chan_signer = local_chan.get_signer();
+               // Make the signer believe we validated another commitment, so we can release the secret
+               chan_signer.get_enforcement_state().last_holder_commitment -= 1;
+
                let pubkeys = chan_signer.pubkeys();
                (pubkeys.revocation_basepoint, pubkeys.htlc_basepoint,
                 chan_signer.release_commitment_secret(INITIAL_COMMITMENT_NUMBER),
-                chan_signer.get_per_commitment_point(INITIAL_COMMITMENT_NUMBER - 2, &secp_ctx))
+                chan_signer.get_per_commitment_point(INITIAL_COMMITMENT_NUMBER - 2, &secp_ctx),
+                chan_signer.pubkeys().funding_pubkey)
        };
-       let (remote_delayed_payment_basepoint, remote_htlc_basepoint,remote_point) = {
+       let (remote_delayed_payment_basepoint, remote_htlc_basepoint, remote_point, remote_funding) = {
                let chan_lock = nodes[1].node.channel_state.lock().unwrap();
                let remote_chan = chan_lock.by_id.get(&chan.2).unwrap();
                let chan_signer = remote_chan.get_signer();
                let pubkeys = chan_signer.pubkeys();
                (pubkeys.delayed_payment_basepoint, pubkeys.htlc_basepoint,
-                chan_signer.get_per_commitment_point(INITIAL_COMMITMENT_NUMBER - 1, &secp_ctx))
+                chan_signer.get_per_commitment_point(INITIAL_COMMITMENT_NUMBER - 1, &secp_ctx),
+                chan_signer.pubkeys().funding_pubkey)
        };
 
        // Assemble the set of keys we can use for signatures for our commitment_signed message.
@@ -1341,6 +1346,7 @@ fn test_fee_spike_violation_fails_htlc() {
                        commitment_number,
                        95000,
                        local_chan_balance,
+                       false, local_funding, remote_funding,
                        commit_tx_keys.clone(),
                        feerate_per_kw,
                        &mut vec![(accepted_htlc_info, ())],
@@ -4048,7 +4054,7 @@ fn test_invalid_channel_announcement() {
                                bitcoin_key_1: if were_node_one { as_bitcoin_key } else { bs_bitcoin_key },
                                bitcoin_key_2: if were_node_one { bs_bitcoin_key } else { as_bitcoin_key },
                                excess_data: Vec::new(),
-                       };
+                       }
                }
        }
 
@@ -7981,7 +7987,7 @@ fn test_counterparty_raa_skip_no_crash() {
        // commitment transaction, we would have happily carried on and provided them the next
        // commitment transaction based on one RAA forward. This would probably eventually have led to
        // channel closure, but it would not have resulted in funds loss. Still, our
-       // EnforcingSigner would have paniced as it doesn't like jumps into the future. Here, we
+       // EnforcingSigner would have panicked as it doesn't like jumps into the future. Here, we
        // check simply that the channel is closed in response to such an RAA, but don't check whether
        // we decide to punish our counterparty for revoking their funds (as we don't currently
        // implement that).
@@ -7992,11 +7998,19 @@ fn test_counterparty_raa_skip_no_crash() {
        let channel_id = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()).2;
 
        let mut guard = nodes[0].node.channel_state.lock().unwrap();
-       let keys = &guard.by_id.get_mut(&channel_id).unwrap().get_signer();
+       let keys = guard.by_id.get_mut(&channel_id).unwrap().get_signer();
+
        const INITIAL_COMMITMENT_NUMBER: u64 = (1 << 48) - 1;
+
+       // Make signer believe we got a counterparty signature, so that it allows the revocation
+       keys.get_enforcement_state().last_holder_commitment -= 1;
        let per_commitment_secret = keys.release_commitment_secret(INITIAL_COMMITMENT_NUMBER);
+
        // Must revoke without gaps
+       keys.get_enforcement_state().last_holder_commitment -= 1;
        keys.release_commitment_secret(INITIAL_COMMITMENT_NUMBER - 1);
+
+       keys.get_enforcement_state().last_holder_commitment -= 1;
        let next_per_commitment_point = PublicKey::from_secret_key(&Secp256k1::new(),
                &SecretKey::from_slice(&keys.release_commitment_secret(INITIAL_COMMITMENT_NUMBER - 2)).unwrap());