@@ -1286,7 +1286,7 @@ macro_rules! remove_channel {
1286
1286
}
1287
1287
1288
1288
macro_rules! handle_monitor_err {
1289
- ( $self: ident, $err: expr, $short_to_id: expr, $chan: expr, $action_type: path, $resend_raa: expr, $resend_commitment: expr, $failed_forwards: expr, $failed_fails: expr, $failed_finalized_fulfills: expr, $chan_id: expr) => {
1289
+ ( $self: ident, $err: expr, $short_to_id: expr, $chan: expr, $action_type: path, $resend_raa: expr, $resend_commitment: expr, $resend_funding_locked : expr , $ failed_forwards: expr, $failed_fails: expr, $failed_finalized_fulfills: expr, $chan_id: expr) => {
1290
1290
match $err {
1291
1291
ChannelMonitorUpdateErr :: PermanentFailure => {
1292
1292
log_error!( $self. logger, "Closing channel {} due to monitor update ChannelMonitorUpdateErr::PermanentFailure" , log_bytes!( $chan_id[ ..] ) ) ;
@@ -1324,30 +1324,33 @@ macro_rules! handle_monitor_err {
1324
1324
if !$resend_raa {
1325
1325
debug_assert!( $action_type == RAACommitmentOrder :: CommitmentFirst || !$resend_commitment) ;
1326
1326
}
1327
- $chan. monitor_update_failed( $resend_raa, $resend_commitment, $failed_forwards, $failed_fails, $failed_finalized_fulfills) ;
1327
+ $chan. monitor_update_failed( $resend_raa, $resend_commitment, $resend_funding_locked , $ failed_forwards, $failed_fails, $failed_finalized_fulfills) ;
1328
1328
( Err ( MsgHandleErrInternal :: from_chan_no_close( ChannelError :: Ignore ( "Failed to update ChannelMonitor" . to_owned( ) ) , * $chan_id) ) , false )
1329
1329
} ,
1330
1330
}
1331
1331
} ;
1332
- ( $self: ident, $err: expr, $channel_state: expr, $entry: expr, $action_type: path, $resend_raa: expr, $resend_commitment: expr, $failed_forwards: expr, $failed_fails: expr, $failed_finalized_fulfills: expr) => { {
1333
- let ( res, drop) = handle_monitor_err!( $self, $err, $channel_state. short_to_id, $entry. get_mut( ) , $action_type, $resend_raa, $resend_commitment, $failed_forwards, $failed_fails, $failed_finalized_fulfills, $entry. key( ) ) ;
1332
+ ( $self: ident, $err: expr, $channel_state: expr, $entry: expr, $action_type: path, $resend_raa: expr, $resend_commitment: expr, $resend_funding_locked : expr , $ failed_forwards: expr, $failed_fails: expr, $failed_finalized_fulfills: expr) => { {
1333
+ let ( res, drop) = handle_monitor_err!( $self, $err, $channel_state. short_to_id, $entry. get_mut( ) , $action_type, $resend_raa, $resend_commitment, $resend_funding_locked , $ failed_forwards, $failed_fails, $failed_finalized_fulfills, $entry. key( ) ) ;
1334
1334
if drop {
1335
1335
$entry. remove_entry( ) ;
1336
1336
}
1337
1337
res
1338
1338
} } ;
1339
1339
( $self: ident, $err: expr, $channel_state: expr, $entry: expr, $action_type: path, $chan_id: expr, COMMITMENT_UPDATE_ONLY ) => { {
1340
1340
debug_assert!( $action_type == RAACommitmentOrder :: CommitmentFirst ) ;
1341
- handle_monitor_err!( $self, $err, $channel_state, $entry, $action_type, false , true , Vec :: new( ) , Vec :: new( ) , Vec :: new( ) , $chan_id)
1341
+ handle_monitor_err!( $self, $err, $channel_state, $entry, $action_type, false , true , false , Vec :: new( ) , Vec :: new( ) , Vec :: new( ) , $chan_id)
1342
1342
} } ;
1343
1343
( $self: ident, $err: expr, $channel_state: expr, $entry: expr, $action_type: path, $chan_id: expr, NO_UPDATE ) => {
1344
- handle_monitor_err!( $self, $err, $channel_state, $entry, $action_type, false , false , Vec :: new( ) , Vec :: new( ) , Vec :: new( ) , $chan_id)
1344
+ handle_monitor_err!( $self, $err, $channel_state, $entry, $action_type, false , false , false , Vec :: new( ) , Vec :: new( ) , Vec :: new( ) , $chan_id)
1345
+ } ;
1346
+ ( $self: ident, $err: expr, $channel_state: expr, $entry: expr, $action_type: path, $resend_funding_locked: expr, OPTIONALLY_RESEND_FUNDING_LOCKED ) => {
1347
+ handle_monitor_err!( $self, $err, $channel_state, $entry, $action_type, false , false , $resend_funding_locked, Vec :: new( ) , Vec :: new( ) , Vec :: new( ) )
1345
1348
} ;
1346
1349
( $self: ident, $err: expr, $channel_state: expr, $entry: expr, $action_type: path, $resend_raa: expr, $resend_commitment: expr) => {
1347
- handle_monitor_err!( $self, $err, $channel_state, $entry, $action_type, $resend_raa, $resend_commitment, Vec :: new( ) , Vec :: new( ) , Vec :: new( ) )
1350
+ handle_monitor_err!( $self, $err, $channel_state, $entry, $action_type, $resend_raa, $resend_commitment, false , Vec :: new( ) , Vec :: new( ) , Vec :: new( ) )
1348
1351
} ;
1349
1352
( $self: ident, $err: expr, $channel_state: expr, $entry: expr, $action_type: path, $resend_raa: expr, $resend_commitment: expr, $failed_forwards: expr, $failed_fails: expr) => {
1350
- handle_monitor_err!( $self, $err, $channel_state, $entry, $action_type, $resend_raa, $resend_commitment, $failed_forwards, $failed_fails, Vec :: new( ) )
1353
+ handle_monitor_err!( $self, $err, $channel_state, $entry, $action_type, $resend_raa, $resend_commitment, false , $failed_forwards, $failed_fails, Vec :: new( ) )
1351
1354
} ;
1352
1355
}
1353
1356
@@ -4268,7 +4271,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
4268
4271
// hasn't persisted to disk yet - we can't lose money on a transaction that we haven't
4269
4272
// accepted payment from yet. We do, however, need to wait to send our funding_locked
4270
4273
// until we have persisted our monitor.
4271
- chan. monitor_update_failed ( false , false , Vec :: new ( ) , Vec :: new ( ) , Vec :: new ( ) ) ;
4274
+ chan. monitor_update_failed ( false , false , false , Vec :: new ( ) , Vec :: new ( ) , Vec :: new ( ) ) ;
4272
4275
} ,
4273
4276
}
4274
4277
}
@@ -4299,12 +4302,12 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
4299
4302
if chan. get ( ) . get_counterparty_node_id ( ) != * counterparty_node_id {
4300
4303
return Err ( MsgHandleErrInternal :: send_err_msg_no_close ( "Got a message for a channel from the wrong node!" . to_owned ( ) , msg. channel_id ) ) ;
4301
4304
}
4302
- let ( monitor, funding_tx) = match chan. get_mut ( ) . funding_signed ( & msg, best_block, & self . logger ) {
4305
+ let ( monitor, funding_tx, funding_locked ) = match chan. get_mut ( ) . funding_signed ( & msg, best_block, & self . logger ) {
4303
4306
Ok ( update) => update,
4304
4307
Err ( e) => try_chan_entry ! ( self , Err ( e) , channel_state, chan) ,
4305
4308
} ;
4306
4309
if let Err ( e) = self . chain_monitor . watch_channel ( chan. get ( ) . get_funding_txo ( ) . unwrap ( ) , monitor) {
4307
- let mut res = handle_monitor_err ! ( self , e, channel_state, chan, RAACommitmentOrder :: RevokeAndACKFirst , false , false ) ;
4310
+ let mut res = handle_monitor_err ! ( self , e, channel_state, chan, RAACommitmentOrder :: RevokeAndACKFirst , funding_locked . is_some ( ) , OPTIONALLY_RESEND_FUNDING_LOCKED ) ;
4308
4311
if let Err ( MsgHandleErrInternal { ref mut shutdown_finish, .. } ) = res {
4309
4312
// We weren't able to watch the channel to begin with, so no updates should be made on
4310
4313
// it. Previously, full_stack_target found an (unreachable) panic when the
@@ -4315,6 +4318,9 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
4315
4318
}
4316
4319
return res
4317
4320
}
4321
+ if let Some ( msg) = funding_locked {
4322
+ send_funding_locked ! ( channel_state. short_to_id, channel_state. pending_msg_events, chan. get( ) , msg) ;
4323
+ }
4318
4324
funding_tx
4319
4325
} ,
4320
4326
hash_map:: Entry :: Vacant ( _) => return Err ( MsgHandleErrInternal :: send_err_msg_no_close ( "Failed to find corresponding channel" . to_owned ( ) , msg. channel_id ) )
@@ -4665,7 +4671,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
4665
4671
} else {
4666
4672
if let Err ( e) = handle_monitor_err ! ( self , e, channel_state, chan,
4667
4673
RAACommitmentOrder :: CommitmentFirst , false ,
4668
- raa_updates. commitment_update. is_some( ) ,
4674
+ raa_updates. commitment_update. is_some( ) , false ,
4669
4675
raa_updates. accepted_htlcs, raa_updates. failed_htlcs,
4670
4676
raa_updates. finalized_claimed_htlcs) {
4671
4677
break Err ( e) ;
@@ -5520,6 +5526,19 @@ where
5520
5526
}
5521
5527
}
5522
5528
}
5529
+ if channel. is_our_funding_locked ( ) {
5530
+ if let Some ( real_scid) = channel. get_short_channel_id ( ) {
5531
+ // If we sent a 0conf funding_locked, and now have an SCID, we add it
5532
+ // to the short_to_id map here. Note that we check whether we can relay
5533
+ // using the real SCID at relay-time (i.e. enforce option_scid_alias
5534
+ // then), and if the funding tx is ever un-confirmed we force-close the
5535
+ // channel, ensuring short_to_id is always consistent.
5536
+ let scid_insert = short_to_id. insert ( real_scid, channel. channel_id ( ) ) ;
5537
+ assert ! ( scid_insert. is_none( ) || scid_insert. unwrap( ) == channel. channel_id( ) ,
5538
+ "SCIDs should never collide - ensure you weren't behind by a full {} blocks when creating channels" ,
5539
+ fake_scid:: MAX_SCID_BLOCKS_FROM_NOW ) ;
5540
+ }
5541
+ }
5523
5542
} else if let Err ( reason) = res {
5524
5543
update_maps_on_chan_removal ! ( self , short_to_id, channel) ;
5525
5544
// It looks like our counterparty went on-chain or funding transaction was
0 commit comments