From e7241c9f1cff4e25de740bfd63ec676e50a76435 Mon Sep 17 00:00:00 2001 From: Alain Mebsout Date: Wed, 5 Jun 2024 01:51:45 +0200 Subject: [PATCH 1/6] Rollup node: use reference for current protocol This adds an indirection to prevent the read-only node contexts to have a copy of the current protocol instead. (cherry picked from commit 4b88d90935128b0c5c307baa530ad2e8687d0fbd) --- src/lib_smart_rollup_node/node_context.ml | 4 ++-- src/lib_smart_rollup_node/node_context.mli | 2 +- .../node_context_loader.ml | 6 +++--- src/lib_smart_rollup_node/outbox_execution.ml | 6 +++--- src/lib_smart_rollup_node/protocol_plugins.ml | 5 +++-- src/lib_smart_rollup_node/publisher.ml | 4 ++-- src/lib_smart_rollup_node/rollup_node_daemon.ml | 17 ++++++++--------- src/lib_smart_rollup_node/rpc_directory.ml | 3 ++- .../test/helpers/helpers.ml | 6 ++++-- .../lib_sc_rollup_node/pvm_plugin.ml | 2 +- .../lib_sc_rollup_node/pvm_plugin.ml | 2 +- .../lib_sc_rollup_node/pvm_plugin.ml | 2 +- .../lib_sc_rollup_node/pvm_plugin.ml | 2 +- 13 files changed, 32 insertions(+), 29 deletions(-) diff --git a/src/lib_smart_rollup_node/node_context.ml b/src/lib_smart_rollup_node/node_context.ml index c6f36a2ac2e3..b5e076cb8e68 100644 --- a/src/lib_smart_rollup_node/node_context.ml +++ b/src/lib_smart_rollup_node/node_context.ml @@ -115,7 +115,7 @@ type 'a t = { private_info : ('a, private_info option) Reference.t; kernel_debug_logger : debug_logger; finaliser : unit -> unit Lwt.t; - mutable current_protocol : current_protocol; + current_protocol : current_protocol Reference.rw; global_block_watcher : Sc_rollup_block.t Lwt_watcher.input; sync : sync_info; } @@ -209,7 +209,7 @@ let checkout_context node_ctxt block_hash = let dal_supported node_ctxt = node_ctxt.dal_cctxt <> None - && node_ctxt.current_protocol.constants.dal.feature_enable + && (Reference.get node_ctxt.current_protocol).constants.dal.feature_enable let readonly (node_ctxt : _ t) = { diff --git a/src/lib_smart_rollup_node/node_context.mli b/src/lib_smart_rollup_node/node_context.mli index f28826f182d8..eb4340b092e0 100644 --- a/src/lib_smart_rollup_node/node_context.mli +++ b/src/lib_smart_rollup_node/node_context.mli @@ -129,7 +129,7 @@ type 'a t = { (** Logger used for writing [kernel_debug] messages *) finaliser : unit -> unit Lwt.t; (** Aggregation of finalisers to run when the node context closes *) - mutable current_protocol : current_protocol; + current_protocol : current_protocol Reference.rw; (** Information about the current protocol. This value is changed in place on protocol upgrades. *) global_block_watcher : Sc_rollup_block.t Lwt_watcher.input; diff --git a/src/lib_smart_rollup_node/node_context_loader.ml b/src/lib_smart_rollup_node/node_context_loader.ml index ec867e68b63e..0df4b2652f5b 100644 --- a/src/lib_smart_rollup_node/node_context_loader.ml +++ b/src/lib_smart_rollup_node/node_context_loader.ml @@ -196,7 +196,7 @@ let init (cctxt : #Client_context.full) ~data_dir ~irmin_cache_size context; kernel_debug_logger; finaliser = kernel_debug_finaliser; - current_protocol; + current_protocol = Reference.new_ current_protocol; global_block_watcher; sync; } @@ -328,7 +328,7 @@ module For_snapshots = struct context; kernel_debug_logger = (fun _ -> Lwt.return_unit); finaliser = Lwt.return; - current_protocol; + current_protocol = Reference.new_ current_protocol; global_block_watcher; sync; } @@ -441,7 +441,7 @@ module Internal_for_tests = struct unsafe_patches; injector_retention_period = 0; block_finality_time = 2; - current_protocol; + current_protocol = Reference.new_ current_protocol; lockfile; store; context; diff --git a/src/lib_smart_rollup_node/outbox_execution.ml b/src/lib_smart_rollup_node/outbox_execution.ml index 3d292d73ca03..aeff4abfd3f3 100644 --- a/src/lib_smart_rollup_node/outbox_execution.ml +++ b/src/lib_smart_rollup_node/outbox_execution.ml @@ -52,13 +52,13 @@ let executable_whitelist_update_message (node_ctxt : _ Node_context.t) = let*:* Node_context.{last_outbox_level_searched; last_whitelist_update} = Reference.get node_ctxt.private_info in + let current_protocol = Reference.get node_ctxt.current_protocol in let commitment_period = Int32.of_int - node_ctxt.Node_context.current_protocol.constants.sc_rollup - .commitment_period_in_blocks + current_protocol.constants.sc_rollup.commitment_period_in_blocks in let max_cemented_commitment = - node_ctxt.Node_context.current_protocol.constants.sc_rollup + current_protocol.constants.sc_rollup .max_number_of_stored_cemented_commitments in let rec fold_over_outbox_level_in_commmitment ~cemented_commitment_hash diff --git a/src/lib_smart_rollup_node/protocol_plugins.ml b/src/lib_smart_rollup_node/protocol_plugins.ml index d976a2a57092..6ec4a550fd19 100644 --- a/src/lib_smart_rollup_node/protocol_plugins.ml +++ b/src/lib_smart_rollup_node/protocol_plugins.ml @@ -118,8 +118,9 @@ let constants_cache = let get_constants_of_protocol ?level (node_ctxt : _ Node_context.t) protocol_hash = let open Lwt_result_syntax in - if Protocol_hash.(protocol_hash = node_ctxt.current_protocol.hash) then - return node_ctxt.current_protocol.constants + let current_protocol = Reference.get node_ctxt.current_protocol in + if Protocol_hash.(protocol_hash = current_protocol.hash) then + return current_protocol.constants else let retrieve protocol_hash = let*? plugin = proto_plugin_for_protocol protocol_hash in diff --git a/src/lib_smart_rollup_node/publisher.ml b/src/lib_smart_rollup_node/publisher.ml index 36d016413427..aec6ccdbe44d 100644 --- a/src/lib_smart_rollup_node/publisher.ml +++ b/src/lib_smart_rollup_node/publisher.ml @@ -77,11 +77,11 @@ let sub_level level decrement = let sc_rollup_commitment_period node_ctxt = (* Publishing commitments is done w.r.t. the period in the protocol in which the commitment is published, and not the one for the inbox level. *) - node_ctxt.Node_context.current_protocol.constants.sc_rollup + (Reference.get node_ctxt.Node_context.current_protocol).constants.sc_rollup .commitment_period_in_blocks let sc_rollup_challenge_window node_ctxt = - node_ctxt.Node_context.current_protocol.constants.sc_rollup + (Reference.get node_ctxt.Node_context.current_protocol).constants.sc_rollup .challenge_window_in_blocks let next_commitment_level node_ctxt last_commitment_level = diff --git a/src/lib_smart_rollup_node/rollup_node_daemon.ml b/src/lib_smart_rollup_node/rollup_node_daemon.ml index 22193d358d16..996da4097712 100644 --- a/src/lib_smart_rollup_node/rollup_node_daemon.ml +++ b/src/lib_smart_rollup_node/rollup_node_daemon.ml @@ -59,13 +59,12 @@ let handle_protocol_migration ~catching_up state (head : Layer1.header) = let open Lwt_result_syntax in let* head_proto = Node_context.protocol_of_level state.node_ctxt head.level in let new_protocol = head_proto.protocol in - when_ Protocol_hash.(new_protocol <> state.node_ctxt.current_protocol.hash) - @@ fun () -> + let current_protocol = Reference.get state.node_ctxt.current_protocol in + when_ Protocol_hash.(new_protocol <> current_protocol.hash) @@ fun () -> let*! () = Daemon_event.migration ~catching_up - ( state.node_ctxt.current_protocol.hash, - state.node_ctxt.current_protocol.proto_level ) + (current_protocol.hash, current_protocol.proto_level) (new_protocol, head_proto.proto_level) in let*? new_plugin = Protocol_plugins.proto_plugin_for_protocol new_protocol in @@ -87,7 +86,7 @@ let handle_protocol_migration ~catching_up state (head : Layer1.header) = } in state.plugin <- new_plugin ; - state.node_ctxt.current_protocol <- new_protocol ; + Reference.set state.node_ctxt.current_protocol new_protocol ; return_unit let maybe_split_context node_ctxt commitment_hash head_level = @@ -103,7 +102,7 @@ let maybe_split_context node_ctxt commitment_hash head_level = Option.value node_ctxt.config.gc_parameters.context_splitting_period ~default: - node_ctxt.current_protocol.constants.sc_rollup + (Reference.get node_ctxt.current_protocol).constants.sc_rollup .challenge_window_in_blocks in if Int32.(to_int @@ sub head_level last) >= splitting_period then ( @@ -572,6 +571,7 @@ let rec process_daemon ({node_ctxt; _} as state) = let run ({node_ctxt; configuration; plugin; _} as state) = let open Lwt_result_syntax in let module Plugin = (val state.plugin) in + let current_protocol = Reference.get node_ctxt.current_protocol in Metrics.Info.init_rollup_node_info ~id:configuration.sc_rollup_address ~mode:configuration.mode @@ -586,10 +586,9 @@ let run ({node_ctxt; configuration; plugin; _} as state) = { cctxt = (node_ctxt.cctxt :> Client_context.full); fee_parameters = configuration.fee_parameters; - minimal_block_delay = - node_ctxt.current_protocol.constants.minimal_block_delay; + minimal_block_delay = current_protocol.constants.minimal_block_delay; delay_increment_per_round = - node_ctxt.current_protocol.constants.delay_increment_per_round; + current_protocol.constants.delay_increment_per_round; } ~data_dir:node_ctxt.data_dir ~signers diff --git a/src/lib_smart_rollup_node/rpc_directory.ml b/src/lib_smart_rollup_node/rpc_directory.ml index 26de837f2e7b..6b721d2bfc22 100644 --- a/src/lib_smart_rollup_node/rpc_directory.ml +++ b/src/lib_smart_rollup_node/rpc_directory.ml @@ -560,7 +560,8 @@ let build_protocol_directories node_ctxt = (Protocol_plugins.registered_protocols ()) let get_proto_dir ?protocol (node_ctxt : _ Node_context.t) = - let proto = Option.value protocol ~default:node_ctxt.current_protocol.hash in + let current_protocol = Reference.get node_ctxt.current_protocol in + let proto = Option.value protocol ~default:current_protocol.hash in match Protocol_hash.Table.find protocol_directories proto with | None -> error_with "Unknown protocol %a" Protocol_hash.pp proto | Some (block_dir, full_dir) -> Ok (block_dir, full_dir, proto) diff --git a/src/lib_smart_rollup_node/test/helpers/helpers.ml b/src/lib_smart_rollup_node/test/helpers/helpers.ml index c2934152e2e5..ef97c47c2b8a 100644 --- a/src/lib_smart_rollup_node/test/helpers/helpers.ml +++ b/src/lib_smart_rollup_node/test/helpers/helpers.ml @@ -85,7 +85,8 @@ let add_l2_genesis_block (node_ctxt : _ Node_context.t) ~boot_sector = let predecessor = head in let predecessor_timestamp = Time.Protocol.epoch in let*? (module Plugin) = - Protocol_plugins.proto_plugin_for_protocol node_ctxt.current_protocol.hash + Protocol_plugins.proto_plugin_for_protocol + (Reference.get node_ctxt.current_protocol).hash in let inbox = (* The global inbox starts at level 0, with the origination. *) @@ -243,7 +244,8 @@ let add_l2_block (node_ctxt : _ Node_context.t) ?(is_first_block = false) in let predecessor = header_of_block predecessor_l2_block in let*? plugin = - Protocol_plugins.proto_plugin_for_protocol node_ctxt.current_protocol.hash + Protocol_plugins.proto_plugin_for_protocol + (Reference.get node_ctxt.current_protocol).hash in Rollup_node_daemon.Internal_for_tests.process_messages plugin diff --git a/src/proto_018_Proxford/lib_sc_rollup_node/pvm_plugin.ml b/src/proto_018_Proxford/lib_sc_rollup_node/pvm_plugin.ml index af7dcb6d1e34..7d3f16d9a920 100644 --- a/src/proto_018_Proxford/lib_sc_rollup_node/pvm_plugin.ml +++ b/src/proto_018_Proxford/lib_sc_rollup_node/pvm_plugin.ml @@ -69,7 +69,7 @@ let get_status (node_ctxt : _ Node_context.t) state = let*! current_level = PVM.get_current_level (of_node_pvmstate state) in let* constants = match current_level with - | None -> return node_ctxt.current_protocol.constants + | None -> return (Reference.get node_ctxt.current_protocol).constants | Some level -> Protocol_plugins.get_constants_of_level node_ctxt diff --git a/src/proto_019_PtParisB/lib_sc_rollup_node/pvm_plugin.ml b/src/proto_019_PtParisB/lib_sc_rollup_node/pvm_plugin.ml index 8c403dae83ac..32c81255578e 100644 --- a/src/proto_019_PtParisB/lib_sc_rollup_node/pvm_plugin.ml +++ b/src/proto_019_PtParisB/lib_sc_rollup_node/pvm_plugin.ml @@ -74,7 +74,7 @@ let get_status (node_ctxt : _ Node_context.t) state = let*! current_level = PVM.get_current_level state in let* constants = match current_level with - | None -> return node_ctxt.current_protocol.constants + | None -> return (Reference.get node_ctxt.current_protocol).constants | Some level -> Protocol_plugins.get_constants_of_level node_ctxt diff --git a/src/proto_020_PsParisC/lib_sc_rollup_node/pvm_plugin.ml b/src/proto_020_PsParisC/lib_sc_rollup_node/pvm_plugin.ml index 8c403dae83ac..7ea7ddab5a5e 100644 --- a/src/proto_020_PsParisC/lib_sc_rollup_node/pvm_plugin.ml +++ b/src/proto_020_PsParisC/lib_sc_rollup_node/pvm_plugin.ml @@ -74,7 +74,7 @@ let get_status (node_ctxt : _ Node_context.t) state = let*! current_level = PVM.get_current_level state in let* constants = match current_level with - | None -> return node_ctxt.current_protocol.constants + | None -> return Reference.(get node_ctxt.current_protocol).constants | Some level -> Protocol_plugins.get_constants_of_level node_ctxt diff --git a/src/proto_alpha/lib_sc_rollup_node/pvm_plugin.ml b/src/proto_alpha/lib_sc_rollup_node/pvm_plugin.ml index 8c403dae83ac..32c81255578e 100644 --- a/src/proto_alpha/lib_sc_rollup_node/pvm_plugin.ml +++ b/src/proto_alpha/lib_sc_rollup_node/pvm_plugin.ml @@ -74,7 +74,7 @@ let get_status (node_ctxt : _ Node_context.t) state = let*! current_level = PVM.get_current_level state in let* constants = match current_level with - | None -> return node_ctxt.current_protocol.constants + | None -> return (Reference.get node_ctxt.current_protocol).constants | Some level -> Protocol_plugins.get_constants_of_level node_ctxt -- GitLab From 692102d39dd980c39906796cd474c2605d09181d Mon Sep 17 00:00:00 2001 From: Alain Mebsout Date: Wed, 5 Jun 2024 10:26:33 +0200 Subject: [PATCH 2/6] Rollup node: fix misuse of level for protocol constants (cherry picked from commit b2da31d0a017549fff9eaa5894130d5ea999bfbd) --- src/lib_smart_rollup_node/protocol_plugins.ml | 7 ++++++- src/lib_smart_rollup_node/protocol_plugins.mli | 8 ++++++++ src/lib_smart_rollup_node/rollup_node_daemon.ml | 11 +++++------ 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/lib_smart_rollup_node/protocol_plugins.ml b/src/lib_smart_rollup_node/protocol_plugins.ml index 6ec4a550fd19..bf5ce0099283 100644 --- a/src/lib_smart_rollup_node/protocol_plugins.ml +++ b/src/lib_smart_rollup_node/protocol_plugins.ml @@ -132,7 +132,12 @@ let get_constants_of_protocol ?level (node_ctxt : _ Node_context.t) Node_context.protocol_activation_level node_ctxt protocol_hash in l - | Some l -> return l + | Some l -> + (* If the head is the last block of the protocol, i.e. a migration + block, we need to use its predecessor to fetch constants from the + correct context. For the other cases, the context of the + predecessor is always the same protocol. *) + return (Int32.pred l) in Plugin.Layer1_helpers.retrieve_constants ~block:(`Level level) diff --git a/src/lib_smart_rollup_node/protocol_plugins.mli b/src/lib_smart_rollup_node/protocol_plugins.mli index 4ff4954167c6..afefdf7e9f30 100644 --- a/src/lib_smart_rollup_node/protocol_plugins.mli +++ b/src/lib_smart_rollup_node/protocol_plugins.mli @@ -87,3 +87,11 @@ val get_constants_of_block_hash : _ Node_context.t -> Block_hash.t -> Rollup_constants.protocol_constants tzresult Lwt.t + +(** Retrieve constants for a given protocol (values are cached). [level], if + provided, must be a level of the protocol. *) +val get_constants_of_protocol : + ?level:int32 -> + _ Node_context.t -> + Protocol_hash.t -> + Rollup_constants.protocol_constants tzresult Lwt.t diff --git a/src/lib_smart_rollup_node/rollup_node_daemon.ml b/src/lib_smart_rollup_node/rollup_node_daemon.ml index 996da4097712..254ce6c02135 100644 --- a/src/lib_smart_rollup_node/rollup_node_daemon.ml +++ b/src/lib_smart_rollup_node/rollup_node_daemon.ml @@ -69,14 +69,13 @@ let handle_protocol_migration ~catching_up state (head : Layer1.header) = in let*? new_plugin = Protocol_plugins.proto_plugin_for_protocol new_protocol in let* constants = - (* If the head is the last block of the protocol, i.e. a migration block, we - need to use its predecessor to fetch constants from the correct - context. For the other cases, the context of the predecessor is always - the same protocol. *) let constants_level = - Int32.max (Int32.pred head.level) state.node_ctxt.genesis_info.level + Int32.max head.level state.node_ctxt.genesis_info.level in - Protocol_plugins.get_constants_of_level state.node_ctxt constants_level + Protocol_plugins.get_constants_of_protocol + state.node_ctxt + ~level:constants_level + new_protocol in let new_protocol = { -- GitLab From 7e9a770a74908bcc2005bc9a44072159b2c85650 Mon Sep 17 00:00:00 2001 From: Alain Mebsout Date: Wed, 5 Jun 2024 10:39:05 +0200 Subject: [PATCH 3/6] Rollup node: event for protocol change with constants (cherry picked from commit 6e0a5b5f2ab672b457cdd8dd76f7ad396c3a03e1) --- src/lib_smart_rollup/rollup_constants.ml | 111 ++++++++++++++++++ src/lib_smart_rollup_node/daemon_event.ml | 16 +++ src/lib_smart_rollup_node/daemon_event.mli | 3 + .../rollup_node_daemon.ml | 6 + 4 files changed, 136 insertions(+) diff --git a/src/lib_smart_rollup/rollup_constants.ml b/src/lib_smart_rollup/rollup_constants.ml index caed70d3f331..37d1b96bac6c 100644 --- a/src/lib_smart_rollup/rollup_constants.ml +++ b/src/lib_smart_rollup/rollup_constants.ml @@ -53,3 +53,114 @@ type protocol_constants = { sc_rollup : sc_rollup_constants; dal : dal_constants; } + +let reveal_activation_level_encoding = + let open Data_encoding in + conv + (fun { + blake2B; + metadata; + dal_page; + dal_parameters; + dal_attested_slots_validity_lag; + } -> + ( blake2B, + metadata, + dal_page, + dal_parameters, + dal_attested_slots_validity_lag )) + (fun ( blake2B, + metadata, + dal_page, + dal_parameters, + dal_attested_slots_validity_lag ) -> + { + blake2B; + metadata; + dal_page; + dal_parameters; + dal_attested_slots_validity_lag; + }) + @@ obj5 + (req "blake2B" int32) + (req "metadata" int32) + (req "dal_page" int32) + (req "dal_parameters" int32) + (req "dal_attested_slots_validity_lag" int32) + +let encoding = + let open Data_encoding in + conv + (fun { + minimal_block_delay; + delay_increment_per_round; + sc_rollup = + { + challenge_window_in_blocks; + commitment_period_in_blocks; + reveal_activation_level; + max_number_of_stored_cemented_commitments; + }; + dal = + { + feature_enable; + attestation_lag; + number_of_slots; + cryptobox_parameters; + }; + } -> + ( minimal_block_delay, + delay_increment_per_round, + ( challenge_window_in_blocks, + commitment_period_in_blocks, + reveal_activation_level, + max_number_of_stored_cemented_commitments ), + (feature_enable, attestation_lag, number_of_slots, cryptobox_parameters) + )) + (fun ( minimal_block_delay, + delay_increment_per_round, + ( challenge_window_in_blocks, + commitment_period_in_blocks, + reveal_activation_level, + max_number_of_stored_cemented_commitments ), + ( feature_enable, + attestation_lag, + number_of_slots, + cryptobox_parameters ) ) -> + { + minimal_block_delay; + delay_increment_per_round; + sc_rollup = + { + challenge_window_in_blocks; + commitment_period_in_blocks; + reveal_activation_level; + max_number_of_stored_cemented_commitments; + }; + dal = + { + feature_enable; + attestation_lag; + number_of_slots; + cryptobox_parameters; + }; + }) + @@ obj4 + (req "minimal_block_delay" int64) + (req "delay_increment_per_round" int64) + (req + "sc_rollup" + (obj4 + (req "challenge_window_in_blocks" int31) + (req "commitment_period_in_blocks" int31) + (opt "reveal_activation_level" reveal_activation_level_encoding) + (req "max_number_of_stored_cemented_commitments" int31))) + (req + "dal" + (obj4 + (req "feature_enable" bool) + (req "attestation_lag" int31) + (req "number_of_slots" int31) + (req + "cryptobox_parameters" + Tezos_crypto_dal.Cryptobox.parameters_encoding))) diff --git a/src/lib_smart_rollup_node/daemon_event.ml b/src/lib_smart_rollup_node/daemon_event.ml index bd03e51d2bea..d069c4797614 100644 --- a/src/lib_smart_rollup_node/daemon_event.ml +++ b/src/lib_smart_rollup_node/daemon_event.ml @@ -135,6 +135,19 @@ module Simple = struct ppf (if catching_up then "Catching up on migration" else "Migration")) + let switched_protocol = + declare_3 + ~name:"smart_rollup_node_daemon_switched_protocol" + ~msg:"Switched to {protocol} ({proto_level}) with constants {constants} " + ~level:Notice + ("protocol", Protocol_hash.encoding) + ("proto_level", Data_encoding.int31) + ("constants", Rollup_constants.encoding) + ~pp3:(fun fmt c -> + Data_encoding.Json.pp + fmt + (Data_encoding.Json.construct Rollup_constants.encoding c)) + let error = declare_1 ~section @@ -222,6 +235,9 @@ let migration ~catching_up (old_protocol, old_protocol_level) new_protocol, new_protocol_level ) +let switched_protocol protocol proto_level constants = + Simple.(emit switched_protocol) (protocol, proto_level, constants) + let error e = Simple.(emit error) e let degraded_mode () = Simple.(emit degraded_mode) () diff --git a/src/lib_smart_rollup_node/daemon_event.mli b/src/lib_smart_rollup_node/daemon_event.mli index a0353d43f806..5e309109298e 100644 --- a/src/lib_smart_rollup_node/daemon_event.mli +++ b/src/lib_smart_rollup_node/daemon_event.mli @@ -68,6 +68,9 @@ val migration : Protocol_hash.t * int -> unit Lwt.t +val switched_protocol : + Protocol_hash.t -> int -> Rollup_constants.protocol_constants -> unit Lwt.t + (** Emit a fatal error for the daemon. *) val error : tztrace -> unit Lwt.t diff --git a/src/lib_smart_rollup_node/rollup_node_daemon.ml b/src/lib_smart_rollup_node/rollup_node_daemon.ml index 254ce6c02135..d9571fb4a220 100644 --- a/src/lib_smart_rollup_node/rollup_node_daemon.ml +++ b/src/lib_smart_rollup_node/rollup_node_daemon.ml @@ -86,6 +86,12 @@ let handle_protocol_migration ~catching_up state (head : Layer1.header) = in state.plugin <- new_plugin ; Reference.set state.node_ctxt.current_protocol new_protocol ; + let*! () = + Daemon_event.switched_protocol + new_protocol.hash + new_protocol.proto_level + new_protocol.constants + in return_unit let maybe_split_context node_ctxt commitment_hash head_level = -- GitLab From 6ddc4f038297421e502d796255416f146f41c2e5 Mon Sep 17 00:00:00 2001 From: Alain Mebsout Date: Wed, 5 Jun 2024 09:32:57 +0200 Subject: [PATCH 4/6] Test: test commitment publication after migration with constant change (cherry picked from commit 1824e18073e0ed7be8ac252202b87d952a568dcb) --- tezt/lib_tezos/sc_rollup_helpers.ml | 12 ++++++- tezt/lib_tezos/sc_rollup_helpers.mli | 1 + tezt/tests/sc_rollup_migration.ml | 50 ++++++++++++++++++++++------ 3 files changed, 51 insertions(+), 12 deletions(-) diff --git a/tezt/lib_tezos/sc_rollup_helpers.ml b/tezt/lib_tezos/sc_rollup_helpers.ml index 9072b8efaf53..11fd1e6cd497 100644 --- a/tezt/lib_tezos/sc_rollup_helpers.ml +++ b/tezt/lib_tezos/sc_rollup_helpers.ml @@ -214,13 +214,23 @@ let make_bool_parameter name = function | None -> [] | Some value -> [([name], `Bool value)] +let make_string_parameter name = function + | None -> [] + | Some value -> [([name], `String value)] + let setup_l1 ?timestamp ?bootstrap_smart_rollups ?bootstrap_contracts ?commitment_period ?challenge_window ?timeout ?whitelist_enable - ?rpc_external ?(riscv_pvm_enable = false) protocol = + ?rpc_external ?(riscv_pvm_enable = false) ?minimal_block_delay protocol = let parameters = make_parameter "smart_rollup_commitment_period_in_blocks" commitment_period @ make_parameter "smart_rollup_challenge_window_in_blocks" challenge_window @ make_parameter "smart_rollup_timeout_period_in_blocks" timeout + @ make_string_parameter + "minimal_block_delay" + (Option.map string_of_int minimal_block_delay) + @ make_string_parameter + "delay_increment_per_round" + (Option.map string_of_int minimal_block_delay) @ (if Protocol.number protocol >= 018 then make_bool_parameter "smart_rollup_private_enable" whitelist_enable else []) diff --git a/tezt/lib_tezos/sc_rollup_helpers.mli b/tezt/lib_tezos/sc_rollup_helpers.mli index 0b1a6a7d48a7..cd82d8478589 100644 --- a/tezt/lib_tezos/sc_rollup_helpers.mli +++ b/tezt/lib_tezos/sc_rollup_helpers.mli @@ -118,6 +118,7 @@ val setup_l1 : ?whitelist_enable:bool -> ?rpc_external:bool -> ?riscv_pvm_enable:bool -> + ?minimal_block_delay:int -> Protocol.t -> (Node.t * Client.t) Lwt.t diff --git a/tezt/tests/sc_rollup_migration.ml b/tezt/tests/sc_rollup_migration.ml index 9b9480025fdf..330363c7ae4c 100644 --- a/tezt/tests/sc_rollup_migration.ml +++ b/tezt/tests/sc_rollup_migration.ml @@ -15,6 +15,10 @@ open Sc_rollup_helpers +let block_time_to_trigger_constant_update_on_migration = function + | Protocol.Alpha -> Some 5 + | ParisB | ParisC -> Some 8 + let test_l1_migration_scenario ?parameters_ty ?(src = Constant.bootstrap1.alias) ?variant ?(tags = []) ?(timeout = 10) ?(commitment_period = 10) ~kind ~migrate_from ~migrate_to ~scenario_prior ~scenario_after ~description () = @@ -426,8 +430,9 @@ let test_cont_refute_pre_migration ~kind ~migrate_from ~migrate_to = let test_l2_migration_scenario ?parameters_ty ?(mode = Sc_rollup_node.Operator) ?(operator = Constant.bootstrap1.alias) ?boot_sector ?commitment_period - ?challenge_window ?timeout ?variant ?(tags = []) ~kind ~migrate_from - ~migrate_to ~scenario_prior ~scenario_after ~description () = + ?challenge_window ?(with_constant_change = false) ?timeout ?variant + ?(tags = []) ~kind ~migrate_from ~migrate_to ~scenario_prior ~scenario_after + ~description () = let tags = Tag.etherlink :: Protocol.tag migrate_from :: Protocol.tag migrate_to :: kind :: "l2" :: "migration" :: tags @@ -443,8 +448,17 @@ let test_l2_migration_scenario ?parameters_ty ?(mode = Sc_rollup_node.Operator) (Protocol.name migrate_to) (format_title_scenario kind {variant; tags; description})) @@ fun () -> + let minimal_block_delay = + if not with_constant_change then None + else block_time_to_trigger_constant_update_on_migration migrate_to + in let* tezos_node, tezos_client = - setup_l1 ?commitment_period ?challenge_window ?timeout migrate_from + setup_l1 + ?commitment_period + ?challenge_window + ?minimal_block_delay + ?timeout + migrate_from in let* rollup_node, sc_rollup = setup_rollup @@ -456,7 +470,7 @@ let test_l2_migration_scenario ?parameters_ty ?(mode = Sc_rollup_node.Operator) tezos_node tezos_client in - let* () = Sc_rollup_node.run rollup_node sc_rollup [] in + let* () = Sc_rollup_node.run rollup_node sc_rollup ~event_level:`Debug [] in let* prior_res = scenario_prior ~sc_rollup ~rollup_node tezos_node tezos_client in @@ -480,19 +494,32 @@ let test_l2_migration_scenario ?parameters_ty ?(mode = Sc_rollup_node.Operator) scenario_after ~sc_rollup ~rollup_node tezos_node tezos_client prior_res let test_rollup_node_simple_migration ~kind ~migrate_from ~migrate_to = - let tags = ["store"] in - let description = "node can read data after store migration" in - let commitment_period = 5 in - let challenge_window = 5 in - let scenario_prior ~sc_rollup:_ ~rollup_node _tezos_node tezos_client = - let* () = Sc_rollup_helpers.send_messages commitment_period tezos_client in + let tags = ["store"; "commitment"] in + let description = "node can commit after migration" in + let commitment_period = 8 in + let challenge_window = 20 in + let scenario_prior ~sc_rollup:_ ~rollup_node tezos_node tezos_client = + let* constants = + Client.RPC.call tezos_client @@ RPC.get_chain_block_context_constants () + in + let blocks_per_cycle = JSON.(constants |-> "blocks_per_cycle" |> as_int) in + (* Do migration at end of second cycle *) + let* level = Node.get_level tezos_node in + let* () = + Sc_rollup_helpers.send_messages + ((2 * blocks_per_cycle) - level - 1) + tezos_client + in let* _ = Sc_rollup_node.wait_sync rollup_node ~timeout:10. in unit in let scenario_after ~sc_rollup ~rollup_node tezos_node tezos_client () = let* migration_level = Node.get_level tezos_node in + let* {commitment_period_in_blocks = new_commitment_period; _} = + Sc_rollup_helpers.get_sc_rollup_constants tezos_client + in let* () = - Sc_rollup_helpers.send_messages (commitment_period + 3) tezos_client + Sc_rollup_helpers.send_messages (new_commitment_period + 4) tezos_client in let* _ = Sc_rollup_node.wait_sync rollup_node ~timeout:10. in let* _l2_block = @@ -523,6 +550,7 @@ let test_rollup_node_simple_migration ~kind ~migrate_from ~migrate_to = ~kind ~commitment_period ~challenge_window + ~with_constant_change:true ~migrate_from ~migrate_to ~scenario_prior -- GitLab From 15b64ed00e859dc76d38e0b3994113f72faef5f7 Mon Sep 17 00:00:00 2001 From: Alain Mebsout Date: Thu, 6 Jun 2024 15:22:45 +0200 Subject: [PATCH 5/6] Doc: changelog (cherry picked from commit bfe7b35a14d8295c170c49b7cb91bf90f8fcb1ec) --- CHANGES.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index 73c56ad80b62..586c2b24b05c 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -214,6 +214,9 @@ Smart Rollup node - Support for unsafely increasing the WASM PVM's tick limit of a rollup. (MRs :gl:`!12907`, :gl:`!12957`, :gl:`!12983`, :gl:`!13357`) +- Fix a bug in how commitments are computed after a protocol migration + where the the commitment period changes. (MR :gl:`!13588`) + Smart Rollup WASM Debugger -------------------------- -- GitLab From 3c24cb528ff7d1a829c5ea94809545f78d53c89f Mon Sep 17 00:00:00 2001 From: Thomas Letan Date: Mon, 17 Jun 2024 18:58:49 +0200 Subject: [PATCH 6/6] Tezt: Refine magic number of migration scenario --- tezt/tests/sc_rollup_migration.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tezt/tests/sc_rollup_migration.ml b/tezt/tests/sc_rollup_migration.ml index 330363c7ae4c..55073345f64f 100644 --- a/tezt/tests/sc_rollup_migration.ml +++ b/tezt/tests/sc_rollup_migration.ml @@ -519,7 +519,7 @@ let test_rollup_node_simple_migration ~kind ~migrate_from ~migrate_to = Sc_rollup_helpers.get_sc_rollup_constants tezos_client in let* () = - Sc_rollup_helpers.send_messages (new_commitment_period + 4) tezos_client + Sc_rollup_helpers.send_messages (new_commitment_period + 2) tezos_client in let* _ = Sc_rollup_node.wait_sync rollup_node ~timeout:10. in let* _l2_block = -- GitLab