diff --git a/CHANGES.rst b/CHANGES.rst index bd6fb1b742b9bc60f909ea76d62d738f79968022..6fa1c6291cee5e11426bcbe7e70b6cb0ce8cd152 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 -------------------------- diff --git a/src/lib_smart_rollup_node/protocol_plugins.ml b/src/lib_smart_rollup_node/protocol_plugins.ml index cc4b4c42d3a23305bf4abd06b107fc892e9f3aed..fe14afbcb4cdc1f857093311a1dedb08408d18eb 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 a51f85cab64ea2c68de43d21ce536abcb8ea8dc1..64029bc0030759f8795cdef06aa2ca802999689f 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 47903eab8fb8d8f02c16c2a50b94ff2c5eeb5e0c..51b5a87320868dc9710e04f2c4f98451bdba9a21 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 = {