@@ -20,14 +20,12 @@ use bitcoin::script::{Script, ScriptBuf};
2020use bitcoin:: hashes:: { Hash , HashEngine } ;
2121use bitcoin:: hashes:: sha256:: Hash as Sha256 ;
2222use bitcoin:: hash_types:: { Txid , BlockHash } ;
23- use bitcoin:: secp256k1:: PublicKey ;
2423use bitcoin:: secp256k1:: { Secp256k1 , ecdsa:: Signature } ;
2524use bitcoin:: secp256k1;
2625
2726use 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 } ;
2928use crate :: ln:: msgs:: DecodeError ;
30- use crate :: types:: payment:: PaymentPreimage ;
3129use crate :: ln:: chan_utils:: { self , ChannelTransactionParameters , HTLCOutputInCommitment , HolderCommitmentTransaction } ;
3230use crate :: chain:: ClaimId ;
3331use crate :: chain:: chaininterface:: { FeeEstimator , BroadcasterInterface , LowerBoundedFeeEstimator } ;
@@ -173,17 +171,6 @@ impl Writeable for Option<Vec<Option<(usize, Signature)>>> {
173171 }
174172}
175173
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-
187174// Represents the different types of claims for which events are yielded externally to satisfy said
188175// claims.
189176#[ derive( Clone , PartialEq , Eq ) ]
@@ -202,7 +189,7 @@ pub(crate) enum ClaimEvent {
202189 /// resolved by broadcasting a transaction with sufficient fee to claim them.
203190 BumpHTLC {
204191 target_feerate_sat_per_1000_weight : u32 ,
205- htlcs : Vec < ExternalHTLCClaim > ,
192+ htlcs : Vec < HTLCDescriptor > ,
206193 tx_lock_time : LockTime ,
207194 } ,
208195}
@@ -234,7 +221,7 @@ pub(crate) enum FeerateStrategy {
234221#[ derive( Clone ) ]
235222pub struct OnchainTxHandler < ChannelSigner : EcdsaChannelSigner > {
236223 channel_value_satoshis : u64 ,
237- channel_keys_id : [ u8 ; 32 ] ,
224+ channel_keys_id : [ u8 ; 32 ] , // Deprecated as of 0.2.
238225 destination_script : ScriptBuf , // Deprecated as of 0.2.
239226 holder_commitment : HolderCommitmentTransaction ,
240227 prev_holder_commitment : Option < HolderCommitmentTransaction > ,
@@ -610,19 +597,16 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
610597 let target_feerate_sat_per_1000_weight = cached_request. compute_package_feerate (
611598 fee_estimator, conf_target, feerate_strategy,
612599 ) ;
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+ ) ) ;
626610 }
627611
628612 let predicted_weight = cached_request. package_weight ( destination_script) ;
@@ -1218,87 +1202,14 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
12181202 self . prev_holder_commitment = Some ( replace ( & mut self . holder_commitment , tx) ) ;
12191203 }
12201204
1221- #[ cfg( any( test, feature="_test_utils" , feature="unsafe_revoked_tx_signing" ) ) ]
1222- pub ( crate ) fn get_fully_signed_copy_holder_tx ( & mut self , funding_redeemscript : & Script ) -> Transaction {
1223- let sig = self . signer . unsafe_sign_holder_commitment ( & self . channel_transaction_parameters , & self . holder_commitment , & self . secp_ctx ) . expect ( "sign holder commitment" ) ;
1224- self . holder_commitment . add_holder_sig ( funding_redeemscript, sig)
1225- }
1226-
1227- pub ( crate ) fn get_maybe_signed_htlc_tx ( & mut self , outp : & :: bitcoin:: OutPoint , preimage : & Option < PaymentPreimage > ) -> Option < MaybeSignedTransaction > {
1228- let get_signed_htlc_tx = |holder_commitment : & HolderCommitmentTransaction | {
1229- let trusted_tx = holder_commitment. trust ( ) ;
1230- if trusted_tx. txid ( ) != outp. txid {
1231- return None ;
1232- }
1233- let ( htlc_idx, htlc) = trusted_tx. htlcs ( ) . iter ( ) . enumerate ( )
1234- . find ( |( _, htlc) | htlc. transaction_output_index . unwrap ( ) == outp. vout )
1235- . unwrap ( ) ;
1236- let counterparty_htlc_sig = holder_commitment. counterparty_htlc_sigs [ htlc_idx] ;
1237- let mut htlc_tx = trusted_tx. build_unsigned_htlc_tx (
1238- & self . channel_transaction_parameters . as_holder_broadcastable ( ) , htlc_idx, preimage,
1239- ) ;
1240-
1241- let htlc_descriptor = HTLCDescriptor {
1242- channel_derivation_parameters : ChannelDerivationParameters {
1243- value_satoshis : self . channel_value_satoshis ,
1244- keys_id : self . channel_keys_id ,
1245- transaction_parameters : self . channel_transaction_parameters . clone ( ) ,
1246- } ,
1247- commitment_txid : trusted_tx. txid ( ) ,
1248- per_commitment_number : trusted_tx. commitment_number ( ) ,
1249- per_commitment_point : trusted_tx. per_commitment_point ( ) ,
1250- feerate_per_kw : trusted_tx. feerate_per_kw ( ) ,
1251- htlc : htlc. clone ( ) ,
1252- preimage : preimage. clone ( ) ,
1253- counterparty_sig : counterparty_htlc_sig. clone ( ) ,
1254- } ;
1255- if let Ok ( htlc_sig) = self . signer . sign_holder_htlc_transaction ( & htlc_tx, 0 , & htlc_descriptor, & self . secp_ctx ) {
1256- htlc_tx. input [ 0 ] . witness = trusted_tx. build_htlc_input_witness (
1257- htlc_idx, & counterparty_htlc_sig, & htlc_sig, preimage,
1258- ) ;
1259- }
1260- Some ( MaybeSignedTransaction ( htlc_tx) )
1261- } ;
1262-
1263- // Check if the HTLC spends from the current holder commitment first, or the previous.
1264- get_signed_htlc_tx ( & self . holder_commitment )
1265- . or_else ( || self . prev_holder_commitment . as_ref ( ) . and_then ( |prev_holder_commitment| get_signed_htlc_tx ( prev_holder_commitment) ) )
1266- }
1267-
1268- pub ( crate ) fn generate_external_htlc_claim (
1269- & self , outp : & :: bitcoin:: OutPoint , preimage : & Option < PaymentPreimage >
1270- ) -> Option < ExternalHTLCClaim > {
1271- let find_htlc = |holder_commitment : & HolderCommitmentTransaction | -> Option < ExternalHTLCClaim > {
1272- let trusted_tx = holder_commitment. trust ( ) ;
1273- if outp. txid != trusted_tx. txid ( ) {
1274- return None ;
1275- }
1276- trusted_tx. htlcs ( ) . iter ( ) . enumerate ( )
1277- . find ( |( _, htlc) | if let Some ( output_index) = htlc. transaction_output_index {
1278- output_index == outp. vout
1279- } else {
1280- false
1281- } )
1282- . map ( |( htlc_idx, htlc) | {
1283- let counterparty_htlc_sig = holder_commitment. counterparty_htlc_sigs [ htlc_idx] ;
1284- ExternalHTLCClaim {
1285- commitment_txid : trusted_tx. txid ( ) ,
1286- per_commitment_number : trusted_tx. commitment_number ( ) ,
1287- htlc : htlc. clone ( ) ,
1288- preimage : * preimage,
1289- counterparty_sig : counterparty_htlc_sig,
1290- per_commitment_point : trusted_tx. per_commitment_point ( ) ,
1291- }
1292- } )
1293- } ;
1294- // Check if the HTLC spends from the current holder commitment or the previous one otherwise.
1295- find_htlc ( & self . holder_commitment )
1296- . or_else ( || self . prev_holder_commitment . as_ref ( ) . map ( |c| find_htlc ( c) ) . flatten ( ) )
1297- }
1298-
12991205 pub ( crate ) fn channel_type_features ( & self ) -> & ChannelTypeFeatures {
13001206 & self . channel_transaction_parameters . channel_type_features
13011207 }
1208+
1209+ // Deprecated as of 0.2, only use in cases where it was not previously available.
1210+ pub ( crate ) fn channel_keys_id ( & self ) -> [ u8 ; 32 ] {
1211+ self . channel_keys_id
1212+ }
13021213}
13031214
13041215#[ cfg( test) ]
@@ -1319,7 +1230,7 @@ mod tests {
13191230 } ;
13201231 use crate :: ln:: channel_keys:: { DelayedPaymentBasepoint , HtlcBasepoint , RevocationBasepoint } ;
13211232 use crate :: ln:: functional_test_utils:: create_dummy_block;
1322- use crate :: sign:: InMemorySigner ;
1233+ use crate :: sign:: { ChannelDerivationParameters , HTLCDescriptor , InMemorySigner } ;
13231234 use crate :: types:: payment:: { PaymentHash , PaymentPreimage } ;
13241235 use crate :: util:: test_utils:: { TestBroadcaster , TestFeeEstimator , TestLogger } ;
13251236
@@ -1424,17 +1335,27 @@ mod tests {
14241335 let logger = TestLogger :: new ( ) ;
14251336
14261337 // Request claiming of each HTLC on the holder's commitment, with current block height 1.
1427- let holder_commit_txid = tx_handler. current_holder_commitment_tx ( ) . trust ( ) . txid ( ) ;
1338+ let holder_commit = tx_handler. current_holder_commitment_tx ( ) ;
1339+ let holder_commit_txid = holder_commit. trust ( ) . txid ( ) ;
14281340 let mut requests = Vec :: new ( ) ;
1429- for ( htlc , _ ) in htlcs {
1341+ for ( idx , htlc ) in holder_commit . htlcs ( ) . iter ( ) . enumerate ( ) {
14301342 requests. push ( PackageTemplate :: build_package (
14311343 holder_commit_txid,
14321344 htlc. transaction_output_index . unwrap ( ) ,
1433- PackageSolvingData :: HolderHTLCOutput ( HolderHTLCOutput :: build_offered (
1434- htlc. amount_msat ,
1435- htlc. cltv_expiry ,
1436- ChannelTypeFeatures :: only_static_remote_key ( ) ,
1437- ) ) ,
1345+ PackageSolvingData :: HolderHTLCOutput ( HolderHTLCOutput :: build ( HTLCDescriptor {
1346+ channel_derivation_parameters : ChannelDerivationParameters {
1347+ value_satoshis : tx_handler. channel_value_satoshis ,
1348+ keys_id : tx_handler. channel_keys_id ,
1349+ transaction_parameters : tx_handler. channel_transaction_parameters . clone ( ) ,
1350+ } ,
1351+ commitment_txid : holder_commit_txid,
1352+ per_commitment_number : holder_commit. commitment_number ( ) ,
1353+ per_commitment_point : holder_commit. per_commitment_point ( ) ,
1354+ feerate_per_kw : holder_commit. feerate_per_kw ( ) ,
1355+ htlc : htlc. clone ( ) ,
1356+ preimage : None ,
1357+ counterparty_sig : holder_commit. counterparty_htlc_sigs [ idx] . clone ( ) ,
1358+ } ) ) ,
14381359 0 ,
14391360 ) ) ;
14401361 }
0 commit comments