Skip to content

Commit 1b95a6e

Browse files
committedDec 5, 2024··
Fix handling of applicable_by_fee in revalidate
Fix the issue #16397 by ensuring removal from `applicable_by_fee` is done only for the previous head of queue.
1 parent badac1d commit 1b95a6e

File tree

1 file changed

+46
-37
lines changed

1 file changed

+46
-37
lines changed
 

‎src/lib/network_pool/indexed_pool.ml

+46-37
Original file line numberDiff line numberDiff line change
@@ -786,43 +786,52 @@ let revalidate :
786786
(F_sequence.to_seq dropped_for_nonce)
787787
dropped_for_balance
788788
in
789-
match Sequence.next to_drop with
790-
| None ->
791-
acc
792-
| Some (head, tail) ->
793-
let t'' =
794-
Sequence.fold tail
795-
~init:
796-
(remove_all_by_fee_and_hash_and_expiration_exn
797-
(remove_applicable_exn t head)
798-
head )
799-
~f:remove_all_by_fee_and_hash_and_expiration_exn
800-
in
801-
let t''' =
802-
match F_sequence.uncons keep_queue with
803-
| None ->
804-
{ t'' with
805-
all_by_sender = Map.remove t''.all_by_sender sender
806-
}
807-
| Some (first_kept, _) ->
808-
let first_kept_unchecked =
809-
Transaction_hash.User_command_with_valid_signature.command
810-
first_kept
811-
in
812-
{ t'' with
813-
all_by_sender =
814-
Map.set t''.all_by_sender ~key:sender
815-
~data:(keep_queue, currency_reserved_updated)
816-
; applicable_by_fee =
817-
Map_set.insert
818-
( module Transaction_hash
819-
.User_command_with_valid_signature )
820-
t''.applicable_by_fee
821-
(User_command.fee_per_wu first_kept_unchecked)
822-
first_kept
823-
}
824-
in
825-
(t''', Sequence.append dropped_acc to_drop) )
789+
let keeping_prefix = F_sequence.is_empty dropped_for_nonce in
790+
let keeping_suffix = Sequence.is_empty dropped_for_balance in
791+
(* t with all_by_sender and applicable_by_fee fields updated *)
792+
let t_partially_updated =
793+
match F_sequence.uncons keep_queue with
794+
| _ when keeping_prefix && keeping_suffix ->
795+
(* Nothing dropped, nothing needs to be updated *)
796+
t
797+
| None ->
798+
(* We drop the entire queue, first element needs to be removed from
799+
applicable_by_fee *)
800+
let t' = remove_applicable_exn t first_cmd in
801+
{ t' with all_by_sender = Map.remove t'.all_by_sender sender }
802+
| Some _ when keeping_prefix ->
803+
(* We drop only transactions from the end of queue, keeping
804+
the head untouched, no need to update applicable_by_fee *)
805+
{ t with
806+
all_by_sender =
807+
Map.set t.all_by_sender ~key:sender
808+
~data:(keep_queue, currency_reserved_updated)
809+
}
810+
| Some (first_kept, _) ->
811+
(* We need to replace old queue head with the new queue head
812+
in applicable_by_fee *)
813+
let first_kept_unchecked =
814+
Transaction_hash.User_command_with_valid_signature.command
815+
first_kept
816+
in
817+
let t' = remove_applicable_exn t first_cmd in
818+
{ t' with
819+
all_by_sender =
820+
Map.set t'.all_by_sender ~key:sender
821+
~data:(keep_queue, currency_reserved_updated)
822+
; applicable_by_fee =
823+
Map_set.insert
824+
(module Transaction_hash.User_command_with_valid_signature)
825+
t'.applicable_by_fee
826+
(User_command.fee_per_wu first_kept_unchecked)
827+
first_kept
828+
}
829+
in
830+
let t_updated =
831+
Sequence.fold ~init:t_partially_updated
832+
~f:remove_all_by_fee_and_hash_and_expiration_exn to_drop
833+
in
834+
(t_updated, Sequence.append dropped_acc to_drop) )
826835

827836
let expired_by_global_slot (t : t) :
828837
Transaction_hash.User_command_with_valid_signature.t Sequence.t =

0 commit comments

Comments
 (0)
Please sign in to comment.