@@ -1855,7 +1855,7 @@ macro_rules! handle_monitor_update_completion {
1855
1855
}
1856
1856
1857
1857
macro_rules! handle_new_monitor_update {
1858
- ( $self: ident, $update_res: expr, $update_id: expr, $peer_state_lock: expr, $peer_state: expr, $per_peer_state_lock: expr, $chan: expr, MANUALLY_REMOVING , $remove: expr) => { {
1858
+ ( $self: ident, $update_res: expr, $update_id: expr, $peer_state_lock: expr, $peer_state: expr, $per_peer_state_lock: expr, $chan: expr, MANUALLY_REMOVING_ALREADY_APPLIED , $remove: expr) => { {
1859
1859
// update_maps_on_chan_removal needs to be able to take id_to_peer, so make sure we can in
1860
1860
// any case so that it won't deadlock.
1861
1861
debug_assert_ne!( $self. id_to_peer. held_by_thread( ) , LockHeldState :: HeldByThread ) ;
@@ -1888,8 +1888,15 @@ macro_rules! handle_new_monitor_update {
1888
1888
} ,
1889
1889
}
1890
1890
} } ;
1891
- ( $self: ident, $update_res: expr, $update_id: expr, $peer_state_lock: expr, $peer_state: expr, $per_peer_state_lock: expr, $chan_entry: expr) => {
1892
- handle_new_monitor_update!( $self, $update_res, $update_id, $peer_state_lock, $peer_state, $per_peer_state_lock, $chan_entry. get_mut( ) , MANUALLY_REMOVING , $chan_entry. remove_entry( ) )
1891
+ ( $self: ident, $update_res: expr, $update_id: expr, $peer_state_lock: expr, $peer_state: expr, $per_peer_state_lock: expr, $chan_entry: expr, ALREADY_APPLIED ) => {
1892
+ handle_new_monitor_update!( $self, $update_res, $update_id, $peer_state_lock, $peer_state, $per_peer_state_lock, $chan_entry. get_mut( ) , MANUALLY_REMOVING_ALREADY_APPLIED , $chan_entry. remove_entry( ) )
1893
+ } ;
1894
+ ( $self: ident, $funding_txo: expr, $update: expr, $peer_state_lock: expr, $peer_state: expr, $per_peer_state_lock: expr, $chan: expr, MANUALLY_REMOVING , $remove: expr) => { {
1895
+ let update_res = $self. chain_monitor. update_channel( $funding_txo, & $update) ;
1896
+ handle_new_monitor_update!( $self, update_res, $update. update_id, $peer_state_lock, $peer_state, $per_peer_state_lock, $chan, MANUALLY_REMOVING_ALREADY_APPLIED , $remove)
1897
+ } } ;
1898
+ ( $self: ident, $funding_txo: expr, $update: expr, $peer_state_lock: expr, $peer_state: expr, $per_peer_state_lock: expr, $chan_entry: expr) => {
1899
+ handle_new_monitor_update!( $self, $funding_txo, $update, $peer_state_lock, $peer_state, $per_peer_state_lock, $chan_entry. get_mut( ) , MANUALLY_REMOVING , $chan_entry. remove_entry( ) )
1893
1900
}
1894
1901
}
1895
1902
@@ -2304,9 +2311,7 @@ where
2304
2311
2305
2312
// Update the monitor with the shutdown script if necessary.
2306
2313
if let Some ( monitor_update) = monitor_update_opt. take ( ) {
2307
- let update_id = monitor_update. update_id ;
2308
- let update_res = self . chain_monitor . update_channel ( funding_txo_opt. unwrap ( ) , & monitor_update) ;
2309
- break handle_new_monitor_update ! ( self , update_res, update_id, peer_state_lock, peer_state, per_peer_state, chan_entry) ;
2314
+ break handle_new_monitor_update ! ( self , funding_txo_opt. unwrap( ) , monitor_update, peer_state_lock, peer_state, per_peer_state, chan_entry) ;
2310
2315
}
2311
2316
2312
2317
if chan_entry. get ( ) . is_shutdown ( ) {
@@ -2989,7 +2994,7 @@ where
2989
2994
Some ( monitor_update) => {
2990
2995
let update_id = monitor_update. update_id ;
2991
2996
let update_res = self . chain_monitor . update_channel ( funding_txo, & monitor_update) ;
2992
- if let Err ( e) = handle_new_monitor_update ! ( self , update_res, update_id, peer_state_lock, peer_state, per_peer_state, chan) {
2997
+ if let Err ( e) = handle_new_monitor_update ! ( self , update_res, update_id, peer_state_lock, peer_state, per_peer_state, chan, ALREADY_APPLIED ) {
2993
2998
break Err ( e) ;
2994
2999
}
2995
3000
if update_res == ChannelMonitorUpdateStatus :: InProgress {
@@ -4027,7 +4032,7 @@ where
4027
4032
let peer_state = & mut * peer_state_lock;
4028
4033
match peer_state. channel_by_id . entry ( funding_txo. to_channel_id ( ) ) {
4029
4034
hash_map:: Entry :: Occupied ( mut chan) => {
4030
- handle_new_monitor_update ! ( self , update_res, update. update_id, peer_state_lock, peer_state, per_peer_state, chan)
4035
+ handle_new_monitor_update ! ( self , update_res, update. update_id, peer_state_lock, peer_state, per_peer_state, chan, ALREADY_APPLIED )
4031
4036
} ,
4032
4037
hash_map:: Entry :: Vacant ( _) => Ok ( ( ) ) ,
4033
4038
}
@@ -4613,9 +4618,7 @@ where
4613
4618
log_bytes!( chan_id) , action) ;
4614
4619
peer_state. monitor_update_blocked_actions . entry ( chan_id) . or_insert ( Vec :: new ( ) ) . push ( action) ;
4615
4620
}
4616
- let update_id = monitor_update. update_id ;
4617
- let update_res = self . chain_monitor . update_channel ( prev_hop. outpoint , & monitor_update) ;
4618
- let res = handle_new_monitor_update ! ( self , update_res, update_id, peer_state_lock,
4621
+ let res = handle_new_monitor_update ! ( self , prev_hop. outpoint, monitor_update, peer_state_lock,
4619
4622
peer_state, per_peer_state, chan) ;
4620
4623
if let Err ( e) = res {
4621
4624
// TODO: This is a *critical* error - we probably updated the outbound edge
@@ -5152,7 +5155,8 @@ where
5152
5155
5153
5156
let chan = e. insert ( chan) ;
5154
5157
let mut res = handle_new_monitor_update ! ( self , monitor_res, 0 , peer_state_lock, peer_state,
5155
- per_peer_state, chan, MANUALLY_REMOVING , { peer_state. channel_by_id. remove( & new_channel_id) } ) ;
5158
+ per_peer_state, chan, MANUALLY_REMOVING_ALREADY_APPLIED ,
5159
+ { peer_state. channel_by_id. remove( & new_channel_id) } ) ;
5156
5160
5157
5161
// Note that we reply with the new channel_id in error messages if we gave up on the
5158
5162
// channel, not the temporary_channel_id. This is compatible with ourselves, but the
@@ -5185,7 +5189,7 @@ where
5185
5189
let monitor = try_chan_entry ! ( self ,
5186
5190
chan. get_mut( ) . funding_signed( & msg, best_block, & self . signer_provider, & self . logger) , chan) ;
5187
5191
let update_res = self . chain_monitor . watch_channel ( chan. get ( ) . context . get_funding_txo ( ) . unwrap ( ) , monitor) ;
5188
- let mut res = handle_new_monitor_update ! ( self , update_res, 0 , peer_state_lock, peer_state, per_peer_state, chan) ;
5192
+ let mut res = handle_new_monitor_update ! ( self , update_res, 0 , peer_state_lock, peer_state, per_peer_state, chan, ALREADY_APPLIED ) ;
5189
5193
if let Err ( MsgHandleErrInternal { ref mut shutdown_finish, .. } ) = res {
5190
5194
// We weren't able to watch the channel to begin with, so no updates should be made on
5191
5195
// it. Previously, full_stack_target found an (unreachable) panic when the
@@ -5282,9 +5286,7 @@ where
5282
5286
5283
5287
// Update the monitor with the shutdown script if necessary.
5284
5288
if let Some ( monitor_update) = monitor_update_opt {
5285
- let update_id = monitor_update. update_id ;
5286
- let update_res = self . chain_monitor . update_channel ( funding_txo_opt. unwrap ( ) , & monitor_update) ;
5287
- break handle_new_monitor_update ! ( self , update_res, update_id, peer_state_lock, peer_state, per_peer_state, chan_entry) ;
5289
+ break handle_new_monitor_update ! ( self , funding_txo_opt. unwrap( ) , monitor_update, peer_state_lock, peer_state, per_peer_state, chan_entry) ;
5288
5290
}
5289
5291
break Ok ( ( ) ) ;
5290
5292
} ,
@@ -5474,9 +5476,7 @@ where
5474
5476
let funding_txo = chan. get ( ) . context . get_funding_txo ( ) ;
5475
5477
let monitor_update_opt = try_chan_entry ! ( self , chan. get_mut( ) . commitment_signed( & msg, & self . logger) , chan) ;
5476
5478
if let Some ( monitor_update) = monitor_update_opt {
5477
- let update_res = self . chain_monitor . update_channel ( funding_txo. unwrap ( ) , & monitor_update) ;
5478
- let update_id = monitor_update. update_id ;
5479
- handle_new_monitor_update ! ( self , update_res, update_id, peer_state_lock,
5479
+ handle_new_monitor_update ! ( self , funding_txo. unwrap( ) , monitor_update, peer_state_lock,
5480
5480
peer_state, per_peer_state, chan)
5481
5481
} else { Ok ( ( ) ) }
5482
5482
} ,
@@ -5613,9 +5613,7 @@ where
5613
5613
let funding_txo = chan. get ( ) . context . get_funding_txo ( ) ;
5614
5614
let ( htlcs_to_fail, monitor_update_opt) = try_chan_entry ! ( self , chan. get_mut( ) . revoke_and_ack( & msg, & self . logger) , chan) ;
5615
5615
let res = if let Some ( monitor_update) = monitor_update_opt {
5616
- let update_res = self . chain_monitor . update_channel ( funding_txo. unwrap ( ) , & monitor_update) ;
5617
- let update_id = monitor_update. update_id ;
5618
- handle_new_monitor_update ! ( self , update_res, update_id,
5616
+ handle_new_monitor_update ! ( self , funding_txo. unwrap( ) , monitor_update,
5619
5617
peer_state_lock, peer_state, per_peer_state, chan)
5620
5618
} else { Ok ( ( ) ) } ;
5621
5619
( htlcs_to_fail, res)
@@ -5891,11 +5889,8 @@ where
5891
5889
if let Some ( monitor_update) = monitor_opt {
5892
5890
has_monitor_update = true ;
5893
5891
5894
- let update_res = self . chain_monitor . update_channel (
5895
- funding_txo. expect ( "channel is live" ) , & monitor_update) ;
5896
- let update_id = monitor_update. update_id ;
5897
5892
let channel_id: [ u8 ; 32 ] = * channel_id;
5898
- let res = handle_new_monitor_update ! ( self , update_res , update_id ,
5893
+ let res = handle_new_monitor_update ! ( self , funding_txo . unwrap ( ) , monitor_update ,
5899
5894
peer_state_lock, peer_state, per_peer_state, chan, MANUALLY_REMOVING ,
5900
5895
peer_state. channel_by_id. remove( & channel_id) ) ;
5901
5896
if res. is_err ( ) {
@@ -6237,9 +6232,7 @@ where
6237
6232
if let Some ( ( monitor_update, further_update_exists) ) = chan. get_mut ( ) . unblock_next_blocked_monitor_update ( ) {
6238
6233
log_debug ! ( self . logger, "Unlocking monitor updating for channel {} and updating monitor" ,
6239
6234
log_bytes!( & channel_funding_outpoint. to_channel_id( ) [ ..] ) ) ;
6240
- let update_res = self . chain_monitor . update_channel ( channel_funding_outpoint, & monitor_update) ;
6241
- let update_id = monitor_update. update_id ;
6242
- if let Err ( e) = handle_new_monitor_update ! ( self , update_res, update_id,
6235
+ if let Err ( e) = handle_new_monitor_update ! ( self , channel_funding_outpoint, monitor_update,
6243
6236
peer_state_lck, peer_state, per_peer_state, chan)
6244
6237
{
6245
6238
errors. push ( ( e, counterparty_node_id) ) ;
0 commit comments