@@ -2169,9 +2169,8 @@ impl<Signer: Sign> Channel<Signer> {
2169
2169
Ok ( ( ) )
2170
2170
}
2171
2171
2172
- pub fn commitment_signed < F : Deref , L : Deref > ( & mut self , msg : & msgs:: CommitmentSigned , fee_estimator : & F , logger : & L ) -> Result < ( msgs:: RevokeAndACK , Option < msgs:: CommitmentSigned > , Option < msgs:: ClosingSigned > , ChannelMonitorUpdate ) , ( Option < ChannelMonitorUpdate > , ChannelError ) >
2173
- where F :: Target : FeeEstimator ,
2174
- L :: Target : Logger
2172
+ pub fn commitment_signed < L : Deref > ( & mut self , msg : & msgs:: CommitmentSigned , logger : & L ) -> Result < ( msgs:: RevokeAndACK , Option < msgs:: CommitmentSigned > , ChannelMonitorUpdate ) , ( Option < ChannelMonitorUpdate > , ChannelError ) >
2173
+ where L :: Target : Logger
2175
2174
{
2176
2175
if ( self . channel_state & ( ChannelState :: ChannelFunded as u32 ) ) != ( ChannelState :: ChannelFunded as u32 ) {
2177
2176
return Err ( ( None , ChannelError :: Close ( "Got commitment signed message when channel was not in an operational state" . to_owned ( ) ) ) ) ;
@@ -2346,12 +2345,10 @@ impl<Signer: Sign> Channel<Signer> {
2346
2345
}
2347
2346
log_debug ! ( logger, "Received valid commitment_signed from peer in channel {}, updated HTLC state but awaiting a monitor update resolution to reply." ,
2348
2347
log_bytes!( self . channel_id) ) ;
2349
- // TODO: Call maybe_propose_first_closing_signed on restoration (or call it here and
2350
- // re-send the message on restoration)
2351
2348
return Err ( ( Some ( monitor_update) , ChannelError :: Ignore ( "Previous monitor update failure prevented generation of RAA" . to_owned ( ) ) ) ) ;
2352
2349
}
2353
2350
2354
- let ( commitment_signed, closing_signed ) = if need_commitment && ( self . channel_state & ( ChannelState :: AwaitingRemoteRevoke as u32 ) ) == 0 {
2351
+ let commitment_signed = if need_commitment && ( self . channel_state & ( ChannelState :: AwaitingRemoteRevoke as u32 ) ) == 0 {
2355
2352
// If we're AwaitingRemoteRevoke we can't send a new commitment here, but that's ok -
2356
2353
// we'll send one right away when we get the revoke_and_ack when we
2357
2354
// free_holding_cell_htlcs().
@@ -2360,10 +2357,8 @@ impl<Signer: Sign> Channel<Signer> {
2360
2357
// strictly increasing by one, so decrement it here.
2361
2358
self . latest_monitor_update_id = monitor_update. update_id ;
2362
2359
monitor_update. updates . append ( & mut additional_update. updates ) ;
2363
- ( Some ( msg) , None )
2364
- } else if !need_commitment {
2365
- ( None , self . maybe_propose_first_closing_signed ( fee_estimator) )
2366
- } else { ( None , None ) } ;
2360
+ Some ( msg)
2361
+ } else { None } ;
2367
2362
2368
2363
log_debug ! ( logger, "Received valid commitment_signed from peer in channel {}, updating HTLC state and responding with{} a revoke_and_ack." ,
2369
2364
log_bytes!( self . channel_id( ) ) , if commitment_signed. is_some( ) { " our own commitment_signed and" } else { "" } ) ;
@@ -2372,7 +2367,7 @@ impl<Signer: Sign> Channel<Signer> {
2372
2367
channel_id : self . channel_id ,
2373
2368
per_commitment_secret,
2374
2369
next_per_commitment_point,
2375
- } , commitment_signed, closing_signed , monitor_update) )
2370
+ } , commitment_signed, monitor_update) )
2376
2371
}
2377
2372
2378
2373
/// Public version of the below, checking relevant preconditions first.
@@ -2504,9 +2499,8 @@ impl<Signer: Sign> Channel<Signer> {
2504
2499
/// waiting on this revoke_and_ack. The generation of this new commitment_signed may also fail,
2505
2500
/// generating an appropriate error *after* the channel state has been updated based on the
2506
2501
/// revoke_and_ack message.
2507
- pub fn revoke_and_ack < F : Deref , L : Deref > ( & mut self , msg : & msgs:: RevokeAndACK , fee_estimator : & F , logger : & L ) -> Result < ( Option < msgs:: CommitmentUpdate > , Vec < ( PendingHTLCInfo , u64 ) > , Vec < ( HTLCSource , PaymentHash , HTLCFailReason ) > , Option < msgs:: ClosingSigned > , ChannelMonitorUpdate , Vec < ( HTLCSource , PaymentHash ) > ) , ChannelError >
2508
- where F :: Target : FeeEstimator ,
2509
- L :: Target : Logger ,
2502
+ pub fn revoke_and_ack < L : Deref > ( & mut self , msg : & msgs:: RevokeAndACK , logger : & L ) -> Result < ( Option < msgs:: CommitmentUpdate > , Vec < ( PendingHTLCInfo , u64 ) > , Vec < ( HTLCSource , PaymentHash , HTLCFailReason ) > , ChannelMonitorUpdate , Vec < ( HTLCSource , PaymentHash ) > ) , ChannelError >
2503
+ where L :: Target : Logger ,
2510
2504
{
2511
2505
if ( self . channel_state & ( ChannelState :: ChannelFunded as u32 ) ) != ( ChannelState :: ChannelFunded as u32 ) {
2512
2506
return Err ( ChannelError :: Close ( "Got revoke/ACK message when channel was not in an operational state" . to_owned ( ) ) ) ;
@@ -2686,7 +2680,7 @@ impl<Signer: Sign> Channel<Signer> {
2686
2680
self . monitor_pending_forwards . append ( & mut to_forward_infos) ;
2687
2681
self . monitor_pending_failures . append ( & mut revoked_htlcs) ;
2688
2682
log_debug ! ( logger, "Received a valid revoke_and_ack for channel {} but awaiting a monitor update resolution to reply." , log_bytes!( self . channel_id( ) ) ) ;
2689
- return Ok ( ( None , Vec :: new ( ) , Vec :: new ( ) , None , monitor_update, Vec :: new ( ) ) )
2683
+ return Ok ( ( None , Vec :: new ( ) , Vec :: new ( ) , monitor_update, Vec :: new ( ) ) )
2690
2684
}
2691
2685
2692
2686
match self . free_holding_cell_htlcs ( logger) ? {
@@ -2705,7 +2699,7 @@ impl<Signer: Sign> Channel<Signer> {
2705
2699
self . latest_monitor_update_id = monitor_update. update_id ;
2706
2700
monitor_update. updates . append ( & mut additional_update. updates ) ;
2707
2701
2708
- Ok ( ( Some ( commitment_update) , to_forward_infos, revoked_htlcs, None , monitor_update, htlcs_to_fail) )
2702
+ Ok ( ( Some ( commitment_update) , to_forward_infos, revoked_htlcs, monitor_update, htlcs_to_fail) )
2709
2703
} ,
2710
2704
( None , htlcs_to_fail) => {
2711
2705
if require_commitment {
@@ -2725,14 +2719,13 @@ impl<Signer: Sign> Channel<Signer> {
2725
2719
update_fail_malformed_htlcs,
2726
2720
update_fee : None ,
2727
2721
commitment_signed
2728
- } ) , to_forward_infos, revoked_htlcs, None , monitor_update, htlcs_to_fail) )
2722
+ } ) , to_forward_infos, revoked_htlcs, monitor_update, htlcs_to_fail) )
2729
2723
} else {
2730
2724
log_debug ! ( logger, "Received a valid revoke_and_ack for channel {} with no reply necessary." , log_bytes!( self . channel_id( ) ) ) ;
2731
- Ok ( ( None , to_forward_infos, revoked_htlcs, self . maybe_propose_first_closing_signed ( fee_estimator ) , monitor_update, htlcs_to_fail) )
2725
+ Ok ( ( None , to_forward_infos, revoked_htlcs, monitor_update, htlcs_to_fail) )
2732
2726
}
2733
2727
}
2734
2728
}
2735
-
2736
2729
}
2737
2730
2738
2731
/// Adds a pending update to this channel. See the doc for send_htlc for
@@ -3119,13 +3112,17 @@ impl<Signer: Sign> Channel<Signer> {
3119
3112
}
3120
3113
}
3121
3114
3122
- fn maybe_propose_first_closing_signed < F : Deref > ( & mut self , fee_estimator : & F ) -> Option < msgs:: ClosingSigned >
3123
- where F :: Target : FeeEstimator
3115
+ pub fn maybe_propose_first_closing_signed < F : Deref , L : Deref > ( & mut self , fee_estimator : & F , logger : & L )
3116
+ -> Result < Option < msgs:: ClosingSigned > , ChannelError >
3117
+ where F :: Target : FeeEstimator , L :: Target : Logger
3124
3118
{
3125
3119
if !self . is_outbound ( ) || !self . pending_inbound_htlcs . is_empty ( ) || !self . pending_outbound_htlcs . is_empty ( ) ||
3126
- self . channel_state & ( BOTH_SIDES_SHUTDOWN_MASK | ChannelState :: AwaitingRemoteRevoke as u32 ) != BOTH_SIDES_SHUTDOWN_MASK ||
3120
+ self . channel_state &
3121
+ ( BOTH_SIDES_SHUTDOWN_MASK | ChannelState :: AwaitingRemoteRevoke as u32 |
3122
+ ChannelState :: PeerDisconnected as u32 | ChannelState :: MonitorUpdateFailed as u32 )
3123
+ != BOTH_SIDES_SHUTDOWN_MASK ||
3127
3124
self . last_sent_closing_fee . is_some ( ) || self . pending_update_fee . is_some ( ) {
3128
- return None ;
3125
+ return Ok ( None ) ;
3129
3126
}
3130
3127
3131
3128
let mut proposed_feerate = fee_estimator. get_est_sat_per_1000_weight ( ConfirmationTarget :: Background ) ;
@@ -3134,26 +3131,24 @@ impl<Signer: Sign> Channel<Signer> {
3134
3131
}
3135
3132
let tx_weight = self . get_closing_transaction_weight ( Some ( & self . get_closing_scriptpubkey ( ) ) , Some ( self . counterparty_shutdown_scriptpubkey . as_ref ( ) . unwrap ( ) ) ) ;
3136
3133
let proposed_total_fee_satoshis = proposed_feerate as u64 * tx_weight / 1000 ;
3134
+ log_trace ! ( logger, "Proposing initial closing signed for our counterparty with a feerate of {} sat/kWeight (= {} sats)" ,
3135
+ proposed_feerate, proposed_total_fee_satoshis) ;
3137
3136
3138
3137
let ( closing_tx, total_fee_satoshis) = self . build_closing_transaction ( proposed_total_fee_satoshis, false ) ;
3139
3138
let sig = self . holder_signer
3140
3139
. sign_closing_transaction ( & closing_tx, & self . secp_ctx )
3141
- . ok ( ) ;
3142
- assert ! ( closing_tx. get_weight( ) as u64 <= tx_weight) ;
3143
- if sig. is_none ( ) { return None ; }
3140
+ . map_err ( |( ) | ChannelError :: Close ( "Failed to get signature for closing transaction." . to_owned ( ) ) ) ?;
3144
3141
3145
- self . last_sent_closing_fee = Some ( ( proposed_feerate, total_fee_satoshis, sig. clone ( ) . unwrap ( ) ) ) ;
3146
- Some ( msgs:: ClosingSigned {
3142
+ self . last_sent_closing_fee = Some ( ( proposed_feerate, total_fee_satoshis, sig. clone ( ) ) ) ;
3143
+ Ok ( Some ( msgs:: ClosingSigned {
3147
3144
channel_id : self . channel_id ,
3148
3145
fee_satoshis : total_fee_satoshis,
3149
- signature : sig. unwrap ( ) ,
3146
+ signature : sig,
3150
3147
fee_range : None ,
3151
- } )
3148
+ } ) )
3152
3149
}
3153
3150
3154
- pub fn shutdown < F : Deref > ( & mut self , fee_estimator : & F , their_features : & InitFeatures , msg : & msgs:: Shutdown ) -> Result < ( Option < msgs:: Shutdown > , Option < msgs:: ClosingSigned > , Vec < ( HTLCSource , PaymentHash ) > ) , ChannelError >
3155
- where F :: Target : FeeEstimator
3156
- {
3151
+ pub fn shutdown ( & mut self , their_features : & InitFeatures , msg : & msgs:: Shutdown ) -> Result < ( Option < msgs:: Shutdown > , Vec < ( HTLCSource , PaymentHash ) > ) , ChannelError > {
3157
3152
if self . channel_state & ( ChannelState :: PeerDisconnected as u32 ) == ChannelState :: PeerDisconnected as u32 {
3158
3153
return Err ( ChannelError :: Close ( "Peer sent shutdown when we needed a channel_reestablish" . to_owned ( ) ) ) ;
3159
3154
}
@@ -3217,7 +3212,7 @@ impl<Signer: Sign> Channel<Signer> {
3217
3212
self . channel_state |= ChannelState :: LocalShutdownSent as u32 ;
3218
3213
self . update_time_counter += 1 ;
3219
3214
3220
- Ok ( ( shutdown, self . maybe_propose_first_closing_signed ( fee_estimator ) , dropped_outbound_htlcs) )
3215
+ Ok ( ( shutdown, dropped_outbound_htlcs) )
3221
3216
}
3222
3217
3223
3218
fn build_signed_closing_transaction ( & self , tx : & mut Transaction , counterparty_sig : & Signature , sig : & Signature ) {
0 commit comments