@@ -212,6 +212,8 @@ pub(crate) enum OnchainClaim {
212
212
213
213
/// Represents the different feerates a pending request can use when generating a claim.
214
214
pub ( crate ) enum FeerateStrategy {
215
+ /// We must reuse the most recently used feerate, if any.
216
+ RetryPrevious ,
215
217
/// We must pick the highest between the most recently used and the current feerate estimate.
216
218
HighestOfPreviousOrNew ,
217
219
/// We must force a bump of the most recently used feerate, either by using the current feerate
@@ -506,9 +508,13 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
506
508
}
507
509
match claim {
508
510
OnchainClaim :: Tx ( tx) => {
509
- let log_start = if bumped_feerate { "Broadcasting RBF-bumped" } else { "Rebroadcasting" } ;
510
- log_info ! ( logger, "{} onchain {}" , log_start, log_tx!( tx) ) ;
511
- broadcaster. broadcast_transactions ( & [ & tx] ) ;
511
+ if tx. input . iter ( ) . any ( |input| input. witness . is_empty ( ) ) {
512
+ log_info ! ( logger, "Waiting for signature of unsigned onchain transaction {}" , tx. txid( ) ) ;
513
+ } else {
514
+ let log_start = if bumped_feerate { "Broadcasting RBF-bumped" } else { "Rebroadcasting" } ;
515
+ log_info ! ( logger, "{} onchain {}" , log_start, log_tx!( tx) ) ;
516
+ broadcaster. broadcast_transactions ( & [ & tx] ) ;
517
+ }
512
518
} ,
513
519
OnchainClaim :: Event ( event) => {
514
520
let log_start = if bumped_feerate { "Yielding fee-bumped" } else { "Replaying" } ;
@@ -610,7 +616,7 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
610
616
) {
611
617
assert ! ( new_feerate != 0 ) ;
612
618
613
- let transaction = cached_request. finalize_malleable_package (
619
+ let transaction = cached_request. maybe_finalize_malleable_package (
614
620
cur_height, self , output_value, self . destination_script . clone ( ) , logger
615
621
) . unwrap ( ) ;
616
622
log_trace ! ( logger, "...with timer {} and feerate {}" , new_timer, new_feerate) ;
@@ -623,7 +629,7 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
623
629
// which require external funding.
624
630
let mut inputs = cached_request. inputs ( ) ;
625
631
debug_assert_eq ! ( inputs. len( ) , 1 ) ;
626
- let tx = match cached_request. finalize_untractable_package ( self , logger) {
632
+ let tx = match cached_request. maybe_finalize_untractable_package ( self , logger) {
627
633
Some ( tx) => tx,
628
634
None => return None ,
629
635
} ;
@@ -645,8 +651,8 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
645
651
let commitment_tx_feerate_sat_per_1000_weight =
646
652
compute_feerate_sat_per_1000_weight ( fee_sat, tx. weight ( ) . to_wu ( ) ) ;
647
653
if commitment_tx_feerate_sat_per_1000_weight >= package_target_feerate_sat_per_1000_weight {
648
- log_debug ! ( logger, "Pre-signed {} already has feerate {} sat/kW above required {} sat/kW" ,
649
- log_tx! ( tx ) , commitment_tx_feerate_sat_per_1000_weight,
654
+ log_debug ! ( logger, "Pre-signed commitment {} already has feerate {} sat/kW above required {} sat/kW" ,
655
+ tx . txid ( ) , commitment_tx_feerate_sat_per_1000_weight,
650
656
package_target_feerate_sat_per_1000_weight) ;
651
657
return Some ( ( new_timer, 0 , OnchainClaim :: Tx ( tx. clone ( ) ) ) ) ;
652
658
}
@@ -785,8 +791,12 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
785
791
// `OnchainClaim`.
786
792
let claim_id = match claim {
787
793
OnchainClaim :: Tx ( tx) => {
788
- log_info ! ( logger, "Broadcasting onchain {}" , log_tx!( tx) ) ;
789
- broadcaster. broadcast_transactions ( & [ & tx] ) ;
794
+ if tx. input . iter ( ) . any ( |input| input. witness . is_empty ( ) ) {
795
+ log_info ! ( logger, "Waiting for signature of unsigned onchain transaction {}" , tx. txid( ) ) ;
796
+ } else {
797
+ log_info ! ( logger, "Broadcasting onchain {}" , log_tx!( tx) ) ;
798
+ broadcaster. broadcast_transactions ( & [ & tx] ) ;
799
+ }
790
800
ClaimId ( tx. txid ( ) . to_byte_array ( ) )
791
801
} ,
792
802
OnchainClaim :: Event ( claim_event) => {
@@ -978,8 +988,13 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
978
988
) {
979
989
match bump_claim {
980
990
OnchainClaim :: Tx ( bump_tx) => {
981
- log_info ! ( logger, "Broadcasting RBF-bumped onchain {}" , log_tx!( bump_tx) ) ;
982
- broadcaster. broadcast_transactions ( & [ & bump_tx] ) ;
991
+ if bump_tx. input . iter ( ) . any ( |input| input. witness . is_empty ( ) ) {
992
+ log_info ! ( logger, "Waiting for signature of RBF-bumped unsigned onchain transaction {}" ,
993
+ bump_tx. txid( ) ) ;
994
+ } else {
995
+ log_info ! ( logger, "Broadcasting RBF-bumped onchain {}" , log_tx!( bump_tx) ) ;
996
+ broadcaster. broadcast_transactions ( & [ & bump_tx] ) ;
997
+ }
983
998
} ,
984
999
OnchainClaim :: Event ( claim_event) => {
985
1000
log_info ! ( logger, "Yielding RBF-bumped onchain event to spend inputs {:?}" , request. outpoints( ) ) ;
@@ -1061,8 +1076,12 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
1061
1076
request. set_feerate ( new_feerate) ;
1062
1077
match bump_claim {
1063
1078
OnchainClaim :: Tx ( bump_tx) => {
1064
- log_info ! ( logger, "Broadcasting onchain {}" , log_tx!( bump_tx) ) ;
1065
- broadcaster. broadcast_transactions ( & [ & bump_tx] ) ;
1079
+ if bump_tx. input . iter ( ) . any ( |input| input. witness . is_empty ( ) ) {
1080
+ log_info ! ( logger, "Waiting for signature of unsigned onchain transaction {}" , bump_tx. txid( ) ) ;
1081
+ } else {
1082
+ log_info ! ( logger, "Broadcasting onchain {}" , log_tx!( bump_tx) ) ;
1083
+ broadcaster. broadcast_transactions ( & [ & bump_tx] ) ;
1084
+ }
1066
1085
} ,
1067
1086
OnchainClaim :: Event ( claim_event) => {
1068
1087
log_info ! ( logger, "Yielding onchain event after reorg to spend inputs {:?}" , request. outpoints( ) ) ;
@@ -1115,13 +1134,10 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
1115
1134
& self . holder_commitment . trust ( ) . built_transaction ( ) . transaction
1116
1135
}
1117
1136
1118
- //TODO: getting lastest holder transactions should be infallible and result in us "force-closing the channel", but we may
1119
- // have empty holder commitment transaction if a ChannelMonitor is asked to force-close just after OutboundV1Channel::get_funding_created,
1120
- // before providing a initial commitment transaction. For outbound channel, init ChannelMonitor at Channel::funding_signed, there is nothing
1121
- // to monitor before.
1122
- pub ( crate ) fn get_fully_signed_holder_tx ( & mut self , funding_redeemscript : & Script ) -> Transaction {
1123
- let sig = self . signer . sign_holder_commitment ( & self . holder_commitment , & self . secp_ctx ) . expect ( "signing holder commitment" ) ;
1124
- self . holder_commitment . add_holder_sig ( funding_redeemscript, sig)
1137
+ pub ( crate ) fn get_maybe_signed_holder_tx ( & mut self , funding_redeemscript : & Script ) -> Transaction {
1138
+ self . signer . sign_holder_commitment ( & self . holder_commitment , & self . secp_ctx )
1139
+ . map ( |sig| self . holder_commitment . add_holder_sig ( funding_redeemscript, sig) )
1140
+ . unwrap_or_else ( |_| self . get_unsigned_holder_commitment_tx ( ) . clone ( ) )
1125
1141
}
1126
1142
1127
1143
#[ cfg( any( test, feature="unsafe_revoked_tx_signing" ) ) ]
@@ -1130,7 +1146,7 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
1130
1146
self . holder_commitment . add_holder_sig ( funding_redeemscript, sig)
1131
1147
}
1132
1148
1133
- pub ( crate ) fn get_fully_signed_htlc_tx ( & mut self , outp : & :: bitcoin:: OutPoint , preimage : & Option < PaymentPreimage > ) -> Option < Transaction > {
1149
+ pub ( crate ) fn get_maybe_signed_htlc_tx ( & mut self , outp : & :: bitcoin:: OutPoint , preimage : & Option < PaymentPreimage > ) -> Option < Transaction > {
1134
1150
let get_signed_htlc_tx = |holder_commitment : & HolderCommitmentTransaction | {
1135
1151
let trusted_tx = holder_commitment. trust ( ) ;
1136
1152
if trusted_tx. txid ( ) != outp. txid {
@@ -1158,10 +1174,11 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
1158
1174
preimage : preimage. clone ( ) ,
1159
1175
counterparty_sig : counterparty_htlc_sig. clone ( ) ,
1160
1176
} ;
1161
- let htlc_sig = self . signer . sign_holder_htlc_transaction ( & htlc_tx, 0 , & htlc_descriptor, & self . secp_ctx ) . unwrap ( ) ;
1162
- htlc_tx. input [ 0 ] . witness = trusted_tx. build_htlc_input_witness (
1163
- htlc_idx, & counterparty_htlc_sig, & htlc_sig, preimage,
1164
- ) ;
1177
+ if let Ok ( htlc_sig) = self . signer . sign_holder_htlc_transaction ( & htlc_tx, 0 , & htlc_descriptor, & self . secp_ctx ) {
1178
+ htlc_tx. input [ 0 ] . witness = trusted_tx. build_htlc_input_witness (
1179
+ htlc_idx, & counterparty_htlc_sig, & htlc_sig, preimage,
1180
+ ) ;
1181
+ }
1165
1182
Some ( htlc_tx)
1166
1183
} ;
1167
1184
0 commit comments