Commit 31b4fb5d authored by Romain's avatar Romain Committed by Seb Mondet

Node, Validator, Baker: parameterize user activated upgrades and overrides

parent c1f5310a
......@@ -43,6 +43,8 @@ let with_node f =
chain_name = Distributed_db_version.of_string "TEZOS_DOCGEN";
sandboxed_chain_name =
Distributed_db_version.of_string "SANDBOXED_TEZOS_DOCGEN";
user_activated_upgrades = [];
user_activated_protocol_overrides = [];
patch_context = None;
store_root = dir / "store";
context_root = dir / "context";
......
......@@ -363,6 +363,8 @@ let main node =
[".."; "<block_id>"],
RPC_directory.map (fun () -> assert false)
@@ Block_directory.build_raw_rpc_directory
~user_activated_upgrades:[]
~user_activated_protocol_overrides:[]
(module Proto)
(module Proto) ))
protocols
......
......@@ -46,10 +46,14 @@ type blockchain_network = {
old_chain_name : chain_name option;
incompatible_chain_name : chain_name option;
sandboxed_chain_name : chain_name;
user_activated_upgrades : User_activated.upgrades;
user_activated_protocol_overrides : User_activated.protocol_overrides;
}
let make_blockchain_network ~chain_name ?old_chain_name
?incompatible_chain_name ~sandboxed_chain_name genesis =
?incompatible_chain_name ~sandboxed_chain_name
?(user_activated_upgrades = []) ?(user_activated_protocol_overrides = [])
genesis =
let of_string = Distributed_db_version.of_string in
{
genesis;
......@@ -57,6 +61,15 @@ let make_blockchain_network ~chain_name ?old_chain_name
old_chain_name = Option.map old_chain_name ~f:of_string;
incompatible_chain_name = Option.map incompatible_chain_name ~f:of_string;
sandboxed_chain_name = of_string sandboxed_chain_name;
user_activated_upgrades =
List.map
(fun (l, h) -> (l, Protocol_hash.of_b58check_exn h))
user_activated_upgrades;
user_activated_protocol_overrides =
List.map
(fun (a, b) ->
(Protocol_hash.of_b58check_exn a, Protocol_hash.of_b58check_exn b))
user_activated_protocol_overrides;
}
let blockchain_network_mainnet =
......@@ -75,6 +88,12 @@ let blockchain_network_mainnet =
~old_chain_name:"TEZOS_BETANET_2018-06-30T16:07:32Z"
~incompatible_chain_name:"INCOMPATIBLE"
~sandboxed_chain_name:"SANDBOXED_TEZOS_MAINNET"
~user_activated_upgrades:
[ (28082l, "PsYLVpVvgbLhAhoqAkMFUo6gudkJ9weNXhUYCiLDzcUpFpkk8Wt");
(204761l, "PsddFKi32cMJ2qPjf43Qv5GDWLDPZb3T3bF6fLKiF5HtvHNU7aP") ]
~user_activated_protocol_overrides:
[ ( "PsBABY5HQTSkA4297zNHfsZNKtxULfL18y95qb3m53QJiXGmrbU",
"PsBabyM1eUXZseaJdmXFApDSBqj8YBfwELoxZHHW77EMcAbbwAS" ) ]
let blockchain_network_alphanet =
make_blockchain_network
......@@ -145,31 +164,43 @@ let blockchain_network_encoding : blockchain_network Data_encoding.t =
chain_name;
old_chain_name;
incompatible_chain_name;
sandboxed_chain_name } ->
sandboxed_chain_name;
user_activated_upgrades;
user_activated_protocol_overrides } ->
( genesis,
chain_name,
old_chain_name,
incompatible_chain_name,
sandboxed_chain_name ))
sandboxed_chain_name,
user_activated_upgrades,
user_activated_protocol_overrides ))
(fun ( genesis,
chain_name,
old_chain_name,
incompatible_chain_name,
sandboxed_chain_name ) ->
sandboxed_chain_name,
user_activated_upgrades,
user_activated_protocol_overrides ) ->
{
genesis;
chain_name;
old_chain_name;
incompatible_chain_name;
sandboxed_chain_name;
user_activated_upgrades;
user_activated_protocol_overrides;
})
(let chain = Distributed_db_version.name_encoding in
obj5
obj7
(req "genesis" State.Chain.genesis_encoding)
(req "chain_name" chain)
(opt "old_chain_name" chain)
(opt "incompatible_chain_name" chain)
(req "sandboxed_chain_name" chain))
(req "sandboxed_chain_name" chain)
(req "user_activated_upgrades" User_activated.upgrades_encoding)
(req
"user_activated_protocol_overrides"
User_activated.protocol_overrides_encoding))
let sugared_blockchain_network_encoding : blockchain_network Data_encoding.t =
let open Data_encoding in
......
......@@ -34,6 +34,8 @@ type blockchain_network = {
old_chain_name : chain_name option;
incompatible_chain_name : chain_name option;
sandboxed_chain_name : chain_name;
user_activated_upgrades : User_activated.upgrades;
user_activated_protocol_overrides : User_activated.protocol_overrides;
}
val blockchain_network_mainnet : blockchain_network
......
......@@ -50,7 +50,7 @@ module Term = struct
Internal_event_unix.init ()
>>= fun () ->
Node_shared_arg.read_and_patch_config_file
~ignore_bootstrap_peers: true
~ignore_bootstrap_peers:true
args
>>=? fun config ->
let data_dir = config.data_dir in
......@@ -72,7 +72,15 @@ module Term = struct
(history_mode = History_mode.Full)
(Snapshots.Cannot_reconstruct history_mode)
>>=? fun () ->
Snapshots.reconstruct chain_id store chain_state context_index
Snapshots.reconstruct
chain_id
~user_activated_upgrades:
config.blockchain_network.user_activated_upgrades
~user_activated_protocol_overrides:
config.blockchain_network.user_activated_protocol_overrides
store
chain_state
context_index
>>=? fun () ->
Store.close store ;
State.close state >>= fun () -> return_unit
......
......@@ -160,6 +160,10 @@ let init_node ?sandbox ?checkpoint ~singleprocess (config : Node_config_file.t)
genesis;
chain_name = config.blockchain_network.chain_name;
sandboxed_chain_name = config.blockchain_network.sandboxed_chain_name;
user_activated_upgrades =
config.blockchain_network.user_activated_upgrades;
user_activated_protocol_overrides =
config.blockchain_network.user_activated_protocol_overrides;
patch_context;
store_root = Node_data_version.store_dir config.data_dir;
context_root = Node_data_version.context_dir config.data_dir;
......
......@@ -111,6 +111,10 @@ module Term = struct
~data_dir
~dir_cleaner
~genesis
~user_activated_upgrades:
node_config.blockchain_network.user_activated_upgrades
~user_activated_protocol_overrides:
node_config.blockchain_network.user_activated_protocol_overrides
snapshot_file
block
in
......
......@@ -58,7 +58,11 @@ let run stdin stdout =
(inconsistent_handshake "bad magic")
>>=? fun () ->
External_validation.recv stdin External_validation.parameters_encoding
>>= fun {context_root; protocol_root; sandbox_parameters} ->
>>= fun { context_root;
protocol_root;
sandbox_parameters;
user_activated_upgrades;
user_activated_protocol_overrides } ->
let genesis_block = ref Block_hash.zero in
let genesis_time = ref Time.Protocol.epoch in
let genesis_protocol = ref Protocol_hash.zero in
......@@ -130,6 +134,8 @@ let run stdin stdout =
>>=? fun () ->
Block_validation.apply
chain_id
~user_activated_upgrades
~user_activated_protocol_overrides
~max_operations_ttl
~predecessor_block_header
~predecessor_context
......@@ -147,6 +153,8 @@ let run stdin stdout =
| Ok () ->
Block_validation.apply
chain_id
~user_activated_upgrades
~user_activated_protocol_overrides
~max_operations_ttl
~predecessor_block_header
~predecessor_context
......
......@@ -159,32 +159,24 @@ let hash block = Block_hash.hash_bytes [to_bytes block]
let hash_raw bytes = Block_hash.hash_bytes [bytes]
let forced_protocol_upgrades : (Int32.t * Protocol_hash.t) list =
[ (* nothing *) ]
let voted_protocol_overrides : (Protocol_hash.t * Protocol_hash.t) list =
List.map
(fun (a, b) ->
(Protocol_hash.of_b58check_exn a, Protocol_hash.of_b58check_exn b))
[ (* nothing *) ]
module LevelMap = Map.Make (struct
type t = Int32.t
let compare = Int32.compare
end)
let get_forced_protocol_upgrade =
let get_forced_protocol_upgrade ~user_activated_upgrades =
let table =
List.fold_left
(fun map (level, hash) -> LevelMap.add level hash map)
LevelMap.empty
forced_protocol_upgrades
user_activated_upgrades
in
fun ~level -> LevelMap.find_opt level table
let get_voted_protocol_overrides proto_hash =
List.assoc_opt proto_hash voted_protocol_overrides
let get_voted_protocol_overrides ~user_activated_protocol_overrides proto_hash
=
List.assoc_opt proto_hash user_activated_protocol_overrides
let () =
Data_encoding.Registration.register shell_header_encoding ;
......
......@@ -60,6 +60,12 @@ val of_b58check : string -> t option
val bounded_encoding : ?max_size:int -> unit -> t Data_encoding.t
val get_forced_protocol_upgrade : level:Int32.t -> Protocol_hash.t option
val get_forced_protocol_upgrade :
user_activated_upgrades:User_activated.upgrades ->
level:Int32.t ->
Protocol_hash.t option
val get_voted_protocol_overrides : Protocol_hash.t -> Protocol_hash.t option
val get_voted_protocol_overrides :
user_activated_protocol_overrides:User_activated.protocol_overrides ->
Protocol_hash.t ->
Protocol_hash.t option
......@@ -43,6 +43,7 @@ end
module Time = Time
module Fitness = Fitness
module User_activated = User_activated
module Block_header = Block_header
module Operation = Operation
module Protocol = Protocol
......
......@@ -67,6 +67,7 @@ end
module Time = Time
module Fitness = Fitness
module User_activated = User_activated
module Block_header = Block_header
module Operation = Operation
module Protocol = Protocol
......
(*****************************************************************************)
(* *)
(* Open Source License *)
(* Copyright (c) 2019 Nomadic Labs, <[email protected]> *)
(* *)
(* Permission is hereby granted, free of charge, to any person obtaining a *)
(* copy of this software and associated documentation files (the "Software"),*)
(* to deal in the Software without restriction, including without limitation *)
(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *)
(* and/or sell copies of the Software, and to permit persons to whom the *)
(* Software is furnished to do so, subject to the following conditions: *)
(* *)
(* The above copyright notice and this permission notice shall be included *)
(* in all copies or substantial portions of the Software. *)
(* *)
(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*)
(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *)
(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *)
(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*)
(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *)
(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *)
(* DEALINGS IN THE SOFTWARE. *)
(* *)
(*****************************************************************************)
type upgrades = (Int32.t * Protocol_hash.t) list
let upgrades_encoding =
let open Data_encoding in
def
"user_activated.upgrades"
~title:"User activated upgrades"
~description:
"User activated upgrades: at given level, switch to given protocol."
(list
(obj2
(req "level" int32)
(req "replacement_protocol" Protocol_hash.encoding)))
type protocol_overrides = (Protocol_hash.t * Protocol_hash.t) list
let protocol_overrides_encoding =
let open Data_encoding in
def
"user_activated.protocol_overrides"
~title:"User activated protocol overrides"
~description:
"User activated protocol overrides: activate a protocol instead of \
another."
@@ list
(obj2
(req "replaced_protocol" Protocol_hash.encoding)
(req "replacement_protocol" Protocol_hash.encoding))
let () =
Data_encoding.Registration.register upgrades_encoding ;
Data_encoding.Registration.register protocol_overrides_encoding
(*****************************************************************************)
(* *)
(* Open Source License *)
(* Copyright (c) 2019 Nomadic Labs, <[email protected]> *)
(* *)
(* Permission is hereby granted, free of charge, to any person obtaining a *)
(* copy of this software and associated documentation files (the "Software"),*)
(* to deal in the Software without restriction, including without limitation *)
(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *)
(* and/or sell copies of the Software, and to permit persons to whom the *)
(* Software is furnished to do so, subject to the following conditions: *)
(* *)
(* The above copyright notice and this permission notice shall be included *)
(* in all copies or substantial portions of the Software. *)
(* *)
(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*)
(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *)
(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *)
(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*)
(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *)
(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *)
(* DEALINGS IN THE SOFTWARE. *)
(* *)
(*****************************************************************************)
(** User activated upgrades: at given level, switch to given protocol. *)
type upgrades = (Int32.t * Protocol_hash.t) list
val upgrades_encoding : upgrades Data_encoding.t
(** User activated protocol overrides.
An override [(a, b)] denotes that if [a] is to be activated at the end
of the promotion phase, [b] shall be activated instead. *)
type protocol_overrides = (Protocol_hash.t * Protocol_hash.t) list
val protocol_overrides_encoding : protocol_overrides Data_encoding.t
......@@ -108,7 +108,8 @@ let build_raw_header_rpc_directory (module Proto : Block_services.PROTO) =
}) ;
!dir
let build_raw_rpc_directory (module Proto : Block_services.PROTO)
let build_raw_rpc_directory ~user_activated_upgrades
~user_activated_protocol_overrides (module Proto : Block_services.PROTO)
(module Next_proto : Registered_protocol.T) =
let dir : State.Block.block RPC_directory.t ref = ref RPC_directory.empty in
let merge d = dir := RPC_directory.merge d !dir in
......@@ -283,6 +284,8 @@ let build_raw_rpc_directory (module Proto : Block_services.PROTO)
p.operations
in
Prevalidation.preapply
~user_activated_upgrades
~user_activated_protocol_overrides
~predecessor:block
~timestamp
~protocol_data
......@@ -349,7 +352,8 @@ let get_protocol hash =
| Some protocol ->
protocol
let get_directory chain_state block =
let get_directory ~user_activated_upgrades ~user_activated_protocol_overrides
chain_state block =
State.Block.get_rpc_directory block
>>= function
| Some dir ->
......@@ -363,6 +367,8 @@ let get_directory chain_state block =
| None ->
Lwt.return
(build_raw_rpc_directory
~user_activated_upgrades
~user_activated_protocol_overrides
(module Block_services.Fake_protocol)
next_protocol)
| Some pred -> (
......@@ -380,7 +386,13 @@ let get_directory chain_state block =
| Some dir ->
Lwt.return dir
| None ->
let dir = build_raw_rpc_directory (module Proto) next_protocol in
let dir =
build_raw_rpc_directory
~user_activated_upgrades
~user_activated_protocol_overrides
(module Proto)
next_protocol
in
State.Block.set_rpc_directory block dir
>>= fun () -> Lwt.return dir ) )
......@@ -478,7 +490,8 @@ let get_block chain_state = function
~below_save_point:true
(State.Block.hash head)
let build_rpc_directory chain_state block =
let build_rpc_directory ~user_activated_upgrades
~user_activated_protocol_overrides chain_state block =
get_block chain_state block
>>= function
| None ->
......@@ -493,7 +506,11 @@ let build_rpc_directory chain_state block =
block_level >= save_point_level
|| Block_hash.equal block_hash genesis.block
then
get_directory chain_state b
get_directory
~user_activated_upgrades
~user_activated_protocol_overrides
chain_state
b
>>= fun dir ->
Lwt.return (RPC_directory.map (fun _ -> Lwt.return b) dir)
else
......
......@@ -27,9 +27,15 @@ val get_block :
State.Chain.t -> Block_services.block -> State.Block.t option Lwt.t
val build_raw_rpc_directory :
user_activated_upgrades:User_activated.upgrades ->
user_activated_protocol_overrides:User_activated.protocol_overrides ->
(module Block_services.PROTO) ->
(module Registered_protocol.T) ->
State.Block.t RPC_directory.directory
val build_rpc_directory :
State.Chain.t -> Block_services.block -> 'a RPC_directory.t Lwt.t
user_activated_upgrades:User_activated.upgrades ->
user_activated_protocol_overrides:User_activated.protocol_overrides ->
State.Chain.t ->
Block_services.block ->
'a RPC_directory.t Lwt.t
......@@ -38,12 +38,24 @@ module Seq_validator = struct
let name = "validation_process.sequential"
end)
type validation_context = {context_index : Context.index}
type validation_context = {
context_index : Context.index;
user_activated_upgrades : User_activated.upgrades;
user_activated_protocol_overrides : User_activated.protocol_overrides;
}
type t = validation_context
let init context_index =
lwt_log_notice "Initialized" >>= fun () -> Lwt.return {context_index}
let init ~user_activated_upgrades ~user_activated_protocol_overrides
context_index =
lwt_log_notice "Initialized"
>>= fun () ->
Lwt.return
{
context_index;
user_activated_upgrades;
user_activated_protocol_overrides;
}
let close _ = lwt_log_notice "Shutting down..."
......@@ -56,6 +68,9 @@ module Seq_validator = struct
>>=? fun predecessor_context ->
Block_validation.apply
chain_id
~user_activated_upgrades:validator_process.user_activated_upgrades
~user_activated_protocol_overrides:
validator_process.user_activated_protocol_overrides
~max_operations_ttl
~predecessor_block_header
~predecessor_context
......@@ -72,6 +87,8 @@ module External_validator = struct
type validation_context = {
context_root : string;
protocol_root : string;
user_activated_upgrades : User_activated.upgrades;
user_activated_protocol_overrides : User_activated.protocol_overrides;
process_path : string;
mutable validator_process : Lwt_process.process_full option;
lock : Lwt_mutex.t;
......@@ -80,13 +97,17 @@ module External_validator = struct
type t = validation_context
let init ?sandbox_parameters ~context_root ~protocol_root ~process_path =
let init ?sandbox_parameters ~context_root ~protocol_root
~user_activated_upgrades ~user_activated_protocol_overrides ~process_path
=
lwt_log_notice (fun f -> f "Initialized")
>>= fun () ->
Lwt.return
{
context_root;
protocol_root;
user_activated_upgrades;
user_activated_protocol_overrides;
process_path;
validator_process = None;
lock = Lwt_mutex.create ();
......@@ -152,6 +173,9 @@ module External_validator = struct
External_validation.context_root = vp.context_root;
protocol_root = vp.protocol_root;
sandbox_parameters = vp.sandbox_parameters;
user_activated_upgrades = vp.user_activated_upgrades;
user_activated_protocol_overrides =
vp.user_activated_protocol_overrides;
}
in
vp.validator_process <- Some process ;
......@@ -220,14 +244,21 @@ type validator_kind =
type t = Sequential of Seq_validator.t | External of External_validator.t
let init = function
let init ~user_activated_upgrades ~user_activated_protocol_overrides kind =
match kind with
| Internal index ->
Seq_validator.init index >>= fun v -> return (Sequential v)
Seq_validator.init
~user_activated_upgrades
~user_activated_protocol_overrides
index
>>= fun v -> return (Sequential v)
| External {context_root; protocol_root; process_path; sandbox_parameters} ->
External_validator.init
?sandbox_parameters
~context_root
~protocol_root
~user_activated_upgrades
~user_activated_protocol_overrides
~process_path
>>= fun v ->
External_validator.send_request
......@@ -288,7 +319,7 @@ let apply_block bvp ~predecessor block_header operations =
let commit_genesis bvp ~genesis_hash ~chain_id ~time ~protocol =
match bvp with
| Sequential {context_index} ->
| Sequential {context_index; _} ->
Context.commit_genesis context_index ~chain_id ~time ~protocol
>>= fun res -> return res
| External vp ->
......
......@@ -35,7 +35,11 @@ type validator_kind =
type t
val init : validator_kind -> t tzresult Lwt.t
val init :
user_activated_upgrades:User_activated.upgrades ->
user_activated_protocol_overrides:User_activated.protocol_overrides ->
validator_kind ->
t tzresult Lwt.t
val close : t -> unit Lwt.t
......
......@@ -117,7 +117,7 @@ let list_blocks chain_state ?(length = 1) ?min_date heads =
requested_heads
>>= fun (_, blocks) -> return (List.rev blocks)
let rpc_directory =
let rpc_directory ~user_activated_upgrades ~user_activated_protocol_overrides =
let dir : State.Chain.t RPC_directory.t ref = ref RPC_directory.empty in
let register0 s f =
dir :=
......@@ -153,7 +153,9 @@ let rpc_directory =
list_blocks chain ?length:q#length ?min_date:q#min_date q#heads) ;
register_dynamic_directory2
Block_services.path
Block_directory.build_rpc_directory ;
(Block_directory.build_rpc_directory
~user_activated_upgrades
~user_activated_protocol_overrides) ;
(* invalid_blocks *)
register0 S.Invalid_blocks.list (fun chain () () ->
let convert (hash, level, errors) = {hash; level; errors} in
......@@ -170,10 +172,16 @@ let rpc_directory =
State.Block.unmark_invalid chain hash) ;
!dir
let build_rpc_directory validator =
let build_rpc_directory ~user_activated_upgrades
~user_activated_protocol_overrides validator =
let distributed_db = Validator.distributed_db validator in
let state = Distributed_db.state distributed_db in
let dir = ref rpc_directory in
let dir =
ref
(rpc_directory
~user_activated_upgrades
~user_activated_protocol_overrides)
in
(* Mempool *)
let merge d = dir := RPC_directory.merge !dir d in
merge
......
......@@ -32,6 +32,13 @@ val get_chain : State.t -> Chain_services.chain -> State.Chain.t Lwt.t
val get_checkpoint : State.t -> Chain_services.chain -> Block_hash.t Lwt.t
val rpc_directory : State.Chain.t RPC_directory.t
val rpc_directory :
user_activated_upgrades:User_activated.upgrades ->
user_activated_protocol_overrides:User_activated.protocol_overrides ->
State.Chain.t RPC_directory.t
val build_rpc_directory : Validator.t -> unit RPC_directory.t
val build_rpc_directory :
user_activated_upgrades:User_activated.upgrades ->
user_activated_protocol_overrides:User_activated.protocol_overrides ->
Validator.t ->
unit RPC_directory.t
(*****************************************************************************)
(* *)
(* Open Source License *)
(* Copyright (c) 2019 Nomadic Labs, <[email protected]> *)
(* *)
(* Permission is hereby granted, free of charge, to any person obtaining a *)
(* copy of this software and associated documentation files (the "Software"),*)
(* to deal in the Software without restriction, including without limitation *)
(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *)
(* and/or sell copies of the Software, and to permit persons to whom the *)
(* Software is furnished to do so, subject to the following conditions: *)
(* *)
(* The above copyright notice and this permission notice shall be included *)
(* in all copies or substantial portions of the Software. *)
(* *)
(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*)
(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *)
(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *)
(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*)