diff --git a/manifest/main.ml b/manifest/main.ml index cb1ee73bde5553a918b5beeaf0db10e6f048c7d8..bf600537587ce0da260c5ac9c5a2e871d7a5aba2 100644 --- a/manifest/main.ml +++ b/manifest/main.ml @@ -1717,6 +1717,7 @@ protocols.|} "Environment_protocol_T"; "Environment_protocol_T_V0"; "Environment_protocol_T_V3"; + "Environment_protocol_T_V6"; "Environment_protocol_T_test"; "Dummy_context"; "Memory_context"; diff --git a/src/bin_client/test/proto_test_injection/main.ml b/src/bin_client/test/proto_test_injection/main.ml index b35c94fe78ad751eed64da4965af36b411d777e0..40c776339e6313da03edca5f8f8b2740cf3782fb 100644 --- a/src/bin_client/test/proto_test_injection/main.ml +++ b/src/bin_client/test/proto_test_injection/main.ml @@ -132,7 +132,7 @@ let finalize_block ctxt _block_header = let rpc_services = RPC_directory.empty -let init ctxt block_header = +let init _chain_id ctxt block_header = let fitness = block_header.Block_header.fitness in let message = None in return diff --git a/src/bin_validation/validator.ml b/src/bin_validation/validator.ml index 800933188f12b1a45ceda368f6aa8b5cd009352a..3c111802d6fde5815f26788009013e84666daf15 100644 --- a/src/bin_validation/validator.ml +++ b/src/bin_validation/validator.ml @@ -426,7 +426,8 @@ let run input output = block_precheck_result in loop cache cached_result - | External_validation.Fork_test_chain {context_hash; forked_header} -> + | External_validation.Fork_test_chain + {chain_id; context_hash; forked_header} -> let*! () = Events.(emit fork_test_chain_request forked_header) in let*! context_opt = Context.checkout context_index context_hash in let*! () = @@ -434,7 +435,7 @@ let run input output = | Some ctxt -> let*! test_chain_init_result = with_retry_to_load_protocol protocol_root (fun () -> - Block_validation.init_test_chain ctxt forked_header) + Block_validation.init_test_chain chain_id ctxt forked_header) in External_validation.send output diff --git a/src/lib_protocol_environment/dune b/src/lib_protocol_environment/dune index a376974b8baead5b052415b5b19e5bf4e65e5995..29d7a6a53b231a8b93f01c60e4b6b83d892bed33 100644 --- a/src/lib_protocol_environment/dune +++ b/src/lib_protocol_environment/dune @@ -37,6 +37,7 @@ Environment_protocol_T Environment_protocol_T_V0 Environment_protocol_T_V3 + Environment_protocol_T_V6 Environment_protocol_T_test Dummy_context Memory_context diff --git a/src/lib_protocol_environment/environment_V0.ml b/src/lib_protocol_environment/environment_V0.ml index 34aab02710df60842c481c92b01329675ef5b0c0..08a5efe65f401a3895ca54a0f04491138c42b6d0 100644 --- a/src/lib_protocol_environment/environment_V0.ml +++ b/src/lib_protocol_environment/environment_V0.ml @@ -832,7 +832,7 @@ struct let set_log_message_consumer _ = () - include Environment_protocol_T.V0toV3 (LiftV0 (P)) + include Environment_protocol_T.V0toV6 (LiftV0 (P)) end) class ['chain, 'block] proto_rpc_context (t : Tezos_rpc.RPC_context.t) diff --git a/src/lib_protocol_environment/environment_V1.ml b/src/lib_protocol_environment/environment_V1.ml index 770161ec76a6f62342c653783a4644cd7c304393..da70bc32efab03fc69c8babc7e1b688793c0a6d7 100644 --- a/src/lib_protocol_environment/environment_V1.ml +++ b/src/lib_protocol_environment/environment_V1.ml @@ -1029,7 +1029,7 @@ struct let environment_version = Protocol.V1 - include Environment_protocol_T.V0toV3 (LiftV1 (P)) + include Environment_protocol_T.V0toV6 (LiftV1 (P)) end) class ['chain, 'block] proto_rpc_context (t : Tezos_rpc.RPC_context.t) diff --git a/src/lib_protocol_environment/environment_V2.ml b/src/lib_protocol_environment/environment_V2.ml index 301d20edc5876a3588bad6eca776f22012c876c8..0822d5b5f15a00fa1a18d411f837da590997e64d 100644 --- a/src/lib_protocol_environment/environment_V2.ml +++ b/src/lib_protocol_environment/environment_V2.ml @@ -1024,7 +1024,7 @@ struct let environment_version = Protocol.V2 - include Environment_protocol_T.V0toV3 (LiftV2 (P)) + include Environment_protocol_T.V0toV6 (LiftV2 (P)) end) class ['chain, 'block] proto_rpc_context (t : Tezos_rpc.RPC_context.t) diff --git a/src/lib_protocol_environment/environment_V3.ml b/src/lib_protocol_environment/environment_V3.ml index 2445b8dd2a73700c78e2ed3c31ecd7063d1eba7c..0090c26dbd82226d360ad84b50a68eeddbbc3ff4 100644 --- a/src/lib_protocol_environment/environment_V3.ml +++ b/src/lib_protocol_environment/environment_V3.ml @@ -1228,7 +1228,7 @@ struct let+ r = finalize_block c shell_header in wrap_tzresult r - let init c bh = + let init _chain_id c bh = let open Lwt_syntax in let+ r = init c bh in wrap_tzresult r diff --git a/src/lib_protocol_environment/environment_V4.ml b/src/lib_protocol_environment/environment_V4.ml index 347c6e0259c76ab4f02d74f8cb4b4eff5858affd..8eba67de5d83c0501715a2549e5249f7b0fe829e 100644 --- a/src/lib_protocol_environment/environment_V4.ml +++ b/src/lib_protocol_environment/environment_V4.ml @@ -1255,7 +1255,7 @@ struct let+ r = finalize_block c shell_header in wrap_tzresult r - let init c bh = + let init _chain_id c bh = let open Lwt_syntax in let+ r = init c bh in wrap_tzresult r diff --git a/src/lib_protocol_environment/environment_V5.ml b/src/lib_protocol_environment/environment_V5.ml index 173496f32020403de9b5cf7d9dd713f6801fe3d8..b7964e507a34e75613e5adf2621172f2d852256a 100644 --- a/src/lib_protocol_environment/environment_V5.ml +++ b/src/lib_protocol_environment/environment_V5.ml @@ -1231,7 +1231,7 @@ struct let+ r = finalize_block c shell_header in wrap_tzresult r - let init c bh = + let init _chain_id c bh = let open Lwt_syntax in let+ r = init c bh in wrap_tzresult r diff --git a/src/lib_protocol_environment/environment_V6.ml b/src/lib_protocol_environment/environment_V6.ml index 8d5aa897345b7af79fafe4509e2206a56f6cebc6..8995f0de156a46bbb70b6968db23861890cdda4e 100644 --- a/src/lib_protocol_environment/environment_V6.ml +++ b/src/lib_protocol_environment/environment_V6.ml @@ -1065,7 +1065,7 @@ struct let activate = Context.set_protocol module type PROTOCOL = - Environment_protocol_T_V3.T + Environment_protocol_T_V6.T with type context := Context.t and type cache_value := Environment_context.Context.cache_value and type cache_key := Environment_context.Context.cache_key @@ -1231,9 +1231,9 @@ struct let+ r = finalize_block c shell_header in wrap_tzresult r - let init c bh = + let init chain_id c bh = let open Lwt_syntax in - let+ r = init c bh in + let+ r = init chain_id c bh in wrap_tzresult r let set_log_message_consumer f = Logging.logging_function := Some f diff --git a/src/lib_protocol_environment/environment_protocol_T.ml b/src/lib_protocol_environment/environment_protocol_T.ml index 70d93baebf08af7f36a7847601279ab88d14ae2f..19936e0c1478a4155c3a358d1ae7f1d4d95f1317 100644 --- a/src/lib_protocol_environment/environment_protocol_T.ml +++ b/src/lib_protocol_environment/environment_protocol_T.ml @@ -53,7 +53,7 @@ module type T = sig (* Documentation for this interface may be found in module type [PROTOCOL] of [sigs/v3/updater.mli]. *) - include Environment_protocol_T_V3.T + include Environment_protocol_T_V6.T val set_log_message_consumer : (Internal_event.level -> string -> unit) -> unit @@ -61,14 +61,14 @@ module type T = sig val environment_version : Protocol.env_version end -module V0toV3 +module V0toV6 (E : Environment_protocol_T_V0.T with type context := Context.t and type quota := quota and type validation_result := validation_result and type rpc_context := rpc_context and type 'a tzresult := 'a Error_monad.tzresult) : - Environment_protocol_T_V3.T + Environment_protocol_T_V6.T with type context := Context.t and type quota := quota and type validation_result := validation_result @@ -100,6 +100,8 @@ module V0toV3 type cache_key = Context.Cache.key type cache_value = Context.Cache.value + + let init _chain_id c hd = init c hd end (* [module type PROTOCOL] is protocol signature that the shell can use. @@ -175,10 +177,10 @@ module IgnoreCaches struct include P - let init context header = + let init chain_id context header = let open Lwt_syntax in let* context = Context.Cache.set_cache_layout context [] in - init context header + init chain_id context header let begin_partial_application ~chain_id ~ancestor_context ~(predecessor : Block_header.t) ~predecessor_hash:_ ~cache:_ diff --git a/src/lib_protocol_environment/environment_protocol_T_V6.ml b/src/lib_protocol_environment/environment_protocol_T_V6.ml new file mode 100644 index 0000000000000000000000000000000000000000..0107a7b3cc356a4d2d4ae168c882910c3b5b35af --- /dev/null +++ b/src/lib_protocol_environment/environment_protocol_T_V6.ml @@ -0,0 +1,141 @@ +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. *) +(* Copyright (c) 2018 Nomadic Labs. *) +(* *) +(* 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. *) +(* *) +(*****************************************************************************) + +(* Documentation for this interface can be found in + module type [PROTOCOL] of [sigs/v3/updater.mli]. *) + +module type T = sig + type context + + type quota + + type validation_result + + type rpc_context + + type 'a tzresult + + val max_block_length : int + + val max_operation_data_length : int + + val validation_passes : quota list + + type block_header_data + + val block_header_data_encoding : block_header_data Data_encoding.t + + type block_header = { + shell : Block_header.shell_header; + protocol_data : block_header_data; + } + + type block_header_metadata + + val block_header_metadata_encoding : block_header_metadata Data_encoding.t + + type operation_data + + type operation_receipt + + type operation = { + shell : Operation.shell_header; + protocol_data : operation_data; + } + + val operation_data_encoding : operation_data Data_encoding.t + + val operation_receipt_encoding : operation_receipt Data_encoding.t + + val operation_data_and_receipt_encoding : + (operation_data * operation_receipt) Data_encoding.t + + val acceptable_passes : operation -> int list + + val relative_position_within_block : operation -> operation -> int + + type validation_state + + val begin_partial_application : + chain_id:Chain_id.t -> + ancestor_context:context -> + predecessor_timestamp:Time.Protocol.t -> + predecessor_fitness:Fitness.t -> + block_header -> + validation_state tzresult Lwt.t + + val begin_application : + chain_id:Chain_id.t -> + predecessor_context:context -> + predecessor_timestamp:Time.Protocol.t -> + predecessor_fitness:Fitness.t -> + block_header -> + validation_state tzresult Lwt.t + + val begin_construction : + chain_id:Chain_id.t -> + predecessor_context:context -> + predecessor_timestamp:Time.Protocol.t -> + predecessor_level:Int32.t -> + predecessor_fitness:Fitness.t -> + predecessor:Block_hash.t -> + timestamp:Time.Protocol.t -> + ?protocol_data:block_header_data -> + unit -> + validation_state tzresult Lwt.t + + val apply_operation : + validation_state -> + operation -> + (validation_state * operation_receipt) tzresult Lwt.t + + val finalize_block : + validation_state -> + Block_header.shell_header option -> + (validation_result * block_header_metadata) tzresult Lwt.t + + val rpc_services : rpc_context RPC_directory.t + + val init : + Chain_id.t -> + context -> + Block_header.shell_header -> + validation_result tzresult Lwt.t + + type cache_value + + type cache_key + + val value_of_key : + chain_id:Chain_id.t -> + predecessor_context:context -> + predecessor_timestamp:Time.Protocol.t -> + predecessor_level:Int32.t -> + predecessor_fitness:Fitness.t -> + predecessor:Block_hash.t -> + timestamp:Time.Protocol.t -> + (cache_key -> cache_value tzresult Lwt.t) tzresult Lwt.t +end diff --git a/src/lib_protocol_environment/sigs/v6/updater.mli b/src/lib_protocol_environment/sigs/v6/updater.mli index d1858539ba55f1652bf7e149ef128da7a79f40dd..1339de69b90ac8fcc92eaabaa7f3ecf7dd3b52cc 100644 --- a/src/lib_protocol_environment/sigs/v6/updater.mli +++ b/src/lib_protocol_environment/sigs/v6/updater.mli @@ -254,15 +254,19 @@ module type PROTOCOL = sig by this protocol implementation. *) val rpc_services : rpc_context RPC_directory.t - (** [init ctxt hd] initializes the context, or upgrades the context - after a protocol amendment. This function receives as arguments - the context [ctxt] resulting from the application of the block - that triggered the amendment, as well as its header [hd]. This - function should fail if the "protocol stitching", i.e., the - transition from a valid previous protocol to the one being - activated, has not been implemented. *) + (** [init chain_id ctxt hd] initializes the context, or upgrades the + context after a protocol amendment. This function receives as + arguments the [chain_id] of the current chain and the context + [ctxt] resulting from the application of the block that triggered + the amendment, as well as its header [hd]. This function should + fail if the "protocol stitching", i.e., the transition from a + valid previous protocol to the one being activated, has not been + implemented. *) val init : - Context.t -> Block_header.shell_header -> validation_result tzresult Lwt.t + Chain_id.t -> + Context.t -> + Block_header.shell_header -> + validation_result tzresult Lwt.t (** [value_of_key chain_id predecessor_context predecessor_timestamp predecessor_level predecessor_fitness diff --git a/src/lib_shell/block_validator_process.ml b/src/lib_shell/block_validator_process.ml index eb3addbf89e31b25fb74c510252b5e173e1c4df4..a806a24db27d160f2c30d359da1a1c8c05e67af3 100644 --- a/src/lib_shell/block_validator_process.ml +++ b/src/lib_shell/block_validator_process.ml @@ -85,7 +85,8 @@ module type S = sig val commit_genesis : t -> chain_id:Chain_id.t -> Context_hash.t tzresult Lwt.t (** [init_test_chain] must only be called on a forking block. *) - val init_test_chain : t -> Store.Block.t -> Block_header.t tzresult Lwt.t + val init_test_chain : + t -> Chain_id.t -> Store.Block.t -> Block_header.t tzresult Lwt.t val reconfigure_event_logging : t -> Internal_event_unix.Configuration.t -> unit tzresult Lwt.t @@ -341,11 +342,11 @@ module Internal_validator_process = struct ~time:genesis.time ~protocol:genesis.protocol - let init_test_chain validator forking_block = + let init_test_chain validator chain_id forking_block = let open Lwt_result_syntax in let forked_header = Store.Block.header forking_block in let* context = Store.Block.context validator.chain_store forking_block in - Block_validation.init_test_chain context forked_header + Block_validation.init_test_chain chain_id context forked_header let reconfigure_event_logging _ _ = Lwt_result_syntax.return_unit end @@ -801,11 +802,12 @@ module External_validator_process = struct let request = External_validation.Commit_genesis {chain_id} in send_request validator request Context_hash.encoding - let init_test_chain validator forking_block = + let init_test_chain validator chain_id forking_block = let forked_header = Store.Block.header forking_block in let context_hash = forked_header.shell.context in let request = - External_validation.Fork_test_chain {context_hash; forked_header} + External_validation.Fork_test_chain + {chain_id; context_hash; forked_header} in send_request validator request Block_header.encoding @@ -937,9 +939,9 @@ let precheck_block (E {validator_process = (module VP); validator}) chain_store let commit_genesis (E {validator_process = (module VP); validator}) ~chain_id = VP.commit_genesis validator ~chain_id -let init_test_chain (E {validator_process = (module VP); validator}) +let init_test_chain (E {validator_process = (module VP); validator}) chain_id forked_block = - VP.init_test_chain validator forked_block + VP.init_test_chain validator chain_id forked_block let preapply_block (E {validator_process = (module VP); validator} : t) chain_store ~predecessor ~protocol_data ~timestamp operations = diff --git a/src/lib_shell/block_validator_process.mli b/src/lib_shell/block_validator_process.mli index a36b1586f9b900a8f5829070cc31e8288eec0bfd..a726e5d705efa57ec17dc17aa964bd4c4de684cc 100644 --- a/src/lib_shell/block_validator_process.mli +++ b/src/lib_shell/block_validator_process.mli @@ -103,4 +103,5 @@ val precheck_block : val commit_genesis : t -> chain_id:Chain_id.t -> Context_hash.t tzresult Lwt.t (** [init_test_chain] must only be called on a forking block. *) -val init_test_chain : t -> Store.Block.t -> Block_header.t tzresult Lwt.t +val init_test_chain : + t -> Chain_id.t -> Store.Block.t -> Block_header.t tzresult Lwt.t diff --git a/src/lib_shell/chain_validator.ml b/src/lib_shell/chain_validator.ml index 1030481714aa19ef6aece2e373eb09420300a058..c370cf3e73c5eb1c781fc175eb819a7d3b454c3e 100644 --- a/src/lib_shell/chain_validator.ml +++ b/src/lib_shell/chain_validator.ml @@ -259,7 +259,10 @@ let may_switch_test_chain w active_chains spawn_child block = in let bvp = nv.parameters.block_validator_process in let*! r = - Block_validator_process.init_test_chain bvp forking_block + Block_validator_process.init_test_chain + bvp + (Store.Chain.chain_id chain_store) + forking_block in match r with | Ok genesis_header -> diff --git a/src/lib_shell/patch_context.ml b/src/lib_shell/patch_context.ml index bddd500b5ff68b44becb5785fae0fb4796d25763..376d40762f6b18fa378c7334a9962702740dc312 100644 --- a/src/lib_shell/patch_context.ml +++ b/src/lib_shell/patch_context.ml @@ -40,6 +40,7 @@ let patch_context (genesis : Genesis.t) key_json ctxt = let ctxt = Shell_context.wrap_disk_context ctxt in let* {context; _} = Proto.init + (Chain_id.of_block_hash genesis.block) ctxt { level = 0l; diff --git a/src/lib_store/test/alpha_utils.ml b/src/lib_store/test/alpha_utils.ml index 62d69dc936f2657b3eed947422151634b9cb6d6f..6369a58503c47fcefd89166aa203b2f64466de91 100644 --- a/src/lib_store/test/alpha_utils.ml +++ b/src/lib_store/test/alpha_utils.ml @@ -442,7 +442,7 @@ let patch_context ctxt ~json = let* ctxt = Context.add ctxt ["version"] (Bytes.of_string "genesis") in let* ctxt = Context.add ctxt protocol_param_key proto_params in let ctxt = Shell_context.wrap_disk_context ctxt in - let* r = Main.init ctxt shell in + let* r = Main.init Chain_id.zero ctxt shell in match r with | Error e -> failwith "%a" Environment.Error_monad.pp_trace e | Ok {context; _} -> return_ok (Shell_context.unwrap_disk_context context) diff --git a/src/lib_store/test/test_utils.ml b/src/lib_store/test/test_utils.ml index 2c3719ec53888bed3efa9f6debd580050c9bf065..46475d6f80fe4c678c7d68d138460f6920f461aa 100644 --- a/src/lib_store/test/test_utils.ml +++ b/src/lib_store/test/test_utils.ml @@ -168,6 +168,7 @@ let dummy_patch_context ctxt = let ctxt = Tezos_shell_context.Shell_context.wrap_disk_context ctxt in let*! res = Protocol.Main.init + Chain_id.zero ctxt { level = 0l; diff --git a/src/lib_validation/block_validation.ml b/src/lib_validation/block_validation.ml index 0114db98990241d034a52961b19b16d102066b6f..a95a6153b1c58e60f17eff45a03e932a95150647 100644 --- a/src/lib_validation/block_validation.ml +++ b/src/lib_validation/block_validation.ml @@ -154,7 +154,7 @@ let update_testchain_status ctxt ~predecessor_hash timestamp = ctxt (Running {chain_id; genesis; protocol; expiration}) -let init_test_chain ctxt forked_header = +let init_test_chain chain_id ctxt forked_header = let open Lwt_result_syntax in let*! tc = Context.get_test_chain ctxt in match tc with @@ -172,7 +172,7 @@ let init_test_chain ctxt forked_header = Proto_test.set_log_message_consumer (Protocol_logging.make_log_message_consumer ()) ; let* {context = test_ctxt; _} = - Proto_test.init test_ctxt forked_header.Block_header.shell + Proto_test.init chain_id test_ctxt forked_header.Block_header.shell in let test_ctxt = Shell_context.unwrap_disk_context test_ctxt in let*! test_ctxt = Context.add_test_chain test_ctxt Not_running in @@ -546,8 +546,9 @@ module Make (Proto : Registered_protocol.T) = struct in return (validation_result, block_data, ops_metadata)) - let may_init_new_protocol new_protocol (block_header : Proto.block_header) - block_hash (validation_result : Environment_context.validation_result) = + let may_init_new_protocol chain_id new_protocol + (block_header : Proto.block_header) block_hash + (validation_result : Environment_context.validation_result) = let open Lwt_result_syntax in if Protocol_hash.equal new_protocol Proto.hash then return (validation_result, Proto.environment_version) @@ -569,7 +570,7 @@ module Make (Proto : Registered_protocol.T) = struct NewProto.set_log_message_consumer (Protocol_logging.make_log_message_consumer ()) ; let* validation_result = - NewProto.init validation_result.context block_header.shell + NewProto.init chain_id validation_result.context block_header.shell in return (validation_result, NewProto.environment_version) @@ -668,6 +669,7 @@ module Make (Proto : Registered_protocol.T) = struct in let* validation_result, new_protocol_env_version = may_init_new_protocol + chain_id new_protocol block_header block_hash @@ -747,6 +749,7 @@ module Make (Proto : Registered_protocol.T) = struct let*! new_protocol = Context.get_protocol context in let* _validation_result, new_protocol_env_version = may_init_new_protocol + chain_id new_protocol block_header block_hash @@ -1015,7 +1018,7 @@ module Make (Proto : Registered_protocol.T) = struct NewProto.set_log_message_consumer (Protocol_logging.make_log_message_consumer ()) ; let* validation_result = - NewProto.init validation_result.context shell_header + NewProto.init chain_id validation_result.context shell_header in let (Environment_context.Context.Context {cache; _}) = validation_result.context diff --git a/src/lib_validation/block_validation.mli b/src/lib_validation/block_validation.mli index b3e735bafa8fe205b7a326ff881751c75030615b..9d29f56ee094127dafb5a6a4f4353eb9205df2c4 100644 --- a/src/lib_validation/block_validation.mli +++ b/src/lib_validation/block_validation.mli @@ -60,7 +60,7 @@ val check_proto_environment_version_increasing : (** [init_test_chain] must only be called on a forking block. *) val init_test_chain : - Context.t -> Block_header.t -> Block_header.t tzresult Lwt.t + Chain_id.t -> Context.t -> Block_header.t -> Block_header.t tzresult Lwt.t type operation_metadata = Metadata of Bytes.t | Too_large_metadata diff --git a/src/lib_validation/external_validation.ml b/src/lib_validation/external_validation.ml index bf97c9524fd314faefb5421ad7f4df4084d27449..f31d0bcfe3a8e22e835677292f69fad95f1cacc4 100644 --- a/src/lib_validation/external_validation.ml +++ b/src/lib_validation/external_validation.ml @@ -70,6 +70,7 @@ type request = } | Commit_genesis of {chain_id : Chain_id.t} | Fork_test_chain of { + chain_id : Chain_id.t; context_hash : Context_hash.t; forked_header : Block_header.t; } @@ -352,15 +353,16 @@ let request_encoding = case (Tag 3) ~title:"fork_test_chain" - (obj2 + (obj3 + (req "chain_id" Chain_id.encoding) (req "context_hash" Context_hash.encoding) (req "forked_header" Block_header.encoding)) (function - | Fork_test_chain {context_hash; forked_header} -> - Some (context_hash, forked_header) + | Fork_test_chain {chain_id; context_hash; forked_header} -> + Some (chain_id, context_hash, forked_header) | _ -> None) - (fun (context_hash, forked_header) -> - Fork_test_chain {context_hash; forked_header}); + (fun (chain_id, context_hash, forked_header) -> + Fork_test_chain {chain_id; context_hash; forked_header}); case (Tag 4) ~title:"terminate" diff --git a/src/lib_validation/external_validation.mli b/src/lib_validation/external_validation.mli index 1de97ae4639eb544b5aa3b416c61121e523683ed..4fd1ccd55fdf5a1a301afa169c0e8ab24831a91d 100644 --- a/src/lib_validation/external_validation.mli +++ b/src/lib_validation/external_validation.mli @@ -70,6 +70,7 @@ type request = } | Commit_genesis of {chain_id : Chain_id.t} | Fork_test_chain of { + chain_id : Chain_id.t; context_hash : Context_hash.t; forked_header : Block_header.t; } diff --git a/src/proto_alpha/lib_client/mockup.ml b/src/proto_alpha/lib_client/mockup.ml index 0ab6cdc269cd9e16416339fc2b1ad6e472774536..646a1db0cb794a93c67265f8b6a2c70e067ad72f 100644 --- a/src/proto_alpha/lib_client/mockup.ml +++ b/src/proto_alpha/lib_client/mockup.ml @@ -1336,7 +1336,7 @@ let initial_context chain_id (header : Block_header.shell_header) add ctxt ["protocol_parameters"] proto_params) >>= fun ctxt -> Protocol.Environment.Updater.activate ctxt Protocol.hash >>= fun ctxt -> - Protocol.Main.init ctxt header >|= Protocol.Environment.wrap_tzresult + Protocol.Main.init chain_id ctxt header >|= Protocol.Environment.wrap_tzresult >>=? fun {context; _} -> let ({ timestamp = predecessor_timestamp; @@ -1531,7 +1531,8 @@ let migrate : rpc_context in Protocol.Environment.Updater.activate context Protocol.hash >>= fun context -> - Protocol.Main.init context block_header >|= Protocol.Environment.wrap_tzresult + Protocol.Main.init chain context block_header + >|= Protocol.Environment.wrap_tzresult >>=? fun {context; _} -> let rpc_context = Tezos_protocol_environment.{block_hash; block_header; context} diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index 3e4a57cb14e75633f90e02e2a5f05fb7d0ec0000..332549e2def51a399db6bb0db6f77e22b132a97c 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -3425,6 +3425,7 @@ end (** Create an [Alpha_context.t] from an untyped context (first block in the chain only). *) val prepare_first_block : + Chain_id.t -> Context.t -> typecheck: (context -> diff --git a/src/proto_alpha/lib_protocol/init_storage.ml b/src/proto_alpha/lib_protocol/init_storage.ml index 2c5d888317eaf06899d5eb546c17829b50f9a957..258702c6e1f02a990bd7d7de728d54bae8edf4d5 100644 --- a/src/proto_alpha/lib_protocol/init_storage.ml +++ b/src/proto_alpha/lib_protocol/init_storage.ml @@ -58,7 +58,7 @@ See !3730 for an example. *) -let prepare_first_block ctxt ~typecheck ~level ~timestamp = +let prepare_first_block _chain_id ctxt ~typecheck ~level ~timestamp = Raw_context.prepare_first_block ~level ~timestamp ctxt >>=? fun (previous_protocol, ctxt) -> let parametric = Raw_context.constants ctxt in diff --git a/src/proto_alpha/lib_protocol/init_storage.mli b/src/proto_alpha/lib_protocol/init_storage.mli index 0b71d116c541a90afb2a2476b122bea7e529e56d..bb803694bc090b2157a14a754fc7e7b9eb25b38d 100644 --- a/src/proto_alpha/lib_protocol/init_storage.mli +++ b/src/proto_alpha/lib_protocol/init_storage.mli @@ -32,6 +32,7 @@ (* This is the genesis protocol: initialise the state *) val prepare_first_block : + Chain_id.t -> Context.t -> typecheck: (Raw_context.t -> diff --git a/src/proto_alpha/lib_protocol/main.ml b/src/proto_alpha/lib_protocol/main.ml index f7840ac0b33ece97129da38aa2f2a157008c7f1a..3a1dfce1293978acc75542ebff3c5b971593cf5d 100644 --- a/src/proto_alpha/lib_protocol/main.ml +++ b/src/proto_alpha/lib_protocol/main.ml @@ -728,7 +728,7 @@ let relative_position_within_block op1 op2 = | Cons (Manager_operation op1, _), Cons (Manager_operation op2, _) -> Z.compare op1.counter op2.counter -let init ctxt block_header = +let init chain_id ctxt block_header = let level = block_header.Block_header.level in let timestamp = block_header.timestamp in let typecheck (ctxt : Alpha_context.context) (script : Alpha_context.Script.t) @@ -773,7 +773,7 @@ let init ctxt block_header = ~round:Alpha_context.Round.zero ~predecessor_round:Alpha_context.Round.zero in - Alpha_context.prepare_first_block ~typecheck ~level ~timestamp ctxt + Alpha_context.prepare_first_block chain_id ~typecheck ~level ~timestamp ctxt >>=? fun ctxt -> let cache_nonce = cache_nonce_from_block_header diff --git a/src/proto_alpha/lib_protocol/test/helpers/block.ml b/src/proto_alpha/lib_protocol/test/helpers/block.ml index f705a39183d1acc08cb7d0a6050038791e855a29..9e35b868f7f93f65c92f72da0348df8f72631529 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/block.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/block.ml @@ -295,16 +295,16 @@ let prepare_main_init_params ?bootstrap_contracts commitments constants add empty ["version"] (Bytes.of_string "genesis") >>= fun ctxt -> add ctxt protocol_param_key proto_params) -let initial_context ?(commitments = []) ?bootstrap_contracts constants header - initial_accounts = +let initial_context ?(commitments = []) ?bootstrap_contracts chain_id constants + header initial_accounts = prepare_main_init_params ?bootstrap_contracts commitments constants initial_accounts >>= fun ctxt -> - Main.init ctxt header >|= Environment.wrap_tzresult >|=? fun {context; _} -> - context + Main.init chain_id ctxt header >|= Environment.wrap_tzresult + >|=? fun {context; _} -> context let initial_alpha_context ?(commitments = []) constants (block_header : Block_header.shell_header) initial_accounts = @@ -344,7 +344,12 @@ let initial_alpha_context ?(commitments = []) constants in (({script with storage}, lazy_storage_diff), ctxt) in - Alpha_context.prepare_first_block ~typecheck ~level ~timestamp ctxt + Alpha_context.prepare_first_block + ~typecheck + ~level + ~timestamp + Chain_id.zero + ctxt >|= Environment.wrap_tzresult let genesis_with_parameters parameters = @@ -384,7 +389,9 @@ let genesis_with_parameters parameters = add empty ["version"] (Bytes.of_string "genesis") >>= fun ctxt -> add ctxt protocol_param_key proto_params) >>= fun ctxt -> - Main.init ctxt shell >|= Environment.wrap_tzresult >|=? fun {context; _} -> + let chain_id = Chain_id.of_block_hash hash in + Main.init chain_id ctxt shell >|= Environment.wrap_tzresult + >|=? fun {context; _} -> { hash; header = {shell; protocol_data = {contents; signature = Signature.zero}}; @@ -563,6 +570,7 @@ let genesis ?commitments ?consensus_threshold ?min_proposal_quorum initial_context ?commitments ?bootstrap_contracts + (Chain_id.of_block_hash hash) constants shell initial_accounts diff --git a/src/proto_alpha/lib_protocol/test/helpers/context.ml b/src/proto_alpha/lib_protocol/test/helpers/context.ml index e3eb5edf2abf1c013889ab4302ee79965241e2f4..c5f7874c415c3546b7add44c289c7db417d695c3 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/context.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/context.ml @@ -502,6 +502,7 @@ let default_raw_context () = >>= fun context -> let typecheck ctxt script_repr = return ((script_repr, None), ctxt) in Init_storage.prepare_first_block + Chain_id.zero context ~level:0l ~timestamp:(Time.Protocol.of_seconds 1643125688L) diff --git a/src/proto_demo_counter/lib_protocol/main.ml b/src/proto_demo_counter/lib_protocol/main.ml index 20eddc31662ea40583aeee10f23d479a17e4e3c6..cf8694b8dd41d1844b0598b62490504928f050af 100644 --- a/src/proto_demo_counter/lib_protocol/main.ml +++ b/src/proto_demo_counter/lib_protocol/main.ml @@ -178,7 +178,7 @@ let get_init_state context : State.t tzresult Lwt.t = | Some state -> return state ) -let init context block_header = +let init _chain_id context block_header = let open Block_header in let fitness = block_header.fitness in Logging.log Notice "init: fitness = %a%!" Fitness.pp fitness ; diff --git a/src/proto_demo_noops/lib_protocol/main.ml b/src/proto_demo_noops/lib_protocol/main.ml index 0e963c033dad24a2bafe78de3311cffda45f8fe5..467f8f8eebe4b1cd875afbad53115929e0f40905 100644 --- a/src/proto_demo_noops/lib_protocol/main.ml +++ b/src/proto_demo_noops/lib_protocol/main.ml @@ -128,7 +128,7 @@ let finalize_block state _ = }, () ) -let init context block_header = +let init _chain_id context block_header = let open Block_header in let fitness = block_header.fitness in Context.Cache.set_cache_layout context [] >>= fun context ->