Shell: disable prevalidator if disable-mempool is used
This commit is contained in:
parent
d5925f088c
commit
df4e474577
@ -56,7 +56,7 @@ module Types = struct
|
||||
|
||||
mutable child:
|
||||
(state * (unit -> unit Lwt.t (* shutdown *))) option ;
|
||||
prevalidator: Prevalidator.t ;
|
||||
prevalidator: Prevalidator.t option ;
|
||||
active_peers: Peer_validator.t Lwt.t P2p_peer.Table.t ;
|
||||
bootstrapped_peers: unit P2p_peer.Table.t ;
|
||||
}
|
||||
@ -235,7 +235,11 @@ let on_request (type a) w spawn_child (req : a Request.t) : a tzresult Lwt.t =
|
||||
else begin
|
||||
Chain.set_head nv.parameters.chain_state block >>= fun previous ->
|
||||
broadcast_head w ~previous block >>= fun () ->
|
||||
Prevalidator.flush nv.prevalidator block_hash >>=? fun () ->
|
||||
begin match nv.prevalidator with
|
||||
| Some prevalidator ->
|
||||
Prevalidator.flush prevalidator block_hash
|
||||
| None -> return ()
|
||||
end >>=? fun () ->
|
||||
may_switch_test_chain w spawn_child block >>= fun () ->
|
||||
Lwt_watcher.notify nv.new_head_input block ;
|
||||
if Block_hash.equal head_hash block_header.shell.predecessor then
|
||||
@ -255,17 +259,23 @@ let on_close w =
|
||||
let nv = Worker.state w in
|
||||
Distributed_db.deactivate nv.parameters.chain_db >>= fun () ->
|
||||
Lwt.join
|
||||
(Prevalidator.shutdown nv.prevalidator ::
|
||||
(begin match nv.prevalidator with
|
||||
| Some prevalidator -> Prevalidator.shutdown prevalidator
|
||||
| None -> Lwt.return_unit
|
||||
end ::
|
||||
Lwt_utils.may ~f:(fun (_, shutdown) -> shutdown ()) nv.child ::
|
||||
P2p_peer.Table.fold
|
||||
(fun _ pv acc -> (pv >>= Peer_validator.shutdown) :: acc)
|
||||
nv.active_peers []) >>= fun () ->
|
||||
Lwt.return_unit
|
||||
|
||||
let on_launch w _ parameters =
|
||||
let on_launch start_prevalidator w _ parameters =
|
||||
Chain.init_head parameters.chain_state >>= fun () ->
|
||||
Prevalidator.create
|
||||
parameters.prevalidator_limits parameters.chain_db >>= fun prevalidator ->
|
||||
(if start_prevalidator then
|
||||
Prevalidator.create
|
||||
parameters.prevalidator_limits parameters.chain_db >>= fun prevalidator ->
|
||||
Lwt.return_some prevalidator
|
||||
else Lwt.return_none) >>= fun prevalidator ->
|
||||
let valid_block_input = Lwt_watcher.create_input () in
|
||||
let new_head_input = Lwt_watcher.create_input () in
|
||||
let bootstrapped_waiter, bootstrapped_wakener = Lwt.wait () in
|
||||
@ -296,7 +306,11 @@ let on_launch w _ parameters =
|
||||
may_activate_peer_validator w peer_id >>= fun pv ->
|
||||
Peer_validator.notify_head pv block ;
|
||||
(* TODO notify prevalidator only if head is known ??? *)
|
||||
Prevalidator.notify_operations nv.prevalidator peer_id ops ;
|
||||
begin match nv.prevalidator with
|
||||
| Some prevalidator ->
|
||||
Prevalidator.notify_operations prevalidator peer_id ops
|
||||
| None -> ()
|
||||
end ;
|
||||
Lwt.return_unit
|
||||
end;
|
||||
end ;
|
||||
@ -311,15 +325,15 @@ let on_launch w _ parameters =
|
||||
Lwt.return nv
|
||||
|
||||
let rec create
|
||||
?max_child_ttl ?parent
|
||||
?max_child_ttl ~start_prevalidator ?parent
|
||||
peer_validator_limits prevalidator_limits block_validator
|
||||
global_valid_block_input db chain_state limits =
|
||||
let spawn_child ~parent pvl pl bl gvbi db n l =
|
||||
create ~parent pvl pl bl gvbi db n l >>= fun w ->
|
||||
create ~start_prevalidator ~parent pvl pl bl gvbi db n l >>= fun w ->
|
||||
Lwt.return (Worker.state w, (fun () -> Worker.shutdown w)) in
|
||||
let module Handlers = struct
|
||||
type self = t
|
||||
let on_launch = on_launch
|
||||
let on_launch = on_launch start_prevalidator
|
||||
let on_request w = on_request w spawn_child
|
||||
let on_close = on_close
|
||||
let on_error _ _ _ errs = Lwt.return (Error errs)
|
||||
@ -347,11 +361,13 @@ let rec create
|
||||
|
||||
let create
|
||||
?max_child_ttl
|
||||
~start_prevalidator
|
||||
peer_validator_limits prevalidator_limits
|
||||
block_validator global_valid_block_input global_db state limits =
|
||||
(* hide the optional ?parent *)
|
||||
create
|
||||
?max_child_ttl
|
||||
~start_prevalidator
|
||||
peer_validator_limits prevalidator_limits
|
||||
block_validator global_valid_block_input global_db state limits
|
||||
|
||||
|
@ -16,6 +16,7 @@ type limits = {
|
||||
|
||||
val create:
|
||||
?max_child_ttl:int ->
|
||||
start_prevalidator:bool ->
|
||||
Peer_validator.limits ->
|
||||
Prevalidator.limits ->
|
||||
Block_validator.t ->
|
||||
@ -29,7 +30,7 @@ val bootstrapped: t -> unit Lwt.t
|
||||
|
||||
val chain_id: t -> Chain_id.t
|
||||
val chain_state: t -> State.Chain.t
|
||||
val prevalidator: t -> Prevalidator.t
|
||||
val prevalidator: t -> Prevalidator.t option
|
||||
val chain_db: t -> Distributed_db.chain_db
|
||||
val child: t -> t option
|
||||
|
||||
|
@ -149,6 +149,10 @@ let create { genesis ; store_root ; context_root ;
|
||||
block_validator_limits
|
||||
prevalidator_limits
|
||||
chain_validator_limits =
|
||||
let start_prevalidator =
|
||||
match p2p_params with
|
||||
| Some (config, _limits) -> not config.P2p.disable_mempool
|
||||
| None -> true in
|
||||
init_p2p p2p_params >>=? fun (p2p, conn_metadata_cfg) ->
|
||||
State.read
|
||||
~store_root ~context_root ?patch_context genesis >>=? fun (state, mainchain_state) ->
|
||||
@ -160,7 +164,7 @@ let create { genesis ; store_root ; context_root ;
|
||||
prevalidator_limits
|
||||
chain_validator_limits >>= fun validator ->
|
||||
Validator.activate validator
|
||||
?max_child_ttl mainchain_state >>= fun mainchain_validator ->
|
||||
?max_child_ttl ~start_prevalidator mainchain_state >>= fun mainchain_validator ->
|
||||
let shutdown () =
|
||||
P2p.shutdown p2p >>= fun () ->
|
||||
Validator.shutdown validator >>= fun () ->
|
||||
@ -319,8 +323,12 @@ module RPC = struct
|
||||
|
||||
let pending_operations node =
|
||||
let validator = get_validator node (`Head 0) in
|
||||
let pv = Chain_validator.prevalidator validator in
|
||||
Lwt.return (Prevalidator.operations pv)
|
||||
let pv_opt = Chain_validator.prevalidator validator in
|
||||
match pv_opt with
|
||||
| Some pv ->
|
||||
Lwt.return (Prevalidator.operations pv)
|
||||
| None ->
|
||||
Lwt.return (Preapply_result.empty, Operation_hash.Map.empty)
|
||||
|
||||
let protocols { state } =
|
||||
State.Protocol.list state >>= fun set ->
|
||||
|
@ -38,7 +38,7 @@ let create state db
|
||||
valid_block_input ;
|
||||
active_chains = Chain_id.Table.create 7 }
|
||||
|
||||
let activate v ?max_child_ttl chain_state =
|
||||
let activate v ?max_child_ttl ~start_prevalidator chain_state =
|
||||
let chain_id = State.Chain.id chain_state in
|
||||
lwt_log_notice "activate chain %a" Chain_id.pp chain_id >>= fun () ->
|
||||
try Chain_id.Table.find v.active_chains chain_id
|
||||
@ -46,6 +46,7 @@ let activate v ?max_child_ttl chain_state =
|
||||
let nv =
|
||||
Chain_validator.create
|
||||
?max_child_ttl
|
||||
~start_prevalidator
|
||||
v.peer_validator_limits v.prevalidator_limits
|
||||
v.block_validator v.valid_block_input v.db chain_state
|
||||
v.chain_validator_limits in
|
||||
@ -126,5 +127,7 @@ let inject_operation v ?chain_id op =
|
||||
failwith "Unknown branch (%a), cannot inject the operation."
|
||||
Block_hash.pp_short op.shell.branch
|
||||
end >>=? fun nv ->
|
||||
let pv = Chain_validator.prevalidator nv in
|
||||
Prevalidator.inject_operation pv op
|
||||
let pv_opt = Chain_validator.prevalidator nv in
|
||||
match pv_opt with
|
||||
| Some pv -> Prevalidator.inject_operation pv op
|
||||
| None -> failwith "Prevalidator is not running, cannot inject the operation."
|
||||
|
@ -25,6 +25,7 @@ val shutdown: t -> unit Lwt.t
|
||||
val activate:
|
||||
t ->
|
||||
?max_child_ttl:int ->
|
||||
start_prevalidator:bool ->
|
||||
State.Chain.t -> Chain_validator.t Lwt.t
|
||||
|
||||
val get: t -> Chain_id.t -> Chain_validator.t tzresult Lwt.t
|
||||
|
Loading…
Reference in New Issue
Block a user