diff --git a/CHANGES.rst b/CHANGES.rst index b6b8c3a316b2655c5c12be9118ce56204c317271..78bd4b12bf67ce4a072cbec1c92532ab306d2a7b 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 -------------------------- diff --git a/src/lib_smart_rollup_node/protocol_plugins.ml b/src/lib_smart_rollup_node/protocol_plugins.ml index f5e3c0b4294e50f8511c0839e4d372a2990de721..df9daee9d5d255e7af1d9968e6a760911044fed3 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 b7bb6604d4c98963135f273bfc271189611a0857..9a8b83afaf68dab755c0a56a4cf079371c31ea70 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 d18f5ab0e1b2745b4e88e428ea14a2a2ca3249c3..75468413300b6b099618d09f9a6b8a73324f5384 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 = {