Skip to content

Commit 0790709

Browse files
committed
Change the order in drop_until_sufficient_balance
Dropped sequence was returned in reverse order, then concatenated to a sequence in straight order. This is part of a fix for issue #16397.
1 parent 3e405df commit 0790709

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

src/lib/network_pool/indexed_pool.ml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,11 @@ let remove_with_dependents_exn' t cmd =
641641
failwith "remove_with_dependents_exn"
642642

643643
(** Drop commands from the end of the queue until the total currency consumed is
644-
<= the current balance. *)
644+
<= the current balance.
645+
646+
Returns the prefix of a queue, updated currency reserved and sequence of
647+
dropped transactions in the same order they appear in queue.
648+
*)
645649
let drop_until_sufficient_balance :
646650
Transaction_hash.User_command_with_valid_signature.t F_sequence.t
647651
* Currency.Amount.t
@@ -654,17 +658,17 @@ let drop_until_sufficient_balance :
654658
if Currency.Amount.(currency_reserved' <= current_balance) then
655659
(queue', currency_reserved', dropped_so_far)
656660
else
657-
let daeh, liat =
661+
let init, last =
658662
Option.value_exn
659663
~message:
660664
"couldn't drop any more transactions when trying to preserve \
661665
sufficient balance"
662666
(F_sequence.unsnoc queue')
663667
in
664-
let consumed = Option.value_exn (currency_consumed liat) in
665-
go daeh
668+
let consumed = Option.value_exn (currency_consumed last) in
669+
go init
666670
(Option.value_exn Currency.Amount.(currency_reserved' - consumed))
667-
(Sequence.append dropped_so_far @@ Sequence.singleton liat)
671+
(Sequence.shift_right dropped_so_far last)
668672
in
669673
go queue currency_reserved Sequence.empty
670674

@@ -760,6 +764,7 @@ let revalidate :
760764
(keep_queue, currency_reserved')
761765
current_balance
762766
in
767+
(* NB: to_drop is ordered by nonce *)
763768
let to_drop =
764769
Sequence.append (F_sequence.to_seq drop_queue) dropped_for_balance
765770
in

0 commit comments

Comments
 (0)