From f67d84fa82b6502fb3c71b82fc52c8261e769b23 Mon Sep 17 00:00:00 2001 From: Alain Mebsout Date: Mon, 27 Feb 2023 19:32:34 +0100 Subject: [PATCH 1/4] Proto/SCORU: move no_history functions outside of error monad --- .../lib_protocol/alpha_context.mli | 9 +- src/proto_alpha/lib_protocol/apply.ml | 9 +- ...up_inbox_merkelized_payload_hashes_repr.ml | 24 +++-- ...p_inbox_merkelized_payload_hashes_repr.mli | 12 ++- .../sc_rollup_inbox_message_repr.ml | 21 ++++- .../sc_rollup_inbox_message_repr.mli | 4 + .../lib_protocol/sc_rollup_inbox_repr.ml | 91 ++++++++----------- .../lib_protocol/sc_rollup_inbox_repr.mli | 4 +- .../lib_protocol/sc_rollup_inbox_storage.ml | 44 ++------- .../lib_protocol/sc_rollup_inbox_storage.mli | 2 +- .../test/helpers/sc_rollup_helpers.ml | 25 +++-- .../test/pbt/test_sc_rollup_encoding.ml | 8 +- src/proto_alpha/lib_sc_rollup_node/inbox.ml | 4 +- 13 files changed, 124 insertions(+), 133 deletions(-) diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index 0ba07430157c..9cac03f3b0c4 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -3318,6 +3318,8 @@ module Sc_rollup : sig val no_history : t end + val genesis_no_history : Inbox_message.serialized -> t + val genesis : History.t -> Inbox_message.serialized -> (History.t * t) tzresult @@ -3472,7 +3474,7 @@ module Sc_rollup : sig (proof * inbox_message option) tzresult Lwt.t val finalize_inbox_level_no_history : - t -> Inbox_merkelized_payload_hashes.t -> t tzresult + t -> Inbox_merkelized_payload_hashes.t -> t val init_witness_no_history : Inbox_merkelized_payload_hashes.t @@ -3480,7 +3482,7 @@ module Sc_rollup : sig predecessor_timestamp:Time.t -> predecessor:Block_hash.t -> Inbox_merkelized_payload_hashes.t -> - Inbox_merkelized_payload_hashes.t tzresult + Inbox_merkelized_payload_hashes.t val genesis : predecessor_timestamp:Time.t -> @@ -3548,8 +3550,7 @@ module Sc_rollup : sig val finalize_inbox_level : context -> context Lwt.t - val add_info_per_level : - predecessor:Block_hash.t -> context -> context Lwt.t + val add_info_per_level : predecessor:Block_hash.t -> context -> context val get_inbox : context -> (t * context) tzresult Lwt.t end diff --git a/src/proto_alpha/lib_protocol/apply.ml b/src/proto_alpha/lib_protocol/apply.ml index e903c316640c..1bdfe3b03bbd 100644 --- a/src/proto_alpha/lib_protocol/apply.ml +++ b/src/proto_alpha/lib_protocol/apply.ml @@ -2402,7 +2402,7 @@ let begin_application ctxt chain_id ~migration_balance_updates let* ctxt, liquidity_baking_operations_results, liquidity_baking_toggle_ema = apply_liquidity_baking_subsidy ctxt ~toggle_vote in - let*! ctxt = + let ctxt = Sc_rollup.Inbox.add_info_per_level ~predecessor:block_header.shell.predecessor ctxt @@ -2461,7 +2461,7 @@ let begin_full_construction ctxt chain_id ~migration_balance_updates let* ctxt, liquidity_baking_operations_results, liquidity_baking_toggle_ema = apply_liquidity_baking_subsidy ctxt ~toggle_vote in - let*! ctxt = + let ctxt = Sc_rollup.Inbox.add_info_per_level ~predecessor:predecessor_hash ctxt in let mode = @@ -2498,15 +2498,14 @@ let begin_partial_construction ctxt chain_id ~migration_balance_updates let* ctxt, liquidity_baking_operations_results, liquidity_baking_toggle_ema = apply_liquidity_baking_subsidy ctxt ~toggle_vote in - let* ctxt = + let ctxt = (* The mode [Partial_construction] is used in simulation. We try to put a realistic value of the block's timestamp. Even though, it should not have an impact on the simulation of the following smart rollup operations. *) let predecessor = predecessor_hash in - let*! ctxt = Sc_rollup.Inbox.add_info_per_level ~predecessor ctxt in - return ctxt + Sc_rollup.Inbox.add_info_per_level ~predecessor ctxt in let mode = Partial_construction {predecessor_level; predecessor_fitness} in return diff --git a/src/proto_alpha/lib_protocol/sc_rollup_inbox_merkelized_payload_hashes_repr.ml b/src/proto_alpha/lib_protocol/sc_rollup_inbox_merkelized_payload_hashes_repr.ml index 8354f5a5946c..b9c49ea88f4b 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_inbox_merkelized_payload_hashes_repr.ml +++ b/src/proto_alpha/lib_protocol/sc_rollup_inbox_merkelized_payload_hashes_repr.ml @@ -149,24 +149,28 @@ let remember history merkelized payload = let prev_cell_ptr = hash merkelized in History.remember prev_cell_ptr {merkelized; payload} history -let genesis history payload = - let open Result_syntax in +let genesis_no_history payload = let payload_hash = Sc_rollup_inbox_message_repr.hash_serialized_message payload in - let merkelized = Skip_list.genesis payload_hash in + Skip_list.genesis payload_hash + +let genesis history payload = + let open Result_syntax in + let merkelized = genesis_no_history payload in let+ history = remember history merkelized payload in (history, merkelized) +let add_payload_no_history prev_merkelized payload = + let prev_merkelized_ptr = hash prev_merkelized in + Skip_list.next + ~prev_cell:prev_merkelized + ~prev_cell_ptr:prev_merkelized_ptr + (Sc_rollup_inbox_message_repr.hash_serialized_message payload) + let add_payload history prev_merkelized payload = let open Result_syntax in - let prev_merkelized_ptr = hash prev_merkelized in - let merkelized = - Skip_list.next - ~prev_cell:prev_merkelized - ~prev_cell_ptr:prev_merkelized_ptr - (Sc_rollup_inbox_message_repr.hash_serialized_message payload) - in + let merkelized = add_payload_no_history prev_merkelized payload in let* history = remember history merkelized payload in return (history, merkelized) diff --git a/src/proto_alpha/lib_protocol/sc_rollup_inbox_merkelized_payload_hashes_repr.mli b/src/proto_alpha/lib_protocol/sc_rollup_inbox_merkelized_payload_hashes_repr.mli index 487bf2446a19..1d0bf1ce1572 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_inbox_merkelized_payload_hashes_repr.mli +++ b/src/proto_alpha/lib_protocol/sc_rollup_inbox_merkelized_payload_hashes_repr.mli @@ -70,6 +70,10 @@ val remember : Sc_rollup_inbox_message_repr.serialized -> History.t tzresult +(** [genesis_no_history payload] is the initial merkelized payload hashes with + index 0. *) +val genesis_no_history : Sc_rollup_inbox_message_repr.serialized -> t + (** [genesis history payload] is the initial merkelized payload hashes with index 0. It is remembered in [history] using [remember]. *) val genesis : @@ -77,9 +81,13 @@ val genesis : Sc_rollup_inbox_message_repr.serialized -> (History.t * t) tzresult -(** [add_payload history merkelized payload] creates a new {!t} with [payload] +(** [add_payload_no_history merkelized payload] creates a new {!t} with [payload] and [merkelized] as ancestor (i.e. [index = succ (get_index - merkelized)]). [merkelized] is remembered in [history] with [remember]. *) + merkelized)]). *) +val add_payload_no_history : t -> Sc_rollup_inbox_message_repr.serialized -> t + +(** [add_payload] is identical to {!add_payload_no_history} but the resulting + [merkelized] is remembered in [history] with [remember]. *) val add_payload : History.t -> t -> diff --git a/src/proto_alpha/lib_protocol/sc_rollup_inbox_message_repr.ml b/src/proto_alpha/lib_protocol/sc_rollup_inbox_message_repr.ml index 5475e6805c21..e8a6f5e7be1d 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_inbox_message_repr.ml +++ b/src/proto_alpha/lib_protocol/sc_rollup_inbox_message_repr.ml @@ -197,10 +197,27 @@ let hash_serialized_message (payload : serialized) = let start_of_level_serialized = (* If [Start_of_level] cannot be serialized, this will be detected at - compilation time as we are defining a top-level value. *) + startup time as we are defining a top-level value. *) Data_encoding.Binary.to_string_exn encoding (Internal Start_of_level) let end_of_level_serialized = (* If [End_of_level] cannot be serialized, this will be detected at - compilation time as we are defining a top-level value. *) + startup time as we are defining a top-level value. *) Data_encoding.Binary.to_string_exn encoding (Internal End_of_level) + +let info_per_level_serialized ~predecessor_timestamp ~predecessor = + match + serialize (Internal (Info_per_level {predecessor_timestamp; predecessor})) + with + | Error _ -> + (* The info per level should always be serializable as the encoding + functions for this case do not fail. *) + assert false + | Ok info -> info + +let (_dummy_serialized_info_per_level_serialized : serialized) = + (* This allows to detect an error, at startup, we might have introduced in the + encoding of serialization of info per level messages . *) + info_per_level_serialized + ~predecessor_timestamp:(Time.of_seconds Int64.min_int) + ~predecessor:Block_hash.zero diff --git a/src/proto_alpha/lib_protocol/sc_rollup_inbox_message_repr.mli b/src/proto_alpha/lib_protocol/sc_rollup_inbox_message_repr.mli index edf1d07f2e6d..c4873becc4ea 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_inbox_message_repr.mli +++ b/src/proto_alpha/lib_protocol/sc_rollup_inbox_message_repr.mli @@ -101,3 +101,7 @@ val start_of_level_serialized : serialized (** {!serialized} representation of [Internal [End_of_level]]. *) val end_of_level_serialized : serialized + +(** {!info_per_level_serialized ~predecessor_timestamp ~predecessor} is the serialized representation of the internal message for {!Info_per_level}. *) +val info_per_level_serialized : + predecessor_timestamp:Time.t -> predecessor:Block_hash.t -> serialized diff --git a/src/proto_alpha/lib_protocol/sc_rollup_inbox_repr.ml b/src/proto_alpha/lib_protocol/sc_rollup_inbox_repr.ml index 3bceac9e32b5..0ea2d76067ac 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_inbox_repr.ml +++ b/src/proto_alpha/lib_protocol/sc_rollup_inbox_repr.ml @@ -300,6 +300,11 @@ let add_protocol_internal_message payload payloads_history witness = witness payload +let add_protocol_internal_message_no_history payload witness = + Sc_rollup_inbox_merkelized_payload_hashes_repr.add_payload_no_history + witness + payload + let add_message payload payloads_history witness = let open Result_syntax in let message_counter = @@ -318,12 +323,6 @@ let add_message payload payloads_history witness = witness payload -(** [no_history] creates an empty history with [capacity] set to - zero---this makes the [remember] function a no-op. We want this - behaviour in the protocol because we don't want to store - previous levels of the inbox. *) -let no_history = History.empty ~capacity:0L - let take_snapshot inbox = inbox.old_levels_messages (** [archive history inbox witness] archives the current inbox level depending @@ -349,6 +348,20 @@ let archive history inbox witness = let inbox = {inbox with old_levels_messages} in return (history, inbox) +(** [archive_no_history inbox witness] archives the current inbox level. Updates + the [inbox.current_level] and [inbox.old_levels_messages]. *) +let archive_no_history inbox witness = + let old_levels_messages = + let prev_cell = inbox.old_levels_messages in + let prev_cell_ptr = hash_history_proof prev_cell in + let current_level_proof = + let hash = Sc_rollup_inbox_merkelized_payload_hashes_repr.hash witness in + {hash; level = inbox.level} + in + Skip_list.next ~prev_cell ~prev_cell_ptr current_level_proof + in + {inbox with old_levels_messages} + let add_messages payloads_history payloads witness = let open Result_syntax in let* () = @@ -706,43 +719,25 @@ let init_witness payloads_history = return (payloads_history, witness) let init_witness_no_history = - let no_payloads_history = - Sc_rollup_inbox_merkelized_payload_hashes_repr.History.no_history - in - let res = init_witness no_payloads_history in - match res with - | Ok (_payloads_history, witness) -> witness - | Error _ -> - (* We extract the [witness] from the result monad so the caller does - not have to deal with the error case. This is a top-level declaration, - this will fail at compile-time. *) - (* TODO: https://gitlab.com/tezos/tezos/-/issues/4359 - - Adding [SOL] without the history could remove the result monad here. *) - assert false + let sol = Sc_rollup_inbox_message_repr.start_of_level_serialized in + Sc_rollup_inbox_merkelized_payload_hashes_repr.genesis_no_history sol let add_info_per_level ~predecessor_timestamp ~predecessor payloads_history witness = - let open Result_syntax in - let* info_per_level = - Sc_rollup_inbox_message_repr.( - serialize (Internal (Info_per_level {predecessor_timestamp; predecessor}))) + let info_per_level = + Sc_rollup_inbox_message_repr.info_per_level_serialized + ~predecessor_timestamp + ~predecessor in add_protocol_internal_message info_per_level payloads_history witness let add_info_per_level_no_history ~predecessor_timestamp ~predecessor witness = - let open Result_syntax in - let no_payloads_history = - Sc_rollup_inbox_merkelized_payload_hashes_repr.History.no_history - in - let* _payloads_history, witness = - add_info_per_level + let info_per_level = + Sc_rollup_inbox_message_repr.info_per_level_serialized ~predecessor_timestamp ~predecessor - no_payloads_history - witness in - return witness + add_protocol_internal_message_no_history info_per_level witness let finalize_inbox_level payloads_history history inbox witness = let open Result_syntax in @@ -755,15 +750,10 @@ let finalize_inbox_level payloads_history history inbox witness = return (payloads_history, history, witness, inbox) let finalize_inbox_level_no_history inbox witness = - let open Result_syntax in - let* _payloads_history, _history, _witness, inbox = - finalize_inbox_level - Sc_rollup_inbox_merkelized_payload_hashes_repr.History.no_history - no_history - inbox - witness - in - return inbox + let inbox = {inbox with level = Raw_level_repr.succ inbox.level} in + let eol = Sc_rollup_inbox_message_repr.end_of_level_serialized in + let witness = add_protocol_internal_message_no_history eol witness in + archive_no_history inbox witness let add_all_messages ~protocol_migration_message ~predecessor_timestamp ~predecessor history inbox messages = @@ -832,33 +822,28 @@ let add_all_messages ~protocol_migration_message ~predecessor_timestamp let genesis ~protocol_migration_message ~predecessor_timestamp ~predecessor level = let open Result_syntax in - let no_payloads_history = - Sc_rollup_inbox_merkelized_payload_hashes_repr.History.no_history - in (* 1. Add [SOL], [Protocol_migration], and [Info_per_level]. *) let witness = init_witness_no_history in - let* protocol_migration = + let+ protocol_migration = Sc_rollup_inbox_message_repr.serialize (Internal protocol_migration_message) in - let* _payloads_history, witness = - add_protocol_internal_message protocol_migration no_payloads_history witness + let witness = + add_protocol_internal_message_no_history protocol_migration witness in - let* witness = + let witness = add_info_per_level_no_history ~predecessor_timestamp ~predecessor witness in (* 2. Add [EOL]. *) let eol = Sc_rollup_inbox_message_repr.end_of_level_serialized in - let* _payloads_history, witness = - add_protocol_internal_message eol no_payloads_history witness - in + let witness = add_protocol_internal_message_no_history eol witness in let level_proof = let hash = Sc_rollup_inbox_merkelized_payload_hashes_repr.hash witness in {hash; level} in - return {level; old_levels_messages = Skip_list.genesis level_proof} + {level; old_levels_messages = Skip_list.genesis level_proof} module Internal_for_tests = struct type nonrec inclusion_proof = inclusion_proof diff --git a/src/proto_alpha/lib_protocol/sc_rollup_inbox_repr.mli b/src/proto_alpha/lib_protocol/sc_rollup_inbox_repr.mli index 412d5c593709..7616407c5687 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_inbox_repr.mli +++ b/src/proto_alpha/lib_protocol/sc_rollup_inbox_repr.mli @@ -330,13 +330,13 @@ val add_info_per_level_no_history : predecessor_timestamp:Time.t -> predecessor:Block_hash.t -> Sc_rollup_inbox_merkelized_payload_hashes_repr.t -> - Sc_rollup_inbox_merkelized_payload_hashes_repr.t tzresult + Sc_rollup_inbox_merkelized_payload_hashes_repr.t (** [finalize_inbox_level payloads_history history inbox level_witness] updates the current inbox's level witness by adding [EOL], and archives the current level. *) val finalize_inbox_level_no_history : - t -> Sc_rollup_inbox_merkelized_payload_hashes_repr.t -> t tzresult + t -> Sc_rollup_inbox_merkelized_payload_hashes_repr.t -> t (** [genesis ~protocol_migration_message ~timestamp ~predecessor level] initializes the inbox at some given [level] with: [SOL], diff --git a/src/proto_alpha/lib_protocol/sc_rollup_inbox_storage.ml b/src/proto_alpha/lib_protocol/sc_rollup_inbox_storage.ml index d41e28ad6c9d..23c1764f4c08 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_inbox_storage.ml +++ b/src/proto_alpha/lib_protocol/sc_rollup_inbox_storage.ml @@ -119,7 +119,7 @@ let finalize_inbox_level ctxt = let open Lwt_result_syntax in let* inbox, ctxt = get_inbox ctxt in let witness = Raw_context.Sc_rollup_in_memory_inbox.current_messages ctxt in - let*? inbox = + let inbox = Sc_rollup_inbox_repr.finalize_inbox_level_no_history inbox witness in let* ctxt = Store.Inbox.update ctxt inbox in @@ -171,42 +171,19 @@ let add_protocol_migration ctxt = return ctxt let add_info_per_level ~predecessor ctxt = - let open Lwt_syntax in - let* res = - let open Lwt_result_syntax in - let predecessor_timestamp = Raw_context.predecessor_timestamp ctxt in - let witness = Raw_context.Sc_rollup_in_memory_inbox.current_messages ctxt in - let*? witness = - Sc_rollup_inbox_repr.add_info_per_level_no_history - ~predecessor_timestamp - ~predecessor - witness - in - let ctxt = - Raw_context.Sc_rollup_in_memory_inbox.set_current_messages ctxt witness - in - return ctxt + let predecessor_timestamp = Raw_context.predecessor_timestamp ctxt in + let witness = Raw_context.Sc_rollup_in_memory_inbox.current_messages ctxt in + let witness = + Sc_rollup_inbox_repr.add_info_per_level_no_history + ~predecessor_timestamp + ~predecessor + witness in - match res with - | Ok ctxt -> return ctxt - | Error err -> - (* As a protection, we backtrack the [ctxt] if adding the info per level - failed. This way, we cannot make [begin_application], - [begin_partial_application] and [begin_full_construction] fail. *) - Logging.( - log - Fatal - "Adding [Info_per_level] failed because of %a, the context is \ - backtracked. Smart rollups inbox failed to finalize this block, \ - this behavior is undefined and its consequence is unexplored." - pp_trace - err) ; - return ctxt + Raw_context.Sc_rollup_in_memory_inbox.set_current_messages ctxt witness let init_inbox ~predecessor ctxt = let open Lwt_syntax in let* res = - let open Lwt_result_syntax in let ({level; _} : Level_repr.t) = Raw_context.current_level ctxt in let predecessor_timestamp = Raw_context.predecessor_timestamp ctxt in let*? inbox = @@ -217,8 +194,7 @@ let init_inbox ~predecessor ctxt = ~predecessor level in - let* ctxt = Store.Inbox.init ctxt inbox in - return ctxt + Store.Inbox.init ctxt inbox in match res with | Ok ctxt -> return ctxt diff --git a/src/proto_alpha/lib_protocol/sc_rollup_inbox_storage.mli b/src/proto_alpha/lib_protocol/sc_rollup_inbox_storage.mli index c557c100eb7b..df81a120a338 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_inbox_storage.mli +++ b/src/proto_alpha/lib_protocol/sc_rollup_inbox_storage.mli @@ -57,7 +57,7 @@ val add_protocol_migration : Raw_context.t -> Raw_context.t Lwt.t (** Adds the [Info_per_level] in the in-memory inbox level witness. *) val add_info_per_level : - predecessor:Block_hash.t -> Raw_context.t -> Raw_context.t Lwt.t + predecessor:Block_hash.t -> Raw_context.t -> Raw_context.t (** [finalize_inbox_level ctxt] ends the internal representation for the block. *) diff --git a/src/proto_alpha/lib_protocol/test/helpers/sc_rollup_helpers.ml b/src/proto_alpha/lib_protocol/test/helpers/sc_rollup_helpers.ml index 7a74aea5cd70..4d26ef225900 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/sc_rollup_helpers.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/sc_rollup_helpers.ml @@ -612,11 +612,10 @@ let list_of_inputs_from_list_of_messages payloads_per_levels let dumb_init level = - WithExceptions.Result.get_ok ~loc:__LOC__ - @@ Sc_rollup.Inbox.genesis - ~predecessor_timestamp:Time.Protocol.epoch - ~predecessor:Block_hash.zero - level + Sc_rollup.Inbox.genesis + ~predecessor_timestamp:Time.Protocol.epoch + ~predecessor:Block_hash.zero + level let dumb_init_repr level = WithExceptions.Result.get_ok ~loc:__LOC__ @@ -820,12 +819,11 @@ module Protocol_inbox = struct messages in let witness = Sc_rollup.Inbox.init_witness_no_history in - let* witness = - Environment.wrap_tzresult - @@ Sc_rollup.Inbox.add_info_per_level_no_history - ~predecessor_timestamp - ~predecessor - witness + let witness = + Sc_rollup.Inbox.add_info_per_level_no_history + ~predecessor_timestamp + ~predecessor + witness in let* witness = if List.is_empty payloads then ok witness @@ -833,9 +831,8 @@ module Protocol_inbox = struct Environment.wrap_tzresult @@ Sc_rollup.Inbox.add_messages_no_history payloads witness in - let* inbox = - Environment.wrap_tzresult - @@ Sc_rollup.Inbox.finalize_inbox_level_no_history inbox witness + let inbox = + Sc_rollup.Inbox.finalize_inbox_level_no_history inbox witness in aux inbox rst in diff --git a/src/proto_alpha/lib_protocol/test/pbt/test_sc_rollup_encoding.ml b/src/proto_alpha/lib_protocol/test/pbt/test_sc_rollup_encoding.ml index cbe883a48a47..b324e4641f23 100644 --- a/src/proto_alpha/lib_protocol/test/pbt/test_sc_rollup_encoding.ml +++ b/src/proto_alpha/lib_protocol/test/pbt/test_sc_rollup_encoding.ml @@ -26,8 +26,8 @@ (** Testing ------- Component: Protocol Library - Invocation: dune exec \ - src/proto_alpha/lib_protocol/test/pbt/test_sc_rollup_encoding.exe + Invocation: dune exec src/proto_alpha/lib_protocol/test/pbt/main.exe \ + -- -f 'SC rollup encoding' Subject: SC rollup encoding *) @@ -95,7 +95,7 @@ let gen_inbox level = Environment.wrap_tzresult @@ let witness = Sc_rollup_inbox_repr.init_witness_no_history in - let* witness = + let witness = Sc_rollup_inbox_repr.add_info_per_level_no_history ~predecessor_timestamp:Time.Protocol.epoch ~predecessor:Block_hash.zero @@ -109,7 +109,7 @@ let gen_inbox level = let* witness = Sc_rollup_inbox_repr.add_messages_no_history input_messages witness in - Sc_rollup_inbox_repr.finalize_inbox_level_no_history inbox witness + return (Sc_rollup_inbox_repr.finalize_inbox_level_no_history inbox witness) in return @@ (witness_and_inbox |> function diff --git a/src/proto_alpha/lib_sc_rollup_node/inbox.ml b/src/proto_alpha/lib_sc_rollup_node/inbox.ml index 8482218af91e..1b91398fb589 100644 --- a/src/proto_alpha/lib_sc_rollup_node/inbox.ml +++ b/src/proto_alpha/lib_sc_rollup_node/inbox.ml @@ -237,5 +237,5 @@ let payloads_history_of_messages ~is_migration_block ~predecessor (Sc_rollup.Inbox.History.empty ~capacity:0L) dummy_inbox messages - in - payloads_history + in + payloads_history -- GitLab From 4d3482982ca6949e551408e3f7a4efb64f3add35 Mon Sep 17 00:00:00 2001 From: Alain Mebsout Date: Mon, 27 Feb 2023 19:37:21 +0100 Subject: [PATCH 2/4] Proto/SCORU: remove failsafe mechanism for finalize_inbox As well as init_inbox. The only failure that can happen is a storage one which is already the case with all the other functions called in block finalization and migration. --- .../lib_protocol/alpha_context.mli | 2 +- src/proto_alpha/lib_protocol/apply.ml | 2 +- src/proto_alpha/lib_protocol/init_storage.ml | 2 +- .../lib_protocol/sc_rollup_inbox_storage.ml | 68 +++++-------------- .../lib_protocol/sc_rollup_inbox_storage.mli | 4 +- 5 files changed, 22 insertions(+), 56 deletions(-) diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index 9cac03f3b0c4..b849b993a37f 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -3548,7 +3548,7 @@ module Sc_rollup : sig destination:rollup -> context tzresult Lwt.t - val finalize_inbox_level : context -> context Lwt.t + val finalize_inbox_level : context -> context tzresult Lwt.t val add_info_per_level : predecessor:Block_hash.t -> context -> context diff --git a/src/proto_alpha/lib_protocol/apply.ml b/src/proto_alpha/lib_protocol/apply.ml index 1bdfe3b03bbd..11d565336f97 100644 --- a/src/proto_alpha/lib_protocol/apply.ml +++ b/src/proto_alpha/lib_protocol/apply.ml @@ -2589,7 +2589,7 @@ let finalize_application ctxt block_data_contents ~round ~predecessor_hash in let* ctxt = Amendment.may_start_new_voting_period ctxt in let* ctxt, dal_attestation = Dal_apply.finalisation ctxt in - let*! ctxt = Sc_rollup.Inbox.finalize_inbox_level ctxt in + let* ctxt = Sc_rollup.Inbox.finalize_inbox_level ctxt in let balance_updates = migration_balance_updates @ baking_receipts @ cycle_end_balance_updates in diff --git a/src/proto_alpha/lib_protocol/init_storage.ml b/src/proto_alpha/lib_protocol/init_storage.ml index cd1924024a48..5a12fbcc4e9f 100644 --- a/src/proto_alpha/lib_protocol/init_storage.ml +++ b/src/proto_alpha/lib_protocol/init_storage.ml @@ -155,7 +155,7 @@ let prepare_first_block _chain_id ctxt ~typecheck ~level ~timestamp ~predecessor >>=? fun (ctxt, operation_results) -> Storage.Pending_migration.Operation_results.init ctxt operation_results >>=? fun ctxt -> - Sc_rollup_inbox_storage.init_inbox ~predecessor ctxt >>= fun ctxt -> + Sc_rollup_inbox_storage.init_inbox ~predecessor ctxt >>=? fun ctxt -> return ( ctxt, commitments_balance_updates @ bootstrap_balance_updates diff --git a/src/proto_alpha/lib_protocol/sc_rollup_inbox_storage.ml b/src/proto_alpha/lib_protocol/sc_rollup_inbox_storage.ml index 23c1764f4c08..8c7aea0a0a2f 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_inbox_storage.ml +++ b/src/proto_alpha/lib_protocol/sc_rollup_inbox_storage.ml @@ -114,31 +114,13 @@ let add_deposit ctxt ~payload ~sender ~source ~destination = add_internal_message ctxt internal_message let finalize_inbox_level ctxt = - let open Lwt_syntax in - let* res = - let open Lwt_result_syntax in - let* inbox, ctxt = get_inbox ctxt in - let witness = Raw_context.Sc_rollup_in_memory_inbox.current_messages ctxt in - let inbox = - Sc_rollup_inbox_repr.finalize_inbox_level_no_history inbox witness - in - let* ctxt = Store.Inbox.update ctxt inbox in - return ctxt + let open Lwt_result_syntax in + let* inbox, ctxt = get_inbox ctxt in + let witness = Raw_context.Sc_rollup_in_memory_inbox.current_messages ctxt in + let inbox = + Sc_rollup_inbox_repr.finalize_inbox_level_no_history inbox witness in - match res with - | Ok ctxt -> return ctxt - | Error err -> - (* As a protection, we backtrack the [ctxt] if finalizing the inbox level - failed. This way, we cannot make [finalize_block] fail. *) - Logging.( - log - Fatal - "Finalizing inbox level failed because of %a, the context is \ - backtracked. Smart rollups inbox failed to finalize this block, \ - this behavior is undefined and its consequence is unexplored." - pp_trace - err) ; - return ctxt + Store.Inbox.update ctxt inbox let add_protocol_migration ctxt = let open Lwt_syntax in @@ -182,31 +164,15 @@ let add_info_per_level ~predecessor ctxt = Raw_context.Sc_rollup_in_memory_inbox.set_current_messages ctxt witness let init_inbox ~predecessor ctxt = - let open Lwt_syntax in - let* res = - let ({level; _} : Level_repr.t) = Raw_context.current_level ctxt in - let predecessor_timestamp = Raw_context.predecessor_timestamp ctxt in - let*? inbox = - Sc_rollup_inbox_repr.genesis - ~protocol_migration_message: - Raw_context.protocol_migration_internal_message - ~predecessor_timestamp - ~predecessor - level - in - Store.Inbox.init ctxt inbox + let open Lwt_result_syntax in + let ({level; _} : Level_repr.t) = Raw_context.current_level ctxt in + let predecessor_timestamp = Raw_context.predecessor_timestamp ctxt in + let*? inbox = + Sc_rollup_inbox_repr.genesis + ~protocol_migration_message: + Raw_context.protocol_migration_internal_message + ~predecessor_timestamp + ~predecessor + level in - match res with - | Ok ctxt -> return ctxt - | Error err -> - (* As a protection, we backtrack the [ctxt] if initializing the inbox - failed. This way, we cannot make [prepare_first_block] fail. *) - Logging.( - log - Fatal - "Initializing inbox failed because of %a, the context is \ - backtracked. Smart rollups inbox failed, this behavior is undefined \ - and its consequence is unexplored." - pp_trace - err) ; - return ctxt + Store.Inbox.init ctxt inbox diff --git a/src/proto_alpha/lib_protocol/sc_rollup_inbox_storage.mli b/src/proto_alpha/lib_protocol/sc_rollup_inbox_storage.mli index df81a120a338..eed430707a00 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_inbox_storage.mli +++ b/src/proto_alpha/lib_protocol/sc_rollup_inbox_storage.mli @@ -50,7 +50,7 @@ val add_deposit : (** Initialize the inbox in the storage at protocol initialization. *) val init_inbox : - predecessor:Block_hash.t -> Raw_context.t -> Raw_context.t Lwt.t + predecessor:Block_hash.t -> Raw_context.t -> Raw_context.t tzresult Lwt.t (** Adds the [Protocol_migration] in the in-memory inbox level witness. *) val add_protocol_migration : Raw_context.t -> Raw_context.t Lwt.t @@ -61,4 +61,4 @@ val add_info_per_level : (** [finalize_inbox_level ctxt] ends the internal representation for the block. *) -val finalize_inbox_level : Raw_context.t -> Raw_context.t Lwt.t +val finalize_inbox_level : Raw_context.t -> Raw_context.t tzresult Lwt.t -- GitLab From 6da2bb3e9b226b294914d16ae0f37a7baeff664c Mon Sep 17 00:00:00 2001 From: Alain Mebsout Date: Thu, 2 Mar 2023 17:32:59 +0100 Subject: [PATCH 3/4] Test: PBT for non failing add_info_per_level --- manifest/main.ml | 1 + src/proto_alpha/lib_protocol/test/pbt/dune | 1 + .../test/pbt/test_sc_rollup_inbox.ml | 80 +++++++++++++++++++ 3 files changed, 82 insertions(+) create mode 100644 src/proto_alpha/lib_protocol/test/pbt/test_sc_rollup_inbox.ml diff --git a/manifest/main.ml b/manifest/main.ml index 533801ee65ef..e3740a32d30e 100644 --- a/manifest/main.ml +++ b/manifest/main.ml @@ -4077,6 +4077,7 @@ end = struct (2, "test_bitset", N.(number >= 013)); (2, "test_sc_rollup_tick_repr", N.(number >= 013)); (2, "test_sc_rollup_encoding", N.(number >= 015)); + (2, "test_sc_rollup_inbox", N.(number >= 017)); (3, "refutation_game_pbt", N.(number == 013)); (3, "test_refutation_game", N.(number >= 016)); (3, "test_carbonated_map", N.(number >= 013)); diff --git a/src/proto_alpha/lib_protocol/test/pbt/dune b/src/proto_alpha/lib_protocol/test/pbt/dune index 3c8ac4126d05..bf93c73aa5ff 100644 --- a/src/proto_alpha/lib_protocol/test/pbt/dune +++ b/src/proto_alpha/lib_protocol/test/pbt/dune @@ -51,6 +51,7 @@ test_bitset test_sc_rollup_tick_repr test_sc_rollup_encoding + test_sc_rollup_inbox test_refutation_game test_carbonated_map test_zk_rollup_encoding diff --git a/src/proto_alpha/lib_protocol/test/pbt/test_sc_rollup_inbox.ml b/src/proto_alpha/lib_protocol/test/pbt/test_sc_rollup_inbox.ml new file mode 100644 index 000000000000..b0b7d811a548 --- /dev/null +++ b/src/proto_alpha/lib_protocol/test/pbt/test_sc_rollup_inbox.ml @@ -0,0 +1,80 @@ +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2022 Nomadic Labs, *) +(* *) +(* Permission is hereby granted, free of charge, to any person obtaining a *) +(* copy of this software and associated documentation files (the "Software"),*) +(* to deal in the Software without restriction, including without limitation *) +(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) +(* and/or sell copies of the Software, and to permit persons to whom the *) +(* Software is furnished to do so, subject to the following conditions: *) +(* *) +(* The above copyright notice and this permission notice shall be included *) +(* in all copies or substantial portions of the Software. *) +(* *) +(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) +(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) +(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) +(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) +(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) +(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) +(* DEALINGS IN THE SOFTWARE. *) +(* *) +(*****************************************************************************) + +(** Testing + ------- + Component: Protocol Library + Invocation: dune exec src/proto_alpha/lib_protocol/test/pbt/main.exe \ + -- -f 'Smart rollup inbox' + Subject: Smart rollup inbox +*) + +open Protocol +open Qcheck2_helpers + +let gen_block_hash = + let open QCheck2.Gen in + let gen = + let+ b = bytes_fixed_gen Block_hash.size in + Block_hash.of_bytes_exn b + in + (* This is not beautiful, but there is currently no other way to + remove the shrinker. *) + make_primitive + ~gen:(fun rand -> generate1 ~rand gen) + ~shrink:(fun _ -> Seq.empty) + +let gen_time = + let open QCheck2.Gen in + let+ s = int64 in + Time.Protocol.of_seconds s + +let gen_add_info_per_level = + let open QCheck2.Gen in + let* predecessor_timestamp = gen_time in + let* predecessor = gen_block_hash in + return (predecessor_timestamp, predecessor) + +let test_add_info_per_level = + QCheck2.Test.make + ~count:10_000 + ~name:"test_add_info_per_level" + gen_add_info_per_level + @@ fun (predecessor_timestamp, predecessor) -> + (* Test that we can indeed serialize the [Info_per_level] message for these + inputs *) + let _bytes = + Sc_rollup_inbox_message_repr.info_per_level_serialized + ~predecessor_timestamp + ~predecessor + in + true + +let tests = [test_add_info_per_level] + +let () = + Alcotest.run + "Smart rollup inbox" + [(Protocol.name ^ ": safety", qcheck_wrap tests)] -- GitLab From b469cda563ae7253f3698d702006320ba74b122f Mon Sep 17 00:00:00 2001 From: Alain Mebsout Date: Thu, 2 Mar 2023 18:25:02 +0100 Subject: [PATCH 4/4] Proto/SCORU: add migration protocol message does not fail --- src/proto_alpha/lib_protocol/alpha_context.ml | 5 ++- .../lib_protocol/alpha_context.mli | 4 +- src/proto_alpha/lib_protocol/init_storage.ml | 2 +- src/proto_alpha/lib_protocol/raw_context.ml | 14 +++++++ src/proto_alpha/lib_protocol/raw_context.mli | 4 ++ .../lib_protocol/sc_rollup_inbox_repr.ml | 6 +-- .../lib_protocol/sc_rollup_inbox_repr.mli | 4 +- .../lib_protocol/sc_rollup_inbox_storage.ml | 38 ++++-------------- .../lib_protocol/sc_rollup_inbox_storage.mli | 2 +- .../test/helpers/sc_rollup_helpers.ml | 40 ++++++++----------- src/proto_alpha/lib_sc_rollup_node/inbox.ml | 28 ++++++------- 11 files changed, 68 insertions(+), 79 deletions(-) diff --git a/src/proto_alpha/lib_protocol/alpha_context.ml b/src/proto_alpha/lib_protocol/alpha_context.ml index 2a83eb96f132..18c5c2b57580 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.ml +++ b/src/proto_alpha/lib_protocol/alpha_context.ml @@ -67,6 +67,9 @@ module Sc_rollup = struct let protocol_migration_internal_message = Raw_context.protocol_migration_internal_message + + let protocol_migration_serialized_message = + Raw_context.protocol_migration_serialized_message end module Inbox_merkelized_payload_hashes = @@ -84,7 +87,7 @@ module Sc_rollup = struct let genesis = genesis ~protocol_migration_message: - Inbox_message.protocol_migration_internal_message + Inbox_message.protocol_migration_serialized_message let add_all_messages ~first_block = add_all_messages diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index b849b993a37f..a215cb1b20b3 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -3272,6 +3272,8 @@ module Sc_rollup : sig type serialized = private string + val protocol_migration_serialized_message : serialized + val encoding : t Data_encoding.t val unsafe_of_string : string -> serialized @@ -3488,7 +3490,7 @@ module Sc_rollup : sig predecessor_timestamp:Time.t -> predecessor:Block_hash.t -> Raw_level.t -> - t tzresult + t module Internal_for_tests : sig type inclusion_proof = history_proof list diff --git a/src/proto_alpha/lib_protocol/init_storage.ml b/src/proto_alpha/lib_protocol/init_storage.ml index 5a12fbcc4e9f..0ea2a0baeaed 100644 --- a/src/proto_alpha/lib_protocol/init_storage.ml +++ b/src/proto_alpha/lib_protocol/init_storage.ml @@ -171,7 +171,7 @@ let prepare_first_block _chain_id ctxt ~typecheck ~level ~timestamp ~predecessor Storage.Legacy.Grand_parent_branch.remove ctxt >>= fun ctxt -> (* This needs to be kept in the migration code for every protocol, except Genesis. *) - Sc_rollup_inbox_storage.add_protocol_migration ctxt >>= fun ctxt -> + let ctxt = Sc_rollup_inbox_storage.add_protocol_migration ctxt in return (ctxt, [])) >>=? fun (ctxt, balance_updates) -> List.fold_right_es patch_script Legacy_script_patches.addresses_to_patch ctxt diff --git a/src/proto_alpha/lib_protocol/raw_context.ml b/src/proto_alpha/lib_protocol/raw_context.ml index 297a17360ce9..7e1e67fe8b77 100644 --- a/src/proto_alpha/lib_protocol/raw_context.ml +++ b/src/proto_alpha/lib_protocol/raw_context.ml @@ -648,6 +648,20 @@ let version = "v1" let protocol_migration_internal_message = Sc_rollup_inbox_message_repr.Protocol_migration version_value +let protocol_migration_serialized_message = + match + Sc_rollup_inbox_message_repr.serialize + (Internal protocol_migration_internal_message) + with + | Ok msg -> msg + | Error trace -> + Format.kasprintf + failwith + "%s: Could not serialize protocol message : %a" + __LOC__ + pp_trace + trace + let cycle_eras_key = [version; "cycle_eras"] let constants_key = [version; "constants"] diff --git a/src/proto_alpha/lib_protocol/raw_context.mli b/src/proto_alpha/lib_protocol/raw_context.mli index ba4398abf9ba..db67547aea84 100644 --- a/src/proto_alpha/lib_protocol/raw_context.mli +++ b/src/proto_alpha/lib_protocol/raw_context.mli @@ -78,6 +78,10 @@ type root = t val protocol_migration_internal_message : Sc_rollup_inbox_message_repr.internal_inbox_message +(** Serialized version of {!protocol_migration_internal_message}. *) +val protocol_migration_serialized_message : + Sc_rollup_inbox_message_repr.serialized + (** Retrieves the state of the database and gives its abstract view. It also returns wether this is the first block validated with this version of the protocol. *) diff --git a/src/proto_alpha/lib_protocol/sc_rollup_inbox_repr.ml b/src/proto_alpha/lib_protocol/sc_rollup_inbox_repr.ml index 0ea2d76067ac..1bda105c9717 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_inbox_repr.ml +++ b/src/proto_alpha/lib_protocol/sc_rollup_inbox_repr.ml @@ -821,14 +821,10 @@ let add_all_messages ~protocol_migration_message ~predecessor_timestamp let genesis ~protocol_migration_message ~predecessor_timestamp ~predecessor level = - let open Result_syntax in (* 1. Add [SOL], [Protocol_migration], and [Info_per_level]. *) let witness = init_witness_no_history in - let+ protocol_migration = - Sc_rollup_inbox_message_repr.serialize (Internal protocol_migration_message) - in let witness = - add_protocol_internal_message_no_history protocol_migration witness + add_protocol_internal_message_no_history protocol_migration_message witness in let witness = add_info_per_level_no_history ~predecessor_timestamp ~predecessor witness diff --git a/src/proto_alpha/lib_protocol/sc_rollup_inbox_repr.mli b/src/proto_alpha/lib_protocol/sc_rollup_inbox_repr.mli index 7616407c5687..311ee0f5dfb0 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_inbox_repr.mli +++ b/src/proto_alpha/lib_protocol/sc_rollup_inbox_repr.mli @@ -346,11 +346,11 @@ val finalize_inbox_level_no_history : The expected value of [protocol_migration_message] is [Raw_context.protocol_migration_internal_message]. *) val genesis : - protocol_migration_message:Sc_rollup_inbox_message_repr.internal_inbox_message -> + protocol_migration_message:Sc_rollup_inbox_message_repr.serialized -> predecessor_timestamp:Time.t -> predecessor:Block_hash.t -> Raw_level_repr.t -> - t tzresult + t module Internal_for_tests : sig (** Given a inbox [A] at some level [L] and another inbox [B] at some level diff --git a/src/proto_alpha/lib_protocol/sc_rollup_inbox_storage.ml b/src/proto_alpha/lib_protocol/sc_rollup_inbox_storage.ml index 8c7aea0a0a2f..c23461813356 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_inbox_storage.ml +++ b/src/proto_alpha/lib_protocol/sc_rollup_inbox_storage.ml @@ -123,34 +123,13 @@ let finalize_inbox_level ctxt = Store.Inbox.update ctxt inbox let add_protocol_migration ctxt = - let open Lwt_syntax in - let res = - let open Result_syntax in - let witness = Raw_context.Sc_rollup_in_memory_inbox.current_messages ctxt in - let* protocol_migration = - Sc_rollup_inbox_message_repr.serialize - (Internal Raw_context.protocol_migration_internal_message) - in - let+ witness = - Sc_rollup_inbox_repr.add_messages_no_history [protocol_migration] witness - in - Raw_context.Sc_rollup_in_memory_inbox.set_current_messages ctxt witness + let witness = Raw_context.Sc_rollup_in_memory_inbox.current_messages ctxt in + let witness = + Sc_rollup_inbox_merkelized_payload_hashes_repr.add_payload_no_history + witness + Raw_context.protocol_migration_serialized_message in - match res with - | Ok ctxt -> return ctxt - | Error err -> - (* As a protection, we backtrack the [ctxt] if adding the info per level - failed. This way, we cannot make [begin_application], - [begin_partial_application] and [begin_full_construction] fail. *) - Logging.( - log - Fatal - "Adding [Protocol_migration] failed because of %a, the context is \ - backtracked. Smart rollups inbox might be inconsistent, this \ - behavior is undefined and its consequence is unexplored." - pp_trace - err) ; - return ctxt + Raw_context.Sc_rollup_in_memory_inbox.set_current_messages ctxt witness let add_info_per_level ~predecessor ctxt = let predecessor_timestamp = Raw_context.predecessor_timestamp ctxt in @@ -164,13 +143,12 @@ let add_info_per_level ~predecessor ctxt = Raw_context.Sc_rollup_in_memory_inbox.set_current_messages ctxt witness let init_inbox ~predecessor ctxt = - let open Lwt_result_syntax in let ({level; _} : Level_repr.t) = Raw_context.current_level ctxt in let predecessor_timestamp = Raw_context.predecessor_timestamp ctxt in - let*? inbox = + let inbox = Sc_rollup_inbox_repr.genesis ~protocol_migration_message: - Raw_context.protocol_migration_internal_message + Raw_context.protocol_migration_serialized_message ~predecessor_timestamp ~predecessor level diff --git a/src/proto_alpha/lib_protocol/sc_rollup_inbox_storage.mli b/src/proto_alpha/lib_protocol/sc_rollup_inbox_storage.mli index eed430707a00..e3dc89141013 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_inbox_storage.mli +++ b/src/proto_alpha/lib_protocol/sc_rollup_inbox_storage.mli @@ -53,7 +53,7 @@ val init_inbox : predecessor:Block_hash.t -> Raw_context.t -> Raw_context.t tzresult Lwt.t (** Adds the [Protocol_migration] in the in-memory inbox level witness. *) -val add_protocol_migration : Raw_context.t -> Raw_context.t Lwt.t +val add_protocol_migration : Raw_context.t -> Raw_context.t (** Adds the [Info_per_level] in the in-memory inbox level witness. *) val add_info_per_level : diff --git a/src/proto_alpha/lib_protocol/test/helpers/sc_rollup_helpers.ml b/src/proto_alpha/lib_protocol/test/helpers/sc_rollup_helpers.ml index 4d26ef225900..6b3ffe77c4cb 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/sc_rollup_helpers.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/sc_rollup_helpers.ml @@ -618,13 +618,12 @@ let dumb_init level = level let dumb_init_repr level = - WithExceptions.Result.get_ok ~loc:__LOC__ - @@ Sc_rollup_inbox_repr.genesis - ~protocol_migration_message: - Raw_context.protocol_migration_internal_message - ~predecessor_timestamp:Time.Protocol.epoch - ~predecessor:Block_hash.zero - level + Sc_rollup_inbox_repr.genesis + ~protocol_migration_message: + Raw_context.protocol_migration_serialized_message + ~predecessor_timestamp:Time.Protocol.epoch + ~predecessor:Block_hash.zero + level let origination_op ?force_reveal ?counter ?fee ?gas_limit ?storage_limit ?origination_proof ?(boot_sector = "") ?(parameters_ty = "unit") ctxt src @@ -665,12 +664,11 @@ module Node_inbox = struct ?(genesis_predecessor = Block_hash.zero) ?(inbox_creation_level = Raw_level.root) () = let open Result_syntax in - let* inbox = - Environment.wrap_tzresult - @@ Sc_rollup.Inbox.genesis - ~predecessor_timestamp:genesis_predecessor_timestamp - ~predecessor:genesis_predecessor - inbox_creation_level + let inbox = + Sc_rollup.Inbox.genesis + ~predecessor_timestamp:genesis_predecessor_timestamp + ~predecessor:genesis_predecessor + inbox_creation_level in let history = Sc_rollup.Inbox.History.empty ~capacity:10000L in let payloads_histories = Payloads_histories.empty in @@ -787,15 +785,10 @@ module Protocol_inbox = struct let new_inbox ?(genesis_predecessor_timestamp = Time.Protocol.epoch) ?(genesis_predecessor = Block_hash.zero) ?(inbox_creation_level = Raw_level.root) () = - let open Result_syntax in - let* inbox = - Environment.wrap_tzresult - @@ Sc_rollup.Inbox.genesis - ~predecessor_timestamp:genesis_predecessor_timestamp - ~predecessor:genesis_predecessor - inbox_creation_level - in - return inbox + Sc_rollup.Inbox.genesis + ~predecessor_timestamp:genesis_predecessor_timestamp + ~predecessor:genesis_predecessor + inbox_creation_level let fill_inbox inbox payloads_per_levels = let open Result_syntax in @@ -850,8 +843,7 @@ module Protocol_inbox = struct let construct_inbox ?inbox_creation_level ?genesis_predecessor_timestamp ?genesis_predecessor payloads_per_levels = - let open Result_syntax in - let* inbox = + let inbox = new_inbox ?genesis_predecessor_timestamp ?genesis_predecessor diff --git a/src/proto_alpha/lib_sc_rollup_node/inbox.ml b/src/proto_alpha/lib_sc_rollup_node/inbox.ml index 1b91398fb589..8308d58e3328 100644 --- a/src/proto_alpha/lib_sc_rollup_node/inbox.ml +++ b/src/proto_alpha/lib_sc_rollup_node/inbox.ml @@ -217,20 +217,20 @@ let start () = Inbox_event.starting () let payloads_history_of_messages ~is_migration_block ~predecessor ~predecessor_timestamp messages = let open Result_syntax in - Environment.wrap_tzresult - @@ let* dummy_inbox = - (* The inbox is not necessary to compute the payloads *) - Sc_rollup.Inbox.genesis - ~predecessor_timestamp - ~predecessor - Raw_level.root - in - let+ ( payloads_history, - _history, - _inbox, - _witness, - _messages_with_protocol_internal_messages ) = - Sc_rollup.Inbox.add_all_messages + let dummy_inbox = + (* The inbox is not necessary to compute the payloads *) + Sc_rollup.Inbox.genesis ~predecessor_timestamp ~predecessor Raw_level.root + in + let+ ( payloads_history, + _history, + _inbox, + _witness, + _messages_with_protocol_internal_messages ) = + (* TODO: https://gitlab.com/tezos/tezos/-/issues/4918 Inject + [Protocol_migration (Proto_017)] when migrating to proto_alpha + (N after next snapshot). *) + Environment.wrap_tzresult + @@ Sc_rollup.Inbox.add_all_messages ~first_block:is_migration_block ~predecessor_timestamp ~predecessor -- GitLab