From 1c0201c80ac97ef2a49708fc0473e392f107d29d Mon Sep 17 00:00:00 2001 From: Guillaume Genestier Date: Thu, 9 Oct 2025 15:40:53 +0200 Subject: [PATCH 1/3] Proto/DAL: Add the storage of the attestation for previous protocol Co-Authored-By: Eugen Zalinescu (eugen.zalinescu@nomadiclabs.com) --- src/proto_alpha/lib_protocol/alpha_context.ml | 4 ++++ src/proto_alpha/lib_protocol/alpha_context.mli | 4 ++++ src/proto_alpha/lib_protocol/init_storage.ml | 13 +++++++++++++ src/proto_alpha/lib_protocol/storage.ml | 11 +++++++++++ src/proto_alpha/lib_protocol/storage.mli | 5 +++++ 5 files changed, 37 insertions(+) diff --git a/src/proto_alpha/lib_protocol/alpha_context.ml b/src/proto_alpha/lib_protocol/alpha_context.ml index dcefa6a73362..383d61425c1f 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.ml +++ b/src/proto_alpha/lib_protocol/alpha_context.ml @@ -169,6 +169,10 @@ module Dal = struct module Slots_history = Dal_slot_repr.History module Slots_storage = Dal_slot_storage module Delegate = Dal_already_denounced_storage + + module Prev_attestation_lag = struct + let get = Storage.Dal.Prev_attestation_lag.get + end end module Dal_errors = Dal_errors_repr diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index a233813c9ab4..acb01c813672 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -3200,6 +3200,10 @@ module Dal : sig (** See {!Dal_already_denounced_storage.is_denounced}. *) val is_denounced : context -> public_key_hash -> bool Lwt.t end + + module Prev_attestation_lag : sig + val get : context -> int tzresult Lwt.t + end end (** This module re-exports definitions from {!Dal_errors_repr}. *) diff --git a/src/proto_alpha/lib_protocol/init_storage.ml b/src/proto_alpha/lib_protocol/init_storage.ml index 2eeb17665d9a..288367f02460 100644 --- a/src/proto_alpha/lib_protocol/init_storage.ml +++ b/src/proto_alpha/lib_protocol/init_storage.ml @@ -238,6 +238,19 @@ let prepare_first_block chain_id ctxt ~typecheck_smart_contract let* ctxt = Sc_rollup_refutation_storage.migrate_clean_refutation_games ctxt in + let* ctxt = + match previous_proto_constants with + | Some previous_proto_constants -> + let*! ctxt = + Storage.Dal.Prev_attestation_lag.add + ctxt + previous_proto_constants.dal.attestation_lag + in + return ctxt + | None -> + (* unreachable because the previous protocol is not Genesis *) + assert false + in return (ctxt, []) (* End of alpha predecessor stitching. Comment used for automatic snapshot *) in diff --git a/src/proto_alpha/lib_protocol/storage.ml b/src/proto_alpha/lib_protocol/storage.ml index 4ffa4b13f2ff..0850624c0268 100644 --- a/src/proto_alpha/lib_protocol/storage.ml +++ b/src/proto_alpha/lib_protocol/storage.ml @@ -2379,6 +2379,17 @@ module Dal = struct let encoding = Data_encoding.empty end) + + module Prev_attestation_lag = + Make_single_data_storage (Registered) (Raw_context) + (struct + let name = ["dal_prev_attestation_lag"] + end) + (struct + type t = int + + let encoding = Data_encoding.uint8 + end) end module Zk_rollup = struct diff --git a/src/proto_alpha/lib_protocol/storage.mli b/src/proto_alpha/lib_protocol/storage.mli index 443db5c16f30..d37fbd9241de 100644 --- a/src/proto_alpha/lib_protocol/storage.mli +++ b/src/proto_alpha/lib_protocol/storage.mli @@ -1129,6 +1129,11 @@ module Dal : sig with type t := Raw_context.t and type key = Signature.Public_key_hash.t and type value = unit + + (** This stores the value of [attestation_lag] at the previous protocol. + Useful during protocol migration when the parameter's value changes. *) + module Prev_attestation_lag : + Single_data_storage with type t := Raw_context.t and type value = int end module Zk_rollup : sig -- GitLab From 5cd5943772ff268744a816b32eba35fdca40c78d Mon Sep 17 00:00:00 2001 From: Guillaume Genestier Date: Thu, 9 Oct 2025 15:41:30 +0200 Subject: [PATCH 2/3] Proto/Alpha: Use the previous attestation_lag in the denunciation of entrapment evidence --- src/proto_alpha/lib_protocol/validate.ml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/proto_alpha/lib_protocol/validate.ml b/src/proto_alpha/lib_protocol/validate.ml index 1b20a4502e52..666f3785c108 100644 --- a/src/proto_alpha/lib_protocol/validate.ml +++ b/src/proto_alpha/lib_protocol/validate.ml @@ -2487,8 +2487,11 @@ module Anonymous = struct shard_owner = shard_owner.delegate; }) in - let attestation_lag = - (Constants.parametric vi.ctxt).dal.attestation_lag + let* attestation_lag = + let* migration_level = First_level_of_protocol.get ctxt in + if Raw_level.(level.level < migration_level) then + Alpha_context.Dal.Prev_attestation_lag.get ctxt + else return (Constants.parametric vi.ctxt).dal.attestation_lag in let* published_level = match Raw_level.(sub (succ level.level) attestation_lag) with -- GitLab From 872cb3757edb2163f96b82c015effa814399a155 Mon Sep 17 00:00:00 2001 From: Eugen Zalinescu Date: Sat, 18 Oct 2025 09:52:02 +0200 Subject: [PATCH 3/3] Scripts: update scripts/patch-profiler-proto.sh --- scripts/profile_alpha.patch | 44 ++++++++++--------------------------- 1 file changed, 12 insertions(+), 32 deletions(-) diff --git a/scripts/profile_alpha.patch b/scripts/profile_alpha.patch index f9f985d2db03..67832359b5c4 100644 --- a/scripts/profile_alpha.patch +++ b/scripts/profile_alpha.patch @@ -47,7 +47,7 @@ index 0078267eca..a301359869 100644 + let+ ctxt = Bootstrap.cycle_end ctxt last_cycle in + (ctxt, balance_updates, deactivated)) + [@profiler.record_s {verbosity = Notice} "delegate end cycle"] - + let apply_liquidity_baking_subsidy ctxt ~per_block_vote = let open Lwt_result_syntax in diff --git a/src/proto_alpha/lib_protocol/baking.ml b/src/proto_alpha/lib_protocol/baking.ml @@ -69,7 +69,7 @@ index 1388bc3ea7..ae55ed9ae2 100644 in - return (ctxt, map) + return (ctxt, map)) [@profiler.record_s {verbosity = Notice} "attesting_rights"] - + let incr_slot att_rights = let one = Attesting_power.make ~slots:1 ~stake:0L in diff --git a/src/proto_alpha/lib_protocol/delegate_cycles.ml b/src/proto_alpha/lib_protocol/delegate_cycles.ml @@ -197,10 +197,10 @@ index 7fea31a9fe..75d43668c3 100644 (flags (:standard) diff --git a/src/proto_alpha/lib_protocol/init_storage.ml b/src/proto_alpha/lib_protocol/init_storage.ml -index 2eeb17665d..1202879935 100644 +index 288367f0246..2cfdd533ea7 100644 --- a/src/proto_alpha/lib_protocol/init_storage.ml +++ b/src/proto_alpha/lib_protocol/init_storage.ml -@@ -221,31 +221,55 @@ let prepare_first_block chain_id ctxt ~typecheck_smart_contract +@@ -221,22 +221,38 @@ let prepare_first_block chain_id ctxt ~typecheck_smart_contract (* Start of Alpha stitching. Comment used for automatic snapshot *) | Alpha -> let* ctxt = @@ -241,27 +241,8 @@ index 2eeb17665d..1202879935 100644 + {verbosity = Notice} + "Sc_rollup_refutation_storage.migrate_clean_refutation_games"]) in - return (ctxt, []) - (* End of alpha predecessor stitching. Comment used for automatic snapshot *) - in - let* ctxt = -- List.fold_left_es patch_script ctxt Legacy_script_patches.addresses_to_patch -+ (List.fold_left_es -+ patch_script -+ ctxt -+ Legacy_script_patches.addresses_to_patch -+ [@profiler.record_s {verbosity = Notice} "patch_script"]) - in - let*? balance_updates = Receipt_repr.group_balance_updates balance_updates in - let*! ctxt = -- Storage.Pending_migration.Balance_updates.add ctxt balance_updates -+ (Storage.Pending_migration.Balance_updates.add -+ ctxt -+ balance_updates -+ [@profiler.record_s -+ {verbosity = Notice} "Storage.Pending_migration.Balance_updates.add"]) - in - return ctxt + let* ctxt = + match previous_proto_constants with diff --git a/src/proto_alpha/lib_protocol/raw_context.ml b/src/proto_alpha/lib_protocol/raw_context.ml index c501d7fc16..00e5338465 100644 --- a/src/proto_alpha/lib_protocol/raw_context.ml @@ -280,7 +261,7 @@ index c501d7fc16..00e5338465 100644 + ~all_bakers_attest_first_level:None [@profiler.record_s {verbosity = Notice} "Prepare"]) in (previous_proto, previous_proto_constants, ctxt) - + diff --git a/src/proto_alpha/lib_protocol/script_cache.ml b/src/proto_alpha/lib_protocol/script_cache.ml index 35cc6b5178..5c679ad606 100644 --- a/src/proto_alpha/lib_protocol/script_cache.ml @@ -308,7 +289,7 @@ index 35cc6b5178..5c679ad606 100644 + in + return (ctxt, identifier, Some (unparsed_script, script_ir))) + [@profiler.record_s {verbosity = Notice} "cache_miss"]) - + let update ctxt identifier updated_script approx_size = Cache.update ctxt identifier (Some (updated_script, approx_size)) diff --git a/src/proto_alpha/lib_protocol/script_interpreter.ml b/src/proto_alpha/lib_protocol/script_interpreter.ml @@ -344,7 +325,7 @@ index e098905296..54b1e80d85 100644 }, - ctxt ) + ctxt )) [@profiler.record_s {verbosity = Notice} "execute"] - + let execute_with_typed_parameter ?logger ctxt ~cached_script mode step_constants ~script ~entrypoint ~parameter_ty ~location ~parameter ~internal = diff --git a/src/proto_alpha/lib_protocol/script_ir_translator.ml b/src/proto_alpha/lib_protocol/script_ir_translator.ml @@ -383,7 +364,7 @@ index b91d2d8711..60727fae94 100644 ( Ex_script (Script @@ -5926,15 +5930,15 @@ let list_of_big_map_ids ids = - + let parse_data ~elab_conf ctxt ~allow_forged_tickets ~allow_forged_lazy_storage_id ty t = - parse_data @@ -404,9 +385,8 @@ index b91d2d8711..60727fae94 100644 + ctxt + ty + t [@profiler.record_s {verbosity = Notice} "parse_data"]) - + let parse_view ~elab_conf ctxt ty view = parse_view ~unparse_code_rec ~elab_conf ctxt ty view --- +-- 2.51.0 - -- GitLab