@@ -20,14 +20,12 @@ use bitcoin::script::{Script, ScriptBuf};
20
20
use bitcoin:: hashes:: { Hash , HashEngine } ;
21
21
use bitcoin:: hashes:: sha256:: Hash as Sha256 ;
22
22
use bitcoin:: hash_types:: { Txid , BlockHash } ;
23
- use bitcoin:: secp256k1:: PublicKey ;
24
23
use bitcoin:: secp256k1:: { Secp256k1 , ecdsa:: Signature } ;
25
24
use bitcoin:: secp256k1;
26
25
27
26
use crate :: chain:: chaininterface:: { ConfirmationTarget , compute_feerate_sat_per_1000_weight} ;
28
- use crate :: sign:: { ChannelDerivationParameters , HTLCDescriptor , EntropySource , SignerProvider , ecdsa:: EcdsaChannelSigner } ;
27
+ use crate :: sign:: { EntropySource , HTLCDescriptor , SignerProvider , ecdsa:: EcdsaChannelSigner } ;
29
28
use crate :: ln:: msgs:: DecodeError ;
30
- use crate :: types:: payment:: PaymentPreimage ;
31
29
use crate :: ln:: chan_utils:: { self , ChannelTransactionParameters , HTLCOutputInCommitment , HolderCommitmentTransaction } ;
32
30
use crate :: chain:: ClaimId ;
33
31
use crate :: chain:: chaininterface:: { FeeEstimator , BroadcasterInterface , LowerBoundedFeeEstimator } ;
@@ -173,17 +171,6 @@ impl Writeable for Option<Vec<Option<(usize, Signature)>>> {
173
171
}
174
172
}
175
173
176
- /// The claim commonly referred to as the pre-signed second-stage HTLC transaction.
177
- #[ derive( Clone , PartialEq , Eq ) ]
178
- pub ( crate ) struct ExternalHTLCClaim {
179
- pub ( crate ) commitment_txid : Txid ,
180
- pub ( crate ) per_commitment_number : u64 ,
181
- pub ( crate ) htlc : HTLCOutputInCommitment ,
182
- pub ( crate ) preimage : Option < PaymentPreimage > ,
183
- pub ( crate ) counterparty_sig : Signature ,
184
- pub ( crate ) per_commitment_point : PublicKey ,
185
- }
186
-
187
174
// Represents the different types of claims for which events are yielded externally to satisfy said
188
175
// claims.
189
176
#[ derive( Clone , PartialEq , Eq ) ]
@@ -202,7 +189,7 @@ pub(crate) enum ClaimEvent {
202
189
/// resolved by broadcasting a transaction with sufficient fee to claim them.
203
190
BumpHTLC {
204
191
target_feerate_sat_per_1000_weight : u32 ,
205
- htlcs : Vec < ExternalHTLCClaim > ,
192
+ htlcs : Vec < HTLCDescriptor > ,
206
193
tx_lock_time : LockTime ,
207
194
} ,
208
195
}
@@ -234,7 +221,7 @@ pub(crate) enum FeerateStrategy {
234
221
#[ derive( Clone ) ]
235
222
pub struct OnchainTxHandler < ChannelSigner : EcdsaChannelSigner > {
236
223
channel_value_satoshis : u64 ,
237
- channel_keys_id : [ u8 ; 32 ] ,
224
+ channel_keys_id : [ u8 ; 32 ] , // Deprecated as of 0.2.
238
225
destination_script : ScriptBuf , // Deprecated as of 0.2.
239
226
holder_commitment : HolderCommitmentTransaction ,
240
227
prev_holder_commitment : Option < HolderCommitmentTransaction > ,
@@ -610,19 +597,16 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
610
597
let target_feerate_sat_per_1000_weight = cached_request. compute_package_feerate (
611
598
fee_estimator, conf_target, feerate_strategy,
612
599
) ;
613
- if let Some ( htlcs) = cached_request. construct_malleable_package_with_external_funding ( self ) {
614
- return Some ( (
615
- new_timer,
616
- target_feerate_sat_per_1000_weight as u64 ,
617
- OnchainClaim :: Event ( ClaimEvent :: BumpHTLC {
618
- target_feerate_sat_per_1000_weight,
619
- htlcs,
620
- tx_lock_time : LockTime :: from_consensus ( cached_request. package_locktime ( cur_height) ) ,
621
- } ) ,
622
- ) ) ;
623
- } else {
624
- return None ;
625
- }
600
+ let htlcs = cached_request. construct_malleable_package_with_external_funding ( self ) ?;
601
+ return Some ( (
602
+ new_timer,
603
+ target_feerate_sat_per_1000_weight as u64 ,
604
+ OnchainClaim :: Event ( ClaimEvent :: BumpHTLC {
605
+ target_feerate_sat_per_1000_weight,
606
+ htlcs,
607
+ tx_lock_time : LockTime :: from_consensus ( cached_request. package_locktime ( cur_height) ) ,
608
+ } ) ,
609
+ ) ) ;
626
610
}
627
611
628
612
let predicted_weight = cached_request. package_weight ( destination_script) ;
@@ -1219,87 +1203,14 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
1219
1203
self . prev_holder_commitment = Some ( replace ( & mut self . holder_commitment , tx) ) ;
1220
1204
}
1221
1205
1222
- #[ cfg( any( test, feature="_test_utils" , feature="unsafe_revoked_tx_signing" ) ) ]
1223
- pub ( crate ) fn get_fully_signed_copy_holder_tx ( & mut self , funding_redeemscript : & Script ) -> Transaction {
1224
- let sig = self . signer . unsafe_sign_holder_commitment ( & self . channel_transaction_parameters , & self . holder_commitment , & self . secp_ctx ) . expect ( "sign holder commitment" ) ;
1225
- self . holder_commitment . add_holder_sig ( funding_redeemscript, sig)
1226
- }
1227
-
1228
- pub ( crate ) fn get_maybe_signed_htlc_tx ( & mut self , outp : & :: bitcoin:: OutPoint , preimage : & Option < PaymentPreimage > ) -> Option < MaybeSignedTransaction > {
1229
- let get_signed_htlc_tx = |holder_commitment : & HolderCommitmentTransaction | {
1230
- let trusted_tx = holder_commitment. trust ( ) ;
1231
- if trusted_tx. txid ( ) != outp. txid {
1232
- return None ;
1233
- }
1234
- let ( htlc_idx, htlc) = trusted_tx. htlcs ( ) . iter ( ) . enumerate ( )
1235
- . find ( |( _, htlc) | htlc. transaction_output_index . unwrap ( ) == outp. vout )
1236
- . unwrap ( ) ;
1237
- let counterparty_htlc_sig = holder_commitment. counterparty_htlc_sigs [ htlc_idx] ;
1238
- let mut htlc_tx = trusted_tx. build_unsigned_htlc_tx (
1239
- & self . channel_transaction_parameters . as_holder_broadcastable ( ) , htlc_idx, preimage,
1240
- ) ;
1241
-
1242
- let htlc_descriptor = HTLCDescriptor {
1243
- channel_derivation_parameters : ChannelDerivationParameters {
1244
- value_satoshis : self . channel_value_satoshis ,
1245
- keys_id : self . channel_keys_id ,
1246
- transaction_parameters : self . channel_transaction_parameters . clone ( ) ,
1247
- } ,
1248
- commitment_txid : trusted_tx. txid ( ) ,
1249
- per_commitment_number : trusted_tx. commitment_number ( ) ,
1250
- per_commitment_point : trusted_tx. per_commitment_point ( ) ,
1251
- feerate_per_kw : trusted_tx. feerate_per_kw ( ) ,
1252
- htlc : htlc. clone ( ) ,
1253
- preimage : preimage. clone ( ) ,
1254
- counterparty_sig : counterparty_htlc_sig. clone ( ) ,
1255
- } ;
1256
- if let Ok ( htlc_sig) = self . signer . sign_holder_htlc_transaction ( & htlc_tx, 0 , & htlc_descriptor, & self . secp_ctx ) {
1257
- htlc_tx. input [ 0 ] . witness = trusted_tx. build_htlc_input_witness (
1258
- htlc_idx, & counterparty_htlc_sig, & htlc_sig, preimage,
1259
- ) ;
1260
- }
1261
- Some ( MaybeSignedTransaction ( htlc_tx) )
1262
- } ;
1263
-
1264
- // Check if the HTLC spends from the current holder commitment first, or the previous.
1265
- get_signed_htlc_tx ( & self . holder_commitment )
1266
- . or_else ( || self . prev_holder_commitment . as_ref ( ) . and_then ( |prev_holder_commitment| get_signed_htlc_tx ( prev_holder_commitment) ) )
1267
- }
1268
-
1269
- pub ( crate ) fn generate_external_htlc_claim (
1270
- & self , outp : & :: bitcoin:: OutPoint , preimage : & Option < PaymentPreimage >
1271
- ) -> Option < ExternalHTLCClaim > {
1272
- let find_htlc = |holder_commitment : & HolderCommitmentTransaction | -> Option < ExternalHTLCClaim > {
1273
- let trusted_tx = holder_commitment. trust ( ) ;
1274
- if outp. txid != trusted_tx. txid ( ) {
1275
- return None ;
1276
- }
1277
- trusted_tx. htlcs ( ) . iter ( ) . enumerate ( )
1278
- . find ( |( _, htlc) | if let Some ( output_index) = htlc. transaction_output_index {
1279
- output_index == outp. vout
1280
- } else {
1281
- false
1282
- } )
1283
- . map ( |( htlc_idx, htlc) | {
1284
- let counterparty_htlc_sig = holder_commitment. counterparty_htlc_sigs [ htlc_idx] ;
1285
- ExternalHTLCClaim {
1286
- commitment_txid : trusted_tx. txid ( ) ,
1287
- per_commitment_number : trusted_tx. commitment_number ( ) ,
1288
- htlc : htlc. clone ( ) ,
1289
- preimage : * preimage,
1290
- counterparty_sig : counterparty_htlc_sig,
1291
- per_commitment_point : trusted_tx. per_commitment_point ( ) ,
1292
- }
1293
- } )
1294
- } ;
1295
- // Check if the HTLC spends from the current holder commitment or the previous one otherwise.
1296
- find_htlc ( & self . holder_commitment )
1297
- . or_else ( || self . prev_holder_commitment . as_ref ( ) . map ( |c| find_htlc ( c) ) . flatten ( ) )
1298
- }
1299
-
1300
1206
pub ( crate ) fn channel_type_features ( & self ) -> & ChannelTypeFeatures {
1301
1207
& self . channel_transaction_parameters . channel_type_features
1302
1208
}
1209
+
1210
+ // Deprecated as of 0.2, only use in cases where it was not previously available.
1211
+ pub ( crate ) fn channel_keys_id ( & self ) -> [ u8 ; 32 ] {
1212
+ self . channel_keys_id
1213
+ }
1303
1214
}
1304
1215
1305
1216
#[ cfg( test) ]
@@ -1320,7 +1231,7 @@ mod tests {
1320
1231
} ;
1321
1232
use crate :: ln:: channel_keys:: { DelayedPaymentBasepoint , HtlcBasepoint , RevocationBasepoint } ;
1322
1233
use crate :: ln:: functional_test_utils:: create_dummy_block;
1323
- use crate :: sign:: InMemorySigner ;
1234
+ use crate :: sign:: { ChannelDerivationParameters , HTLCDescriptor , InMemorySigner } ;
1324
1235
use crate :: types:: payment:: { PaymentHash , PaymentPreimage } ;
1325
1236
use crate :: util:: test_utils:: { TestBroadcaster , TestFeeEstimator , TestLogger } ;
1326
1237
@@ -1425,17 +1336,27 @@ mod tests {
1425
1336
let logger = TestLogger :: new ( ) ;
1426
1337
1427
1338
// Request claiming of each HTLC on the holder's commitment, with current block height 1.
1428
- let holder_commit_txid = tx_handler. current_holder_commitment_tx ( ) . trust ( ) . txid ( ) ;
1339
+ let holder_commit = tx_handler. current_holder_commitment_tx ( ) ;
1340
+ let holder_commit_txid = holder_commit. trust ( ) . txid ( ) ;
1429
1341
let mut requests = Vec :: new ( ) ;
1430
- for ( htlc , _ ) in htlcs {
1342
+ for ( idx , htlc ) in holder_commit . htlcs ( ) . iter ( ) . enumerate ( ) {
1431
1343
requests. push ( PackageTemplate :: build_package (
1432
1344
holder_commit_txid,
1433
1345
htlc. transaction_output_index . unwrap ( ) ,
1434
- PackageSolvingData :: HolderHTLCOutput ( HolderHTLCOutput :: build_offered (
1435
- htlc. amount_msat ,
1436
- htlc. cltv_expiry ,
1437
- ChannelTypeFeatures :: only_static_remote_key ( ) ,
1438
- ) ) ,
1346
+ PackageSolvingData :: HolderHTLCOutput ( HolderHTLCOutput :: build ( HTLCDescriptor {
1347
+ channel_derivation_parameters : ChannelDerivationParameters {
1348
+ value_satoshis : tx_handler. channel_value_satoshis ,
1349
+ keys_id : tx_handler. channel_keys_id ,
1350
+ transaction_parameters : tx_handler. channel_transaction_parameters . clone ( ) ,
1351
+ } ,
1352
+ commitment_txid : holder_commit_txid,
1353
+ per_commitment_number : holder_commit. commitment_number ( ) ,
1354
+ per_commitment_point : holder_commit. per_commitment_point ( ) ,
1355
+ feerate_per_kw : holder_commit. feerate_per_kw ( ) ,
1356
+ htlc : htlc. clone ( ) ,
1357
+ preimage : None ,
1358
+ counterparty_sig : holder_commit. counterparty_htlc_sigs [ idx] . clone ( ) ,
1359
+ } ) ) ,
1439
1360
0 ,
1440
1361
) ) ;
1441
1362
}
0 commit comments