@@ -1526,7 +1526,7 @@ macro_rules! remove_channel {
1526
1526
}
1527
1527
1528
1528
macro_rules! handle_monitor_err {
1529
- ( $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) => {
1529
+ ( $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) => {
1530
1530
match $err {
1531
1531
ChannelMonitorUpdateErr :: PermanentFailure => {
1532
1532
log_error!( $self. logger, "Closing channel {} due to monitor update ChannelMonitorUpdateErr::PermanentFailure" , log_bytes!( $chan_id[ ..] ) ) ;
@@ -1564,30 +1564,33 @@ macro_rules! handle_monitor_err {
1564
1564
if !$resend_raa {
1565
1565
debug_assert!( $action_type == RAACommitmentOrder :: CommitmentFirst || !$resend_commitment) ;
1566
1566
}
1567
- $chan. monitor_update_failed( $resend_raa, $resend_commitment, $failed_forwards, $failed_fails, $failed_finalized_fulfills) ;
1567
+ $chan. monitor_update_failed( $resend_raa, $resend_commitment, $resend_funding_locked , $ failed_forwards, $failed_fails, $failed_finalized_fulfills) ;
1568
1568
( Err ( MsgHandleErrInternal :: from_chan_no_close( ChannelError :: Ignore ( "Failed to update ChannelMonitor" . to_owned( ) ) , * $chan_id) ) , false )
1569
1569
} ,
1570
1570
}
1571
1571
} ;
1572
- ( $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) => { {
1573
- 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( ) ) ;
1572
+ ( $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) => { {
1573
+ 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( ) ) ;
1574
1574
if drop {
1575
1575
$entry. remove_entry( ) ;
1576
1576
}
1577
1577
res
1578
1578
} } ;
1579
1579
( $self: ident, $err: expr, $channel_state: expr, $entry: expr, $action_type: path, $chan_id: expr, COMMITMENT_UPDATE_ONLY ) => { {
1580
1580
debug_assert!( $action_type == RAACommitmentOrder :: CommitmentFirst ) ;
1581
- handle_monitor_err!( $self, $err, $channel_state, $entry, $action_type, false , true , Vec :: new( ) , Vec :: new( ) , Vec :: new( ) , $chan_id)
1581
+ handle_monitor_err!( $self, $err, $channel_state, $entry, $action_type, false , true , false , Vec :: new( ) , Vec :: new( ) , Vec :: new( ) , $chan_id)
1582
1582
} } ;
1583
1583
( $self: ident, $err: expr, $channel_state: expr, $entry: expr, $action_type: path, $chan_id: expr, NO_UPDATE ) => {
1584
- handle_monitor_err!( $self, $err, $channel_state, $entry, $action_type, false , false , Vec :: new( ) , Vec :: new( ) , Vec :: new( ) , $chan_id)
1584
+ handle_monitor_err!( $self, $err, $channel_state, $entry, $action_type, false , false , false , Vec :: new( ) , Vec :: new( ) , Vec :: new( ) , $chan_id)
1585
+ } ;
1586
+ ( $self: ident, $err: expr, $channel_state: expr, $entry: expr, $action_type: path, $resend_funding_locked: expr, OPTIONALLY_RESEND_FUNDING_LOCKED ) => {
1587
+ handle_monitor_err!( $self, $err, $channel_state, $entry, $action_type, false , false , $resend_funding_locked, Vec :: new( ) , Vec :: new( ) , Vec :: new( ) )
1585
1588
} ;
1586
1589
( $self: ident, $err: expr, $channel_state: expr, $entry: expr, $action_type: path, $resend_raa: expr, $resend_commitment: expr) => {
1587
- handle_monitor_err!( $self, $err, $channel_state, $entry, $action_type, $resend_raa, $resend_commitment, Vec :: new( ) , Vec :: new( ) , Vec :: new( ) )
1590
+ handle_monitor_err!( $self, $err, $channel_state, $entry, $action_type, $resend_raa, $resend_commitment, false , Vec :: new( ) , Vec :: new( ) , Vec :: new( ) )
1588
1591
} ;
1589
1592
( $self: ident, $err: expr, $channel_state: expr, $entry: expr, $action_type: path, $resend_raa: expr, $resend_commitment: expr, $failed_forwards: expr, $failed_fails: expr) => {
1590
- handle_monitor_err!( $self, $err, $channel_state, $entry, $action_type, $resend_raa, $resend_commitment, $failed_forwards, $failed_fails, Vec :: new( ) )
1593
+ handle_monitor_err!( $self, $err, $channel_state, $entry, $action_type, $resend_raa, $resend_commitment, false , $failed_forwards, $failed_fails, Vec :: new( ) )
1591
1594
} ;
1592
1595
}
1593
1596
@@ -4495,7 +4498,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
4495
4498
// hasn't persisted to disk yet - we can't lose money on a transaction that we haven't
4496
4499
// accepted payment from yet. We do, however, need to wait to send our funding_locked
4497
4500
// until we have persisted our monitor.
4498
- chan. monitor_update_failed ( false , false , Vec :: new ( ) , Vec :: new ( ) , Vec :: new ( ) ) ;
4501
+ chan. monitor_update_failed ( false , false , false , Vec :: new ( ) , Vec :: new ( ) , Vec :: new ( ) ) ;
4499
4502
} ,
4500
4503
}
4501
4504
}
@@ -4526,12 +4529,12 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
4526
4529
if chan. get ( ) . get_counterparty_node_id ( ) != * counterparty_node_id {
4527
4530
return Err ( MsgHandleErrInternal :: send_err_msg_no_close ( "Got a message for a channel from the wrong node!" . to_owned ( ) , msg. channel_id ) ) ;
4528
4531
}
4529
- let ( monitor, funding_tx) = match chan. get_mut ( ) . funding_signed ( & msg, best_block, & self . logger ) {
4532
+ let ( monitor, funding_tx, funding_locked ) = match chan. get_mut ( ) . funding_signed ( & msg, best_block, & self . logger ) {
4530
4533
Ok ( update) => update,
4531
4534
Err ( e) => try_chan_entry ! ( self , Err ( e) , channel_state, chan) ,
4532
4535
} ;
4533
4536
if let Err ( e) = self . chain_monitor . watch_channel ( chan. get ( ) . get_funding_txo ( ) . unwrap ( ) , monitor) {
4534
- let mut res = handle_monitor_err ! ( self , e, channel_state, chan, RAACommitmentOrder :: RevokeAndACKFirst , false , false ) ;
4537
+ let mut res = handle_monitor_err ! ( self , e, channel_state, chan, RAACommitmentOrder :: RevokeAndACKFirst , funding_locked . is_some ( ) , OPTIONALLY_RESEND_FUNDING_LOCKED ) ;
4535
4538
if let Err ( MsgHandleErrInternal { ref mut shutdown_finish, .. } ) = res {
4536
4539
// We weren't able to watch the channel to begin with, so no updates should be made on
4537
4540
// it. Previously, full_stack_target found an (unreachable) panic when the
@@ -4542,6 +4545,9 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
4542
4545
}
4543
4546
return res
4544
4547
}
4548
+ if let Some ( msg) = funding_locked {
4549
+ send_funding_locked ! ( channel_state. short_to_id, channel_state. pending_msg_events, chan. get( ) , msg) ;
4550
+ }
4545
4551
funding_tx
4546
4552
} ,
4547
4553
hash_map:: Entry :: Vacant ( _) => return Err ( MsgHandleErrInternal :: send_err_msg_no_close ( "Failed to find corresponding channel" . to_owned ( ) , msg. channel_id ) )
@@ -4892,7 +4898,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
4892
4898
} else {
4893
4899
if let Err ( e) = handle_monitor_err ! ( self , e, channel_state, chan,
4894
4900
RAACommitmentOrder :: CommitmentFirst , false ,
4895
- raa_updates. commitment_update. is_some( ) ,
4901
+ raa_updates. commitment_update. is_some( ) , false ,
4896
4902
raa_updates. accepted_htlcs, raa_updates. failed_htlcs,
4897
4903
raa_updates. finalized_claimed_htlcs) {
4898
4904
break Err ( e) ;
@@ -5746,6 +5752,18 @@ where
5746
5752
}
5747
5753
}
5748
5754
}
5755
+ if channel. is_our_funding_locked ( ) {
5756
+ if let Some ( real_scid) = channel. get_short_channel_id ( ) {
5757
+ // If we sent a 0conf funding_locked, and now have an SCID, we add it
5758
+ // to the short_to_id map here. Note that we check whether we can relay
5759
+ // using the real SCID at relay-time, and if the funding tx is ever
5760
+ // un-confirmed we force-close the channel, ensuring short_to_id is
5761
+ // always consistent.
5762
+ let scid_insert = short_to_id. insert ( real_scid, channel. channel_id ( ) ) ;
5763
+ assert ! ( scid_insert. is_none( ) || scid_insert. unwrap( ) == channel. channel_id( ) ,
5764
+ "SCIDs should never collide - ensure you weren't behind by a full XXX days when creating channels" ) ;
5765
+ }
5766
+ }
5749
5767
} else if let Err ( reason) = res {
5750
5768
update_maps_on_chan_removal ! ( self , short_to_id, channel) ;
5751
5769
// It looks like our counterparty went on-chain or funding transaction was
0 commit comments