diff --git a/src/node/shell/node.ml b/src/node/shell/node.ml index db0b8c4df..9aee1554c 100644 --- a/src/node/shell/node.ml +++ b/src/node/shell/node.ml @@ -51,10 +51,10 @@ let inject_block validator ?force bytes operations = type t = { state: State.t ; distributed_db: Distributed_db.t ; - validator: Validator.worker ; + validator: Validator.t ; mainnet_db: Distributed_db.net_db ; mainnet_net: State.Net.t ; - mainnet_validator: Validator.t ; + mainnet_validator: Validator.net_validator ; inject_block: ?force:bool -> MBytes.t -> Distributed_db.operation list list -> @@ -107,7 +107,7 @@ let create { genesis ; store_root ; context_root ; ~store_root ~context_root ?patch_context () >>=? fun state -> let distributed_db = Distributed_db.create state p2p in let validator = - Validator.create_worker ?max_ttl state distributed_db in + Validator.create ?max_ttl state distributed_db in may_create_net state genesis >>= fun mainnet_net -> Validator.activate validator mainnet_net >>= fun mainnet_validator -> let mainnet_db = Validator.net_db mainnet_validator in diff --git a/src/node/shell/validator.ml b/src/node/shell/validator.ml index aa7b22cf9..bec9e8d95 100644 --- a/src/node/shell/validator.ml +++ b/src/node/shell/validator.ml @@ -9,11 +9,11 @@ open Logging.Node.Validator -type worker = { - activate: ?parent:t -> State.Net.t -> t Lwt.t ; - get: Net_id.t -> t tzresult Lwt.t ; - get_exn: Net_id.t -> t Lwt.t ; - deactivate: t -> unit Lwt.t ; +type t = { + activate: ?parent:net_validator -> State.Net.t -> net_validator Lwt.t ; + get: Net_id.t -> net_validator tzresult Lwt.t ; + get_exn: Net_id.t -> net_validator Lwt.t ; + deactivate: net_validator -> unit Lwt.t ; inject_block: ?force:bool -> MBytes.t -> Distributed_db.operation list list -> @@ -24,11 +24,11 @@ type worker = { db: Distributed_db.t ; } -and t = { +and net_validator = { net: State.Net.t ; - worker: worker ; - parent: t option ; - mutable child: t option ; + worker: t ; + parent: net_validator option ; + mutable child: net_validator option ; prevalidator: Prevalidator.t ; net_db: Distributed_db.net_db ; notify_block: Block_hash.t -> Block_header.t -> unit Lwt.t ; @@ -38,7 +38,7 @@ and t = { check_child: Block_hash.t -> Protocol_hash.t -> Time.t -> Time.t -> unit tzresult Lwt.t ; deactivate_child: unit -> unit Lwt.t ; - test_validator: unit -> (t * Distributed_db.net_db) option ; + test_validator: unit -> (net_validator * Distributed_db.net_db) option ; shutdown: unit -> unit Lwt.t ; valid_block_input_for_net: State.Block.t Watcher.input ; new_head_input: State.Block.t Watcher.input ; @@ -49,7 +49,7 @@ let net_state { net } = net let net_db { net_db } = net_db let activate w net = w.activate net -let deactivate t = t.worker.deactivate t +let deactivate net_validator = net_validator.worker.deactivate net_validator let get w = w.get let get_exn w = w.get_exn let notify_block w = w.notify_block @@ -366,7 +366,7 @@ module Context_db = struct type value = State.Block.t type data = - { validator: t ; + { validator: net_validator ; state: [ `Inited of Block_header.t tzresult | `Initing of Block_header.t tzresult Lwt.t | `Running of State.Block.t tzresult Lwt.t ] ; @@ -470,7 +470,7 @@ module Context_db = struct Lwt.wakeup wakener err ; Lwt.return_unit - let process (v:t) ~get_context ~set_context hash block = + let process (v: net_validator) ~get_context ~set_context hash block = let net_state = Distributed_db.state v.net_db in get_context v block.Block_header.shell.predecessor >>= function | Error _ as error -> @@ -671,11 +671,11 @@ let rec create_validator ?max_ttl ?parent worker state db net = wait () else Lwt.return_unit in - let t = + let net_validator = wait () >>= fun () -> Watcher.shutdown stopper ; Lwt.return_unit in - Lwt.no_cancel t + Lwt.no_cancel net_validator in let rec v = { @@ -787,9 +787,9 @@ let rec create_validator ?max_ttl ?parent worker state db net = type error += Unknown_network of Net_id.t -let create_worker ?max_ttl state db = +let create ?max_ttl state db = - let validators : t Lwt.t Net_id.Table.t = + let validators : net_validator Lwt.t Net_id.Table.t = Net_id.Table.create 7 in let valid_block_input = Watcher.create_input () in @@ -882,7 +882,7 @@ let create_worker ?max_ttl state db = cancel () >>= fun () -> let validators = Net_id.Table.fold - (fun _ (v: t Lwt.t) acc -> (v >>= fun v -> v.shutdown ()) :: acc) + (fun _ (v: net_validator Lwt.t) acc -> (v >>= fun v -> v.shutdown ()) :: acc) validators [] in Lwt.join (maintenance_worker :: validators) in @@ -939,5 +939,5 @@ let new_head_watcher { new_head_input } = let watcher { valid_block_input_for_net } = Watcher.create_stream valid_block_input_for_net -let global_watcher ({ valid_block_input } : worker) = +let global_watcher ({ valid_block_input } : t) = Watcher.create_stream valid_block_input diff --git a/src/node/shell/validator.mli b/src/node/shell/validator.mli index ace11895b..9dc8312c1 100644 --- a/src/node/shell/validator.mli +++ b/src/node/shell/validator.mli @@ -7,40 +7,40 @@ (* *) (**************************************************************************) -type worker - -val create_worker: ?max_ttl:int -> State.t -> Distributed_db.t -> worker -val shutdown: worker -> unit Lwt.t - -val notify_block: worker -> Block_hash.t -> Block_header.t -> unit Lwt.t - type t +val create: ?max_ttl:int -> State.t -> Distributed_db.t -> t +val shutdown: t -> unit Lwt.t + +val notify_block: t -> Block_hash.t -> Block_header.t -> unit Lwt.t + +type net_validator + type error += | Non_increasing_timestamp | Non_increasing_fitness -val activate: worker -> State.Net.t -> t Lwt.t -val get: worker -> Net_id.t -> t tzresult Lwt.t -val get_exn: worker -> Net_id.t -> t Lwt.t -val deactivate: t -> unit Lwt.t +val activate: t -> State.Net.t -> net_validator Lwt.t +val get: t -> Net_id.t -> net_validator tzresult Lwt.t +val get_exn: t -> Net_id.t -> net_validator Lwt.t +val deactivate: net_validator -> unit Lwt.t -val net_state: t -> State.Net.t -val net_db: t -> Distributed_db.net_db +val net_state: net_validator -> State.Net.t +val net_db: net_validator -> Distributed_db.net_db val fetch_block: - t -> Block_hash.t -> State.Block.t tzresult Lwt.t + net_validator -> Block_hash.t -> State.Block.t tzresult Lwt.t val inject_block: - worker -> ?force:bool -> + t -> ?force:bool -> MBytes.t -> Distributed_db.operation list list -> (Block_hash.t * State.Block.t tzresult Lwt.t) tzresult Lwt.t -val prevalidator: t -> Prevalidator.t -val test_validator: t -> (t * Distributed_db.net_db) option +val prevalidator: net_validator -> Prevalidator.t +val test_validator: net_validator -> (net_validator * Distributed_db.net_db) option -val watcher: t -> State.Block.t Lwt_stream.t * Watcher.stopper -val new_head_watcher: t -> State.Block.t Lwt_stream.t * Watcher.stopper -val global_watcher: worker -> State.Block.t Lwt_stream.t * Watcher.stopper +val watcher: net_validator -> State.Block.t Lwt_stream.t * Watcher.stopper +val new_head_watcher: net_validator -> State.Block.t Lwt_stream.t * Watcher.stopper +val global_watcher: t -> State.Block.t Lwt_stream.t * Watcher.stopper -val bootstrapped: t -> unit Lwt.t +val bootstrapped: net_validator -> unit Lwt.t