Shell/Mempool: limited, configurable size of parsed cache
This commit is contained in:
parent
2d5c56eeca
commit
5cc9e6ccc6
@ -62,7 +62,13 @@ module type T = sig
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
module Make(Proto: Registered_protocol.T) : T with module Proto = Proto = struct
|
module type STATIC = sig
|
||||||
|
val max_size_parsed_cache: int
|
||||||
|
end
|
||||||
|
|
||||||
|
module Make(Static: STATIC)(Proto: Registered_protocol.T)
|
||||||
|
: T with module Proto = Proto
|
||||||
|
= struct
|
||||||
|
|
||||||
module Proto = Proto
|
module Proto = Proto
|
||||||
|
|
||||||
@ -221,32 +227,34 @@ module Make(Proto: Registered_protocol.T) : T with module Proto = Proto = struct
|
|||||||
(* parsed operations' cache. used for memoization *)
|
(* parsed operations' cache. used for memoization *)
|
||||||
module ParsedCache = struct
|
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 =
|
let create () : t = {
|
||||||
(Operation_hash.Table.encoding
|
table = Operation_hash.Table.create Static.max_size_parsed_cache ;
|
||||||
(Error_monad.result_encoding operation_encoding))
|
ring = Ring.create Static.max_size_parsed_cache ;
|
||||||
|
}
|
||||||
let create () : t =
|
|
||||||
Operation_hash.Table.create 1000
|
|
||||||
|
|
||||||
let add t raw_op parsed_op =
|
let add t raw_op parsed_op =
|
||||||
let hash = Operation.hash raw_op in
|
let hash = Operation.hash raw_op in
|
||||||
Operation_hash.Table.replace t hash parsed_op
|
Option.iter
|
||||||
|
~f:(Operation_hash.Table.remove t.table)
|
||||||
let mem t raw_op =
|
(Ring.add_and_return_erased t.ring hash);
|
||||||
let hash = Operation.hash raw_op in
|
Operation_hash.Table.replace t.table hash parsed_op
|
||||||
Operation_hash.Table.mem t hash
|
|
||||||
|
|
||||||
let find_opt t raw_op =
|
let find_opt t raw_op =
|
||||||
let hash = Operation.hash raw_op in
|
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 =
|
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 =
|
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
|
end
|
||||||
|
|
||||||
|
@ -63,5 +63,9 @@ module type T = sig
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
module Make (Proto : Registered_protocol.T) : T
|
module type STATIC = sig
|
||||||
|
val max_size_parsed_cache: int
|
||||||
|
end
|
||||||
|
|
||||||
|
module Make (Static : STATIC) (Proto : Registered_protocol.T) : T with module Proto = Proto
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user