diff --git a/CHANGES.rst b/CHANGES.rst index 48a3cf1b5f573597c9655630216cfd6693b1ba69..e637ba1b5190737ab58e74b8b057b2547cb989ec 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -224,6 +224,11 @@ Smart Rollup node - Added a new metrics ``head_inbox_process_time`` to report the time the rollup node spent to process a new Layer 1 head. (MR :gl:`!8971`) +- **Breaking change** Field ``"messages"`` of RPC ``/global/block/{block_id}`` + now contains *serialized* messages (external messages start with ``01`` and + internal start with ``00``). (MR :gl:`!8876`) + + Smart Rollup client ------------------- diff --git a/manifest/main.ml b/manifest/main.ml index 47ffab5a64d9e0ed446bcb5c670cf687c104f586..40ca477bdb4774c7224eba3a3359276f84939774 100644 --- a/manifest/main.ml +++ b/manifest/main.ml @@ -4082,6 +4082,7 @@ let octez_smart_rollup_lib = octez_base_unix; octez_stdlib_unix |> open_; octez_crypto |> open_; + octez_crypto_dal; ] let octez_smart_rollup_node_lib = diff --git a/opam/octez-smart-rollup.opam b/opam/octez-smart-rollup.opam index 12b736b587fce35e8cec0243cb637dd0fd6a151f..83ddb21309a035ea6f32f77a7cea1725670069c0 100644 --- a/opam/octez-smart-rollup.opam +++ b/opam/octez-smart-rollup.opam @@ -13,6 +13,7 @@ depends: [ "tezos-base" "tezos-stdlib-unix" "tezos-crypto" + "tezos-crypto-dal" ] build: [ ["rm" "-r" "vendors" "contrib"] diff --git a/src/lib_smart_rollup/dal.ml b/src/lib_smart_rollup/dal.ml new file mode 100644 index 0000000000000000000000000000000000000000..c0ba23428faee722ceb4f1e3a157e1a378997990 --- /dev/null +++ b/src/lib_smart_rollup/dal.ml @@ -0,0 +1,142 @@ +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2023 Functori, *) +(* *) +(* 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. *) +(* *) +(*****************************************************************************) + +module Slot_index = struct + type t = int + + let encoding = Data_encoding.uint8 +end + +module Page_index = struct + type t = int + + let encoding = Data_encoding.int16 +end + +module Commitment = struct + include Tezos_crypto_dal.Cryptobox.Verifier.Commitment + + type t = Tezos_crypto_dal.Cryptobox.Verifier.commitment +end + +module Slot_header = struct + module V1 = struct + type id = {published_level : int32; index : Slot_index.t} + + type t = {id : id; commitment : Commitment.t} + + let id_encoding = + let open Data_encoding in + conv + (fun {published_level; index} -> (published_level, index)) + (fun (published_level, index) -> {published_level; index}) + (obj2 (req "level" int32) (req "index" Slot_index.encoding)) + + let encoding = + let open Data_encoding in + conv + (fun {id; commitment} -> (id, commitment)) + (fun (id, commitment) -> {id; commitment}) + (merge_objs id_encoding (obj1 (req "commitment" Commitment.encoding))) + end + + type versioned = V1 of V1.t + + let versioned_encoding = + let open Data_encoding in + union + [ + case + ~title:"smart_rollup_dal_slot_header.v1" + (Tag 0) + V1.encoding + (function V1 header -> Some header) + (fun header -> V1 header); + ] + + include V1 + + let of_versioned = function V1 header -> header [@@inline] + + let to_versioned header = V1 header [@@inline] +end + +module Slot_history = struct + module V1 = struct + (* Serialized representation for protocol agnostic slot history *) + type t = bytes + + let encoding = Data_encoding.Variable.bytes + end + + type versioned = V1 of V1.t + + let versioned_encoding = + let open Data_encoding in + union + [ + case + ~title:"smart_rollup_slot_history.v1" + (Tag 0) + V1.encoding + (function V1 x -> Some x) + (fun x -> V1 x); + ] + + include V1 + + let of_versioned = function V1 x -> x [@@inline] + + let to_versioned x = V1 x [@@inline] +end + +module Slot_history_cache = struct + module V1 = struct + (* Serialized representation for protocol agnostic slot history cache *) + type t = bytes + + let encoding = Data_encoding.Variable.bytes + end + + type versioned = V1 of V1.t + + let versioned_encoding = + let open Data_encoding in + union + [ + case + ~title:"smart_rollup_slot_history_cache.v1" + (Tag 0) + V1.encoding + (function V1 x -> Some x) + (fun x -> V1 x); + ] + + include V1 + + let of_versioned = function V1 x -> x [@@inline] + + let to_versioned x = V1 x [@@inline] +end diff --git a/src/proto_alpha/lib_sc_rollup_node/store_migration.mli b/src/lib_smart_rollup/dal.mli similarity index 53% rename from src/proto_alpha/lib_sc_rollup_node/store_migration.mli rename to src/lib_smart_rollup/dal.mli index 0b99202ca76815cb77f3cb7151c21e3aa5b9f7dd..f87ad4438b321c11ebfae648793b06fc815d6d0d 100644 --- a/src/proto_alpha/lib_sc_rollup_node/store_migration.mli +++ b/src/lib_smart_rollup/dal.mli @@ -23,45 +23,70 @@ (* *) (*****************************************************************************) -(** Type of parameter for migration functor {!Make}. *) -module type MIGRATION_ACTIONS = sig - (** Type of store from which data is migrated. *) - type from_store - - (** Type of store to which the data is migrated. *) - type dest_store - - (** Action or actions to migrate data associated to a block. NOTE: - [dest_store] is an empty R/W store initialized in a temporary location. *) - val migrate_block_action : - from_store -> dest_store -> Sc_rollup_block.t -> unit tzresult Lwt.t - - (** The final actions to be performed in the migration. In particular, this is - where data from the temporary store in [dest_store] in [tmp_dir] should be - reported in the actual [storage_dir]. *) - val final_actions : - storage_dir:string -> - tmp_dir:string -> - from_store -> - dest_store -> - unit tzresult Lwt.t +module Slot_index : sig + type t = int + + (** Encoding on 1 byte, matches + [Protocol.Alpha_context.Dal.Slot_index.encoding]. *) + val encoding : t Data_encoding.t +end + +module Page_index : sig + type t = int + + (** Encoding on 2 bytes, matches + [Protocol.Alpha_context.Dal.Slot.Page.Index.encoding]. *) + val encoding : t Data_encoding.t +end + +(** A slot commitment, same as protocol slot commitments through environment. *) +module Commitment : sig + type t = Tezos_crypto_dal.Cryptobox.Verifier.commitment + + val encoding : t Data_encoding.t +end + +module Slot_header : sig + (** A slot header. *) + module V1 : sig + type id = {published_level : int32; index : Slot_index.t} + + type t = {id : id; commitment : Commitment.t} + + (** Encoding for [V1] matches + [Protocol.Alpha_context.Dal.Slot.Header.encoding]. *) + val encoding : t Data_encoding.t + end + + include Versioned_data.S with type t = V1.t + + include module type of V1 with type id = V1.id and type t = V1.t end -module type S = sig - (** Migration function for the store located in [storage_dir]. *) - val migrate : storage_dir:string -> unit tzresult Lwt.t +module Slot_history : sig + (** V1 are serialized slot histories as they appear first in Mumbai. + Introduce V2 if encoding in future protocol changes. *) + module V1 : sig + type t + + val encoding : t Data_encoding.t + end + + include Versioned_data.S with type t = V1.t + + include module type of V1 with type t = V1.t end -(** Functor to create and {e register} a migration. *) -module Make - (S_from : Store_sig.S) - (S_dest : Store_sig.S) - (Actions : MIGRATION_ACTIONS - with type from_store := Store_sigs.ro S_from.t - and type dest_store := Store_sigs.rw S_dest.t) : S - -(** Migrate store located in rollup node {e store} directory [storage_dir] if - needed. If there is no possible migration path registered to go from the - current version to the last {!Store.version}, this function resolves with an - error. *) -val maybe_run_migration : storage_dir:string -> unit tzresult Lwt.t +module Slot_history_cache : sig + (** V1 are serialized slot history caches as they appear first in + Mumbai. Introduce V2 if encoding in future protocol changes. *) + module V1 : sig + type t + + val encoding : t Data_encoding.t + end + + include Versioned_data.S with type t = V1.t + + include module type of V1 with type t = V1.t +end diff --git a/src/lib_smart_rollup/dune b/src/lib_smart_rollup/dune index 003e6743fa1986cfc26e42dd495800d34c3ce130..7924ffa64331529abc51db6bb523daa2601801a5 100644 --- a/src/lib_smart_rollup/dune +++ b/src/lib_smart_rollup/dune @@ -9,7 +9,8 @@ tezos-base tezos-base.unix tezos-stdlib-unix - tezos-crypto) + tezos-crypto + tezos-crypto-dal) (flags (:standard) -open Tezos_base.TzPervasives diff --git a/src/proto_016_PtMumbai/lib_sc_rollup_layer2/sc_rollup_block.ml b/src/lib_smart_rollup/sc_rollup_block.ml similarity index 83% rename from src/proto_016_PtMumbai/lib_sc_rollup_layer2/sc_rollup_block.ml rename to src/lib_smart_rollup/sc_rollup_block.ml index a5c25b817f13899df8a2c5aa8b30c30c78e21aac..1932f5c93cbb6a726a13b4a845a768b3ca5f84fc 100644 --- a/src/proto_016_PtMumbai/lib_sc_rollup_layer2/sc_rollup_block.ml +++ b/src/lib_smart_rollup/sc_rollup_block.ml @@ -23,30 +23,28 @@ (* *) (*****************************************************************************) -open Protocol -open Alpha_context - type header = { block_hash : Block_hash.t; - level : Raw_level.t; + level : int32; predecessor : Block_hash.t; - commitment_hash : Sc_rollup.Commitment.Hash.t option; - previous_commitment_hash : Sc_rollup.Commitment.Hash.t; + commitment_hash : Commitment.Hash.t option; + previous_commitment_hash : Commitment.Hash.t; context : Smart_rollup_context_hash.t; - inbox_witness : Sc_rollup.Inbox_merkelized_payload_hashes.Hash.t; - inbox_hash : Sc_rollup.Inbox.Hash.t; + inbox_witness : + Tezos_crypto.Hashed.Smart_rollup_merkelized_payload_hashes_hash.t; + inbox_hash : Inbox.Hash.t; } type content = { - inbox : Sc_rollup.Inbox.t; - messages : Sc_rollup.Inbox_message.t list; - commitment : Sc_rollup.Commitment.t option; + inbox : Inbox.t; + messages : string list; + commitment : Commitment.t option; } type ('header, 'content) block = { header : 'header; content : 'content; - initial_tick : Sc_rollup.Tick.t; + initial_tick : Z.t; num_ticks : int64; } @@ -58,11 +56,11 @@ let commitment_hash_opt_encoding = let open Data_encoding in let binary = conv - (Option.value ~default:Sc_rollup.Commitment.Hash.zero) - (fun h -> if Sc_rollup.Commitment.Hash.(h = zero) then None else Some h) - Sc_rollup.Commitment.Hash.encoding + (Option.value ~default:Commitment.Hash.zero) + (fun h -> if Commitment.Hash.(h = zero) then None else Some h) + Commitment.Hash.encoding in - let json = option Sc_rollup.Commitment.Hash.encoding in + let json = option Commitment.Hash.encoding in splitted ~binary ~json let header_encoding = @@ -108,7 +106,7 @@ let header_encoding = (req "block_hash" Block_hash.encoding ~description:"Tezos block hash.") (req "level" - Raw_level.encoding + int32 ~description: "Level of the block, corresponds to the level of the tezos block.") (req @@ -122,7 +120,7 @@ let header_encoding = "Hash of this block's commitment if any was computed for it.") (req "previous_commitment_hash" - Sc_rollup.Commitment.Hash.encoding + Commitment.Hash.encoding ~description: "Previous commitment hash in the chain. If there is a commitment \ for this block, this field contains the commitment that was \ @@ -133,13 +131,14 @@ let header_encoding = ~description:"Hash of the layer 2 context for this block.") (req "inbox_witness" - Sc_rollup.Inbox_merkelized_payload_hashes.Hash.encoding + Tezos_crypto.Hashed.Smart_rollup_merkelized_payload_hashes_hash + .encoding ~description: "Witness for the inbox for this block, i.e. the Merkle hash of \ payloads of messages.") (req "inbox_hash" - Sc_rollup.Inbox.Hash.encoding + Inbox.Hash.encoding ~description:"Hash of the inbox for this block.") let header_size = @@ -152,17 +151,14 @@ let content_encoding = (fun {inbox; messages; commitment} -> (inbox, messages, commitment)) (fun (inbox, messages, commitment) -> {inbox; messages; commitment}) @@ obj3 - (req - "inbox" - Sc_rollup.Inbox.encoding - ~description:"Inbox for this block.") + (req "inbox" Inbox.encoding ~description:"Inbox for this block.") (req "messages" - (list (dynamic_size Sc_rollup.Inbox_message.encoding)) + (list (dynamic_size (Variable.string' Hex))) ~description:"Messages added to the inbox in this block.") (opt "commitment" - Sc_rollup.Commitment.encoding + Commitment.encoding ~description:"Commitment, if any is computed for this block.") let block_encoding header_encoding content_encoding = @@ -177,7 +173,7 @@ let block_encoding header_encoding content_encoding = @@ obj2 (req "initial_tick" - Sc_rollup.Tick.encoding + Data_encoding.n ~description: "Initial tick of the PVM at this block, i.e. before evaluation of \ the messages.") @@ -196,4 +192,4 @@ let most_recent_commitment (header : header) = Option.value header.commitment_hash ~default:header.previous_commitment_hash let final_tick {initial_tick; num_ticks; _} = - Sc_rollup.Tick.jump initial_tick (Z.of_int64 num_ticks) + Z.max Z.zero (Z.add initial_tick (Z.of_int64 num_ticks)) diff --git a/src/proto_017_PtNairob/lib_sc_rollup_layer2/sc_rollup_block.mli b/src/lib_smart_rollup/sc_rollup_block.mli similarity index 87% rename from src/proto_017_PtNairob/lib_sc_rollup_layer2/sc_rollup_block.mli rename to src/lib_smart_rollup/sc_rollup_block.mli index b575a5da9f52aaad5e2151bdbce9d4e5e9a4110b..e5676b0cba7772036cdad2e7d2e2f9c8128597dc 100644 --- a/src/proto_017_PtNairob/lib_sc_rollup_layer2/sc_rollup_block.mli +++ b/src/lib_smart_rollup/sc_rollup_block.mli @@ -23,9 +23,6 @@ (* *) (*****************************************************************************) -open Protocol -open Alpha_context - (** {2 Structure of layer 2 blocks} *) (** A layer 2 block header contains information about the inbox and commitment @@ -33,30 +30,31 @@ open Alpha_context messages. *) type header = { block_hash : Block_hash.t; (** Tezos block hash. *) - level : Raw_level.t; + level : int32; (** Level of the block, corresponds to the level of the tezos block. *) predecessor : Block_hash.t; (** Predecessor hash of the Tezos block. *) - commitment_hash : Sc_rollup.Commitment.Hash.t option; + commitment_hash : Commitment.Hash.t option; (** Hash of this block's commitment if any was computed for it. *) - previous_commitment_hash : Sc_rollup.Commitment.Hash.t; + previous_commitment_hash : Commitment.Hash.t; (** Previous commitment hash in the chain. If there is a commitment for this block, this field contains the commitment that was previously computed. *) context : Smart_rollup_context_hash.t; (** Hash of the layer 2 context for this block. *) - inbox_witness : Sc_rollup.Inbox_merkelized_payload_hashes.Hash.t; + inbox_witness : + Tezos_crypto.Hashed.Smart_rollup_merkelized_payload_hashes_hash.t; (** Witness for the inbox for this block, i.e. the Merkle hash of payloads of messages. *) - inbox_hash : Sc_rollup.Inbox.Hash.t; (** Hash of the inbox for this block. *) + inbox_hash : Inbox.Hash.t; (** Hash of the inbox for this block. *) } (** Contents of blocks which include the actual content of the inbox and messages. *) type content = { - inbox : Sc_rollup.Inbox.t; (** Inbox for this block. *) - messages : Sc_rollup.Inbox_message.t list; - (** Messages added to the inbox in this block. *) - commitment : Sc_rollup.Commitment.t option; + inbox : Inbox.t; (** Inbox for this block. *) + messages : string list; + (** Serialized messages added to the inbox in this block. *) + commitment : Commitment.t option; (** Commitment, if any is computed for this block. [header.commitment = Some h] iff [commitment = Some c] and [hash c = h]. *) } @@ -66,7 +64,7 @@ type content = { type ('header, 'content) block = { header : 'header; (** Header of this block. *) content : 'content; (** Content of the block. *) - initial_tick : Sc_rollup.Tick.t; + initial_tick : Z.t; (** Initial tick of the PVM at this block, i.e. before evaluation of the messages. *) num_ticks : int64; @@ -104,8 +102,8 @@ val full_encoding : full Data_encoding.t (** [most_recent_commitment header] returns the most recent commitment information at the block of with [header]. It is either the commitment for this block if there is one or the previous commitment otherwise. *) -val most_recent_commitment : header -> Sc_rollup.Commitment.Hash.t +val most_recent_commitment : header -> Commitment.Hash.t (** [final_tick block] is the final tick, after evaluation of the messages in the [block], i.e. [block.initial_tick + block.num_ticks]. *) -val final_tick : ('a, 'b) block -> Sc_rollup.Tick.t +val final_tick : ('a, 'b) block -> Z.t diff --git a/src/proto_016_PtMumbai/lib_sc_rollup_node/store.ml b/src/lib_smart_rollup_node/store.ml similarity index 100% rename from src/proto_016_PtMumbai/lib_sc_rollup_node/store.ml rename to src/lib_smart_rollup_node/store.ml diff --git a/src/proto_016_PtMumbai/lib_sc_rollup_node/store_migration.ml b/src/lib_smart_rollup_node/store_migration.ml similarity index 100% rename from src/proto_016_PtMumbai/lib_sc_rollup_node/store_migration.ml rename to src/lib_smart_rollup_node/store_migration.ml diff --git a/src/proto_016_PtMumbai/lib_sc_rollup_node/store_migration.mli b/src/lib_smart_rollup_node/store_migration.mli similarity index 100% rename from src/proto_016_PtMumbai/lib_sc_rollup_node/store_migration.mli rename to src/lib_smart_rollup_node/store_migration.mli diff --git a/src/proto_016_PtMumbai/lib_sc_rollup_node/store_sig.ml b/src/lib_smart_rollup_node/store_sig.ml similarity index 100% rename from src/proto_016_PtMumbai/lib_sc_rollup_node/store_sig.ml rename to src/lib_smart_rollup_node/store_sig.ml diff --git a/src/proto_alpha/lib_sc_rollup_node/store_v0.ml b/src/lib_smart_rollup_node/store_v0.ml similarity index 86% rename from src/proto_alpha/lib_sc_rollup_node/store_v0.ml rename to src/lib_smart_rollup_node/store_v0.ml index 066a37f739fb3ba9037c31a4a8789ee09936bad4..b02a6c05a0d868b61d9d41b844bc9942af09c9d1 100644 --- a/src/proto_alpha/lib_sc_rollup_node/store_v0.ml +++ b/src/lib_smart_rollup_node/store_v0.ml @@ -28,13 +28,9 @@ [src/proto_016_PtMumbai/lib_sc_rollup_node/store.ml], which contains the store for the Mumbai rollup node. *) -open Protocol include Store_sigs include Store_utils -(** Aggregated collection of messages from the L1 inbox *) -open Alpha_context - let version = Store_version.V0 module Irmin_store = struct @@ -62,7 +58,7 @@ module Add_empty_header = struct let header _ = () end -module Make_hash_index_key (H : Environment.S.HASH) = +module Make_hash_index_key (H : Tezos_crypto.Intfs.HASH) = Indexed_store.Make_index_key (struct include Indexed_store.Make_fixed_encodable (H) @@ -101,17 +97,16 @@ module Messages = (struct let name = "messages" end) - (Make_hash_index_key (Sc_rollup.Inbox_merkelized_payload_hashes.Hash)) + (Make_hash_index_key (Octez_smart_rollup.Merkelized_payload_hashes_hash)) (struct - type t = Sc_rollup.Inbox_message.t list + type t = string list let name = "messages_list" - let encoding = - Data_encoding.(list @@ dynamic_size Sc_rollup.Inbox_message.encoding) + let encoding = Data_encoding.(list @@ dynamic_size (Variable.string' Hex)) module Header = struct - type t = Block_hash.t * Timestamp.t * int + type t = Block_hash.t * Time.Protocol.t * int let name = "messages_inbox_info" @@ -119,7 +114,7 @@ module Messages = let open Data_encoding in obj3 (req "predecessor" Block_hash.encoding) - (req "predecessor_timestamp" Timestamp.encoding) + (req "predecessor_timestamp" Time.Protocol.encoding) (req "num_messages" int31) let fixed_size = @@ -134,13 +129,13 @@ module Inboxes = (struct let name = "inboxes" end) - (Make_hash_index_key (Sc_rollup.Inbox.Hash)) + (Make_hash_index_key (Octez_smart_rollup.Inbox_hash)) (struct - type t = Sc_rollup.Inbox.t + type t = Octez_smart_rollup.Inbox.V1.t let name = "inbox" - let encoding = Sc_rollup.Inbox.encoding + let encoding = Octez_smart_rollup.Inbox.V1.encoding include Add_empty_header end) @@ -150,26 +145,26 @@ module Commitments = (struct let name = "commitments" end) - (Make_hash_index_key (Sc_rollup.Commitment.Hash)) + (Make_hash_index_key (Octez_smart_rollup.Commitment.Hash)) (Indexed_store.Make_index_value (Indexed_store.Make_fixed_encodable (struct - include Sc_rollup.Commitment + include Octez_smart_rollup.Commitment.V1 let name = "commitment" end))) module Commitments_published_at_level = struct type element = { - first_published_at_level : Raw_level.t; - published_at_level : Raw_level.t option; + first_published_at_level : int32; + published_at_level : int32 option; } let element_encoding = let open Data_encoding in let opt_level_encoding = conv - (function None -> -1l | Some l -> Raw_level.to_int32 l) - (fun l -> if l = -1l then None else Some (Raw_level.of_int32_exn l)) - Data_encoding.int32 + (function None -> -1l | Some l -> l) + (fun l -> if l = -1l then None else Some l) + int32 in conv (fun {first_published_at_level; published_at_level} -> @@ -177,7 +172,7 @@ module Commitments_published_at_level = struct (fun (first_published_at_level, published_at_level) -> {first_published_at_level; published_at_level}) @@ obj2 - (req "first_published_at_level" Raw_level.encoding) + (req "first_published_at_level" int32) (req "published_at_level" opt_level_encoding) include @@ -185,7 +180,7 @@ module Commitments_published_at_level = struct (struct let name = "commitments" end) - (Make_hash_index_key (Sc_rollup.Commitment.Hash)) + (Make_hash_index_key (Octez_smart_rollup.Commitment.Hash)) (Indexed_store.Make_index_value (Indexed_store.Make_fixed_encodable (struct type t = element @@ -245,21 +240,21 @@ module Dal_slot_pages = let to_path_representation = Block_hash.to_b58check end) (struct - type key = Dal.Slot_index.t * Dal.Page.Index.t + type key = + Octez_smart_rollup.Dal.Slot_index.t + * Octez_smart_rollup.Dal.Page_index.t let encoding = - Data_encoding.(tup2 Dal.Slot_index.encoding Dal.Page.Index.encoding) + Data_encoding.(tup2 Dal.Slot_index.encoding Dal.Page_index.encoding) - let compare (i1, p1) (i2, p2) = - Compare.or_else (Dal.Slot_index.compare i1 i2) (fun () -> - Dal.Page.Index.compare p1 p2) + let compare = Stdlib.compare let name = "slot_index" end) (struct - type value = Dal.Page.content + type value = bytes - let encoding = Dal.Page.content_encoding + let encoding = Data_encoding.(bytes' Hex) let name = "slot_pages" end) @@ -277,11 +272,11 @@ module Dal_processed_slots = let to_path_representation = Block_hash.to_b58check end) (struct - type key = Dal.Slot_index.t + type key = Octez_smart_rollup.Dal.Slot_index.t - let encoding = Dal.Slot_index.encoding + let encoding = Octez_smart_rollup.Dal.Slot_index.encoding - let compare = Dal.Slot_index.compare + let compare = Compare.Int.compare let name = "slot_index" end) @@ -319,20 +314,20 @@ module Dal_slots_headers = let to_path_representation = Block_hash.to_b58check end) (struct - type key = Dal.Slot_index.t + type key = Octez_smart_rollup.Dal.Slot_index.t - let encoding = Dal.Slot_index.encoding + let encoding = Octez_smart_rollup.Dal.Slot_index.encoding - let compare = Dal.Slot_index.compare + let compare = Compare.Int.compare let name = "slot_index" end) (struct - type value = Dal.Slot.Header.t + type value = Octez_smart_rollup.Dal.Slot_header.t let name = "slot_header" - let encoding = Dal.Slot.Header.encoding + let encoding = Octez_smart_rollup.Dal.Slot_header.V1.encoding end) (* Published slot headers per block hash, stored as a list of bindings from @@ -355,11 +350,11 @@ module Dal_confirmed_slots_history = let to_path_representation = Block_hash.to_b58check end) (struct - type value = Dal.Slots_history.t + type value = Octez_smart_rollup.Dal.Slot_history.t let name = "dal_slot_histories" - let encoding = Dal.Slots_history.encoding + let encoding = Octez_smart_rollup.Dal.Slot_history.V1.encoding end) (** Confirmed DAL slots histories cache. See documentation of @@ -377,11 +372,11 @@ module Dal_confirmed_slots_histories = let to_path_representation = Block_hash.to_b58check end) (struct - type value = Dal.Slots_history.History_cache.t + type value = Octez_smart_rollup.Dal.Slot_history_cache.t - let name = "dal_slot_history_cache" + let name = "dal_slot_histories" - let encoding = Dal.Slots_history.History_cache.encoding + let encoding = Octez_smart_rollup.Dal.Slot_history_cache.V1.encoding end) type 'a store = { diff --git a/src/proto_alpha/lib_sc_rollup_node/store_v0.mli b/src/lib_smart_rollup_node/store_v0.mli similarity index 88% rename from src/proto_alpha/lib_sc_rollup_node/store_v0.mli rename to src/lib_smart_rollup_node/store_v0.mli index f2d9a002d6c1d6bf8000a7e5eb4ead8a11bf9894..97c6848ee2ffe852bd8dc394e655576d2ed3f824 100644 --- a/src/proto_alpha/lib_sc_rollup_node/store_v0.mli +++ b/src/lib_smart_rollup_node/store_v0.mli @@ -32,8 +32,6 @@ layout for the Mumbai rollup node. *) -open Protocol -open Alpha_context open Indexed_store module Irmin_store : sig @@ -53,32 +51,32 @@ module L2_blocks : (** Storage for persisting messages downloaded from the L1 node. *) module Messages : INDEXED_FILE - with type key := Sc_rollup.Inbox_merkelized_payload_hashes.Hash.t - and type value := Sc_rollup.Inbox_message.t list - and type header := Block_hash.t * Timestamp.t * int + with type key := Octez_smart_rollup.Merkelized_payload_hashes_hash.t + and type value := string list + and type header := Block_hash.t * Time.Protocol.t * int (** Aggregated collection of messages from the L1 inbox *) module Inboxes : SIMPLE_INDEXED_FILE - with type key := Sc_rollup.Inbox.Hash.t - and type value := Sc_rollup.Inbox.t + with type key := Octez_smart_rollup.Inbox.Hash.t + and type value := Octez_smart_rollup.Inbox.V1.t and type header := unit (** Storage containing commitments and corresponding commitment hashes that the rollup node has knowledge of. *) module Commitments : INDEXABLE_STORE - with type key := Sc_rollup.Commitment.Hash.t - and type value := Sc_rollup.Commitment.t + with type key := Octez_smart_rollup.Commitment.Hash.t + and type value := Octez_smart_rollup.Commitment.t (** Storage mapping commitment hashes to the level when they were published by the rollup node. It only contains hashes of commitments published by this rollup node. *) module Commitments_published_at_level : sig type element = { - first_published_at_level : Raw_level.t; + first_published_at_level : int32; (** The level at which this commitment was first published. *) - published_at_level : Raw_level.t option; + published_at_level : int32 option; (** The level at which we published this commitment. If [first_published_at_level <> published_at_level] it means that the commitment is republished. *) @@ -86,7 +84,7 @@ module Commitments_published_at_level : sig include INDEXABLE_STORE - with type key := Sc_rollup.Commitment.Hash.t + with type key := Octez_smart_rollup.Commitment.Hash.t and type value := element end @@ -105,13 +103,13 @@ module Dal_slots_headers : Store_sigs.Nested_map with type primary_key := Block_hash.t and type secondary_key := Dal.Slot_index.t - and type value := Dal.Slot.Header.t + and type value := Dal.Slot_header.V1.t and type 'a store := 'a Irmin_store.t module Dal_confirmed_slots_history : Store_sigs.Append_only_map with type key := Block_hash.t - and type value := Dal.Slots_history.t + and type value := Dal.Slot_history.V1.t and type 'a store := 'a Irmin_store.t (** Confirmed DAL slots histories cache. See documentation of @@ -119,7 +117,7 @@ module Dal_confirmed_slots_history : module Dal_confirmed_slots_histories : Store_sigs.Append_only_map with type key := Block_hash.t - and type value := Dal.Slots_history.History_cache.t + and type value := Dal.Slot_history_cache.V1.t and type 'a store := 'a Irmin_store.t (** [Dal_slot_pages] is a [Store_utils.Nested_map] used to store the contents @@ -131,8 +129,8 @@ module Dal_confirmed_slots_histories : module Dal_slot_pages : Store_sigs.Nested_map with type primary_key := Block_hash.t - and type secondary_key := Dal.Slot_index.t * Dal.Page.Index.t - and type value := Dal.Page.content + and type secondary_key := Dal.Slot_index.t * Dal.Page_index.t + and type value := bytes and type 'a store := 'a Irmin_store.t (** [Dal_processed_slots] is a [Store_utils.Nested_map] used to store the processing diff --git a/src/proto_alpha/lib_sc_rollup_node/store_v1.ml b/src/lib_smart_rollup_node/store_v1.ml similarity index 94% rename from src/proto_alpha/lib_sc_rollup_node/store_v1.ml rename to src/lib_smart_rollup_node/store_v1.ml index adecbb8a2b5b62a821ecfa369413cf481e2e5348..129f6665a781519b710e8b0a065390d861d779d6 100644 --- a/src/proto_alpha/lib_sc_rollup_node/store_v1.ml +++ b/src/lib_smart_rollup_node/store_v1.ml @@ -24,15 +24,13 @@ (* *) (*****************************************************************************) -open Protocol -open Alpha_context include Store_sigs include Store_utils include Store_v0 let version = Store_version.V1 -module Make_hash_index_key (H : Environment.S.HASH) = +module Make_hash_index_key (H : Tezos_crypto.Intfs.HASH) = Indexed_store.Make_index_key (struct include Indexed_store.Make_fixed_encodable (H) @@ -45,17 +43,16 @@ module Messages = (struct let name = "messages" end) - (Make_hash_index_key (Sc_rollup.Inbox_merkelized_payload_hashes.Hash)) + (Make_hash_index_key (Merkelized_payload_hashes_hash)) (struct - type t = Sc_rollup.Inbox_message.t list + type t = string list let name = "messages_list" - let encoding = - Data_encoding.(list @@ dynamic_size Sc_rollup.Inbox_message.encoding) + let encoding = Data_encoding.(list @@ dynamic_size Variable.(string' Hex)) module Header = struct - type t = bool * Block_hash.t * Timestamp.t * int + type t = bool * Block_hash.t * Time.Protocol.t * int let name = "messages_inbox_info" @@ -64,7 +61,7 @@ module Messages = obj4 (req "is_first_block" bool) (req "predecessor" Block_hash.encoding) - (req "predecessor_timestamp" Timestamp.encoding) + (req "predecessor_timestamp" Time.Protocol.encoding) (req "num_messages" int31) let fixed_size = @@ -97,7 +94,7 @@ module Dal_slots_statuses = let encoding = Dal.Slot_index.encoding - let compare = Dal.Slot_index.compare + let compare = Compare.Int.compare let name = "slot_index" end) diff --git a/src/proto_alpha/lib_sc_rollup_node/store_v1.mli b/src/lib_smart_rollup_node/store_v1.mli similarity index 93% rename from src/proto_alpha/lib_sc_rollup_node/store_v1.mli rename to src/lib_smart_rollup_node/store_v1.mli index 7662907121003367f4bdf443fb185008a1db33cc..bb6eb14155af2515d1baa95f0620f49c587cdb43 100644 --- a/src/proto_alpha/lib_sc_rollup_node/store_v1.mli +++ b/src/lib_smart_rollup_node/store_v1.mli @@ -27,8 +27,6 @@ (** This version of the store is used for the rollup nodes for protocols for and after Nairobi, i.e. >= 17. *) -open Protocol -open Alpha_context open Indexed_store include module type of struct @@ -38,9 +36,9 @@ end (** Storage for persisting messages downloaded from the L1 node. *) module Messages : INDEXED_FILE - with type key := Sc_rollup.Inbox_merkelized_payload_hashes.Hash.t - and type value := Sc_rollup.Inbox_message.t list - and type header := bool * Block_hash.t * Timestamp.t * int + with type key := Merkelized_payload_hashes_hash.t + and type value := string list + and type header := bool * Block_hash.t * Time.Protocol.t * int module Dal_pages : sig type removed_in_v1 diff --git a/src/proto_016_PtMumbai/lib_sc_rollup_node/store_v2.ml b/src/lib_smart_rollup_node/store_v2.ml similarity index 75% rename from src/proto_016_PtMumbai/lib_sc_rollup_node/store_v2.ml rename to src/lib_smart_rollup_node/store_v2.ml index 18b77336aa55753bbe7453796b9182a5bda1fec2..51294ef2ee5a60bc4e4b56210ad24100b5eb7362 100644 --- a/src/proto_016_PtMumbai/lib_sc_rollup_node/store_v2.ml +++ b/src/lib_smart_rollup_node/store_v2.ml @@ -24,15 +24,13 @@ (* *) (*****************************************************************************) -open Protocol -open Alpha_context include Store_sigs include Store_utils include Store_v1 let version = Store_version.V2 -module Make_hash_index_key (H : Environment.S.HASH) = +module Make_hash_index_key (H : Tezos_crypto.Intfs.HASH) = Indexed_store.Make_index_key (struct include Indexed_store.Make_fixed_encodable (H) @@ -45,14 +43,13 @@ module Messages = (struct let name = "messages" end) - (Make_hash_index_key (Sc_rollup.Inbox_merkelized_payload_hashes.Hash)) + (Make_hash_index_key (Merkelized_payload_hashes_hash)) (struct - type t = Sc_rollup.Inbox_message.t list + type t = string list let name = "messages_list" - let encoding = - Data_encoding.(list @@ dynamic_size Sc_rollup.Inbox_message.encoding) + let encoding = Data_encoding.(list @@ dynamic_size (Variable.string' Hex)) module Header = struct type t = Block_hash.t @@ -89,25 +86,15 @@ module Inboxes = (struct let name = "inboxes" end) - (Make_hash_index_key (Sc_rollup.Inbox.Hash)) + (Make_hash_index_key (Octez_smart_rollup.Inbox.Hash)) (struct - type t = Sc_rollup.Inbox.t - - let to_repr inbox = - inbox - |> Data_encoding.Binary.to_string_exn Sc_rollup.Inbox.encoding - |> Data_encoding.Binary.of_string_exn Sc_rollup_inbox_repr.encoding - - let of_repr inbox = - inbox - |> Data_encoding.Binary.to_string_exn Sc_rollup_inbox_repr.encoding - |> Data_encoding.Binary.of_string_exn Sc_rollup.Inbox.encoding + type t = Octez_smart_rollup.Inbox.t let encoding = Data_encoding.conv - (fun x -> to_repr x |> Sc_rollup_inbox_repr.to_versioned) - (fun x -> Sc_rollup_inbox_repr.of_versioned x |> of_repr) - Sc_rollup_inbox_repr.versioned_encoding + Octez_smart_rollup.Inbox.to_versioned + Octez_smart_rollup.Inbox.of_versioned + Octez_smart_rollup.Inbox.versioned_encoding let name = "inbox" @@ -120,31 +107,101 @@ module Commitments = (struct let name = "commitments" end) - (Make_hash_index_key (Sc_rollup.Commitment.Hash)) + (Make_hash_index_key (Octez_smart_rollup.Commitment.Hash)) (struct - type t = Sc_rollup.Commitment.t - - let to_repr commitment = - commitment - |> Data_encoding.Binary.to_string_exn Sc_rollup.Commitment.encoding - |> Data_encoding.Binary.of_string_exn Sc_rollup_commitment_repr.encoding - - let of_repr commitment = - commitment - |> Data_encoding.Binary.to_string_exn Sc_rollup_commitment_repr.encoding - |> Data_encoding.Binary.of_string_exn Sc_rollup.Commitment.encoding + type t = Octez_smart_rollup.Commitment.t let encoding = Data_encoding.conv - (fun x -> to_repr x |> Sc_rollup_commitment_repr.to_versioned) - (fun x -> Sc_rollup_commitment_repr.of_versioned x |> of_repr) - Sc_rollup_commitment_repr.versioned_encoding + Octez_smart_rollup.Commitment.to_versioned + Octez_smart_rollup.Commitment.of_versioned + Octez_smart_rollup.Commitment.versioned_encoding let name = "commitment" include Add_empty_header end) +(** Versioned slot headers *) +module Dal_slots_headers = + Irmin_store.Make_nested_map + (struct + let path = ["dal"; "slot_headers"] + end) + (struct + type key = Block_hash.t + + let to_path_representation = Block_hash.to_b58check + end) + (struct + type key = Octez_smart_rollup.Dal.Slot_index.t + + let encoding = Octez_smart_rollup.Dal.Slot_index.encoding + + let compare = Compare.Int.compare + + let name = "slot_index" + end) + (struct + type value = Octez_smart_rollup.Dal.Slot_header.t + + let name = "slot_header" + + let encoding = + Data_encoding.conv + Octez_smart_rollup.Dal.Slot_header.to_versioned + Octez_smart_rollup.Dal.Slot_header.of_versioned + Octez_smart_rollup.Dal.Slot_header.versioned_encoding + end) + +(** Versioned Confirmed DAL slots history *) +module Dal_confirmed_slots_history = + Irmin_store.Make_append_only_map + (struct + let path = ["dal"; "confirmed_slots_history"] + end) + (struct + type key = Block_hash.t + + let to_path_representation = Block_hash.to_b58check + end) + (struct + type value = Octez_smart_rollup.Dal.Slot_history.t + + let name = "dal_slot_histories" + + let encoding = + Data_encoding.conv + Octez_smart_rollup.Dal.Slot_history.to_versioned + Octez_smart_rollup.Dal.Slot_history.of_versioned + Octez_smart_rollup.Dal.Slot_history.versioned_encoding + end) + +(** Versioned Confirmed DAL slots histories cache. *) +module Dal_confirmed_slots_histories = + (* TODO: https://gitlab.com/tezos/tezos/-/issues/4390 + Store single history points in map instead of whole history. *) + Irmin_store.Make_append_only_map + (struct + let path = ["dal"; "confirmed_slots_histories_cache"] + end) + (struct + type key = Block_hash.t + + let to_path_representation = Block_hash.to_b58check + end) + (struct + type value = Octez_smart_rollup.Dal.Slot_history_cache.t + + let name = "dal_slot_histories" + + let encoding = + Data_encoding.conv + Octez_smart_rollup.Dal.Slot_history_cache.to_versioned + Octez_smart_rollup.Dal.Slot_history_cache.of_versioned + Octez_smart_rollup.Dal.Slot_history_cache.versioned_encoding + end) + module Protocols = struct type level = First_known of int32 | Activation_level of int32 diff --git a/src/proto_alpha/lib_sc_rollup_node/store_v2.mli b/src/lib_smart_rollup_node/store_v2.mli similarity index 75% rename from src/proto_alpha/lib_sc_rollup_node/store_v2.mli rename to src/lib_smart_rollup_node/store_v2.mli index fb8e1bc4313f3031b7e63f1e50bb4bced2439170..50f3cf4b0ba7ec282d4fb411d84c058f13595d85 100644 --- a/src/proto_alpha/lib_sc_rollup_node/store_v2.mli +++ b/src/lib_smart_rollup_node/store_v2.mli @@ -27,8 +27,6 @@ (** This version of the store is used for the rollup nodes for protocols for and after Nairobi, i.e. >= 17. *) -open Protocol -open Alpha_context open Indexed_store include module type of struct @@ -38,25 +36,50 @@ end (** Storage for persisting messages downloaded from the L1 node. *) module Messages : INDEXED_FILE - with type key := Sc_rollup.Inbox_merkelized_payload_hashes.Hash.t - and type value := Sc_rollup.Inbox_message.t list + with type key := Merkelized_payload_hashes_hash.t + and type value := string list and type header := Block_hash.t (** Storage for persisting inboxes. *) module Inboxes : SIMPLE_INDEXED_FILE - with type key := Sc_rollup.Inbox.Hash.t - and type value := Sc_rollup.Inbox.t + with type key := Octez_smart_rollup.Inbox.Hash.t + and type value := Octez_smart_rollup.Inbox.t and type header := unit (** Storage containing commitments and corresponding commitment hashes that the rollup node has knowledge of. *) module Commitments : SIMPLE_INDEXED_FILE - with type key := Sc_rollup.Commitment.Hash.t - and type value := Sc_rollup.Commitment.t + with type key := Octez_smart_rollup.Commitment.Hash.t + and type value := Octez_smart_rollup.Commitment.t and type header := unit +(** Published slot headers per block hash, + stored as a list of bindings from [Dal_slot_index.t] + to [Dal.Slot.t]. The encoding function converts this + list into a [Dal.Slot_index.t]-indexed map. *) +module Dal_slots_headers : + Store_sigs.Nested_map + with type primary_key := Block_hash.t + and type secondary_key := Dal.Slot_index.t + and type value := Dal.Slot_header.t + and type 'a store := 'a Irmin_store.t + +module Dal_confirmed_slots_history : + Store_sigs.Append_only_map + with type key := Block_hash.t + and type value := Dal.Slot_history.t + and type 'a store := 'a Irmin_store.t + +(** Confirmed DAL slots histories cache. See documentation of + {!Dal_slot_repr.Slots_history} for more details. *) +module Dal_confirmed_slots_histories : + Store_sigs.Append_only_map + with type key := Block_hash.t + and type value := Dal.Slot_history_cache.t + and type 'a store := 'a Irmin_store.t + module Protocols : sig type level = First_known of int32 | Activation_level of int32 diff --git a/src/proto_016_PtMumbai/lib_sc_rollup_node/store_version.ml b/src/lib_smart_rollup_node/store_version.ml similarity index 100% rename from src/proto_016_PtMumbai/lib_sc_rollup_node/store_version.ml rename to src/lib_smart_rollup_node/store_version.ml diff --git a/src/proto_016_PtMumbai/lib_sc_rollup_node/store_version.mli b/src/lib_smart_rollup_node/store_version.mli similarity index 100% rename from src/proto_016_PtMumbai/lib_sc_rollup_node/store_version.mli rename to src/lib_smart_rollup_node/store_version.mli diff --git a/src/proto_016_PtMumbai/lib_sc_rollup_layer2/sc_rollup_block.mli b/src/proto_016_PtMumbai/lib_sc_rollup_layer2/sc_rollup_block.mli deleted file mode 100644 index b575a5da9f52aaad5e2151bdbce9d4e5e9a4110b..0000000000000000000000000000000000000000 --- a/src/proto_016_PtMumbai/lib_sc_rollup_layer2/sc_rollup_block.mli +++ /dev/null @@ -1,111 +0,0 @@ -(*****************************************************************************) -(* *) -(* 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. *) -(* *) -(*****************************************************************************) - -open Protocol -open Alpha_context - -(** {2 Structure of layer 2 blocks} *) - -(** A layer 2 block header contains information about the inbox and commitment - with respect to a layer 1 block, but without the inbox content of - messages. *) -type header = { - block_hash : Block_hash.t; (** Tezos block hash. *) - level : Raw_level.t; - (** Level of the block, corresponds to the level of the tezos block. *) - predecessor : Block_hash.t; (** Predecessor hash of the Tezos block. *) - commitment_hash : Sc_rollup.Commitment.Hash.t option; - (** Hash of this block's commitment if any was computed for it. *) - previous_commitment_hash : Sc_rollup.Commitment.Hash.t; - (** Previous commitment hash in the chain. If there is a commitment for this - block, this field contains the commitment that was previously - computed. *) - context : Smart_rollup_context_hash.t; - (** Hash of the layer 2 context for this block. *) - inbox_witness : Sc_rollup.Inbox_merkelized_payload_hashes.Hash.t; - (** Witness for the inbox for this block, i.e. the Merkle hash of payloads - of messages. *) - inbox_hash : Sc_rollup.Inbox.Hash.t; (** Hash of the inbox for this block. *) -} - -(** Contents of blocks which include the actual content of the inbox and - messages. *) -type content = { - inbox : Sc_rollup.Inbox.t; (** Inbox for this block. *) - messages : Sc_rollup.Inbox_message.t list; - (** Messages added to the inbox in this block. *) - commitment : Sc_rollup.Commitment.t option; - (** Commitment, if any is computed for this block. [header.commitment = - Some h] iff [commitment = Some c] and [hash c = h]. *) -} - -(** Block parameterized by a header and content. The parameters are here to - allow to split the header and rest of the block. *) -type ('header, 'content) block = { - header : 'header; (** Header of this block. *) - content : 'content; (** Content of the block. *) - initial_tick : Sc_rollup.Tick.t; - (** Initial tick of the PVM at this block, i.e. before evaluation of the - messages. *) - num_ticks : int64; - (** Number of ticks produced by the evaluation of the messages in this - block. *) -} - -(** The type of layer 2 blocks. This type corresponds to what is stored on disk - for L2 blocks. The contents is stored in separate tables because it can be - large to read is is not always necessary. *) -type t = (header, unit) block - -(** The type of layer 2 blocks including their content (inbox, messages, commitment). *) -type full = (header, content) block - -(** {2 Encodings} *) - -val header_encoding : header Data_encoding.t - -val header_size : int - -val content_encoding : content Data_encoding.t - -val block_encoding : - 'header Data_encoding.t -> - 'content Data_encoding.t -> - ('header, 'content) block Data_encoding.t - -val encoding : t Data_encoding.t - -val full_encoding : full Data_encoding.t - -(** {2 Helper functions} *) - -(** [most_recent_commitment header] returns the most recent commitment - information at the block of with [header]. It is either the commitment for - this block if there is one or the previous commitment otherwise. *) -val most_recent_commitment : header -> Sc_rollup.Commitment.Hash.t - -(** [final_tick block] is the final tick, after evaluation of the messages in - the [block], i.e. [block.initial_tick + block.num_ticks]. *) -val final_tick : ('a, 'b) block -> Sc_rollup.Tick.t diff --git a/src/proto_016_PtMumbai/lib_sc_rollup_layer2/sc_rollup_proto_types.ml b/src/proto_016_PtMumbai/lib_sc_rollup_layer2/sc_rollup_proto_types.ml index a8b1ce9c072cb61ee0b42bf655efabd8dd6bd254..5bb9d6dbb492327d34b256e2d8c66b1693287040 100644 --- a/src/proto_016_PtMumbai/lib_sc_rollup_layer2/sc_rollup_proto_types.ml +++ b/src/proto_016_PtMumbai/lib_sc_rollup_layer2/sc_rollup_proto_types.ml @@ -251,3 +251,88 @@ module Kind = struct | Example_arith -> Example_arith | Wasm_2_0_0 -> Wasm_2_0_0 end + +module Dal = struct + module Slot_index = struct + type t = Dal.Slot_index.t + + let of_octez (i : Octez_smart_rollup.Dal.Slot_index.t) : t = + match Dal.Slot_index.of_int i with + | None -> Format.ksprintf invalid_arg "Dal.Slot_index.of_octez: %d" i + | Some i -> i + + let to_octez : t -> Octez_smart_rollup.Dal.Slot_index.t = + Dal.Slot_index.to_int + end + + module Page_index = struct + type t = Dal.Page.Index.t + + let of_octez : Octez_smart_rollup.Dal.Page_index.t -> t = Fun.id + + let to_octez : t -> Octez_smart_rollup.Dal.Page_index.t = Fun.id + end + + module Slot_header = struct + type t = Dal.Slot.Header.t + + let of_octez + Octez_smart_rollup.Dal.Slot_header. + {id = {published_level; index}; commitment} : t = + Dal.Slot.Header. + { + id = + { + published_level = Raw_level.of_int32_exn published_level; + index = Slot_index.of_octez index; + }; + commitment; + } + + let to_octez Dal.Slot.Header.{id = {published_level; index}; commitment} : + Octez_smart_rollup.Dal.Slot_header.t = + Octez_smart_rollup.Dal.Slot_header. + { + id = + { + published_level = Raw_level.to_int32 published_level; + index = Slot_index.to_octez index; + }; + commitment; + } + end + + module Slot_history = struct + type t = Dal.Slots_history.t + + let of_octez (h : Octez_smart_rollup.Dal.Slot_history.t) : t = + h + |> Data_encoding.Binary.to_bytes_exn + Octez_smart_rollup.Dal.Slot_history.encoding + |> Data_encoding.Binary.of_bytes_exn Dal.Slots_history.encoding + + let to_octez (h : t) : Octez_smart_rollup.Dal.Slot_history.t = + h + |> Data_encoding.Binary.to_bytes_exn Dal.Slots_history.encoding + |> Data_encoding.Binary.of_bytes_exn + Octez_smart_rollup.Dal.Slot_history.encoding + end + + module Slot_history_cache = struct + type t = Dal.Slots_history.History_cache.t + + let of_octez (h : Octez_smart_rollup.Dal.Slot_history_cache.t) : t = + h + |> Data_encoding.Binary.to_bytes_exn + Octez_smart_rollup.Dal.Slot_history_cache.encoding + |> Data_encoding.Binary.of_bytes_exn + Dal.Slots_history.History_cache.encoding + + let to_octez (h : t) : Octez_smart_rollup.Dal.Slot_history_cache.t = + h + |> Data_encoding.Binary.to_bytes_exn + Dal.Slots_history.History_cache.encoding + |> Data_encoding.Binary.of_bytes_exn + Octez_smart_rollup.Dal.Slot_history_cache.encoding + end +end diff --git a/src/proto_016_PtMumbai/lib_sc_rollup_layer2/sc_rollup_proto_types.mli b/src/proto_016_PtMumbai/lib_sc_rollup_layer2/sc_rollup_proto_types.mli index d24bfcd9c6ee4dc4015473e5eab5a3561de48a10..905a7b7bde6dc484c26a08fdd5f47eaf8d4c951b 100644 --- a/src/proto_016_PtMumbai/lib_sc_rollup_layer2/sc_rollup_proto_types.mli +++ b/src/proto_016_PtMumbai/lib_sc_rollup_layer2/sc_rollup_proto_types.mli @@ -116,3 +116,45 @@ module Kind : sig val to_octez : t -> Octez_smart_rollup.Kind.t end + +module Dal : sig + module Slot_index : sig + type t = Dal.Slot_index.t + + val of_octez : Octez_smart_rollup.Dal.Slot_index.t -> t + + val to_octez : t -> Octez_smart_rollup.Dal.Slot_index.t + end + + module Page_index : sig + type t = Dal.Page.Index.t + + val of_octez : Octez_smart_rollup.Dal.Page_index.t -> t + + val to_octez : t -> Octez_smart_rollup.Dal.Page_index.t + end + + module Slot_header : sig + type t = Dal.Slot.Header.t + + val of_octez : Octez_smart_rollup.Dal.Slot_header.t -> t + + val to_octez : t -> Octez_smart_rollup.Dal.Slot_header.t + end + + module Slot_history : sig + type t = Dal.Slots_history.t + + val of_octez : Octez_smart_rollup.Dal.Slot_history.t -> t + + val to_octez : t -> Octez_smart_rollup.Dal.Slot_history.t + end + + module Slot_history_cache : sig + type t = Dal.Slots_history.History_cache.t + + val of_octez : Octez_smart_rollup.Dal.Slot_history_cache.t -> t + + val to_octez : t -> Octez_smart_rollup.Dal.Slot_history_cache.t + end +end diff --git a/src/proto_016_PtMumbai/lib_sc_rollup_layer2/sc_rollup_services.ml b/src/proto_016_PtMumbai/lib_sc_rollup_layer2/sc_rollup_services.ml index c2a21f4160345f5d147ceeb720e74d05f23e4edb..c4532a958aab2cd37eabb01023ce2f82f0de0828 100644 --- a/src/proto_016_PtMumbai/lib_sc_rollup_layer2/sc_rollup_services.ml +++ b/src/proto_016_PtMumbai/lib_sc_rollup_layer2/sc_rollup_services.ml @@ -100,8 +100,8 @@ type message_status = cemented : bool; commitment : Sc_rollup.Commitment.t; commitment_hash : Sc_rollup.Commitment.Hash.t; - first_published_at_level : Raw_level.t; - published_at_level : Raw_level.t; + first_published_at_level : int32; + published_at_level : int32; } module Encodings = struct @@ -116,8 +116,8 @@ module Encodings = struct obj4 (req "commitment" Sc_rollup.Commitment.encoding) (req "hash" Sc_rollup.Commitment.Hash.encoding) - (opt "first_published_at_level" Raw_level.encoding) - (opt "published_at_level" Raw_level.encoding) + (opt "first_published_at_level" int32) + (opt "published_at_level" int32) let hex_string = conv Bytes.of_string Bytes.to_string bytes @@ -322,8 +322,8 @@ module Encodings = struct (req "cemented" bool) (req "commitment" Sc_rollup.Commitment.encoding) (req "hash" Sc_rollup.Commitment.Hash.encoding) - (req "first_published_at_level" Raw_level.encoding) - (req "published_at_level" Raw_level.encoding)) + (req "first_published_at_level" int32) + (req "published_at_level" int32)) (function | Committed { diff --git a/src/proto_016_PtMumbai/lib_sc_rollup_node/RPC_server.ml b/src/proto_016_PtMumbai/lib_sc_rollup_node/RPC_server.ml index a450fda0114871c81449ed4d2f3730e262d5cef5..8fea1385726b2808bf0ba19420dddcafdb20d863 100644 --- a/src/proto_016_PtMumbai/lib_sc_rollup_node/RPC_server.ml +++ b/src/proto_016_PtMumbai/lib_sc_rollup_node/RPC_server.ml @@ -39,10 +39,7 @@ let get_head_hash_opt node_ctxt = let get_head_level_opt node_ctxt = let open Lwt_result_syntax in let+ res = Node_context.last_processed_head_opt node_ctxt in - Option.map - (fun Sc_rollup_block.{header = {level; _}; _} -> - Alpha_context.Raw_level.to_int32 level) - res + Option.map (fun Sc_rollup_block.{header = {level; _}; _} -> level) res module Slot_pages_map = struct open Protocol @@ -167,7 +164,10 @@ module Common = struct let open Lwt_result_syntax in let* l2_block = Node_context.get_l2_block node_ctxt block in let+ num_messages = - Node_context.get_num_messages node_ctxt l2_block.header.inbox_witness + Node_context.get_num_messages + node_ctxt + (Sc_rollup_proto_types.Merkelized_payload_hashes_hash.of_octez + l2_block.header.inbox_witness) in Z.of_int num_messages @@ -314,6 +314,7 @@ let () = | Some head -> let commitment_hash = Sc_rollup_block.most_recent_commitment head.header + |> Sc_rollup_proto_types.Commitment_hash.of_octez in let+ commitment = Node_context.find_commitment node_ctxt commitment_hash @@ -509,6 +510,7 @@ let () = WithExceptions.Option.get ~loc:__LOC__ block.header.commitment_hash + |> Sc_rollup_proto_types.Commitment_hash.of_octez in (* Commitment computed *) let* published_at = diff --git a/src/proto_016_PtMumbai/lib_sc_rollup_node/daemon.ml b/src/proto_016_PtMumbai/lib_sc_rollup_node/daemon.ml index 3077c3dcde6d487ee3e2997e6187016af42b1628..2f4e386a992f5ef0e2d887c2c3acf277a51e0f25 100644 --- a/src/proto_016_PtMumbai/lib_sc_rollup_node/daemon.ml +++ b/src/proto_016_PtMumbai/lib_sc_rollup_node/daemon.ml @@ -42,6 +42,7 @@ let is_refutable_commitment node_ctxt let* our_commitment_and_hash = Option.filter_map_es (fun hash -> + let hash = Sc_rollup_proto_types.Commitment_hash.of_octez hash in let+ commitment = Node_context.find_commitment node_ctxt hash in Option.map (fun c -> (c, hash)) commitment) l2_block.header.commitment_hash @@ -102,8 +103,8 @@ let process_included_l1_operation (type kind) (node_ctxt : Node_context.rw) node_ctxt commitment_hash { - first_published_at_level = published_at_level; - published_at_level = Some (Raw_level.of_int32_exn head.Layer1.level); + first_published_at_level = Raw_level.to_int32 published_at_level; + published_at_level = Some head.Layer1.level; } in let*! () = @@ -136,7 +137,8 @@ let process_included_l1_operation (type kind) (node_ctxt : Node_context.rw) node_ctxt their_commitment_hash { - first_published_at_level = published_at_level; + first_published_at_level = + Raw_level.to_int32 published_at_level; published_at_level = None; } in @@ -160,17 +162,18 @@ let process_included_l1_operation (type kind) (node_ctxt : Node_context.rw) in let*? () = (* We stop the node if we disagree with a cemented commitment *) + let our_commitment_hash = + Option.map + Sc_rollup_proto_types.Commitment_hash.of_octez + inbox_block.header.commitment_hash + in error_unless (Option.equal Sc_rollup.Commitment.Hash.( = ) - inbox_block.header.commitment_hash + our_commitment_hash (Some commitment)) (Sc_rollup_node_errors.Disagree_with_cemented - { - inbox_level; - ours = inbox_block.header.commitment_hash; - on_l1 = commitment; - }) + {inbox_level; ours = our_commitment_hash; on_l1 = commitment}) in let lcc = Reference.get node_ctxt.lcc in let*! () = @@ -357,6 +360,11 @@ let rec process_head (daemon_components : (module Daemon_components.S)) let* inbox_hash, inbox, inbox_witness, messages = Inbox.process_head node_ctxt ~predecessor head in + let inbox_witness = + Sc_rollup_proto_types.Merkelized_payload_hashes_hash.to_octez + inbox_witness + in + let inbox_hash = Sc_rollup_proto_types.Inbox_hash.to_octez inbox_hash in let* () = when_ (Node_context.dal_supported node_ctxt) @@ fun () -> Dal_slots_tracker.process_head node_ctxt (Layer1.head_of_header head) @@ -377,6 +385,11 @@ let rec process_head (daemon_components : (module Daemon_components.S)) let* commitment_hash = Publisher.process_head node_ctxt ~predecessor:predecessor.hash head ctxt in + let commitment_hash = + Option.map + Sc_rollup_proto_types.Commitment_hash.to_octez + commitment_hash + in let* () = unless (catching_up && Option.is_none commitment_hash) @@ fun () -> Inbox.same_as_layer_1 node_ctxt head.hash inbox @@ -385,7 +398,9 @@ let rec process_head (daemon_components : (module Daemon_components.S)) let* previous_commitment_hash = if level = node_ctxt.genesis_info.Sc_rollup.Commitment.level then (* Previous commitment for rollup genesis is itself. *) - return node_ctxt.genesis_info.Sc_rollup.Commitment.commitment_hash + return + (Sc_rollup_proto_types.Commitment_hash.to_octez + node_ctxt.genesis_info.Sc_rollup.Commitment.commitment_hash) else let+ pred = Node_context.get_l2_block node_ctxt predecessor.hash in Sc_rollup_block.most_recent_commitment pred.header @@ -394,7 +409,7 @@ let rec process_head (daemon_components : (module Daemon_components.S)) Sc_rollup_block. { block_hash = head.hash; - level; + level = head.level; predecessor = predecessor.hash; commitment_hash; previous_commitment_hash; @@ -404,7 +419,13 @@ let rec process_head (daemon_components : (module Daemon_components.S)) } in let l2_block = - Sc_rollup_block.{header; content = (); num_ticks; initial_tick} + Sc_rollup_block. + { + header; + content = (); + num_ticks; + initial_tick = Sc_rollup.Tick.to_z initial_tick; + } in let* () = Node_context.mark_finalized_level @@ -429,12 +450,7 @@ let on_layer_1_head (daemon_components : (module Daemon_components.S)) node_ctxt let old_head = match old_head with | Some h -> - `Head - Layer1. - { - hash = h.header.block_hash; - level = Raw_level.to_int32 h.header.level; - } + `Head Layer1.{hash = h.header.block_hash; level = h.header.level} | None -> (* if no head has been processed yet, we want to handle all blocks since, and including, the rollup origination. *) @@ -670,6 +686,11 @@ module Internal_for_tests = struct head messages in + let inbox_witness = + Sc_rollup_proto_types.Merkelized_payload_hashes_hash.to_octez + inbox_witness + in + let inbox_hash = Sc_rollup_proto_types.Inbox_hash.to_octez inbox_hash in let* ctxt, _num_messages, num_ticks, initial_tick = Interpreter.process_head node_ctxt ctxt ~predecessor head (inbox, messages) in @@ -681,11 +702,16 @@ module Internal_for_tests = struct head ctxt in + let commitment_hash = + Option.map Sc_rollup_proto_types.Commitment_hash.to_octez commitment_hash + in let level = Raw_level.of_int32_exn head.level in let* previous_commitment_hash = if level = node_ctxt.genesis_info.Sc_rollup.Commitment.level then (* Previous commitment for rollup genesis is itself. *) - return node_ctxt.genesis_info.Sc_rollup.Commitment.commitment_hash + return + (Sc_rollup_proto_types.Commitment_hash.to_octez + node_ctxt.genesis_info.Sc_rollup.Commitment.commitment_hash) else let+ pred = Node_context.get_l2_block node_ctxt predecessor.hash in Sc_rollup_block.most_recent_commitment pred.header @@ -694,7 +720,7 @@ module Internal_for_tests = struct Sc_rollup_block. { block_hash = head.hash; - level; + level = head.level; predecessor = predecessor.hash; commitment_hash; previous_commitment_hash; @@ -704,7 +730,13 @@ module Internal_for_tests = struct } in let l2_block = - Sc_rollup_block.{header; content = (); num_ticks; initial_tick} + Sc_rollup_block. + { + header; + content = (); + num_ticks; + initial_tick = Sc_rollup.Tick.to_z initial_tick; + } in let* () = Node_context.save_l2_head node_ctxt l2_block in return l2_block diff --git a/src/proto_016_PtMumbai/lib_sc_rollup_node/interpreter.ml b/src/proto_016_PtMumbai/lib_sc_rollup_node/interpreter.ml index 177e25a9bb77580ebf004e4444dd902de2c6515b..32ae0fcb1f8cdc77310825defe82ae24aac02ef6 100644 --- a/src/proto_016_PtMumbai/lib_sc_rollup_node/interpreter.ml +++ b/src/proto_016_PtMumbai/lib_sc_rollup_node/interpreter.ml @@ -150,7 +150,7 @@ let process_head (node_ctxt : _ Node_context.t) ctxt the messages the block ([remaining_messages]). *) let start_state_of_block node_ctxt (block : Sc_rollup_block.t) = let open Lwt_result_syntax in - let pred_level = Raw_level.to_int32 block.header.level |> Int32.pred in + let pred_level = Int32.pred block.header.level in let* ctxt = Node_context.checkout_context node_ctxt block.header.predecessor in @@ -160,9 +160,16 @@ let start_state_of_block node_ctxt (block : Sc_rollup_block.t) = ctxt Layer1.{hash = block.header.predecessor; level = pred_level} in - let* inbox = Node_context.get_inbox node_ctxt block.header.inbox_hash in + let* inbox = + Node_context.get_inbox + node_ctxt + (Sc_rollup_proto_types.Inbox_hash.of_octez block.header.inbox_hash) + in let* {predecessor; predecessor_timestamp; messages} = - Node_context.get_messages node_ctxt block.header.inbox_witness + Node_context.get_messages + node_ctxt + (Sc_rollup_proto_types.Merkelized_payload_hashes_hash.of_octez + block.header.inbox_witness) in let inbox_level = Sc_rollup.Inbox.inbox_level inbox in let module PVM = (val node_ctxt.pvm) in @@ -210,9 +217,8 @@ let state_of_tick_aux node_ctxt ~start_state (event : Sc_rollup_block.t) tick = let* start_state = match start_state with | Some start_state - when Raw_level.( - start_state.Fueled_pvm.Accounted.inbox_level = event.header.level) - -> + when Raw_level.to_int32 start_state.Fueled_pvm.Accounted.inbox_level + = event.header.level -> return start_state | _ -> (* Recompute start state on level change or if we don't have a @@ -261,7 +267,7 @@ let state_of_tick node_ctxt ?start_state tick level = match event with | None -> return_none | Some event -> - assert (Raw_level.(event.header.level <= level)) ; + assert (event.header.level <= Raw_level.to_int32 level) ; let* result_state = if Node_context.is_loser node_ctxt then (* TODO: https://gitlab.com/tezos/tezos/-/issues/5253 diff --git a/src/proto_016_PtMumbai/lib_sc_rollup_node/node_context.ml b/src/proto_016_PtMumbai/lib_sc_rollup_node/node_context.ml index 5e12722b9d436db27224cdc11d8bb67662b86333..d9c4667059be49ccfcde935086528574d2215613 100644 --- a/src/proto_016_PtMumbai/lib_sc_rollup_node/node_context.ml +++ b/src/proto_016_PtMumbai/lib_sc_rollup_node/node_context.ml @@ -462,7 +462,7 @@ let level_of_hash {l1_ctxt; store; _} hash = let open Lwt_result_syntax in let* l2_header = Store.L2_blocks.header store.l2_blocks hash in match l2_header with - | Some {level; _} -> return (Raw_level.to_int32 level) + | Some {level; _} -> return level | None -> let+ {level; _} = Layer1.fetch_tezos_shell_header l1_ctxt hash in level @@ -538,7 +538,7 @@ let get_l2_block_predecessor node_ctxt hash = let+ header = Store.L2_blocks.header node_ctxt.store.l2_blocks hash in Option.map (fun {Sc_rollup_block.predecessor; level; _} -> - (predecessor, Int32.pred (Raw_level.to_int32 level))) + (predecessor, Int32.pred level)) header let get_predecessor_opt node_ctxt (hash, level) = @@ -610,8 +610,8 @@ let get_predecessor_header node_ctxt head = first look for a block before the [tick] *) let tick_search ~big_step_blocks node_ctxt head tick = let open Lwt_result_syntax in - if Sc_rollup.Tick.(head.Sc_rollup_block.initial_tick <= tick) then - if Sc_rollup.Tick.(Sc_rollup_block.final_tick head < tick) then + if Z.Compare.(head.Sc_rollup_block.initial_tick <= tick) then + if Z.Compare.(Sc_rollup_block.final_tick head < tick) then (* The head block does not contain the tick *) return_none else @@ -621,20 +621,18 @@ let tick_search ~big_step_blocks node_ctxt head tick = let genesis_level = Raw_level.to_int32 node_ctxt.genesis_info.level in let rec find_big_step (end_block : Sc_rollup_block.t) = let start_level = - Int32.sub - (Raw_level.to_int32 end_block.header.level) - (Int32.of_int big_step_blocks) + Int32.sub end_block.header.level (Int32.of_int big_step_blocks) in let start_level = if start_level < genesis_level then genesis_level else start_level in let* start_block = get_l2_block_by_level node_ctxt start_level in - if Sc_rollup.Tick.(start_block.initial_tick <= tick) then + if Z.Compare.(start_block.initial_tick <= tick) then return (start_block, end_block) else find_big_step start_block in let block_level Sc_rollup_block.{header = {level; _}; _} = - Raw_level.to_int32 level |> Int32.to_int + Int32.to_int level in let rec dicho start_block end_block = (* Precondition: @@ -650,7 +648,7 @@ let tick_search ~big_step_blocks node_ctxt head tick = let* block_middle = get_l2_block_by_level node_ctxt (Int32.of_int middle_level) in - if Sc_rollup.Tick.(block_middle.initial_tick <= tick) then + if Z.Compare.(block_middle.initial_tick <= tick) then dicho block_middle end_block else dicho start_block block_middle in @@ -673,51 +671,80 @@ let block_with_tick ({store; _} as node_ctxt) ~max_level tick = the refutation period as the big_step_blocks to do a dichotomy on the full space but we anticipate refutation to happen most of the time close to the head. *) + let max_level = Raw_level.to_int32 max_level in let** head = - if Raw_level.(head.header.level <= max_level) then return_some head - else find_l2_block_by_level node_ctxt (Raw_level.to_int32 max_level) + if head.header.level <= max_level then return_some head + else find_l2_block_by_level node_ctxt max_level in - tick_search ~big_step_blocks:4096 node_ctxt head tick + tick_search ~big_step_blocks:4096 node_ctxt head (Sc_rollup.Tick.to_z tick) -let get_commitment {store; _} commitment_hash = +let find_octez_commitment {store; _} commitment_hash = let open Lwt_result_syntax in - let* commitment = Store.Commitments.read store.commitments commitment_hash in + let+ commitment = Store.Commitments.read store.commitments commitment_hash in + Option.map fst commitment + +let find_commitment node_ctxt commitment_hash = + let open Lwt_result_syntax in + let commitment_hash = + Sc_rollup_proto_types.Commitment_hash.to_octez commitment_hash + in + let+ commitment = find_octez_commitment node_ctxt commitment_hash in + Option.map Sc_rollup_proto_types.Commitment.of_octez commitment + +let get_octez_commitment node_ctxt commitment_hash = + let open Lwt_result_syntax in + let* commitment = find_octez_commitment node_ctxt commitment_hash in match commitment with | None -> failwith "Could not retrieve commitment %a" - Sc_rollup.Commitment.Hash.pp + Octez_smart_rollup.Commitment.Hash.pp commitment_hash - | Some (c, ()) -> return c + | Some i -> return i -let find_commitment {store; _} hash = +let get_commitment node_ctxt commitment_hash = let open Lwt_result_syntax in - let+ commitment = Store.Commitments.read store.commitments hash in - Option.map fst commitment + let* commitment = find_commitment node_ctxt commitment_hash in + match commitment with + | None -> + failwith + "Could not retrieve commitment %a" + Sc_rollup.Commitment.Hash.pp + commitment_hash + | Some i -> return i let commitment_exists {store; _} hash = + let hash = Sc_rollup_proto_types.Commitment_hash.to_octez hash in Store.Commitments.mem store.commitments hash let save_commitment {store; _} commitment = let open Lwt_result_syntax in - let hash = Sc_rollup.Commitment.hash_uncarbonated commitment in + let commitment = Sc_rollup_proto_types.Commitment.to_octez commitment in + let hash = Octez_smart_rollup.Commitment.hash commitment in let+ () = Store.Commitments.append store.commitments ~key:hash ~value:commitment in - hash + Sc_rollup_proto_types.Commitment_hash.of_octez hash let commitment_published_at_level {store; _} commitment = + let commitment = Sc_rollup_proto_types.Commitment_hash.to_octez commitment in Store.Commitments_published_at_level.find store.commitments_published_at_level commitment -let set_commitment_published_at_level {store; _} = - Store.Commitments_published_at_level.add store.commitments_published_at_level +let set_commitment_published_at_level {store; _} hash = + let hash = Sc_rollup_proto_types.Commitment_hash.to_octez hash in + Store.Commitments_published_at_level.add + store.commitments_published_at_level + hash type commitment_source = Anyone | Us let commitment_was_published {store; _} ~source commitment_hash = let open Lwt_result_syntax in + let commitment_hash = + Sc_rollup_proto_types.Commitment_hash.to_octez commitment_hash + in match source with | Anyone -> Store.Commitments_published_at_level.mem @@ -733,31 +760,52 @@ let commitment_was_published {store; _} ~source commitment_hash = | Some {published_at_level = Some _; _} -> true | _ -> false) -let get_inbox {store; _} inbox_hash = +let find_octez_inbox {store; _} inbox_hash = let open Lwt_result_syntax in - let* inbox = Store.Inboxes.read store.inboxes inbox_hash in + let+ inbox = Store.Inboxes.read store.inboxes inbox_hash in + Option.map fst inbox + +let find_inbox node_ctxt inbox_hash = + let open Lwt_result_syntax in + let inbox_hash = Sc_rollup_proto_types.Inbox_hash.to_octez inbox_hash in + let+ inbox = find_octez_inbox node_ctxt inbox_hash in + Option.map Sc_rollup_proto_types.Inbox.of_octez inbox + +let get_octez_inbox node_ctxt inbox_hash = + let open Lwt_result_syntax in + let* inbox = find_octez_inbox node_ctxt inbox_hash in match inbox with | None -> - failwith "Could not retrieve inbox %a" Sc_rollup.Inbox.Hash.pp inbox_hash - | Some (i, ()) -> return i + failwith + "Could not retrieve inbox %a" + Octez_smart_rollup.Inbox.Hash.pp + inbox_hash + | Some i -> return i -let find_inbox {store; _} hash = +let get_inbox node_ctxt inbox_hash = let open Lwt_result_syntax in - let+ inbox = Store.Inboxes.read store.inboxes hash in - Option.map fst inbox + let* inbox = find_inbox node_ctxt inbox_hash in + match inbox with + | None -> + failwith "Could not retrieve inbox %a" Sc_rollup.Inbox.Hash.pp inbox_hash + | Some i -> return i let save_inbox {store; _} inbox = let open Lwt_result_syntax in - let hash = Sc_rollup.Inbox.hash inbox in + let inbox = Sc_rollup_proto_types.Inbox.to_octez inbox in + let hash = Octez_smart_rollup.Inbox.hash inbox in let+ () = Store.Inboxes.append store.inboxes ~key:hash ~value:inbox in - hash + Sc_rollup_proto_types.Inbox_hash.of_octez hash let find_inbox_by_block_hash ({store; _} as node_ctxt) block_hash = let open Lwt_result_syntax in let* header = Store.L2_blocks.header store.l2_blocks block_hash in match header with | None -> return_none - | Some {inbox_hash; _} -> find_inbox node_ctxt inbox_hash + | Some {inbox_hash; _} -> + find_inbox + node_ctxt + (Sc_rollup_proto_types.Inbox_hash.of_octez inbox_hash) let genesis_inbox node_ctxt = let genesis_level = Raw_level.to_int32 node_ctxt.genesis_info.level in @@ -806,12 +854,22 @@ type messages_info = { let find_messages node_ctxt messages_hash = let open Lwt_result_syntax in + let messages_hash = + Sc_rollup_proto_types.Merkelized_payload_hashes_hash.to_octez messages_hash + in let* msg = Store.Messages.read node_ctxt.store.messages messages_hash in match msg with | None -> return_none | Some (messages, block_hash) -> let* header = header_of_hash node_ctxt block_hash in let* pred_header = header_of_hash node_ctxt header.header.predecessor in + let*? messages = + Environment.wrap_tzresult + @@ List.map_e + (fun m -> + Sc_rollup.Inbox_message.(deserialize @@ unsafe_of_string m)) + messages + in return_some { predecessor = pred_header.hash; @@ -819,18 +877,22 @@ let find_messages node_ctxt messages_hash = messages; } -let get_messages_aux find node_ctxt hash = +let get_messages_aux find pp node_ctxt hash = let open Lwt_result_syntax in let* res = find node_ctxt hash in match res with | None -> failwith "Could not retrieve messages with payloads merkelized hash %a" - Sc_rollup.Inbox_merkelized_payload_hashes.Hash.pp + pp hash | Some res -> return res -let get_messages node_ctxt = get_messages_aux find_messages node_ctxt +let get_messages node_ctxt = + get_messages_aux + find_messages + Sc_rollup.Inbox_merkelized_payload_hashes.Hash.pp + node_ctxt let get_messages_without_proto_messages node_ctxt = get_messages_aux @@ -840,30 +902,45 @@ let get_messages_without_proto_messages node_ctxt = match msg with | None -> return_none | Some (messages, _block_hash) -> return_some messages) + Tezos_crypto.Hashed.Smart_rollup_merkelized_payload_hashes_hash.pp node_ctxt let get_num_messages {store; _} hash = let open Lwt_result_syntax in + let hash = + Sc_rollup_proto_types.Merkelized_payload_hashes_hash.to_octez hash + in let* msg = Store.Messages.read store.messages hash in match msg with | None -> failwith "Could not retrieve number of messages for inbox witness %a" - Sc_rollup.Inbox_merkelized_payload_hashes.Hash.pp + Tezos_crypto.Hashed.Smart_rollup_merkelized_payload_hashes_hash.pp hash | Some (messages, _block_hash) -> return (List.length messages) let save_messages {store; _} key ~block_hash messages = + let open Lwt_result_syntax in + let key = Sc_rollup_proto_types.Merkelized_payload_hashes_hash.to_octez key in + let*? messages = + Environment.wrap_tzresult + @@ List.map_e + (fun m -> + let open Result_syntax in + let+ m = Sc_rollup.Inbox_message.serialize m in + Sc_rollup.Inbox_message.unsafe_to_string m) + messages + in Store.Messages.append store.messages ~key ~header:block_hash ~value:messages let get_full_l2_block node_ctxt block_hash = let open Lwt_result_syntax in let* block = get_l2_block node_ctxt block_hash in - let* inbox = get_inbox node_ctxt block.header.inbox_hash + let* inbox = get_octez_inbox node_ctxt block.header.inbox_hash and* messages = get_messages_without_proto_messages node_ctxt block.header.inbox_witness and* commitment = - Option.map_es (get_commitment node_ctxt) block.header.commitment_hash + Option.map_es (get_octez_commitment node_ctxt) block.header.commitment_hash in return {block with content = {Sc_rollup_block.inbox; messages; commitment}} @@ -1022,52 +1099,77 @@ let get_slot_header {store; _} ~published_in_block_hash slot_index = slot_index Block_hash.pp published_in_block_hash - @@ Store.Dal_slots_headers.get - store.irmin_store - ~primary_key:published_in_block_hash - ~secondary_key:slot_index + @@ + let open Lwt_result_syntax in + let+ header = + Store.Dal_slots_headers.get + store.irmin_store + ~primary_key:published_in_block_hash + ~secondary_key:(Dal.Slot_index.to_int slot_index) + in + Sc_rollup_proto_types.Dal.Slot_header.of_octez header let get_all_slot_headers {store; _} ~published_in_block_hash = - Store.Dal_slots_headers.list_values - store.irmin_store - ~primary_key:published_in_block_hash + let open Lwt_result_syntax in + let+ headers = + Store.Dal_slots_headers.list_values + store.irmin_store + ~primary_key:published_in_block_hash + in + List.rev_map Sc_rollup_proto_types.Dal.Slot_header.of_octez headers + |> List.rev let get_slot_indexes {store; _} ~published_in_block_hash = - Store.Dal_slots_headers.list_secondary_keys - store.irmin_store - ~primary_key:published_in_block_hash + let open Lwt_result_syntax in + let+ indexes = + Store.Dal_slots_headers.list_secondary_keys + store.irmin_store + ~primary_key:published_in_block_hash + in + List.rev_map Sc_rollup_proto_types.Dal.Slot_index.of_octez indexes |> List.rev let save_slot_header {store; _} ~published_in_block_hash (slot_header : Dal.Slot.Header.t) = Store.Dal_slots_headers.add store.irmin_store ~primary_key:published_in_block_hash - ~secondary_key:slot_header.id.index - slot_header + ~secondary_key: + (Sc_rollup_proto_types.Dal.Slot_index.to_octez slot_header.id.index) + (Sc_rollup_proto_types.Dal.Slot_header.to_octez slot_header) let processed_slot {store; _} ~confirmed_in_block_hash slot_index = Store.Dal_slots_statuses.find store.irmin_store ~primary_key:confirmed_in_block_hash - ~secondary_key:slot_index + ~secondary_key:(Dal.Slot_index.to_int slot_index) let list_slot_pages {store; _} ~confirmed_in_block_hash = - Store.Dal_slot_pages.list_secondary_keys_with_values - store.irmin_store - ~primary_key:confirmed_in_block_hash + let open Lwt_result_syntax in + let+ slot_pages = + Store.Dal_slot_pages.list_secondary_keys_with_values + store.irmin_store + ~primary_key:confirmed_in_block_hash + in + List.rev_map + (fun ((slot_index, page_index), content) -> + ( (Sc_rollup_proto_types.Dal.Slot_index.of_octez slot_index, page_index), + content )) + slot_pages + |> List.rev let find_slot_page {store; _} ~confirmed_in_block_hash ~slot_index ~page_index = Store.Dal_slot_pages.find store.irmin_store ~primary_key:confirmed_in_block_hash - ~secondary_key:(slot_index, page_index) + ~secondary_key: + (Sc_rollup_proto_types.Dal.Slot_index.to_octez slot_index, page_index) let save_unconfirmed_slot {store; _} current_block_hash slot_index = (* No page is actually saved *) Store.Dal_slots_statuses.add store.irmin_store ~primary_key:current_block_hash - ~secondary_key:slot_index + ~secondary_key:(Sc_rollup_proto_types.Dal.Slot_index.to_octez slot_index) `Unconfirmed let save_confirmed_slot {store; _} current_block_hash slot_index pages = @@ -1080,27 +1182,39 @@ let save_confirmed_slot {store; _} current_block_hash slot_index pages = Store.Dal_slot_pages.add store.irmin_store ~primary_key:current_block_hash - ~secondary_key:(slot_index, page_number) + ~secondary_key: + ( Sc_rollup_proto_types.Dal.Slot_index.to_octez slot_index, + page_number ) page) pages in Store.Dal_slots_statuses.add store.irmin_store ~primary_key:current_block_hash - ~secondary_key:slot_index + ~secondary_key:(Sc_rollup_proto_types.Dal.Slot_index.to_octez slot_index) `Confirmed -let find_confirmed_slots_history {store; _} = - Store.Dal_confirmed_slots_history.find store.irmin_store +let find_confirmed_slots_history {store; _} block = + let open Lwt_result_syntax in + let+ res = Store.Dal_confirmed_slots_history.find store.irmin_store block in + Option.map Sc_rollup_proto_types.Dal.Slot_history.of_octez res -let save_confirmed_slots_history {store; _} = - Store.Dal_confirmed_slots_history.add store.irmin_store +let save_confirmed_slots_history {store; _} block hist = + Store.Dal_confirmed_slots_history.add + store.irmin_store + block + (Sc_rollup_proto_types.Dal.Slot_history.to_octez hist) -let find_confirmed_slots_histories {store; _} = - Store.Dal_confirmed_slots_histories.find store.irmin_store +let find_confirmed_slots_histories {store; _} block = + let open Lwt_result_syntax in + let+ res = Store.Dal_confirmed_slots_histories.find store.irmin_store block in + Option.map Sc_rollup_proto_types.Dal.Slot_history_cache.of_octez res -let save_confirmed_slots_histories {store; _} = - Store.Dal_confirmed_slots_histories.add store.irmin_store +let save_confirmed_slots_histories {store; _} block hist = + Store.Dal_confirmed_slots_histories.add + store.irmin_store + block + (Sc_rollup_proto_types.Dal.Slot_history_cache.to_octez hist) module Internal_for_tests = struct let create_node_context cctxt diff --git a/src/proto_016_PtMumbai/lib_sc_rollup_node/publisher.ml b/src/proto_016_PtMumbai/lib_sc_rollup_node/publisher.ml index 96274d64f95c759ae8b7559ffe013153936f4606..7febcaea817bfe2b8e7e5db671ada33aa4644d8f 100644 --- a/src/proto_016_PtMumbai/lib_sc_rollup_node/publisher.ml +++ b/src/proto_016_PtMumbai/lib_sc_rollup_node/publisher.ml @@ -110,9 +110,9 @@ let build_commitment (node_ctxt : _ Node_context.t) let*! compressed_state = PVM.state_hash pvm_state in let*! tick = PVM.get_tick pvm_state in let* prev_commitment_tick = tick_of_level node_ctxt prev_commitment_level in + let distance = Z.sub (Sc_rollup.Tick.to_z tick) prev_commitment_tick in let number_of_ticks = - Sc_rollup.Tick.distance tick prev_commitment_tick - |> Z.to_int64 |> Sc_rollup.Number_of_ticks.of_value + distance |> Z.to_int64 |> Sc_rollup.Number_of_ticks.of_value in let*? number_of_ticks = match number_of_ticks with @@ -177,6 +177,7 @@ let create_commitment_if_necessary (node_ctxt : _ Node_context.t) ~predecessor let* last_commitment_hash = let+ pred = Node_context.get_l2_block node_ctxt predecessor in Sc_rollup_block.most_recent_commitment pred.header + |> Sc_rollup_proto_types.Commitment_hash.of_octez in let* last_commitment = Node_context.get_commitment node_ctxt last_commitment_hash @@ -221,9 +222,7 @@ let missing_commitments (node_ctxt : _ Node_context.t) = in let* head = Node_context.last_processed_head_opt node_ctxt in let next_head_level = - Option.map - (fun (b : Sc_rollup_block.t) -> Raw_level.succ b.header.level) - head + Option.map (fun (b : Sc_rollup_block.t) -> Int32.succ b.header.level) head in let sc_rollup_challenge_window_int32 = sc_rollup_challenge_window node_ctxt |> Int32.of_int @@ -249,7 +248,7 @@ let missing_commitments (node_ctxt : _ Node_context.t) = match (published_info, next_head_level) with | None, _ | _, None -> false | Some {first_published_at_level; _}, Some next_head_level -> - Raw_level.diff next_head_level first_published_at_level + Int32.sub next_head_level first_published_at_level > sc_rollup_challenge_window_int32 in let acc = if past_curfew then acc else commitment :: acc in @@ -264,6 +263,7 @@ let missing_commitments (node_ctxt : _ Node_context.t) = commitments that are missing. *) let commitment = Sc_rollup_block.most_recent_commitment finalized.header + |> Sc_rollup_proto_types.Commitment_hash.of_octez in gather [] commitment @@ -320,7 +320,9 @@ let earliest_cementing_level node_ctxt commitment_hash = Node_context.commitment_published_at_level node_ctxt commitment_hash in return_some - @@ add_level first_published_at_level (sc_rollup_challenge_window node_ctxt) + @@ Int32.add + first_published_at_level + (sc_rollup_challenge_window node_ctxt |> Int32.of_int) (** [latest_cementable_commitment node_ctxt head] is the most recent commitment hash that could be cemented in [head]'s successor if: @@ -333,7 +335,10 @@ let earliest_cementing_level node_ctxt commitment_hash = let latest_cementable_commitment (node_ctxt : _ Node_context.t) (head : Sc_rollup_block.t) = let open Lwt_result_option_syntax in - let commitment_hash = Sc_rollup_block.most_recent_commitment head.header in + let commitment_hash = + Sc_rollup_block.most_recent_commitment head.header + |> Sc_rollup_proto_types.Commitment_hash.of_octez + in let** commitment = Node_context.find_commitment node_ctxt commitment_hash in let** cementable_level_bound = return @@ -349,6 +354,7 @@ let latest_cementable_commitment (node_ctxt : _ Node_context.t) in let cementable_commitment = Sc_rollup_block.most_recent_commitment cementable_bound_block.header + |> Sc_rollup_proto_types.Commitment_hash.of_octez in return_some cementable_commitment @@ -374,7 +380,7 @@ let cementable_commitments (node_ctxt : _ Node_context.t) = match earliest_cementing_level with | None -> acc | Some earliest_cementing_level -> - if Raw_level.(earliest_cementing_level > head_level) then + if earliest_cementing_level > head_level then (* Commitments whose cementing level are after the head's successor won't be cementable in the next block. *) acc diff --git a/src/proto_016_PtMumbai/lib_sc_rollup_node/store_v0.ml b/src/proto_016_PtMumbai/lib_sc_rollup_node/store_v0.ml deleted file mode 100644 index 066a37f739fb3ba9037c31a4a8789ee09936bad4..0000000000000000000000000000000000000000 --- a/src/proto_016_PtMumbai/lib_sc_rollup_node/store_v0.ml +++ /dev/null @@ -1,506 +0,0 @@ -(*****************************************************************************) -(* *) -(* Open Source License *) -(* Copyright (c) 2021 Nomadic Labs, *) -(* Copyright (c) 2023 Functori, *) -(* *) -(* 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. *) -(* *) -(*****************************************************************************) - -(** This module is a copy of - [src/proto_016_PtMumbai/lib_sc_rollup_node/store.ml], which contains the - store for the Mumbai rollup node. *) - -open Protocol -include Store_sigs -include Store_utils - -(** Aggregated collection of messages from the L1 inbox *) -open Alpha_context - -let version = Store_version.V0 - -module Irmin_store = struct - module IStore = Irmin_store.Make (struct - let name = "Tezos smart rollup node" - end) - - include IStore - include Store_utils.Make (IStore) -end - -module Empty_header = struct - type t = unit - - let name = "empty" - - let encoding = Data_encoding.unit - - let fixed_size = 0 -end - -module Add_empty_header = struct - module Header = Empty_header - - let header _ = () -end - -module Make_hash_index_key (H : Environment.S.HASH) = -Indexed_store.Make_index_key (struct - include Indexed_store.Make_fixed_encodable (H) - - let equal = H.equal -end) - -(** L2 blocks *) -module L2_blocks = - Indexed_store.Make_indexed_file - (struct - let name = "l2_blocks" - end) - (Tezos_store_shared.Block_key) - (struct - type t = (unit, unit) Sc_rollup_block.block - - let name = "sc_rollup_block_info" - - let encoding = - Sc_rollup_block.block_encoding Data_encoding.unit Data_encoding.unit - - module Header = struct - type t = Sc_rollup_block.header - - let name = "sc_rollup_block_header" - - let encoding = Sc_rollup_block.header_encoding - - let fixed_size = Sc_rollup_block.header_size - end - end) - -(** Unaggregated messages per block *) -module Messages = - Indexed_store.Make_indexed_file - (struct - let name = "messages" - end) - (Make_hash_index_key (Sc_rollup.Inbox_merkelized_payload_hashes.Hash)) - (struct - type t = Sc_rollup.Inbox_message.t list - - let name = "messages_list" - - let encoding = - Data_encoding.(list @@ dynamic_size Sc_rollup.Inbox_message.encoding) - - module Header = struct - type t = Block_hash.t * Timestamp.t * int - - let name = "messages_inbox_info" - - let encoding = - let open Data_encoding in - obj3 - (req "predecessor" Block_hash.encoding) - (req "predecessor_timestamp" Timestamp.encoding) - (req "num_messages" int31) - - let fixed_size = - WithExceptions.Option.get ~loc:__LOC__ - @@ Data_encoding.Binary.fixed_length encoding - end - end) - -(** Inbox state for each block *) -module Inboxes = - Indexed_store.Make_simple_indexed_file - (struct - let name = "inboxes" - end) - (Make_hash_index_key (Sc_rollup.Inbox.Hash)) - (struct - type t = Sc_rollup.Inbox.t - - let name = "inbox" - - let encoding = Sc_rollup.Inbox.encoding - - include Add_empty_header - end) - -module Commitments = - Indexed_store.Make_indexable - (struct - let name = "commitments" - end) - (Make_hash_index_key (Sc_rollup.Commitment.Hash)) - (Indexed_store.Make_index_value (Indexed_store.Make_fixed_encodable (struct - include Sc_rollup.Commitment - - let name = "commitment" - end))) - -module Commitments_published_at_level = struct - type element = { - first_published_at_level : Raw_level.t; - published_at_level : Raw_level.t option; - } - - let element_encoding = - let open Data_encoding in - let opt_level_encoding = - conv - (function None -> -1l | Some l -> Raw_level.to_int32 l) - (fun l -> if l = -1l then None else Some (Raw_level.of_int32_exn l)) - Data_encoding.int32 - in - conv - (fun {first_published_at_level; published_at_level} -> - (first_published_at_level, published_at_level)) - (fun (first_published_at_level, published_at_level) -> - {first_published_at_level; published_at_level}) - @@ obj2 - (req "first_published_at_level" Raw_level.encoding) - (req "published_at_level" opt_level_encoding) - - include - Indexed_store.Make_indexable - (struct - let name = "commitments" - end) - (Make_hash_index_key (Sc_rollup.Commitment.Hash)) - (Indexed_store.Make_index_value (Indexed_store.Make_fixed_encodable (struct - type t = element - - let name = "published_levels" - - let encoding = element_encoding - end))) -end - -module L2_head = Indexed_store.Make_singleton (struct - type t = Sc_rollup_block.t - - let name = "l2_head" - - let encoding = Sc_rollup_block.encoding -end) - -module Last_finalized_level = Indexed_store.Make_singleton (struct - type t = int32 - - let name = "finalized_level" - - let encoding = Data_encoding.int32 -end) - -(** Table from L1 levels to blocks hashes. *) -module Levels_to_hashes = - Indexed_store.Make_indexable - (struct - let name = "tezos_levels" - end) - (Indexed_store.Make_index_key (struct - type t = int32 - - let encoding = Data_encoding.int32 - - let name = "level" - - let fixed_size = 4 - - let equal = Int32.equal - end)) - (Tezos_store_shared.Block_key) - -(* Published slot headers per block hash, - stored as a list of bindings from `Dal_slot_index.t` - to `Dal.Slot.t`. The encoding function converts this - list into a `Dal.Slot_index.t`-indexed map. *) -module Dal_slot_pages = - Irmin_store.Make_nested_map - (struct - let path = ["dal"; "slot_pages"] - end) - (struct - type key = Block_hash.t - - let to_path_representation = Block_hash.to_b58check - end) - (struct - type key = Dal.Slot_index.t * Dal.Page.Index.t - - let encoding = - Data_encoding.(tup2 Dal.Slot_index.encoding Dal.Page.Index.encoding) - - let compare (i1, p1) (i2, p2) = - Compare.or_else (Dal.Slot_index.compare i1 i2) (fun () -> - Dal.Page.Index.compare p1 p2) - - let name = "slot_index" - end) - (struct - type value = Dal.Page.content - - let encoding = Dal.Page.content_encoding - - let name = "slot_pages" - end) - -(** stores slots whose data have been considered and pages stored to disk (if - they are confirmed). *) -module Dal_processed_slots = - Irmin_store.Make_nested_map - (struct - let path = ["dal"; "processed_slots"] - end) - (struct - type key = Block_hash.t - - let to_path_representation = Block_hash.to_b58check - end) - (struct - type key = Dal.Slot_index.t - - let encoding = Dal.Slot_index.encoding - - let compare = Dal.Slot_index.compare - - let name = "slot_index" - end) - (struct - type value = [`Confirmed | `Unconfirmed] - - let name = "slot_processing_status" - - let encoding = - let open Data_encoding in - let mk_case constr ~tag ~title = - case - ~title - (Tag tag) - (obj1 (req "kind" (constant title))) - (fun x -> if x = constr then Some () else None) - (fun () -> constr) - in - union - ~tag_size:`Uint8 - [ - mk_case `Confirmed ~tag:0 ~title:"Confirmed"; - mk_case `Unconfirmed ~tag:1 ~title:"Unconfirmed"; - ] - end) - -module Dal_slots_headers = - Irmin_store.Make_nested_map - (struct - let path = ["dal"; "slot_headers"] - end) - (struct - type key = Block_hash.t - - let to_path_representation = Block_hash.to_b58check - end) - (struct - type key = Dal.Slot_index.t - - let encoding = Dal.Slot_index.encoding - - let compare = Dal.Slot_index.compare - - let name = "slot_index" - end) - (struct - type value = Dal.Slot.Header.t - - let name = "slot_header" - - let encoding = Dal.Slot.Header.encoding - end) - -(* Published slot headers per block hash, stored as a list of bindings from - `Dal_slot_index.t` to `Dal.Slot.t`. The encoding function converts this - list into a `Dal.Slot_index.t`-indexed map. Note that the block_hash - refers to the block where slots headers have been confirmed, not - the block where they have been published. -*) - -(** Confirmed DAL slots history. See documentation of - {!Dal_slot_repr.Slots_history} for more details. *) -module Dal_confirmed_slots_history = - Irmin_store.Make_append_only_map - (struct - let path = ["dal"; "confirmed_slots_history"] - end) - (struct - type key = Block_hash.t - - let to_path_representation = Block_hash.to_b58check - end) - (struct - type value = Dal.Slots_history.t - - let name = "dal_slot_histories" - - let encoding = Dal.Slots_history.encoding - end) - -(** Confirmed DAL slots histories cache. See documentation of - {!Dal_slot_repr.Slots_history} for more details. *) -module Dal_confirmed_slots_histories = - (* TODO: https://gitlab.com/tezos/tezos/-/issues/4390 - Store single history points in map instead of whole history. *) - Irmin_store.Make_append_only_map - (struct - let path = ["dal"; "confirmed_slots_histories_cache"] - end) - (struct - type key = Block_hash.t - - let to_path_representation = Block_hash.to_b58check - end) - (struct - type value = Dal.Slots_history.History_cache.t - - let name = "dal_slot_history_cache" - - let encoding = Dal.Slots_history.History_cache.encoding - end) - -type 'a store = { - l2_blocks : 'a L2_blocks.t; - messages : 'a Messages.t; - inboxes : 'a Inboxes.t; - commitments : 'a Commitments.t; - commitments_published_at_level : 'a Commitments_published_at_level.t; - l2_head : 'a L2_head.t; - last_finalized_level : 'a Last_finalized_level.t; - levels_to_hashes : 'a Levels_to_hashes.t; - irmin_store : 'a Irmin_store.t; -} - -type 'a t = ([< `Read | `Write > `Read] as 'a) store - -type rw = Store_sigs.rw t - -type ro = Store_sigs.ro t - -let readonly - ({ - l2_blocks; - messages; - inboxes; - commitments; - commitments_published_at_level; - l2_head; - last_finalized_level; - levels_to_hashes; - irmin_store; - } : - _ t) : ro = - { - l2_blocks = L2_blocks.readonly l2_blocks; - messages = Messages.readonly messages; - inboxes = Inboxes.readonly inboxes; - commitments = Commitments.readonly commitments; - commitments_published_at_level = - Commitments_published_at_level.readonly commitments_published_at_level; - l2_head = L2_head.readonly l2_head; - last_finalized_level = Last_finalized_level.readonly last_finalized_level; - levels_to_hashes = Levels_to_hashes.readonly levels_to_hashes; - irmin_store = Irmin_store.readonly irmin_store; - } - -let close - ({ - l2_blocks; - messages; - inboxes; - commitments; - commitments_published_at_level; - l2_head = _; - last_finalized_level = _; - levels_to_hashes; - irmin_store; - } : - _ t) = - let open Lwt_result_syntax in - let+ () = L2_blocks.close l2_blocks - and+ () = Messages.close messages - and+ () = Inboxes.close inboxes - and+ () = Commitments.close commitments - and+ () = Commitments_published_at_level.close commitments_published_at_level - and+ () = Levels_to_hashes.close levels_to_hashes - and+ () = Irmin_store.close irmin_store in - () - -let load (type a) (mode : a mode) ~l2_blocks_cache_size data_dir : - a store tzresult Lwt.t = - let open Lwt_result_syntax in - let path name = Filename.concat data_dir name in - let cache_size = l2_blocks_cache_size in - let* l2_blocks = L2_blocks.load mode ~path:(path "l2_blocks") ~cache_size in - let* messages = Messages.load mode ~path:(path "messages") ~cache_size in - let* inboxes = Inboxes.load mode ~path:(path "inboxes") ~cache_size in - let* commitments = Commitments.load mode ~path:(path "commitments") in - let* commitments_published_at_level = - Commitments_published_at_level.load - mode - ~path:(path "commitments_published_at_level") - in - let* l2_head = L2_head.load mode ~path:(path "l2_head") in - let* last_finalized_level = - Last_finalized_level.load mode ~path:(path "last_finalized_level") - in - let* levels_to_hashes = - Levels_to_hashes.load mode ~path:(path "levels_to_hashes") - in - let+ irmin_store = Irmin_store.load mode (path "irmin_store") in - { - l2_blocks; - messages; - inboxes; - commitments; - commitments_published_at_level; - l2_head; - last_finalized_level; - levels_to_hashes; - irmin_store; - } - -let iter_l2_blocks ({l2_blocks; l2_head; _} : _ t) f = - let open Lwt_result_syntax in - let* head = L2_head.read l2_head in - match head with - | None -> - (* No reachable head, nothing to do *) - return_unit - | Some head -> - let rec loop hash = - let* block = L2_blocks.read l2_blocks hash in - match block with - | None -> - (* The block does not exist, the known chain stops here, so do we. *) - return_unit - | Some (block, header) -> - let* () = f {block with header} in - loop header.predecessor - in - loop head.header.block_hash diff --git a/src/proto_016_PtMumbai/lib_sc_rollup_node/store_v0.mli b/src/proto_016_PtMumbai/lib_sc_rollup_node/store_v0.mli deleted file mode 100644 index f2d9a002d6c1d6bf8000a7e5eb4ead8a11bf9894..0000000000000000000000000000000000000000 --- a/src/proto_016_PtMumbai/lib_sc_rollup_node/store_v0.mli +++ /dev/null @@ -1,164 +0,0 @@ -(*****************************************************************************) -(* *) -(* Open Source License *) -(* Copyright (c) 2022 Nomadic Labs, *) -(* Copyright (c) 2023 Functori, *) -(* *) -(* 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. *) -(* *) -(*****************************************************************************) - -(** This version of the store is used for the rollup nodes for protocol Mumbai, - i.e. = 16. - - This interface is a copy of - [src/proto_016_PtMumbai/lib_sc_rollup_node/store.mli], which contains the - layout for the Mumbai rollup node. -*) - -open Protocol -open Alpha_context -open Indexed_store - -module Irmin_store : sig - include module type of Irmin_store.Make (struct - let name = "Tezos smart rollup node" - end) - - include Store_sigs.Store with type 'a t := 'a t -end - -module L2_blocks : - INDEXED_FILE - with type key := Block_hash.t - and type value := (unit, unit) Sc_rollup_block.block - and type header := Sc_rollup_block.header - -(** Storage for persisting messages downloaded from the L1 node. *) -module Messages : - INDEXED_FILE - with type key := Sc_rollup.Inbox_merkelized_payload_hashes.Hash.t - and type value := Sc_rollup.Inbox_message.t list - and type header := Block_hash.t * Timestamp.t * int - -(** Aggregated collection of messages from the L1 inbox *) -module Inboxes : - SIMPLE_INDEXED_FILE - with type key := Sc_rollup.Inbox.Hash.t - and type value := Sc_rollup.Inbox.t - and type header := unit - -(** Storage containing commitments and corresponding commitment hashes that the - rollup node has knowledge of. *) -module Commitments : - INDEXABLE_STORE - with type key := Sc_rollup.Commitment.Hash.t - and type value := Sc_rollup.Commitment.t - -(** Storage mapping commitment hashes to the level when they were published by - the rollup node. It only contains hashes of commitments published by this - rollup node. *) -module Commitments_published_at_level : sig - type element = { - first_published_at_level : Raw_level.t; - (** The level at which this commitment was first published. *) - published_at_level : Raw_level.t option; - (** The level at which we published this commitment. If - [first_published_at_level <> published_at_level] it means that the - commitment is republished. *) - } - - include - INDEXABLE_STORE - with type key := Sc_rollup.Commitment.Hash.t - and type value := element -end - -module L2_head : SINGLETON_STORE with type value := Sc_rollup_block.t - -module Last_finalized_level : SINGLETON_STORE with type value := int32 - -module Levels_to_hashes : - INDEXABLE_STORE with type key := int32 and type value := Block_hash.t - -(** Published slot headers per block hash, - stored as a list of bindings from [Dal_slot_index.t] - to [Dal.Slot.t]. The encoding function converts this - list into a [Dal.Slot_index.t]-indexed map. *) -module Dal_slots_headers : - Store_sigs.Nested_map - with type primary_key := Block_hash.t - and type secondary_key := Dal.Slot_index.t - and type value := Dal.Slot.Header.t - and type 'a store := 'a Irmin_store.t - -module Dal_confirmed_slots_history : - Store_sigs.Append_only_map - with type key := Block_hash.t - and type value := Dal.Slots_history.t - and type 'a store := 'a Irmin_store.t - -(** Confirmed DAL slots histories cache. See documentation of - {!Dal_slot_repr.Slots_history} for more details. *) -module Dal_confirmed_slots_histories : - Store_sigs.Append_only_map - with type key := Block_hash.t - and type value := Dal.Slots_history.History_cache.t - and type 'a store := 'a Irmin_store.t - -(** [Dal_slot_pages] is a [Store_utils.Nested_map] used to store the contents - of dal slots fetched by the rollup node, as a list of pages. The values of - this storage module have type `string list`. A value of the form - [page_contents] refers to a page of a slot that has been confirmed, and - whose contents are [page_contents]. -*) -module Dal_slot_pages : - Store_sigs.Nested_map - with type primary_key := Block_hash.t - and type secondary_key := Dal.Slot_index.t * Dal.Page.Index.t - and type value := Dal.Page.content - and type 'a store := 'a Irmin_store.t - -(** [Dal_processed_slots] is a [Store_utils.Nested_map] used to store the processing - status of dal slots content fetched by the rollup node. The values of - this storage module have type `[`Confirmed | `Unconfirmed]`, depending on - whether the content of the slot has been confirmed or not. If an entry is - not present for a [(block_hash, slot_index)], this either means that it's - not processed yet. -*) -module Dal_processed_slots : - Store_sigs.Nested_map - with type primary_key := Block_hash.t - and type secondary_key := Dal.Slot_index.t - and type value := [`Confirmed | `Unconfirmed] - and type 'a store := 'a Irmin_store.t - -type +'a store = { - l2_blocks : 'a L2_blocks.t; - messages : 'a Messages.t; - inboxes : 'a Inboxes.t; - commitments : 'a Commitments.t; - commitments_published_at_level : 'a Commitments_published_at_level.t; - l2_head : 'a L2_head.t; - last_finalized_level : 'a Last_finalized_level.t; - levels_to_hashes : 'a Levels_to_hashes.t; - irmin_store : 'a Irmin_store.t; -} - -include Store_sig.S with type 'a store := 'a store diff --git a/src/proto_016_PtMumbai/lib_sc_rollup_node/store_v1.ml b/src/proto_016_PtMumbai/lib_sc_rollup_node/store_v1.ml deleted file mode 100644 index adecbb8a2b5b62a821ecfa369413cf481e2e5348..0000000000000000000000000000000000000000 --- a/src/proto_016_PtMumbai/lib_sc_rollup_node/store_v1.ml +++ /dev/null @@ -1,253 +0,0 @@ -(*****************************************************************************) -(* *) -(* Open Source License *) -(* Copyright (c) 2021 Nomadic Labs, *) -(* Copyright (c) 2023 Functori, *) -(* *) -(* 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. *) -(* *) -(*****************************************************************************) - -open Protocol -open Alpha_context -include Store_sigs -include Store_utils -include Store_v0 - -let version = Store_version.V1 - -module Make_hash_index_key (H : Environment.S.HASH) = -Indexed_store.Make_index_key (struct - include Indexed_store.Make_fixed_encodable (H) - - let equal = H.equal -end) - -(** Unaggregated messages per block *) -module Messages = - Indexed_store.Make_indexed_file - (struct - let name = "messages" - end) - (Make_hash_index_key (Sc_rollup.Inbox_merkelized_payload_hashes.Hash)) - (struct - type t = Sc_rollup.Inbox_message.t list - - let name = "messages_list" - - let encoding = - Data_encoding.(list @@ dynamic_size Sc_rollup.Inbox_message.encoding) - - module Header = struct - type t = bool * Block_hash.t * Timestamp.t * int - - let name = "messages_inbox_info" - - let encoding = - let open Data_encoding in - obj4 - (req "is_first_block" bool) - (req "predecessor" Block_hash.encoding) - (req "predecessor_timestamp" Timestamp.encoding) - (req "num_messages" int31) - - let fixed_size = - WithExceptions.Option.get ~loc:__LOC__ - @@ Data_encoding.Binary.fixed_length encoding - end - end) - -module Dal_pages = struct - type removed_in_v1 -end - -module Dal_processed_slots = struct - type removed_in_v1 -end - -(** Store attestation statuses for DAL slots on L1. *) -module Dal_slots_statuses = - Irmin_store.Make_nested_map - (struct - let path = ["dal"; "slots_statuses"] - end) - (struct - type key = Block_hash.t - - let to_path_representation = Block_hash.to_b58check - end) - (struct - type key = Dal.Slot_index.t - - let encoding = Dal.Slot_index.encoding - - let compare = Dal.Slot_index.compare - - let name = "slot_index" - end) - (struct - (* TODO: https://gitlab.com/tezos/tezos/-/issues/4780. - - Rename Confirm-ed/ation to Attest-ed/ation in the rollup node. *) - type value = [`Confirmed | `Unconfirmed] - - let name = "slot_status" - - let encoding = - (* We don't use - Data_encoding.string_enum because a union is more storage-efficient. *) - let open Data_encoding in - union - ~tag_size:`Uint8 - [ - case - ~title:"Confirmed" - (Tag 0) - (obj1 (req "kind" (constant "Confirmed"))) - (function `Confirmed -> Some () | `Unconfirmed -> None) - (fun () -> `Confirmed); - case - ~title:"Unconfirmed" - (Tag 1) - (obj1 (req "kind" (constant "Unconfirmed"))) - (function `Unconfirmed -> Some () | `Confirmed -> None) - (fun () -> `Unconfirmed); - ] - end) - -type nonrec 'a store = { - l2_blocks : 'a L2_blocks.t; - messages : 'a Messages.t; - inboxes : 'a Inboxes.t; - commitments : 'a Commitments.t; - commitments_published_at_level : 'a Commitments_published_at_level.t; - l2_head : 'a L2_head.t; - last_finalized_level : 'a Last_finalized_level.t; - levels_to_hashes : 'a Levels_to_hashes.t; - irmin_store : 'a Irmin_store.t; -} - -type 'a t = ([< `Read | `Write > `Read] as 'a) store - -type rw = Store_sigs.rw t - -type ro = Store_sigs.ro t - -let readonly - ({ - l2_blocks; - messages; - inboxes; - commitments; - commitments_published_at_level; - l2_head; - last_finalized_level; - levels_to_hashes; - irmin_store; - } : - _ t) : ro = - { - l2_blocks = L2_blocks.readonly l2_blocks; - messages = Messages.readonly messages; - inboxes = Inboxes.readonly inboxes; - commitments = Commitments.readonly commitments; - commitments_published_at_level = - Commitments_published_at_level.readonly commitments_published_at_level; - l2_head = L2_head.readonly l2_head; - last_finalized_level = Last_finalized_level.readonly last_finalized_level; - levels_to_hashes = Levels_to_hashes.readonly levels_to_hashes; - irmin_store = Irmin_store.readonly irmin_store; - } - -let close - ({ - l2_blocks; - messages; - inboxes; - commitments; - commitments_published_at_level; - l2_head = _; - last_finalized_level = _; - levels_to_hashes; - irmin_store; - } : - _ t) = - let open Lwt_result_syntax in - let+ () = L2_blocks.close l2_blocks - and+ () = Messages.close messages - and+ () = Inboxes.close inboxes - and+ () = Commitments.close commitments - and+ () = Commitments_published_at_level.close commitments_published_at_level - and+ () = Levels_to_hashes.close levels_to_hashes - and+ () = Irmin_store.close irmin_store in - () - -let load (type a) (mode : a mode) ~l2_blocks_cache_size data_dir : - a store tzresult Lwt.t = - let open Lwt_result_syntax in - let path name = Filename.concat data_dir name in - let cache_size = l2_blocks_cache_size in - let* l2_blocks = L2_blocks.load mode ~path:(path "l2_blocks") ~cache_size in - let* messages = Messages.load mode ~path:(path "messages") ~cache_size in - let* inboxes = Inboxes.load mode ~path:(path "inboxes") ~cache_size in - let* commitments = Commitments.load mode ~path:(path "commitments") in - let* commitments_published_at_level = - Commitments_published_at_level.load - mode - ~path:(path "commitments_published_at_level") - in - let* l2_head = L2_head.load mode ~path:(path "l2_head") in - let* last_finalized_level = - Last_finalized_level.load mode ~path:(path "last_finalized_level") - in - let* levels_to_hashes = - Levels_to_hashes.load mode ~path:(path "levels_to_hashes") - in - let+ irmin_store = Irmin_store.load mode (path "irmin_store") in - { - l2_blocks; - messages; - inboxes; - commitments; - commitments_published_at_level; - l2_head; - last_finalized_level; - levels_to_hashes; - irmin_store; - } - -let iter_l2_blocks ({l2_blocks; l2_head; _} : _ t) f = - let open Lwt_result_syntax in - let* head = L2_head.read l2_head in - match head with - | None -> - (* No reachable head, nothing to do *) - return_unit - | Some head -> - let rec loop hash = - let* block = L2_blocks.read l2_blocks hash in - match block with - | None -> - (* The block does not exist, the known chain stops here, so do we. *) - return_unit - | Some (block, header) -> - let* () = f {block with header} in - loop header.predecessor - in - loop head.header.block_hash diff --git a/src/proto_016_PtMumbai/lib_sc_rollup_node/store_v1.mli b/src/proto_016_PtMumbai/lib_sc_rollup_node/store_v1.mli deleted file mode 100644 index 7662907121003367f4bdf443fb185008a1db33cc..0000000000000000000000000000000000000000 --- a/src/proto_016_PtMumbai/lib_sc_rollup_node/store_v1.mli +++ /dev/null @@ -1,79 +0,0 @@ -(*****************************************************************************) -(* *) -(* Open Source License *) -(* Copyright (c) 2022 Nomadic Labs, *) -(* Copyright (c) 2023 Functori, *) -(* *) -(* 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. *) -(* *) -(*****************************************************************************) - -(** This version of the store is used for the rollup nodes for protocols for and - after Nairobi, i.e. >= 17. *) - -open Protocol -open Alpha_context -open Indexed_store - -include module type of struct - include Store_v0 -end - -(** Storage for persisting messages downloaded from the L1 node. *) -module Messages : - INDEXED_FILE - with type key := Sc_rollup.Inbox_merkelized_payload_hashes.Hash.t - and type value := Sc_rollup.Inbox_message.t list - and type header := bool * Block_hash.t * Timestamp.t * int - -module Dal_pages : sig - type removed_in_v1 -end - -module Dal_processed_slots : sig - type removed_in_v1 -end - -(** [Dal_slots_statuses] is a [Store_utils.Nested_map] used to store the - attestation status of DAL slots. The values of this storage module have type - `[`Confirmed | `Unconfirmed]`, depending on whether the content of the slot - has been attested on L1 or not. If an entry is not present for a - [(block_hash, slot_index)], this means that the corresponding block is not - processed yet. -*) -module Dal_slots_statuses : - Store_sigs.Nested_map - with type primary_key := Block_hash.t - and type secondary_key := Dal.Slot_index.t - and type value := [`Confirmed | `Unconfirmed] - and type 'a store := 'a Irmin_store.t - -type +'a store = { - l2_blocks : 'a L2_blocks.t; - messages : 'a Messages.t; - inboxes : 'a Inboxes.t; - commitments : 'a Commitments.t; - commitments_published_at_level : 'a Commitments_published_at_level.t; - l2_head : 'a L2_head.t; - last_finalized_level : 'a Last_finalized_level.t; - levels_to_hashes : 'a Levels_to_hashes.t; - irmin_store : 'a Irmin_store.t; -} - -include Store_sig.S with type 'a store := 'a store diff --git a/src/proto_016_PtMumbai/lib_sc_rollup_node/store_v2.mli b/src/proto_016_PtMumbai/lib_sc_rollup_node/store_v2.mli deleted file mode 100644 index fb8e1bc4313f3031b7e63f1e50bb4bced2439170..0000000000000000000000000000000000000000 --- a/src/proto_016_PtMumbai/lib_sc_rollup_node/store_v2.mli +++ /dev/null @@ -1,94 +0,0 @@ -(*****************************************************************************) -(* *) -(* Open Source License *) -(* Copyright (c) 2022 Nomadic Labs, *) -(* Copyright (c) 2023 Functori, *) -(* *) -(* 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. *) -(* *) -(*****************************************************************************) - -(** This version of the store is used for the rollup nodes for protocols for and - after Nairobi, i.e. >= 17. *) - -open Protocol -open Alpha_context -open Indexed_store - -include module type of struct - include Store_v1 -end - -(** Storage for persisting messages downloaded from the L1 node. *) -module Messages : - INDEXED_FILE - with type key := Sc_rollup.Inbox_merkelized_payload_hashes.Hash.t - and type value := Sc_rollup.Inbox_message.t list - and type header := Block_hash.t - -(** Storage for persisting inboxes. *) -module Inboxes : - SIMPLE_INDEXED_FILE - with type key := Sc_rollup.Inbox.Hash.t - and type value := Sc_rollup.Inbox.t - and type header := unit - -(** Storage containing commitments and corresponding commitment hashes that the - rollup node has knowledge of. *) -module Commitments : - SIMPLE_INDEXED_FILE - with type key := Sc_rollup.Commitment.Hash.t - and type value := Sc_rollup.Commitment.t - and type header := unit - -module Protocols : sig - type level = First_known of int32 | Activation_level of int32 - - (** Each element of this type represents information we have about a Tezos - protocol regarding its activation. *) - type proto_info = { - level : level; - (** The level at which we have seen the protocol for the first time, - either because we saw its activation or because the first block we - saw (at the origination of the rollup) was from this protocol. *) - proto_level : int; - (** The protocol level, i.e. its number in the sequence of protocol - activations on the chain. *) - protocol : Protocol_hash.t; (** The protocol this information concerns. *) - } - - val proto_info_encoding : proto_info Data_encoding.t - - include SINGLETON_STORE with type value = proto_info list -end - -type +'a store = { - l2_blocks : 'a L2_blocks.t; - messages : 'a Messages.t; - inboxes : 'a Inboxes.t; - commitments : 'a Commitments.t; - commitments_published_at_level : 'a Commitments_published_at_level.t; - l2_head : 'a L2_head.t; - last_finalized_level : 'a Last_finalized_level.t; - levels_to_hashes : 'a Levels_to_hashes.t; - protocols : 'a Protocols.t; - irmin_store : 'a Irmin_store.t; -} - -include Store_sig.S with type 'a store := 'a store diff --git a/src/proto_016_PtMumbai/lib_sc_rollup_node/test/canary.ml b/src/proto_016_PtMumbai/lib_sc_rollup_node/test/canary.ml index 8ea34ee871d59ae07b7a971eb0259749f894edb9..ea4cfb044d4b22ecaa41ba85559efcb5bc5ffda6 100644 --- a/src/proto_016_PtMumbai/lib_sc_rollup_node/test/canary.ml +++ b/src/proto_016_PtMumbai/lib_sc_rollup_node/test/canary.ml @@ -31,6 +31,7 @@ Subject: Canary unit tests to make sure the test helpers work as intended *) +open Octez_smart_rollup open Protocol.Alpha_context let build_chain node_ctxt ~genesis ~length = @@ -55,9 +56,7 @@ let canary_test node_ctxt ~genesis = Node_context.get_l2_block node_ctxt block.header.block_hash in let* store_block_by_level = - Node_context.get_l2_block_by_level - node_ctxt - (Raw_level.to_int32 block.header.level) + Node_context.get_l2_block_by_level node_ctxt block.header.level in Helpers.Assert.L2_block.equal ~loc:__LOC__ diff --git a/src/proto_016_PtMumbai/lib_sc_rollup_node/test/helpers/helpers.ml b/src/proto_016_PtMumbai/lib_sc_rollup_node/test/helpers/helpers.ml index 1af610d1f524e8b2e6443ce5c901244fc456b54c..32b4f107f6dd37f92bcf4fea97584bc8d773b71c 100644 --- a/src/proto_016_PtMumbai/lib_sc_rollup_node/test/helpers/helpers.ml +++ b/src/proto_016_PtMumbai/lib_sc_rollup_node/test/helpers/helpers.ml @@ -23,6 +23,7 @@ (* *) (*****************************************************************************) +open Octez_smart_rollup open Protocol open Alpha_context @@ -84,12 +85,22 @@ let add_l2_genesis_block (node_ctxt : _ Node_context.t) ~boot_sector = ~genesis_state_hash in let* commitment_hash = Node_context.save_commitment node_ctxt commitment in - let previous_commitment_hash = node_ctxt.genesis_info.commitment_hash in + let previous_commitment_hash = + node_ctxt.genesis_info.commitment_hash + |> Sc_rollup_proto_types.Commitment_hash.to_octez + in + let commitment_hash = + Sc_rollup_proto_types.Commitment_hash.to_octez commitment_hash + in + let inbox_witness = + Sc_rollup_proto_types.Merkelized_payload_hashes_hash.to_octez inbox_witness + in + let inbox_hash = Sc_rollup_proto_types.Inbox_hash.to_octez inbox_hash in let header = Sc_rollup_block. { block_hash = head.hash; - level = node_ctxt.genesis_info.level; + level = Raw_level.to_int32 node_ctxt.genesis_info.level; predecessor = predecessor.hash; commitment_hash = Some commitment_hash; previous_commitment_hash; @@ -99,7 +110,13 @@ let add_l2_genesis_block (node_ctxt : _ Node_context.t) ~boot_sector = } in let l2_block = - Sc_rollup_block.{header; content = (); num_ticks; initial_tick} + Sc_rollup_block. + { + header; + content = (); + num_ticks; + initial_tick = Sc_rollup.Tick.to_z initial_tick; + } in let* () = Node_context.save_l2_head node_ctxt l2_block in return l2_block @@ -136,6 +153,7 @@ let initialize_node_context ?(constants = default_constants) kind ~boot_sector = let* genesis = add_l2_genesis_block ctxt ~boot_sector in let commitment_hash = WithExceptions.Option.get ~loc:__LOC__ genesis.header.commitment_hash + |> Sc_rollup_proto_types.Commitment_hash.of_octez in let ctxt = {ctxt with genesis_info = {ctxt.genesis_info with commitment_hash}} @@ -182,7 +200,7 @@ let append_l2_block (node_ctxt : _ Node_context.t) messages = | None -> failwith "No genesis block, please add one with add_l2_genesis_block" in - let pred_level = Raw_level.to_int32 predecessor_l2_block.header.level in + let pred_level = predecessor_l2_block.header.level in let predecessor = head_of_level ~predecessor:predecessor_l2_block.header.predecessor @@ -204,9 +222,7 @@ let append_dummy_l2_chain node_ctxt ~length = let open Lwt_result_syntax in let* head = Node_context.last_processed_head_opt node_ctxt in let head_level = - match head with - | None -> 0 - | Some h -> h.header.level |> Raw_level.to_int32 |> Int32.to_int + match head with None -> 0 | Some h -> h.header.level |> Int32.to_int in let batches = Stdlib.List.init length (fun i -> diff --git a/src/proto_016_PtMumbai/lib_sc_rollup_node/test/helpers/helpers.mli b/src/proto_016_PtMumbai/lib_sc_rollup_node/test/helpers/helpers.mli index 04b986c0394cfeee62f8c01e74ad83457863ecc5..1fc9332c2e92e2e864e7163b2804698aa30157a0 100644 --- a/src/proto_016_PtMumbai/lib_sc_rollup_node/test/helpers/helpers.mli +++ b/src/proto_016_PtMumbai/lib_sc_rollup_node/test/helpers/helpers.mli @@ -23,6 +23,7 @@ (* *) (*****************************************************************************) +open Octez_smart_rollup open Protocol open Alpha_context diff --git a/src/proto_016_PtMumbai/lib_sc_rollup_node/test/test_octez_conversions.ml b/src/proto_016_PtMumbai/lib_sc_rollup_node/test/test_octez_conversions.ml index e52dff8a73d0634ef3a2aa556bff91b0373576fa..28807a286f9bf750edfb9105c369093fb3184d94 100644 --- a/src/proto_016_PtMumbai/lib_sc_rollup_node/test/test_octez_conversions.ml +++ b/src/proto_016_PtMumbai/lib_sc_rollup_node/test/test_octez_conversions.ml @@ -188,6 +188,67 @@ let gen_inbox = | Error e -> Stdlib.failwith (Format.asprintf "%a" Error_monad.pp_print_trace e)) +let gen_slot_index = + let open QCheck2.Gen in + graft_corners (int_bound 0xff) [0; 1; 2; 0xff] () + +let gen_page_index = + let open QCheck2.Gen in + let max = 0xfff / 2 in + graft_corners (int_bound max) [0; 1; 2; max] () + +let gen_slot_header_commitment = + let open QCheck2.Gen in + make_primitive + ~gen:(fun state -> + Tezos_crypto_dal.Cryptobox.Internal_for_tests.dummy_commitment ~state ()) + ~shrink:(fun _ -> Seq.empty) + +let gen_slot_header = + let open QCheck2.Gen in + let* published_level = gen_level in + let* index = gen_slot_index in + let+ commitment = gen_slot_header_commitment in + Octez_smart_rollup.Dal.Slot_header.{id = {published_level; index}; commitment} + +let compare_slot_header_id (s1 : Octez_smart_rollup.Dal.Slot_header.id) + (s2 : Octez_smart_rollup.Dal.Slot_header.id) = + let c = Int32.compare s1.published_level s2.published_level in + if c <> 0 then c else Int.compare s1.index s2.index + +let gen_slot_headers = + let open QCheck2.Gen in + let size = int_bound 50 in + let+ l = list_size size gen_slot_header in + List.sort + (fun (h1 : Octez_smart_rollup.Dal.Slot_header.t) + (h2 : Octez_smart_rollup.Dal.Slot_header.t) -> + compare_slot_header_id h1.id h2.id) + l + +let gen_slot_history = + let open Protocol.Alpha_context in + let open QCheck2.Gen in + let h = Dal.Slots_history.genesis in + let+ l = gen_slot_headers in + let l = List.map Sc_rollup_proto_types.Dal.Slot_header.of_octez l in + Dal.Slots_history.add_confirmed_slot_headers_no_cache h l |> function + | Error e -> + Stdlib.failwith (Format.asprintf "%a" Environment.Error_monad.pp_trace e) + | Ok v -> Sc_rollup_proto_types.Dal.Slot_history.to_octez v + +let gen_slot_history_cache = + let open Protocol.Alpha_context in + let open QCheck2.Gen in + let h = Dal.Slots_history.genesis in + let c = Dal.Slots_history.History_cache.empty ~capacity:Int64.max_int in + let+ l = gen_slot_headers in + let l = List.map Sc_rollup_proto_types.Dal.Slot_header.of_octez l in + Dal.Slots_history.add_confirmed_slot_headers h c l |> function + | Error e -> + Stdlib.failwith (Format.asprintf "%a" Environment.Error_monad.pp_trace e) + | Ok (_, c) -> Sc_rollup_proto_types.Dal.Slot_history_cache.to_octez c + let test_roundtrip ~count name gen to_octez from_octez octez_encoding proto_encoding = let test octez1 = @@ -305,6 +366,56 @@ let test_inbox = Octez_smart_rollup.Inbox.encoding Protocol.Alpha_context.Sc_rollup.Inbox.encoding +let test_slot_index = + test_roundtrip + ~count:100 + "dal_slot_index" + gen_slot_index + Sc_rollup_proto_types.Dal.Slot_index.to_octez + Sc_rollup_proto_types.Dal.Slot_index.of_octez + Octez_smart_rollup.Dal.Slot_index.encoding + Protocol.Alpha_context.Dal.Slot_index.encoding + +let test_page_index = + test_roundtrip + ~count:100 + "dal_page_index" + gen_page_index + Sc_rollup_proto_types.Dal.Page_index.to_octez + Sc_rollup_proto_types.Dal.Page_index.of_octez + Octez_smart_rollup.Dal.Page_index.encoding + Protocol.Alpha_context.Dal.Page.Index.encoding + +let test_slot_header = + test_roundtrip + ~count:1000 + "dal_slot_header" + gen_slot_header + Sc_rollup_proto_types.Dal.Slot_header.to_octez + Sc_rollup_proto_types.Dal.Slot_header.of_octez + Octez_smart_rollup.Dal.Slot_header.encoding + Protocol.Alpha_context.Dal.Slot.Header.encoding + +let test_slot_history = + test_roundtrip + ~count:300 + "dal_slot_history" + gen_slot_history + Sc_rollup_proto_types.Dal.Slot_history.to_octez + Sc_rollup_proto_types.Dal.Slot_history.of_octez + Octez_smart_rollup.Dal.Slot_history.encoding + Protocol.Alpha_context.Dal.Slots_history.encoding + +let test_slot_history_cache = + test_roundtrip + ~count:300 + "dal_slot_history_cache" + gen_slot_history_cache + Sc_rollup_proto_types.Dal.Slot_history_cache.to_octez + Sc_rollup_proto_types.Dal.Slot_history_cache.of_octez + Octez_smart_rollup.Dal.Slot_history_cache.encoding + Protocol.Alpha_context.Dal.Slots_history.History_cache.encoding + let tests = [ test_address; @@ -315,6 +426,11 @@ let tests = test_stakers; test_refutation; test_inbox; + test_slot_index; + test_page_index; + test_slot_header; + test_slot_history; + test_slot_history_cache; ] let () = diff --git a/src/proto_017_PtNairob/lib_sc_rollup_layer2/sc_rollup_block.ml b/src/proto_017_PtNairob/lib_sc_rollup_layer2/sc_rollup_block.ml deleted file mode 100644 index a5c25b817f13899df8a2c5aa8b30c30c78e21aac..0000000000000000000000000000000000000000 --- a/src/proto_017_PtNairob/lib_sc_rollup_layer2/sc_rollup_block.ml +++ /dev/null @@ -1,199 +0,0 @@ -(*****************************************************************************) -(* *) -(* 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. *) -(* *) -(*****************************************************************************) - -open Protocol -open Alpha_context - -type header = { - block_hash : Block_hash.t; - level : Raw_level.t; - predecessor : Block_hash.t; - commitment_hash : Sc_rollup.Commitment.Hash.t option; - previous_commitment_hash : Sc_rollup.Commitment.Hash.t; - context : Smart_rollup_context_hash.t; - inbox_witness : Sc_rollup.Inbox_merkelized_payload_hashes.Hash.t; - inbox_hash : Sc_rollup.Inbox.Hash.t; -} - -type content = { - inbox : Sc_rollup.Inbox.t; - messages : Sc_rollup.Inbox_message.t list; - commitment : Sc_rollup.Commitment.t option; -} - -type ('header, 'content) block = { - header : 'header; - content : 'content; - initial_tick : Sc_rollup.Tick.t; - num_ticks : int64; -} - -type t = (header, unit) block - -type full = (header, content) block - -let commitment_hash_opt_encoding = - let open Data_encoding in - let binary = - conv - (Option.value ~default:Sc_rollup.Commitment.Hash.zero) - (fun h -> if Sc_rollup.Commitment.Hash.(h = zero) then None else Some h) - Sc_rollup.Commitment.Hash.encoding - in - let json = option Sc_rollup.Commitment.Hash.encoding in - splitted ~binary ~json - -let header_encoding = - let open Data_encoding in - conv - (fun { - block_hash; - level; - predecessor; - commitment_hash; - previous_commitment_hash; - context; - inbox_witness; - inbox_hash; - } -> - ( block_hash, - level, - predecessor, - commitment_hash, - previous_commitment_hash, - context, - inbox_witness, - inbox_hash )) - (fun ( block_hash, - level, - predecessor, - commitment_hash, - previous_commitment_hash, - context, - inbox_witness, - inbox_hash ) -> - { - block_hash; - level; - predecessor; - commitment_hash; - previous_commitment_hash; - context; - inbox_witness; - inbox_hash; - }) - @@ obj8 - (req "block_hash" Block_hash.encoding ~description:"Tezos block hash.") - (req - "level" - Raw_level.encoding - ~description: - "Level of the block, corresponds to the level of the tezos block.") - (req - "predecessor" - Block_hash.encoding - ~description:"Predecessor hash of the Tezos block.") - (req - "commitment_hash" - commitment_hash_opt_encoding - ~description: - "Hash of this block's commitment if any was computed for it.") - (req - "previous_commitment_hash" - Sc_rollup.Commitment.Hash.encoding - ~description: - "Previous commitment hash in the chain. If there is a commitment \ - for this block, this field contains the commitment that was \ - previously computed.") - (req - "context" - Smart_rollup_context_hash.encoding - ~description:"Hash of the layer 2 context for this block.") - (req - "inbox_witness" - Sc_rollup.Inbox_merkelized_payload_hashes.Hash.encoding - ~description: - "Witness for the inbox for this block, i.e. the Merkle hash of \ - payloads of messages.") - (req - "inbox_hash" - Sc_rollup.Inbox.Hash.encoding - ~description:"Hash of the inbox for this block.") - -let header_size = - WithExceptions.Option.get ~loc:__LOC__ - @@ Data_encoding.Binary.fixed_length header_encoding - -let content_encoding = - let open Data_encoding in - conv - (fun {inbox; messages; commitment} -> (inbox, messages, commitment)) - (fun (inbox, messages, commitment) -> {inbox; messages; commitment}) - @@ obj3 - (req - "inbox" - Sc_rollup.Inbox.encoding - ~description:"Inbox for this block.") - (req - "messages" - (list (dynamic_size Sc_rollup.Inbox_message.encoding)) - ~description:"Messages added to the inbox in this block.") - (opt - "commitment" - Sc_rollup.Commitment.encoding - ~description:"Commitment, if any is computed for this block.") - -let block_encoding header_encoding content_encoding = - let open Data_encoding in - conv - (fun {header; content; initial_tick; num_ticks} -> - (header, (content, (initial_tick, num_ticks)))) - (fun (header, (content, (initial_tick, num_ticks))) -> - {header; content; initial_tick; num_ticks}) - @@ merge_objs header_encoding - @@ merge_objs content_encoding - @@ obj2 - (req - "initial_tick" - Sc_rollup.Tick.encoding - ~description: - "Initial tick of the PVM at this block, i.e. before evaluation of \ - the messages.") - (req - "num_ticks" - int64 - ~description: - "Number of ticks produced by the evaluation of the messages in \ - this block.") - -let encoding = block_encoding header_encoding Data_encoding.unit - -let full_encoding = block_encoding header_encoding content_encoding - -let most_recent_commitment (header : header) = - Option.value header.commitment_hash ~default:header.previous_commitment_hash - -let final_tick {initial_tick; num_ticks; _} = - Sc_rollup.Tick.jump initial_tick (Z.of_int64 num_ticks) diff --git a/src/proto_017_PtNairob/lib_sc_rollup_layer2/sc_rollup_proto_types.ml b/src/proto_017_PtNairob/lib_sc_rollup_layer2/sc_rollup_proto_types.ml index c8c63b27718fc46976f70ebdfdab7f4a0e7160aa..e8c04d28ba95600bf8e40c65d7ebcbe8bdddcd72 100644 --- a/src/proto_017_PtNairob/lib_sc_rollup_layer2/sc_rollup_proto_types.ml +++ b/src/proto_017_PtNairob/lib_sc_rollup_layer2/sc_rollup_proto_types.ml @@ -251,3 +251,88 @@ module Kind = struct | Example_arith -> Example_arith | Wasm_2_0_0 -> Wasm_2_0_0 end + +module Dal = struct + module Slot_index = struct + type t = Dal.Slot_index.t + + let of_octez (i : Octez_smart_rollup.Dal.Slot_index.t) : t = + match Dal.Slot_index.of_int_opt i with + | None -> Format.ksprintf invalid_arg "Dal.Slot_index.of_octez: %d" i + | Some i -> i + + let to_octez : t -> Octez_smart_rollup.Dal.Slot_index.t = + Dal.Slot_index.to_int + end + + module Page_index = struct + type t = Dal.Page.Index.t + + let of_octez : Octez_smart_rollup.Dal.Page_index.t -> t = Fun.id + + let to_octez : t -> Octez_smart_rollup.Dal.Page_index.t = Fun.id + end + + module Slot_header = struct + type t = Dal.Slot.Header.t + + let of_octez + Octez_smart_rollup.Dal.Slot_header. + {id = {published_level; index}; commitment} : t = + Dal.Slot.Header. + { + id = + { + published_level = Raw_level.of_int32_exn published_level; + index = Slot_index.of_octez index; + }; + commitment; + } + + let to_octez Dal.Slot.Header.{id = {published_level; index}; commitment} : + Octez_smart_rollup.Dal.Slot_header.t = + Octez_smart_rollup.Dal.Slot_header. + { + id = + { + published_level = Raw_level.to_int32 published_level; + index = Slot_index.to_octez index; + }; + commitment; + } + end + + module Slot_history = struct + type t = Dal.Slots_history.t + + let of_octez (h : Octez_smart_rollup.Dal.Slot_history.t) : t = + h + |> Data_encoding.Binary.to_bytes_exn + Octez_smart_rollup.Dal.Slot_history.encoding + |> Data_encoding.Binary.of_bytes_exn Dal.Slots_history.encoding + + let to_octez (h : t) : Octez_smart_rollup.Dal.Slot_history.t = + h + |> Data_encoding.Binary.to_bytes_exn Dal.Slots_history.encoding + |> Data_encoding.Binary.of_bytes_exn + Octez_smart_rollup.Dal.Slot_history.encoding + end + + module Slot_history_cache = struct + type t = Dal.Slots_history.History_cache.t + + let of_octez (h : Octez_smart_rollup.Dal.Slot_history_cache.t) : t = + h + |> Data_encoding.Binary.to_bytes_exn + Octez_smart_rollup.Dal.Slot_history_cache.encoding + |> Data_encoding.Binary.of_bytes_exn + Dal.Slots_history.History_cache.encoding + + let to_octez (h : t) : Octez_smart_rollup.Dal.Slot_history_cache.t = + h + |> Data_encoding.Binary.to_bytes_exn + Dal.Slots_history.History_cache.encoding + |> Data_encoding.Binary.of_bytes_exn + Octez_smart_rollup.Dal.Slot_history_cache.encoding + end +end diff --git a/src/proto_017_PtNairob/lib_sc_rollup_layer2/sc_rollup_proto_types.mli b/src/proto_017_PtNairob/lib_sc_rollup_layer2/sc_rollup_proto_types.mli index d24bfcd9c6ee4dc4015473e5eab5a3561de48a10..905a7b7bde6dc484c26a08fdd5f47eaf8d4c951b 100644 --- a/src/proto_017_PtNairob/lib_sc_rollup_layer2/sc_rollup_proto_types.mli +++ b/src/proto_017_PtNairob/lib_sc_rollup_layer2/sc_rollup_proto_types.mli @@ -116,3 +116,45 @@ module Kind : sig val to_octez : t -> Octez_smart_rollup.Kind.t end + +module Dal : sig + module Slot_index : sig + type t = Dal.Slot_index.t + + val of_octez : Octez_smart_rollup.Dal.Slot_index.t -> t + + val to_octez : t -> Octez_smart_rollup.Dal.Slot_index.t + end + + module Page_index : sig + type t = Dal.Page.Index.t + + val of_octez : Octez_smart_rollup.Dal.Page_index.t -> t + + val to_octez : t -> Octez_smart_rollup.Dal.Page_index.t + end + + module Slot_header : sig + type t = Dal.Slot.Header.t + + val of_octez : Octez_smart_rollup.Dal.Slot_header.t -> t + + val to_octez : t -> Octez_smart_rollup.Dal.Slot_header.t + end + + module Slot_history : sig + type t = Dal.Slots_history.t + + val of_octez : Octez_smart_rollup.Dal.Slot_history.t -> t + + val to_octez : t -> Octez_smart_rollup.Dal.Slot_history.t + end + + module Slot_history_cache : sig + type t = Dal.Slots_history.History_cache.t + + val of_octez : Octez_smart_rollup.Dal.Slot_history_cache.t -> t + + val to_octez : t -> Octez_smart_rollup.Dal.Slot_history_cache.t + end +end diff --git a/src/proto_017_PtNairob/lib_sc_rollup_layer2/sc_rollup_services.ml b/src/proto_017_PtNairob/lib_sc_rollup_layer2/sc_rollup_services.ml index a6da8d1c06b43ad25be75fda95a3bfafe1ab104c..62664a971c3a37a5e7bca2e095468d650bbf3d6a 100644 --- a/src/proto_017_PtNairob/lib_sc_rollup_layer2/sc_rollup_services.ml +++ b/src/proto_017_PtNairob/lib_sc_rollup_layer2/sc_rollup_services.ml @@ -100,8 +100,8 @@ type message_status = cemented : bool; commitment : Sc_rollup.Commitment.t; commitment_hash : Sc_rollup.Commitment.Hash.t; - first_published_at_level : Raw_level.t; - published_at_level : Raw_level.t; + first_published_at_level : int32; + published_at_level : int32; } module Encodings = struct @@ -116,8 +116,8 @@ module Encodings = struct obj4 (req "commitment" Sc_rollup.Commitment.encoding) (req "hash" Sc_rollup.Commitment.Hash.encoding) - (opt "first_published_at_level" Raw_level.encoding) - (opt "published_at_level" Raw_level.encoding) + (opt "first_published_at_level" int32) + (opt "published_at_level" int32) let hex_string = conv Bytes.of_string Bytes.to_string bytes @@ -322,8 +322,8 @@ module Encodings = struct (req "cemented" bool) (req "commitment" Sc_rollup.Commitment.encoding) (req "hash" Sc_rollup.Commitment.Hash.encoding) - (req "first_published_at_level" Raw_level.encoding) - (req "published_at_level" Raw_level.encoding)) + (req "first_published_at_level" int32) + (req "published_at_level" int32)) (function | Committed { diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/RPC_server.ml b/src/proto_017_PtNairob/lib_sc_rollup_node/RPC_server.ml index a78d121505ed60ad6265ff4a339e8a0428173aeb..6f049377dd2ba8ec9eeb7d6876646a1497c070c0 100644 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/RPC_server.ml +++ b/src/proto_017_PtNairob/lib_sc_rollup_node/RPC_server.ml @@ -39,10 +39,7 @@ let get_head_hash_opt node_ctxt = let get_head_level_opt node_ctxt = let open Lwt_result_syntax in let+ res = Node_context.last_processed_head_opt node_ctxt in - Option.map - (fun Sc_rollup_block.{header = {level; _}; _} -> - Alpha_context.Raw_level.to_int32 level) - res + Option.map (fun Sc_rollup_block.{header = {level; _}; _} -> level) res module Slot_pages_map = struct open Protocol @@ -125,7 +122,10 @@ module Common = struct let open Lwt_result_syntax in let* l2_block = Node_context.get_l2_block node_ctxt block in let+ num_messages = - Node_context.get_num_messages node_ctxt l2_block.header.inbox_witness + Node_context.get_num_messages + node_ctxt + (Sc_rollup_proto_types.Merkelized_payload_hashes_hash.of_octez + l2_block.header.inbox_witness) in Z.of_int num_messages @@ -272,6 +272,7 @@ let () = | Some head -> let commitment_hash = Sc_rollup_block.most_recent_commitment head.header + |> Sc_rollup_proto_types.Commitment_hash.of_octez in let+ commitment = Node_context.find_commitment node_ctxt commitment_hash @@ -460,6 +461,7 @@ let () = WithExceptions.Option.get ~loc:__LOC__ block.header.commitment_hash + |> Sc_rollup_proto_types.Commitment_hash.of_octez in (* Commitment computed *) let* published_at = diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/daemon.ml b/src/proto_017_PtNairob/lib_sc_rollup_node/daemon.ml index 1b5a066383515897e9e2142be0ca20a2c654fe49..87f777338e06f0f0f76082de5b94e1ee3f533dd9 100644 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/daemon.ml +++ b/src/proto_017_PtNairob/lib_sc_rollup_node/daemon.ml @@ -42,6 +42,7 @@ let is_refutable_commitment node_ctxt let* our_commitment_and_hash = Option.filter_map_es (fun hash -> + let hash = Sc_rollup_proto_types.Commitment_hash.of_octez hash in let+ commitment = Node_context.find_commitment node_ctxt hash in Option.map (fun c -> (c, hash)) commitment) l2_block.header.commitment_hash @@ -102,8 +103,8 @@ let process_included_l1_operation (type kind) (node_ctxt : Node_context.rw) node_ctxt commitment_hash { - first_published_at_level = published_at_level; - published_at_level = Some (Raw_level.of_int32_exn head.Layer1.level); + first_published_at_level = Raw_level.to_int32 published_at_level; + published_at_level = Some head.Layer1.level; } in let*! () = @@ -136,7 +137,8 @@ let process_included_l1_operation (type kind) (node_ctxt : Node_context.rw) node_ctxt their_commitment_hash { - first_published_at_level = published_at_level; + first_published_at_level = + Raw_level.to_int32 published_at_level; published_at_level = None; } in @@ -160,17 +162,18 @@ let process_included_l1_operation (type kind) (node_ctxt : Node_context.rw) in let*? () = (* We stop the node if we disagree with a cemented commitment *) + let our_commitment_hash = + Option.map + Sc_rollup_proto_types.Commitment_hash.of_octez + inbox_block.header.commitment_hash + in error_unless (Option.equal Sc_rollup.Commitment.Hash.( = ) - inbox_block.header.commitment_hash + our_commitment_hash (Some commitment_hash)) (Sc_rollup_node_errors.Disagree_with_cemented - { - inbox_level; - ours = inbox_block.header.commitment_hash; - on_l1 = commitment_hash; - }) + {inbox_level; ours = our_commitment_hash; on_l1 = commitment_hash}) in let lcc = Reference.get node_ctxt.lcc in let*! () = @@ -355,6 +358,11 @@ let rec process_head (daemon_components : (module Daemon_components.S)) let* inbox_hash, inbox, inbox_witness, messages = Inbox.process_head node_ctxt ~predecessor head in + let inbox_witness = + Sc_rollup_proto_types.Merkelized_payload_hashes_hash.to_octez + inbox_witness + in + let inbox_hash = Sc_rollup_proto_types.Inbox_hash.to_octez inbox_hash in let* () = when_ (Node_context.dal_supported node_ctxt) @@ fun () -> Dal_slots_tracker.process_head node_ctxt (Layer1.head_of_header head) @@ -375,6 +383,11 @@ let rec process_head (daemon_components : (module Daemon_components.S)) let* commitment_hash = Publisher.process_head node_ctxt ~predecessor:predecessor.hash head ctxt in + let commitment_hash = + Option.map + Sc_rollup_proto_types.Commitment_hash.to_octez + commitment_hash + in let* () = unless (catching_up && Option.is_none commitment_hash) @@ fun () -> Inbox.same_as_layer_1 node_ctxt head.hash inbox @@ -383,7 +396,9 @@ let rec process_head (daemon_components : (module Daemon_components.S)) let* previous_commitment_hash = if level = node_ctxt.genesis_info.Sc_rollup.Commitment.level then (* Previous commitment for rollup genesis is itself. *) - return node_ctxt.genesis_info.Sc_rollup.Commitment.commitment_hash + return + (Sc_rollup_proto_types.Commitment_hash.to_octez + node_ctxt.genesis_info.Sc_rollup.Commitment.commitment_hash) else let+ pred = Node_context.get_l2_block node_ctxt predecessor.hash in Sc_rollup_block.most_recent_commitment pred.header @@ -392,7 +407,7 @@ let rec process_head (daemon_components : (module Daemon_components.S)) Sc_rollup_block. { block_hash = head.hash; - level; + level = head.level; predecessor = predecessor.hash; commitment_hash; previous_commitment_hash; @@ -402,7 +417,13 @@ let rec process_head (daemon_components : (module Daemon_components.S)) } in let l2_block = - Sc_rollup_block.{header; content = (); num_ticks; initial_tick} + Sc_rollup_block. + { + header; + content = (); + num_ticks; + initial_tick = Sc_rollup.Tick.to_z initial_tick; + } in let* () = Node_context.mark_finalized_level @@ -427,12 +448,7 @@ let on_layer_1_head (daemon_components : (module Daemon_components.S)) node_ctxt let old_head = match old_head with | Some h -> - `Head - Layer1. - { - hash = h.header.block_hash; - level = Raw_level.to_int32 h.header.level; - } + `Head Layer1.{hash = h.header.block_hash; level = h.header.level} | None -> (* if no head has been processed yet, we want to handle all blocks since, and including, the rollup origination. *) @@ -664,6 +680,11 @@ module Internal_for_tests = struct head messages in + let inbox_witness = + Sc_rollup_proto_types.Merkelized_payload_hashes_hash.to_octez + inbox_witness + in + let inbox_hash = Sc_rollup_proto_types.Inbox_hash.to_octez inbox_hash in let* ctxt, _num_messages, num_ticks, initial_tick = Interpreter.process_head node_ctxt ctxt ~predecessor head (inbox, messages) in @@ -675,11 +696,16 @@ module Internal_for_tests = struct head ctxt in + let commitment_hash = + Option.map Sc_rollup_proto_types.Commitment_hash.to_octez commitment_hash + in let level = Raw_level.of_int32_exn head.level in let* previous_commitment_hash = if level = node_ctxt.genesis_info.Sc_rollup.Commitment.level then (* Previous commitment for rollup genesis is itself. *) - return node_ctxt.genesis_info.Sc_rollup.Commitment.commitment_hash + return + (Sc_rollup_proto_types.Commitment_hash.to_octez + node_ctxt.genesis_info.Sc_rollup.Commitment.commitment_hash) else let+ pred = Node_context.get_l2_block node_ctxt predecessor.hash in Sc_rollup_block.most_recent_commitment pred.header @@ -688,7 +714,7 @@ module Internal_for_tests = struct Sc_rollup_block. { block_hash = head.hash; - level; + level = head.level; predecessor = predecessor.hash; commitment_hash; previous_commitment_hash; @@ -698,7 +724,13 @@ module Internal_for_tests = struct } in let l2_block = - Sc_rollup_block.{header; content = (); num_ticks; initial_tick} + Sc_rollup_block. + { + header; + content = (); + num_ticks; + initial_tick = Sc_rollup.Tick.to_z initial_tick; + } in let* () = Node_context.save_l2_head node_ctxt l2_block in return l2_block diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/interpreter.ml b/src/proto_017_PtNairob/lib_sc_rollup_node/interpreter.ml index a7501fe0e3cd122c86e8cd579beaf8d074d25c42..5e00fc32543f5547fbc56f20f02104f2e89fd0aa 100644 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/interpreter.ml +++ b/src/proto_017_PtNairob/lib_sc_rollup_node/interpreter.ml @@ -150,7 +150,7 @@ let process_head (node_ctxt : _ Node_context.t) ctxt the messages the block ([remaining_messages]). *) let start_state_of_block node_ctxt (block : Sc_rollup_block.t) = let open Lwt_result_syntax in - let pred_level = Raw_level.to_int32 block.header.level |> Int32.pred in + let pred_level = Int32.pred block.header.level in let* ctxt = Node_context.checkout_context node_ctxt block.header.predecessor in @@ -160,9 +160,16 @@ let start_state_of_block node_ctxt (block : Sc_rollup_block.t) = ctxt Layer1.{hash = block.header.predecessor; level = pred_level} in - let* inbox = Node_context.get_inbox node_ctxt block.header.inbox_hash in + let* inbox = + Node_context.get_inbox + node_ctxt + (Sc_rollup_proto_types.Inbox_hash.of_octez block.header.inbox_hash) + in let* {is_first_block; predecessor; predecessor_timestamp; messages} = - Node_context.get_messages node_ctxt block.header.inbox_witness + Node_context.get_messages + node_ctxt + (Sc_rollup_proto_types.Merkelized_payload_hashes_hash.of_octez + block.header.inbox_witness) in let inbox_level = Sc_rollup.Inbox.inbox_level inbox in let module PVM = (val node_ctxt.pvm) in @@ -215,9 +222,8 @@ let state_of_tick_aux node_ctxt ~start_state (event : Sc_rollup_block.t) tick = let* start_state = match start_state with | Some start_state - when Raw_level.( - start_state.Fueled_pvm.Accounted.inbox_level = event.header.level) - -> + when Raw_level.to_int32 start_state.Fueled_pvm.Accounted.inbox_level + = event.header.level -> return start_state | _ -> (* Recompute start state on level change or if we don't have a @@ -266,7 +272,7 @@ let state_of_tick node_ctxt ?start_state tick level = match event with | None -> return_none | Some event -> - assert (Raw_level.(event.header.level <= level)) ; + assert (event.header.level <= Raw_level.to_int32 level) ; let* result_state = if Node_context.is_loser node_ctxt then (* TODO: https://gitlab.com/tezos/tezos/-/issues/5253 diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/node_context.ml b/src/proto_017_PtNairob/lib_sc_rollup_node/node_context.ml index cec116c42af0ac46c7e1f6c8362d8133006b261e..a40d1cec8df3bf4fd452c506c4ea9ed1e96cbaf9 100644 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/node_context.ml +++ b/src/proto_017_PtNairob/lib_sc_rollup_node/node_context.ml @@ -460,7 +460,7 @@ let level_of_hash {l1_ctxt; store; _} hash = let open Lwt_result_syntax in let* l2_header = Store.L2_blocks.header store.l2_blocks hash in match l2_header with - | Some {level; _} -> return (Raw_level.to_int32 level) + | Some {level; _} -> return level | None -> let+ {level; _} = Layer1.fetch_tezos_shell_header l1_ctxt hash in level @@ -536,7 +536,7 @@ let get_l2_block_predecessor node_ctxt hash = let+ header = Store.L2_blocks.header node_ctxt.store.l2_blocks hash in Option.map (fun {Sc_rollup_block.predecessor; level; _} -> - (predecessor, Int32.pred (Raw_level.to_int32 level))) + (predecessor, Int32.pred level)) header let get_predecessor_opt node_ctxt (hash, level) = @@ -608,8 +608,8 @@ let get_predecessor_header node_ctxt head = first look for a block before the [tick] *) let tick_search ~big_step_blocks node_ctxt head tick = let open Lwt_result_syntax in - if Sc_rollup.Tick.(head.Sc_rollup_block.initial_tick <= tick) then - if Sc_rollup.Tick.(Sc_rollup_block.final_tick head < tick) then + if Z.Compare.(head.Sc_rollup_block.initial_tick <= tick) then + if Z.Compare.(Sc_rollup_block.final_tick head < tick) then (* The head block does not contain the tick *) return_none else @@ -619,20 +619,18 @@ let tick_search ~big_step_blocks node_ctxt head tick = let genesis_level = Raw_level.to_int32 node_ctxt.genesis_info.level in let rec find_big_step (end_block : Sc_rollup_block.t) = let start_level = - Int32.sub - (Raw_level.to_int32 end_block.header.level) - (Int32.of_int big_step_blocks) + Int32.sub end_block.header.level (Int32.of_int big_step_blocks) in let start_level = if start_level < genesis_level then genesis_level else start_level in let* start_block = get_l2_block_by_level node_ctxt start_level in - if Sc_rollup.Tick.(start_block.initial_tick <= tick) then + if Z.Compare.(start_block.initial_tick <= tick) then return (start_block, end_block) else find_big_step start_block in let block_level Sc_rollup_block.{header = {level; _}; _} = - Raw_level.to_int32 level |> Int32.to_int + Int32.to_int level in let rec dicho start_block end_block = (* Precondition: @@ -648,7 +646,7 @@ let tick_search ~big_step_blocks node_ctxt head tick = let* block_middle = get_l2_block_by_level node_ctxt (Int32.of_int middle_level) in - if Sc_rollup.Tick.(block_middle.initial_tick <= tick) then + if Z.Compare.(block_middle.initial_tick <= tick) then dicho block_middle end_block else dicho start_block block_middle in @@ -671,51 +669,80 @@ let block_with_tick ({store; _} as node_ctxt) ~max_level tick = the refutation period as the big_step_blocks to do a dichotomy on the full space but we anticipate refutation to happen most of the time close to the head. *) + let max_level = Raw_level.to_int32 max_level in let** head = - if Raw_level.(head.header.level <= max_level) then return_some head - else find_l2_block_by_level node_ctxt (Raw_level.to_int32 max_level) + if head.header.level <= max_level then return_some head + else find_l2_block_by_level node_ctxt max_level in - tick_search ~big_step_blocks:4096 node_ctxt head tick + tick_search ~big_step_blocks:4096 node_ctxt head (Sc_rollup.Tick.to_z tick) -let get_commitment {store; _} commitment_hash = +let find_octez_commitment {store; _} commitment_hash = let open Lwt_result_syntax in - let* commitment = Store.Commitments.read store.commitments commitment_hash in + let+ commitment = Store.Commitments.read store.commitments commitment_hash in + Option.map fst commitment + +let find_commitment node_ctxt commitment_hash = + let open Lwt_result_syntax in + let commitment_hash = + Sc_rollup_proto_types.Commitment_hash.to_octez commitment_hash + in + let+ commitment = find_octez_commitment node_ctxt commitment_hash in + Option.map Sc_rollup_proto_types.Commitment.of_octez commitment + +let get_octez_commitment node_ctxt commitment_hash = + let open Lwt_result_syntax in + let* commitment = find_octez_commitment node_ctxt commitment_hash in match commitment with | None -> failwith "Could not retrieve commitment %a" - Sc_rollup.Commitment.Hash.pp + Octez_smart_rollup.Commitment.Hash.pp commitment_hash - | Some (c, ()) -> return c + | Some i -> return i -let find_commitment {store; _} hash = +let get_commitment node_ctxt commitment_hash = let open Lwt_result_syntax in - let+ commitment = Store.Commitments.read store.commitments hash in - Option.map fst commitment + let* commitment = find_commitment node_ctxt commitment_hash in + match commitment with + | None -> + failwith + "Could not retrieve commitment %a" + Sc_rollup.Commitment.Hash.pp + commitment_hash + | Some i -> return i let commitment_exists {store; _} hash = + let hash = Sc_rollup_proto_types.Commitment_hash.to_octez hash in Store.Commitments.mem store.commitments hash let save_commitment {store; _} commitment = let open Lwt_result_syntax in - let hash = Sc_rollup.Commitment.hash_uncarbonated commitment in + let commitment = Sc_rollup_proto_types.Commitment.to_octez commitment in + let hash = Octez_smart_rollup.Commitment.hash commitment in let+ () = Store.Commitments.append store.commitments ~key:hash ~value:commitment in - hash + Sc_rollup_proto_types.Commitment_hash.of_octez hash let commitment_published_at_level {store; _} commitment = + let commitment = Sc_rollup_proto_types.Commitment_hash.to_octez commitment in Store.Commitments_published_at_level.find store.commitments_published_at_level commitment -let set_commitment_published_at_level {store; _} = - Store.Commitments_published_at_level.add store.commitments_published_at_level +let set_commitment_published_at_level {store; _} hash = + let hash = Sc_rollup_proto_types.Commitment_hash.to_octez hash in + Store.Commitments_published_at_level.add + store.commitments_published_at_level + hash type commitment_source = Anyone | Us let commitment_was_published {store; _} ~source commitment_hash = let open Lwt_result_syntax in + let commitment_hash = + Sc_rollup_proto_types.Commitment_hash.to_octez commitment_hash + in match source with | Anyone -> Store.Commitments_published_at_level.mem @@ -731,31 +758,52 @@ let commitment_was_published {store; _} ~source commitment_hash = | Some {published_at_level = Some _; _} -> true | _ -> false) -let get_inbox {store; _} inbox_hash = +let find_octez_inbox {store; _} inbox_hash = let open Lwt_result_syntax in - let* inbox = Store.Inboxes.read store.inboxes inbox_hash in + let+ inbox = Store.Inboxes.read store.inboxes inbox_hash in + Option.map fst inbox + +let find_inbox node_ctxt inbox_hash = + let open Lwt_result_syntax in + let inbox_hash = Sc_rollup_proto_types.Inbox_hash.to_octez inbox_hash in + let+ inbox = find_octez_inbox node_ctxt inbox_hash in + Option.map Sc_rollup_proto_types.Inbox.of_octez inbox + +let get_octez_inbox node_ctxt inbox_hash = + let open Lwt_result_syntax in + let* inbox = find_octez_inbox node_ctxt inbox_hash in match inbox with | None -> - failwith "Could not retrieve inbox %a" Sc_rollup.Inbox.Hash.pp inbox_hash - | Some (i, ()) -> return i + failwith + "Could not retrieve inbox %a" + Octez_smart_rollup.Inbox.Hash.pp + inbox_hash + | Some i -> return i -let find_inbox {store; _} hash = +let get_inbox node_ctxt inbox_hash = let open Lwt_result_syntax in - let+ inbox = Store.Inboxes.read store.inboxes hash in - Option.map fst inbox + let* inbox = find_inbox node_ctxt inbox_hash in + match inbox with + | None -> + failwith "Could not retrieve inbox %a" Sc_rollup.Inbox.Hash.pp inbox_hash + | Some i -> return i let save_inbox {store; _} inbox = let open Lwt_result_syntax in - let hash = Sc_rollup.Inbox.hash inbox in + let inbox = Sc_rollup_proto_types.Inbox.to_octez inbox in + let hash = Octez_smart_rollup.Inbox.hash inbox in let+ () = Store.Inboxes.append store.inboxes ~key:hash ~value:inbox in - hash + Sc_rollup_proto_types.Inbox_hash.of_octez hash let find_inbox_by_block_hash ({store; _} as node_ctxt) block_hash = let open Lwt_result_syntax in let* header = Store.L2_blocks.header store.l2_blocks block_hash in match header with | None -> return_none - | Some {inbox_hash; _} -> find_inbox node_ctxt inbox_hash + | Some {inbox_hash; _} -> + find_inbox + node_ctxt + (Sc_rollup_proto_types.Inbox_hash.of_octez inbox_hash) let genesis_inbox node_ctxt = let genesis_level = Raw_level.to_int32 node_ctxt.genesis_info.level in @@ -805,6 +853,9 @@ type messages_info = { let find_messages node_ctxt messages_hash = let open Lwt_result_syntax in + let messages_hash = + Sc_rollup_proto_types.Merkelized_payload_hashes_hash.to_octez messages_hash + in let* msg = Store.Messages.read node_ctxt.store.messages messages_hash in match msg with | None -> return_none @@ -817,6 +868,13 @@ let find_messages node_ctxt messages_hash = let is_first_block = pred_header.header.proto_level <> grand_parent_header.header.proto_level in + let*? messages = + Environment.wrap_tzresult + @@ List.map_e + (fun m -> + Sc_rollup.Inbox_message.(deserialize @@ unsafe_of_string m)) + messages + in return_some { is_first_block; @@ -825,18 +883,22 @@ let find_messages node_ctxt messages_hash = messages; } -let get_messages_aux find node_ctxt hash = +let get_messages_aux find pp node_ctxt hash = let open Lwt_result_syntax in let* res = find node_ctxt hash in match res with | None -> failwith "Could not retrieve messages with payloads merkelized hash %a" - Sc_rollup.Inbox_merkelized_payload_hashes.Hash.pp + pp hash | Some res -> return res -let get_messages node_ctxt = get_messages_aux find_messages node_ctxt +let get_messages node_ctxt = + get_messages_aux + find_messages + Sc_rollup.Inbox_merkelized_payload_hashes.Hash.pp + node_ctxt let get_messages_without_proto_messages node_ctxt = get_messages_aux @@ -846,30 +908,44 @@ let get_messages_without_proto_messages node_ctxt = match msg with | None -> return_none | Some (messages, _block_hash) -> return_some messages) + Tezos_crypto.Hashed.Smart_rollup_merkelized_payload_hashes_hash.pp node_ctxt let get_num_messages {store; _} hash = let open Lwt_result_syntax in + let hash = + Sc_rollup_proto_types.Merkelized_payload_hashes_hash.to_octez hash + in let* msg = Store.Messages.read store.messages hash in match msg with | None -> failwith "Could not retrieve number of messages for inbox witness %a" - Sc_rollup.Inbox_merkelized_payload_hashes.Hash.pp + Tezos_crypto.Hashed.Smart_rollup_merkelized_payload_hashes_hash.pp hash | Some (messages, _block_hash) -> return (List.length messages) let save_messages {store; _} key ~block_hash messages = - Store.Messages.append store.messages ~key ~header:block_hash ~value:messages + let open Lwt_result_syntax in + let key = Sc_rollup_proto_types.Merkelized_payload_hashes_hash.to_octez key in + let*? messages = + Environment.wrap_tzresult + @@ List.map_e Sc_rollup.Inbox_message.serialize messages + in + Store.Messages.append + store.messages + ~key + ~header:block_hash + ~value:(messages :> string list) let get_full_l2_block node_ctxt block_hash = let open Lwt_result_syntax in let* block = get_l2_block node_ctxt block_hash in - let* inbox = get_inbox node_ctxt block.header.inbox_hash + let* inbox = get_octez_inbox node_ctxt block.header.inbox_hash and* messages = get_messages_without_proto_messages node_ctxt block.header.inbox_witness and* commitment = - Option.map_es (get_commitment node_ctxt) block.header.commitment_hash + Option.map_es (get_octez_commitment node_ctxt) block.header.commitment_hash in return {block with content = {Sc_rollup_block.inbox; messages; commitment}} @@ -1028,58 +1104,91 @@ let get_slot_header {store; _} ~published_in_block_hash slot_index = slot_index Block_hash.pp published_in_block_hash - @@ Store.Dal_slots_headers.get - store.irmin_store - ~primary_key:published_in_block_hash - ~secondary_key:slot_index + @@ + let open Lwt_result_syntax in + let+ header = + Store.Dal_slots_headers.get + store.irmin_store + ~primary_key:published_in_block_hash + ~secondary_key:(Sc_rollup_proto_types.Dal.Slot_index.to_octez slot_index) + in + Sc_rollup_proto_types.Dal.Slot_header.of_octez header let get_all_slot_headers {store; _} ~published_in_block_hash = - Store.Dal_slots_headers.list_values - store.irmin_store - ~primary_key:published_in_block_hash + let open Lwt_result_syntax in + let+ headers = + Store.Dal_slots_headers.list_values + store.irmin_store + ~primary_key:published_in_block_hash + in + List.rev_map Sc_rollup_proto_types.Dal.Slot_header.of_octez headers + |> List.rev let get_slot_indexes {store; _} ~published_in_block_hash = - Store.Dal_slots_headers.list_secondary_keys - store.irmin_store - ~primary_key:published_in_block_hash + let open Lwt_result_syntax in + let+ indexes = + Store.Dal_slots_headers.list_secondary_keys + store.irmin_store + ~primary_key:published_in_block_hash + in + List.rev_map Sc_rollup_proto_types.Dal.Slot_index.of_octez indexes |> List.rev let save_slot_header {store; _} ~published_in_block_hash (slot_header : Dal.Slot.Header.t) = Store.Dal_slots_headers.add store.irmin_store ~primary_key:published_in_block_hash - ~secondary_key:slot_header.id.index - slot_header + ~secondary_key: + (Sc_rollup_proto_types.Dal.Slot_index.to_octez slot_header.id.index) + (Sc_rollup_proto_types.Dal.Slot_header.to_octez slot_header) let find_slot_status {store; _} ~confirmed_in_block_hash slot_index = Store.Dal_slots_statuses.find store.irmin_store ~primary_key:confirmed_in_block_hash - ~secondary_key:slot_index + ~secondary_key:(Sc_rollup_proto_types.Dal.Slot_index.to_octez slot_index) let list_slots_statuses {store; _} ~confirmed_in_block_hash = - Store.Dal_slots_statuses.list_secondary_keys_with_values - store.irmin_store - ~primary_key:confirmed_in_block_hash + let open Lwt_result_syntax in + let+ statuses = + Store.Dal_slots_statuses.list_secondary_keys_with_values + store.irmin_store + ~primary_key:confirmed_in_block_hash + in + List.rev_map + (fun (index, status) -> + (Sc_rollup_proto_types.Dal.Slot_index.of_octez index, status)) + statuses + |> List.rev let save_slot_status {store; _} current_block_hash slot_index status = Store.Dal_slots_statuses.add store.irmin_store ~primary_key:current_block_hash - ~secondary_key:slot_index + ~secondary_key:(Sc_rollup_proto_types.Dal.Slot_index.to_octez slot_index) status -let find_confirmed_slots_history {store; _} = - Store.Dal_confirmed_slots_history.find store.irmin_store +let find_confirmed_slots_history {store; _} block = + let open Lwt_result_syntax in + let+ res = Store.Dal_confirmed_slots_history.find store.irmin_store block in + Option.map Sc_rollup_proto_types.Dal.Slot_history.of_octez res -let save_confirmed_slots_history {store; _} = - Store.Dal_confirmed_slots_history.add store.irmin_store +let save_confirmed_slots_history {store; _} block hist = + Store.Dal_confirmed_slots_history.add + store.irmin_store + block + (Sc_rollup_proto_types.Dal.Slot_history.to_octez hist) -let find_confirmed_slots_histories {store; _} = - Store.Dal_confirmed_slots_histories.find store.irmin_store +let find_confirmed_slots_histories {store; _} block = + let open Lwt_result_syntax in + let+ res = Store.Dal_confirmed_slots_histories.find store.irmin_store block in + Option.map Sc_rollup_proto_types.Dal.Slot_history_cache.of_octez res -let save_confirmed_slots_histories {store; _} = - Store.Dal_confirmed_slots_histories.add store.irmin_store +let save_confirmed_slots_histories {store; _} block hist = + Store.Dal_confirmed_slots_histories.add + store.irmin_store + block + (Sc_rollup_proto_types.Dal.Slot_history_cache.to_octez hist) module Internal_for_tests = struct let create_node_context cctxt diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/publisher.ml b/src/proto_017_PtNairob/lib_sc_rollup_node/publisher.ml index 96274d64f95c759ae8b7559ffe013153936f4606..7febcaea817bfe2b8e7e5db671ada33aa4644d8f 100644 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/publisher.ml +++ b/src/proto_017_PtNairob/lib_sc_rollup_node/publisher.ml @@ -110,9 +110,9 @@ let build_commitment (node_ctxt : _ Node_context.t) let*! compressed_state = PVM.state_hash pvm_state in let*! tick = PVM.get_tick pvm_state in let* prev_commitment_tick = tick_of_level node_ctxt prev_commitment_level in + let distance = Z.sub (Sc_rollup.Tick.to_z tick) prev_commitment_tick in let number_of_ticks = - Sc_rollup.Tick.distance tick prev_commitment_tick - |> Z.to_int64 |> Sc_rollup.Number_of_ticks.of_value + distance |> Z.to_int64 |> Sc_rollup.Number_of_ticks.of_value in let*? number_of_ticks = match number_of_ticks with @@ -177,6 +177,7 @@ let create_commitment_if_necessary (node_ctxt : _ Node_context.t) ~predecessor let* last_commitment_hash = let+ pred = Node_context.get_l2_block node_ctxt predecessor in Sc_rollup_block.most_recent_commitment pred.header + |> Sc_rollup_proto_types.Commitment_hash.of_octez in let* last_commitment = Node_context.get_commitment node_ctxt last_commitment_hash @@ -221,9 +222,7 @@ let missing_commitments (node_ctxt : _ Node_context.t) = in let* head = Node_context.last_processed_head_opt node_ctxt in let next_head_level = - Option.map - (fun (b : Sc_rollup_block.t) -> Raw_level.succ b.header.level) - head + Option.map (fun (b : Sc_rollup_block.t) -> Int32.succ b.header.level) head in let sc_rollup_challenge_window_int32 = sc_rollup_challenge_window node_ctxt |> Int32.of_int @@ -249,7 +248,7 @@ let missing_commitments (node_ctxt : _ Node_context.t) = match (published_info, next_head_level) with | None, _ | _, None -> false | Some {first_published_at_level; _}, Some next_head_level -> - Raw_level.diff next_head_level first_published_at_level + Int32.sub next_head_level first_published_at_level > sc_rollup_challenge_window_int32 in let acc = if past_curfew then acc else commitment :: acc in @@ -264,6 +263,7 @@ let missing_commitments (node_ctxt : _ Node_context.t) = commitments that are missing. *) let commitment = Sc_rollup_block.most_recent_commitment finalized.header + |> Sc_rollup_proto_types.Commitment_hash.of_octez in gather [] commitment @@ -320,7 +320,9 @@ let earliest_cementing_level node_ctxt commitment_hash = Node_context.commitment_published_at_level node_ctxt commitment_hash in return_some - @@ add_level first_published_at_level (sc_rollup_challenge_window node_ctxt) + @@ Int32.add + first_published_at_level + (sc_rollup_challenge_window node_ctxt |> Int32.of_int) (** [latest_cementable_commitment node_ctxt head] is the most recent commitment hash that could be cemented in [head]'s successor if: @@ -333,7 +335,10 @@ let earliest_cementing_level node_ctxt commitment_hash = let latest_cementable_commitment (node_ctxt : _ Node_context.t) (head : Sc_rollup_block.t) = let open Lwt_result_option_syntax in - let commitment_hash = Sc_rollup_block.most_recent_commitment head.header in + let commitment_hash = + Sc_rollup_block.most_recent_commitment head.header + |> Sc_rollup_proto_types.Commitment_hash.of_octez + in let** commitment = Node_context.find_commitment node_ctxt commitment_hash in let** cementable_level_bound = return @@ -349,6 +354,7 @@ let latest_cementable_commitment (node_ctxt : _ Node_context.t) in let cementable_commitment = Sc_rollup_block.most_recent_commitment cementable_bound_block.header + |> Sc_rollup_proto_types.Commitment_hash.of_octez in return_some cementable_commitment @@ -374,7 +380,7 @@ let cementable_commitments (node_ctxt : _ Node_context.t) = match earliest_cementing_level with | None -> acc | Some earliest_cementing_level -> - if Raw_level.(earliest_cementing_level > head_level) then + if earliest_cementing_level > head_level then (* Commitments whose cementing level are after the head's successor won't be cementable in the next block. *) acc diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/store.ml b/src/proto_017_PtNairob/lib_sc_rollup_node/store.ml deleted file mode 100644 index f89bd6e8cfb551522c566991a8cede8bb4e94e69..0000000000000000000000000000000000000000 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/store.ml +++ /dev/null @@ -1,27 +0,0 @@ -(*****************************************************************************) -(* *) -(* Open Source License *) -(* Copyright (c) 2021 Nomadic Labs, *) -(* Copyright (c) 2023 Functori, *) -(* *) -(* 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. *) -(* *) -(*****************************************************************************) - -include Store_v2 diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/store_migration.ml b/src/proto_017_PtNairob/lib_sc_rollup_node/store_migration.ml deleted file mode 100644 index a10d8043c46d84973ed7fea31701575d8fea9876..0000000000000000000000000000000000000000 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/store_migration.ml +++ /dev/null @@ -1,438 +0,0 @@ -(*****************************************************************************) -(* *) -(* Open Source License *) -(* Copyright (c) 2023 Functori, *) -(* *) -(* 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. *) -(* *) -(*****************************************************************************) - -open Store_version - -type version_result = Version_known | Unintialized_version - -let messages_store_location ~storage_dir = - let open Filename.Infix in - storage_dir // "messages" - -let version_of_unversioned_store ~storage_dir = - let open Lwt_syntax in - let path = messages_store_location ~storage_dir in - let* messages_store_v0 = Store_v0.Messages.load ~path ~cache_size:1 Read_only - and* messages_store_v1 = - Store_v1.Messages.load ~path ~cache_size:1 Read_only - in - let cleanup () = - let open Lwt_syntax in - let* (_ : unit tzresult) = - match messages_store_v0 with - | Error _ -> Lwt.return_ok () - | Ok s -> Store_v0.Messages.close s - and* (_ : unit tzresult) = - match messages_store_v1 with - | Error _ -> Lwt.return_ok () - | Ok s -> Store_v1.Messages.close s - in - return_unit - in - let guess_version () = - let open Lwt_result_syntax in - match (messages_store_v0, messages_store_v1) with - | Ok _, Error _ -> return_some V0 - | Error _, Ok _ -> return_some V1 - | Ok _, Ok _ -> - (* Empty store, both loads succeed *) - return_none - | Error _, Error _ -> - failwith - "Cannot determine unversioned store version (no messages decodable)" - in - Lwt.finalize guess_version cleanup - -let version_of_store ~storage_dir = - let open Lwt_result_syntax in - let* version = Store_version.read_version_file ~dir:storage_dir in - match version with - | Some v -> return_some (v, Version_known) - | None -> - let+ v = version_of_unversioned_store ~storage_dir in - Option.map (fun v -> (v, Unintialized_version)) v - -module type MIGRATION_ACTIONS = sig - type from_store - - type dest_store - - val migrate_block_action : - from_store -> dest_store -> Sc_rollup_block.t -> unit tzresult Lwt.t - - val final_actions : - storage_dir:string -> - tmp_dir:string -> - from_store -> - dest_store -> - unit tzresult Lwt.t -end - -module type S = sig - val migrate : storage_dir:string -> unit tzresult Lwt.t -end - -let migrations = Stdlib.Hashtbl.create 7 - -module Make - (S_from : Store_sig.S) - (S_dest : Store_sig.S) - (Actions : MIGRATION_ACTIONS - with type from_store := Store_sigs.ro S_from.t - and type dest_store := Store_sigs.rw S_dest.t) : S = struct - let tmp_dir ~storage_dir = - Filename.concat (Configuration.default_storage_dir storage_dir) - @@ Format.asprintf - "migration_%a_%a" - Store_version.pp - S_from.version - Store_version.pp - S_dest.version - - let migrate ~storage_dir = - let open Lwt_result_syntax in - let* source_store = - S_from.load Read_only ~l2_blocks_cache_size:1 storage_dir - in - let tmp_dir = tmp_dir ~storage_dir in - let*! tmp_dir_exists = Lwt_utils_unix.dir_exists tmp_dir in - let*? () = - if tmp_dir_exists then - error_with - "Store migration (from %a to %a) is already ongoing. Wait for it to \ - finish or remove %S and restart." - Store_version.pp - S_from.version - Store_version.pp - S_dest.version - tmp_dir - else Ok () - in - let*! () = Lwt_utils_unix.create_dir tmp_dir in - let* dest_store = S_dest.load Read_write ~l2_blocks_cache_size:1 tmp_dir in - let cleanup () = - let open Lwt_syntax in - let* (_ : unit tzresult) = S_from.close source_store - and* (_ : unit tzresult) = S_dest.close dest_store in - (* Don't remove migration dir to allow for later resume. *) - return_unit - in - let run_migration () = - let* () = - S_from.iter_l2_blocks - source_store - (Actions.migrate_block_action source_store dest_store) - in - let* () = - Actions.final_actions ~storage_dir ~tmp_dir source_store dest_store - in - let*! () = Lwt_utils_unix.remove_dir tmp_dir in - Store_version.write_version_file ~dir:storage_dir S_dest.version - in - Lwt.finalize run_migration cleanup - - let () = Stdlib.Hashtbl.add migrations S_from.version (S_dest.version, migrate) -end - -let migration_path ~from ~dest = - let rec path acc from dest = - if from = dest then Some (List.rev acc) - else - let first_steps = - Stdlib.Hashtbl.find_all migrations from - |> List.stable_sort (fun (va, _) (vb, _) -> - (* Try biggest jumps first that don't go beyond the - destination *) - if va > dest && vb > dest then Stdlib.compare va vb - else if va > dest then 1 - else if vb > dest then -1 - else Stdlib.compare vb va) - in - (* Recursively look for migration sub-paths *) - let paths = - List.filter_map - (fun (step, migration) -> - path ((from, step, migration) :: acc) step dest) - first_steps - in - (* Choose shortest migration path *) - List.stable_sort List.compare_lengths paths |> List.hd - in - path [] from dest - -let maybe_run_migration ~storage_dir = - let open Lwt_result_syntax in - let* current_version = version_of_store ~storage_dir in - let last_version = Store.version in - match (current_version, last_version) with - | None, _ -> - (* Store not initialized, write last version *) - Store_version.write_version_file ~dir:storage_dir last_version - | Some (current, versioned), last when last = current -> ( - match versioned with - | Unintialized_version -> - Store_version.write_version_file ~dir:storage_dir last_version - | Version_known -> - (* Up to date, nothing to do *) - return_unit) - | Some (current, _), last -> ( - let migrations = migration_path ~from:current ~dest:last in - match migrations with - | None -> - failwith - "Store version %a is not supported by this rollup node because \ - there is no migration path from it to %a." - Store_version.pp - current - Store_version.pp - last - | Some migrations -> - Format.printf "Starting store migration@." ; - let+ () = - List.iter_es - (fun (vx, vy, migrate) -> - Format.printf - "- Migrating store from %a to %a@." - Store_version.pp - vx - Store_version.pp - vy ; - migrate ~storage_dir) - migrations - in - Format.printf "Store migration completed@.") - -module V1_migrations = struct - let convert_store_messages - (messages, (block_hash, timestamp, number_of_messages)) = - ( messages, - (false (* is migration block *), block_hash, timestamp, number_of_messages) - ) - - let migrate_messages (v0_store : _ Store_v0.t) (v1_store : _ Store_v1.t) - (l2_block : Sc_rollup_block.t) = - let open Lwt_result_syntax in - let* v0_messages = - Store_v0.Messages.read v0_store.messages l2_block.header.inbox_witness - in - match v0_messages with - | None -> return_unit - | Some v0_messages -> - let value, header = convert_store_messages v0_messages in - Store_v1.Messages.append - v1_store.messages - ~key:l2_block.header.inbox_witness - ~header - ~value - - (* In place migration of processed slots under new key name by hand *) - let migrate_dal_processed_slots_irmin (v1_store : _ Store_v1.t) = - let open Lwt_syntax in - let open Store_v1 in - let info () = - let date = - Tezos_base.Time.( - System.now () |> System.to_protocol |> Protocol.to_seconds) - in - let author = - Format.asprintf - "Rollup node %a" - Tezos_version_parser.pp - Tezos_version_value.Current_git_info.version - in - let message = "Migration store from v0 to v1" in - Irmin_store.Raw_irmin.Info.v ~author ~message date - in - let store = Irmin_store.Raw_irmin.unsafe v1_store.irmin_store in - let old_root = Store_v0.Dal_processed_slots.path in - let new_root = Dal_slots_statuses.path in - let* old_tree = Irmin_store.Raw_irmin.find_tree store old_root in - match old_tree with - | None -> return_unit - | Some _ -> - (* Move the tree in the new key *) - Irmin_store.Raw_irmin.with_tree_exn - ~info - store - new_root - (fun _new_tree -> return old_tree) - - let final_actions ~storage_dir ~tmp_dir (_v0_store : _ Store_v0.t) - (v1_store : _ Store_v1.t) = - let open Lwt_result_syntax in - let*! () = - Lwt_utils_unix.remove_dir (messages_store_location ~storage_dir) - in - let*! () = - Lwt_unix.rename - (messages_store_location ~storage_dir:tmp_dir) - (messages_store_location ~storage_dir) - in - let*! () = migrate_dal_processed_slots_irmin v1_store in - return_unit - - module From_v0 = - Make (Store_v0) (Store_v1) - (struct - let migrate_block_action = migrate_messages - - let final_actions = final_actions - end) -end - -module V2_migrations = struct - let messages_store_location ~storage_dir = - let open Filename.Infix in - storage_dir // "messages" - - let commitments_store_location ~storage_dir = - let open Filename.Infix in - storage_dir // "commitments" - - let inboxes_store_location ~storage_dir = - let open Filename.Infix in - storage_dir // "inboxes" - - let migrate_messages read_messages (v2_store : _ Store_v2.t) - (l2_block : Sc_rollup_block.t) = - let open Lwt_result_syntax in - let* v1_messages = read_messages l2_block.header.inbox_witness in - match v1_messages with - | None -> return_unit - | Some (messages, _v1_header) -> - let header = l2_block.header.block_hash in - Store_v2.Messages.append - v2_store.messages - ~key:l2_block.header.inbox_witness - ~header - ~value:messages - - let migrate_commitment read_commitment (v2_store : _ Store_v2.t) - (l2_block : Sc_rollup_block.t) = - let open Lwt_result_syntax in - match l2_block.header.commitment_hash with - | None -> return_unit - | Some commitment_hash -> ( - let* v1_commitment = read_commitment commitment_hash in - match v1_commitment with - | None -> return_unit - | Some commitment -> - Store_v2.Commitments.append - v2_store.commitments - ~key:commitment_hash - ~value:commitment) - - let migrate_inbox read_inbox (v2_store : _ Store_v2.t) - (l2_block : Sc_rollup_block.t) = - let open Lwt_result_syntax in - let* v1_inbox = read_inbox l2_block.header.inbox_hash in - match v1_inbox with - | None -> return_unit - | Some (inbox, ()) -> - Store_v2.Inboxes.append - v2_store.inboxes - ~key:l2_block.header.inbox_hash - ~value:inbox - - let final_actions ~storage_dir ~tmp_dir _ _ = - let open Lwt_result_syntax in - let*! () = - Lwt_utils_unix.remove_dir (messages_store_location ~storage_dir) - in - let*! () = - Lwt_utils_unix.remove_dir (commitments_store_location ~storage_dir) - in - let*! () = - Lwt_utils_unix.remove_dir (inboxes_store_location ~storage_dir) - in - let*! () = - Lwt_unix.rename - (messages_store_location ~storage_dir:tmp_dir) - (messages_store_location ~storage_dir) - in - let*! () = - Lwt_unix.rename - (commitments_store_location ~storage_dir:tmp_dir) - (commitments_store_location ~storage_dir) - in - let*! () = - Lwt_unix.rename - (inboxes_store_location ~storage_dir:tmp_dir) - (inboxes_store_location ~storage_dir) - in - return_unit - - module From_v1 = - Make (Store_v1) (Store_v2) - (struct - let migrate_block_action v1_store v2_store l2_block = - let open Lwt_result_syntax in - let* () = - migrate_messages - Store_v1.(Messages.read v1_store.messages) - v2_store - l2_block - and* () = - migrate_commitment - Store_v1.(Commitments.find v1_store.commitments) - v2_store - l2_block - and* () = - migrate_inbox - Store_v1.(Inboxes.read v1_store.inboxes) - v2_store - l2_block - in - return_unit - - let final_actions = final_actions - end) - - module From_v0 = - Make (Store_v0) (Store_v2) - (struct - let migrate_block_action v0_store v2_store l2_block = - let open Lwt_result_syntax in - let* () = - migrate_messages - Store_v0.(Messages.read v0_store.messages) - v2_store - l2_block - and* () = - migrate_commitment - Store_v0.(Commitments.find v0_store.commitments) - v2_store - l2_block - and* () = - migrate_inbox - Store_v0.(Inboxes.read v0_store.inboxes) - v2_store - l2_block - in - return_unit - - let final_actions = final_actions - end) -end diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/store_migration.mli b/src/proto_017_PtNairob/lib_sc_rollup_node/store_migration.mli deleted file mode 100644 index 0b99202ca76815cb77f3cb7151c21e3aa5b9f7dd..0000000000000000000000000000000000000000 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/store_migration.mli +++ /dev/null @@ -1,67 +0,0 @@ -(*****************************************************************************) -(* *) -(* Open Source License *) -(* Copyright (c) 2023 Functori, *) -(* *) -(* 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. *) -(* *) -(*****************************************************************************) - -(** Type of parameter for migration functor {!Make}. *) -module type MIGRATION_ACTIONS = sig - (** Type of store from which data is migrated. *) - type from_store - - (** Type of store to which the data is migrated. *) - type dest_store - - (** Action or actions to migrate data associated to a block. NOTE: - [dest_store] is an empty R/W store initialized in a temporary location. *) - val migrate_block_action : - from_store -> dest_store -> Sc_rollup_block.t -> unit tzresult Lwt.t - - (** The final actions to be performed in the migration. In particular, this is - where data from the temporary store in [dest_store] in [tmp_dir] should be - reported in the actual [storage_dir]. *) - val final_actions : - storage_dir:string -> - tmp_dir:string -> - from_store -> - dest_store -> - unit tzresult Lwt.t -end - -module type S = sig - (** Migration function for the store located in [storage_dir]. *) - val migrate : storage_dir:string -> unit tzresult Lwt.t -end - -(** Functor to create and {e register} a migration. *) -module Make - (S_from : Store_sig.S) - (S_dest : Store_sig.S) - (Actions : MIGRATION_ACTIONS - with type from_store := Store_sigs.ro S_from.t - and type dest_store := Store_sigs.rw S_dest.t) : S - -(** Migrate store located in rollup node {e store} directory [storage_dir] if - needed. If there is no possible migration path registered to go from the - current version to the last {!Store.version}, this function resolves with an - error. *) -val maybe_run_migration : storage_dir:string -> unit tzresult Lwt.t diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/store_sig.ml b/src/proto_017_PtNairob/lib_sc_rollup_node/store_sig.ml deleted file mode 100644 index ffac28ff0409d1304131464a80fdd11701499e9d..0000000000000000000000000000000000000000 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/store_sig.ml +++ /dev/null @@ -1,65 +0,0 @@ -(*****************************************************************************) -(* *) -(* Open Source License *) -(* Copyright (c) 2023 Functori, *) -(* *) -(* 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. *) -(* *) -(*****************************************************************************) - -module type S = sig - type +'a store - - (** Type of store. The parameter indicates if the store can be written or only - read. *) - type 'a t = ([< `Read | `Write > `Read] as 'a) store - - (** Read/write store {!t}. *) - type rw = Store_sigs.rw t - - (** Read only store {!t}. *) - type ro = Store_sigs.ro t - - (** Version supported by this code. *) - val version : Store_version.t - - (** [close store] closes the store. *) - val close : _ t -> unit tzresult Lwt.t - - (** [load mode ~l2_blocks_cache_size directory] loads a store from the data - persisted in [directory]. If [mode] is {!Store_sigs.Read_only}, then the - indexes and irmin store will be opened in readonly mode and only read - operations will be permitted. This allows to open a store for read access - that is already opened in {!Store_sigs.Read_write} mode in another - process. [l2_blocks_cache_size] is the number of L2 blocks the rollup node - will keep in memory. *) - val load : - 'a Store_sigs.mode -> - l2_blocks_cache_size:int -> - string -> - 'a store tzresult Lwt.t - - (** [readonly store] returns a read-only version of [store]. *) - val readonly : _ t -> ro - - (** [iter_l2_blocks store f] iterates [f] on all L2 blocks reachable from the - head, from newest to oldest. *) - val iter_l2_blocks : - _ t -> (Sc_rollup_block.t -> unit tzresult Lwt.t) -> unit tzresult Lwt.t -end diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/store_v0.ml b/src/proto_017_PtNairob/lib_sc_rollup_node/store_v0.ml deleted file mode 100644 index 066a37f739fb3ba9037c31a4a8789ee09936bad4..0000000000000000000000000000000000000000 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/store_v0.ml +++ /dev/null @@ -1,506 +0,0 @@ -(*****************************************************************************) -(* *) -(* Open Source License *) -(* Copyright (c) 2021 Nomadic Labs, *) -(* Copyright (c) 2023 Functori, *) -(* *) -(* 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. *) -(* *) -(*****************************************************************************) - -(** This module is a copy of - [src/proto_016_PtMumbai/lib_sc_rollup_node/store.ml], which contains the - store for the Mumbai rollup node. *) - -open Protocol -include Store_sigs -include Store_utils - -(** Aggregated collection of messages from the L1 inbox *) -open Alpha_context - -let version = Store_version.V0 - -module Irmin_store = struct - module IStore = Irmin_store.Make (struct - let name = "Tezos smart rollup node" - end) - - include IStore - include Store_utils.Make (IStore) -end - -module Empty_header = struct - type t = unit - - let name = "empty" - - let encoding = Data_encoding.unit - - let fixed_size = 0 -end - -module Add_empty_header = struct - module Header = Empty_header - - let header _ = () -end - -module Make_hash_index_key (H : Environment.S.HASH) = -Indexed_store.Make_index_key (struct - include Indexed_store.Make_fixed_encodable (H) - - let equal = H.equal -end) - -(** L2 blocks *) -module L2_blocks = - Indexed_store.Make_indexed_file - (struct - let name = "l2_blocks" - end) - (Tezos_store_shared.Block_key) - (struct - type t = (unit, unit) Sc_rollup_block.block - - let name = "sc_rollup_block_info" - - let encoding = - Sc_rollup_block.block_encoding Data_encoding.unit Data_encoding.unit - - module Header = struct - type t = Sc_rollup_block.header - - let name = "sc_rollup_block_header" - - let encoding = Sc_rollup_block.header_encoding - - let fixed_size = Sc_rollup_block.header_size - end - end) - -(** Unaggregated messages per block *) -module Messages = - Indexed_store.Make_indexed_file - (struct - let name = "messages" - end) - (Make_hash_index_key (Sc_rollup.Inbox_merkelized_payload_hashes.Hash)) - (struct - type t = Sc_rollup.Inbox_message.t list - - let name = "messages_list" - - let encoding = - Data_encoding.(list @@ dynamic_size Sc_rollup.Inbox_message.encoding) - - module Header = struct - type t = Block_hash.t * Timestamp.t * int - - let name = "messages_inbox_info" - - let encoding = - let open Data_encoding in - obj3 - (req "predecessor" Block_hash.encoding) - (req "predecessor_timestamp" Timestamp.encoding) - (req "num_messages" int31) - - let fixed_size = - WithExceptions.Option.get ~loc:__LOC__ - @@ Data_encoding.Binary.fixed_length encoding - end - end) - -(** Inbox state for each block *) -module Inboxes = - Indexed_store.Make_simple_indexed_file - (struct - let name = "inboxes" - end) - (Make_hash_index_key (Sc_rollup.Inbox.Hash)) - (struct - type t = Sc_rollup.Inbox.t - - let name = "inbox" - - let encoding = Sc_rollup.Inbox.encoding - - include Add_empty_header - end) - -module Commitments = - Indexed_store.Make_indexable - (struct - let name = "commitments" - end) - (Make_hash_index_key (Sc_rollup.Commitment.Hash)) - (Indexed_store.Make_index_value (Indexed_store.Make_fixed_encodable (struct - include Sc_rollup.Commitment - - let name = "commitment" - end))) - -module Commitments_published_at_level = struct - type element = { - first_published_at_level : Raw_level.t; - published_at_level : Raw_level.t option; - } - - let element_encoding = - let open Data_encoding in - let opt_level_encoding = - conv - (function None -> -1l | Some l -> Raw_level.to_int32 l) - (fun l -> if l = -1l then None else Some (Raw_level.of_int32_exn l)) - Data_encoding.int32 - in - conv - (fun {first_published_at_level; published_at_level} -> - (first_published_at_level, published_at_level)) - (fun (first_published_at_level, published_at_level) -> - {first_published_at_level; published_at_level}) - @@ obj2 - (req "first_published_at_level" Raw_level.encoding) - (req "published_at_level" opt_level_encoding) - - include - Indexed_store.Make_indexable - (struct - let name = "commitments" - end) - (Make_hash_index_key (Sc_rollup.Commitment.Hash)) - (Indexed_store.Make_index_value (Indexed_store.Make_fixed_encodable (struct - type t = element - - let name = "published_levels" - - let encoding = element_encoding - end))) -end - -module L2_head = Indexed_store.Make_singleton (struct - type t = Sc_rollup_block.t - - let name = "l2_head" - - let encoding = Sc_rollup_block.encoding -end) - -module Last_finalized_level = Indexed_store.Make_singleton (struct - type t = int32 - - let name = "finalized_level" - - let encoding = Data_encoding.int32 -end) - -(** Table from L1 levels to blocks hashes. *) -module Levels_to_hashes = - Indexed_store.Make_indexable - (struct - let name = "tezos_levels" - end) - (Indexed_store.Make_index_key (struct - type t = int32 - - let encoding = Data_encoding.int32 - - let name = "level" - - let fixed_size = 4 - - let equal = Int32.equal - end)) - (Tezos_store_shared.Block_key) - -(* Published slot headers per block hash, - stored as a list of bindings from `Dal_slot_index.t` - to `Dal.Slot.t`. The encoding function converts this - list into a `Dal.Slot_index.t`-indexed map. *) -module Dal_slot_pages = - Irmin_store.Make_nested_map - (struct - let path = ["dal"; "slot_pages"] - end) - (struct - type key = Block_hash.t - - let to_path_representation = Block_hash.to_b58check - end) - (struct - type key = Dal.Slot_index.t * Dal.Page.Index.t - - let encoding = - Data_encoding.(tup2 Dal.Slot_index.encoding Dal.Page.Index.encoding) - - let compare (i1, p1) (i2, p2) = - Compare.or_else (Dal.Slot_index.compare i1 i2) (fun () -> - Dal.Page.Index.compare p1 p2) - - let name = "slot_index" - end) - (struct - type value = Dal.Page.content - - let encoding = Dal.Page.content_encoding - - let name = "slot_pages" - end) - -(** stores slots whose data have been considered and pages stored to disk (if - they are confirmed). *) -module Dal_processed_slots = - Irmin_store.Make_nested_map - (struct - let path = ["dal"; "processed_slots"] - end) - (struct - type key = Block_hash.t - - let to_path_representation = Block_hash.to_b58check - end) - (struct - type key = Dal.Slot_index.t - - let encoding = Dal.Slot_index.encoding - - let compare = Dal.Slot_index.compare - - let name = "slot_index" - end) - (struct - type value = [`Confirmed | `Unconfirmed] - - let name = "slot_processing_status" - - let encoding = - let open Data_encoding in - let mk_case constr ~tag ~title = - case - ~title - (Tag tag) - (obj1 (req "kind" (constant title))) - (fun x -> if x = constr then Some () else None) - (fun () -> constr) - in - union - ~tag_size:`Uint8 - [ - mk_case `Confirmed ~tag:0 ~title:"Confirmed"; - mk_case `Unconfirmed ~tag:1 ~title:"Unconfirmed"; - ] - end) - -module Dal_slots_headers = - Irmin_store.Make_nested_map - (struct - let path = ["dal"; "slot_headers"] - end) - (struct - type key = Block_hash.t - - let to_path_representation = Block_hash.to_b58check - end) - (struct - type key = Dal.Slot_index.t - - let encoding = Dal.Slot_index.encoding - - let compare = Dal.Slot_index.compare - - let name = "slot_index" - end) - (struct - type value = Dal.Slot.Header.t - - let name = "slot_header" - - let encoding = Dal.Slot.Header.encoding - end) - -(* Published slot headers per block hash, stored as a list of bindings from - `Dal_slot_index.t` to `Dal.Slot.t`. The encoding function converts this - list into a `Dal.Slot_index.t`-indexed map. Note that the block_hash - refers to the block where slots headers have been confirmed, not - the block where they have been published. -*) - -(** Confirmed DAL slots history. See documentation of - {!Dal_slot_repr.Slots_history} for more details. *) -module Dal_confirmed_slots_history = - Irmin_store.Make_append_only_map - (struct - let path = ["dal"; "confirmed_slots_history"] - end) - (struct - type key = Block_hash.t - - let to_path_representation = Block_hash.to_b58check - end) - (struct - type value = Dal.Slots_history.t - - let name = "dal_slot_histories" - - let encoding = Dal.Slots_history.encoding - end) - -(** Confirmed DAL slots histories cache. See documentation of - {!Dal_slot_repr.Slots_history} for more details. *) -module Dal_confirmed_slots_histories = - (* TODO: https://gitlab.com/tezos/tezos/-/issues/4390 - Store single history points in map instead of whole history. *) - Irmin_store.Make_append_only_map - (struct - let path = ["dal"; "confirmed_slots_histories_cache"] - end) - (struct - type key = Block_hash.t - - let to_path_representation = Block_hash.to_b58check - end) - (struct - type value = Dal.Slots_history.History_cache.t - - let name = "dal_slot_history_cache" - - let encoding = Dal.Slots_history.History_cache.encoding - end) - -type 'a store = { - l2_blocks : 'a L2_blocks.t; - messages : 'a Messages.t; - inboxes : 'a Inboxes.t; - commitments : 'a Commitments.t; - commitments_published_at_level : 'a Commitments_published_at_level.t; - l2_head : 'a L2_head.t; - last_finalized_level : 'a Last_finalized_level.t; - levels_to_hashes : 'a Levels_to_hashes.t; - irmin_store : 'a Irmin_store.t; -} - -type 'a t = ([< `Read | `Write > `Read] as 'a) store - -type rw = Store_sigs.rw t - -type ro = Store_sigs.ro t - -let readonly - ({ - l2_blocks; - messages; - inboxes; - commitments; - commitments_published_at_level; - l2_head; - last_finalized_level; - levels_to_hashes; - irmin_store; - } : - _ t) : ro = - { - l2_blocks = L2_blocks.readonly l2_blocks; - messages = Messages.readonly messages; - inboxes = Inboxes.readonly inboxes; - commitments = Commitments.readonly commitments; - commitments_published_at_level = - Commitments_published_at_level.readonly commitments_published_at_level; - l2_head = L2_head.readonly l2_head; - last_finalized_level = Last_finalized_level.readonly last_finalized_level; - levels_to_hashes = Levels_to_hashes.readonly levels_to_hashes; - irmin_store = Irmin_store.readonly irmin_store; - } - -let close - ({ - l2_blocks; - messages; - inboxes; - commitments; - commitments_published_at_level; - l2_head = _; - last_finalized_level = _; - levels_to_hashes; - irmin_store; - } : - _ t) = - let open Lwt_result_syntax in - let+ () = L2_blocks.close l2_blocks - and+ () = Messages.close messages - and+ () = Inboxes.close inboxes - and+ () = Commitments.close commitments - and+ () = Commitments_published_at_level.close commitments_published_at_level - and+ () = Levels_to_hashes.close levels_to_hashes - and+ () = Irmin_store.close irmin_store in - () - -let load (type a) (mode : a mode) ~l2_blocks_cache_size data_dir : - a store tzresult Lwt.t = - let open Lwt_result_syntax in - let path name = Filename.concat data_dir name in - let cache_size = l2_blocks_cache_size in - let* l2_blocks = L2_blocks.load mode ~path:(path "l2_blocks") ~cache_size in - let* messages = Messages.load mode ~path:(path "messages") ~cache_size in - let* inboxes = Inboxes.load mode ~path:(path "inboxes") ~cache_size in - let* commitments = Commitments.load mode ~path:(path "commitments") in - let* commitments_published_at_level = - Commitments_published_at_level.load - mode - ~path:(path "commitments_published_at_level") - in - let* l2_head = L2_head.load mode ~path:(path "l2_head") in - let* last_finalized_level = - Last_finalized_level.load mode ~path:(path "last_finalized_level") - in - let* levels_to_hashes = - Levels_to_hashes.load mode ~path:(path "levels_to_hashes") - in - let+ irmin_store = Irmin_store.load mode (path "irmin_store") in - { - l2_blocks; - messages; - inboxes; - commitments; - commitments_published_at_level; - l2_head; - last_finalized_level; - levels_to_hashes; - irmin_store; - } - -let iter_l2_blocks ({l2_blocks; l2_head; _} : _ t) f = - let open Lwt_result_syntax in - let* head = L2_head.read l2_head in - match head with - | None -> - (* No reachable head, nothing to do *) - return_unit - | Some head -> - let rec loop hash = - let* block = L2_blocks.read l2_blocks hash in - match block with - | None -> - (* The block does not exist, the known chain stops here, so do we. *) - return_unit - | Some (block, header) -> - let* () = f {block with header} in - loop header.predecessor - in - loop head.header.block_hash diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/store_v0.mli b/src/proto_017_PtNairob/lib_sc_rollup_node/store_v0.mli deleted file mode 100644 index f2d9a002d6c1d6bf8000a7e5eb4ead8a11bf9894..0000000000000000000000000000000000000000 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/store_v0.mli +++ /dev/null @@ -1,164 +0,0 @@ -(*****************************************************************************) -(* *) -(* Open Source License *) -(* Copyright (c) 2022 Nomadic Labs, *) -(* Copyright (c) 2023 Functori, *) -(* *) -(* 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. *) -(* *) -(*****************************************************************************) - -(** This version of the store is used for the rollup nodes for protocol Mumbai, - i.e. = 16. - - This interface is a copy of - [src/proto_016_PtMumbai/lib_sc_rollup_node/store.mli], which contains the - layout for the Mumbai rollup node. -*) - -open Protocol -open Alpha_context -open Indexed_store - -module Irmin_store : sig - include module type of Irmin_store.Make (struct - let name = "Tezos smart rollup node" - end) - - include Store_sigs.Store with type 'a t := 'a t -end - -module L2_blocks : - INDEXED_FILE - with type key := Block_hash.t - and type value := (unit, unit) Sc_rollup_block.block - and type header := Sc_rollup_block.header - -(** Storage for persisting messages downloaded from the L1 node. *) -module Messages : - INDEXED_FILE - with type key := Sc_rollup.Inbox_merkelized_payload_hashes.Hash.t - and type value := Sc_rollup.Inbox_message.t list - and type header := Block_hash.t * Timestamp.t * int - -(** Aggregated collection of messages from the L1 inbox *) -module Inboxes : - SIMPLE_INDEXED_FILE - with type key := Sc_rollup.Inbox.Hash.t - and type value := Sc_rollup.Inbox.t - and type header := unit - -(** Storage containing commitments and corresponding commitment hashes that the - rollup node has knowledge of. *) -module Commitments : - INDEXABLE_STORE - with type key := Sc_rollup.Commitment.Hash.t - and type value := Sc_rollup.Commitment.t - -(** Storage mapping commitment hashes to the level when they were published by - the rollup node. It only contains hashes of commitments published by this - rollup node. *) -module Commitments_published_at_level : sig - type element = { - first_published_at_level : Raw_level.t; - (** The level at which this commitment was first published. *) - published_at_level : Raw_level.t option; - (** The level at which we published this commitment. If - [first_published_at_level <> published_at_level] it means that the - commitment is republished. *) - } - - include - INDEXABLE_STORE - with type key := Sc_rollup.Commitment.Hash.t - and type value := element -end - -module L2_head : SINGLETON_STORE with type value := Sc_rollup_block.t - -module Last_finalized_level : SINGLETON_STORE with type value := int32 - -module Levels_to_hashes : - INDEXABLE_STORE with type key := int32 and type value := Block_hash.t - -(** Published slot headers per block hash, - stored as a list of bindings from [Dal_slot_index.t] - to [Dal.Slot.t]. The encoding function converts this - list into a [Dal.Slot_index.t]-indexed map. *) -module Dal_slots_headers : - Store_sigs.Nested_map - with type primary_key := Block_hash.t - and type secondary_key := Dal.Slot_index.t - and type value := Dal.Slot.Header.t - and type 'a store := 'a Irmin_store.t - -module Dal_confirmed_slots_history : - Store_sigs.Append_only_map - with type key := Block_hash.t - and type value := Dal.Slots_history.t - and type 'a store := 'a Irmin_store.t - -(** Confirmed DAL slots histories cache. See documentation of - {!Dal_slot_repr.Slots_history} for more details. *) -module Dal_confirmed_slots_histories : - Store_sigs.Append_only_map - with type key := Block_hash.t - and type value := Dal.Slots_history.History_cache.t - and type 'a store := 'a Irmin_store.t - -(** [Dal_slot_pages] is a [Store_utils.Nested_map] used to store the contents - of dal slots fetched by the rollup node, as a list of pages. The values of - this storage module have type `string list`. A value of the form - [page_contents] refers to a page of a slot that has been confirmed, and - whose contents are [page_contents]. -*) -module Dal_slot_pages : - Store_sigs.Nested_map - with type primary_key := Block_hash.t - and type secondary_key := Dal.Slot_index.t * Dal.Page.Index.t - and type value := Dal.Page.content - and type 'a store := 'a Irmin_store.t - -(** [Dal_processed_slots] is a [Store_utils.Nested_map] used to store the processing - status of dal slots content fetched by the rollup node. The values of - this storage module have type `[`Confirmed | `Unconfirmed]`, depending on - whether the content of the slot has been confirmed or not. If an entry is - not present for a [(block_hash, slot_index)], this either means that it's - not processed yet. -*) -module Dal_processed_slots : - Store_sigs.Nested_map - with type primary_key := Block_hash.t - and type secondary_key := Dal.Slot_index.t - and type value := [`Confirmed | `Unconfirmed] - and type 'a store := 'a Irmin_store.t - -type +'a store = { - l2_blocks : 'a L2_blocks.t; - messages : 'a Messages.t; - inboxes : 'a Inboxes.t; - commitments : 'a Commitments.t; - commitments_published_at_level : 'a Commitments_published_at_level.t; - l2_head : 'a L2_head.t; - last_finalized_level : 'a Last_finalized_level.t; - levels_to_hashes : 'a Levels_to_hashes.t; - irmin_store : 'a Irmin_store.t; -} - -include Store_sig.S with type 'a store := 'a store diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/store_v1.ml b/src/proto_017_PtNairob/lib_sc_rollup_node/store_v1.ml deleted file mode 100644 index adecbb8a2b5b62a821ecfa369413cf481e2e5348..0000000000000000000000000000000000000000 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/store_v1.ml +++ /dev/null @@ -1,253 +0,0 @@ -(*****************************************************************************) -(* *) -(* Open Source License *) -(* Copyright (c) 2021 Nomadic Labs, *) -(* Copyright (c) 2023 Functori, *) -(* *) -(* 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. *) -(* *) -(*****************************************************************************) - -open Protocol -open Alpha_context -include Store_sigs -include Store_utils -include Store_v0 - -let version = Store_version.V1 - -module Make_hash_index_key (H : Environment.S.HASH) = -Indexed_store.Make_index_key (struct - include Indexed_store.Make_fixed_encodable (H) - - let equal = H.equal -end) - -(** Unaggregated messages per block *) -module Messages = - Indexed_store.Make_indexed_file - (struct - let name = "messages" - end) - (Make_hash_index_key (Sc_rollup.Inbox_merkelized_payload_hashes.Hash)) - (struct - type t = Sc_rollup.Inbox_message.t list - - let name = "messages_list" - - let encoding = - Data_encoding.(list @@ dynamic_size Sc_rollup.Inbox_message.encoding) - - module Header = struct - type t = bool * Block_hash.t * Timestamp.t * int - - let name = "messages_inbox_info" - - let encoding = - let open Data_encoding in - obj4 - (req "is_first_block" bool) - (req "predecessor" Block_hash.encoding) - (req "predecessor_timestamp" Timestamp.encoding) - (req "num_messages" int31) - - let fixed_size = - WithExceptions.Option.get ~loc:__LOC__ - @@ Data_encoding.Binary.fixed_length encoding - end - end) - -module Dal_pages = struct - type removed_in_v1 -end - -module Dal_processed_slots = struct - type removed_in_v1 -end - -(** Store attestation statuses for DAL slots on L1. *) -module Dal_slots_statuses = - Irmin_store.Make_nested_map - (struct - let path = ["dal"; "slots_statuses"] - end) - (struct - type key = Block_hash.t - - let to_path_representation = Block_hash.to_b58check - end) - (struct - type key = Dal.Slot_index.t - - let encoding = Dal.Slot_index.encoding - - let compare = Dal.Slot_index.compare - - let name = "slot_index" - end) - (struct - (* TODO: https://gitlab.com/tezos/tezos/-/issues/4780. - - Rename Confirm-ed/ation to Attest-ed/ation in the rollup node. *) - type value = [`Confirmed | `Unconfirmed] - - let name = "slot_status" - - let encoding = - (* We don't use - Data_encoding.string_enum because a union is more storage-efficient. *) - let open Data_encoding in - union - ~tag_size:`Uint8 - [ - case - ~title:"Confirmed" - (Tag 0) - (obj1 (req "kind" (constant "Confirmed"))) - (function `Confirmed -> Some () | `Unconfirmed -> None) - (fun () -> `Confirmed); - case - ~title:"Unconfirmed" - (Tag 1) - (obj1 (req "kind" (constant "Unconfirmed"))) - (function `Unconfirmed -> Some () | `Confirmed -> None) - (fun () -> `Unconfirmed); - ] - end) - -type nonrec 'a store = { - l2_blocks : 'a L2_blocks.t; - messages : 'a Messages.t; - inboxes : 'a Inboxes.t; - commitments : 'a Commitments.t; - commitments_published_at_level : 'a Commitments_published_at_level.t; - l2_head : 'a L2_head.t; - last_finalized_level : 'a Last_finalized_level.t; - levels_to_hashes : 'a Levels_to_hashes.t; - irmin_store : 'a Irmin_store.t; -} - -type 'a t = ([< `Read | `Write > `Read] as 'a) store - -type rw = Store_sigs.rw t - -type ro = Store_sigs.ro t - -let readonly - ({ - l2_blocks; - messages; - inboxes; - commitments; - commitments_published_at_level; - l2_head; - last_finalized_level; - levels_to_hashes; - irmin_store; - } : - _ t) : ro = - { - l2_blocks = L2_blocks.readonly l2_blocks; - messages = Messages.readonly messages; - inboxes = Inboxes.readonly inboxes; - commitments = Commitments.readonly commitments; - commitments_published_at_level = - Commitments_published_at_level.readonly commitments_published_at_level; - l2_head = L2_head.readonly l2_head; - last_finalized_level = Last_finalized_level.readonly last_finalized_level; - levels_to_hashes = Levels_to_hashes.readonly levels_to_hashes; - irmin_store = Irmin_store.readonly irmin_store; - } - -let close - ({ - l2_blocks; - messages; - inboxes; - commitments; - commitments_published_at_level; - l2_head = _; - last_finalized_level = _; - levels_to_hashes; - irmin_store; - } : - _ t) = - let open Lwt_result_syntax in - let+ () = L2_blocks.close l2_blocks - and+ () = Messages.close messages - and+ () = Inboxes.close inboxes - and+ () = Commitments.close commitments - and+ () = Commitments_published_at_level.close commitments_published_at_level - and+ () = Levels_to_hashes.close levels_to_hashes - and+ () = Irmin_store.close irmin_store in - () - -let load (type a) (mode : a mode) ~l2_blocks_cache_size data_dir : - a store tzresult Lwt.t = - let open Lwt_result_syntax in - let path name = Filename.concat data_dir name in - let cache_size = l2_blocks_cache_size in - let* l2_blocks = L2_blocks.load mode ~path:(path "l2_blocks") ~cache_size in - let* messages = Messages.load mode ~path:(path "messages") ~cache_size in - let* inboxes = Inboxes.load mode ~path:(path "inboxes") ~cache_size in - let* commitments = Commitments.load mode ~path:(path "commitments") in - let* commitments_published_at_level = - Commitments_published_at_level.load - mode - ~path:(path "commitments_published_at_level") - in - let* l2_head = L2_head.load mode ~path:(path "l2_head") in - let* last_finalized_level = - Last_finalized_level.load mode ~path:(path "last_finalized_level") - in - let* levels_to_hashes = - Levels_to_hashes.load mode ~path:(path "levels_to_hashes") - in - let+ irmin_store = Irmin_store.load mode (path "irmin_store") in - { - l2_blocks; - messages; - inboxes; - commitments; - commitments_published_at_level; - l2_head; - last_finalized_level; - levels_to_hashes; - irmin_store; - } - -let iter_l2_blocks ({l2_blocks; l2_head; _} : _ t) f = - let open Lwt_result_syntax in - let* head = L2_head.read l2_head in - match head with - | None -> - (* No reachable head, nothing to do *) - return_unit - | Some head -> - let rec loop hash = - let* block = L2_blocks.read l2_blocks hash in - match block with - | None -> - (* The block does not exist, the known chain stops here, so do we. *) - return_unit - | Some (block, header) -> - let* () = f {block with header} in - loop header.predecessor - in - loop head.header.block_hash diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/store_v1.mli b/src/proto_017_PtNairob/lib_sc_rollup_node/store_v1.mli deleted file mode 100644 index 7662907121003367f4bdf443fb185008a1db33cc..0000000000000000000000000000000000000000 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/store_v1.mli +++ /dev/null @@ -1,79 +0,0 @@ -(*****************************************************************************) -(* *) -(* Open Source License *) -(* Copyright (c) 2022 Nomadic Labs, *) -(* Copyright (c) 2023 Functori, *) -(* *) -(* 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. *) -(* *) -(*****************************************************************************) - -(** This version of the store is used for the rollup nodes for protocols for and - after Nairobi, i.e. >= 17. *) - -open Protocol -open Alpha_context -open Indexed_store - -include module type of struct - include Store_v0 -end - -(** Storage for persisting messages downloaded from the L1 node. *) -module Messages : - INDEXED_FILE - with type key := Sc_rollup.Inbox_merkelized_payload_hashes.Hash.t - and type value := Sc_rollup.Inbox_message.t list - and type header := bool * Block_hash.t * Timestamp.t * int - -module Dal_pages : sig - type removed_in_v1 -end - -module Dal_processed_slots : sig - type removed_in_v1 -end - -(** [Dal_slots_statuses] is a [Store_utils.Nested_map] used to store the - attestation status of DAL slots. The values of this storage module have type - `[`Confirmed | `Unconfirmed]`, depending on whether the content of the slot - has been attested on L1 or not. If an entry is not present for a - [(block_hash, slot_index)], this means that the corresponding block is not - processed yet. -*) -module Dal_slots_statuses : - Store_sigs.Nested_map - with type primary_key := Block_hash.t - and type secondary_key := Dal.Slot_index.t - and type value := [`Confirmed | `Unconfirmed] - and type 'a store := 'a Irmin_store.t - -type +'a store = { - l2_blocks : 'a L2_blocks.t; - messages : 'a Messages.t; - inboxes : 'a Inboxes.t; - commitments : 'a Commitments.t; - commitments_published_at_level : 'a Commitments_published_at_level.t; - l2_head : 'a L2_head.t; - last_finalized_level : 'a Last_finalized_level.t; - levels_to_hashes : 'a Levels_to_hashes.t; - irmin_store : 'a Irmin_store.t; -} - -include Store_sig.S with type 'a store := 'a store diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/store_v2.ml b/src/proto_017_PtNairob/lib_sc_rollup_node/store_v2.ml deleted file mode 100644 index 18b77336aa55753bbe7453796b9182a5bda1fec2..0000000000000000000000000000000000000000 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/store_v2.ml +++ /dev/null @@ -1,330 +0,0 @@ -(*****************************************************************************) -(* *) -(* Open Source License *) -(* Copyright (c) 2021 Nomadic Labs, *) -(* Copyright (c) 2023 Functori, *) -(* *) -(* 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. *) -(* *) -(*****************************************************************************) - -open Protocol -open Alpha_context -include Store_sigs -include Store_utils -include Store_v1 - -let version = Store_version.V2 - -module Make_hash_index_key (H : Environment.S.HASH) = -Indexed_store.Make_index_key (struct - include Indexed_store.Make_fixed_encodable (H) - - let equal = H.equal -end) - -(** Unaggregated messages per block *) -module Messages = - Indexed_store.Make_indexed_file - (struct - let name = "messages" - end) - (Make_hash_index_key (Sc_rollup.Inbox_merkelized_payload_hashes.Hash)) - (struct - type t = Sc_rollup.Inbox_message.t list - - let name = "messages_list" - - let encoding = - Data_encoding.(list @@ dynamic_size Sc_rollup.Inbox_message.encoding) - - module Header = struct - type t = Block_hash.t - - let name = "messages_block" - - let encoding = Block_hash.encoding - - let fixed_size = - WithExceptions.Option.get ~loc:__LOC__ - @@ Data_encoding.Binary.fixed_length encoding - end - end) - -module Empty_header = struct - type t = unit - - let name = "empty" - - let encoding = Data_encoding.unit - - let fixed_size = 0 -end - -module Add_empty_header = struct - module Header = Empty_header - - let header _ = () -end - -(** Versioned inboxes *) -module Inboxes = - Indexed_store.Make_simple_indexed_file - (struct - let name = "inboxes" - end) - (Make_hash_index_key (Sc_rollup.Inbox.Hash)) - (struct - type t = Sc_rollup.Inbox.t - - let to_repr inbox = - inbox - |> Data_encoding.Binary.to_string_exn Sc_rollup.Inbox.encoding - |> Data_encoding.Binary.of_string_exn Sc_rollup_inbox_repr.encoding - - let of_repr inbox = - inbox - |> Data_encoding.Binary.to_string_exn Sc_rollup_inbox_repr.encoding - |> Data_encoding.Binary.of_string_exn Sc_rollup.Inbox.encoding - - let encoding = - Data_encoding.conv - (fun x -> to_repr x |> Sc_rollup_inbox_repr.to_versioned) - (fun x -> Sc_rollup_inbox_repr.of_versioned x |> of_repr) - Sc_rollup_inbox_repr.versioned_encoding - - let name = "inbox" - - include Add_empty_header - end) - -(** Versioned commitments *) -module Commitments = - Indexed_store.Make_simple_indexed_file - (struct - let name = "commitments" - end) - (Make_hash_index_key (Sc_rollup.Commitment.Hash)) - (struct - type t = Sc_rollup.Commitment.t - - let to_repr commitment = - commitment - |> Data_encoding.Binary.to_string_exn Sc_rollup.Commitment.encoding - |> Data_encoding.Binary.of_string_exn Sc_rollup_commitment_repr.encoding - - let of_repr commitment = - commitment - |> Data_encoding.Binary.to_string_exn Sc_rollup_commitment_repr.encoding - |> Data_encoding.Binary.of_string_exn Sc_rollup.Commitment.encoding - - let encoding = - Data_encoding.conv - (fun x -> to_repr x |> Sc_rollup_commitment_repr.to_versioned) - (fun x -> Sc_rollup_commitment_repr.of_versioned x |> of_repr) - Sc_rollup_commitment_repr.versioned_encoding - - let name = "commitment" - - include Add_empty_header - end) - -module Protocols = struct - type level = First_known of int32 | Activation_level of int32 - - type proto_info = { - level : level; - proto_level : int; - protocol : Protocol_hash.t; - } - - type value = proto_info list - - let level_encoding = - let open Data_encoding in - conv - (function First_known l -> (l, false) | Activation_level l -> (l, true)) - (function l, false -> First_known l | l, true -> Activation_level l) - @@ obj2 (req "level" int32) (req "activates" bool) - - let proto_info_encoding = - let open Data_encoding in - conv - (fun {level; proto_level; protocol} -> (level, proto_level, protocol)) - (fun (level, proto_level, protocol) -> {level; proto_level; protocol}) - @@ obj3 - (req "level" level_encoding) - (req "proto_level" int31) - (req "protocol" Protocol_hash.encoding) - - include Indexed_store.Make_singleton (struct - type t = value - - let name = "protocols" - - let level_encoding = - let open Data_encoding in - conv - (function - | First_known l -> (l, false) | Activation_level l -> (l, true)) - (function l, false -> First_known l | l, true -> Activation_level l) - @@ obj2 (req "level" int32) (req "activates" bool) - - let proto_info_encoding = - let open Data_encoding in - conv - (fun {level; proto_level; protocol} -> (level, proto_level, protocol)) - (fun (level, proto_level, protocol) -> {level; proto_level; protocol}) - @@ obj3 - (req "level" level_encoding) - (req "proto_level" int31) - (req "protocol" Protocol_hash.encoding) - - let encoding = Data_encoding.list proto_info_encoding - end) -end - -type 'a store = { - l2_blocks : 'a L2_blocks.t; - messages : 'a Messages.t; - inboxes : 'a Inboxes.t; - commitments : 'a Commitments.t; - commitments_published_at_level : 'a Commitments_published_at_level.t; - l2_head : 'a L2_head.t; - last_finalized_level : 'a Last_finalized_level.t; - levels_to_hashes : 'a Levels_to_hashes.t; - protocols : 'a Protocols.t; - irmin_store : 'a Irmin_store.t; -} - -type 'a t = ([< `Read | `Write > `Read] as 'a) store - -type rw = Store_sigs.rw t - -type ro = Store_sigs.ro t - -let readonly - ({ - l2_blocks; - messages; - inboxes; - commitments; - commitments_published_at_level; - l2_head; - last_finalized_level; - levels_to_hashes; - protocols; - irmin_store; - } : - _ t) : ro = - { - l2_blocks = L2_blocks.readonly l2_blocks; - messages = Messages.readonly messages; - inboxes = Inboxes.readonly inboxes; - commitments = Commitments.readonly commitments; - commitments_published_at_level = - Commitments_published_at_level.readonly commitments_published_at_level; - l2_head = L2_head.readonly l2_head; - last_finalized_level = Last_finalized_level.readonly last_finalized_level; - levels_to_hashes = Levels_to_hashes.readonly levels_to_hashes; - protocols = Protocols.readonly protocols; - irmin_store = Irmin_store.readonly irmin_store; - } - -let close - ({ - l2_blocks; - messages; - inboxes; - commitments; - commitments_published_at_level; - l2_head = _; - last_finalized_level = _; - levels_to_hashes; - protocols = _; - irmin_store; - } : - _ t) = - let open Lwt_result_syntax in - let+ () = L2_blocks.close l2_blocks - and+ () = Messages.close messages - and+ () = Inboxes.close inboxes - and+ () = Commitments.close commitments - and+ () = Commitments_published_at_level.close commitments_published_at_level - and+ () = Levels_to_hashes.close levels_to_hashes - and+ () = Irmin_store.close irmin_store in - () - -let load (type a) (mode : a mode) ~l2_blocks_cache_size data_dir : - a store tzresult Lwt.t = - let open Lwt_result_syntax in - let path name = Filename.concat data_dir name in - let cache_size = l2_blocks_cache_size in - let* l2_blocks = L2_blocks.load mode ~path:(path "l2_blocks") ~cache_size in - let* messages = Messages.load mode ~path:(path "messages") ~cache_size in - let* inboxes = Inboxes.load mode ~path:(path "inboxes") ~cache_size in - let* commitments = - Commitments.load mode ~path:(path "commitments") ~cache_size - in - let* commitments_published_at_level = - Commitments_published_at_level.load - mode - ~path:(path "commitments_published_at_level") - in - let* l2_head = L2_head.load mode ~path:(path "l2_head") in - let* last_finalized_level = - Last_finalized_level.load mode ~path:(path "last_finalized_level") - in - let* levels_to_hashes = - Levels_to_hashes.load mode ~path:(path "levels_to_hashes") - in - let* protocols = Protocols.load mode ~path:(path "protocols") in - let+ irmin_store = Irmin_store.load mode (path "irmin_store") in - { - l2_blocks; - messages; - inboxes; - commitments; - commitments_published_at_level; - l2_head; - last_finalized_level; - levels_to_hashes; - protocols; - irmin_store; - } - -let iter_l2_blocks ({l2_blocks; l2_head; _} : _ t) f = - let open Lwt_result_syntax in - let* head = L2_head.read l2_head in - match head with - | None -> - (* No reachable head, nothing to do *) - return_unit - | Some head -> - let rec loop hash = - let* block = L2_blocks.read l2_blocks hash in - match block with - | None -> - (* The block does not exist, the known chain stops here, so do we. *) - return_unit - | Some (block, header) -> - let* () = f {block with header} in - loop header.predecessor - in - loop head.header.block_hash diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/store_v2.mli b/src/proto_017_PtNairob/lib_sc_rollup_node/store_v2.mli deleted file mode 100644 index fb8e1bc4313f3031b7e63f1e50bb4bced2439170..0000000000000000000000000000000000000000 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/store_v2.mli +++ /dev/null @@ -1,94 +0,0 @@ -(*****************************************************************************) -(* *) -(* Open Source License *) -(* Copyright (c) 2022 Nomadic Labs, *) -(* Copyright (c) 2023 Functori, *) -(* *) -(* 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. *) -(* *) -(*****************************************************************************) - -(** This version of the store is used for the rollup nodes for protocols for and - after Nairobi, i.e. >= 17. *) - -open Protocol -open Alpha_context -open Indexed_store - -include module type of struct - include Store_v1 -end - -(** Storage for persisting messages downloaded from the L1 node. *) -module Messages : - INDEXED_FILE - with type key := Sc_rollup.Inbox_merkelized_payload_hashes.Hash.t - and type value := Sc_rollup.Inbox_message.t list - and type header := Block_hash.t - -(** Storage for persisting inboxes. *) -module Inboxes : - SIMPLE_INDEXED_FILE - with type key := Sc_rollup.Inbox.Hash.t - and type value := Sc_rollup.Inbox.t - and type header := unit - -(** Storage containing commitments and corresponding commitment hashes that the - rollup node has knowledge of. *) -module Commitments : - SIMPLE_INDEXED_FILE - with type key := Sc_rollup.Commitment.Hash.t - and type value := Sc_rollup.Commitment.t - and type header := unit - -module Protocols : sig - type level = First_known of int32 | Activation_level of int32 - - (** Each element of this type represents information we have about a Tezos - protocol regarding its activation. *) - type proto_info = { - level : level; - (** The level at which we have seen the protocol for the first time, - either because we saw its activation or because the first block we - saw (at the origination of the rollup) was from this protocol. *) - proto_level : int; - (** The protocol level, i.e. its number in the sequence of protocol - activations on the chain. *) - protocol : Protocol_hash.t; (** The protocol this information concerns. *) - } - - val proto_info_encoding : proto_info Data_encoding.t - - include SINGLETON_STORE with type value = proto_info list -end - -type +'a store = { - l2_blocks : 'a L2_blocks.t; - messages : 'a Messages.t; - inboxes : 'a Inboxes.t; - commitments : 'a Commitments.t; - commitments_published_at_level : 'a Commitments_published_at_level.t; - l2_head : 'a L2_head.t; - last_finalized_level : 'a Last_finalized_level.t; - levels_to_hashes : 'a Levels_to_hashes.t; - protocols : 'a Protocols.t; - irmin_store : 'a Irmin_store.t; -} - -include Store_sig.S with type 'a store := 'a store diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/store_version.ml b/src/proto_017_PtNairob/lib_sc_rollup_node/store_version.ml deleted file mode 100644 index db71f628911302ba849e2d0fdec8895320b2db1b..0000000000000000000000000000000000000000 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/store_version.ml +++ /dev/null @@ -1,61 +0,0 @@ -(*****************************************************************************) -(* *) -(* Open Source License *) -(* Copyright (c) 2023 Functori, *) -(* *) -(* 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. *) -(* *) -(*****************************************************************************) - -type t = V0 | V1 | V2 - -let pp ppf v = - Format.pp_print_string ppf - @@ match v with V0 -> "v0" | V1 -> "v1" | V2 -> "v2" - -let encoding = - let open Data_encoding in - conv - (function V0 -> 0 | V1 -> 1 | V2 -> 2) - (function - | 0 -> V0 - | 1 -> V1 - | 2 -> V2 - | v -> Format.ksprintf Stdlib.failwith "Unsupported store version %d" v) - (obj1 (req "store_version" int31)) - -let path ~dir = Filename.concat dir "version" - -let read_version_file ~dir = - let open Lwt_result_syntax in - protect @@ fun () -> - let filename = path ~dir in - let*! exists = Lwt_unix.file_exists filename in - if not exists then return_none - else - let* json = Lwt_utils_unix.Json.read_file filename in - return_some (Data_encoding.Json.destruct encoding json) - -let write_version_file ~dir version = - let open Lwt_result_syntax in - protect @@ fun () -> - let filename = path ~dir in - let*! () = Lwt_utils_unix.create_dir dir in - let json = Data_encoding.Json.construct encoding version in - Lwt_utils_unix.Json.write_file filename json diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/store_version.mli b/src/proto_017_PtNairob/lib_sc_rollup_node/store_version.mli deleted file mode 100644 index 1f2f8b4a26cc96d70357839ccee9be8f7a91acfb..0000000000000000000000000000000000000000 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/store_version.mli +++ /dev/null @@ -1,35 +0,0 @@ -(*****************************************************************************) -(* *) -(* Open Source License *) -(* Copyright (c) 2023 Functori, *) -(* *) -(* 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. *) -(* *) -(*****************************************************************************) - -type t = V0 | V1 | V2 - -(** Pretty-printer for store versions *) -val pp : Format.formatter -> t -> unit - -(** Read the version file from [dir]. *) -val read_version_file : dir:string -> t option tzresult Lwt.t - -(** Write a version to the version file in [dir]. *) -val write_version_file : dir:string -> t -> unit tzresult Lwt.t diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/test/canary.ml b/src/proto_017_PtNairob/lib_sc_rollup_node/test/canary.ml index 711bd74bffb01fadd4ac49271bcd8d3140567fda..4aa0a8575fc979226a21743ead462e1a91a30cf5 100644 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/test/canary.ml +++ b/src/proto_017_PtNairob/lib_sc_rollup_node/test/canary.ml @@ -31,6 +31,7 @@ Subject: Canary unit tests to make sure the test helpers work as intended *) +open Octez_smart_rollup open Protocol.Alpha_context let build_chain node_ctxt ~genesis ~length = @@ -55,9 +56,7 @@ let canary_test node_ctxt ~genesis = Node_context.get_l2_block node_ctxt block.header.block_hash in let* store_block_by_level = - Node_context.get_l2_block_by_level - node_ctxt - (Raw_level.to_int32 block.header.level) + Node_context.get_l2_block_by_level node_ctxt block.header.level in Helpers.Assert.L2_block.equal ~loc:__LOC__ diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/test/helpers/helpers.ml b/src/proto_017_PtNairob/lib_sc_rollup_node/test/helpers/helpers.ml index 9299b441332c34bb7bc89836491e9d3b7bd60696..ce6ecd282b50126157c46c359a789588dd2295c8 100644 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/test/helpers/helpers.ml +++ b/src/proto_017_PtNairob/lib_sc_rollup_node/test/helpers/helpers.ml @@ -23,6 +23,7 @@ (* *) (*****************************************************************************) +open Octez_smart_rollup open Protocol open Alpha_context @@ -83,12 +84,22 @@ let add_l2_genesis_block (node_ctxt : _ Node_context.t) ~boot_sector = ~genesis_state_hash in let* commitment_hash = Node_context.save_commitment node_ctxt commitment in - let previous_commitment_hash = node_ctxt.genesis_info.commitment_hash in + let previous_commitment_hash = + node_ctxt.genesis_info.commitment_hash + |> Sc_rollup_proto_types.Commitment_hash.to_octez + in + let commitment_hash = + Sc_rollup_proto_types.Commitment_hash.to_octez commitment_hash + in + let inbox_witness = + Sc_rollup_proto_types.Merkelized_payload_hashes_hash.to_octez inbox_witness + in + let inbox_hash = Sc_rollup_proto_types.Inbox_hash.to_octez inbox_hash in let header = Sc_rollup_block. { block_hash = head.hash; - level = node_ctxt.genesis_info.level; + level = Raw_level.to_int32 node_ctxt.genesis_info.level; predecessor = predecessor.hash; commitment_hash = Some commitment_hash; previous_commitment_hash; @@ -98,7 +109,13 @@ let add_l2_genesis_block (node_ctxt : _ Node_context.t) ~boot_sector = } in let l2_block = - Sc_rollup_block.{header; content = (); num_ticks; initial_tick} + Sc_rollup_block. + { + header; + content = (); + num_ticks; + initial_tick = Sc_rollup.Tick.to_z initial_tick; + } in let* () = Node_context.save_l2_head node_ctxt l2_block in return l2_block @@ -135,6 +152,7 @@ let initialize_node_context ?(constants = default_constants) kind ~boot_sector = let* genesis = add_l2_genesis_block ctxt ~boot_sector in let commitment_hash = WithExceptions.Option.get ~loc:__LOC__ genesis.header.commitment_hash + |> Sc_rollup_proto_types.Commitment_hash.of_octez in let ctxt = {ctxt with genesis_info = {ctxt.genesis_info with commitment_hash}} @@ -182,7 +200,7 @@ let append_l2_block (node_ctxt : _ Node_context.t) ?(is_first_block = false) | None -> failwith "No genesis block, please add one with add_l2_genesis_block" in - let pred_level = Raw_level.to_int32 predecessor_l2_block.header.level in + let pred_level = predecessor_l2_block.header.level in let predecessor = head_of_level ~predecessor:predecessor_l2_block.header.predecessor @@ -205,9 +223,7 @@ let append_dummy_l2_chain node_ctxt ~length = let open Lwt_result_syntax in let* head = Node_context.last_processed_head_opt node_ctxt in let head_level = - match head with - | None -> 0 - | Some h -> h.header.level |> Raw_level.to_int32 |> Int32.to_int + match head with None -> 0 | Some h -> h.header.level |> Int32.to_int in let batches = Stdlib.List.init length (fun i -> diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/test/helpers/helpers.mli b/src/proto_017_PtNairob/lib_sc_rollup_node/test/helpers/helpers.mli index 6f2035aefe24db787122872a049e94c679c67f76..b6571220f74a7fe518c03d6ed1c25b4fb7d98451 100644 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/test/helpers/helpers.mli +++ b/src/proto_017_PtNairob/lib_sc_rollup_node/test/helpers/helpers.mli @@ -23,6 +23,7 @@ (* *) (*****************************************************************************) +open Octez_smart_rollup open Protocol open Alpha_context diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/test/test_octez_conversions.ml b/src/proto_017_PtNairob/lib_sc_rollup_node/test/test_octez_conversions.ml index 9a27026ae3ad700cc283c2e6c3ad6f3249f26a8f..f099fdb8e4ffa7edb7b1ee3ef84a99dcc5e0cfa2 100644 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/test/test_octez_conversions.ml +++ b/src/proto_017_PtNairob/lib_sc_rollup_node/test/test_octez_conversions.ml @@ -189,6 +189,67 @@ let gen_inbox = | Error e -> Stdlib.failwith (Format.asprintf "%a" Error_monad.pp_print_trace e)) +let gen_slot_index = + let open QCheck2.Gen in + graft_corners (int_bound 0xff) [0; 1; 2; 0xff] () + +let gen_page_index = + let open QCheck2.Gen in + let max = 0xfff / 2 in + graft_corners (int_bound max) [0; 1; 2; max] () + +let gen_slot_header_commitment = + let open QCheck2.Gen in + make_primitive + ~gen:(fun state -> + Tezos_crypto_dal.Cryptobox.Internal_for_tests.dummy_commitment ~state ()) + ~shrink:(fun _ -> Seq.empty) + +let gen_slot_header = + let open QCheck2.Gen in + let* published_level = gen_level in + let* index = gen_slot_index in + let+ commitment = gen_slot_header_commitment in + Octez_smart_rollup.Dal.Slot_header.{id = {published_level; index}; commitment} + +let compare_slot_header_id (s1 : Octez_smart_rollup.Dal.Slot_header.id) + (s2 : Octez_smart_rollup.Dal.Slot_header.id) = + let c = Int32.compare s1.published_level s2.published_level in + if c <> 0 then c else Int.compare s1.index s2.index + +let gen_slot_headers = + let open QCheck2.Gen in + let size = int_bound 50 in + let+ l = list_size size gen_slot_header in + List.sort + (fun (h1 : Octez_smart_rollup.Dal.Slot_header.t) + (h2 : Octez_smart_rollup.Dal.Slot_header.t) -> + compare_slot_header_id h1.id h2.id) + l + +let gen_slot_history = + let open Protocol.Alpha_context in + let open QCheck2.Gen in + let h = Dal.Slots_history.genesis in + let+ l = gen_slot_headers in + let l = List.map Sc_rollup_proto_types.Dal.Slot_header.of_octez l in + Dal.Slots_history.add_confirmed_slot_headers_no_cache h l |> function + | Error e -> + Stdlib.failwith (Format.asprintf "%a" Environment.Error_monad.pp_trace e) + | Ok v -> Sc_rollup_proto_types.Dal.Slot_history.to_octez v + +let gen_slot_history_cache = + let open Protocol.Alpha_context in + let open QCheck2.Gen in + let h = Dal.Slots_history.genesis in + let c = Dal.Slots_history.History_cache.empty ~capacity:Int64.max_int in + let+ l = gen_slot_headers in + let l = List.map Sc_rollup_proto_types.Dal.Slot_header.of_octez l in + Dal.Slots_history.add_confirmed_slot_headers h c l |> function + | Error e -> + Stdlib.failwith (Format.asprintf "%a" Environment.Error_monad.pp_trace e) + | Ok (_, c) -> Sc_rollup_proto_types.Dal.Slot_history_cache.to_octez c + let test_roundtrip ~count name gen to_octez from_octez octez_encoding proto_encoding = let test octez1 = @@ -306,6 +367,56 @@ let test_inbox = Octez_smart_rollup.Inbox.encoding Protocol.Alpha_context.Sc_rollup.Inbox.encoding +let test_slot_index = + test_roundtrip + ~count:100 + "dal_slot_index" + gen_slot_index + Sc_rollup_proto_types.Dal.Slot_index.to_octez + Sc_rollup_proto_types.Dal.Slot_index.of_octez + Octez_smart_rollup.Dal.Slot_index.encoding + Protocol.Alpha_context.Dal.Slot_index.encoding + +let test_page_index = + test_roundtrip + ~count:100 + "dal_page_index" + gen_page_index + Sc_rollup_proto_types.Dal.Page_index.to_octez + Sc_rollup_proto_types.Dal.Page_index.of_octez + Octez_smart_rollup.Dal.Page_index.encoding + Protocol.Alpha_context.Dal.Page.Index.encoding + +let test_slot_header = + test_roundtrip + ~count:1000 + "dal_slot_header" + gen_slot_header + Sc_rollup_proto_types.Dal.Slot_header.to_octez + Sc_rollup_proto_types.Dal.Slot_header.of_octez + Octez_smart_rollup.Dal.Slot_header.encoding + Protocol.Alpha_context.Dal.Slot.Header.encoding + +let test_slot_history = + test_roundtrip + ~count:300 + "dal_slot_history" + gen_slot_history + Sc_rollup_proto_types.Dal.Slot_history.to_octez + Sc_rollup_proto_types.Dal.Slot_history.of_octez + Octez_smart_rollup.Dal.Slot_history.encoding + Protocol.Alpha_context.Dal.Slots_history.encoding + +let test_slot_history_cache = + test_roundtrip + ~count:300 + "dal_slot_history_cache" + gen_slot_history_cache + Sc_rollup_proto_types.Dal.Slot_history_cache.to_octez + Sc_rollup_proto_types.Dal.Slot_history_cache.of_octez + Octez_smart_rollup.Dal.Slot_history_cache.encoding + Protocol.Alpha_context.Dal.Slots_history.History_cache.encoding + let tests = [ test_address; @@ -316,6 +427,11 @@ let tests = test_stakers; test_refutation; test_inbox; + test_slot_index; + test_page_index; + test_slot_header; + test_slot_history; + test_slot_history_cache; ] let () = diff --git a/src/proto_alpha/lib_sc_rollup_layer2/sc_rollup_block.ml b/src/proto_alpha/lib_sc_rollup_layer2/sc_rollup_block.ml deleted file mode 100644 index a5c25b817f13899df8a2c5aa8b30c30c78e21aac..0000000000000000000000000000000000000000 --- a/src/proto_alpha/lib_sc_rollup_layer2/sc_rollup_block.ml +++ /dev/null @@ -1,199 +0,0 @@ -(*****************************************************************************) -(* *) -(* 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. *) -(* *) -(*****************************************************************************) - -open Protocol -open Alpha_context - -type header = { - block_hash : Block_hash.t; - level : Raw_level.t; - predecessor : Block_hash.t; - commitment_hash : Sc_rollup.Commitment.Hash.t option; - previous_commitment_hash : Sc_rollup.Commitment.Hash.t; - context : Smart_rollup_context_hash.t; - inbox_witness : Sc_rollup.Inbox_merkelized_payload_hashes.Hash.t; - inbox_hash : Sc_rollup.Inbox.Hash.t; -} - -type content = { - inbox : Sc_rollup.Inbox.t; - messages : Sc_rollup.Inbox_message.t list; - commitment : Sc_rollup.Commitment.t option; -} - -type ('header, 'content) block = { - header : 'header; - content : 'content; - initial_tick : Sc_rollup.Tick.t; - num_ticks : int64; -} - -type t = (header, unit) block - -type full = (header, content) block - -let commitment_hash_opt_encoding = - let open Data_encoding in - let binary = - conv - (Option.value ~default:Sc_rollup.Commitment.Hash.zero) - (fun h -> if Sc_rollup.Commitment.Hash.(h = zero) then None else Some h) - Sc_rollup.Commitment.Hash.encoding - in - let json = option Sc_rollup.Commitment.Hash.encoding in - splitted ~binary ~json - -let header_encoding = - let open Data_encoding in - conv - (fun { - block_hash; - level; - predecessor; - commitment_hash; - previous_commitment_hash; - context; - inbox_witness; - inbox_hash; - } -> - ( block_hash, - level, - predecessor, - commitment_hash, - previous_commitment_hash, - context, - inbox_witness, - inbox_hash )) - (fun ( block_hash, - level, - predecessor, - commitment_hash, - previous_commitment_hash, - context, - inbox_witness, - inbox_hash ) -> - { - block_hash; - level; - predecessor; - commitment_hash; - previous_commitment_hash; - context; - inbox_witness; - inbox_hash; - }) - @@ obj8 - (req "block_hash" Block_hash.encoding ~description:"Tezos block hash.") - (req - "level" - Raw_level.encoding - ~description: - "Level of the block, corresponds to the level of the tezos block.") - (req - "predecessor" - Block_hash.encoding - ~description:"Predecessor hash of the Tezos block.") - (req - "commitment_hash" - commitment_hash_opt_encoding - ~description: - "Hash of this block's commitment if any was computed for it.") - (req - "previous_commitment_hash" - Sc_rollup.Commitment.Hash.encoding - ~description: - "Previous commitment hash in the chain. If there is a commitment \ - for this block, this field contains the commitment that was \ - previously computed.") - (req - "context" - Smart_rollup_context_hash.encoding - ~description:"Hash of the layer 2 context for this block.") - (req - "inbox_witness" - Sc_rollup.Inbox_merkelized_payload_hashes.Hash.encoding - ~description: - "Witness for the inbox for this block, i.e. the Merkle hash of \ - payloads of messages.") - (req - "inbox_hash" - Sc_rollup.Inbox.Hash.encoding - ~description:"Hash of the inbox for this block.") - -let header_size = - WithExceptions.Option.get ~loc:__LOC__ - @@ Data_encoding.Binary.fixed_length header_encoding - -let content_encoding = - let open Data_encoding in - conv - (fun {inbox; messages; commitment} -> (inbox, messages, commitment)) - (fun (inbox, messages, commitment) -> {inbox; messages; commitment}) - @@ obj3 - (req - "inbox" - Sc_rollup.Inbox.encoding - ~description:"Inbox for this block.") - (req - "messages" - (list (dynamic_size Sc_rollup.Inbox_message.encoding)) - ~description:"Messages added to the inbox in this block.") - (opt - "commitment" - Sc_rollup.Commitment.encoding - ~description:"Commitment, if any is computed for this block.") - -let block_encoding header_encoding content_encoding = - let open Data_encoding in - conv - (fun {header; content; initial_tick; num_ticks} -> - (header, (content, (initial_tick, num_ticks)))) - (fun (header, (content, (initial_tick, num_ticks))) -> - {header; content; initial_tick; num_ticks}) - @@ merge_objs header_encoding - @@ merge_objs content_encoding - @@ obj2 - (req - "initial_tick" - Sc_rollup.Tick.encoding - ~description: - "Initial tick of the PVM at this block, i.e. before evaluation of \ - the messages.") - (req - "num_ticks" - int64 - ~description: - "Number of ticks produced by the evaluation of the messages in \ - this block.") - -let encoding = block_encoding header_encoding Data_encoding.unit - -let full_encoding = block_encoding header_encoding content_encoding - -let most_recent_commitment (header : header) = - Option.value header.commitment_hash ~default:header.previous_commitment_hash - -let final_tick {initial_tick; num_ticks; _} = - Sc_rollup.Tick.jump initial_tick (Z.of_int64 num_ticks) diff --git a/src/proto_alpha/lib_sc_rollup_layer2/sc_rollup_block.mli b/src/proto_alpha/lib_sc_rollup_layer2/sc_rollup_block.mli deleted file mode 100644 index b575a5da9f52aaad5e2151bdbce9d4e5e9a4110b..0000000000000000000000000000000000000000 --- a/src/proto_alpha/lib_sc_rollup_layer2/sc_rollup_block.mli +++ /dev/null @@ -1,111 +0,0 @@ -(*****************************************************************************) -(* *) -(* 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. *) -(* *) -(*****************************************************************************) - -open Protocol -open Alpha_context - -(** {2 Structure of layer 2 blocks} *) - -(** A layer 2 block header contains information about the inbox and commitment - with respect to a layer 1 block, but without the inbox content of - messages. *) -type header = { - block_hash : Block_hash.t; (** Tezos block hash. *) - level : Raw_level.t; - (** Level of the block, corresponds to the level of the tezos block. *) - predecessor : Block_hash.t; (** Predecessor hash of the Tezos block. *) - commitment_hash : Sc_rollup.Commitment.Hash.t option; - (** Hash of this block's commitment if any was computed for it. *) - previous_commitment_hash : Sc_rollup.Commitment.Hash.t; - (** Previous commitment hash in the chain. If there is a commitment for this - block, this field contains the commitment that was previously - computed. *) - context : Smart_rollup_context_hash.t; - (** Hash of the layer 2 context for this block. *) - inbox_witness : Sc_rollup.Inbox_merkelized_payload_hashes.Hash.t; - (** Witness for the inbox for this block, i.e. the Merkle hash of payloads - of messages. *) - inbox_hash : Sc_rollup.Inbox.Hash.t; (** Hash of the inbox for this block. *) -} - -(** Contents of blocks which include the actual content of the inbox and - messages. *) -type content = { - inbox : Sc_rollup.Inbox.t; (** Inbox for this block. *) - messages : Sc_rollup.Inbox_message.t list; - (** Messages added to the inbox in this block. *) - commitment : Sc_rollup.Commitment.t option; - (** Commitment, if any is computed for this block. [header.commitment = - Some h] iff [commitment = Some c] and [hash c = h]. *) -} - -(** Block parameterized by a header and content. The parameters are here to - allow to split the header and rest of the block. *) -type ('header, 'content) block = { - header : 'header; (** Header of this block. *) - content : 'content; (** Content of the block. *) - initial_tick : Sc_rollup.Tick.t; - (** Initial tick of the PVM at this block, i.e. before evaluation of the - messages. *) - num_ticks : int64; - (** Number of ticks produced by the evaluation of the messages in this - block. *) -} - -(** The type of layer 2 blocks. This type corresponds to what is stored on disk - for L2 blocks. The contents is stored in separate tables because it can be - large to read is is not always necessary. *) -type t = (header, unit) block - -(** The type of layer 2 blocks including their content (inbox, messages, commitment). *) -type full = (header, content) block - -(** {2 Encodings} *) - -val header_encoding : header Data_encoding.t - -val header_size : int - -val content_encoding : content Data_encoding.t - -val block_encoding : - 'header Data_encoding.t -> - 'content Data_encoding.t -> - ('header, 'content) block Data_encoding.t - -val encoding : t Data_encoding.t - -val full_encoding : full Data_encoding.t - -(** {2 Helper functions} *) - -(** [most_recent_commitment header] returns the most recent commitment - information at the block of with [header]. It is either the commitment for - this block if there is one or the previous commitment otherwise. *) -val most_recent_commitment : header -> Sc_rollup.Commitment.Hash.t - -(** [final_tick block] is the final tick, after evaluation of the messages in - the [block], i.e. [block.initial_tick + block.num_ticks]. *) -val final_tick : ('a, 'b) block -> Sc_rollup.Tick.t diff --git a/src/proto_alpha/lib_sc_rollup_layer2/sc_rollup_proto_types.ml b/src/proto_alpha/lib_sc_rollup_layer2/sc_rollup_proto_types.ml index e30ee96557553dfb2fcf87d2f1581fb13fda801f..b94153ed4d8acd9f446ef89ac4712b7b3d37516a 100644 --- a/src/proto_alpha/lib_sc_rollup_layer2/sc_rollup_proto_types.ml +++ b/src/proto_alpha/lib_sc_rollup_layer2/sc_rollup_proto_types.ml @@ -236,3 +236,88 @@ module Kind = struct | Example_arith -> Example_arith | Wasm_2_0_0 -> Wasm_2_0_0 end + +module Dal = struct + module Slot_index = struct + type t = Dal.Slot_index.t + + let of_octez (i : Octez_smart_rollup.Dal.Slot_index.t) : t = + match Dal.Slot_index.of_int_opt i with + | None -> Format.ksprintf invalid_arg "Dal.Slot_index.of_octez: %d" i + | Some i -> i + + let to_octez : t -> Octez_smart_rollup.Dal.Slot_index.t = + Dal.Slot_index.to_int + end + + module Page_index = struct + type t = Dal.Page.Index.t + + let of_octez : Octez_smart_rollup.Dal.Page_index.t -> t = Fun.id + + let to_octez : t -> Octez_smart_rollup.Dal.Page_index.t = Fun.id + end + + module Slot_header = struct + type t = Dal.Slot.Header.t + + let of_octez + Octez_smart_rollup.Dal.Slot_header. + {id = {published_level; index}; commitment} : t = + Dal.Slot.Header. + { + id = + { + published_level = Raw_level.of_int32_exn published_level; + index = Slot_index.of_octez index; + }; + commitment; + } + + let to_octez Dal.Slot.Header.{id = {published_level; index}; commitment} : + Octez_smart_rollup.Dal.Slot_header.t = + Octez_smart_rollup.Dal.Slot_header. + { + id = + { + published_level = Raw_level.to_int32 published_level; + index = Slot_index.to_octez index; + }; + commitment; + } + end + + module Slot_history = struct + type t = Dal.Slots_history.t + + let of_octez (h : Octez_smart_rollup.Dal.Slot_history.t) : t = + h + |> Data_encoding.Binary.to_bytes_exn + Octez_smart_rollup.Dal.Slot_history.encoding + |> Data_encoding.Binary.of_bytes_exn Dal.Slots_history.encoding + + let to_octez (h : t) : Octez_smart_rollup.Dal.Slot_history.t = + h + |> Data_encoding.Binary.to_bytes_exn Dal.Slots_history.encoding + |> Data_encoding.Binary.of_bytes_exn + Octez_smart_rollup.Dal.Slot_history.encoding + end + + module Slot_history_cache = struct + type t = Dal.Slots_history.History_cache.t + + let of_octez (h : Octez_smart_rollup.Dal.Slot_history_cache.t) : t = + h + |> Data_encoding.Binary.to_bytes_exn + Octez_smart_rollup.Dal.Slot_history_cache.encoding + |> Data_encoding.Binary.of_bytes_exn + Dal.Slots_history.History_cache.encoding + + let to_octez (h : t) : Octez_smart_rollup.Dal.Slot_history_cache.t = + h + |> Data_encoding.Binary.to_bytes_exn + Dal.Slots_history.History_cache.encoding + |> Data_encoding.Binary.of_bytes_exn + Octez_smart_rollup.Dal.Slot_history_cache.encoding + end +end diff --git a/src/proto_alpha/lib_sc_rollup_layer2/sc_rollup_proto_types.mli b/src/proto_alpha/lib_sc_rollup_layer2/sc_rollup_proto_types.mli index d24bfcd9c6ee4dc4015473e5eab5a3561de48a10..905a7b7bde6dc484c26a08fdd5f47eaf8d4c951b 100644 --- a/src/proto_alpha/lib_sc_rollup_layer2/sc_rollup_proto_types.mli +++ b/src/proto_alpha/lib_sc_rollup_layer2/sc_rollup_proto_types.mli @@ -116,3 +116,45 @@ module Kind : sig val to_octez : t -> Octez_smart_rollup.Kind.t end + +module Dal : sig + module Slot_index : sig + type t = Dal.Slot_index.t + + val of_octez : Octez_smart_rollup.Dal.Slot_index.t -> t + + val to_octez : t -> Octez_smart_rollup.Dal.Slot_index.t + end + + module Page_index : sig + type t = Dal.Page.Index.t + + val of_octez : Octez_smart_rollup.Dal.Page_index.t -> t + + val to_octez : t -> Octez_smart_rollup.Dal.Page_index.t + end + + module Slot_header : sig + type t = Dal.Slot.Header.t + + val of_octez : Octez_smart_rollup.Dal.Slot_header.t -> t + + val to_octez : t -> Octez_smart_rollup.Dal.Slot_header.t + end + + module Slot_history : sig + type t = Dal.Slots_history.t + + val of_octez : Octez_smart_rollup.Dal.Slot_history.t -> t + + val to_octez : t -> Octez_smart_rollup.Dal.Slot_history.t + end + + module Slot_history_cache : sig + type t = Dal.Slots_history.History_cache.t + + val of_octez : Octez_smart_rollup.Dal.Slot_history_cache.t -> t + + val to_octez : t -> Octez_smart_rollup.Dal.Slot_history_cache.t + end +end diff --git a/src/proto_alpha/lib_sc_rollup_layer2/sc_rollup_services.ml b/src/proto_alpha/lib_sc_rollup_layer2/sc_rollup_services.ml index a6da8d1c06b43ad25be75fda95a3bfafe1ab104c..62664a971c3a37a5e7bca2e095468d650bbf3d6a 100644 --- a/src/proto_alpha/lib_sc_rollup_layer2/sc_rollup_services.ml +++ b/src/proto_alpha/lib_sc_rollup_layer2/sc_rollup_services.ml @@ -100,8 +100,8 @@ type message_status = cemented : bool; commitment : Sc_rollup.Commitment.t; commitment_hash : Sc_rollup.Commitment.Hash.t; - first_published_at_level : Raw_level.t; - published_at_level : Raw_level.t; + first_published_at_level : int32; + published_at_level : int32; } module Encodings = struct @@ -116,8 +116,8 @@ module Encodings = struct obj4 (req "commitment" Sc_rollup.Commitment.encoding) (req "hash" Sc_rollup.Commitment.Hash.encoding) - (opt "first_published_at_level" Raw_level.encoding) - (opt "published_at_level" Raw_level.encoding) + (opt "first_published_at_level" int32) + (opt "published_at_level" int32) let hex_string = conv Bytes.of_string Bytes.to_string bytes @@ -322,8 +322,8 @@ module Encodings = struct (req "cemented" bool) (req "commitment" Sc_rollup.Commitment.encoding) (req "hash" Sc_rollup.Commitment.Hash.encoding) - (req "first_published_at_level" Raw_level.encoding) - (req "published_at_level" Raw_level.encoding)) + (req "first_published_at_level" int32) + (req "published_at_level" int32)) (function | Committed { diff --git a/src/proto_alpha/lib_sc_rollup_node/RPC_server.ml b/src/proto_alpha/lib_sc_rollup_node/RPC_server.ml index a78d121505ed60ad6265ff4a339e8a0428173aeb..6f049377dd2ba8ec9eeb7d6876646a1497c070c0 100644 --- a/src/proto_alpha/lib_sc_rollup_node/RPC_server.ml +++ b/src/proto_alpha/lib_sc_rollup_node/RPC_server.ml @@ -39,10 +39,7 @@ let get_head_hash_opt node_ctxt = let get_head_level_opt node_ctxt = let open Lwt_result_syntax in let+ res = Node_context.last_processed_head_opt node_ctxt in - Option.map - (fun Sc_rollup_block.{header = {level; _}; _} -> - Alpha_context.Raw_level.to_int32 level) - res + Option.map (fun Sc_rollup_block.{header = {level; _}; _} -> level) res module Slot_pages_map = struct open Protocol @@ -125,7 +122,10 @@ module Common = struct let open Lwt_result_syntax in let* l2_block = Node_context.get_l2_block node_ctxt block in let+ num_messages = - Node_context.get_num_messages node_ctxt l2_block.header.inbox_witness + Node_context.get_num_messages + node_ctxt + (Sc_rollup_proto_types.Merkelized_payload_hashes_hash.of_octez + l2_block.header.inbox_witness) in Z.of_int num_messages @@ -272,6 +272,7 @@ let () = | Some head -> let commitment_hash = Sc_rollup_block.most_recent_commitment head.header + |> Sc_rollup_proto_types.Commitment_hash.of_octez in let+ commitment = Node_context.find_commitment node_ctxt commitment_hash @@ -460,6 +461,7 @@ let () = WithExceptions.Option.get ~loc:__LOC__ block.header.commitment_hash + |> Sc_rollup_proto_types.Commitment_hash.of_octez in (* Commitment computed *) let* published_at = diff --git a/src/proto_alpha/lib_sc_rollup_node/daemon.ml b/src/proto_alpha/lib_sc_rollup_node/daemon.ml index 99da547ba1932999215f444f536ba6f03c006f02..4c10d33d5f476fde6b48d2264f7c6175b5d1e1b6 100644 --- a/src/proto_alpha/lib_sc_rollup_node/daemon.ml +++ b/src/proto_alpha/lib_sc_rollup_node/daemon.ml @@ -42,6 +42,7 @@ let is_refutable_commitment node_ctxt let* our_commitment_and_hash = Option.filter_map_es (fun hash -> + let hash = Sc_rollup_proto_types.Commitment_hash.of_octez hash in let+ commitment = Node_context.find_commitment node_ctxt hash in Option.map (fun c -> (c, hash)) commitment) l2_block.header.commitment_hash @@ -102,8 +103,8 @@ let process_included_l1_operation (type kind) (node_ctxt : Node_context.rw) node_ctxt commitment_hash { - first_published_at_level = published_at_level; - published_at_level = Some (Raw_level.of_int32_exn head.Layer1.level); + first_published_at_level = Raw_level.to_int32 published_at_level; + published_at_level = Some head.Layer1.level; } in let*! () = @@ -136,7 +137,8 @@ let process_included_l1_operation (type kind) (node_ctxt : Node_context.rw) node_ctxt their_commitment_hash { - first_published_at_level = published_at_level; + first_published_at_level = + Raw_level.to_int32 published_at_level; published_at_level = None; } in @@ -160,17 +162,18 @@ let process_included_l1_operation (type kind) (node_ctxt : Node_context.rw) in let*? () = (* We stop the node if we disagree with a cemented commitment *) + let our_commitment_hash = + Option.map + Sc_rollup_proto_types.Commitment_hash.of_octez + inbox_block.header.commitment_hash + in error_unless (Option.equal Sc_rollup.Commitment.Hash.( = ) - inbox_block.header.commitment_hash + our_commitment_hash (Some commitment_hash)) (Sc_rollup_node_errors.Disagree_with_cemented - { - inbox_level; - ours = inbox_block.header.commitment_hash; - on_l1 = commitment_hash; - }) + {inbox_level; ours = our_commitment_hash; on_l1 = commitment_hash}) in let lcc = Reference.get node_ctxt.lcc in let*! () = @@ -355,6 +358,11 @@ let rec process_head (daemon_components : (module Daemon_components.S)) let* inbox_hash, inbox, inbox_witness, messages = Inbox.process_head node_ctxt ~predecessor head in + let inbox_witness = + Sc_rollup_proto_types.Merkelized_payload_hashes_hash.to_octez + inbox_witness + in + let inbox_hash = Sc_rollup_proto_types.Inbox_hash.to_octez inbox_hash in let* () = when_ (Node_context.dal_supported node_ctxt) @@ fun () -> Dal_slots_tracker.process_head node_ctxt (Layer1.head_of_header head) @@ -375,6 +383,11 @@ let rec process_head (daemon_components : (module Daemon_components.S)) let* commitment_hash = Publisher.process_head node_ctxt ~predecessor:predecessor.hash head ctxt in + let commitment_hash = + Option.map + Sc_rollup_proto_types.Commitment_hash.to_octez + commitment_hash + in let* () = unless (catching_up && Option.is_none commitment_hash) @@ fun () -> Inbox.same_as_layer_1 node_ctxt head.hash inbox @@ -383,7 +396,9 @@ let rec process_head (daemon_components : (module Daemon_components.S)) let* previous_commitment_hash = if level = node_ctxt.genesis_info.Sc_rollup.Commitment.level then (* Previous commitment for rollup genesis is itself. *) - return node_ctxt.genesis_info.Sc_rollup.Commitment.commitment_hash + return + (Sc_rollup_proto_types.Commitment_hash.to_octez + node_ctxt.genesis_info.Sc_rollup.Commitment.commitment_hash) else let+ pred = Node_context.get_l2_block node_ctxt predecessor.hash in Sc_rollup_block.most_recent_commitment pred.header @@ -392,7 +407,7 @@ let rec process_head (daemon_components : (module Daemon_components.S)) Sc_rollup_block. { block_hash = head.hash; - level; + level = head.level; predecessor = predecessor.hash; commitment_hash; previous_commitment_hash; @@ -402,7 +417,13 @@ let rec process_head (daemon_components : (module Daemon_components.S)) } in let l2_block = - Sc_rollup_block.{header; content = (); num_ticks; initial_tick} + Sc_rollup_block. + { + header; + content = (); + num_ticks; + initial_tick = Sc_rollup.Tick.to_z initial_tick; + } in let* () = Node_context.mark_finalized_level @@ -428,12 +449,7 @@ let on_layer_1_head (daemon_components : (module Daemon_components.S)) node_ctxt let old_head = match old_head with | Some h -> - `Head - Layer1. - { - hash = h.header.block_hash; - level = Raw_level.to_int32 h.header.level; - } + `Head Layer1.{hash = h.header.block_hash; level = h.header.level} | None -> (* if no head has been processed yet, we want to handle all blocks since, and including, the rollup origination. *) @@ -666,6 +682,11 @@ module Internal_for_tests = struct head messages in + let inbox_witness = + Sc_rollup_proto_types.Merkelized_payload_hashes_hash.to_octez + inbox_witness + in + let inbox_hash = Sc_rollup_proto_types.Inbox_hash.to_octez inbox_hash in let* ctxt, _num_messages, num_ticks, initial_tick = Interpreter.process_head node_ctxt ctxt ~predecessor head (inbox, messages) in @@ -677,11 +698,16 @@ module Internal_for_tests = struct head ctxt in + let commitment_hash = + Option.map Sc_rollup_proto_types.Commitment_hash.to_octez commitment_hash + in let level = Raw_level.of_int32_exn head.level in let* previous_commitment_hash = if level = node_ctxt.genesis_info.Sc_rollup.Commitment.level then (* Previous commitment for rollup genesis is itself. *) - return node_ctxt.genesis_info.Sc_rollup.Commitment.commitment_hash + return + (Sc_rollup_proto_types.Commitment_hash.to_octez + node_ctxt.genesis_info.Sc_rollup.Commitment.commitment_hash) else let+ pred = Node_context.get_l2_block node_ctxt predecessor.hash in Sc_rollup_block.most_recent_commitment pred.header @@ -690,7 +716,7 @@ module Internal_for_tests = struct Sc_rollup_block. { block_hash = head.hash; - level; + level = head.level; predecessor = predecessor.hash; commitment_hash; previous_commitment_hash; @@ -700,7 +726,13 @@ module Internal_for_tests = struct } in let l2_block = - Sc_rollup_block.{header; content = (); num_ticks; initial_tick} + Sc_rollup_block. + { + header; + content = (); + num_ticks; + initial_tick = Sc_rollup.Tick.to_z initial_tick; + } in let* () = Node_context.save_l2_head node_ctxt l2_block in return l2_block diff --git a/src/proto_alpha/lib_sc_rollup_node/interpreter.ml b/src/proto_alpha/lib_sc_rollup_node/interpreter.ml index 9cb8baaa7fac68eff29f52397c24cc333056efe1..06748f6e0f015513c80f7f506506ad9c24b33e21 100644 --- a/src/proto_alpha/lib_sc_rollup_node/interpreter.ml +++ b/src/proto_alpha/lib_sc_rollup_node/interpreter.ml @@ -168,7 +168,7 @@ let process_head (node_ctxt : _ Node_context.t) ctxt the messages the block ([remaining_messages]). *) let start_state_of_block node_ctxt (block : Sc_rollup_block.t) = let open Lwt_result_syntax in - let pred_level = Raw_level.to_int32 block.header.level |> Int32.pred in + let pred_level = Int32.pred block.header.level in let* ctxt = Node_context.checkout_context node_ctxt block.header.predecessor in @@ -178,9 +178,16 @@ let start_state_of_block node_ctxt (block : Sc_rollup_block.t) = ctxt Layer1.{hash = block.header.predecessor; level = pred_level} in - let* inbox = Node_context.get_inbox node_ctxt block.header.inbox_hash in + let* inbox = + Node_context.get_inbox + node_ctxt + (Sc_rollup_proto_types.Inbox_hash.of_octez block.header.inbox_hash) + in let* {is_first_block; predecessor; predecessor_timestamp; messages} = - Node_context.get_messages node_ctxt block.header.inbox_witness + Node_context.get_messages + node_ctxt + (Sc_rollup_proto_types.Merkelized_payload_hashes_hash.of_octez + block.header.inbox_witness) in let inbox_level = Sc_rollup.Inbox.inbox_level inbox in let module PVM = (val node_ctxt.pvm) in @@ -233,9 +240,8 @@ let state_of_tick_aux node_ctxt ~start_state (event : Sc_rollup_block.t) tick = let* start_state = match start_state with | Some start_state - when Raw_level.( - start_state.Fueled_pvm.Accounted.inbox_level = event.header.level) - -> + when Raw_level.to_int32 start_state.Fueled_pvm.Accounted.inbox_level + = event.header.level -> return start_state | _ -> (* Recompute start state on level change or if we don't have a @@ -284,7 +290,7 @@ let state_of_tick node_ctxt ?start_state tick level = match event with | None -> return_none | Some event -> - assert (Raw_level.(event.header.level <= level)) ; + assert (event.header.level <= Raw_level.to_int32 level) ; let* result_state = if Node_context.is_loser node_ctxt then (* TODO: https://gitlab.com/tezos/tezos/-/issues/5253 diff --git a/src/proto_alpha/lib_sc_rollup_node/node_context.ml b/src/proto_alpha/lib_sc_rollup_node/node_context.ml index cf29439317bdbe3fedfc764ca0de3c15394d6f0a..6ff6c05ff06dae0e4d193133595d5a6c165689ae 100644 --- a/src/proto_alpha/lib_sc_rollup_node/node_context.ml +++ b/src/proto_alpha/lib_sc_rollup_node/node_context.ml @@ -468,7 +468,7 @@ let level_of_hash {l1_ctxt; store; _} hash = let open Lwt_result_syntax in let* l2_header = Store.L2_blocks.header store.l2_blocks hash in match l2_header with - | Some {level; _} -> return (Raw_level.to_int32 level) + | Some {level; _} -> return level | None -> let+ {level; _} = Layer1.fetch_tezos_shell_header l1_ctxt hash in level @@ -544,7 +544,7 @@ let get_l2_block_predecessor node_ctxt hash = let+ header = Store.L2_blocks.header node_ctxt.store.l2_blocks hash in Option.map (fun {Sc_rollup_block.predecessor; level; _} -> - (predecessor, Int32.pred (Raw_level.to_int32 level))) + (predecessor, Int32.pred level)) header let get_predecessor_opt node_ctxt (hash, level) = @@ -616,8 +616,8 @@ let get_predecessor_header node_ctxt head = first look for a block before the [tick] *) let tick_search ~big_step_blocks node_ctxt head tick = let open Lwt_result_syntax in - if Sc_rollup.Tick.(head.Sc_rollup_block.initial_tick <= tick) then - if Sc_rollup.Tick.(Sc_rollup_block.final_tick head < tick) then + if Z.Compare.(head.Sc_rollup_block.initial_tick <= tick) then + if Z.Compare.(Sc_rollup_block.final_tick head < tick) then (* The head block does not contain the tick *) return_none else @@ -627,20 +627,18 @@ let tick_search ~big_step_blocks node_ctxt head tick = let genesis_level = Raw_level.to_int32 node_ctxt.genesis_info.level in let rec find_big_step (end_block : Sc_rollup_block.t) = let start_level = - Int32.sub - (Raw_level.to_int32 end_block.header.level) - (Int32.of_int big_step_blocks) + Int32.sub end_block.header.level (Int32.of_int big_step_blocks) in let start_level = if start_level < genesis_level then genesis_level else start_level in let* start_block = get_l2_block_by_level node_ctxt start_level in - if Sc_rollup.Tick.(start_block.initial_tick <= tick) then + if Z.Compare.(start_block.initial_tick <= tick) then return (start_block, end_block) else find_big_step start_block in let block_level Sc_rollup_block.{header = {level; _}; _} = - Raw_level.to_int32 level |> Int32.to_int + Int32.to_int level in let rec dicho start_block end_block = (* Precondition: @@ -656,7 +654,7 @@ let tick_search ~big_step_blocks node_ctxt head tick = let* block_middle = get_l2_block_by_level node_ctxt (Int32.of_int middle_level) in - if Sc_rollup.Tick.(block_middle.initial_tick <= tick) then + if Z.Compare.(block_middle.initial_tick <= tick) then dicho block_middle end_block else dicho start_block block_middle in @@ -679,51 +677,80 @@ let block_with_tick ({store; _} as node_ctxt) ~max_level tick = the refutation period as the big_step_blocks to do a dichotomy on the full space but we anticipate refutation to happen most of the time close to the head. *) + let max_level = Raw_level.to_int32 max_level in let** head = - if Raw_level.(head.header.level <= max_level) then return_some head - else find_l2_block_by_level node_ctxt (Raw_level.to_int32 max_level) + if head.header.level <= max_level then return_some head + else find_l2_block_by_level node_ctxt max_level in - tick_search ~big_step_blocks:4096 node_ctxt head tick + tick_search ~big_step_blocks:4096 node_ctxt head (Sc_rollup.Tick.to_z tick) -let get_commitment {store; _} commitment_hash = +let find_octez_commitment {store; _} commitment_hash = let open Lwt_result_syntax in - let* commitment = Store.Commitments.read store.commitments commitment_hash in + let+ commitment = Store.Commitments.read store.commitments commitment_hash in + Option.map fst commitment + +let find_commitment node_ctxt commitment_hash = + let open Lwt_result_syntax in + let commitment_hash = + Sc_rollup_proto_types.Commitment_hash.to_octez commitment_hash + in + let+ commitment = find_octez_commitment node_ctxt commitment_hash in + Option.map Sc_rollup_proto_types.Commitment.of_octez commitment + +let get_octez_commitment node_ctxt commitment_hash = + let open Lwt_result_syntax in + let* commitment = find_octez_commitment node_ctxt commitment_hash in match commitment with | None -> failwith "Could not retrieve commitment %a" - Sc_rollup.Commitment.Hash.pp + Octez_smart_rollup.Commitment.Hash.pp commitment_hash - | Some (c, ()) -> return c + | Some i -> return i -let find_commitment {store; _} hash = +let get_commitment node_ctxt commitment_hash = let open Lwt_result_syntax in - let+ commitment = Store.Commitments.read store.commitments hash in - Option.map fst commitment + let* commitment = find_commitment node_ctxt commitment_hash in + match commitment with + | None -> + failwith + "Could not retrieve commitment %a" + Sc_rollup.Commitment.Hash.pp + commitment_hash + | Some i -> return i let commitment_exists {store; _} hash = + let hash = Sc_rollup_proto_types.Commitment_hash.to_octez hash in Store.Commitments.mem store.commitments hash let save_commitment {store; _} commitment = let open Lwt_result_syntax in - let hash = Sc_rollup.Commitment.hash_uncarbonated commitment in + let commitment = Sc_rollup_proto_types.Commitment.to_octez commitment in + let hash = Octez_smart_rollup.Commitment.hash commitment in let+ () = Store.Commitments.append store.commitments ~key:hash ~value:commitment in - hash + Sc_rollup_proto_types.Commitment_hash.of_octez hash let commitment_published_at_level {store; _} commitment = + let commitment = Sc_rollup_proto_types.Commitment_hash.to_octez commitment in Store.Commitments_published_at_level.find store.commitments_published_at_level commitment -let set_commitment_published_at_level {store; _} = - Store.Commitments_published_at_level.add store.commitments_published_at_level +let set_commitment_published_at_level {store; _} hash = + let hash = Sc_rollup_proto_types.Commitment_hash.to_octez hash in + Store.Commitments_published_at_level.add + store.commitments_published_at_level + hash type commitment_source = Anyone | Us let commitment_was_published {store; _} ~source commitment_hash = let open Lwt_result_syntax in + let commitment_hash = + Sc_rollup_proto_types.Commitment_hash.to_octez commitment_hash + in match source with | Anyone -> Store.Commitments_published_at_level.mem @@ -739,31 +766,52 @@ let commitment_was_published {store; _} ~source commitment_hash = | Some {published_at_level = Some _; _} -> true | _ -> false) -let get_inbox {store; _} inbox_hash = +let find_octez_inbox {store; _} inbox_hash = let open Lwt_result_syntax in - let* inbox = Store.Inboxes.read store.inboxes inbox_hash in + let+ inbox = Store.Inboxes.read store.inboxes inbox_hash in + Option.map fst inbox + +let find_inbox node_ctxt inbox_hash = + let open Lwt_result_syntax in + let inbox_hash = Sc_rollup_proto_types.Inbox_hash.to_octez inbox_hash in + let+ inbox = find_octez_inbox node_ctxt inbox_hash in + Option.map Sc_rollup_proto_types.Inbox.of_octez inbox + +let get_octez_inbox node_ctxt inbox_hash = + let open Lwt_result_syntax in + let* inbox = find_octez_inbox node_ctxt inbox_hash in match inbox with | None -> - failwith "Could not retrieve inbox %a" Sc_rollup.Inbox.Hash.pp inbox_hash - | Some (i, ()) -> return i + failwith + "Could not retrieve inbox %a" + Octez_smart_rollup.Inbox.Hash.pp + inbox_hash + | Some i -> return i -let find_inbox {store; _} hash = +let get_inbox node_ctxt inbox_hash = let open Lwt_result_syntax in - let+ inbox = Store.Inboxes.read store.inboxes hash in - Option.map fst inbox + let* inbox = find_inbox node_ctxt inbox_hash in + match inbox with + | None -> + failwith "Could not retrieve inbox %a" Sc_rollup.Inbox.Hash.pp inbox_hash + | Some i -> return i let save_inbox {store; _} inbox = let open Lwt_result_syntax in - let hash = Sc_rollup.Inbox.hash inbox in + let inbox = Sc_rollup_proto_types.Inbox.to_octez inbox in + let hash = Octez_smart_rollup.Inbox.hash inbox in let+ () = Store.Inboxes.append store.inboxes ~key:hash ~value:inbox in - hash + Sc_rollup_proto_types.Inbox_hash.of_octez hash let find_inbox_by_block_hash ({store; _} as node_ctxt) block_hash = let open Lwt_result_syntax in let* header = Store.L2_blocks.header store.l2_blocks block_hash in match header with | None -> return_none - | Some {inbox_hash; _} -> find_inbox node_ctxt inbox_hash + | Some {inbox_hash; _} -> + find_inbox + node_ctxt + (Sc_rollup_proto_types.Inbox_hash.of_octez inbox_hash) let genesis_inbox node_ctxt = let genesis_level = Raw_level.to_int32 node_ctxt.genesis_info.level in @@ -813,6 +861,9 @@ type messages_info = { let find_messages node_ctxt messages_hash = let open Lwt_result_syntax in + let messages_hash = + Sc_rollup_proto_types.Merkelized_payload_hashes_hash.to_octez messages_hash + in let* msg = Store.Messages.read node_ctxt.store.messages messages_hash in match msg with | None -> return_none @@ -825,6 +876,13 @@ let find_messages node_ctxt messages_hash = let is_first_block = pred_header.header.proto_level <> grand_parent_header.header.proto_level in + let*? messages = + Environment.wrap_tzresult + @@ List.map_e + (fun m -> + Sc_rollup.Inbox_message.(deserialize @@ unsafe_of_string m)) + messages + in return_some { is_first_block; @@ -833,18 +891,22 @@ let find_messages node_ctxt messages_hash = messages; } -let get_messages_aux find node_ctxt hash = +let get_messages_aux find pp node_ctxt hash = let open Lwt_result_syntax in let* res = find node_ctxt hash in match res with | None -> failwith "Could not retrieve messages with payloads merkelized hash %a" - Sc_rollup.Inbox_merkelized_payload_hashes.Hash.pp + pp hash | Some res -> return res -let get_messages node_ctxt = get_messages_aux find_messages node_ctxt +let get_messages node_ctxt = + get_messages_aux + find_messages + Sc_rollup.Inbox_merkelized_payload_hashes.Hash.pp + node_ctxt let get_messages_without_proto_messages node_ctxt = get_messages_aux @@ -854,30 +916,44 @@ let get_messages_without_proto_messages node_ctxt = match msg with | None -> return_none | Some (messages, _block_hash) -> return_some messages) + Tezos_crypto.Hashed.Smart_rollup_merkelized_payload_hashes_hash.pp node_ctxt let get_num_messages {store; _} hash = let open Lwt_result_syntax in + let hash = + Sc_rollup_proto_types.Merkelized_payload_hashes_hash.to_octez hash + in let* msg = Store.Messages.read store.messages hash in match msg with | None -> failwith "Could not retrieve number of messages for inbox witness %a" - Sc_rollup.Inbox_merkelized_payload_hashes.Hash.pp + Tezos_crypto.Hashed.Smart_rollup_merkelized_payload_hashes_hash.pp hash | Some (messages, _block_hash) -> return (List.length messages) let save_messages {store; _} key ~block_hash messages = - Store.Messages.append store.messages ~key ~header:block_hash ~value:messages + let open Lwt_result_syntax in + let key = Sc_rollup_proto_types.Merkelized_payload_hashes_hash.to_octez key in + let*? messages = + Environment.wrap_tzresult + @@ List.map_e Sc_rollup.Inbox_message.serialize messages + in + Store.Messages.append + store.messages + ~key + ~header:block_hash + ~value:(messages :> string list) let get_full_l2_block node_ctxt block_hash = let open Lwt_result_syntax in let* block = get_l2_block node_ctxt block_hash in - let* inbox = get_inbox node_ctxt block.header.inbox_hash + let* inbox = get_octez_inbox node_ctxt block.header.inbox_hash and* messages = get_messages_without_proto_messages node_ctxt block.header.inbox_witness and* commitment = - Option.map_es (get_commitment node_ctxt) block.header.commitment_hash + Option.map_es (get_octez_commitment node_ctxt) block.header.commitment_hash in return {block with content = {Sc_rollup_block.inbox; messages; commitment}} @@ -1036,58 +1112,91 @@ let get_slot_header {store; _} ~published_in_block_hash slot_index = slot_index Block_hash.pp published_in_block_hash - @@ Store.Dal_slots_headers.get - store.irmin_store - ~primary_key:published_in_block_hash - ~secondary_key:slot_index + @@ + let open Lwt_result_syntax in + let+ header = + Store.Dal_slots_headers.get + store.irmin_store + ~primary_key:published_in_block_hash + ~secondary_key:(Sc_rollup_proto_types.Dal.Slot_index.to_octez slot_index) + in + Sc_rollup_proto_types.Dal.Slot_header.of_octez header let get_all_slot_headers {store; _} ~published_in_block_hash = - Store.Dal_slots_headers.list_values - store.irmin_store - ~primary_key:published_in_block_hash + let open Lwt_result_syntax in + let+ headers = + Store.Dal_slots_headers.list_values + store.irmin_store + ~primary_key:published_in_block_hash + in + List.rev_map Sc_rollup_proto_types.Dal.Slot_header.of_octez headers + |> List.rev let get_slot_indexes {store; _} ~published_in_block_hash = - Store.Dal_slots_headers.list_secondary_keys - store.irmin_store - ~primary_key:published_in_block_hash + let open Lwt_result_syntax in + let+ indexes = + Store.Dal_slots_headers.list_secondary_keys + store.irmin_store + ~primary_key:published_in_block_hash + in + List.rev_map Sc_rollup_proto_types.Dal.Slot_index.of_octez indexes |> List.rev let save_slot_header {store; _} ~published_in_block_hash (slot_header : Dal.Slot.Header.t) = Store.Dal_slots_headers.add store.irmin_store ~primary_key:published_in_block_hash - ~secondary_key:slot_header.id.index - slot_header + ~secondary_key: + (Sc_rollup_proto_types.Dal.Slot_index.to_octez slot_header.id.index) + (Sc_rollup_proto_types.Dal.Slot_header.to_octez slot_header) let find_slot_status {store; _} ~confirmed_in_block_hash slot_index = Store.Dal_slots_statuses.find store.irmin_store ~primary_key:confirmed_in_block_hash - ~secondary_key:slot_index + ~secondary_key:(Sc_rollup_proto_types.Dal.Slot_index.to_octez slot_index) let list_slots_statuses {store; _} ~confirmed_in_block_hash = - Store.Dal_slots_statuses.list_secondary_keys_with_values - store.irmin_store - ~primary_key:confirmed_in_block_hash + let open Lwt_result_syntax in + let+ statuses = + Store.Dal_slots_statuses.list_secondary_keys_with_values + store.irmin_store + ~primary_key:confirmed_in_block_hash + in + List.rev_map + (fun (index, status) -> + (Sc_rollup_proto_types.Dal.Slot_index.of_octez index, status)) + statuses + |> List.rev let save_slot_status {store; _} current_block_hash slot_index status = Store.Dal_slots_statuses.add store.irmin_store ~primary_key:current_block_hash - ~secondary_key:slot_index + ~secondary_key:(Sc_rollup_proto_types.Dal.Slot_index.to_octez slot_index) status -let find_confirmed_slots_history {store; _} = - Store.Dal_confirmed_slots_history.find store.irmin_store +let find_confirmed_slots_history {store; _} block = + let open Lwt_result_syntax in + let+ res = Store.Dal_confirmed_slots_history.find store.irmin_store block in + Option.map Sc_rollup_proto_types.Dal.Slot_history.of_octez res -let save_confirmed_slots_history {store; _} = - Store.Dal_confirmed_slots_history.add store.irmin_store +let save_confirmed_slots_history {store; _} block hist = + Store.Dal_confirmed_slots_history.add + store.irmin_store + block + (Sc_rollup_proto_types.Dal.Slot_history.to_octez hist) -let find_confirmed_slots_histories {store; _} = - Store.Dal_confirmed_slots_histories.find store.irmin_store +let find_confirmed_slots_histories {store; _} block = + let open Lwt_result_syntax in + let+ res = Store.Dal_confirmed_slots_histories.find store.irmin_store block in + Option.map Sc_rollup_proto_types.Dal.Slot_history_cache.of_octez res -let save_confirmed_slots_histories {store; _} = - Store.Dal_confirmed_slots_histories.add store.irmin_store +let save_confirmed_slots_histories {store; _} block hist = + Store.Dal_confirmed_slots_histories.add + store.irmin_store + block + (Sc_rollup_proto_types.Dal.Slot_history_cache.to_octez hist) module Internal_for_tests = struct let create_node_context cctxt diff --git a/src/proto_alpha/lib_sc_rollup_node/publisher.ml b/src/proto_alpha/lib_sc_rollup_node/publisher.ml index f7de047a773382e9d76cc077108257b2145eee23..d2ad6afc0248e57c179dcd3b1188b1401b246de5 100644 --- a/src/proto_alpha/lib_sc_rollup_node/publisher.ml +++ b/src/proto_alpha/lib_sc_rollup_node/publisher.ml @@ -110,9 +110,9 @@ let build_commitment (node_ctxt : _ Node_context.t) let*! compressed_state = PVM.state_hash pvm_state in let*! tick = PVM.get_tick pvm_state in let* prev_commitment_tick = tick_of_level node_ctxt prev_commitment_level in + let distance = Z.sub (Sc_rollup.Tick.to_z tick) prev_commitment_tick in let number_of_ticks = - Sc_rollup.Tick.distance tick prev_commitment_tick - |> Z.to_int64 |> Sc_rollup.Number_of_ticks.of_value + distance |> Z.to_int64 |> Sc_rollup.Number_of_ticks.of_value in let*? number_of_ticks = match number_of_ticks with @@ -177,6 +177,7 @@ let create_commitment_if_necessary (node_ctxt : _ Node_context.t) ~predecessor let* last_commitment_hash = let+ pred = Node_context.get_l2_block node_ctxt predecessor in Sc_rollup_block.most_recent_commitment pred.header + |> Sc_rollup_proto_types.Commitment_hash.of_octez in let* last_commitment = Node_context.get_commitment node_ctxt last_commitment_hash @@ -221,9 +222,7 @@ let missing_commitments (node_ctxt : _ Node_context.t) = in let* head = Node_context.last_processed_head_opt node_ctxt in let next_head_level = - Option.map - (fun (b : Sc_rollup_block.t) -> Raw_level.succ b.header.level) - head + Option.map (fun (b : Sc_rollup_block.t) -> Int32.succ b.header.level) head in let sc_rollup_challenge_window_int32 = sc_rollup_challenge_window node_ctxt |> Int32.of_int @@ -249,7 +248,7 @@ let missing_commitments (node_ctxt : _ Node_context.t) = match (published_info, next_head_level) with | None, _ | _, None -> false | Some {first_published_at_level; _}, Some next_head_level -> - Raw_level.diff next_head_level first_published_at_level + Int32.sub next_head_level first_published_at_level > sc_rollup_challenge_window_int32 in let acc = if past_curfew then acc else commitment :: acc in @@ -264,6 +263,7 @@ let missing_commitments (node_ctxt : _ Node_context.t) = commitments that are missing. *) let commitment = Sc_rollup_block.most_recent_commitment finalized.header + |> Sc_rollup_proto_types.Commitment_hash.of_octez in gather [] commitment @@ -320,7 +320,9 @@ let earliest_cementing_level node_ctxt commitment_hash = Node_context.commitment_published_at_level node_ctxt commitment_hash in return_some - @@ add_level first_published_at_level (sc_rollup_challenge_window node_ctxt) + @@ Int32.add + first_published_at_level + (sc_rollup_challenge_window node_ctxt |> Int32.of_int) (** [latest_cementable_commitment node_ctxt head] is the most recent commitment hash that could be cemented in [head]'s successor if: @@ -333,7 +335,10 @@ let earliest_cementing_level node_ctxt commitment_hash = let latest_cementable_commitment (node_ctxt : _ Node_context.t) (head : Sc_rollup_block.t) = let open Lwt_result_option_syntax in - let commitment_hash = Sc_rollup_block.most_recent_commitment head.header in + let commitment_hash = + Sc_rollup_block.most_recent_commitment head.header + |> Sc_rollup_proto_types.Commitment_hash.of_octez + in let** commitment = Node_context.find_commitment node_ctxt commitment_hash in let** cementable_level_bound = return @@ -349,6 +354,7 @@ let latest_cementable_commitment (node_ctxt : _ Node_context.t) in let cementable_commitment = Sc_rollup_block.most_recent_commitment cementable_bound_block.header + |> Sc_rollup_proto_types.Commitment_hash.of_octez in return_some cementable_commitment @@ -374,7 +380,7 @@ let cementable_commitments (node_ctxt : _ Node_context.t) = match earliest_cementing_level with | None -> acc | Some earliest_cementing_level -> - if Raw_level.(earliest_cementing_level > head_level) then + if earliest_cementing_level > head_level then (* Commitments whose cementing level are after the head's successor won't be cementable in the next block. *) acc diff --git a/src/proto_alpha/lib_sc_rollup_node/store.ml b/src/proto_alpha/lib_sc_rollup_node/store.ml deleted file mode 100644 index f89bd6e8cfb551522c566991a8cede8bb4e94e69..0000000000000000000000000000000000000000 --- a/src/proto_alpha/lib_sc_rollup_node/store.ml +++ /dev/null @@ -1,27 +0,0 @@ -(*****************************************************************************) -(* *) -(* Open Source License *) -(* Copyright (c) 2021 Nomadic Labs, *) -(* Copyright (c) 2023 Functori, *) -(* *) -(* 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. *) -(* *) -(*****************************************************************************) - -include Store_v2 diff --git a/src/proto_alpha/lib_sc_rollup_node/store_migration.ml b/src/proto_alpha/lib_sc_rollup_node/store_migration.ml deleted file mode 100644 index a10d8043c46d84973ed7fea31701575d8fea9876..0000000000000000000000000000000000000000 --- a/src/proto_alpha/lib_sc_rollup_node/store_migration.ml +++ /dev/null @@ -1,438 +0,0 @@ -(*****************************************************************************) -(* *) -(* Open Source License *) -(* Copyright (c) 2023 Functori, *) -(* *) -(* 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. *) -(* *) -(*****************************************************************************) - -open Store_version - -type version_result = Version_known | Unintialized_version - -let messages_store_location ~storage_dir = - let open Filename.Infix in - storage_dir // "messages" - -let version_of_unversioned_store ~storage_dir = - let open Lwt_syntax in - let path = messages_store_location ~storage_dir in - let* messages_store_v0 = Store_v0.Messages.load ~path ~cache_size:1 Read_only - and* messages_store_v1 = - Store_v1.Messages.load ~path ~cache_size:1 Read_only - in - let cleanup () = - let open Lwt_syntax in - let* (_ : unit tzresult) = - match messages_store_v0 with - | Error _ -> Lwt.return_ok () - | Ok s -> Store_v0.Messages.close s - and* (_ : unit tzresult) = - match messages_store_v1 with - | Error _ -> Lwt.return_ok () - | Ok s -> Store_v1.Messages.close s - in - return_unit - in - let guess_version () = - let open Lwt_result_syntax in - match (messages_store_v0, messages_store_v1) with - | Ok _, Error _ -> return_some V0 - | Error _, Ok _ -> return_some V1 - | Ok _, Ok _ -> - (* Empty store, both loads succeed *) - return_none - | Error _, Error _ -> - failwith - "Cannot determine unversioned store version (no messages decodable)" - in - Lwt.finalize guess_version cleanup - -let version_of_store ~storage_dir = - let open Lwt_result_syntax in - let* version = Store_version.read_version_file ~dir:storage_dir in - match version with - | Some v -> return_some (v, Version_known) - | None -> - let+ v = version_of_unversioned_store ~storage_dir in - Option.map (fun v -> (v, Unintialized_version)) v - -module type MIGRATION_ACTIONS = sig - type from_store - - type dest_store - - val migrate_block_action : - from_store -> dest_store -> Sc_rollup_block.t -> unit tzresult Lwt.t - - val final_actions : - storage_dir:string -> - tmp_dir:string -> - from_store -> - dest_store -> - unit tzresult Lwt.t -end - -module type S = sig - val migrate : storage_dir:string -> unit tzresult Lwt.t -end - -let migrations = Stdlib.Hashtbl.create 7 - -module Make - (S_from : Store_sig.S) - (S_dest : Store_sig.S) - (Actions : MIGRATION_ACTIONS - with type from_store := Store_sigs.ro S_from.t - and type dest_store := Store_sigs.rw S_dest.t) : S = struct - let tmp_dir ~storage_dir = - Filename.concat (Configuration.default_storage_dir storage_dir) - @@ Format.asprintf - "migration_%a_%a" - Store_version.pp - S_from.version - Store_version.pp - S_dest.version - - let migrate ~storage_dir = - let open Lwt_result_syntax in - let* source_store = - S_from.load Read_only ~l2_blocks_cache_size:1 storage_dir - in - let tmp_dir = tmp_dir ~storage_dir in - let*! tmp_dir_exists = Lwt_utils_unix.dir_exists tmp_dir in - let*? () = - if tmp_dir_exists then - error_with - "Store migration (from %a to %a) is already ongoing. Wait for it to \ - finish or remove %S and restart." - Store_version.pp - S_from.version - Store_version.pp - S_dest.version - tmp_dir - else Ok () - in - let*! () = Lwt_utils_unix.create_dir tmp_dir in - let* dest_store = S_dest.load Read_write ~l2_blocks_cache_size:1 tmp_dir in - let cleanup () = - let open Lwt_syntax in - let* (_ : unit tzresult) = S_from.close source_store - and* (_ : unit tzresult) = S_dest.close dest_store in - (* Don't remove migration dir to allow for later resume. *) - return_unit - in - let run_migration () = - let* () = - S_from.iter_l2_blocks - source_store - (Actions.migrate_block_action source_store dest_store) - in - let* () = - Actions.final_actions ~storage_dir ~tmp_dir source_store dest_store - in - let*! () = Lwt_utils_unix.remove_dir tmp_dir in - Store_version.write_version_file ~dir:storage_dir S_dest.version - in - Lwt.finalize run_migration cleanup - - let () = Stdlib.Hashtbl.add migrations S_from.version (S_dest.version, migrate) -end - -let migration_path ~from ~dest = - let rec path acc from dest = - if from = dest then Some (List.rev acc) - else - let first_steps = - Stdlib.Hashtbl.find_all migrations from - |> List.stable_sort (fun (va, _) (vb, _) -> - (* Try biggest jumps first that don't go beyond the - destination *) - if va > dest && vb > dest then Stdlib.compare va vb - else if va > dest then 1 - else if vb > dest then -1 - else Stdlib.compare vb va) - in - (* Recursively look for migration sub-paths *) - let paths = - List.filter_map - (fun (step, migration) -> - path ((from, step, migration) :: acc) step dest) - first_steps - in - (* Choose shortest migration path *) - List.stable_sort List.compare_lengths paths |> List.hd - in - path [] from dest - -let maybe_run_migration ~storage_dir = - let open Lwt_result_syntax in - let* current_version = version_of_store ~storage_dir in - let last_version = Store.version in - match (current_version, last_version) with - | None, _ -> - (* Store not initialized, write last version *) - Store_version.write_version_file ~dir:storage_dir last_version - | Some (current, versioned), last when last = current -> ( - match versioned with - | Unintialized_version -> - Store_version.write_version_file ~dir:storage_dir last_version - | Version_known -> - (* Up to date, nothing to do *) - return_unit) - | Some (current, _), last -> ( - let migrations = migration_path ~from:current ~dest:last in - match migrations with - | None -> - failwith - "Store version %a is not supported by this rollup node because \ - there is no migration path from it to %a." - Store_version.pp - current - Store_version.pp - last - | Some migrations -> - Format.printf "Starting store migration@." ; - let+ () = - List.iter_es - (fun (vx, vy, migrate) -> - Format.printf - "- Migrating store from %a to %a@." - Store_version.pp - vx - Store_version.pp - vy ; - migrate ~storage_dir) - migrations - in - Format.printf "Store migration completed@.") - -module V1_migrations = struct - let convert_store_messages - (messages, (block_hash, timestamp, number_of_messages)) = - ( messages, - (false (* is migration block *), block_hash, timestamp, number_of_messages) - ) - - let migrate_messages (v0_store : _ Store_v0.t) (v1_store : _ Store_v1.t) - (l2_block : Sc_rollup_block.t) = - let open Lwt_result_syntax in - let* v0_messages = - Store_v0.Messages.read v0_store.messages l2_block.header.inbox_witness - in - match v0_messages with - | None -> return_unit - | Some v0_messages -> - let value, header = convert_store_messages v0_messages in - Store_v1.Messages.append - v1_store.messages - ~key:l2_block.header.inbox_witness - ~header - ~value - - (* In place migration of processed slots under new key name by hand *) - let migrate_dal_processed_slots_irmin (v1_store : _ Store_v1.t) = - let open Lwt_syntax in - let open Store_v1 in - let info () = - let date = - Tezos_base.Time.( - System.now () |> System.to_protocol |> Protocol.to_seconds) - in - let author = - Format.asprintf - "Rollup node %a" - Tezos_version_parser.pp - Tezos_version_value.Current_git_info.version - in - let message = "Migration store from v0 to v1" in - Irmin_store.Raw_irmin.Info.v ~author ~message date - in - let store = Irmin_store.Raw_irmin.unsafe v1_store.irmin_store in - let old_root = Store_v0.Dal_processed_slots.path in - let new_root = Dal_slots_statuses.path in - let* old_tree = Irmin_store.Raw_irmin.find_tree store old_root in - match old_tree with - | None -> return_unit - | Some _ -> - (* Move the tree in the new key *) - Irmin_store.Raw_irmin.with_tree_exn - ~info - store - new_root - (fun _new_tree -> return old_tree) - - let final_actions ~storage_dir ~tmp_dir (_v0_store : _ Store_v0.t) - (v1_store : _ Store_v1.t) = - let open Lwt_result_syntax in - let*! () = - Lwt_utils_unix.remove_dir (messages_store_location ~storage_dir) - in - let*! () = - Lwt_unix.rename - (messages_store_location ~storage_dir:tmp_dir) - (messages_store_location ~storage_dir) - in - let*! () = migrate_dal_processed_slots_irmin v1_store in - return_unit - - module From_v0 = - Make (Store_v0) (Store_v1) - (struct - let migrate_block_action = migrate_messages - - let final_actions = final_actions - end) -end - -module V2_migrations = struct - let messages_store_location ~storage_dir = - let open Filename.Infix in - storage_dir // "messages" - - let commitments_store_location ~storage_dir = - let open Filename.Infix in - storage_dir // "commitments" - - let inboxes_store_location ~storage_dir = - let open Filename.Infix in - storage_dir // "inboxes" - - let migrate_messages read_messages (v2_store : _ Store_v2.t) - (l2_block : Sc_rollup_block.t) = - let open Lwt_result_syntax in - let* v1_messages = read_messages l2_block.header.inbox_witness in - match v1_messages with - | None -> return_unit - | Some (messages, _v1_header) -> - let header = l2_block.header.block_hash in - Store_v2.Messages.append - v2_store.messages - ~key:l2_block.header.inbox_witness - ~header - ~value:messages - - let migrate_commitment read_commitment (v2_store : _ Store_v2.t) - (l2_block : Sc_rollup_block.t) = - let open Lwt_result_syntax in - match l2_block.header.commitment_hash with - | None -> return_unit - | Some commitment_hash -> ( - let* v1_commitment = read_commitment commitment_hash in - match v1_commitment with - | None -> return_unit - | Some commitment -> - Store_v2.Commitments.append - v2_store.commitments - ~key:commitment_hash - ~value:commitment) - - let migrate_inbox read_inbox (v2_store : _ Store_v2.t) - (l2_block : Sc_rollup_block.t) = - let open Lwt_result_syntax in - let* v1_inbox = read_inbox l2_block.header.inbox_hash in - match v1_inbox with - | None -> return_unit - | Some (inbox, ()) -> - Store_v2.Inboxes.append - v2_store.inboxes - ~key:l2_block.header.inbox_hash - ~value:inbox - - let final_actions ~storage_dir ~tmp_dir _ _ = - let open Lwt_result_syntax in - let*! () = - Lwt_utils_unix.remove_dir (messages_store_location ~storage_dir) - in - let*! () = - Lwt_utils_unix.remove_dir (commitments_store_location ~storage_dir) - in - let*! () = - Lwt_utils_unix.remove_dir (inboxes_store_location ~storage_dir) - in - let*! () = - Lwt_unix.rename - (messages_store_location ~storage_dir:tmp_dir) - (messages_store_location ~storage_dir) - in - let*! () = - Lwt_unix.rename - (commitments_store_location ~storage_dir:tmp_dir) - (commitments_store_location ~storage_dir) - in - let*! () = - Lwt_unix.rename - (inboxes_store_location ~storage_dir:tmp_dir) - (inboxes_store_location ~storage_dir) - in - return_unit - - module From_v1 = - Make (Store_v1) (Store_v2) - (struct - let migrate_block_action v1_store v2_store l2_block = - let open Lwt_result_syntax in - let* () = - migrate_messages - Store_v1.(Messages.read v1_store.messages) - v2_store - l2_block - and* () = - migrate_commitment - Store_v1.(Commitments.find v1_store.commitments) - v2_store - l2_block - and* () = - migrate_inbox - Store_v1.(Inboxes.read v1_store.inboxes) - v2_store - l2_block - in - return_unit - - let final_actions = final_actions - end) - - module From_v0 = - Make (Store_v0) (Store_v2) - (struct - let migrate_block_action v0_store v2_store l2_block = - let open Lwt_result_syntax in - let* () = - migrate_messages - Store_v0.(Messages.read v0_store.messages) - v2_store - l2_block - and* () = - migrate_commitment - Store_v0.(Commitments.find v0_store.commitments) - v2_store - l2_block - and* () = - migrate_inbox - Store_v0.(Inboxes.read v0_store.inboxes) - v2_store - l2_block - in - return_unit - - let final_actions = final_actions - end) -end diff --git a/src/proto_alpha/lib_sc_rollup_node/store_sig.ml b/src/proto_alpha/lib_sc_rollup_node/store_sig.ml deleted file mode 100644 index ffac28ff0409d1304131464a80fdd11701499e9d..0000000000000000000000000000000000000000 --- a/src/proto_alpha/lib_sc_rollup_node/store_sig.ml +++ /dev/null @@ -1,65 +0,0 @@ -(*****************************************************************************) -(* *) -(* Open Source License *) -(* Copyright (c) 2023 Functori, *) -(* *) -(* 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. *) -(* *) -(*****************************************************************************) - -module type S = sig - type +'a store - - (** Type of store. The parameter indicates if the store can be written or only - read. *) - type 'a t = ([< `Read | `Write > `Read] as 'a) store - - (** Read/write store {!t}. *) - type rw = Store_sigs.rw t - - (** Read only store {!t}. *) - type ro = Store_sigs.ro t - - (** Version supported by this code. *) - val version : Store_version.t - - (** [close store] closes the store. *) - val close : _ t -> unit tzresult Lwt.t - - (** [load mode ~l2_blocks_cache_size directory] loads a store from the data - persisted in [directory]. If [mode] is {!Store_sigs.Read_only}, then the - indexes and irmin store will be opened in readonly mode and only read - operations will be permitted. This allows to open a store for read access - that is already opened in {!Store_sigs.Read_write} mode in another - process. [l2_blocks_cache_size] is the number of L2 blocks the rollup node - will keep in memory. *) - val load : - 'a Store_sigs.mode -> - l2_blocks_cache_size:int -> - string -> - 'a store tzresult Lwt.t - - (** [readonly store] returns a read-only version of [store]. *) - val readonly : _ t -> ro - - (** [iter_l2_blocks store f] iterates [f] on all L2 blocks reachable from the - head, from newest to oldest. *) - val iter_l2_blocks : - _ t -> (Sc_rollup_block.t -> unit tzresult Lwt.t) -> unit tzresult Lwt.t -end diff --git a/src/proto_alpha/lib_sc_rollup_node/store_v2.ml b/src/proto_alpha/lib_sc_rollup_node/store_v2.ml deleted file mode 100644 index 18b77336aa55753bbe7453796b9182a5bda1fec2..0000000000000000000000000000000000000000 --- a/src/proto_alpha/lib_sc_rollup_node/store_v2.ml +++ /dev/null @@ -1,330 +0,0 @@ -(*****************************************************************************) -(* *) -(* Open Source License *) -(* Copyright (c) 2021 Nomadic Labs, *) -(* Copyright (c) 2023 Functori, *) -(* *) -(* 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. *) -(* *) -(*****************************************************************************) - -open Protocol -open Alpha_context -include Store_sigs -include Store_utils -include Store_v1 - -let version = Store_version.V2 - -module Make_hash_index_key (H : Environment.S.HASH) = -Indexed_store.Make_index_key (struct - include Indexed_store.Make_fixed_encodable (H) - - let equal = H.equal -end) - -(** Unaggregated messages per block *) -module Messages = - Indexed_store.Make_indexed_file - (struct - let name = "messages" - end) - (Make_hash_index_key (Sc_rollup.Inbox_merkelized_payload_hashes.Hash)) - (struct - type t = Sc_rollup.Inbox_message.t list - - let name = "messages_list" - - let encoding = - Data_encoding.(list @@ dynamic_size Sc_rollup.Inbox_message.encoding) - - module Header = struct - type t = Block_hash.t - - let name = "messages_block" - - let encoding = Block_hash.encoding - - let fixed_size = - WithExceptions.Option.get ~loc:__LOC__ - @@ Data_encoding.Binary.fixed_length encoding - end - end) - -module Empty_header = struct - type t = unit - - let name = "empty" - - let encoding = Data_encoding.unit - - let fixed_size = 0 -end - -module Add_empty_header = struct - module Header = Empty_header - - let header _ = () -end - -(** Versioned inboxes *) -module Inboxes = - Indexed_store.Make_simple_indexed_file - (struct - let name = "inboxes" - end) - (Make_hash_index_key (Sc_rollup.Inbox.Hash)) - (struct - type t = Sc_rollup.Inbox.t - - let to_repr inbox = - inbox - |> Data_encoding.Binary.to_string_exn Sc_rollup.Inbox.encoding - |> Data_encoding.Binary.of_string_exn Sc_rollup_inbox_repr.encoding - - let of_repr inbox = - inbox - |> Data_encoding.Binary.to_string_exn Sc_rollup_inbox_repr.encoding - |> Data_encoding.Binary.of_string_exn Sc_rollup.Inbox.encoding - - let encoding = - Data_encoding.conv - (fun x -> to_repr x |> Sc_rollup_inbox_repr.to_versioned) - (fun x -> Sc_rollup_inbox_repr.of_versioned x |> of_repr) - Sc_rollup_inbox_repr.versioned_encoding - - let name = "inbox" - - include Add_empty_header - end) - -(** Versioned commitments *) -module Commitments = - Indexed_store.Make_simple_indexed_file - (struct - let name = "commitments" - end) - (Make_hash_index_key (Sc_rollup.Commitment.Hash)) - (struct - type t = Sc_rollup.Commitment.t - - let to_repr commitment = - commitment - |> Data_encoding.Binary.to_string_exn Sc_rollup.Commitment.encoding - |> Data_encoding.Binary.of_string_exn Sc_rollup_commitment_repr.encoding - - let of_repr commitment = - commitment - |> Data_encoding.Binary.to_string_exn Sc_rollup_commitment_repr.encoding - |> Data_encoding.Binary.of_string_exn Sc_rollup.Commitment.encoding - - let encoding = - Data_encoding.conv - (fun x -> to_repr x |> Sc_rollup_commitment_repr.to_versioned) - (fun x -> Sc_rollup_commitment_repr.of_versioned x |> of_repr) - Sc_rollup_commitment_repr.versioned_encoding - - let name = "commitment" - - include Add_empty_header - end) - -module Protocols = struct - type level = First_known of int32 | Activation_level of int32 - - type proto_info = { - level : level; - proto_level : int; - protocol : Protocol_hash.t; - } - - type value = proto_info list - - let level_encoding = - let open Data_encoding in - conv - (function First_known l -> (l, false) | Activation_level l -> (l, true)) - (function l, false -> First_known l | l, true -> Activation_level l) - @@ obj2 (req "level" int32) (req "activates" bool) - - let proto_info_encoding = - let open Data_encoding in - conv - (fun {level; proto_level; protocol} -> (level, proto_level, protocol)) - (fun (level, proto_level, protocol) -> {level; proto_level; protocol}) - @@ obj3 - (req "level" level_encoding) - (req "proto_level" int31) - (req "protocol" Protocol_hash.encoding) - - include Indexed_store.Make_singleton (struct - type t = value - - let name = "protocols" - - let level_encoding = - let open Data_encoding in - conv - (function - | First_known l -> (l, false) | Activation_level l -> (l, true)) - (function l, false -> First_known l | l, true -> Activation_level l) - @@ obj2 (req "level" int32) (req "activates" bool) - - let proto_info_encoding = - let open Data_encoding in - conv - (fun {level; proto_level; protocol} -> (level, proto_level, protocol)) - (fun (level, proto_level, protocol) -> {level; proto_level; protocol}) - @@ obj3 - (req "level" level_encoding) - (req "proto_level" int31) - (req "protocol" Protocol_hash.encoding) - - let encoding = Data_encoding.list proto_info_encoding - end) -end - -type 'a store = { - l2_blocks : 'a L2_blocks.t; - messages : 'a Messages.t; - inboxes : 'a Inboxes.t; - commitments : 'a Commitments.t; - commitments_published_at_level : 'a Commitments_published_at_level.t; - l2_head : 'a L2_head.t; - last_finalized_level : 'a Last_finalized_level.t; - levels_to_hashes : 'a Levels_to_hashes.t; - protocols : 'a Protocols.t; - irmin_store : 'a Irmin_store.t; -} - -type 'a t = ([< `Read | `Write > `Read] as 'a) store - -type rw = Store_sigs.rw t - -type ro = Store_sigs.ro t - -let readonly - ({ - l2_blocks; - messages; - inboxes; - commitments; - commitments_published_at_level; - l2_head; - last_finalized_level; - levels_to_hashes; - protocols; - irmin_store; - } : - _ t) : ro = - { - l2_blocks = L2_blocks.readonly l2_blocks; - messages = Messages.readonly messages; - inboxes = Inboxes.readonly inboxes; - commitments = Commitments.readonly commitments; - commitments_published_at_level = - Commitments_published_at_level.readonly commitments_published_at_level; - l2_head = L2_head.readonly l2_head; - last_finalized_level = Last_finalized_level.readonly last_finalized_level; - levels_to_hashes = Levels_to_hashes.readonly levels_to_hashes; - protocols = Protocols.readonly protocols; - irmin_store = Irmin_store.readonly irmin_store; - } - -let close - ({ - l2_blocks; - messages; - inboxes; - commitments; - commitments_published_at_level; - l2_head = _; - last_finalized_level = _; - levels_to_hashes; - protocols = _; - irmin_store; - } : - _ t) = - let open Lwt_result_syntax in - let+ () = L2_blocks.close l2_blocks - and+ () = Messages.close messages - and+ () = Inboxes.close inboxes - and+ () = Commitments.close commitments - and+ () = Commitments_published_at_level.close commitments_published_at_level - and+ () = Levels_to_hashes.close levels_to_hashes - and+ () = Irmin_store.close irmin_store in - () - -let load (type a) (mode : a mode) ~l2_blocks_cache_size data_dir : - a store tzresult Lwt.t = - let open Lwt_result_syntax in - let path name = Filename.concat data_dir name in - let cache_size = l2_blocks_cache_size in - let* l2_blocks = L2_blocks.load mode ~path:(path "l2_blocks") ~cache_size in - let* messages = Messages.load mode ~path:(path "messages") ~cache_size in - let* inboxes = Inboxes.load mode ~path:(path "inboxes") ~cache_size in - let* commitments = - Commitments.load mode ~path:(path "commitments") ~cache_size - in - let* commitments_published_at_level = - Commitments_published_at_level.load - mode - ~path:(path "commitments_published_at_level") - in - let* l2_head = L2_head.load mode ~path:(path "l2_head") in - let* last_finalized_level = - Last_finalized_level.load mode ~path:(path "last_finalized_level") - in - let* levels_to_hashes = - Levels_to_hashes.load mode ~path:(path "levels_to_hashes") - in - let* protocols = Protocols.load mode ~path:(path "protocols") in - let+ irmin_store = Irmin_store.load mode (path "irmin_store") in - { - l2_blocks; - messages; - inboxes; - commitments; - commitments_published_at_level; - l2_head; - last_finalized_level; - levels_to_hashes; - protocols; - irmin_store; - } - -let iter_l2_blocks ({l2_blocks; l2_head; _} : _ t) f = - let open Lwt_result_syntax in - let* head = L2_head.read l2_head in - match head with - | None -> - (* No reachable head, nothing to do *) - return_unit - | Some head -> - let rec loop hash = - let* block = L2_blocks.read l2_blocks hash in - match block with - | None -> - (* The block does not exist, the known chain stops here, so do we. *) - return_unit - | Some (block, header) -> - let* () = f {block with header} in - loop header.predecessor - in - loop head.header.block_hash diff --git a/src/proto_alpha/lib_sc_rollup_node/store_version.ml b/src/proto_alpha/lib_sc_rollup_node/store_version.ml deleted file mode 100644 index db71f628911302ba849e2d0fdec8895320b2db1b..0000000000000000000000000000000000000000 --- a/src/proto_alpha/lib_sc_rollup_node/store_version.ml +++ /dev/null @@ -1,61 +0,0 @@ -(*****************************************************************************) -(* *) -(* Open Source License *) -(* Copyright (c) 2023 Functori, *) -(* *) -(* 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. *) -(* *) -(*****************************************************************************) - -type t = V0 | V1 | V2 - -let pp ppf v = - Format.pp_print_string ppf - @@ match v with V0 -> "v0" | V1 -> "v1" | V2 -> "v2" - -let encoding = - let open Data_encoding in - conv - (function V0 -> 0 | V1 -> 1 | V2 -> 2) - (function - | 0 -> V0 - | 1 -> V1 - | 2 -> V2 - | v -> Format.ksprintf Stdlib.failwith "Unsupported store version %d" v) - (obj1 (req "store_version" int31)) - -let path ~dir = Filename.concat dir "version" - -let read_version_file ~dir = - let open Lwt_result_syntax in - protect @@ fun () -> - let filename = path ~dir in - let*! exists = Lwt_unix.file_exists filename in - if not exists then return_none - else - let* json = Lwt_utils_unix.Json.read_file filename in - return_some (Data_encoding.Json.destruct encoding json) - -let write_version_file ~dir version = - let open Lwt_result_syntax in - protect @@ fun () -> - let filename = path ~dir in - let*! () = Lwt_utils_unix.create_dir dir in - let json = Data_encoding.Json.construct encoding version in - Lwt_utils_unix.Json.write_file filename json diff --git a/src/proto_alpha/lib_sc_rollup_node/store_version.mli b/src/proto_alpha/lib_sc_rollup_node/store_version.mli deleted file mode 100644 index 1f2f8b4a26cc96d70357839ccee9be8f7a91acfb..0000000000000000000000000000000000000000 --- a/src/proto_alpha/lib_sc_rollup_node/store_version.mli +++ /dev/null @@ -1,35 +0,0 @@ -(*****************************************************************************) -(* *) -(* Open Source License *) -(* Copyright (c) 2023 Functori, *) -(* *) -(* 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. *) -(* *) -(*****************************************************************************) - -type t = V0 | V1 | V2 - -(** Pretty-printer for store versions *) -val pp : Format.formatter -> t -> unit - -(** Read the version file from [dir]. *) -val read_version_file : dir:string -> t option tzresult Lwt.t - -(** Write a version to the version file in [dir]. *) -val write_version_file : dir:string -> t -> unit tzresult Lwt.t diff --git a/src/proto_alpha/lib_sc_rollup_node/test/canary.ml b/src/proto_alpha/lib_sc_rollup_node/test/canary.ml index 0bec04dbbecfce279987f1fa040aa53ee9e37475..5e0877462c9e55c964dc40971dfa04d7d1bcca3b 100644 --- a/src/proto_alpha/lib_sc_rollup_node/test/canary.ml +++ b/src/proto_alpha/lib_sc_rollup_node/test/canary.ml @@ -31,6 +31,7 @@ Subject: Canary unit tests to make sure the test helpers work as intended *) +open Octez_smart_rollup open Protocol.Alpha_context let build_chain node_ctxt ~genesis ~length = @@ -55,9 +56,7 @@ let canary_test node_ctxt ~genesis = Node_context.get_l2_block node_ctxt block.header.block_hash in let* store_block_by_level = - Node_context.get_l2_block_by_level - node_ctxt - (Raw_level.to_int32 block.header.level) + Node_context.get_l2_block_by_level node_ctxt block.header.level in Helpers.Assert.L2_block.equal ~loc:__LOC__ diff --git a/src/proto_alpha/lib_sc_rollup_node/test/helpers/helpers.ml b/src/proto_alpha/lib_sc_rollup_node/test/helpers/helpers.ml index 9299b441332c34bb7bc89836491e9d3b7bd60696..efb908bcb9beac14683830f259d97ebbd76ab637 100644 --- a/src/proto_alpha/lib_sc_rollup_node/test/helpers/helpers.ml +++ b/src/proto_alpha/lib_sc_rollup_node/test/helpers/helpers.ml @@ -23,6 +23,7 @@ (* *) (*****************************************************************************) +open Octez_smart_rollup open Protocol open Alpha_context @@ -88,7 +89,7 @@ let add_l2_genesis_block (node_ctxt : _ Node_context.t) ~boot_sector = Sc_rollup_block. { block_hash = head.hash; - level = node_ctxt.genesis_info.level; + level = Raw_level.to_int32 node_ctxt.genesis_info.level; predecessor = predecessor.hash; commitment_hash = Some commitment_hash; previous_commitment_hash; @@ -98,7 +99,13 @@ let add_l2_genesis_block (node_ctxt : _ Node_context.t) ~boot_sector = } in let l2_block = - Sc_rollup_block.{header; content = (); num_ticks; initial_tick} + Sc_rollup_block. + { + header; + content = (); + num_ticks; + initial_tick = Sc_rollup.Tick.to_z initial_tick; + } in let* () = Node_context.save_l2_head node_ctxt l2_block in return l2_block @@ -182,7 +189,7 @@ let append_l2_block (node_ctxt : _ Node_context.t) ?(is_first_block = false) | None -> failwith "No genesis block, please add one with add_l2_genesis_block" in - let pred_level = Raw_level.to_int32 predecessor_l2_block.header.level in + let pred_level = predecessor_l2_block.header.level in let predecessor = head_of_level ~predecessor:predecessor_l2_block.header.predecessor @@ -205,9 +212,7 @@ let append_dummy_l2_chain node_ctxt ~length = let open Lwt_result_syntax in let* head = Node_context.last_processed_head_opt node_ctxt in let head_level = - match head with - | None -> 0 - | Some h -> h.header.level |> Raw_level.to_int32 |> Int32.to_int + match head with None -> 0 | Some h -> h.header.level |> Int32.to_int in let batches = Stdlib.List.init length (fun i -> diff --git a/src/proto_alpha/lib_sc_rollup_node/test/helpers/helpers.mli b/src/proto_alpha/lib_sc_rollup_node/test/helpers/helpers.mli index 6f2035aefe24db787122872a049e94c679c67f76..b6571220f74a7fe518c03d6ed1c25b4fb7d98451 100644 --- a/src/proto_alpha/lib_sc_rollup_node/test/helpers/helpers.mli +++ b/src/proto_alpha/lib_sc_rollup_node/test/helpers/helpers.mli @@ -23,6 +23,7 @@ (* *) (*****************************************************************************) +open Octez_smart_rollup open Protocol open Alpha_context diff --git a/src/proto_alpha/lib_sc_rollup_node/test/test_octez_conversions.ml b/src/proto_alpha/lib_sc_rollup_node/test/test_octez_conversions.ml index 9a27026ae3ad700cc283c2e6c3ad6f3249f26a8f..f099fdb8e4ffa7edb7b1ee3ef84a99dcc5e0cfa2 100644 --- a/src/proto_alpha/lib_sc_rollup_node/test/test_octez_conversions.ml +++ b/src/proto_alpha/lib_sc_rollup_node/test/test_octez_conversions.ml @@ -189,6 +189,67 @@ let gen_inbox = | Error e -> Stdlib.failwith (Format.asprintf "%a" Error_monad.pp_print_trace e)) +let gen_slot_index = + let open QCheck2.Gen in + graft_corners (int_bound 0xff) [0; 1; 2; 0xff] () + +let gen_page_index = + let open QCheck2.Gen in + let max = 0xfff / 2 in + graft_corners (int_bound max) [0; 1; 2; max] () + +let gen_slot_header_commitment = + let open QCheck2.Gen in + make_primitive + ~gen:(fun state -> + Tezos_crypto_dal.Cryptobox.Internal_for_tests.dummy_commitment ~state ()) + ~shrink:(fun _ -> Seq.empty) + +let gen_slot_header = + let open QCheck2.Gen in + let* published_level = gen_level in + let* index = gen_slot_index in + let+ commitment = gen_slot_header_commitment in + Octez_smart_rollup.Dal.Slot_header.{id = {published_level; index}; commitment} + +let compare_slot_header_id (s1 : Octez_smart_rollup.Dal.Slot_header.id) + (s2 : Octez_smart_rollup.Dal.Slot_header.id) = + let c = Int32.compare s1.published_level s2.published_level in + if c <> 0 then c else Int.compare s1.index s2.index + +let gen_slot_headers = + let open QCheck2.Gen in + let size = int_bound 50 in + let+ l = list_size size gen_slot_header in + List.sort + (fun (h1 : Octez_smart_rollup.Dal.Slot_header.t) + (h2 : Octez_smart_rollup.Dal.Slot_header.t) -> + compare_slot_header_id h1.id h2.id) + l + +let gen_slot_history = + let open Protocol.Alpha_context in + let open QCheck2.Gen in + let h = Dal.Slots_history.genesis in + let+ l = gen_slot_headers in + let l = List.map Sc_rollup_proto_types.Dal.Slot_header.of_octez l in + Dal.Slots_history.add_confirmed_slot_headers_no_cache h l |> function + | Error e -> + Stdlib.failwith (Format.asprintf "%a" Environment.Error_monad.pp_trace e) + | Ok v -> Sc_rollup_proto_types.Dal.Slot_history.to_octez v + +let gen_slot_history_cache = + let open Protocol.Alpha_context in + let open QCheck2.Gen in + let h = Dal.Slots_history.genesis in + let c = Dal.Slots_history.History_cache.empty ~capacity:Int64.max_int in + let+ l = gen_slot_headers in + let l = List.map Sc_rollup_proto_types.Dal.Slot_header.of_octez l in + Dal.Slots_history.add_confirmed_slot_headers h c l |> function + | Error e -> + Stdlib.failwith (Format.asprintf "%a" Environment.Error_monad.pp_trace e) + | Ok (_, c) -> Sc_rollup_proto_types.Dal.Slot_history_cache.to_octez c + let test_roundtrip ~count name gen to_octez from_octez octez_encoding proto_encoding = let test octez1 = @@ -306,6 +367,56 @@ let test_inbox = Octez_smart_rollup.Inbox.encoding Protocol.Alpha_context.Sc_rollup.Inbox.encoding +let test_slot_index = + test_roundtrip + ~count:100 + "dal_slot_index" + gen_slot_index + Sc_rollup_proto_types.Dal.Slot_index.to_octez + Sc_rollup_proto_types.Dal.Slot_index.of_octez + Octez_smart_rollup.Dal.Slot_index.encoding + Protocol.Alpha_context.Dal.Slot_index.encoding + +let test_page_index = + test_roundtrip + ~count:100 + "dal_page_index" + gen_page_index + Sc_rollup_proto_types.Dal.Page_index.to_octez + Sc_rollup_proto_types.Dal.Page_index.of_octez + Octez_smart_rollup.Dal.Page_index.encoding + Protocol.Alpha_context.Dal.Page.Index.encoding + +let test_slot_header = + test_roundtrip + ~count:1000 + "dal_slot_header" + gen_slot_header + Sc_rollup_proto_types.Dal.Slot_header.to_octez + Sc_rollup_proto_types.Dal.Slot_header.of_octez + Octez_smart_rollup.Dal.Slot_header.encoding + Protocol.Alpha_context.Dal.Slot.Header.encoding + +let test_slot_history = + test_roundtrip + ~count:300 + "dal_slot_history" + gen_slot_history + Sc_rollup_proto_types.Dal.Slot_history.to_octez + Sc_rollup_proto_types.Dal.Slot_history.of_octez + Octez_smart_rollup.Dal.Slot_history.encoding + Protocol.Alpha_context.Dal.Slots_history.encoding + +let test_slot_history_cache = + test_roundtrip + ~count:300 + "dal_slot_history_cache" + gen_slot_history_cache + Sc_rollup_proto_types.Dal.Slot_history_cache.to_octez + Sc_rollup_proto_types.Dal.Slot_history_cache.of_octez + Octez_smart_rollup.Dal.Slot_history_cache.encoding + Protocol.Alpha_context.Dal.Slots_history.History_cache.encoding + let tests = [ test_address; @@ -316,6 +427,11 @@ let tests = test_stakers; test_refutation; test_inbox; + test_slot_index; + test_page_index; + test_slot_header; + test_slot_history; + test_slot_history_cache; ] let () = diff --git a/tezt/tests/expected/sc_rollup.ml/Alpha- arith - RPC API should work and be stable.out b/tezt/tests/expected/sc_rollup.ml/Alpha- arith - RPC API should work and be stable.out index 0138355bacce960eb3333473d1892088de4c5286..2d1b4762c72e81eae2763bc3cb05aa607120f9c4 100644 --- a/tezt/tests/expected/sc_rollup.ml/Alpha- arith - RPC API should work and be stable.out +++ b/tezt/tests/expected/sc_rollup.ml/Alpha- arith - RPC API should work and be stable.out @@ -294,5 +294,6 @@ Error [ "[SC_ROLLUP_INBOX_HASH]", "[SC_ROLLUP_INBOX_HASH]", "[SC_ROLLUP_INBOX_HASH]" ] } }, - "messages": [ "31352d31", "31352d32", "31352d33", "31352d34", "31352d35" ], + "messages": + [ "0131352d31", "0131352d32", "0131352d33", "0131352d34", "0131352d35" ], "initial_tick": "352", "num_ticks": "28" } diff --git a/tezt/tests/expected/sc_rollup.ml/Alpha- wasm_2_0_0 - RPC API should work and be stable.out b/tezt/tests/expected/sc_rollup.ml/Alpha- wasm_2_0_0 - RPC API should work and be stable.out index 374d4e62cfa3f91c03e5dce81fa530add229f5c2..9854fc7329c87dfd4ae2156f19b398486f758328 100644 --- a/tezt/tests/expected/sc_rollup.ml/Alpha- wasm_2_0_0 - RPC API should work and be stable.out +++ b/tezt/tests/expected/sc_rollup.ml/Alpha- wasm_2_0_0 - RPC API should work and be stable.out @@ -299,5 +299,6 @@ null [ "[SC_ROLLUP_INBOX_HASH]", "[SC_ROLLUP_INBOX_HASH]", "[SC_ROLLUP_INBOX_HASH]" ] } }, - "messages": [ "31352d31", "31352d32", "31352d33", "31352d34", "31352d35" ], + "messages": + [ "0131352d31", "0131352d32", "0131352d33", "0131352d34", "0131352d35" ], "initial_tick": "1430000000000", "num_ticks": "99000000000" } diff --git a/tezt/tests/expected/sc_rollup.ml/Mumbai- arith - RPC API should work and be stable.out b/tezt/tests/expected/sc_rollup.ml/Mumbai- arith - RPC API should work and be stable.out index 4fa98a5e304c5a7fe25c5b672f520080100aef94..9af5deaa0e81bfcbdf5294620cc3762de6b3cf8c 100644 --- a/tezt/tests/expected/sc_rollup.ml/Mumbai- arith - RPC API should work and be stable.out +++ b/tezt/tests/expected/sc_rollup.ml/Mumbai- arith - RPC API should work and be stable.out @@ -294,5 +294,6 @@ Error [ "[SC_ROLLUP_INBOX_HASH]", "[SC_ROLLUP_INBOX_HASH]", "[SC_ROLLUP_INBOX_HASH]" ] } }, - "messages": [ "31352d31", "31352d32", "31352d33", "31352d34", "31352d35" ], + "messages": + [ "0131352d31", "0131352d32", "0131352d33", "0131352d34", "0131352d35" ], "initial_tick": "352", "num_ticks": "28" } diff --git a/tezt/tests/expected/sc_rollup.ml/Mumbai- wasm_2_0_0 - RPC API should work and be stable.out b/tezt/tests/expected/sc_rollup.ml/Mumbai- wasm_2_0_0 - RPC API should work and be stable.out index 916c93fd2050f04af9d748d67a8aea6ed13ab22a..fcd9232fe4719db9b3e15fe4eb568c50781f9ddb 100644 --- a/tezt/tests/expected/sc_rollup.ml/Mumbai- wasm_2_0_0 - RPC API should work and be stable.out +++ b/tezt/tests/expected/sc_rollup.ml/Mumbai- wasm_2_0_0 - RPC API should work and be stable.out @@ -299,5 +299,6 @@ null [ "[SC_ROLLUP_INBOX_HASH]", "[SC_ROLLUP_INBOX_HASH]", "[SC_ROLLUP_INBOX_HASH]" ] } }, - "messages": [ "31352d31", "31352d32", "31352d33", "31352d34", "31352d35" ], + "messages": + [ "0131352d31", "0131352d32", "0131352d33", "0131352d34", "0131352d35" ], "initial_tick": "1430000000000", "num_ticks": "99000000000" } diff --git a/tezt/tests/expected/sc_rollup.ml/Nairobi- arith - RPC API should work and be stable.out b/tezt/tests/expected/sc_rollup.ml/Nairobi- arith - RPC API should work and be stable.out index a0ba11776392856e1fef7f06b5cc3f6a05b4ad51..d58f7d4ed12e3963ddcbb7a089cd5e81bdea6a2f 100644 --- a/tezt/tests/expected/sc_rollup.ml/Nairobi- arith - RPC API should work and be stable.out +++ b/tezt/tests/expected/sc_rollup.ml/Nairobi- arith - RPC API should work and be stable.out @@ -294,5 +294,6 @@ Error [ "[SC_ROLLUP_INBOX_HASH]", "[SC_ROLLUP_INBOX_HASH]", "[SC_ROLLUP_INBOX_HASH]" ] } }, - "messages": [ "31352d31", "31352d32", "31352d33", "31352d34", "31352d35" ], + "messages": + [ "0131352d31", "0131352d32", "0131352d33", "0131352d34", "0131352d35" ], "initial_tick": "352", "num_ticks": "28" } diff --git a/tezt/tests/expected/sc_rollup.ml/Nairobi- wasm_2_0_0 - RPC API should work and be stable.out b/tezt/tests/expected/sc_rollup.ml/Nairobi- wasm_2_0_0 - RPC API should work and be stable.out index 5440a7e69eb3c1831de46c2168222fe2722f399a..ebb58822677775427e79b588ae648ffdba66cc82 100644 --- a/tezt/tests/expected/sc_rollup.ml/Nairobi- wasm_2_0_0 - RPC API should work and be stable.out +++ b/tezt/tests/expected/sc_rollup.ml/Nairobi- wasm_2_0_0 - RPC API should work and be stable.out @@ -299,5 +299,6 @@ null [ "[SC_ROLLUP_INBOX_HASH]", "[SC_ROLLUP_INBOX_HASH]", "[SC_ROLLUP_INBOX_HASH]" ] } }, - "messages": [ "31352d31", "31352d32", "31352d33", "31352d34", "31352d35" ], + "messages": + [ "0131352d31", "0131352d32", "0131352d33", "0131352d34", "0131352d35" ], "initial_tick": "1430000000000", "num_ticks": "99000000000" }