@@ -497,9 +497,13 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
497497 }
498498 match claim {
499499 OnchainClaim :: Tx ( tx) => {
500- let log_start = if bumped_feerate { "Broadcasting RBF-bumped" } else { "Rebroadcasting" } ;
501- log_info ! ( logger, "{} onchain {}" , log_start, log_tx!( tx) ) ;
502- broadcaster. broadcast_transactions ( & [ & tx] ) ;
500+ if tx. input . iter ( ) . any ( |input| input. witness . is_empty ( ) ) {
501+ log_info ! ( logger, "Waiting for signature of unsigned onchain transaction {}" , tx. txid( ) ) ;
502+ } else {
503+ let log_start = if bumped_feerate { "Broadcasting RBF-bumped" } else { "Rebroadcasting" } ;
504+ log_info ! ( logger, "{} onchain {}" , log_start, log_tx!( tx) ) ;
505+ broadcaster. broadcast_transactions ( & [ & tx] ) ;
506+ }
503507 } ,
504508 OnchainClaim :: Event ( event) => {
505509 let log_start = if bumped_feerate { "Yielding fee-bumped" } else { "Replaying" } ;
@@ -636,8 +640,8 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
636640 let commitment_tx_feerate_sat_per_1000_weight =
637641 compute_feerate_sat_per_1000_weight ( fee_sat, tx. weight ( ) . to_wu ( ) ) ;
638642 if commitment_tx_feerate_sat_per_1000_weight >= package_target_feerate_sat_per_1000_weight {
639- log_debug ! ( logger, "Pre-signed {} already has feerate {} sat/kW above required {} sat/kW" ,
640- log_tx! ( tx ) , commitment_tx_feerate_sat_per_1000_weight,
643+ log_debug ! ( logger, "Pre-signed commitment {} already has feerate {} sat/kW above required {} sat/kW" ,
644+ tx . txid ( ) , commitment_tx_feerate_sat_per_1000_weight,
641645 package_target_feerate_sat_per_1000_weight) ;
642646 return Some ( ( new_timer, 0 , OnchainClaim :: Tx ( tx. clone ( ) ) ) ) ;
643647 }
@@ -776,8 +780,12 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
776780 // `OnchainClaim`.
777781 let claim_id = match claim {
778782 OnchainClaim :: Tx ( tx) => {
779- log_info ! ( logger, "Broadcasting onchain {}" , log_tx!( tx) ) ;
780- broadcaster. broadcast_transactions ( & [ & tx] ) ;
783+ if tx. input . iter ( ) . any ( |input| input. witness . is_empty ( ) ) {
784+ log_info ! ( logger, "Waiting for signature of unsigned onchain transaction {}" , tx. txid( ) ) ;
785+ } else {
786+ log_info ! ( logger, "Broadcasting onchain {}" , log_tx!( tx) ) ;
787+ broadcaster. broadcast_transactions ( & [ & tx] ) ;
788+ }
781789 ClaimId ( tx. txid ( ) . to_byte_array ( ) )
782790 } ,
783791 OnchainClaim :: Event ( claim_event) => {
@@ -969,8 +977,13 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
969977 ) {
970978 match bump_claim {
971979 OnchainClaim :: Tx ( bump_tx) => {
972- log_info ! ( logger, "Broadcasting RBF-bumped onchain {}" , log_tx!( bump_tx) ) ;
973- broadcaster. broadcast_transactions ( & [ & bump_tx] ) ;
980+ if bump_tx. input . iter ( ) . any ( |input| input. witness . is_empty ( ) ) {
981+ log_info ! ( logger, "Waiting for signature of RBF-bumped unsigned onchain transaction {}" ,
982+ bump_tx. txid( ) ) ;
983+ } else {
984+ log_info ! ( logger, "Broadcasting RBF-bumped onchain {}" , log_tx!( bump_tx) ) ;
985+ broadcaster. broadcast_transactions ( & [ & bump_tx] ) ;
986+ }
974987 } ,
975988 OnchainClaim :: Event ( claim_event) => {
976989 log_info ! ( logger, "Yielding RBF-bumped onchain event to spend inputs {:?}" , request. outpoints( ) ) ;
@@ -1052,8 +1065,12 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
10521065 request. set_feerate ( new_feerate) ;
10531066 match bump_claim {
10541067 OnchainClaim :: Tx ( bump_tx) => {
1055- log_info ! ( logger, "Broadcasting onchain {}" , log_tx!( bump_tx) ) ;
1056- broadcaster. broadcast_transactions ( & [ & bump_tx] ) ;
1068+ if bump_tx. input . iter ( ) . any ( |input| input. witness . is_empty ( ) ) {
1069+ log_info ! ( logger, "Waiting for signature of unsigned onchain transaction {}" , bump_tx. txid( ) ) ;
1070+ } else {
1071+ log_info ! ( logger, "Broadcasting onchain {}" , log_tx!( bump_tx) ) ;
1072+ broadcaster. broadcast_transactions ( & [ & bump_tx] ) ;
1073+ }
10571074 } ,
10581075 OnchainClaim :: Event ( claim_event) => {
10591076 log_info ! ( logger, "Yielding onchain event after reorg to spend inputs {:?}" , request. outpoints( ) ) ;
@@ -1106,13 +1123,10 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
11061123 & self . holder_commitment . trust ( ) . built_transaction ( ) . transaction
11071124 }
11081125
1109- //TODO: getting lastest holder transactions should be infallible and result in us "force-closing the channel", but we may
1110- // have empty holder commitment transaction if a ChannelMonitor is asked to force-close just after OutboundV1Channel::get_funding_created,
1111- // before providing a initial commitment transaction. For outbound channel, init ChannelMonitor at Channel::funding_signed, there is nothing
1112- // to monitor before.
1113- pub ( crate ) fn get_fully_signed_holder_tx ( & mut self , funding_redeemscript : & Script ) -> Transaction {
1114- let sig = self . signer . sign_holder_commitment ( & self . holder_commitment , & self . secp_ctx ) . expect ( "signing holder commitment" ) ;
1115- self . holder_commitment . add_holder_sig ( funding_redeemscript, sig)
1126+ pub ( crate ) fn get_maybe_signed_holder_tx ( & mut self , funding_redeemscript : & Script ) -> Transaction {
1127+ self . signer . sign_holder_commitment ( & self . holder_commitment , & self . secp_ctx )
1128+ . map ( |sig| self . holder_commitment . add_holder_sig ( funding_redeemscript, sig) )
1129+ . unwrap_or_else ( |_| self . get_unsigned_holder_commitment_tx ( ) . clone ( ) )
11161130 }
11171131
11181132 #[ cfg( any( test, feature="unsafe_revoked_tx_signing" ) ) ]
@@ -1121,7 +1135,7 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
11211135 self . holder_commitment . add_holder_sig ( funding_redeemscript, sig)
11221136 }
11231137
1124- pub ( crate ) fn get_fully_signed_htlc_tx ( & mut self , outp : & :: bitcoin:: OutPoint , preimage : & Option < PaymentPreimage > ) -> Option < Transaction > {
1138+ pub ( crate ) fn get_maybe_signed_htlc_tx ( & mut self , outp : & :: bitcoin:: OutPoint , preimage : & Option < PaymentPreimage > ) -> Option < Transaction > {
11251139 let get_signed_htlc_tx = |holder_commitment : & HolderCommitmentTransaction | {
11261140 let trusted_tx = holder_commitment. trust ( ) ;
11271141 if trusted_tx. txid ( ) != outp. txid {
@@ -1149,10 +1163,11 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
11491163 preimage : preimage. clone ( ) ,
11501164 counterparty_sig : counterparty_htlc_sig. clone ( ) ,
11511165 } ;
1152- let htlc_sig = self . signer . sign_holder_htlc_transaction ( & htlc_tx, 0 , & htlc_descriptor, & self . secp_ctx ) . unwrap ( ) ;
1153- htlc_tx. input [ 0 ] . witness = trusted_tx. build_htlc_input_witness (
1154- htlc_idx, & counterparty_htlc_sig, & htlc_sig, preimage,
1155- ) ;
1166+ if let Ok ( htlc_sig) = self . signer . sign_holder_htlc_transaction ( & htlc_tx, 0 , & htlc_descriptor, & self . secp_ctx ) {
1167+ htlc_tx. input [ 0 ] . witness = trusted_tx. build_htlc_input_witness (
1168+ htlc_idx, & counterparty_htlc_sig, & htlc_sig, preimage,
1169+ ) ;
1170+ }
11561171 Some ( htlc_tx)
11571172 } ;
11581173
0 commit comments