Skip to content

Commit

Permalink
Merge pull request #15559 from MinaProtocol/sai/issue-11704
Browse files Browse the repository at this point in the history
removing unecessary lru cache for gossip messages in p2p
  • Loading branch information
svv232 authored May 6, 2024
2 parents 9f38ff1 + 051ab46 commit 2417ed3
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 46 deletions.
11 changes: 1 addition & 10 deletions src/lib/network_pool/intf.ml
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,7 @@ module type Resource_pool_base_intf = sig
end

module Verification_error = struct
type t =
| Fee_higher
| Fee_equal
| Recently_seen
| Invalid of Error.t
| Failure of Error.t
type t = Fee_higher | Fee_equal | Invalid of Error.t | Failure of Error.t

let to_error = function
| Fee_equal ->
Expand All @@ -58,12 +53,8 @@ module Verification_error = struct
Error.tag err ~tag:"invalid"
| Failure err ->
Error.tag err ~tag:"failure"
| Recently_seen ->
Error.of_string "recently seen"

let to_short_string = function
| Recently_seen ->
"recently_seen"
| Fee_equal ->
"fee_equal"
| Fee_higher ->
Expand Down
36 changes: 0 additions & 36 deletions src/lib/network_pool/transaction_pool.ml
Original file line number Diff line number Diff line change
Expand Up @@ -308,27 +308,6 @@ struct

module Batcher = Batcher.Transaction_pool

module Lru_cache = struct
let max_size = 2048

module T = struct
type t = User_command.t list [@@deriving hash]
end

module Q = Hash_queue.Make (Int)

type t = unit Q.t

let add t h =
if not (Q.mem t h) then (
if Q.length t >= max_size then ignore (Q.dequeue_front t : 'a option) ;
Q.enqueue_back_exn t h () ;
`Already_mem false )
else (
ignore (Q.lookup_and_move_to_back t h : unit option) ;
`Already_mem true )
end

module Mutex = struct
open Async

Expand Down Expand Up @@ -434,7 +413,6 @@ struct

type t =
{ mutable pool : Indexed_pool.t
; recently_seen : (Lru_cache.t[@sexp.opaque])
; locally_generated_uncommitted :
( Transaction_hash.User_command_with_valid_signature.t
, Time.t * [ `Batch of int ] )
Expand Down Expand Up @@ -855,7 +833,6 @@ struct
; logger
; batcher = Batcher.create config.verifier
; best_tip_diff_relay = None
; recently_seen = Lru_cache.Q.create ()
; best_tip_ledger = None
; verification_key_table = Vk_refcount_table.create ()
}
Expand Down Expand Up @@ -1106,20 +1083,7 @@ struct
, Intf.Verification_error.t )
Deferred.Result.t =
let open Deferred.Result.Let_syntax in
let is_sender_local =
Envelope.Sender.(equal Local) (Envelope.Incoming.sender diff)
in
let open Intf.Verification_error in
let%bind () =
(* TODO: we should probably remove this -- the libp2p gossip cache should cover this already (#11704) *)
let (`Already_mem already_mem) =
Lru_cache.add t.recently_seen (Lru_cache.T.hash diff.data)
in
Deferred.return
@@ Result.ok_if_true
((not already_mem) || is_sender_local)
~error:Recently_seen
in
let%bind () =
let well_formedness_errors =
List.fold (Envelope.Incoming.data diff) ~init:[]
Expand Down

0 comments on commit 2417ed3

Please sign in to comment.