From 032b6f52c5c00c748f224a03c714c899fe966c5f Mon Sep 17 00:00:00 2001 From: Pierre Boutillier Date: Mon, 12 Sep 2022 11:07:04 +0200 Subject: [PATCH 1/3] Proto/Migration: lower vdf_difficulty on Ghostnet On Ghostnet, block are produce twice more often and cycles are twice smaller so overall you have 4 time less time to solve the vdf puzzle --- src/proto_alpha/lib_protocol/init_storage.ml | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/proto_alpha/lib_protocol/init_storage.ml b/src/proto_alpha/lib_protocol/init_storage.ml index e2e048a37e62..6dbc89e431f9 100644 --- a/src/proto_alpha/lib_protocol/init_storage.ml +++ b/src/proto_alpha/lib_protocol/init_storage.ml @@ -101,8 +101,19 @@ let patch_script (address, hash, patched_code) ctxt = context." address ; return ctxt +module Patch_vdf_difficulty_for_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 prepare_first_block _chain_id ctxt ~typecheck ~level ~timestamp = + let patch_constant chain_id ctxt = + 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}) + else Lwt.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,6 +177,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 -> + Patch_vdf_difficulty_for_ghostnet.patch_constant chain_id ctxt >>= fun ctxt -> return (ctxt, [])) >>=? fun (ctxt, balance_updates) -> List.fold_right_es patch_script Legacy_script_patches.addresses_to_patch ctxt -- GitLab From 2073d35b0288aae1961acdd235ccc04919f4d5d3 Mon Sep 17 00:00:00 2001 From: Pierre Boutillier Date: Thu, 22 Sep 2022 08:51:53 +0200 Subject: [PATCH 2/3] Proto/Migration: Reset voting period on Ghostnet --- src/proto_alpha/lib_protocol/init_storage.ml | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/proto_alpha/lib_protocol/init_storage.ml b/src/proto_alpha/lib_protocol/init_storage.ml index 6dbc89e431f9..3af98031d1c1 100644 --- a/src/proto_alpha/lib_protocol/init_storage.ml +++ b/src/proto_alpha/lib_protocol/init_storage.ml @@ -101,16 +101,25 @@ let patch_script (address, hash, patched_code) ctxt = context." address ; return ctxt -module Patch_vdf_difficulty_for_ghostnet = struct + +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_constant chain_id ctxt = + 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}) - else Lwt.return ctxt + >>= 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 = @@ -177,8 +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 -> - Patch_vdf_difficulty_for_ghostnet.patch_constant chain_id 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 -> -- GitLab From c18ef9eedcc2caddf68bad5a150af333c4da6403 Mon Sep 17 00:00:00 2001 From: Pierre Boutillier Date: Thu, 29 Sep 2022 18:39:44 +0200 Subject: [PATCH 3/3] Tezt: Adapt ghostnet migration test to vote reset --- tezt/tests/ghostnet_dictator_migration.ml | 47 +++++++++++++++-------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/tezt/tests/ghostnet_dictator_migration.ml b/tezt/tests/ghostnet_dictator_migration.ml index 1b19650891ba..660521f74f01 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 = -- GitLab