From 91dfb730bfbb6d0a691a4cef17633fe26dfdde3e Mon Sep 17 00:00:00 2001 From: Vincent Botbol Date: Wed, 4 Apr 2018 16:20:03 +0200 Subject: [PATCH] Alpha: parametrize protocol activation with commitments and bootstrap accounts --- scripts/protocol_parameters.json | 20 +++++++ src/bin_client/test/jbuild | 2 + src/bin_client/test/protocol_parameters.json | 22 +++++++ src/bin_client/test/test_injection.sh | 3 +- src/bin_client/test/test_lib.inc.sh | 1 + src/bin_client/test/test_utils.sh | 2 +- src/bin_client/tezos-init-sandboxed-client.sh | 24 +++++++- .../lib_baking/test/proto_alpha_helpers.ml | 33 ++++++++++- .../lib_client/client_proto_programs.ml | 15 ++++- .../lib_client/client_proto_programs.mli | 2 + .../lib_protocol/src/TEZOS_PROTOCOL | 1 + .../lib_protocol/src/alpha_context.ml | 1 - .../lib_protocol/src/alpha_context.mli | 9 --- .../lib_protocol/src/bootstrap_storage.ml | 40 +++---------- .../lib_protocol/src/bootstrap_storage.mli | 14 ++--- .../lib_protocol/src/commitment_repr.ml | 7 +-- .../lib_protocol/src/commitment_storage.ml | 33 ++--------- .../lib_protocol/src/commitment_storage.mli | 4 +- .../lib_protocol/src/constants_repr.ml | 23 +------- .../lib_protocol/src/helpers_services.ml | 16 ++--- .../lib_protocol/src/helpers_services.mli | 4 +- .../lib_protocol/src/init_storage.ml | 6 +- .../lib_protocol/src/parameters_repr.ml | 40 +++++++++++++ .../lib_protocol/src/parameters_repr.mli | 20 +++++++ .../lib_protocol/src/raw_context.ml | 26 ++++++++- .../lib_protocol/src/raw_context.mli | 2 +- .../lib_protocol/test/helpers/helpers_init.ml | 58 +++++++++++++++---- .../lib_protocol/test/sandbox.json | 16 ----- src/proto_demo/lib_protocol/src/main.ml | 3 +- .../lib_client/client_proto_main.ml | 17 +++++- src/proto_genesis/lib_protocol/src/data.ml | 12 ++-- src/proto_genesis/lib_protocol/src/main.ml | 10 ++-- 32 files changed, 313 insertions(+), 173 deletions(-) create mode 100644 scripts/protocol_parameters.json create mode 100644 src/bin_client/test/protocol_parameters.json create mode 100644 src/proto_alpha/lib_protocol/src/parameters_repr.ml create mode 100644 src/proto_alpha/lib_protocol/src/parameters_repr.mli diff --git a/scripts/protocol_parameters.json b/scripts/protocol_parameters.json new file mode 100644 index 000000000..ab136dde2 --- /dev/null +++ b/scripts/protocol_parameters.json @@ -0,0 +1,20 @@ +{ "bootstrap_accounts": [ + [ "edpkuBknW28nW72KG6RoHtYW7p12T6GKc7nAbwYX5m8Wd9sDVC9yav", "4000000000000" ], + [ "edpktzNbDAUjUk697W7gYg2CRuBQjyPxbEg8dLccYYwKSKvkPvjtV9", "4000000000000" ], + [ "edpkuTXkJDGcFd5nh6VvMz8phXxU3Bi7h6hqgywNFi1vZTfQNnS1RV", "4000000000000" ], + [ "edpkuFrRoDSEbJYgxRtLx2ps82UdaYc1WwfS9sE11yhauZt5DgCHbU", "4000000000000" ], + [ "edpkv8EUUH68jmo3f7Um5PezmfGrRF24gnfLpH3sVNwJnV5bVCxL2n", "4000000000000" ] + ], + "commitments": [ + [ "tz1fkmDXEQdua3u71JBVh4eGUGqK4t1G8xhZ", "btz1T77Ly5U1bWNBR5KzDSgNFST5Bh5F1eB6g", "1868898542104130027" ], + [ "tz1doNkK6RKaRswsuKJV4erT6HauYSm9fuHi", "btz1QxTPgszARgWioEor3eMehxW3osfhw3KoJ", "517697389496079974" ], + [ "tz1g6zFsci4YR8p1MJrkyc6wAKizR6mqJmyQ", "btz1NUYc1tV5VBksMNuQG4AuZF9Xudh1sDJni", "962290491831710023" ], + [ "tz1MpbcwGFWVBBWoxwm6iQH5Hzh9mCXbnETJ", "btz1Wwifd8vbQqnbuzSbQLvJEjQ9FUoxVJm68", "1233665184704419921" ], + [ "tz1U4t2PmX5cZVUui4BNaiRVokLa6AxB5G9Z", "btz1RrFkp9GmnypoNGRSyURkBQNUs4PPYG8SR", "131959324067470008" ], + [ "tz1RUxPjviua4XJM78XjSKGUCAS9R3y8Bdof", "btz1hozabzP9HdRakJddzyea7DgPHzJ5PB37N", "112378240876120002" ], + [ "tz1fJPeueQKJrTj2SFV2PmyCinLYJKXCEMf4", "btz1j1k4nrZB4r8RpTYiy8zbi3Fappopkb8ZF", "1060667014046690017" ], + [ "tz1iDPZLxcGf5CqCNpTuuMdtu3zKpJ6HvvFR", "btz1TaSfoSNhFoqwqbPC9iC19rN24KJtB7skD", "71300478465380003" ], + [ "tz1i2kbtVu65dP739qLGRpJNujRM8pdpkH3p", "btz1USqQRuvASPXwseXkGTWeWv4dn3VwMVPEk", "283380756728119992" ], + [ "tz1LKGCg6ESJLDviHkT8Jc7tUwjw4h3d9MaF", "btz1YwCKMbBLRL1qkBjAHGCwjbWDqiTAEFpbw", "1357762577679880028" ] + ] +} diff --git a/src/bin_client/test/jbuild b/src/bin_client/test/jbuild index 82f8bd7ad..591d31532 100644 --- a/src/bin_client/test/jbuild +++ b/src/bin_client/test/jbuild @@ -3,6 +3,7 @@ (alias ((name runtest_basic.sh) (deps (sandbox.json + protocol_parameters.json test_lib.inc.sh (glob_files contracts/*) )) @@ -55,6 +56,7 @@ (locks (/tcp-port/18731 /tcp-port/19731)) (deps (sandbox.json + protocol_parameters.json test_lib.inc.sh (glob_files demo/*) )) diff --git a/src/bin_client/test/protocol_parameters.json b/src/bin_client/test/protocol_parameters.json new file mode 100644 index 000000000..3bf19a7bc --- /dev/null +++ b/src/bin_client/test/protocol_parameters.json @@ -0,0 +1,22 @@ +{ "bootstrap_accounts": + [ + [ "edpkuBknW28nW72KG6RoHtYW7p12T6GKc7nAbwYX5m8Wd9sDVC9yav", "4000000000000" ], + [ "edpktzNbDAUjUk697W7gYg2CRuBQjyPxbEg8dLccYYwKSKvkPvjtV9", "4000000000000" ], + [ "edpkuTXkJDGcFd5nh6VvMz8phXxU3Bi7h6hqgywNFi1vZTfQNnS1RV", "4000000000000" ], + [ "edpkuFrRoDSEbJYgxRtLx2ps82UdaYc1WwfS9sE11yhauZt5DgCHbU", "4000000000000" ], + [ "edpkv8EUUH68jmo3f7Um5PezmfGrRF24gnfLpH3sVNwJnV5bVCxL2n", "4000000000000" ] + ], + "commitments": + [ + [ "tz1fkmDXEQdua3u71JBVh4eGUGqK4t1G8xhZ", "btz1T77Ly5U1bWNBR5KzDSgNFST5Bh5F1eB6g", "1868898542104130027" ], + [ "tz1doNkK6RKaRswsuKJV4erT6HauYSm9fuHi", "btz1QxTPgszARgWioEor3eMehxW3osfhw3KoJ", "517697389496079974" ], + [ "tz1g6zFsci4YR8p1MJrkyc6wAKizR6mqJmyQ", "btz1NUYc1tV5VBksMNuQG4AuZF9Xudh1sDJni", "962290491831710023" ], + [ "tz1MpbcwGFWVBBWoxwm6iQH5Hzh9mCXbnETJ", "btz1Wwifd8vbQqnbuzSbQLvJEjQ9FUoxVJm68", "1233665184704419921" ], + [ "tz1U4t2PmX5cZVUui4BNaiRVokLa6AxB5G9Z", "btz1RrFkp9GmnypoNGRSyURkBQNUs4PPYG8SR", "131959324067470008" ], + [ "tz1RUxPjviua4XJM78XjSKGUCAS9R3y8Bdof", "btz1hozabzP9HdRakJddzyea7DgPHzJ5PB37N", "112378240876120002" ], + [ "tz1fJPeueQKJrTj2SFV2PmyCinLYJKXCEMf4", "btz1j1k4nrZB4r8RpTYiy8zbi3Fappopkb8ZF", "1060667014046690017" ], + [ "tz1iDPZLxcGf5CqCNpTuuMdtu3zKpJ6HvvFR", "btz1TaSfoSNhFoqwqbPC9iC19rN24KJtB7skD", "71300478465380003" ], + [ "tz1i2kbtVu65dP739qLGRpJNujRM8pdpkH3p", "btz1USqQRuvASPXwseXkGTWeWv4dn3VwMVPEk", "283380756728119992" ], + [ "tz1LKGCg6ESJLDviHkT8Jc7tUwjw4h3d9MaF", "btz1YwCKMbBLRL1qkBjAHGCwjbWDqiTAEFpbw", "1357762577679880028" ] + ] +} diff --git a/src/bin_client/test/test_injection.sh b/src/bin_client/test/test_injection.sh index cb1f7c12c..a77b26071 100755 --- a/src/bin_client/test/test_injection.sh +++ b/src/bin_client/test/test_injection.sh @@ -18,7 +18,7 @@ protocol_version="PsxS1brZfzzXCiFwirbMtQr4X5XR6SiHQ46HajpFDdk9GBXR6vy" $admin_client inject protocol "$test_dir/demo" $admin_client list protocols -$client activate protocol $protocol_version with fitness 1 and key dictator +$client activate protocol $protocol_version with fitness 1 and key dictator and parameters $parameters_file answ=$($client -p ProtoALphaALph rpc call /blocks/head/protocol with {} 2>/dev/null) if ! grep "$protocol_version" <<< $answ ; then @@ -28,4 +28,3 @@ fi echo echo End of test echo - diff --git a/src/bin_client/test/test_lib.inc.sh b/src/bin_client/test/test_lib.inc.sh index 913a5713a..5549a4491 100755 --- a/src/bin_client/test/test_lib.inc.sh +++ b/src/bin_client/test/test_lib.inc.sh @@ -5,6 +5,7 @@ src_dir="$(dirname "$test_dir")" cd "$test_dir" sandbox_file="$test_dir/sandbox.json" +parameters_file="$test_dir/protocol_parameters.json" tezos_sandboxed_node="${1:-$test_dir/../../bin_node/tezos-sandboxed-node.sh}" local_node="${2:-$test_dir/../../../_build/default/src/bin_node/main.exe}" diff --git a/src/bin_client/test/test_utils.sh b/src/bin_client/test/test_utils.sh index 472aae619..a335b3f7c 100755 --- a/src/bin_client/test/test_utils.sh +++ b/src/bin_client/test/test_utils.sh @@ -81,6 +81,7 @@ activate_alpha() { protocol ProtoALphaALphaALphaALphaALphaALphaALphaALphaDdp3zK \ with fitness 1 \ and key edsk31vznjHSSpGExDMHYASz45VZqXN4DPxvsa4hAyY8dHM28cZzp6 \ + and parameters protocol_parameters.json > /dev/stderr } @@ -230,4 +231,3 @@ alias tezos-sandbox-stop="kill -9 ${node_pid}; sleep 1; rm -rf ${CLEANUP_DIRS[@] EOF } - diff --git a/src/bin_client/tezos-init-sandboxed-client.sh b/src/bin_client/tezos-init-sandboxed-client.sh index b4b178bf7..93b744e81 100755 --- a/src/bin_client/tezos-init-sandboxed-client.sh +++ b/src/bin_client/tezos-init-sandboxed-client.sh @@ -15,6 +15,23 @@ init_sandboxed_client() { client="$local_client -base-dir $client_dir -addr 127.0.0.1 -port $rpc" admin_client="$local_admin_client -base-dir $client_dir -addr 127.0.0.1 -port $rpc" alpha_baker="$local_alpha_baker -base-dir $client_dir -addr 127.0.0.1 -port $rpc" + parameters_file="${parameters_file:-$client_dir/protocol_parameters.json}" + + if ! [ -f "$parameters_file" ]; then + cat > "$parameters_file" </dev/null 2>&1 ; then tezos-client-reset; fi ; PATH="$client_dir/bin:\$PATH" ; export PATH ; -alias tezos-activate-alpha="$client -block genesis activate protocol ProtoALphaALphaALphaALphaALphaALphaALphaALphaDdp3zK with fitness 1 and key dictator" ; +alias tezos-activate-alpha="$client -block genesis activate protocol ProtoALphaALphaALphaALphaALphaALphaALphaALphaDdp3zK with fitness 1 and key dictator and parameters $parameters_file" ; alias tezos-client-reset="rm -rf \"$client_dir\"; unalias tezos-activate-alpha tezos-client-reset" ; alias tezos-autocomplete="if [ \$ZSH_NAME ] ; then autoload bashcompinit ; bashcompinit ; fi ; source \"$bin_dir/bash-completion.sh\"" ; trap tezos-client-reset EXIT ; diff --git a/src/proto_alpha/lib_baking/test/proto_alpha_helpers.ml b/src/proto_alpha/lib_baking/test/proto_alpha_helpers.ml index 887cc95fd..aaecb6cc8 100644 --- a/src/proto_alpha/lib_baking/test/proto_alpha_helpers.ml +++ b/src/proto_alpha/lib_baking/test/proto_alpha_helpers.ml @@ -44,6 +44,35 @@ let no_write_context ?(block = `Head 0) config : #Client_context.full = object Format.kasprintf (fun _ -> Lwt.return "") end +let protocol_parameters = + let json_result = + Data_encoding.Json.from_string {json| +{ "bootstrap_accounts": [ + [ "edpkuBknW28nW72KG6RoHtYW7p12T6GKc7nAbwYX5m8Wd9sDVC9yav", "4000000000000" ], + [ "edpktzNbDAUjUk697W7gYg2CRuBQjyPxbEg8dLccYYwKSKvkPvjtV9", "4000000000000" ], + [ "edpkuTXkJDGcFd5nh6VvMz8phXxU3Bi7h6hqgywNFi1vZTfQNnS1RV", "4000000000000" ], + [ "edpkuFrRoDSEbJYgxRtLx2ps82UdaYc1WwfS9sE11yhauZt5DgCHbU", "4000000000000" ], + [ "edpkv8EUUH68jmo3f7Um5PezmfGrRF24gnfLpH3sVNwJnV5bVCxL2n", "4000000000000" ] + ], + "commitments": [ + [ "tz1fkmDXEQdua3u71JBVh4eGUGqK4t1G8xhZ", "btz1T77Ly5U1bWNBR5KzDSgNFST5Bh5F1eB6g", "1868898542104130027" ], + [ "tz1doNkK6RKaRswsuKJV4erT6HauYSm9fuHi", "btz1QxTPgszARgWioEor3eMehxW3osfhw3KoJ", "517697389496079974" ], + [ "tz1g6zFsci4YR8p1MJrkyc6wAKizR6mqJmyQ", "btz1NUYc1tV5VBksMNuQG4AuZF9Xudh1sDJni", "962290491831710023" ], + [ "tz1MpbcwGFWVBBWoxwm6iQH5Hzh9mCXbnETJ", "btz1Wwifd8vbQqnbuzSbQLvJEjQ9FUoxVJm68", "1233665184704419921" ], + [ "tz1U4t2PmX5cZVUui4BNaiRVokLa6AxB5G9Z", "btz1RrFkp9GmnypoNGRSyURkBQNUs4PPYG8SR", "131959324067470008" ], + [ "tz1RUxPjviua4XJM78XjSKGUCAS9R3y8Bdof", "btz1hozabzP9HdRakJddzyea7DgPHzJ5PB37N", "112378240876120002" ], + [ "tz1fJPeueQKJrTj2SFV2PmyCinLYJKXCEMf4", "btz1j1k4nrZB4r8RpTYiy8zbi3Fappopkb8ZF", "1060667014046690017" ], + [ "tz1iDPZLxcGf5CqCNpTuuMdtu3zKpJ6HvvFR", "btz1TaSfoSNhFoqwqbPC9iC19rN24KJtB7skD", "71300478465380003" ], + [ "tz1i2kbtVu65dP739qLGRpJNujRM8pdpkH3p", "btz1USqQRuvASPXwseXkGTWeWv4dn3VwMVPEk", "283380756728119992" ], + [ "tz1LKGCg6ESJLDviHkT8Jc7tUwjw4h3d9MaF", "btz1YwCKMbBLRL1qkBjAHGCwjbWDqiTAEFpbw", "1357762577679880028" ] + ] +} +|json} in + match json_result with + | Error err -> raise (Failure err) + | Ok json -> + Data_encoding.Binary.to_bytes Data_encoding.json json + let activate_alpha () = let fitness = Fitness_repr.from_int64 0L in let dictator_sk = Client_keys.Secret_key_locator.create @@ -52,7 +81,9 @@ let activate_alpha () = Tezos_client_genesis.Client_proto_main.bake (no_write_context ~block:(`Head 0) !rpc_config) (`Head 0) (Activate { protocol = Proto_alpha.hash ; - fitness }) + fitness ; + protocol_parameters ; + }) dictator_sk let init ?exe ?(sandbox = "sandbox.json") ?rpc_port () = diff --git a/src/proto_alpha/lib_client/client_proto_programs.ml b/src/proto_alpha/lib_client/client_proto_programs.ml index fdbd7f815..ed117d458 100644 --- a/src/proto_alpha/lib_client/client_proto_programs.ml +++ b/src/proto_alpha/lib_client/client_proto_programs.ml @@ -86,25 +86,36 @@ let print_trace_result (cctxt : #Client_context.printer) ~show_source ~parsed = | Error errs -> print_errors cctxt errs ~show_source ~parsed +let get_contract cctxt block contract = + match contract with + | Some contract -> return contract + | None -> + (* TODO use local contract by default *) + Alpha_services.Contract.list cctxt block >>|? List.hd + let run + ?contract ?(amount = Tez.fifty_cents) ~(program : Michelson_v1_parser.parsed) ~(storage : Michelson_v1_parser.parsed) ~(input : Michelson_v1_parser.parsed) block (cctxt : #RPC_context.simple) = + get_contract cctxt block contract >>=? fun contract -> Alpha_services.Helpers.run_code cctxt - block program.expanded (storage.expanded, input.expanded, amount) + block program.expanded (storage.expanded, input.expanded, amount, contract) let trace + ?contract ?(amount = Tez.fifty_cents) ~(program : Michelson_v1_parser.parsed) ~(storage : Michelson_v1_parser.parsed) ~(input : Michelson_v1_parser.parsed) block (cctxt : #RPC_context.simple) = + get_contract cctxt block contract >>=? fun contract -> Alpha_services.Helpers.trace_code cctxt - block program.expanded (storage.expanded, input.expanded, amount) + block program.expanded (storage.expanded, input.expanded, amount, contract) let hash_and_sign (data : Michelson_v1_parser.parsed) (typ : Michelson_v1_parser.parsed) sk block cctxt = Alpha_services.Helpers.hash_data cctxt block (data.expanded, typ.expanded) >>=? fun hash -> diff --git a/src/proto_alpha/lib_client/client_proto_programs.mli b/src/proto_alpha/lib_client/client_proto_programs.mli index aaa290530..9f598d2f4 100644 --- a/src/proto_alpha/lib_client/client_proto_programs.mli +++ b/src/proto_alpha/lib_client/client_proto_programs.mli @@ -15,6 +15,7 @@ module Program : Client_aliases.Alias with type t = Michelson_v1_parser.parsed Micheline_parser.parsing_result val run : + ?contract:Contract.t -> ?amount:Tez.t -> program:Michelson_v1_parser.parsed -> storage:Michelson_v1_parser.parsed -> @@ -24,6 +25,7 @@ val run : (Script.expr * Script.expr * (Script.expr * Script.expr option) list option) tzresult Lwt.t val trace : + ?contract:Contract.t -> ?amount:Tez.t -> program:Michelson_v1_parser.parsed -> storage:Michelson_v1_parser.parsed -> diff --git a/src/proto_alpha/lib_protocol/src/TEZOS_PROTOCOL b/src/proto_alpha/lib_protocol/src/TEZOS_PROTOCOL index 25311b1d6..b8a4e56f6 100644 --- a/src/proto_alpha/lib_protocol/src/TEZOS_PROTOCOL +++ b/src/proto_alpha/lib_protocol/src/TEZOS_PROTOCOL @@ -31,6 +31,7 @@ "Operation_repr", "Manager_repr", "Commitment_repr", + "Parameters_repr", "Raw_context", "Storage_sigs", diff --git a/src/proto_alpha/lib_protocol/src/alpha_context.ml b/src/proto_alpha/lib_protocol/src/alpha_context.ml index 5bd9f9a6c..471ccd55f 100644 --- a/src/proto_alpha/lib_protocol/src/alpha_context.ml +++ b/src/proto_alpha/lib_protocol/src/alpha_context.ml @@ -78,7 +78,6 @@ module Seed = struct include Seed_repr include Seed_storage end -module Bootstrap = Bootstrap_storage module Fitness = struct diff --git a/src/proto_alpha/lib_protocol/src/alpha_context.mli b/src/proto_alpha/lib_protocol/src/alpha_context.mli index b5e120871..427fff9d4 100644 --- a/src/proto_alpha/lib_protocol/src/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/src/alpha_context.mli @@ -243,15 +243,6 @@ module Script : sig val encoding: t Data_encoding.t end -module Bootstrap : sig - type account = { - public_key_hash: public_key_hash ; - public_key: public_key ; - } - val accounts: context -> account list - val account_encoding: account Data_encoding.t -end - module Constants : sig val proof_of_work_nonce_size: int diff --git a/src/proto_alpha/lib_protocol/src/bootstrap_storage.ml b/src/proto_alpha/lib_protocol/src/bootstrap_storage.ml index 428959c4b..45f8dfa57 100644 --- a/src/proto_alpha/lib_protocol/src/bootstrap_storage.ml +++ b/src/proto_alpha/lib_protocol/src/bootstrap_storage.ml @@ -7,40 +7,14 @@ (* *) (**************************************************************************) -type account = { - public_key_hash : Ed25519.Public_key_hash.t ; - public_key : Ed25519.Public_key.t ; -} - -let init_account ctxt account = - let contract = Contract_repr.implicit_contract account.public_key_hash in - Contract_storage.credit ctxt contract - Constants_repr.bootstrap_wealth >>=? fun ctxt -> +let init ctxt (account: Parameters_repr.bootstrap_account) = + let public_key_hash = Ed25519.Public_key.hash account.public_key in + let contract = Contract_repr.implicit_contract public_key_hash in + Contract_storage.credit ctxt contract account.amount >>=? fun ctxt -> Contract_storage.update_manager_key ctxt contract (Some account.public_key) >>=? fun (ctxt, _) -> - Delegate_storage.set ctxt contract - (Some account.public_key_hash) >>=? fun ctxt -> + Delegate_storage.set ctxt contract (Some public_key_hash) >>=? fun ctxt -> return ctxt - -let make public_key = - { public_key ; public_key_hash = Ed25519.Public_key.hash public_key } - -let accounts ctxt = - let { Constants_repr.bootstrap_keys } = Raw_context.constants ctxt in - List.map make bootstrap_keys - -let init ctxt = - fold_left_s init_account ctxt (accounts ctxt) >>=? fun ctxt -> - return ctxt - -let account_encoding = - let open Data_encoding in - conv - (fun {public_key_hash ; public_key } -> - (public_key_hash, public_key)) - (fun (public_key_hash, public_key) -> - { public_key_hash ; public_key }) - (obj2 - (req "publicKeyHash" Ed25519.Public_key_hash.encoding) - (req "publicKey" Ed25519.Public_key.encoding)) +let init ctxt accounts = + fold_left_s init ctxt accounts diff --git a/src/proto_alpha/lib_protocol/src/bootstrap_storage.mli b/src/proto_alpha/lib_protocol/src/bootstrap_storage.mli index 739e2718d..95a2ece99 100644 --- a/src/proto_alpha/lib_protocol/src/bootstrap_storage.mli +++ b/src/proto_alpha/lib_protocol/src/bootstrap_storage.mli @@ -7,13 +7,7 @@ (* *) (**************************************************************************) -type account = { - public_key_hash : Ed25519.Public_key_hash.t ; - public_key : Ed25519.Public_key.t ; -} - -val account_encoding: account Data_encoding.t - -val accounts: Raw_context.t -> account list - -val init: Raw_context.t -> Raw_context.t tzresult Lwt.t +val init: + Raw_context.t -> + Parameters_repr.bootstrap_account list -> + Raw_context.t tzresult Lwt.t diff --git a/src/proto_alpha/lib_protocol/src/commitment_repr.ml b/src/proto_alpha/lib_protocol/src/commitment_repr.ml index 58cca9b9e..4516a967b 100644 --- a/src/proto_alpha/lib_protocol/src/commitment_repr.ml +++ b/src/proto_alpha/lib_protocol/src/commitment_repr.ml @@ -19,7 +19,6 @@ let encoding = ( blinded_public_key_hash, amount )) (fun ( blinded_public_key_hash, amount) -> { blinded_public_key_hash ; amount }) - (obj2 - (req "blinded_public_key_hash" Blinded_public_key_hash.encoding) - (req "amount" Tez_repr.encoding) - ) + (tup2 + Blinded_public_key_hash.encoding + Tez_repr.encoding) diff --git a/src/proto_alpha/lib_protocol/src/commitment_storage.ml b/src/proto_alpha/lib_protocol/src/commitment_storage.ml index 6f2d7c706..dbbf92ac7 100644 --- a/src/proto_alpha/lib_protocol/src/commitment_storage.ml +++ b/src/proto_alpha/lib_protocol/src/commitment_storage.ml @@ -7,32 +7,11 @@ (* *) (**************************************************************************) -open Commitment_repr - -let test_commitments = [ - "tz1fkmDXEQdua3u71JBVh4eGUGqK4t1G8xhZ", "btz1T77Ly5U1bWNBR5KzDSgNFST5Bh5F1eB6g", 1868898542104130027L ; - "tz1doNkK6RKaRswsuKJV4erT6HauYSm9fuHi", "btz1QxTPgszARgWioEor3eMehxW3osfhw3KoJ", 517697389496079974L ; - "tz1g6zFsci4YR8p1MJrkyc6wAKizR6mqJmyQ", "btz1NUYc1tV5VBksMNuQG4AuZF9Xudh1sDJni", 962290491831710023L ; - "tz1MpbcwGFWVBBWoxwm6iQH5Hzh9mCXbnETJ", "btz1Wwifd8vbQqnbuzSbQLvJEjQ9FUoxVJm68", 1233665184704419921L ; - "tz1U4t2PmX5cZVUui4BNaiRVokLa6AxB5G9Z", "btz1RrFkp9GmnypoNGRSyURkBQNUs4PPYG8SR", 131959324067470008L ; - "tz1RUxPjviua4XJM78XjSKGUCAS9R3y8Bdof", "btz1hozabzP9HdRakJddzyea7DgPHzJ5PB37N", 112378240876120002L ; - "tz1fJPeueQKJrTj2SFV2PmyCinLYJKXCEMf4", "btz1j1k4nrZB4r8RpTYiy8zbi3Fappopkb8ZF", 1060667014046690017L ; - "tz1iDPZLxcGf5CqCNpTuuMdtu3zKpJ6HvvFR", "btz1TaSfoSNhFoqwqbPC9iC19rN24KJtB7skD", 71300478465380003L ; - "tz1i2kbtVu65dP739qLGRpJNujRM8pdpkH3p", "btz1USqQRuvASPXwseXkGTWeWv4dn3VwMVPEk", 283380756728119992L ; - "tz1LKGCg6ESJLDviHkT8Jc7tUwjw4h3d9MaF", "btz1YwCKMbBLRL1qkBjAHGCwjbWDqiTAEFpbw", 1357762577679880028L ; -] - -let init_commitment ctxt (hpkh, blind, amount) = - let half_public_key_hash = Unclaimed_public_key_hash.of_b58check_exn hpkh in - let blinded_public_key_hash = Blinded_public_key_hash.of_b58check_exn blind in - let amount = Tez_repr.of_mutez_exn amount in - Storage.Commitments.init - ctxt half_public_key_hash - { blinded_public_key_hash ; amount } - -let init ctxt = - fold_left_s init_commitment ctxt test_commitments >>=? fun ctxt -> - return ctxt - let get_opt = Storage.Commitments.get_option let delete = Storage.Commitments.delete + +let init ctxt commitments = + let init_commitment ctxt ( hpkh, commitment ) = + Storage.Commitments.init ctxt hpkh commitment in + fold_left_s init_commitment ctxt commitments >>=? fun ctxt -> + return ctxt diff --git a/src/proto_alpha/lib_protocol/src/commitment_storage.mli b/src/proto_alpha/lib_protocol/src/commitment_storage.mli index de0c21772..eca06ff89 100644 --- a/src/proto_alpha/lib_protocol/src/commitment_storage.mli +++ b/src/proto_alpha/lib_protocol/src/commitment_storage.mli @@ -8,7 +8,9 @@ (**************************************************************************) val init: - Raw_context.t -> Raw_context.t tzresult Lwt.t + Raw_context.t -> + (Unclaimed_public_key_hash.t * Commitment_repr.t) list -> + Raw_context.t tzresult Lwt.t val get_opt: Raw_context.t -> Unclaimed_public_key_hash.t -> diff --git a/src/proto_alpha/lib_protocol/src/constants_repr.ml b/src/proto_alpha/lib_protocol/src/constants_repr.ml index 4ffaa5022..82ac12d76 100644 --- a/src/proto_alpha/lib_protocol/src/constants_repr.ml +++ b/src/proto_alpha/lib_protocol/src/constants_repr.ml @@ -38,10 +38,6 @@ let block_reward = let endorsement_reward = Tez_repr.(mul_exn one 2) -(* 4,000,000 tez *) -let bootstrap_wealth = - Tez_repr.(mul_exn one 4_000_000) - let max_revelations_per_block = 32 type constants = { @@ -55,7 +51,6 @@ type constants = { endorsers_per_block: int ; max_gas: int ; proof_of_work_threshold: int64 ; - bootstrap_keys: Ed25519.Public_key.t list ; dictator_pubkey: Ed25519.Public_key.t ; max_operation_data_length: int ; tokens_per_roll: Tez_repr.t ; @@ -77,14 +72,6 @@ let default = { max_gas = 40_000 ; proof_of_work_threshold = Int64.(sub (shift_left 1L 56) 1L) ; - bootstrap_keys = - List.map read_public_key [ - "edpkumCM1MAkah9ESaoQJnf1pXKrEYZMtFnEz46rrpq9SWkF1phM5Q" ; - "edpktsJoNN7G67B4rBwXD44ymRwEMMXVJDV2nURasB3gd6jqibZqWh" ; - "edpkth7ZUHB1X26ruiQXg4WaJPKPFfBqX5wvgja17Bf6hybMcRBCkn" ; - "edpkvTnasCe4gtEPRsgyBhMjvDkyf5YA7QTyEksJj836gXVCSxeQZk" ; - "edpkvXCagqGcEfJ7rUmzwRcPMViM6Yk2XGwwkrLre4d9yMFEqsrwuf" ; - ] ; dictator_pubkey = read_public_key "edpkugeDwmwuwyyD3Q5enapgEYDxZLtEUFFSrvVwXASQMVEqsvTqWu" ; @@ -140,9 +127,6 @@ let constants_encoding = and proof_of_work_threshold = opt Compare.Int64.(=) default.proof_of_work_threshold c.proof_of_work_threshold - and bootstrap_keys = - opt Compare_keys.(=) - default.bootstrap_keys c.bootstrap_keys and dictator_pubkey = opt Ed25519.Public_key.(=) default.dictator_pubkey c.dictator_pubkey @@ -166,7 +150,6 @@ let constants_encoding = endorsers_per_block, max_gas), ( proof_of_work_threshold, - bootstrap_keys, dictator_pubkey, max_operation_data_length, tokens_per_roll, @@ -181,7 +164,6 @@ let constants_encoding = endorsers_per_block, max_gas), ( proof_of_work_threshold, - bootstrap_keys, dictator_pubkey, max_operation_data_length, tokens_per_roll, @@ -207,8 +189,6 @@ let constants_encoding = unopt default.max_gas max_gas ; proof_of_work_threshold = unopt default.proof_of_work_threshold proof_of_work_threshold ; - bootstrap_keys = - unopt default.bootstrap_keys bootstrap_keys ; dictator_pubkey = unopt default.dictator_pubkey dictator_pubkey ; max_operation_data_length = @@ -231,9 +211,8 @@ let constants_encoding = (opt "first_free_baking_slot" uint16) (opt "endorsers_per_block" uint16) (opt "instructions_per_transaction" int31)) - (obj6 + (obj5 (opt "proof_of_work_threshold" int64) - (opt "bootstrap_keys" (list Ed25519.Public_key.encoding)) (opt "dictator_pubkey" Ed25519.Public_key.encoding) (opt "max_operation_data_length" int31) (opt "tokens_per_roll" Tez_repr.encoding) diff --git a/src/proto_alpha/lib_protocol/src/helpers_services.ml b/src/proto_alpha/lib_protocol/src/helpers_services.ml index 37b3054ac..99628b624 100644 --- a/src/proto_alpha/lib_protocol/src/helpers_services.ml +++ b/src/proto_alpha/lib_protocol/src/helpers_services.ml @@ -29,7 +29,7 @@ module S = struct (req "storage" Script.expr_encoding) (req "input" Script.expr_encoding) (req "amount" Tez.encoding) - (opt "contract" Contract.encoding) + (req "contract" Contract.encoding) (opt "origination_nonce" Contract.origination_nonce_encoding)) let run_code = @@ -145,12 +145,6 @@ module I = struct let run_parameters ctxt (script, storage, input, amount, contract, origination_nonce) = - let contract = - match contract with - | Some contract -> contract - | None -> - Contract.implicit_contract - (List.hd (Bootstrap.accounts ctxt)).Bootstrap.public_key_hash in let max_gas = Constants.max_gas ctxt in let origination_nonce = @@ -222,17 +216,17 @@ let () = let minimal_time ctxt ?priority block = RPC_context.make_call0 S.minimal_timestamp ctxt block () priority -let run_code ctxt block code (storage, input, amount) = +let run_code ctxt block code (storage, input, amount, contract) = RPC_context.make_call0 S.run_code ctxt - block () (code, storage, input, amount, None, None) + block () (code, storage, input, amount, contract, None) let apply_operation ctxt block pred_block hash forged_operation signature = RPC_context.make_call0 S.apply_operation ctxt block () (pred_block, hash, forged_operation, signature) -let trace_code ctxt block code (storage, input, amount) = +let trace_code ctxt block code (storage, input, amount, contract) = RPC_context.make_call0 S.trace_code ctxt - block () (code, storage, input, amount, None, None) + block () (code, storage, input, amount, contract, None) let typecheck_code ctxt block = RPC_context.make_call0 S.typecheck_code ctxt block () diff --git a/src/proto_alpha/lib_protocol/src/helpers_services.mli b/src/proto_alpha/lib_protocol/src/helpers_services.mli index 4b545d687..fd95246d3 100644 --- a/src/proto_alpha/lib_protocol/src/helpers_services.mli +++ b/src/proto_alpha/lib_protocol/src/helpers_services.mli @@ -24,13 +24,13 @@ val apply_operation: val run_code: 'a #RPC_context.simple -> 'a -> Script.expr -> - (Script.expr * Script.expr * Tez.t) -> + (Script.expr * Script.expr * Tez.t * Contract.t) -> (Script.expr * Script.expr * (Script.expr * Script.expr option) list option) shell_tzresult Lwt.t val trace_code: 'a #RPC_context.simple -> 'a -> Script.expr -> - (Script.expr * Script.expr * Tez.t) -> + (Script.expr * Script.expr * Tez.t * Contract.t) -> (Script.expr * Script.expr * (Script.location * Gas.t * Script.expr list) list * (Script.expr * Script.expr option) list option) shell_tzresult Lwt.t diff --git a/src/proto_alpha/lib_protocol/src/init_storage.ml b/src/proto_alpha/lib_protocol/src/init_storage.ml index 976cf0f2a..9a8d8e56c 100644 --- a/src/proto_alpha/lib_protocol/src/init_storage.ml +++ b/src/proto_alpha/lib_protocol/src/init_storage.ml @@ -10,14 +10,14 @@ (* This is the genesis protocol: initialise the state *) let prepare_first_block ctxt ~level ~timestamp ~fitness = Raw_context.prepare_first_block - ~level ~timestamp ~fitness ctxt >>=? fun ctxt -> + ~level ~timestamp ~fitness ctxt >>=? fun (param, ctxt) -> + Commitment_storage.init ctxt param.commitments >>=? fun ctxt -> Roll_storage.init ctxt >>=? fun ctxt -> Seed_storage.init ctxt >>=? fun ctxt -> Contract_storage.init ctxt >>=? fun ctxt -> - Bootstrap_storage.init ctxt >>=? fun ctxt -> + Bootstrap_storage.init ctxt param.bootstrap_accounts >>=? fun ctxt -> Roll_storage.init_first_cycles ctxt >>=? fun ctxt -> Vote_storage.init ctxt >>=? fun ctxt -> - Commitment_storage.init ctxt >>=? fun ctxt -> return ctxt let prepare ctxt ~level ~timestamp ~fitness = diff --git a/src/proto_alpha/lib_protocol/src/parameters_repr.ml b/src/proto_alpha/lib_protocol/src/parameters_repr.ml new file mode 100644 index 000000000..7db2c986a --- /dev/null +++ b/src/proto_alpha/lib_protocol/src/parameters_repr.ml @@ -0,0 +1,40 @@ +(**************************************************************************) +(* *) +(* Copyright (c) 2014 - 2018. *) +(* Dynamic Ledger Solutions, Inc. *) +(* *) +(* All rights reserved. No warranty, explicit or implicit, provided. *) +(* *) +(**************************************************************************) + +type bootstrap_account = { + public_key : Ed25519.Public_key.t ; + amount : Tez_repr.t ; +} + +type t = { + bootstrap_accounts : bootstrap_account list ; + commitments : (Unclaimed_public_key_hash.t * Commitment_repr.t) list +} + + +let bootstrap_account_encoding = + let open Data_encoding in + conv + (fun { public_key ; amount } -> (public_key, amount)) + (fun (public_key, amount) -> { public_key ; amount }) + (tup2 Ed25519.Public_key.encoding Tez_repr.encoding) + +let encoding = + let open Data_encoding in + conv + (fun { bootstrap_accounts ; commitments } -> + (bootstrap_accounts, commitments)) + (fun ( bootstrap_accounts, commitments ) -> + { bootstrap_accounts ; commitments }) + (obj2 + (req "bootstrap_accounts" (list bootstrap_account_encoding)) + (req "commitments" + (list (merge_tups + (tup1 Unclaimed_public_key_hash.encoding) + Commitment_repr.encoding)))) diff --git a/src/proto_alpha/lib_protocol/src/parameters_repr.mli b/src/proto_alpha/lib_protocol/src/parameters_repr.mli new file mode 100644 index 000000000..37198a3c8 --- /dev/null +++ b/src/proto_alpha/lib_protocol/src/parameters_repr.mli @@ -0,0 +1,20 @@ +(**************************************************************************) +(* *) +(* Copyright (c) 2014 - 2018. *) +(* Dynamic Ledger Solutions, Inc. *) +(* *) +(* All rights reserved. No warranty, explicit or implicit, provided. *) +(* *) +(**************************************************************************) + +type bootstrap_account = { + public_key : Ed25519.Public_key.t ; + amount : Tez_repr.t ; +} + +type t = { + bootstrap_accounts : bootstrap_account list ; + commitments : (Unclaimed_public_key_hash.t * Commitment_repr.t) list +} + +val encoding: t Data_encoding.t diff --git a/src/proto_alpha/lib_protocol/src/raw_context.ml b/src/proto_alpha/lib_protocol/src/raw_context.ml index 6b5ec3beb..334924a1b 100644 --- a/src/proto_alpha/lib_protocol/src/raw_context.ml +++ b/src/proto_alpha/lib_protocol/src/raw_context.ml @@ -126,6 +126,7 @@ let constants_key = [ version ; "constants" ] (* temporary hardcoded key to be removed... *) let sandbox_param_key = [ "sandbox_parameter" ] +let protocol_param_key = [ "protocol_parameters" ] let get_first_level ctxt = Context.get ctxt first_level_key >>= function @@ -151,7 +152,7 @@ let () = ~id:"context.failed_to_parse_sandbox_parameter" ~title: "Failed to parse sandbox parameter" ~description: - "The sandbox paramater is not a valid JSON string." + "The sandbox parameter is not a valid JSON string." ~pp:begin fun ppf bytes -> Format.fprintf ppf "@[Cannot parse the sandbox parameter:@ %s@]" @@ -169,6 +170,24 @@ let get_sandbox_param c = | None -> fail (Failed_to_parse_sandbox_parameter bytes) | Some json -> return (Some json) +let get_proto_param ctxt = + Context.get ctxt protocol_param_key >>= function + | None -> + failwith "Missing protocol parameters." + | Some bytes -> + match Data_encoding.Binary.of_bytes Data_encoding.json bytes with + | None -> failwith "Invalid json" + | Some json -> begin + Context.del ctxt protocol_param_key >>= fun ctxt -> + match Data_encoding.Json.destruct Parameters_repr.encoding json with + | exception (Data_encoding.Json.Cannot_destruct _ as exn) -> + Format.kasprintf + failwith "Invalid protocol_parameters: %a %a" + (fun ppf -> Data_encoding.Json.print_error ppf) exn + Data_encoding.Json.pp json + | param -> return (param, ctxt) + end + let set_constants ctxt constants = let bytes = Data_encoding.Binary.to_bytes @@ -232,16 +251,19 @@ let check_first_block ctxt = let prepare_first_block ~level ~timestamp ~fitness ctxt = check_first_block ctxt >>=? fun () -> Lwt.return (Raw_level_repr.of_int32 level) >>=? fun first_level -> + get_proto_param ctxt >>=? fun (param, ctxt) -> get_sandbox_param ctxt >>=? fun sandbox_param -> Constants_repr.read sandbox_param >>=? fun constants -> Context.set ctxt version_key (MBytes.of_string version_value) >>= fun ctxt -> set_first_level ctxt first_level >>=? fun ctxt -> set_constants ctxt constants >>= fun ctxt -> - prepare ctxt ~level ~timestamp ~fitness + prepare ctxt ~level ~timestamp ~fitness >>=? fun ctxt -> + return (param, ctxt) let activate ({ context = c ; _ } as s) h = Updater.activate c h >>= fun c -> Lwt.return { s with context = c } + let fork_test_chain ({ context = c ; _ } as s) protocol expiration = Updater.fork_test_chain c ~protocol ~expiration >>= fun c -> Lwt.return { s with context = c } diff --git a/src/proto_alpha/lib_protocol/src/raw_context.mli b/src/proto_alpha/lib_protocol/src/raw_context.mli index d537b2433..d69454db5 100644 --- a/src/proto_alpha/lib_protocol/src/raw_context.mli +++ b/src/proto_alpha/lib_protocol/src/raw_context.mli @@ -41,7 +41,7 @@ val prepare_first_block: level:int32 -> timestamp:Time.t -> fitness:Fitness.t -> - Context.t -> context tzresult Lwt.t + Context.t -> (Parameters_repr.t * context) tzresult Lwt.t val activate: context -> Protocol_hash.t -> t Lwt.t val fork_test_chain: context -> Protocol_hash.t -> Time.t -> t Lwt.t diff --git a/src/proto_alpha/lib_protocol/test/helpers/helpers_init.ml b/src/proto_alpha/lib_protocol/test/helpers/helpers_init.ml index 5d6f91320..2047272d0 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/helpers_init.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/helpers_init.ml @@ -10,20 +10,58 @@ open Proto_alpha open Error_monad -let get_sandbox () = - Lwt_utils_unix.Json.read_file - "src/proto_alpha/lib_protocol/test/sandbox.json" >>= function - | Ok x -> Lwt.return x - | Error _ -> - Lwt_utils_unix.Json.read_file "test/sandbox.json" >>= fun x -> - Lwt.return @@ Helpers_assert.no_error ~msg:__LOC__ x +let sandbox_parameters = + match Data_encoding.Json.from_string {json| +{ + "genesis_pubkey": + "edpkuSLWfVU1Vq7Jg9FucPyKmma6otcMHac9zG4oU1KMHSTBpJuGQ2", + "slot_durations" : [ 1, 0 ], + "cycle_length" : 4, + "block_per_roll_snapshot" : 2, + "time_before_reward" : 1, + "first_free_baking_slot" : 4 +} +|json} with + | Error err -> raise (Failure err) + | Ok json -> + Data_encoding.Binary.to_bytes Data_encoding.json json + +let protocol_parameters = + let json_result = + Data_encoding.Json.from_string {json| +{ "bootstrap_accounts": [ + [ "edpkuBknW28nW72KG6RoHtYW7p12T6GKc7nAbwYX5m8Wd9sDVC9yav", "4000000000000" ], + [ "edpktzNbDAUjUk697W7gYg2CRuBQjyPxbEg8dLccYYwKSKvkPvjtV9", "4000000000000" ], + [ "edpkuTXkJDGcFd5nh6VvMz8phXxU3Bi7h6hqgywNFi1vZTfQNnS1RV", "4000000000000" ], + [ "edpkuFrRoDSEbJYgxRtLx2ps82UdaYc1WwfS9sE11yhauZt5DgCHbU", "4000000000000" ], + [ "edpkv8EUUH68jmo3f7Um5PezmfGrRF24gnfLpH3sVNwJnV5bVCxL2n", "4000000000000" ] + ], + "commitments": [ + [ "tz1fkmDXEQdua3u71JBVh4eGUGqK4t1G8xhZ", "btz1T77Ly5U1bWNBR5KzDSgNFST5Bh5F1eB6g", "1868898542104130027" ], + [ "tz1doNkK6RKaRswsuKJV4erT6HauYSm9fuHi", "btz1QxTPgszARgWioEor3eMehxW3osfhw3KoJ", "517697389496079974" ], + [ "tz1g6zFsci4YR8p1MJrkyc6wAKizR6mqJmyQ", "btz1NUYc1tV5VBksMNuQG4AuZF9Xudh1sDJni", "962290491831710023" ], + [ "tz1MpbcwGFWVBBWoxwm6iQH5Hzh9mCXbnETJ", "btz1Wwifd8vbQqnbuzSbQLvJEjQ9FUoxVJm68", "1233665184704419921" ], + [ "tz1U4t2PmX5cZVUui4BNaiRVokLa6AxB5G9Z", "btz1RrFkp9GmnypoNGRSyURkBQNUs4PPYG8SR", "131959324067470008" ], + [ "tz1RUxPjviua4XJM78XjSKGUCAS9R3y8Bdof", "btz1hozabzP9HdRakJddzyea7DgPHzJ5PB37N", "112378240876120002" ], + [ "tz1fJPeueQKJrTj2SFV2PmyCinLYJKXCEMf4", "btz1j1k4nrZB4r8RpTYiy8zbi3Fappopkb8ZF", "1060667014046690017" ], + [ "tz1iDPZLxcGf5CqCNpTuuMdtu3zKpJ6HvvFR", "btz1TaSfoSNhFoqwqbPC9iC19rN24KJtB7skD", "71300478465380003" ], + [ "tz1i2kbtVu65dP739qLGRpJNujRM8pdpkH3p", "btz1USqQRuvASPXwseXkGTWeWv4dn3VwMVPEk", "283380756728119992" ], + [ "tz1LKGCg6ESJLDviHkT8Jc7tUwjw4h3d9MaF", "btz1YwCKMbBLRL1qkBjAHGCwjbWDqiTAEFpbw", "1357762577679880028" ] + ] +} +|json} in + match json_result with + | Error err -> raise (Failure err) + | Ok json -> + Data_encoding.Binary.to_bytes Data_encoding.json json + let main () = let context = Tezos_protocol_environment_memory.Context.empty in - get_sandbox () >>= fun json -> Tezos_protocol_environment_memory.Context.set context - ["sandbox_parameter"] - (Data_encoding.Binary.to_bytes Data_encoding.json json) >>= fun context -> + ["sandbox_parameter"] sandbox_parameters >>= fun context -> + Tezos_protocol_environment_memory.Context.set context + ["protocol_parameters"] protocol_parameters >>= fun context -> let genesis_hash = Block_hash.of_b58check_exn "BLockGenesisGenesisGenesisGenesisGenesisCCCCCeZiLHU" in diff --git a/src/proto_alpha/lib_protocol/test/sandbox.json b/src/proto_alpha/lib_protocol/test/sandbox.json index 5466b46d4..e69de29bb 100644 --- a/src/proto_alpha/lib_protocol/test/sandbox.json +++ b/src/proto_alpha/lib_protocol/test/sandbox.json @@ -1,16 +0,0 @@ -{ - "genesis_pubkey": - "edpkuSLWfVU1Vq7Jg9FucPyKmma6otcMHac9zG4oU1KMHSTBpJuGQ2", - "bootstrap_keys": [ - "edpkuBknW28nW72KG6RoHtYW7p12T6GKc7nAbwYX5m8Wd9sDVC9yav", - "edpktzNbDAUjUk697W7gYg2CRuBQjyPxbEg8dLccYYwKSKvkPvjtV9", - "edpkuTXkJDGcFd5nh6VvMz8phXxU3Bi7h6hqgywNFi1vZTfQNnS1RV", - "edpkuFrRoDSEbJYgxRtLx2ps82UdaYc1WwfS9sE11yhauZt5DgCHbU", - "edpkv8EUUH68jmo3f7Um5PezmfGrRF24gnfLpH3sVNwJnV5bVCxL2n" - ], - "slot_durations" : [ 1, 0 ], - "cycle_length" : 4, - "block_per_roll_snapshot" : 2, - "time_before_reward" : 1, - "first_free_baking_slot" : 4 -} diff --git a/src/proto_demo/lib_protocol/src/main.ml b/src/proto_demo/lib_protocol/src/main.ml index 916ac19a2..63b354ea8 100644 --- a/src/proto_demo/lib_protocol/src/main.ml +++ b/src/proto_demo/lib_protocol/src/main.ml @@ -90,7 +90,8 @@ let finalize_block ctxt = let fitness = Fitness.from_int64 fitness in return { Updater.message ; context = ctxt.context ; fitness ; max_operations_ttl = 0 ; max_operation_data_length = 0 ; - last_allowed_fork_level = 0l } + last_allowed_fork_level = 0l ; + } let rpc_services = Services.rpc_services diff --git a/src/proto_genesis/lib_client/client_proto_main.ml b/src/proto_genesis/lib_client/client_proto_main.ml index 0d62a7c99..5a11276d6 100644 --- a/src/proto_genesis/lib_client/client_proto_main.ml +++ b/src/proto_genesis/lib_client/client_proto_main.ml @@ -34,6 +34,13 @@ let int_parameter = try return (int_of_string p) with _ -> failwith "Cannot read int")) +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 commands () = let open Clic in let args = @@ -59,11 +66,17 @@ let commands () = @@ prefixes [ "and" ; "key" ] @@ Client_keys.Secret_key.source_param ~name:"password" ~desc:"Dictator's key" + @@ prefixes [ "and" ; "parameters" ] + @@ param ~name:"parameters" + ~desc:"Protocol parameters (as JSON file)" + file_parameter @@ stop) - begin fun timestamp hash fitness sk (cctxt : Client_context.full) -> + begin fun timestamp hash fitness sk param_json_file (cctxt : Client_context.full) -> let fitness = Proto_alpha.Fitness_repr.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 Data_encoding.json json in bake cctxt ?timestamp cctxt#block - (Activate { protocol = hash ; fitness }) + (Activate { protocol = hash ; fitness ; protocol_parameters }) sk >>=? fun hash -> cctxt#answer "Injected %a" Block_hash.pp_short hash >>= fun () -> return () diff --git a/src/proto_genesis/lib_protocol/src/data.ml b/src/proto_genesis/lib_protocol/src/data.ml index 3ca340498..11bc63404 100644 --- a/src/proto_genesis/lib_protocol/src/data.ml +++ b/src/proto_genesis/lib_protocol/src/data.ml @@ -14,6 +14,7 @@ module Command = struct | Activate of { protocol: Protocol_hash.t ; fitness: Fitness.t ; + protocol_parameters : MBytes.t ; } (* Activate a protocol as a testchain *) @@ -36,16 +37,17 @@ module Command = struct union ~tag_size:`Uint8 [ case (Tag 0) (mk_case "activate" - (obj2 + (obj3 (req "hash" Protocol_hash.encoding) (req "fitness" Fitness.encoding) + (req "protocol_parameters" Variable.bytes) )) (function - | Activate { protocol ; fitness} -> - Some (protocol, fitness) + | Activate { protocol ; fitness ; protocol_parameters} -> + Some (protocol, fitness, protocol_parameters) | _ -> None) - (fun (protocol, fitness) -> - Activate { protocol ; fitness }) ; + (fun (protocol, fitness, protocol_parameters) -> + Activate { protocol ; fitness ; protocol_parameters }) ; case (Tag 1) (mk_case "activate_testchain" (obj2 diff --git a/src/proto_genesis/lib_protocol/src/main.ml b/src/proto_genesis/lib_protocol/src/main.ml index 052004d68..faa7f0ddd 100644 --- a/src/proto_genesis/lib_protocol/src/main.ml +++ b/src/proto_genesis/lib_protocol/src/main.ml @@ -77,16 +77,20 @@ let precheck_block Lwt.return (parse_block raw_block) >>=? fun _ -> return () +(* temporary hardcoded key to be removed... *) +let protocol_parameters_key = [ "protocol_parameters" ] let prepare_application ctxt command level timestamp fitness = match command with - | Data.Command.Activate { protocol = hash ; fitness } -> + | Data.Command.Activate { protocol = hash ; fitness ; protocol_parameters } -> let message = Some (Format.asprintf "activate %a" Protocol_hash.pp_short hash) in + Context.set ctxt protocol_parameters_key protocol_parameters >>= fun ctxt -> Updater.activate ctxt hash >>= fun ctxt -> return { Updater.message ; context = ctxt ; fitness ; max_operations_ttl = 0 ; max_operation_data_length = 0 ; - last_allowed_fork_level = level } + last_allowed_fork_level = level ; + } | Activate_testchain { protocol = hash ; delay } -> let message = Some (Format.asprintf "activate testchain %a" Protocol_hash.pp_short hash) in @@ -98,7 +102,6 @@ let prepare_application ctxt command level timestamp fitness = last_allowed_fork_level = Int32.succ level ; } - let begin_application ~predecessor_context:ctxt ~predecessor_timestamp:_ @@ -168,4 +171,3 @@ let init ctxt block_header = max_operation_data_length = 0 ; last_allowed_fork_level = block_header.level ; } -