Commit 29b04943 authored by Romain's avatar Romain Committed by Seb Mondet

Genesis: add proto_genesis_carthagenet

parent 29452a1c
......@@ -43,7 +43,7 @@ endif
cp _build/default/src/proto_$$p/lib_parameters/sandbox-parameters.json sandbox-parameters.json ; \
done
PROTOCOLS := genesis genesis_babylonnet genesis_alphanet alpha demo_noops 000_Ps9mPmXa 001_PtCJ7pwo 002_PsYLVpVv 003_PsddFKi3 004_Pt24m4xi 005_PsBABY5H 005_PsBabyM1
PROTOCOLS := genesis genesis_alphanet genesis_babylonnet genesis_carthagenet alpha demo_noops 000_Ps9mPmXa 001_PtCJ7pwo 002_PsYLVpVv 003_PsddFKi3 004_Pt24m4xi 005_PsBABY5H 005_PsBabyM1
DUNE_INCS=$(patsubst %,src/proto_%/lib_protocol/dune.inc, ${PROTOCOLS})
generate_dune: ${DUNE_INCS}
......
......@@ -9,8 +9,9 @@
tezos-client-commands
tezos-client-genesis
tezos-client-genesis-babylonnet
tezos-client-genesis-alphanet
tezos-client-genesis-babylonnet
tezos-client-genesis-carthagenet
tezos-client-alpha
tezos-client-000-Ps9mPmXa
tezos-client-001-PtCJ7pwo
......
......@@ -11,11 +11,12 @@ depends: [
"dune" { >= "1.7" }
"tezos-base"
"tezos-client-base"
"tezos-client-genesis"
"tezos-client-genesis"
"tezos-client-genesis-babylonnet"
"tezos-client-genesis-alphanet"
"tezos-client-genesis-babylonnet"
"tezos-client-genesis-carthagenet"
"tezos-client-alpha"
"tezos-client-000-Ps9mPmXa"
"tezos-client-001-PtCJ7pwo"
......
......@@ -13,8 +13,9 @@
tezos-shell-context
tezos-protocol-updater
tezos-embedded-protocol-genesis
tezos-embedded-protocol-genesis-babylonnet
tezos-embedded-protocol-genesis-alphanet
tezos-embedded-protocol-genesis-babylonnet
tezos-embedded-protocol-genesis-carthagenet
tezos-embedded-protocol-demo-noops
tezos-embedded-protocol-alpha
tezos-embedded-protocol-000-Ps9mPmXa
......
......@@ -17,8 +17,9 @@ depends: [
"tezos-protocol-updater"
"tezos-validator"
"tezos-embedded-protocol-genesis"
"tezos-embedded-protocol-genesis-babylonnet"
"tezos-embedded-protocol-genesis-alphanet"
"tezos-embedded-protocol-genesis-babylonnet"
"tezos-embedded-protocol-genesis-carthagenet"
"tezos-embedded-protocol-demo-noops"
"tezos-embedded-protocol-alpha"
"tezos-embedded-protocol-demo-noops"
......
wrap-fun-args=false
let-binding-spacing=compact
field-space=loose
break-separators=after-and-docked
sequence-style=separator
doc-comments=before
margin=80
module-item-spacing=sparse
parens-tuple=always
parens-tuple-patterns=always
break-string-literals=newlines-and-wrap
(*****************************************************************************)
(* *)
(* Open Source License *)
(* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. <[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. *)
(* *)
(*****************************************************************************)
open Protocol
open Protocol_client_context
let protocol =
Protocol_hash.of_b58check_exn
"PtYuensgYBb3G3x1hLLbCmcav8ue8Kyd2khADcL5LsT5R1hcXex"
let bake cctxt ?timestamp block command sk =
let timestamp =
match timestamp with
| Some t ->
t
| None ->
Time.System.(to_protocol (Tezos_stdlib_unix.Systime_os.now ()))
in
let protocol_data = {command; signature = Signature.zero} in
Genesis_block_services.Helpers.Preapply.block
cctxt
~block
~timestamp
~protocol_data
[]
>>=? fun (shell_header, _) ->
let blk = Data.Command.forge shell_header command in
Shell_services.Chain.chain_id cctxt ~chain:`Main ()
>>=? fun chain_id ->
Client_keys.append cctxt sk ~watermark:(Block_header chain_id) blk
>>=? fun signed_blk -> Shell_services.Injection.block cctxt signed_blk []
let int64_parameter =
Clic.parameter (fun _ p ->
try return (Int64.of_string p) with _ -> failwith "Cannot read int64")
let file_parameter =
Clic.parameter (fun _ p ->
if not (Sys.file_exists p) then failwith "File doesn't exist: '%s'" p
else return p)
let fitness_from_int64 fitness =
(* definition taken from src/proto_alpha/lib_protocol/src/constants_repr.ml *)
let version_number = "\000" in
(* definitions taken from src/proto_alpha/lib_protocol/src/fitness_repr.ml *)
let int64_to_bytes i =
let b = Bytes.create 8 in
TzEndian.set_int64 b 0 i ; b
in
[Bytes.of_string version_number; int64_to_bytes fitness]
let timestamp_arg =
Clic.arg
~long:"timestamp"
~placeholder:"date"
~doc:"Set the timestamp of the block (and initial time of the chain)"
(Clic.parameter (fun _ t ->
match Time.System.of_notation_opt t with
| None ->
Error_monad.failwith
"Could not parse value provided to -timestamp option"
| Some t ->
return t))
let test_delay_arg =
Clic.default_arg
~long:"delay"
~placeholder:"time"
~doc:"Set the life span of the test chain (in seconds)"
~default:(Int64.to_string (Int64.mul 24L 3600L))
(Clic.parameter (fun _ t ->
match Int64.of_string_opt t with
| None ->
Error_monad.failwith
"Could not parse value provided to -delay option"
| Some t ->
return t))
let proto_param ~name ~desc t =
Clic.param
~name
~desc
(Clic.parameter (fun _ str -> Lwt.return (Protocol_hash.of_b58check str)))
t
let commands () =
let open Clic in
let args =
args1
(arg
~long:"timestamp"
~placeholder:"date"
~doc:"Set the timestamp of the block (and initial time of the chain)"
(parameter (fun _ t ->
match Time.Protocol.of_notation t with
| None ->
Error_monad.failwith
"Could not parse value provided to -timestamp option"
| Some t ->
return t)))
in
[ command
~desc:"Activate a protocol"
args
( prefixes ["activate"; "protocol"]
@@ proto_param ~name:"version" ~desc:"Protocol version (b58check)"
@@ prefixes ["with"; "fitness"]
@@ param
~name:"fitness"
~desc:"Hardcoded fitness of the first block (integer)"
int64_parameter
@@ prefixes ["and"; "key"]
@@ Client_keys.Secret_key.source_param
~name:"password"
~desc:"Activator's key"
@@ prefixes ["and"; "parameters"]
@@ param
~name:"parameters"
~desc:"Protocol parameters (as JSON file)"
file_parameter
@@ stop )
(fun timestamp
hash
fitness
sk
param_json_file
(cctxt : Client_context.full) ->
let fitness = fitness_from_int64 fitness in
Tezos_stdlib_unix.Lwt_utils_unix.Json.read_file param_json_file
>>=? fun json ->
let protocol_parameters =
Data_encoding.Binary.to_bytes_exn Data_encoding.json json
in
bake
cctxt
?timestamp
cctxt#block
(Activate {protocol = hash; fitness; protocol_parameters})
sk
>>=? fun hash ->
cctxt#answer "Injected %a" Block_hash.pp_short hash
>>= fun () -> return_unit);
command
~desc:"Fork a test protocol"
(args2 timestamp_arg test_delay_arg)
( prefixes ["fork"; "test"; "protocol"]
@@ proto_param ~name:"version" ~desc:"Protocol version (b58check)"
@@ prefixes ["with"; "fitness"]
@@ param
~name:"fitness"
~desc:
"Hardcoded fitness of the first block of the testchain (integer)"
int64_parameter
@@ prefixes ["and"; "key"]
@@ Client_keys.Secret_key.source_param
~name:"password"
~desc:"Activator's key"
@@ prefixes ["and"; "parameters"]
@@ param
~name:"parameters"
~desc:"Testchain protocol parameters (as JSON file)"
file_parameter
@@ stop )
(fun (timestamp, delay) hash fitness sk param_json_file cctxt ->
let fitness = fitness_from_int64 fitness in
Tezos_stdlib_unix.Lwt_utils_unix.Json.read_file param_json_file
>>=? fun json ->
let protocol_parameters =
Data_encoding.Binary.to_bytes_exn Data_encoding.json json
in
let timestamp = Option.map ~f:Time.System.to_protocol timestamp in
bake
cctxt
?timestamp
cctxt#block
(Activate_testchain
{protocol = hash; fitness; protocol_parameters; delay})
sk
>>=? fun hash ->
cctxt#answer "Injected %a" Block_hash.pp_short hash
>>= fun () -> return_unit) ]
let () = Client_commands.register protocol @@ fun _network -> commands ()
(*****************************************************************************)
(* *)
(* Open Source License *)
(* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. <[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. *)
(* *)
(*****************************************************************************)
open Protocol
val bake :
#Client_context.full ->
?timestamp:Time.Protocol.t ->
Shell_services.block ->
Data.Command.t ->
Client_keys.sk_uri ->
Block_hash.t tzresult Lwt.t
(library
(name tezos_client_genesis_carthagenet)
(public_name tezos-client-genesis-carthagenet)
(libraries tezos-base
tezos-shell-services
tezos-client-base
tezos-client-commands
tezos-protocol-environment
tezos-protocol-genesis-carthagenet
tezos-stdlib-unix)
(library_flags (:standard -linkall))
(flags (:standard -open Tezos_base__TzPervasives
-open Tezos_shell_services
-open Tezos_client_base
-open Tezos_protocol_genesis_carthagenet
-open Tezos_client_commands)))
(alias
(name runtest_lint)
(deps (glob_files *.ml{,i}))
(action (run %{libexec:tezos-tooling:lint.sh} %{deps})))
(*****************************************************************************)
(* *)
(* Open Source License *)
(* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. <[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. *)
(* *)
(*****************************************************************************)
module Genesis_block_services = Block_services.Make (Protocol) (Protocol)
opam-version: "2.0"
maintainer: "[email protected]"
authors: [ "Tezos devteam" ]
homepage: "https://www.tezos.com/"
bug-reports: "https://gitlab.com/tezos/tezos/issues"
dev-repo: "git+https://gitlab.com/tezos/tezos.git"
license: "MIT"
depends: [
"tezos-tooling" { with-test }
"ocamlfind" { build }
"dune" { >= "1.7" }
"tezos-base"
"tezos-shell-services"
"tezos-client-base"
"tezos-client-commands"
"tezos-protocol-environment"
"tezos-protocol-genesis-carthagenet"
]
build: [
["dune" "build" "-p" name "-j" jobs]
["dune" "runtest" "-p" name "-j" jobs] {with-test}
]
synopsis: "Tezos/Protocol: genesis (protocol-specific commands for `tezos-client`)"
wrap-fun-args=false
let-binding-spacing=compact
field-space=loose
break-separators=after-and-docked
sequence-style=separator
doc-comments=before
margin=80
module-item-spacing=sparse
parens-tuple=always
parens-tuple-patterns=always
break-string-literals=newlines-and-wrap
{
"hash": "PtYuensgYBb3G3x1hLLbCmcav8ue8Kyd2khADcL5LsT5R1hcXex",
"modules": ["Data", "Services", "Main"]
}
(*****************************************************************************)
(* *)
(* Open Source License *)
(* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. <[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. *)
(* *)
(*****************************************************************************)
module Command = struct
type t =
(* Activate a protocol *)
| Activate of {
protocol: Protocol_hash.t ;
fitness: Fitness.t ;
protocol_parameters : MBytes.t ;
}
(* Activate a protocol as a testchain *)
| Activate_testchain of {
protocol: Protocol_hash.t ;
fitness: Fitness.t ;
protocol_parameters : MBytes.t ;
delay: Int64.t ;
}
let mk_case name args =
let open Data_encoding in
conv
(fun o -> ((), o))
(fun ((), o) -> o)
(merge_objs
(obj1 (req "command" (constant name)))
args)
let encoding =
let open Data_encoding in
union ~tag_size:`Uint8 [
case (Tag 0)
~title:"Activate"
(mk_case "activate"
(obj3
(req "hash" Protocol_hash.encoding)
(req "fitness" Fitness.encoding)
(req "protocol_parameters" Variable.bytes)
))
(function
| Activate { protocol ; fitness ; protocol_parameters} ->
Some (protocol, fitness, protocol_parameters)
| _ -> None)
(fun (protocol, fitness, protocol_parameters) ->
Activate { protocol ; fitness ; protocol_parameters }) ;
case (Tag 1)
~title:"Activate_testchain"
(mk_case "activate_testchain"
(obj4
(req "hash" Protocol_hash.encoding)
(req "fitness" Fitness.encoding)
(req "protocol_parameters" Variable.bytes)
(req "validity_time" int64)))
(function
| Activate_testchain { protocol ; fitness ; protocol_parameters ; delay } ->
Some (protocol, fitness, protocol_parameters, delay)
| _ -> None)
(fun (protocol, fitness, protocol_parameters, delay) ->
Activate_testchain { protocol ; fitness ; protocol_parameters ; delay }) ;
]
let signed_encoding =
let open Data_encoding in
obj2
(req "content" encoding)
(req "signature" Signature.encoding)
let forge shell command =
Data_encoding.Binary.to_bytes_exn
(Data_encoding.tup2 Block_header.shell_header_encoding encoding)
(shell, command)
end
module Pubkey = struct
let pubkey_key = ["genesis_key"]
let default =
Signature.Public_key.of_b58check_exn
"edpktiJknwZ8rQkkZdQUBVmG8Goau6C6JBTMX1hohxMGsQAG1qfFze"
let get_pubkey ctxt =
Context.get ctxt pubkey_key >>= function
| None -> Lwt.return default
| Some b ->
match Data_encoding.Binary.of_bytes Signature.Public_key.encoding b with
| None -> Lwt.return default
| Some pk -> Lwt.return pk
let set_pubkey ctxt v =
Context.set ctxt pubkey_key @@
Data_encoding.Binary.to_bytes_exn Signature.Public_key.encoding v
let sandbox_encoding =
let open Data_encoding in
merge_objs
(obj1 (req "genesis_pubkey" Signature.Public_key.encoding))
Data_encoding.unit
let may_change_default ctxt json =
match Data_encoding.Json.destruct sandbox_encoding json with
| exception _ ->
Lwt.return ctxt
| (pubkey, ()) ->
set_pubkey ctxt pubkey >>= fun ctxt ->
Lwt.return ctxt
end
module Init = struct
type error += Incompatible_protocol_version
let version_key = ["version"]
(* This key should always be populated for every version of the
protocol. It's absence meaning that the context is empty. *)
let version_value = "genesis"
let check_inited ctxt =
Context.get ctxt version_key >>= function
| None -> failwith "Internal error: uninitialized context."
| Some version ->
if Compare.String.(version_value <> MBytes.to_string version) then
failwith "Internal error: incompatible protocol version" ;
return_unit
let tag_first_block ctxt =
Context.get ctxt version_key >>= function
| None ->
Context.set
ctxt version_key (MBytes.of_string version_value) >>= fun ctxt ->
return ctxt
| Some _version ->
failwith "Internal error: previously initialized context." ;
end
;; -*- mode: dune; -*-
(include dune.inc)
(rule
(targets "dune.inc.gen")
(deps TEZOS_PROTOCOL (glob_files *.ml) (glob_files *.mli))
(action
(run
%{libexec:tezos-protocol-compiler:replace}
%{libexec:tezos-protocol-compiler:dune_protocol.template}
"dune.inc.gen")))
(alias
(name runtest_dune_template)
(action (diff dune.inc dune.inc.gen)))
(alias
(name runtest)
(deps (alias runtest_dune_template)))
;
; /!\ /!\ Do not modify this file /!\ /!\
;
; but the original template in `tezos-protocol-compiler`
;
(rule
(targets environment.ml)
(action
(write-file %{targets}
"module Name = struct let name = \"genesis-carthagenet\" end
include Tezos_protocol_environment.MakeV1(Name)()
module CamlinternalFormatBasics = struct include CamlinternalFormatBasics end
")))
(rule
(targets registerer.ml)
(deps data.ml services.ml main.mli main.ml
(:src_dir TEZOS_PROTOCOL))
(action
(with-stdout-to %{targets}
(chdir %{workspace_root} (run %{bin:tezos-embedded-protocol-packer} "%{src_dir}" "genesis_carthagenet")))))
(rule
(targets functor.ml)
(deps data.ml services.ml main.mli main.ml
(:src_dir TEZOS_PROTOCOL))
(action (with-stdout-to %{targets}
(chdir %{workspace_root}
(run %{bin:tezos-protocol-compiler.tezos-protocol-packer} %{src_dir})))))
(rule
(targets protocol.ml)
(deps data.ml services.ml main.mli main.ml)
(action
(write-file %{targets}
"module Environment = Tezos_protocol_environment_genesis_carthagenet.Environment
let hash = Tezos_crypto.Protocol_hash.of_b58check_exn \"PtYuensgYBb3G3x1hLLbCmcav8ue8Kyd2khADcL5LsT5R1hcXex\"
let name = Environment.Name.name
include Tezos_raw_protocol_genesis_carthagenet
include Tezos_raw_protocol_genesis_carthagenet.Main
")))
(library
(name tezos_protocol_environment_genesis_carthagenet)
(public_name tezos-protocol-genesis-carthagenet.environment)
(library_flags (:standard -linkall))
(libraries tezos-protocol-environment)
(modules Environment))