@@ -743,61 +743,56 @@ let revalidate :
743
743
" Current account nonce succeeds first nonce in queue; splitting \
744
744
queue at $index"
745
745
~metadata: [ (" index" , `Int first_applicable_nonce_index) ] ;
746
- let drop_queue, keep_queue =
746
+ let dropped_from_nonce, retained_by_nonce =
747
747
F_sequence. split_at queue first_applicable_nonce_index
748
748
in
749
- let currency_reserved' =
749
+ let currency_reserved_partially_updated =
750
750
F_sequence. foldl
751
751
(fun c cmd ->
752
752
Option. value_exn
753
753
Currency.Amount. (c - Option. value_exn (currency_consumed cmd))
754
754
)
755
- currency_reserved drop_queue
755
+ currency_reserved dropped_from_nonce
756
756
in
757
757
(* 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 =
759
759
drop_until_sufficient_balance
760
- (keep_queue, currency_reserved' )
760
+ (retained_by_nonce, currency_reserved_partially_updated )
761
761
current_balance
762
762
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
766
765
(* t with all_by_sender and applicable_by_fee fields updated *)
767
766
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 ->
774
769
(* Nothing dropped, nothing needs to be updated *)
775
770
t
776
- | Some ( first_dropped , _ ), _ , None | None , Some first_dropped , None ->
771
+ | None ->
777
772
(* We drop the entire queue, first element needs to be removed from
778
773
applicable_by_fee *)
779
- let t' = remove_applicable_exn t first_dropped in
774
+ let t' = remove_applicable_exn t first_cmd in
780
775
{ 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
783
778
the head untouched, no need to update applicable_by_fee *)
784
779
{ t with
785
780
all_by_sender =
786
781
Map. set t.all_by_sender ~key: sender
787
- ~data: (keep_queue', currency_reserved'' )
782
+ ~data: (keep_queue, currency_reserved_updated )
788
783
}
789
- | Some (first_dropped , _ ), _ , Some ( first_kept , _ ) ->
784
+ | Some (first_kept , _ ) ->
790
785
(* We need to replace old queue head with the new queue head
791
786
in applicable_by_fee *)
792
787
let first_kept_unchecked =
793
788
Transaction_hash.User_command_with_valid_signature. command
794
789
first_kept
795
790
in
796
- let t' = remove_applicable_exn t first_dropped in
791
+ let t' = remove_applicable_exn t first_cmd in
797
792
{ t' with
798
793
all_by_sender =
799
794
Map. set t'.all_by_sender ~key: sender
800
- ~data: (keep_queue', currency_reserved'' )
795
+ ~data: (keep_queue, currency_reserved_updated )
801
796
; applicable_by_fee =
802
797
Map_set. insert
803
798
(module Transaction_hash. User_command_with_valid_signature )
@@ -806,6 +801,11 @@ let revalidate :
806
801
first_kept
807
802
}
808
803
in
804
+ let to_drop =
805
+ Sequence. append
806
+ (F_sequence. to_seq dropped_from_nonce)
807
+ dropped_for_balance
808
+ in
809
809
let t_updated =
810
810
Sequence. fold ~init: t_partially_updated
811
811
~f: remove_all_by_fee_and_hash_and_expiration_exn to_drop
0 commit comments