diff --git a/src/proto_alpha/bin_sc_rollup_node/inbox.ml b/src/proto_alpha/bin_sc_rollup_node/inbox.ml index 41502115bdb517dc4c0444df77cafce76f22d29c..8d3b10f1fd266126a3161b97d141b5faa1a78d2f 100644 --- a/src/proto_alpha/bin_sc_rollup_node/inbox.ml +++ b/src/proto_alpha/bin_sc_rollup_node/inbox.ml @@ -119,7 +119,7 @@ let process_head Node_context.({l1_ctxt; rollup_address; _} as node_ctxt) store let*? messages = List.map_e (fun message -> - Sc_rollup.Inbox.Message.(to_bytes @@ External message)) + Sc_rollup.Inbox.Message.(serialize @@ External message)) messages in let* messages_tree, history, inbox = diff --git a/src/proto_alpha/bin_sc_rollup_node/interpreter.ml b/src/proto_alpha/bin_sc_rollup_node/interpreter.ml index 3c3ebbdbad26161de3712e9cfdccdd290c94670f..76f22f45dbe2c94aeb0a5ad1f7d1f7cfbc01a910 100644 --- a/src/proto_alpha/bin_sc_rollup_node/interpreter.ml +++ b/src/proto_alpha/bin_sc_rollup_node/interpreter.ml @@ -97,7 +97,8 @@ module Make (PVM : Pvm.S) : S = struct (fun message_counter state external_message -> let message = Sc_rollup.Inbox.Message.External external_message in let*? payload = - Environment.wrap_tzresult (Sc_rollup.Inbox.Message.to_bytes message) + Environment.wrap_tzresult + (Sc_rollup.Inbox.Message.serialize message) in let input = Sc_rollup. diff --git a/src/proto_alpha/lib_benchmarks_proto/sc_rollup_benchmarks.ml b/src/proto_alpha/lib_benchmarks_proto/sc_rollup_benchmarks.ml index de1eed2923381874f0645847e4553a8f75f0c42f..13600e97c04803cb2ffe73e6b870b365ce660caa 100644 --- a/src/proto_alpha/lib_benchmarks_proto/sc_rollup_benchmarks.ml +++ b/src/proto_alpha/lib_benchmarks_proto/sc_rollup_benchmarks.ml @@ -105,7 +105,7 @@ module Sc_rollup_update_num_and_size_of_messages_benchmark = struct let new_message = WithExceptions.Result.get_ok ~loc:__LOC__ @@ Sc_rollup_inbox_message_repr.( - to_bytes @@ External new_external_message) + serialize @@ External new_external_message) in let workload = () in let closure () = @@ -190,7 +190,7 @@ module Sc_rollup_add_external_messages_benchmark = struct in let message = WithExceptions.Result.get_ok ~loc:__LOC__ - @@ Sc_rollup_inbox_message_repr.(to_bytes @@ External external_message) + @@ Sc_rollup_inbox_message_repr.(serialize @@ External external_message) in let last_level_int = Base_samplers.sample_in_interval diff --git a/src/proto_alpha/lib_client_commands/client_proto_context_commands.ml b/src/proto_alpha/lib_client_commands/client_proto_context_commands.ml index 06cf66a0930ca1dd2138fa3a6975b9dd2fd359a1..17d1f91634f6aae969eb05914c6d0bb42c1e537f 100644 --- a/src/proto_alpha/lib_client_commands/client_proto_context_commands.ml +++ b/src/proto_alpha/lib_client_commands/client_proto_context_commands.ml @@ -2514,7 +2514,8 @@ let commands_rw () = @@ param ~name:"parameters_type" ~desc: - "The type of parameters that the smart-contract rollup accepts." + "The interface of the smart-contract rollup including its \ + entrypoints and their signatures." data_parameter @@ prefixes ["booting"; "with"] @@ param diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index c43ea5dd8d27cd18407c4ebde422ba38e4496572..306daa7d0dc68b84935fcd0c1c9d4c94b9055548 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -2793,9 +2793,9 @@ module Sc_rollup : sig val unsafe_of_string : string -> serialized - val to_bytes : t -> serialized tzresult + val serialize : t -> serialized tzresult - val of_bytes : serialized -> t tzresult + val deserialize : serialized -> t tzresult end val pp : Format.formatter -> t -> unit @@ -2932,12 +2932,14 @@ module Sc_rollup : sig type t = Atomic_transaction_batch of {transactions : transaction list} - val of_bytes : string -> t tzresult + type serialized = private string + + val deserialize : serialized -> t tzresult (** This module discloses definitions that are only useful for tests and must not be used otherwise. *) module Internal_for_tests : sig - val to_bytes : t -> string tzresult + val serialize : t -> serialized tzresult end end @@ -3210,12 +3212,14 @@ module Sc_rollup : sig val player_equal : player -> player -> bool + type dissection_chunk = {state_hash : State_hash.t option; tick : Tick.t} + type t = { turn : player; inbox_snapshot : Inbox.t; level : Raw_level.t; pvm_name : string; - dissection : (State_hash.t option * Tick.t) list; + dissection : dissection_chunk list; } val pp : Format.formatter -> t -> unit @@ -3230,9 +3234,7 @@ module Sc_rollup : sig val opponent : player -> player - type step = - | Dissection of (State_hash.t option * Tick.t) list - | Proof of Proof.t + type step = Dissection of dissection_chunk list | Proof of Proof.t type refutation = {choice : Tick.t; step : step} @@ -3270,7 +3272,7 @@ module Sc_rollup : sig Tick.t -> State_hash.t option -> Tick.t -> - (State_hash.t option * Tick.t) list -> + dissection_chunk list -> (unit, error) result Lwt.t val play : t -> refutation -> (outcome, t) Either.t Lwt.t diff --git a/src/proto_alpha/lib_protocol/operation_repr.mli b/src/proto_alpha/lib_protocol/operation_repr.mli index 38939f4c9608b46dcb0833f2d8b4fcef0b542676..d8caa794bc15b60a49378dff9f23ee36c8cc052f 100644 --- a/src/proto_alpha/lib_protocol/operation_repr.mli +++ b/src/proto_alpha/lib_protocol/operation_repr.mli @@ -458,9 +458,12 @@ and _ manager_operation = slot : Dal_slot_repr.t; } -> Kind.dal_publish_slot_header manager_operation - (* [Sc_rollup_originate] allows an implicit account to originate a new - smart contract rollup (initialized with a given boot - sector). *) + (** [Sc_rollup_originate] allows an implicit account to originate a new + smart contract rollup (initialized with a given boot sector). + The [parameters_ty] field allows to provide the expected interface + of the rollup being originated (i.e. its entrypoints with their + associated signatures) as a Michelson type. + *) | Sc_rollup_originate : { kind : Sc_rollups.Kind.t; boot_sector : string; diff --git a/src/proto_alpha/lib_protocol/sc_rollup_PVM_sem.ml b/src/proto_alpha/lib_protocol/sc_rollup_PVM_sem.ml index fc4d848b57d9ec76f831f3fe9a4a3cc2cfb37bf4..b0f31b34aed2ee813fde2ffd4e5ce9049658c65c 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_PVM_sem.ml +++ b/src/proto_alpha/lib_protocol/sc_rollup_PVM_sem.ml @@ -75,7 +75,7 @@ let input_request_encoding = case ~title:"First_after" (Tag 2) - (tup2 Raw_level_repr.encoding n) + (obj2 (req "level" Raw_level_repr.encoding) (req "counter" n)) (function | First_after (level, counter) -> Some (level, counter) | _ -> None) (fun (level, counter) -> First_after (level, counter)); diff --git a/src/proto_alpha/lib_protocol/sc_rollup_arith.ml b/src/proto_alpha/lib_protocol/sc_rollup_arith.ml index 06453b59bd23ba14253b56ffc1348e75599d3bc4..acad3966734dae661452298a39844bdb7d9787d1 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_arith.ml +++ b/src/proto_alpha/lib_protocol/sc_rollup_arith.ml @@ -803,7 +803,7 @@ module Make (Context : P) : let set_input_monadic {PS.inbox_level; message_counter; payload} = let open Monad.Syntax in - match Sc_rollup_inbox_message_repr.of_bytes payload with + match Sc_rollup_inbox_message_repr.deserialize payload with | Ok (External payload) -> let* boot_sector = Boot_sector.get in let msg = boot_sector ^ payload in diff --git a/src/proto_alpha/lib_protocol/sc_rollup_game_repr.ml b/src/proto_alpha/lib_protocol/sc_rollup_game_repr.ml index 1bea47bf9392067fdef7f1deede12de9f0a25229..310a968230f8d1adfb373654862bcfe9e1676289 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_game_repr.ml +++ b/src/proto_alpha/lib_protocol/sc_rollup_game_repr.ml @@ -28,13 +28,18 @@ open Sc_rollup_repr type player = Alice | Bob +type dissection_chunk = { + state_hash : State_hash.t option; + tick : Sc_rollup_tick_repr.t; +} + module V1 = struct type t = { turn : player; inbox_snapshot : Sc_rollup_inbox_repr.t; level : Raw_level_repr.t; pvm_name : string; - dissection : (State_hash.t option * Sc_rollup_tick_repr.t) list; + dissection : dissection_chunk list; } let player_encoding = @@ -62,6 +67,10 @@ module V1 = struct | Bob, Bob -> true | _, _ -> false + let dissection_chunk_equal {state_hash; tick} chunk2 = + Option.equal State_hash.equal state_hash chunk2.state_hash + && Sc_rollup_tick_repr.equal tick chunk2.tick + let equal { turn = turn1; @@ -81,12 +90,7 @@ module V1 = struct && Sc_rollup_inbox_repr.equal inbox_snapshot1 inbox_snapshot2 && Raw_level_repr.equal level1 level2 && String.equal pvm_name1 pvm_name2 - && List.equal - (fun (h1, t1) (h2, t2) -> - Option.equal State_hash.equal h1 h2 - && Sc_rollup_tick_repr.equal t1 t2) - dissection1 - dissection2 + && List.equal dissection_chunk_equal dissection1 dissection2 let string_of_player = function Alice -> "alice" | Bob -> "bob" @@ -94,6 +98,16 @@ module V1 = struct let opponent = function Alice -> Bob | Bob -> Alice + let dissection_encoding = + let open Data_encoding in + list + (conv + (fun {state_hash; tick} -> (state_hash, tick)) + (fun (state_hash, tick) -> {state_hash; tick}) + (obj2 + (req "state" (option State_hash.encoding)) + (req "tick" Sc_rollup_tick_repr.encoding))) + let encoding = let open Data_encoding in conv @@ -106,20 +120,17 @@ module V1 = struct (req "inbox_snapshot" Sc_rollup_inbox_repr.encoding) (req "level" Raw_level_repr.encoding) (req "pvm_name" string) - (req - "dissection" - (list - (tup2 (option State_hash.encoding) Sc_rollup_tick_repr.encoding)))) + (req "dissection" dissection_encoding)) let pp_dissection ppf d = Format.pp_print_list ~pp_sep:(fun ppf () -> Format.pp_print_string ppf ";\n") - (fun ppf (state, tick) -> + (fun ppf {state_hash; tick} -> Format.fprintf ppf " %a @ %a" (Format.pp_print_option State_hash.pp) - state + state_hash Sc_rollup_tick_repr.pp tick) ppf @@ -213,6 +224,8 @@ module Index = struct let staker {alice; bob} = function Alice -> alice | Bob -> bob end +let make_chunk state_hash tick = {state_hash; tick} + let initial inbox ~pvm_name ~(parent : Sc_rollup_commitment_repr.t) ~(child : Sc_rollup_commitment_repr.t) ~refuter ~defender = let ({alice; _} : Index.t) = Index.make refuter defender in @@ -225,14 +238,14 @@ let initial inbox ~pvm_name ~(parent : Sc_rollup_commitment_repr.t) pvm_name; dissection = [ - (Some parent.compressed_state, Sc_rollup_tick_repr.initial); - (Some child.compressed_state, tick); - (None, Sc_rollup_tick_repr.next tick); + make_chunk (Some parent.compressed_state) Sc_rollup_tick_repr.initial; + make_chunk (Some child.compressed_state) tick; + make_chunk None (Sc_rollup_tick_repr.next tick); ]; } type step = - | Dissection of (State_hash.t option * Sc_rollup_tick_repr.t) list + | Dissection of dissection_chunk list | Proof of Sc_rollup_proof_repr.t let step_encoding = @@ -243,7 +256,7 @@ let step_encoding = case ~title:"Dissection" (Tag 0) - (list (tup2 (option State_hash.encoding) Sc_rollup_tick_repr.encoding)) + dissection_encoding (function Dissection d -> Some d | _ -> None) (fun d -> Dissection d); case @@ -260,14 +273,14 @@ let pp_step ppf step = Format.fprintf ppf "dissection:\n" ; Format.pp_print_list ~pp_sep:(fun ppf () -> Format.pp_print_string ppf ";\n\n") - (fun ppf (hash, t) -> + (fun ppf {state_hash; tick} -> Format.fprintf ppf "tick = %a, state = %a\n" Sc_rollup_tick_repr.pp - t + tick (Format.pp_print_option State_hash.pp) - hash) + state_hash) ppf states | Proof proof -> Format.fprintf ppf "proof: %a" Sc_rollup_proof_repr.pp proof @@ -356,7 +369,7 @@ let status_encoding = case ~title:"Ended" (Tag 1) - (tup2 reason_encoding Staker.encoding) + (obj2 (req "reason" reason_encoding) (req "staker" Staker.encoding)) (function Ended (r, s) -> Some (r, s) | _ -> None) (fun (r, s) -> Ended (r, s)); ] @@ -389,10 +402,12 @@ let find_choice game tick = let open Lwt_result_syntax in let rec traverse states = match states with - | (state, state_tick) :: (next_state, next_tick) :: others -> + | {state_hash = state; tick = state_tick} + :: ({state_hash = next_state; tick = next_tick} as next) + :: others -> if Sc_rollup_tick_repr.(tick = state_tick) then return (state, tick, next_state, next_tick) - else traverse ((next_state, next_tick) :: others) + else traverse (next :: others) | _ -> game_error "This choice was not proposed" in traverse game.dissection @@ -419,7 +434,8 @@ let check_dissection start start_tick stop stop_tick dissection = in let* _ = match (List.hd dissection, List.last_opt dissection) with - | Some (a, a_tick), Some (b, b_tick) -> + | Some {state_hash = a; tick = a_tick}, Some {state_hash = b; tick = b_tick} + -> let* () = check (Option.equal State_hash.equal a start && not (Option.is_none a)) @@ -460,13 +476,12 @@ let check_dissection start start_tick stop stop_tick dissection = in let rec traverse states = match states with - | (None, _) :: (Some _, _) :: _ -> + | {state_hash = None; _} :: {state_hash = Some _; _} :: _ -> game_error "Cannot return to a Some state after being at a None state" - | (_, tick) :: (next_state, next_tick) :: others -> + | {tick; _} :: ({tick = next_tick; state_hash = _} as next) :: others -> if Sc_rollup_tick_repr.(tick < next_tick) then let incr = Sc_rollup_tick_repr.distance tick next_tick in - if Z.(leq incr (div dist (of_int 2))) then - traverse ((next_state, next_tick) :: others) + if Z.(leq incr (div dist (of_int 2))) then traverse (next :: others) else game_error "Maximum tick increment in dissection must be less than half \ diff --git a/src/proto_alpha/lib_protocol/sc_rollup_game_repr.mli b/src/proto_alpha/lib_protocol/sc_rollup_game_repr.mli index 6eab6370d3e5b3741c23f0ecc26c697e3939f886..351ad0ffe53d9ba3963f04cc680389bbb8fd732b 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_game_repr.mli +++ b/src/proto_alpha/lib_protocol/sc_rollup_game_repr.mli @@ -85,7 +85,7 @@ equipped with a perfect PVM to play an honest next move: The player with a perfect PVM can calculate honest hashes until - one disagrees with the [dissection], and challenge the dissection + one disagrees with the [dissection], and challenges the dissection at that point, publishing either an honest [dissection] or an honest [Proof]. @@ -129,6 +129,13 @@ open Sc_rollup_repr represent the first and second player in the pair respectively. *) type player = Alice | Bob +(** A dissection chunk is made of a state hash (that could be [None], see + invariants below), and a tick count. *) +type dissection_chunk = { + state_hash : State_hash.t option; + tick : Sc_rollup_tick_repr.t; +} + module V1 : sig (** A game state is characterized by: @@ -164,7 +171,7 @@ module V1 : sig inbox_snapshot : Sc_rollup_inbox_repr.t; level : Raw_level_repr.t; pvm_name : string; - dissection : (State_hash.t option * Sc_rollup_tick_repr.t) list; + dissection : dissection_chunk list; } (** [equal g1 g2] returns [true] iff [g1] is equal to [g2]. *) @@ -175,10 +182,7 @@ module V1 : sig val encoding : t Data_encoding.t - val pp_dissection : - Format.formatter -> - (Sc_rollup_repr.State_hash.t option * Sc_rollup_tick_repr.t) list -> - unit + val pp_dissection : Format.formatter -> dissection_chunk list -> unit val player_equal : player -> player -> bool @@ -248,7 +252,7 @@ val initial : (** A [step] in the game is either a new dissection (if there are intermediate ticks remaining to put in it) or a proof. *) type step = - | Dissection of (State_hash.t option * Sc_rollup_tick_repr.t) list + | Dissection of dissection_chunk list | Proof of Sc_rollup_proof_repr.t (** A [refutation] is a move in the game. [choice] is the final tick @@ -330,7 +334,7 @@ val check_dissection : Sc_rollup_tick_repr.t -> Sc_rollup_repr.State_hash.t option -> Sc_rollup_tick_repr.t -> - (Sc_rollup_repr.State_hash.t option * Sc_rollup_tick_repr.t) list -> + dissection_chunk list -> (unit, error) result Lwt.t (** Applies the move [refutation] to the game. Checks the move is diff --git a/src/proto_alpha/lib_protocol/sc_rollup_inbox_message_repr.ml b/src/proto_alpha/lib_protocol/sc_rollup_inbox_message_repr.ml index 59f41d448821b5989dddfcccf2ee29d2f72970fc..6d3cd8fce6bbb0df218ece00888f2ea8a8bfafce 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_inbox_message_repr.ml +++ b/src/proto_alpha/lib_protocol/sc_rollup_inbox_message_repr.ml @@ -90,15 +90,15 @@ let encoding = type serialized = string -let to_bytes msg = +let serialize msg = let open Tzresult_syntax in match Data_encoding.Binary.to_string_opt encoding msg with | None -> fail Error_encode_inbox_message | Some str -> return str -let of_bytes bytes = +let deserialize s = let open Tzresult_syntax in - match Data_encoding.Binary.of_string_opt encoding bytes with + match Data_encoding.Binary.of_string_opt encoding s with | None -> fail Error_decode_inbox_message | Some msg -> return msg diff --git a/src/proto_alpha/lib_protocol/sc_rollup_inbox_message_repr.mli b/src/proto_alpha/lib_protocol/sc_rollup_inbox_message_repr.mli index 394106f27be46f1ed7c89bc7ea83bbc73bbe5644..11bad2ffa7c3b8f46e1a5c0f70d607adfe7cb877 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_inbox_message_repr.mli +++ b/src/proto_alpha/lib_protocol/sc_rollup_inbox_message_repr.mli @@ -65,8 +65,8 @@ type serialized = private string val unsafe_of_string : string -> serialized -(** [to_bytes msg] encodes the inbox message [msg] in binary format. *) -val to_bytes : t -> serialized tzresult +(** [serialize msg] encodes the inbox message [msg] in binary format. *) +val serialize : t -> serialized tzresult -(** [of_bytes bs] decodes [bs] as an [inbox_message]. *) -val of_bytes : serialized -> t tzresult +(** [deserialize bs] decodes [bs] as an inbox_message [t]. *) +val deserialize : serialized -> t tzresult diff --git a/src/proto_alpha/lib_protocol/sc_rollup_inbox_storage.ml b/src/proto_alpha/lib_protocol/sc_rollup_inbox_storage.ml index 43c8d4161c7fcf10b9f1164e7868f27976830d13..072255fdcba5b9ec1cfb99a3fc1fe8f2efd06081 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_inbox_storage.ml +++ b/src/proto_alpha/lib_protocol/sc_rollup_inbox_storage.ml @@ -156,7 +156,7 @@ let serialize_external_messages ctxt external_messages = ctxt (Sc_rollup_costs.cost_serialize_external_inbox_message ~bytes_len) in - let* serialized_message = to_bytes @@ External message in + let* serialized_message = serialize @@ External message in return (ctxt, serialized_message)) ctxt external_messages @@ -173,7 +173,7 @@ let serialize_internal_message ctxt ~payload ~sender ~source = (Sc_rollup_costs.cost_serialize_internal_inbox_message internal_message) in let* message = - Sc_rollup_inbox_message_repr.(to_bytes @@ Internal internal_message) + Sc_rollup_inbox_message_repr.(serialize @@ Internal internal_message) in return (message, ctxt) diff --git a/src/proto_alpha/lib_protocol/sc_rollup_management_protocol.ml b/src/proto_alpha/lib_protocol/sc_rollup_management_protocol.ml index 47d64f42d46aef41d7e219493fdf84176c4d5f78..9237267ded7002048069bc48061d4bbaa15e6d2c 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_management_protocol.ml +++ b/src/proto_alpha/lib_protocol/sc_rollup_management_protocol.ml @@ -146,7 +146,7 @@ module Internal_for_tests = struct let make_atomic_batch transactions = Atomic_transaction_batch {transactions} - let bytes_of_outbox_message (Atomic_transaction_batch {transactions}) = + let serialize_outbox_message (Atomic_transaction_batch {transactions}) = let open Tzresult_syntax in let to_internal_transaction (Transaction @@ -164,7 +164,8 @@ module Internal_for_tests = struct let output_message_internal = Sc_rollup.Outbox.Message.Atomic_transaction_batch {transactions} in - Sc_rollup.Outbox.Message.Internal_for_tests.to_bytes output_message_internal + Sc_rollup.Outbox.Message.Internal_for_tests.serialize + output_message_internal - let inbox_message_of_bytes = Sc_rollup.Inbox.Message.of_bytes + let deserialize_inbox_message = Sc_rollup.Inbox.Message.deserialize end diff --git a/src/proto_alpha/lib_protocol/sc_rollup_management_protocol.mli b/src/proto_alpha/lib_protocol/sc_rollup_management_protocol.mli index 71f63d5db286d051423570c608cdec715469cf41..688fd402cd86a99f90f5a3fbf931069d7d56610c 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_management_protocol.mli +++ b/src/proto_alpha/lib_protocol/sc_rollup_management_protocol.mli @@ -100,12 +100,13 @@ module Internal_for_tests : sig transactions [ts]. *) val make_atomic_batch : transaction list -> outbox_message - (** [bytes_of_output_message msg] encodes the outbox message [msg] in binary + (** [serialize_output_message msg] encodes the outbox message [msg] in binary format. *) - val bytes_of_outbox_message : outbox_message -> string tzresult + val serialize_outbox_message : + outbox_message -> Sc_rollup.Outbox.Message.serialized tzresult - (** [inbox_message_of_bytes bs] decodes an inbox message from the given bytes + (** [deserialize_inbox_message bs] decodes an inbox message from the given data [bs]. *) - val inbox_message_of_bytes : + val deserialize_inbox_message : Sc_rollup.Inbox.Message.serialized -> Sc_rollup.Inbox.Message.t tzresult end diff --git a/src/proto_alpha/lib_protocol/sc_rollup_operations.mli b/src/proto_alpha/lib_protocol/sc_rollup_operations.mli index 189ecc7268dfada128951f147b7de2ca9dbe167c..7eb6c5afea885331529f29b72d8a3db0832685de 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_operations.mli +++ b/src/proto_alpha/lib_protocol/sc_rollup_operations.mli @@ -40,8 +40,9 @@ type execute_outbox_message_result = { type origination_result = {address : Sc_rollup.Address.t; size : Z.t} -(** [originate context ~kind ~boot_sector] adds a new rollup running in a - given [kind] initialized with a [boot_sector]. *) +(** [originate context ~kind ~boot_sector ~parameters_ty] adds a new rollup + running in a given [kind], initialized with a [boot_sector], and whose + expected signature/interface is [parameters_ty]. *) val originate : context -> kind:Sc_rollup.Kind.t -> diff --git a/src/proto_alpha/lib_protocol/sc_rollup_outbox_message_repr.ml b/src/proto_alpha/lib_protocol/sc_rollup_outbox_message_repr.ml index 609b4c8cd60494032252939278a6627981275823..546a5cb6e778fb5fb5a37e6dd826404bfba37331 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_outbox_message_repr.ml +++ b/src/proto_alpha/lib_protocol/sc_rollup_outbox_message_repr.ml @@ -104,14 +104,16 @@ let pp fmt (Atomic_transaction_batch {transactions}) = fmt transactions -let of_bytes bytes = +type serialized = string + +let deserialize data = let open Tzresult_syntax in - match Data_encoding.Binary.of_string_opt encoding bytes with + match Data_encoding.Binary.of_string_opt encoding data with | Some x -> return x | None -> fail Error_decode_outbox_message module Internal_for_tests = struct - let to_bytes outbox_message = + let serialize outbox_message = let open Tzresult_syntax in match Data_encoding.Binary.to_string_opt encoding outbox_message with | Some str -> return str diff --git a/src/proto_alpha/lib_protocol/sc_rollup_outbox_message_repr.mli b/src/proto_alpha/lib_protocol/sc_rollup_outbox_message_repr.mli index f7de49497640f022cf404b9173afe232629940b7..b896335fe9bcf70a20922fd846d6146f6a45f842 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_outbox_message_repr.mli +++ b/src/proto_alpha/lib_protocol/sc_rollup_outbox_message_repr.mli @@ -49,14 +49,15 @@ val encoding : t Data_encoding.t val pp : Format.formatter -> t -> unit -(** [of_bytes ctxt bs] decodes an outbox message value from the - given bytes [bs]. The function involves parsing Micheline expressions to +type serialized = private string + +(** [deserialize ctxt bs] decodes an outbox message value from the + given data [bs]. The function involves parsing Micheline expressions to typed values. *) -val of_bytes : string -> t tzresult +val deserialize : serialized -> t tzresult -(** Module containing functions exposed so they can be used in test. *) +(** Module containing functions exposed so they can be used in tests. *) module Internal_for_tests : sig - (** [to_bytes msg] returns the bytes of the given outbox - message [msg]. *) - val to_bytes : t -> string tzresult + (** [serialize msg] serializes the given outbox message [msg]. *) + val serialize : t -> serialized tzresult end diff --git a/src/proto_alpha/lib_protocol/sc_rollup_stake_storage.ml b/src/proto_alpha/lib_protocol/sc_rollup_stake_storage.ml index 669c5085809ef6172c0cf68ae0785daf31098f5e..129b2f8d8c7a87c1b8c27445b5de3d1aa81bbcd7 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_stake_storage.ml +++ b/src/proto_alpha/lib_protocol/sc_rollup_stake_storage.ml @@ -343,9 +343,6 @@ let cement_commitment ctxt rollup new_lcc = let* new_lcc_commitment, ctxt = Commitment_storage.get_commitment_unsafe ctxt rollup new_lcc in - let* ctxt, new_lcc_added = - Store.Commitment_added.get (ctxt, rollup) new_lcc - in let* () = fail_when Commitment_hash.(new_lcc_commitment.predecessor <> old_lcc) @@ -359,6 +356,9 @@ let cement_commitment ctxt rollup new_lcc = Compare.Int32.(total_staker_count <> new_lcc_stake_count) Sc_rollup_disputed in + let* ctxt, new_lcc_added = + Store.Commitment_added.get (ctxt, rollup) new_lcc + in let* () = fail_when (let level = (Raw_context.current_level ctxt).level in diff --git a/src/proto_alpha/lib_protocol/sc_rollup_tick_repr.ml b/src/proto_alpha/lib_protocol/sc_rollup_tick_repr.ml index 88e120ae2935b611d4c52593aac186d99249a781..a0bbdeecf9a17ec5b2a838800e632e0a1a73cb84 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_tick_repr.ml +++ b/src/proto_alpha/lib_protocol/sc_rollup_tick_repr.ml @@ -45,7 +45,7 @@ let to_int x = if Z.fits_int x then Some (Z.to_int x) else None let of_z x = x let of_number_of_ticks x = - Z.of_int (Int32.to_int (Sc_rollup_repr.Number_of_ticks.to_int32 x)) + Z.of_int32 (Sc_rollup_repr.Number_of_ticks.to_int32 x) let ( <= ) = leq diff --git a/src/proto_alpha/lib_protocol/test/pbt/test_refutation_game.ml b/src/proto_alpha/lib_protocol/test/pbt/test_refutation_game.ml index bcb575863737ca3bf9bf500dcc81313d09c7384e..220b24cac1278967b32ede655e86792a2c53cc20 100644 --- a/src/proto_alpha/lib_protocol/test/pbt/test_refutation_game.ml +++ b/src/proto_alpha/lib_protocol/test/pbt/test_refutation_game.ml @@ -100,8 +100,9 @@ let tick_of_int_exn n = let tick_to_int_exn t = match Tick.to_int t with None -> assert false | Some n -> n -let random_dissection start_at start_hash stop_at stop_hash : - (State_hash.t option * Tick.t) list option Lwt.t = +let mk_dissection_chunk (state_hash, tick) = Game.{state_hash; tick} + +let random_dissection start_at start_hash stop_at stop_hash = let start_int = tick_to_int_exn start_at in let stop_int = tick_to_int_exn stop_at in let dist = stop_int - start_int in @@ -113,6 +114,8 @@ let random_dissection start_at start_hash stop_at stop_hash : return @@ Result.to_option (List.init branch ~when_negative_length:"error" (fun i -> + mk_dissection_chunk + @@ if i = 0 then (Some start_hash, start_at) else if i = branch - 1 then (stop_hash, stop_at) else @@ -422,7 +425,7 @@ end) : TestPVM = struct let make_external_inbox_message str = WithExceptions.Result.get_ok ~loc:__LOC__ - Inbox.Message.(External str |> to_bytes) + Inbox.Message.(External str |> serialize) let default_state = let promise = @@ -542,7 +545,7 @@ module Strategies (PVM : TestPVM with type hash = State_hash.t) = struct let* h = PVM.state_hash s in return (Some h) in - (hash, tick)) + mk_dissection_chunk (hash, tick)) a) tick_list in @@ -633,15 +636,17 @@ module Strategies (PVM : TestPVM with type hash = State_hash.t) = struct let random_decision d = let number_of_somes = List.length - (List.filter (function Some _, _ -> true | None, _ -> false) d) + (List.filter (fun {Game.state_hash; _} -> Option.is_some state_hash) d) in let x = Random.int (number_of_somes - 1) in let start_hash, start = - match List.nth d x with Some (Some s, t) -> (s, t) | _ -> assert false + match List.nth d x with + | Some Game.{state_hash = Some s; tick = t} -> (s, t) + | _ -> assert false in let _, stop = match List.nth d (x + 1) with - | Some (s, t) -> (s, t) + | Some Game.{state_hash; tick} -> (state_hash, tick) | None -> assert false in let stop_hash = Some (random_hash ()) in @@ -676,7 +681,9 @@ module Strategies (PVM : TestPVM with type hash = State_hash.t) = struct let find_conflict dissection = let rec aux states = match states with - | (start_state, start_tick) :: (next_state, next_tick) :: rest -> + | start :: next :: rest -> + let Game.{state_hash = start_state; tick = start_tick} = start in + let Game.{state_hash = next_state; tick = next_tick} = next in let* c0 = conflicting_section start_tick start_state in let* c = conflicting_section next_tick next_state in if c0 then assert false @@ -684,7 +691,7 @@ module Strategies (PVM : TestPVM with type hash = State_hash.t) = struct if next_state = None then return None else return (Some ((start_state, start_tick), (next_state, next_tick))) - else aux ((next_state, next_tick) :: rest) + else aux (next :: rest) | _ -> return None in aux dissection diff --git a/src/proto_alpha/lib_protocol/test/pbt/test_sc_rollup_encoding.ml b/src/proto_alpha/lib_protocol/test/pbt/test_sc_rollup_encoding.ml index d824eb283e92c8aeb3822a67bab0fa8cc75a4c4d..43b83f5092342e4560689c73688e71fae185d09d 100644 --- a/src/proto_alpha/lib_protocol/test/pbt/test_sc_rollup_encoding.ml +++ b/src/proto_alpha/lib_protocol/test/pbt/test_sc_rollup_encoding.ml @@ -99,7 +99,7 @@ let gen_messages inbox level = lift @@ let*? input_messages = List.map_e - (fun msg -> Sc_rollup_inbox_message_repr.(to_bytes (External msg))) + (fun msg -> Sc_rollup_inbox_message_repr.(serialize (External msg))) payloads in let messages = @@ -154,6 +154,11 @@ let gen_game = let* inbox_snapshot = gen_inbox rollup level in let* pvm_name = gen_pvm_name in let* dissection = gen_dissection in + let dissection = + List.map + (fun (state_hash, tick) -> Sc_rollup_game_repr.{state_hash; tick}) + dissection + in return Sc_rollup_game_repr.{turn; inbox_snapshot; level; pvm_name; dissection} let gen_conflict = diff --git a/src/proto_alpha/lib_protocol/test/unit/test_sc_rollup_arith.ml b/src/proto_alpha/lib_protocol/test/unit/test_sc_rollup_arith.ml index 652c3b942fd6880d52991ee51e2a958d50641787..b8f9158ca0b6b2974a2f2634073368af72b1e110 100644 --- a/src/proto_alpha/lib_protocol/test/unit/test_sc_rollup_arith.ml +++ b/src/proto_alpha/lib_protocol/test/unit/test_sc_rollup_arith.ml @@ -136,7 +136,7 @@ let test_boot () = let make_external_inbox_message str = WithExceptions.Result.get_ok ~loc:__LOC__ - Sc_rollup_inbox_message_repr.(External str |> to_bytes) + Sc_rollup_inbox_message_repr.(External str |> serialize) let test_input_message () = let open Sc_rollup_PVM_sem in diff --git a/src/proto_alpha/lib_protocol/test/unit/test_sc_rollup_game.ml b/src/proto_alpha/lib_protocol/test/unit/test_sc_rollup_game.ml index 5964f92fc9c761a0cb6e1774b20b16ad80600095..2dfb5925b37d996f7037d6564f16a71ffb03cfba 100644 --- a/src/proto_alpha/lib_protocol/test/unit/test_sc_rollup_game.ml +++ b/src/proto_alpha/lib_protocol/test/unit/test_sc_rollup_game.ml @@ -67,13 +67,15 @@ let hash_string s = let hash_int n = hash_string (Format.sprintf "%d" n) +let mk_dissection_chunk (state_hash, tick) = G.{state_hash; tick} + let init_dissection ?(size = 32) ?init_tick start_hash = let default_init_tick i = let hash = if i = size - 1 then None else Some (if i = 0 then start_hash else hash_int i) in - (hash, tick_of_int_exn i) + mk_dissection_chunk (hash, tick_of_int_exn i) in let init_tick = Option.fold @@ -153,6 +155,8 @@ let test_poorly_distributed_dissection () = let* ctxt, rollup, refuter, defender = two_stakers_in_conflict () in let start_hash = hash_string "foo" in let init_tick size i = + mk_dissection_chunk + @@ if i = size - 1 then (None, tick_of_int_exn 10000) else (Some (if i = 0 then start_hash else hash_int i), tick_of_int_exn i) in @@ -174,6 +178,8 @@ let test_single_valid_game_move () = let start_hash = hash_string "foo" in let dissection = Stdlib.List.init 32 (fun i -> + mk_dissection_chunk + @@ if i = 0 then (Some start_hash, tick_of_int_exn 0) else if i = 31 then (None, tick_of_int_exn 10000) else (Some (hash_int i), tick_of_int_exn (i * 200))) diff --git a/src/proto_alpha/lib_protocol/test/unit/test_sc_rollup_inbox.ml b/src/proto_alpha/lib_protocol/test/unit/test_sc_rollup_inbox.ml index 97eaa881f1d0414b864a45070b09735df775e13e..e2bff61cdff72c85bed6d00d54e438b2e01a4f99 100644 --- a/src/proto_alpha/lib_protocol/test/unit/test_sc_rollup_inbox.ml +++ b/src/proto_alpha/lib_protocol/test/unit/test_sc_rollup_inbox.ml @@ -65,7 +65,7 @@ let setup_inbox_with_messages list_of_payloads f = let*? payloads = List.map_e (fun payload -> - Sc_rollup_inbox_message_repr.(to_bytes @@ External payload)) + Sc_rollup_inbox_message_repr.(serialize @@ External payload)) payloads in let* messages, history, inbox' = diff --git a/src/proto_alpha/lib_protocol/test/unit/test_sc_rollup_management_protocol.ml b/src/proto_alpha/lib_protocol/test/unit/test_sc_rollup_management_protocol.ml index cb65d912c203c00c59a048706271365c1f569573..5cd6c391bd54fdfdbfcbf718260ccf8cc8324e63 100644 --- a/src/proto_alpha/lib_protocol/test/unit/test_sc_rollup_management_protocol.ml +++ b/src/proto_alpha/lib_protocol/test/unit/test_sc_rollup_management_protocol.ml @@ -40,13 +40,14 @@ let check_encode_decode_inbox_message message = let open Lwt_result_syntax in let open Sc_rollup_management_protocol in let*? bytes = - Environment.wrap_tzresult @@ Sc_rollup.Inbox.Message.to_bytes message + Environment.wrap_tzresult @@ Sc_rollup.Inbox.Message.serialize message in let*? message' = - Environment.wrap_tzresult @@ Internal_for_tests.inbox_message_of_bytes bytes + Environment.wrap_tzresult + @@ Internal_for_tests.deserialize_inbox_message bytes in let*? bytes' = - Environment.wrap_tzresult @@ Sc_rollup.Inbox.Message.to_bytes message' + Environment.wrap_tzresult @@ Sc_rollup.Inbox.Message.serialize message' in Assert.equal_string ~loc:__LOC__ (bytes :> string) (bytes' :> string) @@ -55,19 +56,19 @@ let check_encode_decode_outbox_message ctxt message = let open Sc_rollup_management_protocol in let*? bytes = Environment.wrap_tzresult - @@ Internal_for_tests.bytes_of_outbox_message message + @@ Internal_for_tests.serialize_outbox_message message in let* message', _ctxt = let*? message_repr = - Environment.wrap_tzresult @@ Sc_rollup.Outbox.Message.of_bytes bytes + Environment.wrap_tzresult @@ Sc_rollup.Outbox.Message.deserialize bytes in wrap @@ outbox_message_of_outbox_message_repr ctxt message_repr in let*? bytes' = Environment.wrap_tzresult - @@ Internal_for_tests.bytes_of_outbox_message message' + @@ Internal_for_tests.serialize_outbox_message message' in - Assert.equal_string ~loc:__LOC__ bytes bytes' + Assert.equal_string ~loc:__LOC__ (bytes :> string) (bytes' :> string) let string_ticket ticketer contents amount = let open WithExceptions in @@ -146,7 +147,7 @@ let test_encode_decode_external_inbox_message () = let inbox_message = Sc_rollup.Inbox.Message.External message in let*? real_encoding = Environment.wrap_tzresult - @@ Sc_rollup.Inbox.Message.to_bytes inbox_message + @@ Sc_rollup.Inbox.Message.serialize inbox_message in let real_encoding = (real_encoding :> string) in (* The prefix consists of a tag (0 for internal, 1 for external). *) diff --git a/src/proto_alpha/lib_protocol/test/unit/test_sc_rollup_storage.ml b/src/proto_alpha/lib_protocol/test/unit/test_sc_rollup_storage.ml index e1bad3da3cd463353e33f82d5cefbade71bef3fc..e689883dbeb95db0c26fe967814d4538c90cce10 100644 --- a/src/proto_alpha/lib_protocol/test/unit/test_sc_rollup_storage.ml +++ b/src/proto_alpha/lib_protocol/test/unit/test_sc_rollup_storage.ml @@ -2352,7 +2352,7 @@ let test_carbonated_memory_inbox_set_messages () = Environment.wrap_tzresult @@ List.map_e (fun external_message -> - Sc_rollup_inbox_message_repr.(to_bytes @@ External external_message)) + Sc_rollup_inbox_message_repr.(serialize @@ External external_message)) ["CAFEBABE"; "CAFEBABE"; "CAFEBABE"] in let* current_messages, _ = diff --git a/tezt/tests/sc_rollup.ml b/tezt/tests/sc_rollup.ml index e871f605605fdf7b0463e0b8ed22a7e1de6e75ae..05e958c4c613de5d58ebc5f1096a3b1bc046dbad 100644 --- a/tezt/tests/sc_rollup.ml +++ b/tezt/tests/sc_rollup.ml @@ -162,7 +162,7 @@ let with_fresh_rollup f tezos_node tezos_client bootstrap1_key = let* configuration_filename = Sc_rollup_node.config_init sc_rollup_node rollup_address in - let* () = Client.bake_for tezos_client in + let* () = Client.bake_for_and_wait tezos_client in f rollup_address sc_rollup_node configuration_filename (* TODO: https://gitlab.com/tezos/tezos/-/issues/2933 @@ -304,7 +304,7 @@ let with_fresh_rollup ?(boot_sector = "") f tezos_node tezos_client let* configuration_filename = Sc_rollup_node.config_init sc_rollup_node rollup_address in - let* () = Client.bake_for tezos_client in + let* () = Client.bake_for_and_wait tezos_client in f rollup_address sc_rollup_node configuration_filename let with_fresh_rollups n f node client bootstrap1 =