@@ -1860,7 +1860,7 @@ macro_rules! handle_monitor_update_completion {
1860
1860
}
1861
1861
1862
1862
macro_rules! handle_new_monitor_update {
1863
- ( $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) => { {
1863
+ ( $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) => { {
1864
1864
// update_maps_on_chan_removal needs to be able to take id_to_peer, so make sure we can in
1865
1865
// any case so that it won't deadlock.
1866
1866
debug_assert_ne!( $self. id_to_peer. held_by_thread( ) , LockHeldState :: HeldByThread ) ;
@@ -1893,8 +1893,15 @@ macro_rules! handle_new_monitor_update {
1893
1893
} ,
1894
1894
}
1895
1895
} } ;
1896
- ( $self: ident, $update_res: expr, $update_id: expr, $peer_state_lock: expr, $peer_state: expr, $per_peer_state_lock: expr, $chan_entry: expr) => {
1897
- 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( ) )
1896
+ ( $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 ) => {
1897
+ 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( ) )
1898
+ } ;
1899
+ ( $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) => { {
1900
+ let update_res = $self. chain_monitor. update_channel( $funding_txo, & $update) ;
1901
+ 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)
1902
+ } } ;
1903
+ ( $self: ident, $funding_txo: expr, $update: expr, $peer_state_lock: expr, $peer_state: expr, $per_peer_state_lock: expr, $chan_entry: expr) => {
1904
+ 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( ) )
1898
1905
}
1899
1906
}
1900
1907
@@ -2309,9 +2316,7 @@ where
2309
2316
2310
2317
// Update the monitor with the shutdown script if necessary.
2311
2318
if let Some ( monitor_update) = monitor_update_opt. take ( ) {
2312
- let update_id = monitor_update. update_id ;
2313
- let update_res = self . chain_monitor . update_channel ( funding_txo_opt. unwrap ( ) , & monitor_update) ;
2314
- break handle_new_monitor_update ! ( self , update_res, update_id, peer_state_lock, peer_state, per_peer_state, chan_entry) ;
2319
+ break handle_new_monitor_update ! ( self , funding_txo_opt. unwrap( ) , monitor_update, peer_state_lock, peer_state, per_peer_state, chan_entry) ;
2315
2320
}
2316
2321
2317
2322
if chan_entry. get ( ) . is_shutdown ( ) {
@@ -3037,7 +3042,7 @@ where
3037
3042
Some ( monitor_update) => {
3038
3043
let update_id = monitor_update. update_id ;
3039
3044
let update_res = self . chain_monitor . update_channel ( funding_txo, & monitor_update) ;
3040
- if let Err ( e) = handle_new_monitor_update ! ( self , update_res, update_id, peer_state_lock, peer_state, per_peer_state, chan) {
3045
+ if let Err ( e) = handle_new_monitor_update ! ( self , update_res, update_id, peer_state_lock, peer_state, per_peer_state, chan, ALREADY_APPLIED ) {
3041
3046
break Err ( e) ;
3042
3047
}
3043
3048
if update_res == ChannelMonitorUpdateStatus :: InProgress {
@@ -4091,7 +4096,7 @@ where
4091
4096
let peer_state = & mut * peer_state_lock;
4092
4097
match peer_state. channel_by_id . entry ( funding_txo. to_channel_id ( ) ) {
4093
4098
hash_map:: Entry :: Occupied ( mut chan) => {
4094
- handle_new_monitor_update ! ( self , update_res, update. update_id, peer_state_lock, peer_state, per_peer_state, chan)
4099
+ handle_new_monitor_update ! ( self , update_res, update. update_id, peer_state_lock, peer_state, per_peer_state, chan, ALREADY_APPLIED )
4095
4100
} ,
4096
4101
hash_map:: Entry :: Vacant ( _) => Ok ( ( ) ) ,
4097
4102
}
@@ -4677,9 +4682,7 @@ where
4677
4682
log_bytes!( chan_id) , action) ;
4678
4683
peer_state. monitor_update_blocked_actions . entry ( chan_id) . or_insert ( Vec :: new ( ) ) . push ( action) ;
4679
4684
}
4680
- let update_id = monitor_update. update_id ;
4681
- let update_res = self . chain_monitor . update_channel ( prev_hop. outpoint , & monitor_update) ;
4682
- let res = handle_new_monitor_update ! ( self , update_res, update_id, peer_state_lock,
4685
+ let res = handle_new_monitor_update ! ( self , prev_hop. outpoint, monitor_update, peer_state_lock,
4683
4686
peer_state, per_peer_state, chan) ;
4684
4687
if let Err ( e) = res {
4685
4688
// TODO: This is a *critical* error - we probably updated the outbound edge
@@ -5216,7 +5219,8 @@ where
5216
5219
5217
5220
let chan = e. insert ( chan) ;
5218
5221
let mut res = handle_new_monitor_update ! ( self , monitor_res, 0 , peer_state_lock, peer_state,
5219
- per_peer_state, chan, MANUALLY_REMOVING , { peer_state. channel_by_id. remove( & new_channel_id) } ) ;
5222
+ per_peer_state, chan, MANUALLY_REMOVING_ALREADY_APPLIED ,
5223
+ { peer_state. channel_by_id. remove( & new_channel_id) } ) ;
5220
5224
5221
5225
// Note that we reply with the new channel_id in error messages if we gave up on the
5222
5226
// channel, not the temporary_channel_id. This is compatible with ourselves, but the
@@ -5249,7 +5253,7 @@ where
5249
5253
let monitor = try_chan_entry ! ( self ,
5250
5254
chan. get_mut( ) . funding_signed( & msg, best_block, & self . signer_provider, & self . logger) , chan) ;
5251
5255
let update_res = self . chain_monitor . watch_channel ( chan. get ( ) . context . get_funding_txo ( ) . unwrap ( ) , monitor) ;
5252
- let mut res = handle_new_monitor_update ! ( self , update_res, 0 , peer_state_lock, peer_state, per_peer_state, chan) ;
5256
+ let mut res = handle_new_monitor_update ! ( self , update_res, 0 , peer_state_lock, peer_state, per_peer_state, chan, ALREADY_APPLIED ) ;
5253
5257
if let Err ( MsgHandleErrInternal { ref mut shutdown_finish, .. } ) = res {
5254
5258
// We weren't able to watch the channel to begin with, so no updates should be made on
5255
5259
// it. Previously, full_stack_target found an (unreachable) panic when the
@@ -5346,9 +5350,7 @@ where
5346
5350
5347
5351
// Update the monitor with the shutdown script if necessary.
5348
5352
if let Some ( monitor_update) = monitor_update_opt {
5349
- let update_id = monitor_update. update_id ;
5350
- let update_res = self . chain_monitor . update_channel ( funding_txo_opt. unwrap ( ) , & monitor_update) ;
5351
- break handle_new_monitor_update ! ( self , update_res, update_id, peer_state_lock, peer_state, per_peer_state, chan_entry) ;
5353
+ break handle_new_monitor_update ! ( self , funding_txo_opt. unwrap( ) , monitor_update, peer_state_lock, peer_state, per_peer_state, chan_entry) ;
5352
5354
}
5353
5355
break Ok ( ( ) ) ;
5354
5356
} ,
@@ -5544,9 +5546,7 @@ where
5544
5546
let funding_txo = chan. get ( ) . context . get_funding_txo ( ) ;
5545
5547
let monitor_update_opt = try_chan_entry ! ( self , chan. get_mut( ) . commitment_signed( & msg, & self . logger) , chan) ;
5546
5548
if let Some ( monitor_update) = monitor_update_opt {
5547
- let update_res = self . chain_monitor . update_channel ( funding_txo. unwrap ( ) , & monitor_update) ;
5548
- let update_id = monitor_update. update_id ;
5549
- handle_new_monitor_update ! ( self , update_res, update_id, peer_state_lock,
5549
+ handle_new_monitor_update ! ( self , funding_txo. unwrap( ) , monitor_update, peer_state_lock,
5550
5550
peer_state, per_peer_state, chan)
5551
5551
} else { Ok ( ( ) ) }
5552
5552
} ,
@@ -5683,9 +5683,7 @@ where
5683
5683
let funding_txo = chan. get ( ) . context . get_funding_txo ( ) ;
5684
5684
let ( htlcs_to_fail, monitor_update_opt) = try_chan_entry ! ( self , chan. get_mut( ) . revoke_and_ack( & msg, & self . logger) , chan) ;
5685
5685
let res = if let Some ( monitor_update) = monitor_update_opt {
5686
- let update_res = self . chain_monitor . update_channel ( funding_txo. unwrap ( ) , & monitor_update) ;
5687
- let update_id = monitor_update. update_id ;
5688
- handle_new_monitor_update ! ( self , update_res, update_id,
5686
+ handle_new_monitor_update ! ( self , funding_txo. unwrap( ) , monitor_update,
5689
5687
peer_state_lock, peer_state, per_peer_state, chan)
5690
5688
} else { Ok ( ( ) ) } ;
5691
5689
( htlcs_to_fail, res)
@@ -5961,11 +5959,8 @@ where
5961
5959
if let Some ( monitor_update) = monitor_opt {
5962
5960
has_monitor_update = true ;
5963
5961
5964
- let update_res = self . chain_monitor . update_channel (
5965
- funding_txo. expect ( "channel is live" ) , & monitor_update) ;
5966
- let update_id = monitor_update. update_id ;
5967
5962
let channel_id: [ u8 ; 32 ] = * channel_id;
5968
- let res = handle_new_monitor_update ! ( self , update_res , update_id ,
5963
+ let res = handle_new_monitor_update ! ( self , funding_txo . unwrap ( ) , monitor_update ,
5969
5964
peer_state_lock, peer_state, per_peer_state, chan, MANUALLY_REMOVING ,
5970
5965
peer_state. channel_by_id. remove( & channel_id) ) ;
5971
5966
if res. is_err ( ) {
@@ -6307,9 +6302,7 @@ where
6307
6302
if let Some ( ( monitor_update, further_update_exists) ) = chan. get_mut ( ) . unblock_next_blocked_monitor_update ( ) {
6308
6303
log_debug ! ( self . logger, "Unlocking monitor updating for channel {} and updating monitor" ,
6309
6304
log_bytes!( & channel_funding_outpoint. to_channel_id( ) [ ..] ) ) ;
6310
- let update_res = self . chain_monitor . update_channel ( channel_funding_outpoint, & monitor_update) ;
6311
- let update_id = monitor_update. update_id ;
6312
- if let Err ( e) = handle_new_monitor_update ! ( self , update_res, update_id,
6305
+ if let Err ( e) = handle_new_monitor_update ! ( self , channel_funding_outpoint, monitor_update,
6313
6306
peer_state_lck, peer_state, per_peer_state, chan)
6314
6307
{
6315
6308
errors. push ( ( e, counterparty_node_id) ) ;
0 commit comments