@@ -714,7 +714,7 @@ fn test_update_fee_that_funder_cannot_afford() {
714
714
let chan_signer = remote_chan.get_signer();
715
715
let pubkeys = chan_signer.as_ref().pubkeys();
716
716
(pubkeys.delayed_payment_basepoint, pubkeys.htlc_basepoint,
717
- chan_signer.as_ref().get_per_commitment_point(INITIAL_COMMITMENT_NUMBER - 1, &secp_ctx),
717
+ chan_signer.as_ref().get_per_commitment_point(INITIAL_COMMITMENT_NUMBER - 1, &secp_ctx).unwrap() ,
718
718
pubkeys.funding_pubkey)
719
719
};
720
720
@@ -1421,8 +1421,8 @@ fn test_fee_spike_violation_fails_htlc() {
1421
1421
1422
1422
let pubkeys = chan_signer.as_ref().pubkeys();
1423
1423
(pubkeys.revocation_basepoint, pubkeys.htlc_basepoint,
1424
- chan_signer.as_ref().release_commitment_secret(INITIAL_COMMITMENT_NUMBER),
1425
- chan_signer.as_ref().get_per_commitment_point(INITIAL_COMMITMENT_NUMBER - 2, &secp_ctx),
1424
+ chan_signer.as_ref().release_commitment_secret(INITIAL_COMMITMENT_NUMBER).unwrap() ,
1425
+ chan_signer.as_ref().get_per_commitment_point(INITIAL_COMMITMENT_NUMBER - 2, &secp_ctx).unwrap() ,
1426
1426
chan_signer.as_ref().pubkeys().funding_pubkey)
1427
1427
};
1428
1428
let (remote_delayed_payment_basepoint, remote_htlc_basepoint, remote_point, remote_funding) = {
@@ -1432,7 +1432,7 @@ fn test_fee_spike_violation_fails_htlc() {
1432
1432
let chan_signer = remote_chan.get_signer();
1433
1433
let pubkeys = chan_signer.as_ref().pubkeys();
1434
1434
(pubkeys.delayed_payment_basepoint, pubkeys.htlc_basepoint,
1435
- chan_signer.as_ref().get_per_commitment_point(INITIAL_COMMITMENT_NUMBER - 1, &secp_ctx),
1435
+ chan_signer.as_ref().get_per_commitment_point(INITIAL_COMMITMENT_NUMBER - 1, &secp_ctx).unwrap() ,
1436
1436
chan_signer.as_ref().pubkeys().funding_pubkey)
1437
1437
};
1438
1438
@@ -7660,15 +7660,15 @@ fn test_counterparty_raa_skip_no_crash() {
7660
7660
7661
7661
// Make signer believe we got a counterparty signature, so that it allows the revocation
7662
7662
keys.as_ecdsa().unwrap().get_enforcement_state().last_holder_commitment -= 1;
7663
- per_commitment_secret = keys.as_ref().release_commitment_secret(INITIAL_COMMITMENT_NUMBER);
7663
+ per_commitment_secret = keys.as_ref().release_commitment_secret(INITIAL_COMMITMENT_NUMBER).unwrap() ;
7664
7664
7665
7665
// Must revoke without gaps
7666
7666
keys.as_ecdsa().unwrap().get_enforcement_state().last_holder_commitment -= 1;
7667
- keys.as_ref().release_commitment_secret(INITIAL_COMMITMENT_NUMBER - 1);
7667
+ keys.as_ref().release_commitment_secret(INITIAL_COMMITMENT_NUMBER - 1).expect("unable to release commitment secret") ;
7668
7668
7669
7669
keys.as_ecdsa().unwrap().get_enforcement_state().last_holder_commitment -= 1;
7670
7670
next_per_commitment_point = PublicKey::from_secret_key(&Secp256k1::new(),
7671
- &SecretKey::from_slice(&keys.as_ref().release_commitment_secret(INITIAL_COMMITMENT_NUMBER - 2)).unwrap());
7671
+ &SecretKey::from_slice(&keys.as_ref().release_commitment_secret(INITIAL_COMMITMENT_NUMBER - 2).unwrap() ).unwrap());
7672
7672
}
7673
7673
7674
7674
nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(),
@@ -8979,6 +8979,193 @@ fn test_duplicate_chan_id() {
8979
8979
send_payment(&nodes[0], &[&nodes[1]], 8000000);
8980
8980
}
8981
8981
8982
+ #[test]
8983
+ fn test_signer_gpcp_unavailable_for_funding_signed() {
8984
+ // Test that a transient failure of the Signer's get_per_commitment_point can be tolerated during
8985
+ // channel open by specifically having it fail for an inbound channel during the handling of the
8986
+ // funding_signed message.
8987
+ let chanmon_cfgs = create_chanmon_cfgs(2);
8988
+ let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
8989
+ let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
8990
+ let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
8991
+
8992
+ // Create an initial channel
8993
+ nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), 100000, 10001, 42, None).unwrap();
8994
+ let mut open_chan_msg = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id());
8995
+ nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), &open_chan_msg);
8996
+ nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), &get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id()));
8997
+
8998
+ // Move the channel through the funding flow...
8999
+ let (temporary_channel_id, tx, _) = create_funding_transaction(&nodes[0], &nodes[1].node.get_our_node_id(), 100000, 42);
9000
+
9001
+ nodes[0].node.funding_transaction_generated(&temporary_channel_id, &nodes[1].node.get_our_node_id(), tx.clone()).unwrap();
9002
+ check_added_monitors(&nodes[0], 0);
9003
+
9004
+ let mut funding_created_msg = get_event_msg!(nodes[0], MessageSendEvent::SendFundingCreated, nodes[1].node.get_our_node_id());
9005
+ nodes[1].node.handle_funding_created(&nodes[0].node.get_our_node_id(), &funding_created_msg);
9006
+ check_added_monitors(&nodes[1], 1);
9007
+
9008
+ let chan_id = expect_channel_pending_event(&nodes[1], &nodes[0].node.get_our_node_id());
9009
+
9010
+ // Tweak the node[0] channel signer to produce an "unavailable" message before we ask it to handle
9011
+ // the funding_signed message.
9012
+ nodes[0].set_channel_signer_available(&nodes[1].node.get_our_node_id(), &chan_id, false);
9013
+ let funding_signed_msg = get_event_msg!(nodes[1], MessageSendEvent::SendFundingSigned, nodes[0].node.get_our_node_id());
9014
+ nodes[0].node.handle_funding_signed(&nodes[1].node.get_our_node_id(), &funding_signed_msg);
9015
+
9016
+ let events = nodes[0].node.get_and_clear_pending_events();
9017
+ assert_eq!(events.len(), 0);
9018
+ check_added_monitors(&nodes[0], 0);
9019
+
9020
+ // Now make it available and verify that we can process the message.
9021
+ nodes[0].set_channel_signer_available(&nodes[1].node.get_our_node_id(), &chan_id, true);
9022
+ nodes[0].node.handle_funding_signed(&nodes[1].node.get_our_node_id(), &funding_signed_msg);
9023
+ check_added_monitors(&nodes[0], 1);
9024
+
9025
+ expect_channel_pending_event(&nodes[0], &nodes[1].node.get_our_node_id());
9026
+
9027
+ assert_eq!(nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().len(), 1);
9028
+ assert_eq!(nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap()[0], tx);
9029
+
9030
+ let (channel_ready, _) = create_chan_between_nodes_with_value_confirm(&nodes[0], &nodes[1], &tx);
9031
+ let (announcement, as_update, bs_update) = create_chan_between_nodes_with_value_b(&nodes[0], &nodes[1], &channel_ready);
9032
+ update_nodes_with_chan_announce(&nodes, 0, 1, &announcement, &as_update, &bs_update);
9033
+
9034
+ send_payment(&nodes[0], &[&nodes[1]], 8000000);
9035
+ }
9036
+
9037
+ #[test]
9038
+ fn test_signer_gpcp_unavailable_for_funding_created() {
9039
+ // Test that a transient failure of the Signer's get_per_commitment_point can be tolerated during
9040
+ // channel open by specifically having it fail for an outbound channel during generation of the
9041
+ // funding_created message.
9042
+ let chanmon_cfgs = create_chanmon_cfgs(2);
9043
+ let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
9044
+ let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
9045
+ let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
9046
+
9047
+ // Create an initial channel
9048
+ nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), 100000, 10001, 42, None).unwrap();
9049
+ let mut open_chan_msg = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id());
9050
+ nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), &open_chan_msg);
9051
+ nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), &get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id()));
9052
+
9053
+ // Move the channel through the funding flow...
9054
+ let (temporary_channel_id, tx, _) = create_funding_transaction(&nodes[0], &nodes[1].node.get_our_node_id(), 100000, 42);
9055
+
9056
+ nodes[0].node.funding_transaction_generated(&temporary_channel_id, &nodes[1].node.get_our_node_id(), tx.clone()).unwrap();
9057
+ check_added_monitors(&nodes[0], 0);
9058
+
9059
+ // Tweak the node[1] channel signer to produce an "unavailable" result before we ask it to handle
9060
+ // the funding_created message.
9061
+ nodes[1].set_channel_signer_available(&nodes[0].node.get_our_node_id(), &temporary_channel_id, false);
9062
+ let mut funding_created_msg = get_event_msg!(nodes[0], MessageSendEvent::SendFundingCreated, nodes[1].node.get_our_node_id());
9063
+ nodes[1].node.handle_funding_created(&nodes[0].node.get_our_node_id(), &funding_created_msg);
9064
+ check_added_monitors(&nodes[1], 0);
9065
+
9066
+ let events = nodes[0].node.get_and_clear_pending_events();
9067
+ assert_eq!(events.len(), 0);
9068
+
9069
+ // Now make it available and verify that we can process the message.
9070
+ nodes[1].set_channel_signer_available(&nodes[0].node.get_our_node_id(), &temporary_channel_id, true);
9071
+ nodes[1].node.handle_funding_created(&nodes[0].node.get_our_node_id(), &funding_created_msg);
9072
+ check_added_monitors(&nodes[1], 1);
9073
+
9074
+ let funding_signed_msg = get_event_msg!(nodes[1], MessageSendEvent::SendFundingSigned, nodes[0].node.get_our_node_id());
9075
+ nodes[0].node.handle_funding_signed(&nodes[1].node.get_our_node_id(), &funding_signed_msg);
9076
+ check_added_monitors(&nodes[0], 1);
9077
+
9078
+ expect_channel_pending_event(&nodes[0], &nodes[1].node.get_our_node_id());
9079
+ expect_channel_pending_event(&nodes[1], &nodes[0].node.get_our_node_id());
9080
+
9081
+ assert_eq!(nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().len(), 1);
9082
+ assert_eq!(nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap()[0], tx);
9083
+
9084
+ let (channel_ready, _) = create_chan_between_nodes_with_value_confirm(&nodes[0], &nodes[1], &tx);
9085
+ let (announcement, as_update, bs_update) = create_chan_between_nodes_with_value_b(&nodes[0], &nodes[1], &channel_ready);
9086
+ update_nodes_with_chan_announce(&nodes, 0, 1, &announcement, &as_update, &bs_update);
9087
+ send_payment(&nodes[0], &[&nodes[1]], 8000000);
9088
+ }
9089
+
9090
+ #[test]
9091
+ fn test_dest_signer_gpcp_unavailable_for_commitment_signed() {
9092
+ // Test that a transient failure of the Signer's get_per_commitment_point can be tolerated by the
9093
+ // destination node for a payment.
9094
+ let chanmon_cfgs = create_chanmon_cfgs(2);
9095
+ let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
9096
+ let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
9097
+ let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
9098
+
9099
+ // Create an initial channel
9100
+ nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), 100000, 10001, 42, None).unwrap();
9101
+ let mut open_chan_msg = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id());
9102
+ nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), &open_chan_msg);
9103
+ nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), &get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id()));
9104
+
9105
+ // Move the channel through the funding flow...
9106
+ let (temporary_channel_id, tx, _) = create_funding_transaction(&nodes[0], &nodes[1].node.get_our_node_id(), 100000, 42);
9107
+
9108
+ nodes[0].node.funding_transaction_generated(&temporary_channel_id, &nodes[1].node.get_our_node_id(), tx.clone()).unwrap();
9109
+ check_added_monitors(&nodes[0], 0);
9110
+
9111
+ let mut funding_created_msg = get_event_msg!(nodes[0], MessageSendEvent::SendFundingCreated, nodes[1].node.get_our_node_id());
9112
+ nodes[1].node.handle_funding_created(&nodes[0].node.get_our_node_id(), &funding_created_msg);
9113
+ check_added_monitors(&nodes[1], 1);
9114
+
9115
+ let funding_signed_msg = get_event_msg!(nodes[1], MessageSendEvent::SendFundingSigned, nodes[0].node.get_our_node_id());
9116
+ nodes[0].node.handle_funding_signed(&nodes[1].node.get_our_node_id(), &funding_signed_msg);
9117
+ check_added_monitors(&nodes[0], 1);
9118
+
9119
+ let chan_id = expect_channel_pending_event(&nodes[0], &nodes[1].node.get_our_node_id());
9120
+ expect_channel_pending_event(&nodes[1], &nodes[0].node.get_our_node_id());
9121
+
9122
+ assert_eq!(nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().len(), 1);
9123
+ assert_eq!(nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap()[0], tx);
9124
+
9125
+ let (channel_ready, _) = create_chan_between_nodes_with_value_confirm(&nodes[0], &nodes[1], &tx);
9126
+ let (announcement, as_update, bs_update) = create_chan_between_nodes_with_value_b(&nodes[0], &nodes[1], &channel_ready);
9127
+ update_nodes_with_chan_announce(&nodes, 0, 1, &announcement, &as_update, &bs_update);
9128
+
9129
+ // Send a payment.
9130
+ let src = &nodes[0];
9131
+ let dst = &nodes[1];
9132
+ let (route, our_payment_hash, _our_payment_preimage, our_payment_secret) = get_route_and_payment_hash!(src, dst, 8000000);
9133
+ src.node.send_payment_with_route(&route, our_payment_hash,
9134
+ RecipientOnionFields::secret_only(our_payment_secret), PaymentId(our_payment_hash.0)).unwrap();
9135
+ check_added_monitors!(src, 1);
9136
+
9137
+ // Pass the payment along the route.
9138
+ let payment_event = {
9139
+ let mut events = src.node.get_and_clear_pending_msg_events();
9140
+ assert_eq!(events.len(), 1);
9141
+ SendEvent::from_event(events.remove(0))
9142
+ };
9143
+ assert_eq!(payment_event.node_id, dst.node.get_our_node_id());
9144
+ assert_eq!(payment_event.msgs.len(), 1);
9145
+
9146
+ dst.node.handle_update_add_htlc(&src.node.get_our_node_id(), &payment_event.msgs[0]);
9147
+
9148
+ // Mark dst's signer as unavailable.
9149
+ dst.set_channel_signer_available(&src.node.get_our_node_id(), &chan_id, false);
9150
+ dst.node.handle_commitment_signed(&src.node.get_our_node_id(), &payment_event.commitment_msg);
9151
+ check_added_monitors(src, 0);
9152
+ check_added_monitors(dst, 0);
9153
+
9154
+ {
9155
+ let src_events = src.node.get_and_clear_pending_msg_events();
9156
+ assert_eq!(src_events.len(), 0);
9157
+ let dst_events = dst.node.get_and_clear_pending_msg_events();
9158
+ assert_eq!(dst_events.len(), 0);
9159
+ }
9160
+
9161
+ // Mark dst's signer as available and re-handle commitment_signed. We expect to see both the RAA
9162
+ // and the CS.
9163
+ dst.set_channel_signer_available(&src.node.get_our_node_id(), &chan_id, true);
9164
+ dst.node.handle_commitment_signed(&src.node.get_our_node_id(), &payment_event.commitment_msg);
9165
+ get_revoke_commit_msgs(dst, &src.node.get_our_node_id());
9166
+ check_added_monitors!(dst, 1);
9167
+ }
9168
+
8982
9169
#[test]
8983
9170
fn test_error_chans_closed() {
8984
9171
// Test that we properly handle error messages, closing appropriate channels.
0 commit comments