diff --git a/src/proto_alpha/lib_protocol/init_storage.ml b/src/proto_alpha/lib_protocol/init_storage.ml index e2e048a37e6200b355448582ff551cc25c609167..3af98031d1c17536ec0283f4bce17aa4a6d939f3 100644 --- a/src/proto_alpha/lib_protocol/init_storage.ml +++ b/src/proto_alpha/lib_protocol/init_storage.ml @@ -102,7 +102,27 @@ let patch_script (address, hash, patched_code) ctxt = address ; return ctxt -let prepare_first_block _chain_id ctxt ~typecheck ~level ~timestamp = +module Patch_ghostnet = struct + let ghostnet_id = + let id = Chain_id.of_b58check_exn "NetXnHfVqm9iesp" in + if Chain_id.equal id Constants_repr.mainnet_id then assert false else id + + let patch chain_id ctxt level = + if Chain_id.equal chain_id ghostnet_id then + Raw_context.patch_constants ctxt (fun c -> + {c with vdf_difficulty = Int64.div c.vdf_difficulty 4L}) + >>= fun ctxt -> + Voting_period_storage.get_current ctxt >>=? fun current -> + let level = Raw_level_repr.to_int32 level in + if Compare.Int32.equal current.start_position level then + (* do nothing; the migration happens at the end of a voting + period, so the period has already been reset *) + return ctxt + else Voting_period_storage.reset ctxt + else return ctxt +end + +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 @@ -166,7 +186,7 @@ let prepare_first_block _chain_id ctxt ~typecheck ~level ~timestamp = Storage.Tenderbake.First_level_of_protocol.update ctxt level >>=? fun ctxt -> Delegate_cycles.Migration_from_Kathmandu.update ctxt >>=? fun ctxt -> - return (ctxt, [])) + Patch_ghostnet.patch chain_id ctxt level >>=? fun ctxt -> return (ctxt, [])) >>=? fun (ctxt, balance_updates) -> List.fold_right_es patch_script Legacy_script_patches.addresses_to_patch ctxt >>=? fun ctxt -> diff --git a/tezt/tests/ghostnet_dictator_migration.ml b/tezt/tests/ghostnet_dictator_migration.ml index 1b19650891bac47a618aac084c0fed891da65241..660521f74f0117c379db1fca960657148031d5c3 100644 --- a/tezt/tests/ghostnet_dictator_migration.ml +++ b/tezt/tests/ghostnet_dictator_migration.ml @@ -53,7 +53,7 @@ let check_dictator client expected_dictator = unit let init chain_id ~from_protocol ~to_protocol = - let user_activated_upgrades = [(3, to_protocol)] in + let user_activated_upgrades = [(11, to_protocol)] in let patch_config, timestamp = match chain_id with | Chain_id_mainnet -> @@ -107,33 +107,46 @@ let register_migration_test chain_id = @@ fun to_protocol -> may_apply (Protocol.previous_protocol to_protocol) @@ fun from_protocol -> let* node, client = init chain_id ~from_protocol ~to_protocol in - let* () = bake node client in - let* () = bake node client in + let* () = repeat 10 (fun () -> bake node client) in Log.info "Checking that migration occurred..." ; let* () = Voting.check_protocols client (Protocol.hash from_protocol, Protocol.hash to_protocol) in - let expected_dictator, expected_remaining = + let expected_dictator, expected_period = match chain_id with | Chain_id_ghostnet when to_protocol = Kathmandu -> - (Some "tz1Xf8zdT3DbAX9cHw3c3CXh79rc4nK4gCe8", 1) - | _ -> (None, 5) + ( Some "tz1Xf8zdT3DbAX9cHw3c3CXh79rc4nK4gCe8", + { + Voting.index = 1; + kind = Proposal; + start_position = 8; + position = 2; + remaining = 1; + } ) + | Chain_id_ghostnet when to_protocol = Alpha -> + ( None, + { + Voting.index = 1; + kind = Proposal; + start_position = 3; + position = 7; + remaining = 0; + } ) + | _ -> + ( None, + { + Voting.index = 1; + kind = Proposal; + start_position = 8; + position = 2; + remaining = 5; + } ) in let* () = check_dictator client expected_dictator in - let* () = - Voting.check_current_period - client - { - Voting.index = 0; - kind = Proposal; - start_position = 0; - position = 2; - remaining = expected_remaining; - } - in + let* () = Voting.check_current_period client expected_period in return () let register ~protocols =