Skip to content

Commit 5275b89

Browse files
committed
Simplify the fix for #16397
1 parent b768bfd commit 5275b89

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

src/lib/network_pool/indexed_pool.ml

+22-22
Original file line numberDiff line numberDiff line change
@@ -743,61 +743,56 @@ let revalidate :
743743
"Current account nonce succeeds first nonce in queue; splitting \
744744
queue at $index"
745745
~metadata:[ ("index", `Int first_applicable_nonce_index) ] ;
746-
let drop_queue, keep_queue =
746+
let dropped_from_nonce, retained_by_nonce =
747747
F_sequence.split_at queue first_applicable_nonce_index
748748
in
749-
let currency_reserved' =
749+
let currency_reserved_partially_updated =
750750
F_sequence.foldl
751751
(fun c cmd ->
752752
Option.value_exn
753753
Currency.Amount.(c - Option.value_exn (currency_consumed cmd))
754754
)
755-
currency_reserved drop_queue
755+
currency_reserved dropped_from_nonce
756756
in
757757
(* NB: dropped_for_balance is ordered by nonce *)
758-
let keep_queue', currency_reserved'', dropped_for_balance =
758+
let keep_queue, currency_reserved_updated, dropped_for_balance =
759759
drop_until_sufficient_balance
760-
(keep_queue, currency_reserved')
760+
(retained_by_nonce, currency_reserved_partially_updated)
761761
current_balance
762762
in
763-
let to_drop =
764-
Sequence.append (F_sequence.to_seq drop_queue) dropped_for_balance
765-
in
763+
let keeping_prefix = F_sequence.is_empty dropped_from_nonce in
764+
let keeping_suffix = Sequence.is_empty dropped_for_balance in
766765
(* t with all_by_sender and applicable_by_fee fields updated *)
767766
let t_partially_updated =
768-
match
769-
( F_sequence.uncons drop_queue
770-
, Sequence.hd dropped_for_balance
771-
, F_sequence.uncons keep_queue' )
772-
with
773-
| None, None, _ ->
767+
match F_sequence.uncons keep_queue with
768+
| _ when keeping_prefix && keeping_suffix ->
774769
(* Nothing dropped, nothing needs to be updated *)
775770
t
776-
| Some (first_dropped, _), _, None | None, Some first_dropped, None ->
771+
| None ->
777772
(* We drop the entire queue, first element needs to be removed from
778773
applicable_by_fee *)
779-
let t' = remove_applicable_exn t first_dropped in
774+
let t' = remove_applicable_exn t first_cmd in
780775
{ t' with all_by_sender = Map.remove t'.all_by_sender sender }
781-
| None, _, Some _ ->
782-
(* We drop only some transactions from the end of queue, keeping
776+
| Some _ when keeping_prefix ->
777+
(* We drop only transactions from the end of queue, keeping
783778
the head untouched, no need to update applicable_by_fee *)
784779
{ t with
785780
all_by_sender =
786781
Map.set t.all_by_sender ~key:sender
787-
~data:(keep_queue', currency_reserved'')
782+
~data:(keep_queue, currency_reserved_updated)
788783
}
789-
| Some (first_dropped, _), _, Some (first_kept, _) ->
784+
| Some (first_kept, _) ->
790785
(* We need to replace old queue head with the new queue head
791786
in applicable_by_fee *)
792787
let first_kept_unchecked =
793788
Transaction_hash.User_command_with_valid_signature.command
794789
first_kept
795790
in
796-
let t' = remove_applicable_exn t first_dropped in
791+
let t' = remove_applicable_exn t first_cmd in
797792
{ t' with
798793
all_by_sender =
799794
Map.set t'.all_by_sender ~key:sender
800-
~data:(keep_queue', currency_reserved'')
795+
~data:(keep_queue, currency_reserved_updated)
801796
; applicable_by_fee =
802797
Map_set.insert
803798
(module Transaction_hash.User_command_with_valid_signature)
@@ -806,6 +801,11 @@ let revalidate :
806801
first_kept
807802
}
808803
in
804+
let to_drop =
805+
Sequence.append
806+
(F_sequence.to_seq dropped_from_nonce)
807+
dropped_for_balance
808+
in
809809
let t_updated =
810810
Sequence.fold ~init:t_partially_updated
811811
~f:remove_all_by_fee_and_hash_and_expiration_exn to_drop

0 commit comments

Comments
 (0)