diff --git a/CHANGES.rst b/CHANGES.rst index 73c56ad80b627ae56d677698de4466a68fe360dc..586c2b24b05c2a48e69cf71a1c63e5cd487da911 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 -------------------------- diff --git a/src/lib_smart_rollup/rollup_constants.ml b/src/lib_smart_rollup/rollup_constants.ml index caed70d3f331af2c03e69a789a5aa33d692938dc..37d1b96bac6c0ae0fb30d837251a6348352c16a9 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 bd03e51d2bea98488c4e2a1b50d5889b848e862c..d069c479761438ffd55f52f05022b528c367c7f5 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 a0353d43f806b730fe38e7dd70a4e2bc1a9eca16..5e309109298e50d892caa9138612faa654b400d1 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/node_context.ml b/src/lib_smart_rollup_node/node_context.ml index c6f36a2ac2e3ff007ea71cc417bfee37b30005fd..b5e076cb8e68d100a47f2adaf816aad0864870d4 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 f28826f182d84e20f2b81ceabc1c2900fcfa3b56..eb4340b092e006a9d8de3181e6b5bdfe0a4d7220 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 ec867e68b63ec1816c27227a76e2c841b2d34b02..0df4b2652f5b0961da035e7d6494a4a9c3a4000f 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 3d292d73ca03d0d1bb8838bf2dd0b890da95133b..aeff4abfd3f347146dda3e3af21d7e2805077d9e 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 d976a2a5709283662c65b611f02d2f28694c6f34..bf5ce00992835618bb670ae8ba930df64f69780a 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 @@ -131,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 4ff4954167c6fe4f11b620d7c6b44d6df9fe0000..afefdf7e9f30351ea01526f60c5182ec42a89c43 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/publisher.ml b/src/lib_smart_rollup_node/publisher.ml index 36d016413427358f4905cf1ec7e8279880f759a7..aec6ccdbe44d70ff4de7eedb77eb91e21a23cf11 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 22193d358d1653d6ee083421365addb817a5d293..d9571fb4a2206532e928e8c25ecbea4a31630842 100644 --- a/src/lib_smart_rollup_node/rollup_node_daemon.ml +++ b/src/lib_smart_rollup_node/rollup_node_daemon.ml @@ -59,25 +59,23 @@ 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 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 = { @@ -87,7 +85,13 @@ 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 ; + 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 = @@ -103,7 +107,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 +576,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 +591,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 26de837f2e7b540bb401ec6b8dbdf3b60520bf0a..6b721d2bfc224eb96b6a8f927e9782493e51219f 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 c2934152e2e587e93408a758a15ef9a8ccd8f0f6..ef97c47c2b8a39958301136a52478ac44cb9ff5e 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 af7dcb6d1e340d419c7f74dfb5fc5b419d981922..7d3f16d9a9205102c1370f4428d0c1f136ce45da 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 8c403dae83ac182d840aedd651b3b54565a200ac..32c81255578e94e2eb34f11e328ec83f4d985b12 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 8c403dae83ac182d840aedd651b3b54565a200ac..7ea7ddab5a5e86417060c802bdfe9ae695a867d2 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 8c403dae83ac182d840aedd651b3b54565a200ac..32c81255578e94e2eb34f11e328ec83f4d985b12 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 diff --git a/tezt/lib_tezos/sc_rollup_helpers.ml b/tezt/lib_tezos/sc_rollup_helpers.ml index 9072b8efaf53b08345c7ccf7a84865374a97d6a5..11fd1e6cd497b40a199b77a83a702f51e4733289 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 0b1a6a7d48a715c4bab8511edc77b4daa55cf061..cd82d84785892c3c9d76d08925983d167f8f31c7 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 9b9480025fdf0baf0b1bbc6434aafd8b12a81e38..55073345f64fd34c77c900a34569a3faec30dc43 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 + 2) 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