Commit b52389f6 authored by Seb Mondet's avatar Seb Mondet Committed by Seb Mondet

Node: parameterize genesis

parent a2e4b2a5
(*****************************************************************************)
(* *)
(* Open Source License *)
(* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. <[email protected]> *)
(* Copyright (c) 2018-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. *)
(* *)
(*****************************************************************************)
let genesis : State.Chain.genesis =
{
time = Time.Protocol.of_notation_exn "2018-06-30T16:07:32Z";
block =
Block_hash.of_b58check_exn
"BLockGenesisGenesisGenesisGenesisGenesisf79b5d1CoW2";
protocol =
Protocol_hash.of_b58check_exn
"ProtoGenesisGenesisGenesisGenesisGenesisGenesk612im";
}
(*****************************************************************************)
(* *)
(* Open Source License *)
(* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. <[email protected]> *)
(* Copyright (c) 2018-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. *)
(* *)
(*****************************************************************************)
val genesis : State.Chain.genesis
......@@ -38,6 +38,153 @@ let default_p2p_port = 9732
let default_discovery_port = 10732
type chain_name = Distributed_db_version.name
type blockchain_network = {
genesis : State.Chain.genesis;
chain_name : chain_name;
old_chain_name : chain_name option;
incompatible_chain_name : chain_name option;
sandboxed_chain_name : chain_name;
}
let make_blockchain_network ~chain_name ?old_chain_name
?incompatible_chain_name ~sandboxed_chain_name genesis =
let of_string = Distributed_db_version.of_string in
{
genesis;
chain_name = of_string 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;
}
let blockchain_network_mainnet =
make_blockchain_network
State.Chain.
{
time = Time.Protocol.of_notation_exn "2018-06-30T16:07:32Z";
block =
Block_hash.of_b58check_exn
"BLockGenesisGenesisGenesisGenesisGenesisf79b5d1CoW2";
protocol =
Protocol_hash.of_b58check_exn
"Ps9mPmXaRzmzk35gbAYNCAw6UXdE2qoABTHbN2oEEc1qM7CwT9P";
}
~chain_name:"TEZOS_MAINNET"
~old_chain_name:"TEZOS_BETANET_2018-06-30T16:07:32Z"
~incompatible_chain_name:"INCOMPATIBLE"
~sandboxed_chain_name:"SANDBOXED_TEZOS_MAINNET"
let blockchain_network_alphanet =
make_blockchain_network
State.Chain.
{
time = Time.Protocol.of_notation_exn "2018-11-30T15:30:56Z";
block =
Block_hash.of_b58check_exn
"BLockGenesisGenesisGenesisGenesisGenesisb83baZgbyZe";
protocol =
Protocol_hash.of_b58check_exn
"Ps6mwMrF2ER2s51cp9yYpjDcuzQjsc2yAz8bQsRgdaRxw4Fk95H";
}
~chain_name:"TEZOS_ALPHANET_2018-11-30T15:30:56Z"
~old_chain_name:"TEZOS_ALPHANET_2018-11-30T15:30:56Z"
~incompatible_chain_name:"INCOMPATIBLE"
~sandboxed_chain_name:"SANDBOXED_TEZOS_MAINNET"
let blockchain_network_zeronet =
make_blockchain_network
State.Chain.
{
time = Time.Protocol.of_notation_exn "2019-08-06T15:18:56Z";
block =
Block_hash.of_b58check_exn
"BLockGenesisGenesisGenesisGenesisGenesiscde8db4cX94";
protocol =
Protocol_hash.of_b58check_exn
"PtBMwNZT94N7gXKw4i273CKcSaBrrBnqnt3RATExNKr9KNX2USV";
}
~chain_name:"TEZOS_ZERONET_2019-08-06T15:18:56Z"
~sandboxed_chain_name:"SANDBOXED_TEZOS"
let blockchain_network_default =
make_blockchain_network
State.Chain.
{
time = Time.Protocol.of_notation_exn "2018-06-30T16:07:32Z";
block =
Block_hash.of_b58check_exn
"BLockGenesisGenesisGenesisGenesisGenesisf79b5d1CoW2";
protocol =
Protocol_hash.of_b58check_exn
"ProtoGenesisGenesisGenesisGenesisGenesisGenesk612im";
}
~chain_name:"TEZOS"
~sandboxed_chain_name:"SANDBOXED_TEZOS"
let blockchain_network_encoding : blockchain_network Data_encoding.t =
let open Data_encoding in
conv
(fun { genesis;
chain_name;
old_chain_name;
incompatible_chain_name;
sandboxed_chain_name } ->
( genesis,
chain_name,
old_chain_name,
incompatible_chain_name,
sandboxed_chain_name ))
(fun ( genesis,
chain_name,
old_chain_name,
incompatible_chain_name,
sandboxed_chain_name ) ->
{
genesis;
chain_name;
old_chain_name;
incompatible_chain_name;
sandboxed_chain_name;
})
(let chain = Distributed_db_version.name_encoding in
obj5
(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))
let sugared_blockchain_network_encoding : blockchain_network Data_encoding.t =
let open Data_encoding in
union
~tag_size:`Uint8
[ case
(Tag 0)
~title:"Custom"
blockchain_network_encoding
(fun x -> Some x)
(fun x -> x);
case
(Tag 1)
~title:"Zeronet"
(constant "Zeronet")
(fun _ -> None)
(fun () -> blockchain_network_zeronet);
case
(Tag 2)
~title:"Alphanet"
(constant "Alphanet")
(fun _ -> None)
(fun () -> blockchain_network_alphanet);
case
(Tag 3)
~title:"Mainnet"
(constant "Mainnet")
(fun _ -> None)
(fun () -> blockchain_network_mainnet) ]
type t = {
data_dir : string;
p2p : p2p;
......@@ -45,6 +192,7 @@ type t = {
log : Lwt_log_sink_unix.cfg;
internal_events : Internal_event_unix.Configuration.t;
shell : shell;
blockchain_network : blockchain_network;
}
and p2p = {
......@@ -137,6 +285,7 @@ let default_config =
log = Lwt_log_sink_unix.default_cfg;
internal_events = Internal_event_unix.Configuration.default;
shell = default_shell;
blockchain_network = blockchain_network_default;
}
let limit : P2p.limits Data_encoding.t =
......@@ -684,11 +833,11 @@ let shell =
let encoding =
let open Data_encoding in
conv
(fun {data_dir; rpc; p2p; log; internal_events; shell} ->
(data_dir, rpc, p2p, log, internal_events, shell))
(fun (data_dir, rpc, p2p, log, internal_events, shell) ->
{data_dir; rpc; p2p; log; internal_events; shell})
(obj6
(fun {data_dir; rpc; p2p; log; internal_events; shell; blockchain_network} ->
(data_dir, rpc, p2p, log, internal_events, shell, blockchain_network))
(fun (data_dir, rpc, p2p, log, internal_events, shell, blockchain_network) ->
{data_dir; rpc; p2p; log; internal_events; shell; blockchain_network})
(obj7
(dft
"data-dir"
~description:"Location of the data dir on disk."
......@@ -715,7 +864,13 @@ let encoding =
"shell"
~description:"Configuration of network parameters"
shell
default_shell))
default_shell)
(dft
"network"
~description:
"Configuration of which network/blockchain to connect to"
sugared_blockchain_network_encoding
blockchain_network_default))
(* Abstract version of [Json_encoding.Cannot_destruct]: first argument is the
string representation of the path, second argument is the error message
......@@ -844,8 +999,7 @@ let update ?data_dir ?min_connections ?expected_connections ?max_connections
history_mode = Option.first_some history_mode cfg.shell.history_mode;
}
in
let internal_events = cfg.internal_events in
return {data_dir; p2p; rpc; log; internal_events; shell}
return {cfg with data_dir; p2p; rpc; log; shell}
let resolve_addr ~default_addr ?default_port ?(passive = false) peer =
let (addr, port) = P2p_point.Id.parse_addr_port peer in
......
......@@ -26,6 +26,24 @@
[@@@ocaml.warning "-30"]
type chain_name = Distributed_db_version.name
type blockchain_network = {
genesis : State.Chain.genesis;
chain_name : chain_name;
old_chain_name : chain_name option;
incompatible_chain_name : chain_name option;
sandboxed_chain_name : chain_name;
}
val blockchain_network_mainnet : blockchain_network
val blockchain_network_alphanet : blockchain_network
val blockchain_network_zeronet : blockchain_network
val blockchain_network_default : blockchain_network
type t = {
data_dir : string;
p2p : p2p;
......@@ -33,6 +51,7 @@ type t = {
log : Lwt_log_sink_unix.cfg;
internal_events : Internal_event_unix.Configuration.t;
shell : shell;
blockchain_network : blockchain_network;
}
and p2p = {
......
......@@ -49,8 +49,11 @@ module Term = struct
let run =
Internal_event_unix.init ()
>>= fun () ->
Node_shared_arg.read_data_dir args
>>=? fun data_dir ->
Node_shared_arg.read_and_patch_config_file
~ignore_bootstrap_peers: true
args
>>=? fun config ->
let data_dir = config.data_dir in
Node_data_version.ensure_data_dir data_dir
>>=? fun () ->
Lwt_lock_file.is_locked (Node_data_version.lock_file data_dir)
......@@ -61,7 +64,7 @@ module Term = struct
let store_root = Node_data_version.store_dir data_dir in
Store.init ~mapsize:40_960_000_000L store_root
>>=? fun store ->
let genesis = Genesis_chain.genesis in
let genesis = config.blockchain_network.genesis in
State.init ~context_root ~store_root genesis
>>=? fun (state, chain_state, context_index, history_mode) ->
let chain_id = Chain_id.of_block_hash genesis.State.Chain.block in
......
......@@ -25,7 +25,6 @@
(*****************************************************************************)
open Node_logging
open Genesis_chain
type error += Non_private_sandbox of P2p_addr.t
......@@ -152,7 +151,10 @@ let init_node ?sandbox ?checkpoint ~singleprocess (config : Node_config_file.t)
return_some ("sandbox_parameter", json))
sandbox
>>=? fun sandbox_param ->
let patch_context = Some (Patch_context.patch_context sandbox_param) in
let genesis = config.blockchain_network.genesis in
let patch_context =
Some (Patch_context.patch_context genesis sandbox_param)
in
let node_config : Node.config =
{
genesis;
......
......@@ -62,9 +62,10 @@ module Term = struct
let run =
Internal_event_unix.init ()
>>= fun () ->
Node_shared_arg.read_data_dir args
>>=? fun data_dir ->
let genesis = Genesis_chain.genesis in
Node_shared_arg.read_and_patch_config_file args
>>=? fun node_config ->
let data_dir = node_config.data_dir in
let genesis = node_config.blockchain_network.genesis in
match subcommand with
| Export ->
Node_data_version.ensure_data_dir data_dir
......@@ -101,7 +102,9 @@ module Term = struct
return_some ("sandbox_parameter", json))
sandbox_file
>>=? fun sandbox_parameters ->
let patch_context = Patch_context.patch_context sandbox_parameters in
let patch_context =
Patch_context.patch_context genesis sandbox_parameters
in
Snapshots.import
~reconstruct
~patch_context
......
......@@ -24,9 +24,7 @@
(* *)
(*****************************************************************************)
open Genesis_chain
let patch_context key_json ctxt =
let patch_context (genesis : State.Chain.genesis) key_json ctxt =
( match key_json with
| None ->
Lwt.return ctxt
......
......@@ -25,4 +25,7 @@
(*****************************************************************************)
val patch_context :
(string * Data_encoding.json) option -> Context.t -> Context.t Lwt.t
State.Chain.genesis ->
(string * Data_encoding.json) option ->
Context.t ->
Context.t Lwt.t
......@@ -28,6 +28,8 @@
type name = string
let of_string x = x
let pp_name = Format.pp_print_string
let name_encoding =
......
......@@ -28,6 +28,8 @@
type name = private string
val of_string : string -> name
val pp_name : Format.formatter -> name -> unit
val name_encoding : name Data_encoding.t
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment