@@ -1910,13 +1910,15 @@ macro_rules! handle_new_monitor_update {
1910
1910
let update_id = $update. update_id;
1911
1911
let in_flight_updates = $peer_state. in_flight_monitor_updates. entry( $funding_txo)
1912
1912
. or_insert_with( Vec :: new) ;
1913
- if !in_flight_updates. contains( & $update) {
1914
- // During startup, we push monitor updates as background events through to here in
1915
- // order to replay updates that were in-flight when we shut down. Thus, we have to
1916
- // filter for uniqueness here.
1917
- in_flight_updates. push( $update) ;
1918
- }
1919
- let update_res = $self. chain_monitor. update_channel( $funding_txo, in_flight_updates. last( ) . unwrap( ) ) ;
1913
+ // During startup, we push monitor updates as background events through to here in
1914
+ // order to replay updates that were in-flight when we shut down. Thus, we have to
1915
+ // filter for uniqueness here.
1916
+ let idx = in_flight_updates. iter( ) . position( |upd| upd == & $update)
1917
+ . unwrap_or_else( || {
1918
+ in_flight_updates. push( $update) ;
1919
+ in_flight_updates. len( ) - 1
1920
+ } ) ;
1921
+ let update_res = $self. chain_monitor. update_channel( $funding_txo, & in_flight_updates[ idx] ) ;
1920
1922
handle_new_monitor_update!( $self, update_res, $peer_state_lock, $peer_state,
1921
1923
$per_peer_state_lock, $chan, _internal, $remove,
1922
1924
{
0 commit comments