@@ -25,7 +25,7 @@ use bitcoin::secp256k1;
25
25
use crate :: ln:: { PaymentPreimage , PaymentHash } ;
26
26
use crate :: ln:: features:: { ChannelTypeFeatures , InitFeatures } ;
27
27
use crate :: ln:: msgs;
28
- use crate :: ln:: msgs:: { DecodeError , OptionalField , DataLossProtect } ;
28
+ use crate :: ln:: msgs:: DecodeError ;
29
29
use crate :: ln:: script:: { self , ShutdownScript } ;
30
30
use crate :: ln:: channelmanager:: { self , CounterpartyForwardingInfo , PendingHTLCStatus , HTLCSource , SentHTLCId , HTLCFailureMsg , PendingHTLCInfo , RAACommitmentOrder , BREAKDOWN_TIMEOUT , MIN_CLTV_EXPIRY_DELTA , MAX_LOCAL_BREAKDOWN_TIMEOUT } ;
31
31
use crate :: ln:: chan_utils:: { CounterpartyCommitmentSecrets , TxCreationKeys , HTLCOutputInCommitment , htlc_success_tx_weight, htlc_timeout_tx_weight, make_funding_redeemscript, ChannelPublicKeys , CommitmentTransaction , HolderCommitmentTransaction , ChannelTransactionParameters , CounterpartyChannelTransactionParameters , MAX_HTLCS , get_commitment_transaction_number_obscure_factor, ClosingTransaction } ;
@@ -1322,7 +1322,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
1322
1322
1323
1323
let counterparty_shutdown_scriptpubkey = if their_features. supports_upfront_shutdown_script ( ) {
1324
1324
match & msg. shutdown_scriptpubkey {
1325
- & OptionalField :: Present ( ref script) => {
1325
+ & Some ( ref script) => {
1326
1326
// Peer is signaling upfront_shutdown and has opt-out with a 0-length script. We don't enforce anything
1327
1327
if script. len ( ) == 0 {
1328
1328
None
@@ -1334,7 +1334,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
1334
1334
}
1335
1335
} ,
1336
1336
// Peer is signaling upfront shutdown but don't opt-out with correct mechanism (a.k.a 0-length script). Peer looks buggy, we fail the channel
1337
- & OptionalField :: Absent => {
1337
+ & None => {
1338
1338
return Err ( ChannelError :: Close ( "Peer is signaling upfront_shutdown but we don't get any script. Use 0-length script to opt-out" . to_owned ( ) ) ) ;
1339
1339
}
1340
1340
}
@@ -2207,7 +2207,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
2207
2207
2208
2208
let counterparty_shutdown_scriptpubkey = if their_features. supports_upfront_shutdown_script ( ) {
2209
2209
match & msg. shutdown_scriptpubkey {
2210
- & OptionalField :: Present ( ref script) => {
2210
+ & Some ( ref script) => {
2211
2211
// Peer is signaling upfront_shutdown and has opt-out with a 0-length script. We don't enforce anything
2212
2212
if script. len ( ) == 0 {
2213
2213
None
@@ -2219,7 +2219,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
2219
2219
}
2220
2220
} ,
2221
2221
// Peer is signaling upfront shutdown but don't opt-out with correct mechanism (a.k.a 0-length script). Peer looks buggy, we fail the channel
2222
- & OptionalField :: Absent => {
2222
+ & None => {
2223
2223
return Err ( ChannelError :: Close ( "Peer is signaling upfront_shutdown but we don't get any script. Use 0-length script to opt-out" . to_owned ( ) ) ) ;
2224
2224
}
2225
2225
}
@@ -4059,32 +4059,27 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
4059
4059
}
4060
4060
4061
4061
if msg. next_remote_commitment_number > 0 {
4062
- match msg. data_loss_protect {
4063
- OptionalField :: Present ( ref data_loss) => {
4064
- let expected_point = self . holder_signer . get_per_commitment_point ( INITIAL_COMMITMENT_NUMBER - msg. next_remote_commitment_number + 1 , & self . secp_ctx ) ;
4065
- let given_secret = SecretKey :: from_slice ( & data_loss. your_last_per_commitment_secret )
4066
- . map_err ( |_| ChannelError :: Close ( "Peer sent a garbage channel_reestablish with unparseable secret key" . to_owned ( ) ) ) ?;
4067
- if expected_point != PublicKey :: from_secret_key ( & self . secp_ctx , & given_secret) {
4068
- return Err ( ChannelError :: Close ( "Peer sent a garbage channel_reestablish with secret key not matching the commitment height provided" . to_owned ( ) ) ) ;
4062
+ let expected_point = self . holder_signer . get_per_commitment_point ( INITIAL_COMMITMENT_NUMBER - msg. next_remote_commitment_number + 1 , & self . secp_ctx ) ;
4063
+ let given_secret = SecretKey :: from_slice ( & msg. your_last_per_commitment_secret )
4064
+ . map_err ( |_| ChannelError :: Close ( "Peer sent a garbage channel_reestablish with unparseable secret key" . to_owned ( ) ) ) ?;
4065
+ if expected_point != PublicKey :: from_secret_key ( & self . secp_ctx , & given_secret) {
4066
+ return Err ( ChannelError :: Close ( "Peer sent a garbage channel_reestablish with secret key not matching the commitment height provided" . to_owned ( ) ) ) ;
4067
+ }
4068
+ if msg. next_remote_commitment_number > INITIAL_COMMITMENT_NUMBER - self . cur_holder_commitment_transaction_number {
4069
+ macro_rules! log_and_panic {
4070
+ ( $err_msg: expr) => {
4071
+ log_error!( logger, $err_msg, log_bytes!( self . channel_id) , log_pubkey!( self . counterparty_node_id) ) ;
4072
+ panic!( $err_msg, log_bytes!( self . channel_id) , log_pubkey!( self . counterparty_node_id) ) ;
4069
4073
}
4070
- if msg. next_remote_commitment_number > INITIAL_COMMITMENT_NUMBER - self . cur_holder_commitment_transaction_number {
4071
- macro_rules! log_and_panic {
4072
- ( $err_msg: expr) => {
4073
- log_error!( logger, $err_msg, log_bytes!( self . channel_id) , log_pubkey!( self . counterparty_node_id) ) ;
4074
- panic!( $err_msg, log_bytes!( self . channel_id) , log_pubkey!( self . counterparty_node_id) ) ;
4075
- }
4076
- }
4077
- log_and_panic ! ( "We have fallen behind - we have received proof that if we broadcast our counterparty is going to claim all our funds.\n \
4078
- This implies you have restarted with lost ChannelMonitor and ChannelManager state, the first of which is a violation of the LDK chain::Watch requirements.\n \
4079
- More specifically, this means you have a bug in your implementation that can cause loss of funds, or you are running with an old backup, which is unsafe.\n \
4080
- If you have restored from an old backup and wish to force-close channels and return to operation, you should start up, call\n \
4081
- ChannelManager::force_close_without_broadcasting_txn on channel {} with counterparty {} or\n \
4082
- ChannelManager::force_close_all_channels_without_broadcasting_txn, then reconnect to peer(s).\n \
4083
- Note that due to a long-standing bug in lnd you may have to reach out to peers running lnd-based nodes to ask them to manually force-close channels\n \
4084
- See https://github.com/lightningdevkit/rust-lightning/issues/1565 for more info.") ;
4085
- }
4086
- } ,
4087
- OptionalField :: Absent => { }
4074
+ }
4075
+ log_and_panic ! ( "We have fallen behind - we have received proof that if we broadcast our counterparty is going to claim all our funds.\n \
4076
+ This implies you have restarted with lost ChannelMonitor and ChannelManager state, the first of which is a violation of the LDK chain::Watch requirements.\n \
4077
+ More specifically, this means you have a bug in your implementation that can cause loss of funds, or you are running with an old backup, which is unsafe.\n \
4078
+ If you have restored from an old backup and wish to force-close channels and return to operation, you should start up, call\n \
4079
+ ChannelManager::force_close_without_broadcasting_txn on channel {} with counterparty {} or\n \
4080
+ ChannelManager::force_close_all_channels_without_broadcasting_txn, then reconnect to peer(s).\n \
4081
+ Note that due to a long-standing bug in lnd you may have to reach out to peers running lnd-based nodes to ask them to manually force-close channels\n \
4082
+ See https://github.com/lightningdevkit/rust-lightning/issues/1565 for more info.") ;
4088
4083
}
4089
4084
}
4090
4085
@@ -5342,7 +5337,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
5342
5337
htlc_basepoint : keys. htlc_basepoint ,
5343
5338
first_per_commitment_point,
5344
5339
channel_flags : if self . config . announced_channel { 1 } else { 0 } ,
5345
- shutdown_scriptpubkey : OptionalField :: Present ( match & self . shutdown_scriptpubkey {
5340
+ shutdown_scriptpubkey : Some ( match & self . shutdown_scriptpubkey {
5346
5341
Some ( script) => script. clone ( ) . into_inner ( ) ,
5347
5342
None => Builder :: new ( ) . into_script ( ) ,
5348
5343
} ) ,
@@ -5408,7 +5403,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
5408
5403
delayed_payment_basepoint : keys. delayed_payment_basepoint ,
5409
5404
htlc_basepoint : keys. htlc_basepoint ,
5410
5405
first_per_commitment_point,
5411
- shutdown_scriptpubkey : OptionalField :: Present ( match & self . shutdown_scriptpubkey {
5406
+ shutdown_scriptpubkey : Some ( match & self . shutdown_scriptpubkey {
5412
5407
Some ( script) => script. clone ( ) . into_inner ( ) ,
5413
5408
None => Builder :: new ( ) . into_script ( ) ,
5414
5409
} ) ,
@@ -5670,19 +5665,13 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
5670
5665
// valid, and valid in fuzzing mode's arbitrary validity criteria:
5671
5666
let mut pk = [ 2 ; 33 ] ; pk[ 1 ] = 0xff ;
5672
5667
let dummy_pubkey = PublicKey :: from_slice ( & pk) . unwrap ( ) ;
5673
- let data_loss_protect = if self . cur_counterparty_commitment_transaction_number + 1 < INITIAL_COMMITMENT_NUMBER {
5668
+ let remote_last_secret = if self . cur_counterparty_commitment_transaction_number + 1 < INITIAL_COMMITMENT_NUMBER {
5674
5669
let remote_last_secret = self . commitment_secrets . get_secret ( self . cur_counterparty_commitment_transaction_number + 2 ) . unwrap ( ) ;
5675
5670
log_trace ! ( logger, "Enough info to generate a Data Loss Protect with per_commitment_secret {} for channel {}" , log_bytes!( remote_last_secret) , log_bytes!( self . channel_id( ) ) ) ;
5676
- OptionalField :: Present ( DataLossProtect {
5677
- your_last_per_commitment_secret : remote_last_secret,
5678
- my_current_per_commitment_point : dummy_pubkey
5679
- } )
5671
+ remote_last_secret
5680
5672
} else {
5681
5673
log_info ! ( logger, "Sending a data_loss_protect with no previous remote per_commitment_secret for channel {}" , log_bytes!( self . channel_id( ) ) ) ;
5682
- OptionalField :: Present ( DataLossProtect {
5683
- your_last_per_commitment_secret : [ 0 ; 32 ] ,
5684
- my_current_per_commitment_point : dummy_pubkey,
5685
- } )
5674
+ [ 0 ; 32 ]
5686
5675
} ;
5687
5676
msgs:: ChannelReestablish {
5688
5677
channel_id : self . channel_id ( ) ,
@@ -5704,7 +5693,8 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
5704
5693
// dropped this channel on disconnect as it hasn't yet reached FundingSent so we can't
5705
5694
// overflow here.
5706
5695
next_remote_commitment_number : INITIAL_COMMITMENT_NUMBER - self . cur_counterparty_commitment_transaction_number - 1 ,
5707
- data_loss_protect,
5696
+ your_last_per_commitment_secret : remote_last_secret,
5697
+ my_current_per_commitment_point : dummy_pubkey,
5708
5698
}
5709
5699
}
5710
5700
@@ -7038,7 +7028,7 @@ mod tests {
7038
7028
use crate :: ln:: channel:: { Channel , InboundHTLCOutput , OutboundHTLCOutput , InboundHTLCState , OutboundHTLCState , HTLCCandidate , HTLCInitiator } ;
7039
7029
use crate :: ln:: channel:: { MAX_FUNDING_SATOSHIS_NO_WUMBO , TOTAL_BITCOIN_SUPPLY_SATOSHIS , MIN_THEIR_CHAN_RESERVE_SATOSHIS } ;
7040
7030
use crate :: ln:: features:: ChannelTypeFeatures ;
7041
- use crate :: ln:: msgs:: { ChannelUpdate , DataLossProtect , DecodeError , OptionalField , UnsignedChannelUpdate , MAX_VALUE_MSAT } ;
7031
+ use crate :: ln:: msgs:: { ChannelUpdate , DecodeError , UnsignedChannelUpdate , MAX_VALUE_MSAT } ;
7042
7032
use crate :: ln:: script:: ShutdownScript ;
7043
7033
use crate :: ln:: chan_utils;
7044
7034
use crate :: ln:: chan_utils:: { htlc_success_tx_weight, htlc_timeout_tx_weight} ;
@@ -7339,25 +7329,15 @@ mod tests {
7339
7329
let msg = node_b_chan. get_channel_reestablish ( & & logger) ;
7340
7330
assert_eq ! ( msg. next_local_commitment_number, 1 ) ; // now called next_commitment_number
7341
7331
assert_eq ! ( msg. next_remote_commitment_number, 0 ) ; // now called next_revocation_number
7342
- match msg. data_loss_protect {
7343
- OptionalField :: Present ( DataLossProtect { your_last_per_commitment_secret, .. } ) => {
7344
- assert_eq ! ( your_last_per_commitment_secret, [ 0 ; 32 ] ) ;
7345
- } ,
7346
- _ => panic ! ( )
7347
- }
7332
+ assert_eq ! ( msg. your_last_per_commitment_secret, [ 0 ; 32 ] ) ;
7348
7333
7349
7334
// Check that the commitment point in Node A's channel_reestablish message
7350
7335
// is sane.
7351
7336
node_a_chan. remove_uncommitted_htlcs_and_mark_paused ( & & logger) ;
7352
7337
let msg = node_a_chan. get_channel_reestablish ( & & logger) ;
7353
7338
assert_eq ! ( msg. next_local_commitment_number, 1 ) ; // now called next_commitment_number
7354
7339
assert_eq ! ( msg. next_remote_commitment_number, 0 ) ; // now called next_revocation_number
7355
- match msg. data_loss_protect {
7356
- OptionalField :: Present ( DataLossProtect { your_last_per_commitment_secret, .. } ) => {
7357
- assert_eq ! ( your_last_per_commitment_secret, [ 0 ; 32 ] ) ;
7358
- } ,
7359
- _ => panic ! ( )
7360
- }
7340
+ assert_eq ! ( msg. your_last_per_commitment_secret, [ 0 ; 32 ] ) ;
7361
7341
}
7362
7342
7363
7343
#[ test]
0 commit comments