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 5dbb4a844ce2e5616cae1579430deb0694d0b7df..94e0b50eef4ed922eea1d5c5f073ec705f546333 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_inbox_repr.ml +++ b/src/proto_alpha/lib_protocol/sc_rollup_inbox_repr.ml @@ -83,7 +83,7 @@ let () = ~description: "Sc_rollup_inbox.consume_n_messages must be called with a non negative \ integer." - (obj1 (req "n" int64)) + (obj1 (req "consume_n_messages" int64)) (function Invalid_number_of_messages_to_consume n -> Some n | _ -> None) (fun n -> Invalid_number_of_messages_to_consume n) @@ -494,12 +494,20 @@ module MakeHashingScheme (Tree : TREE) : counter = 0L; } - (** [remember ptr cell history] extends [history] with a new + type without_history_witness + + type with_history_witness + + type _ with_history = + | No_history : without_history_witness with_history + | With_history : history -> with_history_witness with_history + + (** [remember_history ptr cell history] extends [history] with a new mapping from [ptr] to [cell]. If [history] is full, the oldest mapping is removed. If the history bound is less or equal to zero, then this function returns [history] untouched. *) - let remember ptr cell history = + let remember_history ptr cell history = if Compare.Int64.(history.bound <= 0L) then history else let events = Context_hash.Map.add ptr cell history.events in @@ -526,6 +534,17 @@ module MakeHashingScheme (Tree : TREE) : } else history + let remember : + type history_witness. + history_proof_hash -> + history_proof -> + history_witness with_history -> + history_witness with_history = + fun ptr cell history -> + match history with + | No_history -> No_history + | With_history history -> With_history (remember_history ptr cell history) + let archive_if_needed history inbox target_level = let archive_level history inbox = let prev_cell = inbox.old_levels_messages in @@ -561,7 +580,7 @@ module MakeHashingScheme (Tree : TREE) : in aux (history, inbox) - let add_messages history inbox level payloads messages = + let add_messages_aux history inbox level payloads messages = let open Lwt_tzresult_syntax in if Raw_level_repr.(level < inbox.level) then fail (Invalid_level_add_messages level) @@ -579,11 +598,17 @@ module MakeHashingScheme (Tree : TREE) : in return (messages, history, {inbox with current_messages_hash}) + let add_messages history inbox level payloads messages = + let open Lwt_tzresult_syntax in + let* messages, With_history history, inbox = + add_messages_aux (With_history history) inbox level payloads messages + in + return (messages, history, inbox) + let add_messages_no_history inbox level payloads messages = let open Lwt_tzresult_syntax in - let history = history_at_genesis ~bound:0L in - let* messages, _, inbox = - add_messages history inbox level payloads messages + let* messages, No_history, inbox = + add_messages_aux No_history inbox level payloads messages in return (messages, inbox) @@ -612,7 +637,9 @@ module MakeHashingScheme (Tree : TREE) : let produce_inclusion_proof history inbox1 inbox2 = let cell_ptr = hash_old_levels_messages inbox2.old_levels_messages in let target_index = Skip_list.index inbox1.old_levels_messages in - let history = remember cell_ptr inbox2.old_levels_messages history in + let (With_history history) = + remember cell_ptr inbox2.old_levels_messages (With_history history) + in let deref ptr = Context_hash.Map.find_opt ptr history.events in Skip_list.back_path ~deref ~cell_ptr ~target_index |> Option.map (lift_ptr_path deref) 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 62af4dfb5016ffcf27c1df8fc558602c08c3570b..7c6db25a737b48803de434a0d3ec9aa9b3888cdf 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_inbox_repr.mli +++ b/src/proto_alpha/lib_protocol/sc_rollup_inbox_repr.mli @@ -67,7 +67,7 @@ (typically a low number of hashes) that witnesses its contents, so that the protocol can check the validity of a proof about its contents. This saves space in the context of the layer 1 and is sufficient for the - level 1 to provide a source of truth about the contents of the + layer 1 to provide a source of truth about the contents of the inbox at the current level. {1 A level-indexed chain of inboxes} diff --git a/src/proto_alpha/lib_protocol/sc_rollup_operations.mli b/src/proto_alpha/lib_protocol/sc_rollup_operations.mli index 9f817fac612526c853379420fe2111e450820f3c..f9d92a4371f8b6ebc69ea7a6102eb22958352b81 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_operations.mli +++ b/src/proto_alpha/lib_protocol/sc_rollup_operations.mli @@ -28,7 +28,7 @@ open Alpha_context type error += (* Temporary *) Sc_rollup_invalid_parameters_type -type origination_result = {address : Sc_rollup.Address.t; size : Z.t} +type origination_result = private {address : Sc_rollup.Address.t; size : Z.t} (** [originate context ~kind ~boot_sector] adds a new rollup running in a given [kind] initialized with a [boot_sector]. *) diff --git a/src/proto_alpha/lib_protocol/sc_rollup_storage.ml b/src/proto_alpha/lib_protocol/sc_rollup_storage.ml index 1f728ef87a87e2a1ac30601ba1a09727fc4a013a..f9132b4302510130b69df374a5d120dcc8d2c1fb 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_storage.ml +++ b/src/proto_alpha/lib_protocol/sc_rollup_storage.ml @@ -34,8 +34,7 @@ let originate ctxt ~kind ~boot_sector ~parameters_ty = let level = Raw_context.current_level ctxt in Sc_rollup_repr.Address.from_nonce nonce >>?= fun address -> Store.PVM_kind.add ctxt address kind >>= fun ctxt -> - Store.Initial_level.add ctxt address (Level_storage.current ctxt).level - >>= fun ctxt -> + Store.Initial_level.add ctxt address level.level >>= fun ctxt -> Store.Boot_sector.add ctxt address boot_sector >>= fun ctxt -> Store.Parameters_type.add ctxt address parameters_ty >>=? fun (ctxt, param_ty_size_diff, _added) ->