diff --git a/src/lib_shell/mempool_worker.ml b/src/lib_shell/mempool_worker.ml index cc711d3ef..ca7da1a97 100644 --- a/src/lib_shell/mempool_worker.ml +++ b/src/lib_shell/mempool_worker.ml @@ -227,32 +227,34 @@ module Make(Static: STATIC)(Proto: Registered_protocol.T) (* parsed operations' cache. used for memoization *) module ParsedCache = struct - type t = operation tzresult Operation_hash.Table.t + type t = { + table: operation tzresult Operation_hash.Table.t ; + ring: Operation_hash.t Ring.t ; + } - let encoding = - (Operation_hash.Table.encoding - (Error_monad.result_encoding operation_encoding)) - - let create () : t = - Operation_hash.Table.create 1000 + let create () : t = { + table = Operation_hash.Table.create Static.max_size_parsed_cache ; + ring = Ring.create Static.max_size_parsed_cache ; + } let add t raw_op parsed_op = let hash = Operation.hash raw_op in - Operation_hash.Table.replace t hash parsed_op - - let mem t raw_op = - let hash = Operation.hash raw_op in - Operation_hash.Table.mem t hash + Option.iter + ~f:(Operation_hash.Table.remove t.table) + (Ring.add_and_return_erased t.ring hash); + Operation_hash.Table.replace t.table hash parsed_op let find_opt t raw_op = let hash = Operation.hash raw_op in - Operation_hash.Table.find_opt t hash + Operation_hash.Table.find_opt t.table hash let find_hash_opt t hash = - Operation_hash.Table.find_opt t hash + Operation_hash.Table.find_opt t.table hash let rem t hash = - Operation_hash.Table.remove t hash + (* NOTE: hashes are not removed from the ring. As a result, the cache size + * bound can be lowered. This is a non-issue because it's only a cache. *) + Operation_hash.Table.remove t.table hash end