P2P: allow to limit the size of mempool
This commit is contained in:
parent
fed04d4b8f
commit
6f4a98f6fd
@ -19,9 +19,17 @@ let encoding =
|
|||||||
(fun { known_valid ; pending } -> (known_valid, pending))
|
(fun { known_valid ; pending } -> (known_valid, pending))
|
||||||
(fun (known_valid, pending) -> { known_valid ; pending })
|
(fun (known_valid, pending) -> { known_valid ; pending })
|
||||||
(obj2
|
(obj2
|
||||||
(req "known_valid" (dynamic_size (list Operation_hash.encoding)))
|
(req "known_valid" (list Operation_hash.encoding))
|
||||||
(req "pending" (dynamic_size Operation_hash.Set.encoding)))
|
(req "pending" (dynamic_size Operation_hash.Set.encoding)))
|
||||||
|
|
||||||
|
let bounded_encoding ?max_operations () =
|
||||||
|
match max_operations with
|
||||||
|
| None -> encoding
|
||||||
|
| Some max_operations ->
|
||||||
|
Data_encoding.check_size
|
||||||
|
(8 + max_operations * Operation_hash.size)
|
||||||
|
encoding
|
||||||
|
|
||||||
let empty = {
|
let empty = {
|
||||||
known_valid = [] ;
|
known_valid = [] ;
|
||||||
pending = Operation_hash.Set.empty ;
|
pending = Operation_hash.Set.empty ;
|
||||||
|
@ -19,6 +19,7 @@ type t = {
|
|||||||
type mempool = t
|
type mempool = t
|
||||||
|
|
||||||
val encoding: mempool Data_encoding.t
|
val encoding: mempool Data_encoding.t
|
||||||
|
val bounded_encoding: ?max_operations:int -> unit -> mempool Data_encoding.t
|
||||||
|
|
||||||
val empty: mempool
|
val empty: mempool
|
||||||
(** Empty mempool. *)
|
(** Empty mempool. *)
|
||||||
|
@ -93,6 +93,16 @@ module Bounded_encoding = struct
|
|||||||
protocol_max_size := max
|
protocol_max_size := max
|
||||||
let protocol = delayed (fun () -> !protocol_cache)
|
let protocol = delayed (fun () -> !protocol_cache)
|
||||||
|
|
||||||
|
let mempool_max_operations = ref None
|
||||||
|
let mempool_cache =
|
||||||
|
ref (Mempool.bounded_encoding ?max_operations:!mempool_max_operations ())
|
||||||
|
let update_mempool_encoding () =
|
||||||
|
mempool_cache :=
|
||||||
|
Mempool.bounded_encoding ?max_operations:!mempool_max_operations ()
|
||||||
|
let set_mempool_max_operations max =
|
||||||
|
mempool_max_operations := max
|
||||||
|
let mempool = delayed (fun () -> !mempool_cache)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
type t =
|
type t =
|
||||||
@ -170,7 +180,7 @@ let encoding =
|
|||||||
(obj3
|
(obj3
|
||||||
(req "chain_id" Chain_id.encoding)
|
(req "chain_id" Chain_id.encoding)
|
||||||
(req "current_block_header" (dynamic_size Bounded_encoding.block_header))
|
(req "current_block_header" (dynamic_size Bounded_encoding.block_header))
|
||||||
(req "current_mempool" Mempool.encoding))
|
(req "current_mempool" Bounded_encoding.mempool))
|
||||||
(function
|
(function
|
||||||
| Current_head (chain_id, bh, mempool) -> Some (chain_id, bh, mempool)
|
| Current_head (chain_id, bh, mempool) -> Some (chain_id, bh, mempool)
|
||||||
| _ -> None)
|
| _ -> None)
|
||||||
|
@ -48,4 +48,5 @@ module Bounded_encoding : sig
|
|||||||
val set_operation_list_max_length: int option -> unit
|
val set_operation_list_max_length: int option -> unit
|
||||||
val set_operation_max_pass: int option -> unit
|
val set_operation_max_pass: int option -> unit
|
||||||
val set_protocol_max_size: int option -> unit
|
val set_protocol_max_size: int option -> unit
|
||||||
|
val set_mempool_max_operations: int option -> unit
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user