Shell/Mempool: limited, configurable size of parsed cache

This commit is contained in:
Raphaël Proust 2018-11-16 10:24:35 +08:00 committed by MBourgoin
parent 0bb2f3d4d1
commit ad9d087031
No known key found for this signature in database
GPG Key ID: 4B3F7008ABB5B2D0

View File

@ -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