From 78e87755be618c8d2b1d8e0c480cb947f319aa34 Mon Sep 17 00:00:00 2001 From: Alain Mebsout Date: Fri, 2 Feb 2024 11:23:02 +0100 Subject: [PATCH 1/2] Rollup node: use context from head block to fetch constants Using the first block of the protocol to fetch constants is a bad idea because this block might be gone from the context of the L1 node. Instead, we use the constants from the context of the block we're interested in (if we don't know them already). --- src/lib_smart_rollup_node/protocol_plugins.ml | 19 ++++++++++++++----- .../protocol_plugins.mli | 6 ------ .../rollup_node_daemon.ml | 8 +++++++- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/lib_smart_rollup_node/protocol_plugins.ml b/src/lib_smart_rollup_node/protocol_plugins.ml index cc4b4c42d3a2..fe14afbcb4cd 100644 --- a/src/lib_smart_rollup_node/protocol_plugins.ml +++ b/src/lib_smart_rollup_node/protocol_plugins.ml @@ -108,7 +108,8 @@ let constants_cache = let cache_size = 3 in Constants_cache.create cache_size -let get_constants_of_protocol (node_ctxt : _ Node_context.t) protocol_hash = +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 @@ -116,10 +117,18 @@ let get_constants_of_protocol (node_ctxt : _ Node_context.t) protocol_hash = let retrieve protocol_hash = let*? plugin = proto_plugin_for_protocol protocol_hash in let module Plugin = (val plugin) in - let* (First_known l | Activation_level l) = - Node_context.protocol_activation_level node_ctxt protocol_hash + let* level = + match level with + | None -> + let+ (First_known l | Activation_level l) = + Node_context.protocol_activation_level node_ctxt protocol_hash + in + l + | Some l -> return l in - Plugin.Layer1_helpers.retrieve_constants ~block:(`Level l) node_ctxt.cctxt + Plugin.Layer1_helpers.retrieve_constants + ~block:(`Level level) + node_ctxt.cctxt in Constants_cache.bind_or_put constants_cache @@ -130,7 +139,7 @@ let get_constants_of_protocol (node_ctxt : _ Node_context.t) protocol_hash = let get_constants_of_level node_ctxt level = let open Lwt_result_syntax in let* {protocol; _} = Node_context.protocol_of_level node_ctxt level in - get_constants_of_protocol node_ctxt protocol + get_constants_of_protocol ~level node_ctxt protocol let get_constants_of_block_hash node_ctxt block_hash = let open Lwt_result_syntax in diff --git a/src/lib_smart_rollup_node/protocol_plugins.mli b/src/lib_smart_rollup_node/protocol_plugins.mli index a51f85cab64e..64029bc00307 100644 --- a/src/lib_smart_rollup_node/protocol_plugins.mli +++ b/src/lib_smart_rollup_node/protocol_plugins.mli @@ -71,12 +71,6 @@ val last_proto_plugin : _ Node_context.t -> proto_plugin tzresult Lwt.t depending on the context. *) -(** Retrieve constants for a given protocol (values are cached). *) -val get_constants_of_protocol : - _ Node_context.t -> - Protocol_hash.t -> - Rollup_constants.protocol_constants tzresult Lwt.t - (** Retrieve constants for a given level (values are cached). *) val get_constants_of_level : _ Node_context.t -> diff --git a/src/lib_smart_rollup_node/rollup_node_daemon.ml b/src/lib_smart_rollup_node/rollup_node_daemon.ml index 47903eab8fb8..51b5a8732086 100644 --- a/src/lib_smart_rollup_node/rollup_node_daemon.ml +++ b/src/lib_smart_rollup_node/rollup_node_daemon.ml @@ -69,7 +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 = - Protocol_plugins.get_constants_of_protocol state.node_ctxt new_protocol + (* 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. *) + Protocol_plugins.get_constants_of_level + state.node_ctxt + (Int32.pred head.level) in let new_protocol = { -- GitLab From 6947b8760d71f1322c61df00ed5a30df9493f526 Mon Sep 17 00:00:00 2001 From: Alain Mebsout Date: Fri, 2 Feb 2024 15:19:09 +0100 Subject: [PATCH 2/2] Doc: changelog --- CHANGES.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index bd6fb1b742b9..6fa1c6291cee 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -109,6 +109,8 @@ Smart Rollup node - Pre-images endpoint (configurable on the CLI of the config file) to allow the rollup node to fetch missing pre-images from a remote server. (MR :gl:`!11600`) +- Fix issue with constants fetching during protocol migration. (MR :gl:`!11804`) + Smart Rollup WASM Debugger -------------------------- -- GitLab