From fa34c8f05b5f4fce8fdb8ba8b5275488036fb242 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 f5e3c0b4294e..df9daee9d5d2 100644 --- a/src/lib_smart_rollup_node/protocol_plugins.ml +++ b/src/lib_smart_rollup_node/protocol_plugins.ml @@ -100,7 +100,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 @@ -108,10 +109,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 @@ -122,7 +131,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 b7bb6604d4c9..9a8b83afaf68 100644 --- a/src/lib_smart_rollup_node/protocol_plugins.mli +++ b/src/lib_smart_rollup_node/protocol_plugins.mli @@ -65,12 +65,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 d18f5ab0e1b2..75468413300b 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 58a8ada8d7e39915e5a0f40bce706e3de822f09f 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 b6b8c3a316b2..78bd4b12bf67 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -189,6 +189,8 @@ Smart Rollup client - Fix a critical bug that could lead to data loss when chain reorganizations happen while a GC is running. (MR :gl:`!11358`) +- Fix issue with constants fetching during protocol migration. (MR :gl:`!11804`) + Smart Rollup WASM Debugger -------------------------- -- GitLab