@@ -1616,27 +1616,26 @@ fn test_fee_spike_violation_fails_htlc() {
1616
1616
1617
1617
// Get the EnforcingChannelKeys for each channel, which will be used to (1) get the keys
1618
1618
// needed to sign the new commitment tx and (2) sign the new commitment tx.
1619
- let ( local_revocation_basepoint, local_htlc_basepoint, local_secret, local_secret2 ) = {
1619
+ let ( local_revocation_basepoint, local_htlc_basepoint, local_secret, next_local_point ) = {
1620
1620
let chan_lock = nodes[ 0 ] . node . channel_state . lock ( ) . unwrap ( ) ;
1621
1621
let local_chan = chan_lock. by_id . get ( & chan. 2 ) . unwrap ( ) ;
1622
1622
let chan_keys = local_chan. get_keys ( ) ;
1623
1623
let pubkeys = chan_keys. pubkeys ( ) ;
1624
1624
( pubkeys. revocation_basepoint , pubkeys. htlc_basepoint ,
1625
- chan_keys. release_commitment_secret ( INITIAL_COMMITMENT_NUMBER ) , chan_keys. release_commitment_secret ( INITIAL_COMMITMENT_NUMBER - 2 ) )
1625
+ chan_keys. release_commitment_secret ( INITIAL_COMMITMENT_NUMBER ) ,
1626
+ chan_keys. get_per_commitment_point ( INITIAL_COMMITMENT_NUMBER - 2 , & secp_ctx) )
1626
1627
} ;
1627
- let ( remote_delayed_payment_basepoint, remote_htlc_basepoint, remote_secret1 ) = {
1628
+ let ( remote_delayed_payment_basepoint, remote_htlc_basepoint, remote_point ) = {
1628
1629
let chan_lock = nodes[ 1 ] . node . channel_state . lock ( ) . unwrap ( ) ;
1629
1630
let remote_chan = chan_lock. by_id . get ( & chan. 2 ) . unwrap ( ) ;
1630
1631
let chan_keys = remote_chan. get_keys ( ) ;
1631
1632
let pubkeys = chan_keys. pubkeys ( ) ;
1632
1633
( pubkeys. delayed_payment_basepoint , pubkeys. htlc_basepoint ,
1633
- chan_keys. release_commitment_secret ( INITIAL_COMMITMENT_NUMBER - 1 ) )
1634
+ chan_keys. get_per_commitment_point ( INITIAL_COMMITMENT_NUMBER - 1 , & secp_ctx ) )
1634
1635
} ;
1635
1636
1636
1637
// Assemble the set of keys we can use for signatures for our commitment_signed message.
1637
- let commitment_secret = SecretKey :: from_slice ( & remote_secret1) . unwrap ( ) ;
1638
- let per_commitment_point = PublicKey :: from_secret_key ( & secp_ctx, & commitment_secret) ;
1639
- let commit_tx_keys = chan_utils:: TxCreationKeys :: derive_new ( & secp_ctx, & per_commitment_point, & remote_delayed_payment_basepoint,
1638
+ let commit_tx_keys = chan_utils:: TxCreationKeys :: derive_new ( & secp_ctx, & remote_point, & remote_delayed_payment_basepoint,
1640
1639
& remote_htlc_basepoint, & local_revocation_basepoint, & local_htlc_basepoint) . unwrap ( ) ;
1641
1640
1642
1641
// Build the remote commitment transaction so we can sign it, and then later use the
@@ -1680,10 +1679,11 @@ fn test_fee_spike_violation_fails_htlc() {
1680
1679
let _ = nodes[ 1 ] . node . get_and_clear_pending_msg_events ( ) ;
1681
1680
1682
1681
// Send the RAA to nodes[1].
1683
- let per_commitment_secret = local_secret;
1684
- let next_secret = SecretKey :: from_slice ( & local_secret2) . unwrap ( ) ;
1685
- let next_per_commitment_point = PublicKey :: from_secret_key ( & secp_ctx, & next_secret) ;
1686
- let raa_msg = msgs:: RevokeAndACK { channel_id : chan. 2 , per_commitment_secret, next_per_commitment_point} ;
1682
+ let raa_msg = msgs:: RevokeAndACK {
1683
+ channel_id : chan. 2 ,
1684
+ per_commitment_secret : local_secret,
1685
+ next_per_commitment_point : next_local_point
1686
+ } ;
1687
1687
nodes[ 1 ] . node . handle_revoke_and_ack ( & nodes[ 0 ] . node . get_our_node_id ( ) , & raa_msg) ;
1688
1688
1689
1689
let events = nodes[ 1 ] . node . get_and_clear_pending_msg_events ( ) ;
@@ -4269,7 +4269,6 @@ fn test_no_txn_manager_serialize_deserialize() {
4269
4269
let fee_estimator: test_utils:: TestFeeEstimator ;
4270
4270
let persister: test_utils:: TestPersister ;
4271
4271
let new_chain_monitor: test_utils:: TestChainMonitor ;
4272
- let keys_manager: test_utils:: TestKeysInterface ;
4273
4272
let nodes_0_deserialized: ChannelManager < EnforcingChannelKeys , & test_utils:: TestChainMonitor , & test_utils:: TestBroadcaster , & test_utils:: TestKeysInterface , & test_utils:: TestFeeEstimator , & test_utils:: TestLogger > ;
4274
4273
let mut nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
4275
4274
@@ -4284,12 +4283,12 @@ fn test_no_txn_manager_serialize_deserialize() {
4284
4283
logger = test_utils:: TestLogger :: new ( ) ;
4285
4284
fee_estimator = test_utils:: TestFeeEstimator { sat_per_kw : 253 } ;
4286
4285
persister = test_utils:: TestPersister :: new ( ) ;
4287
- keys_manager = test_utils :: TestKeysInterface :: new ( & nodes [ 0 ] . node_seed , Network :: Testnet ) ;
4288
- new_chain_monitor = test_utils:: TestChainMonitor :: new ( Some ( nodes[ 0 ] . chain_source ) , nodes[ 0 ] . tx_broadcaster . clone ( ) , & logger, & fee_estimator, & persister, & keys_manager) ;
4286
+ let keys_manager = & chanmon_cfgs [ 0 ] . keys_manager ;
4287
+ new_chain_monitor = test_utils:: TestChainMonitor :: new ( Some ( nodes[ 0 ] . chain_source ) , nodes[ 0 ] . tx_broadcaster . clone ( ) , & logger, & fee_estimator, & persister, keys_manager) ;
4289
4288
nodes[ 0 ] . chain_monitor = & new_chain_monitor;
4290
4289
let mut chan_0_monitor_read = & chan_0_monitor_serialized. 0 [ ..] ;
4291
4290
let ( _, mut chan_0_monitor) = <( BlockHash , ChannelMonitor < EnforcingChannelKeys > ) >:: read (
4292
- & mut chan_0_monitor_read, & keys_manager) . unwrap ( ) ;
4291
+ & mut chan_0_monitor_read, keys_manager) . unwrap ( ) ;
4293
4292
assert ! ( chan_0_monitor_read. is_empty( ) ) ;
4294
4293
4295
4294
let mut nodes_0_read = & nodes_0_serialized[ ..] ;
@@ -4299,7 +4298,7 @@ fn test_no_txn_manager_serialize_deserialize() {
4299
4298
channel_monitors. insert ( chan_0_monitor. get_funding_txo ( ) . 0 , & mut chan_0_monitor) ;
4300
4299
<( BlockHash , ChannelManager < EnforcingChannelKeys , & test_utils:: TestChainMonitor , & test_utils:: TestBroadcaster , & test_utils:: TestKeysInterface , & test_utils:: TestFeeEstimator , & test_utils:: TestLogger > ) >:: read ( & mut nodes_0_read, ChannelManagerReadArgs {
4301
4300
default_config : config,
4302
- keys_manager : & keys_manager ,
4301
+ keys_manager,
4303
4302
fee_estimator : & fee_estimator,
4304
4303
chain_monitor : nodes[ 0 ] . chain_monitor ,
4305
4304
tx_broadcaster : nodes[ 0 ] . tx_broadcaster . clone ( ) ,
@@ -4346,7 +4345,6 @@ fn test_manager_serialize_deserialize_events() {
4346
4345
let persister: test_utils:: TestPersister ;
4347
4346
let logger: test_utils:: TestLogger ;
4348
4347
let new_chain_monitor: test_utils:: TestChainMonitor ;
4349
- let keys_manager: test_utils:: TestKeysInterface ;
4350
4348
let nodes_0_deserialized: ChannelManager < EnforcingChannelKeys , & test_utils:: TestChainMonitor , & test_utils:: TestBroadcaster , & test_utils:: TestKeysInterface , & test_utils:: TestFeeEstimator , & test_utils:: TestLogger > ;
4351
4349
let mut nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
4352
4350
@@ -4355,8 +4353,8 @@ fn test_manager_serialize_deserialize_events() {
4355
4353
let push_msat = 10001 ;
4356
4354
let a_flags = InitFeatures :: known ( ) ;
4357
4355
let b_flags = InitFeatures :: known ( ) ;
4358
- let node_a = nodes. pop ( ) . unwrap ( ) ;
4359
- let node_b = nodes. pop ( ) . unwrap ( ) ;
4356
+ let node_a = nodes. remove ( 0 ) ;
4357
+ let node_b = nodes. remove ( 0 ) ;
4360
4358
node_a. node . create_channel ( node_b. node . get_our_node_id ( ) , channel_value, push_msat, 42 , None ) . unwrap ( ) ;
4361
4359
node_b. node . handle_open_channel ( & node_a. node . get_our_node_id ( ) , a_flags, & get_event_msg ! ( node_a, MessageSendEvent :: SendOpenChannel , node_b. node. get_our_node_id( ) ) ) ;
4362
4360
node_a. node . handle_accept_channel ( & node_b. node . get_our_node_id ( ) , b_flags, & get_event_msg ! ( node_b, MessageSendEvent :: SendAcceptChannel , node_a. node. get_our_node_id( ) ) ) ;
@@ -4394,12 +4392,12 @@ fn test_manager_serialize_deserialize_events() {
4394
4392
fee_estimator = test_utils:: TestFeeEstimator { sat_per_kw : 253 } ;
4395
4393
logger = test_utils:: TestLogger :: new ( ) ;
4396
4394
persister = test_utils:: TestPersister :: new ( ) ;
4397
- keys_manager = test_utils :: TestKeysInterface :: new ( & nodes [ 0 ] . node_seed , Network :: Testnet ) ;
4398
- new_chain_monitor = test_utils:: TestChainMonitor :: new ( Some ( nodes[ 0 ] . chain_source ) , nodes[ 0 ] . tx_broadcaster . clone ( ) , & logger, & fee_estimator, & persister, & keys_manager) ;
4395
+ let keys_manager = & chanmon_cfgs [ 0 ] . keys_manager ;
4396
+ new_chain_monitor = test_utils:: TestChainMonitor :: new ( Some ( nodes[ 0 ] . chain_source ) , nodes[ 0 ] . tx_broadcaster . clone ( ) , & logger, & fee_estimator, & persister, keys_manager) ;
4399
4397
nodes[ 0 ] . chain_monitor = & new_chain_monitor;
4400
4398
let mut chan_0_monitor_read = & chan_0_monitor_serialized. 0 [ ..] ;
4401
4399
let ( _, mut chan_0_monitor) = <( BlockHash , ChannelMonitor < EnforcingChannelKeys > ) >:: read (
4402
- & mut chan_0_monitor_read, & keys_manager) . unwrap ( ) ;
4400
+ & mut chan_0_monitor_read, keys_manager) . unwrap ( ) ;
4403
4401
assert ! ( chan_0_monitor_read. is_empty( ) ) ;
4404
4402
4405
4403
let mut nodes_0_read = & nodes_0_serialized[ ..] ;
@@ -4409,7 +4407,7 @@ fn test_manager_serialize_deserialize_events() {
4409
4407
channel_monitors. insert ( chan_0_monitor. get_funding_txo ( ) . 0 , & mut chan_0_monitor) ;
4410
4408
<( BlockHash , ChannelManager < EnforcingChannelKeys , & test_utils:: TestChainMonitor , & test_utils:: TestBroadcaster , & test_utils:: TestKeysInterface , & test_utils:: TestFeeEstimator , & test_utils:: TestLogger > ) >:: read ( & mut nodes_0_read, ChannelManagerReadArgs {
4411
4409
default_config : config,
4412
- keys_manager : & keys_manager ,
4410
+ keys_manager,
4413
4411
fee_estimator : & fee_estimator,
4414
4412
chain_monitor : nodes[ 0 ] . chain_monitor ,
4415
4413
tx_broadcaster : nodes[ 0 ] . tx_broadcaster . clone ( ) ,
@@ -4470,7 +4468,6 @@ fn test_simple_manager_serialize_deserialize() {
4470
4468
let fee_estimator: test_utils:: TestFeeEstimator ;
4471
4469
let persister: test_utils:: TestPersister ;
4472
4470
let new_chain_monitor: test_utils:: TestChainMonitor ;
4473
- let keys_manager: & test_utils:: TestKeysInterface ;
4474
4471
let nodes_0_deserialized: ChannelManager < EnforcingChannelKeys , & test_utils:: TestChainMonitor , & test_utils:: TestBroadcaster , & test_utils:: TestKeysInterface , & test_utils:: TestFeeEstimator , & test_utils:: TestLogger > ;
4475
4472
let mut nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
4476
4473
create_announced_chan_between_nodes ( & nodes, 0 , 1 , InitFeatures :: known ( ) , InitFeatures :: known ( ) ) ;
@@ -4487,7 +4484,7 @@ fn test_simple_manager_serialize_deserialize() {
4487
4484
logger = test_utils:: TestLogger :: new ( ) ;
4488
4485
fee_estimator = test_utils:: TestFeeEstimator { sat_per_kw : 253 } ;
4489
4486
persister = test_utils:: TestPersister :: new ( ) ;
4490
- keys_manager = & chanmon_cfgs[ 0 ] . keys_manager ;
4487
+ let keys_manager = & chanmon_cfgs[ 0 ] . keys_manager ;
4491
4488
new_chain_monitor = test_utils:: TestChainMonitor :: new ( Some ( nodes[ 0 ] . chain_source ) , nodes[ 0 ] . tx_broadcaster . clone ( ) , & logger, & fee_estimator, & persister, keys_manager) ;
4492
4489
nodes[ 0 ] . chain_monitor = & new_chain_monitor;
4493
4490
let mut chan_0_monitor_read = & chan_0_monitor_serialized. 0 [ ..] ;
@@ -4532,7 +4529,6 @@ fn test_manager_serialize_deserialize_inconsistent_monitor() {
4532
4529
let fee_estimator: test_utils:: TestFeeEstimator ;
4533
4530
let persister: test_utils:: TestPersister ;
4534
4531
let new_chain_monitor: test_utils:: TestChainMonitor ;
4535
- let keys_manager: & test_utils:: TestKeysInterface ;
4536
4532
let nodes_0_deserialized: ChannelManager < EnforcingChannelKeys , & test_utils:: TestChainMonitor , & test_utils:: TestBroadcaster , & test_utils:: TestKeysInterface , & test_utils:: TestFeeEstimator , & test_utils:: TestLogger > ;
4537
4533
let mut nodes = create_network ( 4 , & node_cfgs, & node_chanmgrs) ;
4538
4534
create_announced_chan_between_nodes ( & nodes, 0 , 1 , InitFeatures :: known ( ) , InitFeatures :: known ( ) ) ;
@@ -4568,7 +4564,7 @@ fn test_manager_serialize_deserialize_inconsistent_monitor() {
4568
4564
logger = test_utils:: TestLogger :: new ( ) ;
4569
4565
fee_estimator = test_utils:: TestFeeEstimator { sat_per_kw : 253 } ;
4570
4566
persister = test_utils:: TestPersister :: new ( ) ;
4571
- keys_manager = & chanmon_cfgs[ 0 ] . keys_manager ;
4567
+ let keys_manager = & chanmon_cfgs[ 0 ] . keys_manager ;
4572
4568
new_chain_monitor = test_utils:: TestChainMonitor :: new ( Some ( nodes[ 0 ] . chain_source ) , nodes[ 0 ] . tx_broadcaster . clone ( ) , & logger, & fee_estimator, & persister, keys_manager) ;
4573
4569
nodes[ 0 ] . chain_monitor = & new_chain_monitor;
4574
4570
@@ -7374,8 +7370,10 @@ fn test_user_configurable_csv_delay() {
7374
7370
fn test_data_loss_protect ( ) {
7375
7371
// We want to be sure that :
7376
7372
// * we don't broadcast our Local Commitment Tx in case of fallen behind
7373
+ // (but this is not quite true - we broadcast during Drop because chanmon is out of sync with chanmgr)
7377
7374
// * we close channel in case of detecting other being fallen behind
7378
7375
// * we are able to claim our own outputs thanks to to_remote being static
7376
+ // TODO: this test is incomplete and the data_loss_protect implementation is incomplete - see issue #775
7379
7377
let persister;
7380
7378
let logger;
7381
7379
let fee_estimator;
@@ -8084,9 +8082,11 @@ fn test_counterparty_raa_skip_no_crash() {
8084
8082
let mut guard = nodes[ 0 ] . node . channel_state . lock ( ) . unwrap ( ) ;
8085
8083
let keys = & guard. by_id . get_mut ( & channel_id) . unwrap ( ) . holder_keys ;
8086
8084
const INITIAL_COMMITMENT_NUMBER : u64 = ( 1 << 48 ) - 1 ;
8085
+ let per_commitment_secret = keys. release_commitment_secret ( INITIAL_COMMITMENT_NUMBER ) ;
8086
+ // Must revoke without gaps
8087
+ keys. release_commitment_secret ( INITIAL_COMMITMENT_NUMBER - 1 ) ;
8087
8088
let next_per_commitment_point = PublicKey :: from_secret_key ( & Secp256k1 :: new ( ) ,
8088
8089
& SecretKey :: from_slice ( & keys. release_commitment_secret ( INITIAL_COMMITMENT_NUMBER - 2 ) ) . unwrap ( ) ) ;
8089
- let per_commitment_secret = keys. release_commitment_secret ( INITIAL_COMMITMENT_NUMBER ) ;
8090
8090
8091
8091
nodes[ 1 ] . node . handle_revoke_and_ack ( & nodes[ 0 ] . node . get_our_node_id ( ) ,
8092
8092
& msgs:: RevokeAndACK { channel_id, per_commitment_secret, next_per_commitment_point } ) ;
0 commit comments