Skip to content

Commit

Permalink
Change the order in drop_until_sufficient_balance
Browse files Browse the repository at this point in the history
Dropped sequence was returned in reverse order, then concatenated to a
sequence in straight order. This is not causing any immediate issues,
but is better for clarity.
  • Loading branch information
georgeee committed Dec 5, 2024
1 parent 3e405df commit d82727b
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/lib/network_pool/indexed_pool.ml
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,11 @@ let remove_with_dependents_exn' t cmd =
failwith "remove_with_dependents_exn"

(** Drop commands from the end of the queue until the total currency consumed is
<= the current balance. *)
<= the current balance.
Returns the prefix of a queue, updated currency reserved and sequence of
dropped transactions in the same order they appear in queue.
*)
let drop_until_sufficient_balance :
Transaction_hash.User_command_with_valid_signature.t F_sequence.t
* Currency.Amount.t
Expand All @@ -654,17 +658,17 @@ let drop_until_sufficient_balance :
if Currency.Amount.(currency_reserved' <= current_balance) then
(queue', currency_reserved', dropped_so_far)
else
let daeh, liat =
let init, last =
Option.value_exn
~message:
"couldn't drop any more transactions when trying to preserve \
sufficient balance"
(F_sequence.unsnoc queue')
in
let consumed = Option.value_exn (currency_consumed liat) in
go daeh
let consumed = Option.value_exn (currency_consumed last) in
go init
(Option.value_exn Currency.Amount.(currency_reserved' - consumed))
(Sequence.append dropped_so_far @@ Sequence.singleton liat)
(Sequence.shift_right dropped_so_far last)
in
go queue currency_reserved Sequence.empty

Expand Down Expand Up @@ -760,6 +764,7 @@ let revalidate :
(keep_queue, currency_reserved')
current_balance
in
(* NB: to_drop is ordered by nonce *)
let to_drop =
Sequence.append (F_sequence.to_seq drop_queue) dropped_for_balance
in
Expand Down

0 comments on commit d82727b

Please sign in to comment.