@@ -106,7 +106,7 @@ impl Writeable for Option<Vec<Option<(usize, Signature)>>> {
106
106
/// do RBF bumping if possible.
107
107
pub struct OnchainTxHandler < ChanSigner : ChannelKeys > {
108
108
destination_script : Script ,
109
- holder_commitment : Option < HolderCommitmentTransaction > ,
109
+ pub ( super ) holder_commitment : Option < HolderCommitmentTransaction > ,
110
110
// holder_htlc_sigs and prev_holder_htlc_sigs are in the order as they appear in the commitment
111
111
// transaction outputs (hence the Option<>s inside the Vec). The first usize is the index in
112
112
// the set of HTLCs in the HolderCommitmentTransaction (including those which do not appear in
@@ -303,7 +303,7 @@ impl<ChanSigner: ChannelKeys> OnchainTxHandler<ChanSigner> {
303
303
304
304
/// Lightning security model (i.e being able to redeem/timeout HTLC or penalize coutnerparty onchain) lays on the assumption of claim transactions getting confirmed before timelock expiration
305
305
/// (CSV or CLTV following cases). In case of high-fee spikes, claim tx may stuck in the mempool, so you need to bump its feerate quickly using Replace-By-Fee or Child-Pay-For-Parent.
306
- fn generate_claim_tx < F : Deref , L : Deref , U : Deref > ( & mut self , height : u32 , cached_request : & mut OnchainRequest , fee_estimator : F , logger : L , utxo_pool : U ) -> Option < ( Option < u32 > , u64 , Transaction ) >
306
+ fn generate_claim_tx < F : Deref , L : Deref , U : Deref > ( & mut self , height : u32 , cached_request : & mut OnchainRequest , fee_estimator : F , logger : L , utxo_pool : U ) -> Option < ( Option < u32 > , u64 , Vec < Transaction > ) >
307
307
where F :: Target : FeeEstimator ,
308
308
L :: Target : Logger ,
309
309
U :: Target : UtxoPool ,
@@ -323,15 +323,17 @@ impl<ChanSigner: ChannelKeys> OnchainTxHandler<ChanSigner> {
323
323
if let Some ( ( output_value, new_feerate) ) = onchain_utils:: compute_output_value ( predicted_weight, amt, cached_request. feerate_previous , & fee_estimator, & logger) {
324
324
assert ! ( new_feerate != 0 ) ;
325
325
326
- let transaction = cached_request. content . package_finalize ( self , output_value, self . destination_script . clone ( ) , & logger) . unwrap ( ) ;
327
- log_trace ! ( logger, "...with timer {} and feerate {}" , new_timer. unwrap( ) , new_feerate) ;
328
- assert ! ( predicted_weight >= transaction. get_weight( ) ) ;
329
- // Temporary: disable timer for CPFP-package
330
- if cached_request. bump_strategy == BumpStrategy :: CPFP {
326
+ let txn = cached_request. content . package_finalize ( self , output_value, self . destination_script . clone ( ) , & logger, & utxo_pool) . unwrap ( ) ;
327
+ log_trace ! ( logger, "...with timer {} weight {} feerate {} CPFP: {}" , new_timer. unwrap( ) , predicted_weight, new_feerate, txn. len( ) > 1 ) ;
328
+ assert ! ( predicted_weight >= txn[ 0 ] . get_weight( ) + if txn. len( ) == 2 { txn[ 1 ] . get_weight( ) } else { 0 } ) ;
329
+ //TODO: for now disable timer for CPFP-package (2nd-stage HTLC only).
330
+ // Enabling them is pending on refactoring first holder HTLCs construction
331
+ // and signing.
332
+ if predicted_weight == 706 || predicted_weight == 666 {
331
333
new_timer = None ;
332
334
}
333
335
334
- return Some ( ( new_timer, new_feerate, transaction ) )
336
+ return Some ( ( new_timer, new_feerate, txn ) )
335
337
}
336
338
None
337
339
}
@@ -365,17 +367,19 @@ impl<ChanSigner: ChannelKeys> OnchainTxHandler<ChanSigner> {
365
367
// Generate claim transactions and track them to bump if necessary at
366
368
// height timer expiration (i.e in how many blocks we're going to take action).
367
369
for mut req in preprocessed_requests {
368
- if let Some ( ( new_timer, new_feerate, tx ) ) = self . generate_claim_tx ( height, & mut req, & * fee_estimator, & * logger, & * utxo_pool) {
370
+ if let Some ( ( new_timer, new_feerate, txn ) ) = self . generate_claim_tx ( height, & mut req, & * fee_estimator, & * logger, & * utxo_pool) {
369
371
req. height_timer = new_timer;
370
372
req. feerate_previous = new_feerate;
371
- let txid = tx . txid ( ) ;
373
+ let txid = txn [ 0 ] . txid ( ) ;
372
374
for k in req. content . outpoints ( ) {
373
375
log_trace ! ( logger, "Registering claiming request for {}:{}" , k. txid, k. vout) ;
374
376
self . claimable_outpoints . insert ( k. clone ( ) , ( txid, height) ) ;
375
377
}
376
378
self . pending_claim_requests . insert ( txid, req) ;
377
- log_trace ! ( logger, "Broadcast onchain {}" , log_tx!( tx) ) ;
378
- broadcaster. broadcast_transaction ( & tx) ;
379
+ for tx in txn {
380
+ log_trace ! ( logger, "Broadcast onchain {}" , log_tx!( tx) ) ;
381
+ broadcaster. broadcast_transaction ( & tx) ;
382
+ }
379
383
}
380
384
}
381
385
@@ -492,9 +496,11 @@ impl<ChanSigner: ChannelKeys> OnchainTxHandler<ChanSigner> {
492
496
// Build, bump and rebroadcast tx accordingly
493
497
log_trace ! ( logger, "Bumping {} candidates" , bump_candidates. len( ) ) ;
494
498
for ( first_claim_txid, ref mut request) in bump_candidates. iter_mut ( ) {
495
- if let Some ( ( new_timer, new_feerate, bump_tx) ) = self . generate_claim_tx ( height, request, & * fee_estimator, & * logger, & * utxo_pool) {
496
- log_trace ! ( logger, "Broadcast onchain {}" , log_tx!( bump_tx) ) ;
497
- broadcaster. broadcast_transaction ( & bump_tx) ;
499
+ if let Some ( ( new_timer, new_feerate, txn) ) = self . generate_claim_tx ( height, request, & * fee_estimator, & * logger, & * utxo_pool) {
500
+ for tx in txn {
501
+ log_trace ! ( logger, "Broadcast onchain {}" , log_tx!( tx) ) ;
502
+ broadcaster. broadcast_transaction ( & tx) ;
503
+ }
498
504
if let Some ( request) = self . pending_claim_requests . get_mut ( first_claim_txid) {
499
505
request. height_timer = new_timer;
500
506
request. feerate_previous = new_feerate;
@@ -530,10 +536,12 @@ impl<ChanSigner: ChannelKeys> OnchainTxHandler<ChanSigner> {
530
536
}
531
537
}
532
538
for ( _, ref mut request) in bump_candidates. iter_mut ( ) {
533
- if let Some ( ( new_timer, new_feerate, bump_tx ) ) = self . generate_claim_tx ( height, request, & * fee_estimator, & * logger, & * utxo_pool) {
539
+ if let Some ( ( new_timer, new_feerate, txn ) ) = self . generate_claim_tx ( height, request, & * fee_estimator, & * logger, & * utxo_pool) {
534
540
request. height_timer = new_timer;
535
541
request. feerate_previous = new_feerate;
536
- broadcaster. broadcast_transaction ( & bump_tx) ;
542
+ for tx in txn {
543
+ broadcaster. broadcast_transaction ( & tx) ;
544
+ }
537
545
}
538
546
}
539
547
for ( ancestor_claim_txid, request) in bump_candidates. drain ( ) {
0 commit comments