From 034c2f7540f911730fe29674254a04b6b2d02d1b Mon Sep 17 00:00:00 2001 From: Yann Regis-Gianas Date: Tue, 14 Jun 2022 21:49:44 +0200 Subject: [PATCH 01/11] Proto,SCORU: Add rollup node RPC to observe PVM state Signed-off-by: Yann Regis-Gianas --- src/proto_alpha/bin_sc_rollup_node/RPC_server.ml | 16 ++++++++++++++++ .../lib_sc_rollup/sc_rollup_services.ml | 15 +++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/src/proto_alpha/bin_sc_rollup_node/RPC_server.ml b/src/proto_alpha/bin_sc_rollup_node/RPC_server.ml index ce6dfb9c4402..a23784090f6e 100644 --- a/src/proto_alpha/bin_sc_rollup_node/RPC_server.ml +++ b/src/proto_alpha/bin_sc_rollup_node/RPC_server.ml @@ -163,6 +163,21 @@ module Make (PVM : Pvm.S) : S with module PVM = PVM = struct let*! hash = PVM.state_hash state in return hash) + let register_current_state_value store dir = + RPC_directory.register0 + dir + (Sc_rollup_services.current_state_value ()) + (fun {key} () -> + let open Lwt_result_syntax in + let* state = get_state_exn store in + let path = String.split_on_char '/' key in + let*! value = Store.IStoreTree.find state path in + match value with + | None -> failwith "No such key in PVM state" + | Some value -> + Format.eprintf "Encoded %S\n@.%!" (Bytes.to_string value) ; + return value) + let register_last_stored_commitment store dir = RPC_directory.register0 dir @@ -225,6 +240,7 @@ module Make (PVM : Pvm.S) : S with module PVM = PVM = struct |> register_current_total_ticks store |> register_current_num_messages store |> register_current_state_hash store + |> register_current_state_value store |> register_current_status store |> register_last_stored_commitment store |> register_last_published_commitment store diff --git a/src/proto_alpha/lib_sc_rollup/sc_rollup_services.ml b/src/proto_alpha/lib_sc_rollup/sc_rollup_services.ml index ce18348721e6..0aaa6a88f540 100644 --- a/src/proto_alpha/lib_sc_rollup/sc_rollup_services.ml +++ b/src/proto_alpha/lib_sc_rollup/sc_rollup_services.ml @@ -160,4 +160,19 @@ module Local = struct ~query:RPC_query.empty ~output:(Data_encoding.option commitment_with_hash_and_level_encoding) (prefix / "last_published_commitment") + + type state_value_query = {key : string} + + let state_value_query : state_value_query RPC_query.t = + let open RPC_query in + query (fun key -> {key}) + |+ field "key" RPC_arg.string "" (fun t -> t.key) + |> seal + + let current_state_value () = + RPC_service.get_service + ~description:"Current state value" + ~query:state_value_query + ~output:Data_encoding.bytes + RPC_path.(open_root / "state") end -- GitLab From 859112fcf353ead6931b6e147d7f646ef75cf06f Mon Sep 17 00:00:00 2001 From: Yann Regis-Gianas Date: Tue, 14 Jun 2022 22:11:16 +0200 Subject: [PATCH 02/11] Proto,SCORU: Extend client to handle state value rollup node RPC Signed-off-by: Yann Regis-Gianas --- src/proto_alpha/bin_sc_rollup_client/RPC.ml | 3 +++ src/proto_alpha/bin_sc_rollup_client/commands.ml | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/proto_alpha/bin_sc_rollup_client/RPC.ml b/src/proto_alpha/bin_sc_rollup_client/RPC.ml index 5fca1cec6402..dffca04b90a5 100644 --- a/src/proto_alpha/bin_sc_rollup_client/RPC.ml +++ b/src/proto_alpha/bin_sc_rollup_client/RPC.ml @@ -29,3 +29,6 @@ let call (cctxt : #sc_client_context) = cctxt#call_service let get_sc_rollup_addresses_command cctxt = call cctxt (Sc_rollup_services.Global.sc_rollup_address ()) () () () + +let get_state_value_command cctxt key = + call cctxt (Sc_rollup_services.Local.current_state_value ()) () {key} () diff --git a/src/proto_alpha/bin_sc_rollup_client/commands.ml b/src/proto_alpha/bin_sc_rollup_client/commands.ml index 4750ef242393..aef42ec0160a 100644 --- a/src/proto_alpha/bin_sc_rollup_client/commands.ml +++ b/src/proto_alpha/bin_sc_rollup_client/commands.ml @@ -36,6 +36,17 @@ let get_sc_rollup_addresses_command () = RPC.get_sc_rollup_addresses_command cctxt >>=? fun addr -> cctxt#message "@[%a@]" Sc_rollup.Address.pp addr >>= fun () -> return_unit) +let get_state_value_command () = + command + ~desc:"Observe a key in the PVM state." + no_options + (prefixes ["get"; "state"; "value"; "for"] + @@ string ~name:"key" ~desc:"The key of the state value" + @@ stop) + (fun () key (cctxt : #Configuration.sc_client_context) -> + RPC.get_state_value_command cctxt key >>=? fun bytes -> + cctxt#message "@[%S@]" (String.of_bytes bytes) >>= fun () -> return_unit) + (** [display_answer cctxt answer] prints an RPC answer. *) let display_answer (cctxt : #Configuration.sc_client_context) : RPC_context.generic_call_result -> unit Lwt.t = function @@ -143,6 +154,7 @@ end let all () = [ get_sc_rollup_addresses_command (); + get_state_value_command (); rpc_get_command; Keys.generate_keys (); Keys.list_keys (); -- GitLab From d8574a15b344a7e4bc535393ae81ef164be92a28 Mon Sep 17 00:00:00 2001 From: Yann Regis-Gianas Date: Thu, 16 Jun 2022 10:16:17 +0200 Subject: [PATCH 03/11] Tezt,SCORU: Extend a test to check the validity of the PVM state Signed-off-by: Yann Regis-Gianas --- .../bin_sc_rollup_node/RPC_server.ml | 2 +- tezt/lib_tezos/sc_rollup_client.ml | 7 + tezt/lib_tezos/sc_rollup_client.mli | 4 + ... node advances PVM state with messages.out | 304 ++++++++++-------- tezt/tests/sc_rollup.ml | 28 +- 5 files changed, 202 insertions(+), 143 deletions(-) diff --git a/src/proto_alpha/bin_sc_rollup_node/RPC_server.ml b/src/proto_alpha/bin_sc_rollup_node/RPC_server.ml index a23784090f6e..3b70e5f672ee 100644 --- a/src/proto_alpha/bin_sc_rollup_node/RPC_server.ml +++ b/src/proto_alpha/bin_sc_rollup_node/RPC_server.ml @@ -166,7 +166,7 @@ module Make (PVM : Pvm.S) : S with module PVM = PVM = struct let register_current_state_value store dir = RPC_directory.register0 dir - (Sc_rollup_services.current_state_value ()) + (Sc_rollup_services.Local.current_state_value ()) (fun {key} () -> let open Lwt_result_syntax in let* state = get_state_exn store in diff --git a/tezt/lib_tezos/sc_rollup_client.ml b/tezt/lib_tezos/sc_rollup_client.ml index 3be24bcec936..d3c717cc554f 100644 --- a/tezt/lib_tezos/sc_rollup_client.ml +++ b/tezt/lib_tezos/sc_rollup_client.ml @@ -110,6 +110,13 @@ let sc_rollup_address sc_client = in return (String.trim out) +let state_value ?hooks sc_client ~key = + let* out = + spawn_command ?hooks sc_client ["get"; "state"; "value"; "for"; key] + |> Process.check_and_read_stdout + in + return (Scanf.sscanf (String.trim out) "%S" (fun s -> s) |> String.to_bytes) + let rpc_get ?hooks sc_client path = let process = spawn_command ?hooks sc_client ["rpc"; "get"; Client.string_of_path path] diff --git a/tezt/lib_tezos/sc_rollup_client.mli b/tezt/lib_tezos/sc_rollup_client.mli index 13518aed2d4b..5bff639586e2 100644 --- a/tezt/lib_tezos/sc_rollup_client.mli +++ b/tezt/lib_tezos/sc_rollup_client.mli @@ -62,6 +62,10 @@ val ticks : ?hooks:Process.hooks -> t -> int Lwt.t (** [state_hash client] gets the corresponding PVM state hash for the current head block. *) val state_hash : ?hooks:Process.hooks -> t -> string Lwt.t +(** [state_value client key] gets the corresponding PVM state value + mapped to [key] for the current head block. *) +val state_value : ?hooks:Process.hooks -> t -> key:string -> bytes Lwt.t + (** [status client] gets the corresponding PVM status for the current head block. *) val status : ?hooks:Process.hooks -> t -> string Lwt.t diff --git a/tezt/tests/expected/sc_rollup.ml/Alpha- node advances PVM state with messages.out b/tezt/tests/expected/sc_rollup.ml/Alpha- node advances PVM state with messages.out index 9248e4b87c96..e2a54eec4b33 100644 --- a/tezt/tests/expected/sc_rollup.ml/Alpha- node advances PVM state with messages.out +++ b/tezt/tests/expected/sc_rollup.ml/Alpha- node advances PVM state with messages.out @@ -38,9 +38,9 @@ This sequence of operations was run: ./tezos-sc-rollup-client-alpha rpc get /global/total_ticks "0" -./tezos-client --wait none send sc rollup message 'text:["31","36","2b"]' from bootstrap1 to '[SC_ROLLUP_HASH]' +./tezos-client --wait none send sc rollup message '["1 6 + value"]' from bootstrap1 to '[SC_ROLLUP_HASH]' Node is bootstrapped. -Estimated gas: 1652.752 units (will add 100 for safety) +Estimated gas: 1651.787 units (will add 100 for safety) Estimated storage: no bytes added Operation successfully injected in the node. Operation hash is '[OPERATION_HASH]' @@ -51,24 +51,24 @@ and/or an external block explorer to make sure that it has been included. This sequence of operations was run: Manager signed operations: From: [PUBLIC_KEY_HASH] - Fee to the baker: ꜩ0.000463 + Fee to the baker: ꜩ0.00046 Expected counter: 2 - Gas limit: 1753 + Gas limit: 1752 Storage limit: 0 bytes Balance updates: - [PUBLIC_KEY_HASH] ... -ꜩ0.000463 - payload fees(the block proposer) ....... +ꜩ0.000463 + [PUBLIC_KEY_HASH] ... -ꜩ0.00046 + payload fees(the block proposer) ....... +ꜩ0.00046 Add a message to the inbox of the smart contract rollup at address [SC_ROLLUP_HASH] This smart contract rollup messages submission was successfully applied - Consumed gas: 1652.880 + Consumed gas: 1651.915 Resulting inbox state: rollup = [SC_ROLLUP_HASH] level = 3 current messages hash = [SC_ROLLUP_INBOX_HASH] - nb_available_messages = 3 - nb_messages_in_commitment_period = 3 + nb_available_messages = 1 + nb_messages_in_commitment_period = 1 starting_level_of_current_commitment_period = 2 - message_counter = 3 + message_counter = 1 old_levels_messages = content = [SC_ROLLUP_INBOX_HASH] index = 1 @@ -77,21 +77,24 @@ This sequence of operations was run: +./tezos-sc-rollup-client-alpha get state value for vars/value +"\000\000\000\007" + ./tezos-sc-rollup-client-alpha rpc get /global/state_hash -"scs11dQjwnCyKGUtYfzXtjU8qH3igQHAsk71CJbYSc3e8Kyfraqmko" +"scs12jce3k85ri49csMc1uPnWpsTWd2KnDam9se9beyQtf6NSgDqPV" ./tezos-sc-rollup-client-alpha rpc get /global/total_ticks -"17" +"19" ./tezos-sc-rollup-client-alpha rpc get /global/state_hash -"scs11dQjwnCyKGUtYfzXtjU8qH3igQHAsk71CJbYSc3e8Kyfraqmko" +"scs12jce3k85ri49csMc1uPnWpsTWd2KnDam9se9beyQtf6NSgDqPV" ./tezos-sc-rollup-client-alpha rpc get /global/total_ticks -"17" +"19" -./tezos-client --wait none send sc rollup message 'text:["32","38","2b"]' from bootstrap1 to '[SC_ROLLUP_HASH]' +./tezos-client --wait none send sc rollup message '["2 8 + value"]' from bootstrap1 to '[SC_ROLLUP_HASH]' Node is bootstrapped. -Estimated gas: 1652.974 units (will add 100 for safety) +Estimated gas: 1652.009 units (will add 100 for safety) Estimated storage: no bytes added Operation successfully injected in the node. Operation hash is '[OPERATION_HASH]' @@ -102,24 +105,24 @@ and/or an external block explorer to make sure that it has been included. This sequence of operations was run: Manager signed operations: From: [PUBLIC_KEY_HASH] - Fee to the baker: ꜩ0.000463 + Fee to the baker: ꜩ0.00046 Expected counter: 3 Gas limit: 1753 Storage limit: 0 bytes Balance updates: - [PUBLIC_KEY_HASH] ... -ꜩ0.000463 - payload fees(the block proposer) ....... +ꜩ0.000463 + [PUBLIC_KEY_HASH] ... -ꜩ0.00046 + payload fees(the block proposer) ....... +ꜩ0.00046 Add a message to the inbox of the smart contract rollup at address [SC_ROLLUP_HASH] This smart contract rollup messages submission was successfully applied - Consumed gas: 1653.102 + Consumed gas: 1652.137 Resulting inbox state: rollup = [SC_ROLLUP_HASH] level = 4 current messages hash = [SC_ROLLUP_INBOX_HASH] - nb_available_messages = 6 - nb_messages_in_commitment_period = 6 + nb_available_messages = 2 + nb_messages_in_commitment_period = 2 starting_level_of_current_commitment_period = 2 - message_counter = 3 + message_counter = 1 old_levels_messages = content = [SC_ROLLUP_INBOX_HASH] index = 2 @@ -129,21 +132,24 @@ This sequence of operations was run: +./tezos-sc-rollup-client-alpha get state value for vars/value +"\000\000\000\n" + ./tezos-sc-rollup-client-alpha rpc get /global/state_hash -"scs129tezMTWFNQM3iKNAWATZGtigW1bxgD92BAibihfpSm4fRtY7J" +"scs11kdKF4R7zerdddo9p7Ky5CzHKXebFF8cPo9VK9pvnrvXRTVXZy" ./tezos-sc-rollup-client-alpha rpc get /global/total_ticks -"33" +"37" ./tezos-sc-rollup-client-alpha rpc get /global/state_hash -"scs129tezMTWFNQM3iKNAWATZGtigW1bxgD92BAibihfpSm4fRtY7J" +"scs11kdKF4R7zerdddo9p7Ky5CzHKXebFF8cPo9VK9pvnrvXRTVXZy" ./tezos-sc-rollup-client-alpha rpc get /global/total_ticks -"33" +"37" -./tezos-client --wait none send sc rollup message 'text:["33","3130","2b"]' from bootstrap1 to '[SC_ROLLUP_HASH]' +./tezos-client --wait none send sc rollup message '["3 10 + value"]' from bootstrap1 to '[SC_ROLLUP_HASH]' Node is bootstrapped. -Estimated gas: 1653.211 units (will add 100 for safety) +Estimated gas: 1652.231 units (will add 100 for safety) Estimated storage: no bytes added Operation successfully injected in the node. Operation hash is '[OPERATION_HASH]' @@ -154,24 +160,24 @@ and/or an external block explorer to make sure that it has been included. This sequence of operations was run: Manager signed operations: From: [PUBLIC_KEY_HASH] - Fee to the baker: ꜩ0.000465 + Fee to the baker: ꜩ0.000461 Expected counter: 4 - Gas limit: 1754 + Gas limit: 1753 Storage limit: 0 bytes Balance updates: - [PUBLIC_KEY_HASH] ... -ꜩ0.000465 - payload fees(the block proposer) ....... +ꜩ0.000465 + [PUBLIC_KEY_HASH] ... -ꜩ0.000461 + payload fees(the block proposer) ....... +ꜩ0.000461 Add a message to the inbox of the smart contract rollup at address [SC_ROLLUP_HASH] This smart contract rollup messages submission was successfully applied - Consumed gas: 1653.211 + Consumed gas: 1652.231 Resulting inbox state: rollup = [SC_ROLLUP_HASH] level = 5 current messages hash = [SC_ROLLUP_INBOX_HASH] - nb_available_messages = 9 - nb_messages_in_commitment_period = 9 + nb_available_messages = 3 + nb_messages_in_commitment_period = 3 starting_level_of_current_commitment_period = 2 - message_counter = 3 + message_counter = 1 old_levels_messages = content = [SC_ROLLUP_INBOX_HASH] index = 3 @@ -181,21 +187,24 @@ This sequence of operations was run: +./tezos-sc-rollup-client-alpha get state value for vars/value +"\000\000\000\r" + ./tezos-sc-rollup-client-alpha rpc get /global/state_hash -"scs12B99KFjHPESBDrBX3vhATbuMi4fYRW2tgGzKH4PqCn49g2bQq7" +"scs13Rx6jH3ve1qqqw6qAYQabea3Ub2GiXJrsWBgqJz9fcPsbBcJCc" ./tezos-sc-rollup-client-alpha rpc get /global/total_ticks -"51" +"56" ./tezos-sc-rollup-client-alpha rpc get /global/state_hash -"scs12B99KFjHPESBDrBX3vhATbuMi4fYRW2tgGzKH4PqCn49g2bQq7" +"scs13Rx6jH3ve1qqqw6qAYQabea3Ub2GiXJrsWBgqJz9fcPsbBcJCc" ./tezos-sc-rollup-client-alpha rpc get /global/total_ticks -"51" +"56" -./tezos-client --wait none send sc rollup message 'text:["34","3132","2b"]' from bootstrap1 to '[SC_ROLLUP_HASH]' +./tezos-client --wait none send sc rollup message '["4 12 + value"]' from bootstrap1 to '[SC_ROLLUP_HASH]' Node is bootstrapped. -Estimated gas: 1653.211 units (will add 100 for safety) +Estimated gas: 1652.231 units (will add 100 for safety) Estimated storage: no bytes added Operation successfully injected in the node. Operation hash is '[OPERATION_HASH]' @@ -206,24 +215,24 @@ and/or an external block explorer to make sure that it has been included. This sequence of operations was run: Manager signed operations: From: [PUBLIC_KEY_HASH] - Fee to the baker: ꜩ0.000465 + Fee to the baker: ꜩ0.000461 Expected counter: 5 - Gas limit: 1754 + Gas limit: 1753 Storage limit: 0 bytes Balance updates: - [PUBLIC_KEY_HASH] ... -ꜩ0.000465 - payload fees(the block proposer) ....... +ꜩ0.000465 + [PUBLIC_KEY_HASH] ... -ꜩ0.000461 + payload fees(the block proposer) ....... +ꜩ0.000461 Add a message to the inbox of the smart contract rollup at address [SC_ROLLUP_HASH] This smart contract rollup messages submission was successfully applied - Consumed gas: 1653.339 + Consumed gas: 1652.359 Resulting inbox state: rollup = [SC_ROLLUP_HASH] level = 6 current messages hash = [SC_ROLLUP_INBOX_HASH] - nb_available_messages = 12 - nb_messages_in_commitment_period = 12 + nb_available_messages = 4 + nb_messages_in_commitment_period = 4 starting_level_of_current_commitment_period = 2 - message_counter = 3 + message_counter = 1 old_levels_messages = content = [SC_ROLLUP_INBOX_HASH] index = 4 @@ -234,21 +243,24 @@ This sequence of operations was run: +./tezos-sc-rollup-client-alpha get state value for vars/value +"\000\000\000\016" + ./tezos-sc-rollup-client-alpha rpc get /global/state_hash -"scs12Rngw9ErX9yzqhhdHMW1Vef7f9znHSzitW6M8FHmoVzVwRuHq3" +"scs12mPUsjGqUsfyjY1712HZzbFLHGmt23PP5WHeb8w18QHVd1GokR" ./tezos-sc-rollup-client-alpha rpc get /global/total_ticks -"69" +"75" ./tezos-sc-rollup-client-alpha rpc get /global/state_hash -"scs12Rngw9ErX9yzqhhdHMW1Vef7f9znHSzitW6M8FHmoVzVwRuHq3" +"scs12mPUsjGqUsfyjY1712HZzbFLHGmt23PP5WHeb8w18QHVd1GokR" ./tezos-sc-rollup-client-alpha rpc get /global/total_ticks -"69" +"75" -./tezos-client --wait none send sc rollup message 'text:["35","3134","2b"]' from bootstrap1 to '[SC_ROLLUP_HASH]' +./tezos-client --wait none send sc rollup message '["5 14 + value"]' from bootstrap1 to '[SC_ROLLUP_HASH]' Node is bootstrapped. -Estimated gas: 1653.418 units (will add 100 for safety) +Estimated gas: 1652.438 units (will add 100 for safety) Estimated storage: no bytes added Operation successfully injected in the node. Operation hash is '[OPERATION_HASH]' @@ -259,24 +271,24 @@ and/or an external block explorer to make sure that it has been included. This sequence of operations was run: Manager signed operations: From: [PUBLIC_KEY_HASH] - Fee to the baker: ꜩ0.000465 + Fee to the baker: ꜩ0.000461 Expected counter: 6 - Gas limit: 1754 + Gas limit: 1753 Storage limit: 0 bytes Balance updates: - [PUBLIC_KEY_HASH] ... -ꜩ0.000465 - payload fees(the block proposer) ....... +ꜩ0.000465 + [PUBLIC_KEY_HASH] ... -ꜩ0.000461 + payload fees(the block proposer) ....... +ꜩ0.000461 Add a message to the inbox of the smart contract rollup at address [SC_ROLLUP_HASH] This smart contract rollup messages submission was successfully applied - Consumed gas: 1653.418 + Consumed gas: 1652.438 Resulting inbox state: rollup = [SC_ROLLUP_HASH] level = 7 current messages hash = [SC_ROLLUP_INBOX_HASH] - nb_available_messages = 15 - nb_messages_in_commitment_period = 15 + nb_available_messages = 5 + nb_messages_in_commitment_period = 5 starting_level_of_current_commitment_period = 2 - message_counter = 3 + message_counter = 1 old_levels_messages = content = [SC_ROLLUP_INBOX_HASH] index = 5 @@ -287,21 +299,24 @@ This sequence of operations was run: +./tezos-sc-rollup-client-alpha get state value for vars/value +"\000\000\000\019" + ./tezos-sc-rollup-client-alpha rpc get /global/state_hash -"scs11qa3neDD1rL6k2vhQKLxAtE25LY2ao8GhHQWKNR5nKj4nUJtEt" +"scs12Kb3bYztLQfaEf6zYLCTZ5uDnLVrsU8NXmy4uXu7FJCAHMQnuW" ./tezos-sc-rollup-client-alpha rpc get /global/total_ticks -"87" +"94" ./tezos-sc-rollup-client-alpha rpc get /global/state_hash -"scs11qa3neDD1rL6k2vhQKLxAtE25LY2ao8GhHQWKNR5nKj4nUJtEt" +"scs12Kb3bYztLQfaEf6zYLCTZ5uDnLVrsU8NXmy4uXu7FJCAHMQnuW" ./tezos-sc-rollup-client-alpha rpc get /global/total_ticks -"87" +"94" -./tezos-client --wait none send sc rollup message 'text:["36","3136","2b"]' from bootstrap1 to '[SC_ROLLUP_HASH]' +./tezos-client --wait none send sc rollup message '["6 16 + value"]' from bootstrap1 to '[SC_ROLLUP_HASH]' Node is bootstrapped. -Estimated gas: 1653.418 units (will add 100 for safety) +Estimated gas: 1652.438 units (will add 100 for safety) Estimated storage: no bytes added Operation successfully injected in the node. Operation hash is '[OPERATION_HASH]' @@ -312,24 +327,24 @@ and/or an external block explorer to make sure that it has been included. This sequence of operations was run: Manager signed operations: From: [PUBLIC_KEY_HASH] - Fee to the baker: ꜩ0.000465 + Fee to the baker: ꜩ0.000461 Expected counter: 7 - Gas limit: 1754 + Gas limit: 1753 Storage limit: 0 bytes Balance updates: - [PUBLIC_KEY_HASH] ... -ꜩ0.000465 - payload fees(the block proposer) ....... +ꜩ0.000465 + [PUBLIC_KEY_HASH] ... -ꜩ0.000461 + payload fees(the block proposer) ....... +ꜩ0.000461 Add a message to the inbox of the smart contract rollup at address [SC_ROLLUP_HASH] This smart contract rollup messages submission was successfully applied - Consumed gas: 1653.418 + Consumed gas: 1652.438 Resulting inbox state: rollup = [SC_ROLLUP_HASH] level = 8 current messages hash = [SC_ROLLUP_INBOX_HASH] - nb_available_messages = 18 - nb_messages_in_commitment_period = 18 + nb_available_messages = 6 + nb_messages_in_commitment_period = 6 starting_level_of_current_commitment_period = 2 - message_counter = 3 + message_counter = 1 old_levels_messages = content = [SC_ROLLUP_INBOX_HASH] index = 6 @@ -340,21 +355,24 @@ This sequence of operations was run: +./tezos-sc-rollup-client-alpha get state value for vars/value +"\000\000\000\022" + ./tezos-sc-rollup-client-alpha rpc get /global/state_hash -"scs12gfcf4KJQzmmhpEzA1eYqkZdpfLoocwYs4VF64gWzG266ZhdLQ" +"scs11Z4sELS3xEYnoXyh5quHhzG14MM3nXvo2nzXcNeupfWqUTSY5k" ./tezos-sc-rollup-client-alpha rpc get /global/total_ticks -"105" +"113" ./tezos-sc-rollup-client-alpha rpc get /global/state_hash -"scs12gfcf4KJQzmmhpEzA1eYqkZdpfLoocwYs4VF64gWzG266ZhdLQ" +"scs11Z4sELS3xEYnoXyh5quHhzG14MM3nXvo2nzXcNeupfWqUTSY5k" ./tezos-sc-rollup-client-alpha rpc get /global/total_ticks -"105" +"113" -./tezos-client --wait none send sc rollup message 'text:["37","3138","2b"]' from bootstrap1 to '[SC_ROLLUP_HASH]' +./tezos-client --wait none send sc rollup message '["7 18 + value"]' from bootstrap1 to '[SC_ROLLUP_HASH]' Node is bootstrapped. -Estimated gas: 1653.418 units (will add 100 for safety) +Estimated gas: 1652.438 units (will add 100 for safety) Estimated storage: no bytes added Operation successfully injected in the node. Operation hash is '[OPERATION_HASH]' @@ -365,24 +383,24 @@ and/or an external block explorer to make sure that it has been included. This sequence of operations was run: Manager signed operations: From: [PUBLIC_KEY_HASH] - Fee to the baker: ꜩ0.000465 + Fee to the baker: ꜩ0.000461 Expected counter: 8 - Gas limit: 1754 + Gas limit: 1753 Storage limit: 0 bytes Balance updates: - [PUBLIC_KEY_HASH] ... -ꜩ0.000465 - payload fees(the block proposer) ....... +ꜩ0.000465 + [PUBLIC_KEY_HASH] ... -ꜩ0.000461 + payload fees(the block proposer) ....... +ꜩ0.000461 Add a message to the inbox of the smart contract rollup at address [SC_ROLLUP_HASH] This smart contract rollup messages submission was successfully applied - Consumed gas: 1653.418 + Consumed gas: 1652.438 Resulting inbox state: rollup = [SC_ROLLUP_HASH] level = 9 current messages hash = [SC_ROLLUP_INBOX_HASH] - nb_available_messages = 21 - nb_messages_in_commitment_period = 21 + nb_available_messages = 7 + nb_messages_in_commitment_period = 7 starting_level_of_current_commitment_period = 2 - message_counter = 3 + message_counter = 1 old_levels_messages = content = [SC_ROLLUP_INBOX_HASH] index = 7 @@ -393,21 +411,24 @@ This sequence of operations was run: +./tezos-sc-rollup-client-alpha get state value for vars/value +"\000\000\000\025" + ./tezos-sc-rollup-client-alpha rpc get /global/state_hash -"scs11WEUB14isXfXs9KbjbTBHBpk8JHQijGRRE5W6A69uDSeEnEEZb" +"scs134Zv1hADCyVW44K5CJGLFvNBDWmF4My4SHEx27RJeC4YkUpFUk" ./tezos-sc-rollup-client-alpha rpc get /global/total_ticks -"123" +"132" ./tezos-sc-rollup-client-alpha rpc get /global/state_hash -"scs11WEUB14isXfXs9KbjbTBHBpk8JHQijGRRE5W6A69uDSeEnEEZb" +"scs134Zv1hADCyVW44K5CJGLFvNBDWmF4My4SHEx27RJeC4YkUpFUk" ./tezos-sc-rollup-client-alpha rpc get /global/total_ticks -"123" +"132" -./tezos-client --wait none send sc rollup message 'text:["38","3230","2b"]' from bootstrap1 to '[SC_ROLLUP_HASH]' +./tezos-client --wait none send sc rollup message '["8 20 + value"]' from bootstrap1 to '[SC_ROLLUP_HASH]' Node is bootstrapped. -Estimated gas: 1653.418 units (will add 100 for safety) +Estimated gas: 1652.438 units (will add 100 for safety) Estimated storage: no bytes added Operation successfully injected in the node. Operation hash is '[OPERATION_HASH]' @@ -418,24 +439,24 @@ and/or an external block explorer to make sure that it has been included. This sequence of operations was run: Manager signed operations: From: [PUBLIC_KEY_HASH] - Fee to the baker: ꜩ0.000465 + Fee to the baker: ꜩ0.000461 Expected counter: 9 - Gas limit: 1754 + Gas limit: 1753 Storage limit: 0 bytes Balance updates: - [PUBLIC_KEY_HASH] ... -ꜩ0.000465 - payload fees(the block proposer) ....... +ꜩ0.000465 + [PUBLIC_KEY_HASH] ... -ꜩ0.000461 + payload fees(the block proposer) ....... +ꜩ0.000461 Add a message to the inbox of the smart contract rollup at address [SC_ROLLUP_HASH] This smart contract rollup messages submission was successfully applied - Consumed gas: 1653.546 + Consumed gas: 1652.566 Resulting inbox state: rollup = [SC_ROLLUP_HASH] level = 10 current messages hash = [SC_ROLLUP_INBOX_HASH] - nb_available_messages = 24 - nb_messages_in_commitment_period = 24 + nb_available_messages = 8 + nb_messages_in_commitment_period = 8 starting_level_of_current_commitment_period = 2 - message_counter = 3 + message_counter = 1 old_levels_messages = content = [SC_ROLLUP_INBOX_HASH] index = 8 @@ -447,21 +468,24 @@ This sequence of operations was run: +./tezos-sc-rollup-client-alpha get state value for vars/value +"\000\000\000\028" + ./tezos-sc-rollup-client-alpha rpc get /global/state_hash -"scs12g76pxeaFsbaZ3wo7iETcfBmEqYsW5WjQzmB15TUFLLwzvt6GQ" +"scs137z1Hshy7zUWWM38hrmtz2E9LsPLQpMnBtnGbgXiiKHDj7P17Y" ./tezos-sc-rollup-client-alpha rpc get /global/total_ticks -"141" +"151" ./tezos-sc-rollup-client-alpha rpc get /global/state_hash -"scs12g76pxeaFsbaZ3wo7iETcfBmEqYsW5WjQzmB15TUFLLwzvt6GQ" +"scs137z1Hshy7zUWWM38hrmtz2E9LsPLQpMnBtnGbgXiiKHDj7P17Y" ./tezos-sc-rollup-client-alpha rpc get /global/total_ticks -"141" +"151" -./tezos-client --wait none send sc rollup message 'text:["39","3232","2b"]' from bootstrap1 to '[SC_ROLLUP_HASH]' +./tezos-client --wait none send sc rollup message '["9 22 + value"]' from bootstrap1 to '[SC_ROLLUP_HASH]' Node is bootstrapped. -Estimated gas: 1653.625 units (will add 100 for safety) +Estimated gas: 1652.645 units (will add 100 for safety) Estimated storage: no bytes added Operation successfully injected in the node. Operation hash is '[OPERATION_HASH]' @@ -472,24 +496,24 @@ and/or an external block explorer to make sure that it has been included. This sequence of operations was run: Manager signed operations: From: [PUBLIC_KEY_HASH] - Fee to the baker: ꜩ0.000465 + Fee to the baker: ꜩ0.000461 Expected counter: 10 - Gas limit: 1754 + Gas limit: 1753 Storage limit: 0 bytes Balance updates: - [PUBLIC_KEY_HASH] ... -ꜩ0.000465 - payload fees(the block proposer) ....... +ꜩ0.000465 + [PUBLIC_KEY_HASH] ... -ꜩ0.000461 + payload fees(the block proposer) ....... +ꜩ0.000461 Add a message to the inbox of the smart contract rollup at address [SC_ROLLUP_HASH] This smart contract rollup messages submission was successfully applied - Consumed gas: 1653.625 + Consumed gas: 1652.645 Resulting inbox state: rollup = [SC_ROLLUP_HASH] level = 11 current messages hash = [SC_ROLLUP_INBOX_HASH] - nb_available_messages = 27 - nb_messages_in_commitment_period = 27 + nb_available_messages = 9 + nb_messages_in_commitment_period = 9 starting_level_of_current_commitment_period = 2 - message_counter = 3 + message_counter = 1 old_levels_messages = content = [SC_ROLLUP_INBOX_HASH] index = 9 @@ -501,21 +525,24 @@ This sequence of operations was run: +./tezos-sc-rollup-client-alpha get state value for vars/value +"\000\000\000\031" + ./tezos-sc-rollup-client-alpha rpc get /global/state_hash -"scs12xYEBWRb7cg8JMvAgtChTncVYvUPXkcFNpgvW6QpC5tfbLGDCV" +"scs139dDeHknV6X8Xq9pttHXgmfQgbBTYqxFAt62Td91m3C99ezUGX" ./tezos-sc-rollup-client-alpha rpc get /global/total_ticks -"159" +"170" ./tezos-sc-rollup-client-alpha rpc get /global/state_hash -"scs12xYEBWRb7cg8JMvAgtChTncVYvUPXkcFNpgvW6QpC5tfbLGDCV" +"scs139dDeHknV6X8Xq9pttHXgmfQgbBTYqxFAt62Td91m3C99ezUGX" ./tezos-sc-rollup-client-alpha rpc get /global/total_ticks -"159" +"170" -./tezos-client --wait none send sc rollup message 'text:["3130","3234","2b"]' from bootstrap1 to '[SC_ROLLUP_HASH]' +./tezos-client --wait none send sc rollup message '["10 24 + value"]' from bootstrap1 to '[SC_ROLLUP_HASH]' Node is bootstrapped. -Estimated gas: 1653.655 units (will add 100 for safety) +Estimated gas: 1652.660 units (will add 100 for safety) Estimated storage: no bytes added Operation successfully injected in the node. Operation hash is '[OPERATION_HASH]' @@ -526,24 +553,24 @@ and/or an external block explorer to make sure that it has been included. This sequence of operations was run: Manager signed operations: From: [PUBLIC_KEY_HASH] - Fee to the baker: ꜩ0.000467 + Fee to the baker: ꜩ0.000462 Expected counter: 11 - Gas limit: 1754 + Gas limit: 1753 Storage limit: 0 bytes Balance updates: - [PUBLIC_KEY_HASH] ... -ꜩ0.000467 - payload fees(the block proposer) ....... +ꜩ0.000467 + [PUBLIC_KEY_HASH] ... -ꜩ0.000462 + payload fees(the block proposer) ....... +ꜩ0.000462 Add a message to the inbox of the smart contract rollup at address [SC_ROLLUP_HASH] This smart contract rollup messages submission was successfully applied - Consumed gas: 1653.655 + Consumed gas: 1652.660 Resulting inbox state: rollup = [SC_ROLLUP_HASH] level = 12 current messages hash = [SC_ROLLUP_INBOX_HASH] - nb_available_messages = 30 - nb_messages_in_commitment_period = 30 + nb_available_messages = 10 + nb_messages_in_commitment_period = 10 starting_level_of_current_commitment_period = 2 - message_counter = 3 + message_counter = 1 old_levels_messages = content = [SC_ROLLUP_INBOX_HASH] index = 10 @@ -555,8 +582,11 @@ This sequence of operations was run: +./tezos-sc-rollup-client-alpha get state value for vars/value +"\000\000\000\"" + ./tezos-sc-rollup-client-alpha rpc get /global/state_hash -"scs138Hj6BokWB54prj8aVatMThqTtCCgMqZxfvpckbqnfD6TyeknR" +"scs121tVDwin1fUikRYZEFSyoXFV7HQw8u93PvUgw4SCk6PiVYbg2o" ./tezos-sc-rollup-client-alpha rpc get /global/total_ticks -"179" +"190" diff --git a/tezt/tests/sc_rollup.ml b/tezt/tests/sc_rollup.ml index 87f9a48766e7..90b8361105ff 100644 --- a/tezt/tests/sc_rollup.ml +++ b/tezt/tests/sc_rollup.ml @@ -981,12 +981,30 @@ let test_rollup_node_advances_pvm_state = Sc_rollup_client.state_hash ~hooks sc_rollup_client in let* prev_ticks = Sc_rollup_client.total_ticks ~hooks sc_rollup_client in - - let x = Int.to_string i in - let y = Int.to_string ((i + 2) * 2) in - let* () = send_text_messages client sc_rollup_address [x; y; "+"] in + let* () = + send_message + client + sc_rollup_address + (Printf.sprintf "[\"%d %d + value\"]" i ((i + 2) * 2)) + in let* _ = Sc_rollup_node.wait_for_level sc_rollup_node (level + i) in - + let* encoded_value = + Sc_rollup_client.state_value ~hooks sc_rollup_client ~key:"vars/value" + in + let value = + match Data_encoding.(Binary.of_bytes int31) @@ encoded_value with + | Error error -> + failwith + (Format.asprintf + "The arithmetic PVM has an expected state: %a" + Data_encoding.Binary.pp_read_error + error) + | Ok x -> x + in + Check.( + (value = i + ((i + 2) * 2)) + int + ~error_msg:"Invalid value in rollup state (%L <> %R)") ; let* state_hash = Sc_rollup_client.state_hash ~hooks sc_rollup_client in Check.(state_hash <> prev_state_hash) Check.string -- GitLab From 3081a7cd39389c6bdf96c24fd6c3acd38076ae72 Mon Sep 17 00:00:00 2001 From: Yann Regis-Gianas Date: Thu, 16 Jun 2022 14:03:30 +0200 Subject: [PATCH 04/11] Proto,SCORU: Move Inbox up in Alpha_context ... because the PVM input will depend on the Inbox.Message.t. Signed-off-by: Yann Regis-Gianas --- .../lib_protocol/alpha_context.mli | 256 +++++++++--------- 1 file changed, 128 insertions(+), 128 deletions(-) diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index 96e23acf71dd..dfb3c58b10bc 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -2758,6 +2758,134 @@ module Sc_rollup : sig module State_hash : S.HASH + module Inbox : sig + type t + + (** See {!Sc_rollup_inbox_message_repr}. *) + module Message : sig + type internal_inbox_message = { + payload : Script.expr; + sender : Contract_hash.t; + source : Signature.public_key_hash; + } + + type t = Internal of internal_inbox_message | External of string + + type serialized = private string + + val to_bytes : t -> serialized tzresult + + (** This module discloses definitions that are only useful for tests and + must not be used otherwise. *) + module Internal_for_tests : sig + val of_bytes : string -> t tzresult + end + end + + val pp : Format.formatter -> t -> unit + + val encoding : t Data_encoding.t + + val empty : Address.t -> Raw_level.t -> t + + val inbox_level : t -> Raw_level.t + + val number_of_available_messages : t -> Z.t + + val consume_n_messages : int32 -> t -> t option tzresult + + module Hash : S.HASH + + module type MerkelizedOperations = sig + type tree + + type message = tree + + type messages = tree + + type history + + val history_encoding : history Data_encoding.t + + val pp_history : Format.formatter -> history -> unit + + val history_at_genesis : bound:int64 -> history + + val add_external_messages : + history -> + t -> + Raw_level.t -> + string list -> + messages -> + (messages * history * t) tzresult Lwt.t + + val add_messages_no_history : + t -> + Raw_level.t -> + Message.serialized list -> + messages -> + (messages * t, error trace) result Lwt.t + + val get_message : messages -> Z.t -> message option Lwt.t + + val get_message_payload : messages -> Z.t -> string option Lwt.t + + type inclusion_proof + + val inclusion_proof_encoding : inclusion_proof Data_encoding.t + + val pp_inclusion_proof : Format.formatter -> inclusion_proof -> unit + + val number_of_proof_steps : inclusion_proof -> int + + val produce_inclusion_proof : history -> t -> t -> inclusion_proof option + + val verify_inclusion_proof : inclusion_proof -> t -> t -> bool + end + + include MerkelizedOperations with type tree = Context.tree + + module type TREE = sig + type t + + type tree + + type key = string list + + type value = bytes + + val find : tree -> key -> value option Lwt.t + + val find_tree : tree -> key -> tree option Lwt.t + + val add : tree -> key -> value -> tree Lwt.t + + val is_empty : tree -> bool + + val hash : tree -> Context_hash.t + end + + module MakeHashingScheme (Tree : TREE) : + MerkelizedOperations with type tree = Tree.tree + + val add_external_messages : + context -> rollup -> string list -> (t * Z.t * context) tzresult Lwt.t + + val add_internal_message : + context -> + rollup -> + payload:Script.expr -> + sender:Contract_hash.t -> + source:Signature.public_key_hash -> + (t * Z.t * context) tzresult Lwt.t + + val inbox : context -> rollup -> (t * context) tzresult Lwt.t + + module Proof : sig + type t + end + end + type input = { inbox_level : Raw_level.t; message_counter : Z.t; @@ -3022,134 +3150,6 @@ module Sc_rollup : sig val kind : context -> t -> Kind.t option tzresult Lwt.t - module Inbox : sig - type t - - (** See {!Sc_rollup_inbox_message_repr}. *) - module Message : sig - type internal_inbox_message = { - payload : Script.expr; - sender : Contract_hash.t; - source : Signature.public_key_hash; - } - - type t = Internal of internal_inbox_message | External of string - - type serialized = private string - - val to_bytes : t -> serialized tzresult - - (** This module discloses definitions that are only useful for tests and - must not be used otherwise. *) - module Internal_for_tests : sig - val of_bytes : string -> t tzresult - end - end - - val pp : Format.formatter -> t -> unit - - val encoding : t Data_encoding.t - - val empty : Address.t -> Raw_level.t -> t - - val inbox_level : t -> Raw_level.t - - val number_of_available_messages : t -> Z.t - - val consume_n_messages : int32 -> t -> t option tzresult - - module Hash : S.HASH - - module type MerkelizedOperations = sig - type tree - - type message = tree - - type messages = tree - - type history - - val history_encoding : history Data_encoding.t - - val pp_history : Format.formatter -> history -> unit - - val history_at_genesis : bound:int64 -> history - - val add_external_messages : - history -> - t -> - Raw_level.t -> - string list -> - messages -> - (messages * history * t) tzresult Lwt.t - - val add_messages_no_history : - t -> - Raw_level.t -> - Message.serialized list -> - messages -> - (messages * t, error trace) result Lwt.t - - val get_message : messages -> Z.t -> message option Lwt.t - - val get_message_payload : messages -> Z.t -> string option Lwt.t - - type inclusion_proof - - val inclusion_proof_encoding : inclusion_proof Data_encoding.t - - val pp_inclusion_proof : Format.formatter -> inclusion_proof -> unit - - val number_of_proof_steps : inclusion_proof -> int - - val produce_inclusion_proof : history -> t -> t -> inclusion_proof option - - val verify_inclusion_proof : inclusion_proof -> t -> t -> bool - end - - include MerkelizedOperations with type tree = Context.tree - - module type TREE = sig - type t - - type tree - - type key = string list - - type value = bytes - - val find : tree -> key -> value option Lwt.t - - val find_tree : tree -> key -> tree option Lwt.t - - val add : tree -> key -> value -> tree Lwt.t - - val is_empty : tree -> bool - - val hash : tree -> Context_hash.t - end - - module MakeHashingScheme (Tree : TREE) : - MerkelizedOperations with type tree = Tree.tree - - val add_external_messages : - context -> rollup -> string list -> (t * Z.t * context) tzresult Lwt.t - - val add_internal_message : - context -> - rollup -> - payload:Script.expr -> - sender:Contract_hash.t -> - source:Signature.public_key_hash -> - (t * Z.t * context) tzresult Lwt.t - - val inbox : context -> rollup -> (t * context) tzresult Lwt.t - - module Proof : sig - type t - end - end - module Errors : sig type error += Sc_rollup_does_not_exist of t end -- GitLab From 52c7d398504d727a05a72675e292e2fcf6792f7e Mon Sep 17 00:00:00 2001 From: Yann Regis-Gianas Date: Thu, 16 Jun 2022 14:04:39 +0200 Subject: [PATCH 05/11] Proto,SCORU: Slightly relax the type of serialized inbox message ... because we will need to deserialize them from the PVM state. Signed-off-by: Yann Regis-Gianas --- .../lib_protocol/sc_rollup_inbox_message_repr.ml | 14 +++++++------- .../lib_protocol/sc_rollup_inbox_message_repr.mli | 10 ++++------ .../lib_protocol/sc_rollup_management_protocol.ml | 3 +-- .../lib_protocol/sc_rollup_management_protocol.mli | 3 ++- .../lib_protocol/test/pbt/test_refutation_game.ml | 9 +++++++-- .../unit/test_sc_rollup_management_protocol.ml | 3 +-- 6 files changed, 22 insertions(+), 20 deletions(-) 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 938fc2d57b2f..57546f19aebe 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 @@ -97,10 +97,10 @@ let to_bytes msg = | None -> fail Error_encode_inbox_message | Some str -> return str -module Internal_for_tests = struct - let of_bytes bytes = - let open Tzresult_syntax in - match Data_encoding.Binary.of_string_opt encoding bytes with - | None -> fail Error_decode_inbox_message - | Some msg -> return msg -end +let of_bytes bytes = + let open Tzresult_syntax in + match Data_encoding.Binary.of_string_opt encoding bytes with + | None -> fail Error_decode_inbox_message + | Some msg -> return msg + +let unsafe_of_string s = s 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 2b47747fc0a9..394106f27be4 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 @@ -61,14 +61,12 @@ type internal_inbox_message = { an external manager operation. *) type t = Internal of internal_inbox_message | External of string -(** A typed version of a message serialized in binary format. *) 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 -(** Module containing functions exposed so they can be used in test. *) -module Internal_for_tests : sig - (** [of_bytes bs] decodes [bs] as an [inbox_message]. *) - val of_bytes : string -> t tzresult -end +(** [of_bytes bs] decodes [bs] as an [inbox_message]. *) +val of_bytes : serialized -> t tzresult 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 98856c39a1eb..6d00024d1fc8 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_management_protocol.ml +++ b/src/proto_alpha/lib_protocol/sc_rollup_management_protocol.ml @@ -172,6 +172,5 @@ module Internal_for_tests = struct in Sc_rollup.Outbox.Message.Internal_for_tests.to_bytes output_message_internal - let inbox_message_of_bytes = - Sc_rollup.Inbox.Message.Internal_for_tests.of_bytes + let inbox_message_of_bytes = Sc_rollup.Inbox.Message.of_bytes 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 fd4be863605b..e5aa5a6d10ea 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_management_protocol.mli +++ b/src/proto_alpha/lib_protocol/sc_rollup_management_protocol.mli @@ -102,5 +102,6 @@ module Internal_for_tests : sig (** [inbox_message_of_bytes bs] decodes an inbox message from the given bytes [bs]. *) - val inbox_message_of_bytes : string -> Sc_rollup.Inbox.Message.t tzresult + val inbox_message_of_bytes : + Sc_rollup.Inbox.Message.serialized -> Sc_rollup.Inbox.Message.t tzresult end 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 229943e855e5..957630d69c9b 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 @@ -412,6 +412,11 @@ end) : TestPVM = struct let init_context = Tezos_context_memory.make_empty_context () module Utils = struct + let make_external_inbox_message str = + match Inbox.Message.(External str |> to_bytes) with + | Ok s -> s + | _ -> assert false + let default_state = let promise = let* boot = initial_state init_context "" >>= eval in @@ -419,7 +424,7 @@ end) : TestPVM = struct { inbox_level = Raw_level.root; message_counter = Z.zero; - payload = P.inputs; + payload = make_external_inbox_message P.inputs; } in let prelim = set_input input boot in @@ -434,7 +439,7 @@ end) : TestPVM = struct { inbox_level = Raw_level.root; message_counter = Z.zero; - payload = String.concat " " program; + payload = make_external_inbox_message @@ String.concat " " program; } in let prelim = set_input input state in 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 9d13f975705f..1b80b227ce6b 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 @@ -42,7 +42,6 @@ let check_encode_decode_inbox_message message = let*? bytes = Environment.wrap_tzresult @@ Sc_rollup.Inbox.Message.to_bytes message in - let bytes = (bytes :> string) in let*? message' = Environment.wrap_tzresult @@ Internal_for_tests.inbox_message_of_bytes bytes in @@ -50,7 +49,7 @@ let check_encode_decode_inbox_message message = Environment.wrap_tzresult @@ Sc_rollup.Inbox.Message.to_bytes message' in let bytes' = (bytes' :> string) in - Assert.equal_string ~loc:__LOC__ bytes bytes' + Assert.equal_string ~loc:__LOC__ (bytes :> string) (bytes' :> string) let check_encode_decode_outbox_message ctxt message = let open Lwt_result_syntax in -- GitLab From d67317499498192125ccea17eb4c3cb19370e6e5 Mon Sep 17 00:00:00 2001 From: Yann Regis-Gianas Date: Thu, 16 Jun 2022 14:07:44 +0200 Subject: [PATCH 06/11] Proto,SCORU: Make PVMs compliant with the Rollup Management Protocol ... and adjust the rollup node accordingly. Signed-off-by: Yann Regis-Gianas --- src/proto_alpha/bin_sc_rollup_node/inbox.ml | 3 +++ .../bin_sc_rollup_node/interpreter.ml | 13 +++++++---- .../lib_protocol/alpha_context.mli | 10 ++++----- .../lib_protocol/sc_rollup_PVM_sem.ml | 13 +++++++---- .../lib_protocol/sc_rollup_arith.ml | 22 +++++++++++++------ .../lib_protocol/sc_rollup_inbox_repr.ml | 3 ++- .../lib_protocol/sc_rollup_wasm.ml | 4 ++-- .../test/unit/test_sc_rollup_arith.ml | 13 +++++++---- 8 files changed, 53 insertions(+), 28 deletions(-) diff --git a/src/proto_alpha/bin_sc_rollup_node/inbox.ml b/src/proto_alpha/bin_sc_rollup_node/inbox.ml index a51e99ba6f72..bdde8c098385 100644 --- a/src/proto_alpha/bin_sc_rollup_node/inbox.ml +++ b/src/proto_alpha/bin_sc_rollup_node/inbox.ml @@ -68,6 +68,9 @@ module State = struct let set_message_tree = Store.MessageTrees.set end +(* FIXME: https://gitlab.com/tezos/tezos/-/issues/3233 + For the moment, the rollup node ignores L1 to L2 messages. +*) let get_messages cctxt head rollup = let open Lwt_result_syntax in let open Block_services in diff --git a/src/proto_alpha/bin_sc_rollup_node/interpreter.ml b/src/proto_alpha/bin_sc_rollup_node/interpreter.ml index a1a9cb4a25c5..3c66094a2c36 100644 --- a/src/proto_alpha/bin_sc_rollup_node/interpreter.ml +++ b/src/proto_alpha/bin_sc_rollup_node/interpreter.ml @@ -94,14 +94,19 @@ module Make (PVM : Pvm.S) : S = struct let*! messages = Store.Messages.get store hash in (* Iterate the PVM state with all the messages for this level. *) - let*! state = - List.fold_left_i_s - (fun message_counter state payload -> + let* state = + List.fold_left_i_es + (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) + in let input = Sc_rollup. {inbox_level; message_counter = Z.of_int message_counter; payload} in - feed_input state input) + let*! state = feed_input state input in + return state) predecessor_state messages in diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index dfb3c58b10bc..6c6b84859fc5 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -2773,13 +2773,11 @@ module Sc_rollup : sig type serialized = private string + val unsafe_of_string : string -> serialized + val to_bytes : t -> serialized tzresult - (** This module discloses definitions that are only useful for tests and - must not be used otherwise. *) - module Internal_for_tests : sig - val of_bytes : string -> t tzresult - end + val of_bytes : serialized -> t tzresult end val pp : Format.formatter -> t -> unit @@ -2889,7 +2887,7 @@ module Sc_rollup : sig type input = { inbox_level : Raw_level.t; message_counter : Z.t; - payload : string; + payload : Inbox.Message.serialized; } val input_equal : input -> input -> bool 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 5d688ddb87e6..cff8031ecd07 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_PVM_sem.ml +++ b/src/proto_alpha/lib_protocol/sc_rollup_PVM_sem.ml @@ -50,19 +50,24 @@ open Sc_rollup_repr (** An input to a PVM is the [message_counter] element of an inbox at - a given [inbox_level] and contains a given [payload]. *) + a given [inbox_level] and contains a given [payload]. + + According the rollup management protocol, the payload must be + obtained through {!Sc_rollup_inbox_message_repr.to_bytes} which + follows a documented format. *) type input = { inbox_level : Raw_level_repr.t; message_counter : Z.t; - payload : string; + payload : Sc_rollup_inbox_message_repr.serialized; } let input_encoding = let open Data_encoding in conv (fun {inbox_level; message_counter; payload} -> - (inbox_level, message_counter, payload)) + (inbox_level, message_counter, (payload :> string))) (fun (inbox_level, message_counter, payload) -> + let payload = Sc_rollup_inbox_message_repr.unsafe_of_string payload in {inbox_level; message_counter; payload}) (obj3 (req "inbox_level" Raw_level_repr.encoding) @@ -74,7 +79,7 @@ let input_equal (a : input) (b : input) : bool = (* To be robust to the addition of fields in [input] *) Raw_level_repr.equal inbox_level b.inbox_level && Z.equal message_counter b.message_counter - && String.equal payload b.payload + && String.equal (payload :> string) (b.payload :> string) (** The PVM's current input expectations. [No_input_required] is if the machine is busy and has no need for new input. [Initial] will be if diff --git a/src/proto_alpha/lib_protocol/sc_rollup_arith.ml b/src/proto_alpha/lib_protocol/sc_rollup_arith.ml index 2fceb16ac63b..327c0745adca 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_arith.ml +++ b/src/proto_alpha/lib_protocol/sc_rollup_arith.ml @@ -799,14 +799,22 @@ module Make (Context : P) : let set_input_monadic input = let open PS in - let {inbox_level; message_counter; payload} = input in + let open Sc_rollup_inbox_message_repr in let open Monad.Syntax in - let* boot_sector = Boot_sector.get in - let msg = boot_sector ^ payload in - let* () = CurrentLevel.set inbox_level in - let* () = MessageCounter.set (Some message_counter) in - let* () = NextMessage.set (Some msg) in - return () + let {inbox_level; message_counter; payload} = input in + match of_bytes payload with + | Ok (External payload) -> + let* boot_sector = Boot_sector.get in + let msg = boot_sector ^ payload in + let* () = CurrentLevel.set inbox_level in + let* () = MessageCounter.set (Some message_counter) in + let* () = NextMessage.set (Some msg) in + return () + | Error _ | Ok (Internal _) -> + let* () = CurrentLevel.set inbox_level in + let* () = MessageCounter.set (Some message_counter) in + let* () = Status.set WaitingForInputMessage in + return () let set_input input = state_of @@ set_input_monadic input diff --git a/src/proto_alpha/lib_protocol/sc_rollup_inbox_repr.ml b/src/proto_alpha/lib_protocol/sc_rollup_inbox_repr.ml index 1132b6c857f6..b34df886f287 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_inbox_repr.ml +++ b/src/proto_alpha/lib_protocol/sc_rollup_inbox_repr.ml @@ -862,10 +862,11 @@ module Proof = struct if equal proof.level inbox then return None else proof_error "payload is None, inbox proof.level not top" | Some msg -> + let payload = Sc_rollup_inbox_message_repr.unsafe_of_string msg in return @@ Some Sc_rollup_PVM_sem. - {inbox_level = l; message_counter = n; payload = msg} + {inbox_level = l; message_counter = n; payload} else proof_error "Inbox proof parameters don't match (message level)" | Some (level, inc, remaining_proof) -> if diff --git a/src/proto_alpha/lib_protocol/sc_rollup_wasm.ml b/src/proto_alpha/lib_protocol/sc_rollup_wasm.ml index 67d9c7e040ab..eb7888be9ccd 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_wasm.ml +++ b/src/proto_alpha/lib_protocol/sc_rollup_wasm.ml @@ -249,8 +249,8 @@ module V2_0_0 = struct let set_input_state input = let open PS in - let {inbox_level; message_counter; payload} = input in let open Monad.Syntax in + let {inbox_level; message_counter; payload} = input in let* s = get in let* s = lift @@ -259,7 +259,7 @@ module V2_0_0 = struct inbox_level = Raw_level_repr.to_int32_non_negative inbox_level; message_counter; } - payload + (payload :> string) s) in set s 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 1838e469cbd6..f608611f9eff 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 @@ -130,6 +130,11 @@ let test_boot () = | No_input_required -> failwith "After booting, the machine must be waiting for input." +let make_external_inbox_message str = + match Sc_rollup_inbox_message_repr.(External str |> to_bytes) with + | Ok s -> s + | _ -> assert false + let test_input_message () = let open Sc_rollup_PVM_sem in boot "" @@ fun _ctxt state -> @@ -137,7 +142,7 @@ let test_input_message () = { inbox_level = Raw_level_repr.root; message_counter = Z.zero; - payload = "MESSAGE"; + payload = make_external_inbox_message "MESSAGE"; } in set_input input state >>= fun state -> @@ -168,7 +173,7 @@ let test_parsing_message ~valid (source, expected_code) = { inbox_level = Raw_level_repr.root; message_counter = Z.zero; - payload = source; + payload = make_external_inbox_message source; } in set_input input state >>= fun state -> @@ -236,7 +241,7 @@ let test_evaluation_message ~valid { inbox_level = Raw_level_repr.root; message_counter = Z.zero; - payload = source; + payload = make_external_inbox_message source; } in set_input input state >>= fun state -> @@ -311,7 +316,7 @@ let test_output_messages_proofs ~valid ~inbox_level (source, expected_outputs) = { inbox_level = Raw_level_repr.of_int32_exn (Int32.of_int inbox_level); message_counter = Z.zero; - payload = source; + payload = make_external_inbox_message source; } in let*! state = set_input input state in -- GitLab From 0e56624d715960423a887ba59d810b7ecb7ddf7c Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Thu, 16 Jun 2022 19:46:04 +0000 Subject: [PATCH 07/11] Proto,SCORU: Improve code quality --- .../lib_protocol/test/unit/test_sc_rollup_management_protocol.ml | 1 - 1 file changed, 1 deletion(-) 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 1b80b227ce6b..67d35b203af6 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 @@ -48,7 +48,6 @@ let check_encode_decode_inbox_message message = let*? bytes' = Environment.wrap_tzresult @@ Sc_rollup.Inbox.Message.to_bytes message' in - let bytes' = (bytes' :> string) in Assert.equal_string ~loc:__LOC__ (bytes :> string) (bytes' :> string) let check_encode_decode_outbox_message ctxt message = -- GitLab From 9019478742768c527f8bbb1e644eb173beeff4e0 Mon Sep 17 00:00:00 2001 From: Joel Bjornson Date: Thu, 16 Jun 2022 19:48:55 +0000 Subject: [PATCH 08/11] Tezt,SCORU: Fix typo --- tezt/tests/sc_rollup.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tezt/tests/sc_rollup.ml b/tezt/tests/sc_rollup.ml index 90b8361105ff..9adee5c48bb1 100644 --- a/tezt/tests/sc_rollup.ml +++ b/tezt/tests/sc_rollup.ml @@ -996,7 +996,7 @@ let test_rollup_node_advances_pvm_state = | Error error -> failwith (Format.asprintf - "The arithmetic PVM has an expected state: %a" + "The arithmetic PVM has an unexpected state: %a" Data_encoding.Binary.pp_read_error error) | Ok x -> x -- GitLab From bf9ede2bdcd1a8ac5d85e7a3191a5c31b4416228 Mon Sep 17 00:00:00 2001 From: Joel Bjornson Date: Mon, 20 Jun 2022 10:08:31 +0000 Subject: [PATCH 09/11] Proto,SCORU: Fix an issue number --- src/proto_alpha/bin_sc_rollup_node/inbox.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/proto_alpha/bin_sc_rollup_node/inbox.ml b/src/proto_alpha/bin_sc_rollup_node/inbox.ml index bdde8c098385..bef0b8e45535 100644 --- a/src/proto_alpha/bin_sc_rollup_node/inbox.ml +++ b/src/proto_alpha/bin_sc_rollup_node/inbox.ml @@ -68,7 +68,7 @@ module State = struct let set_message_tree = Store.MessageTrees.set end -(* FIXME: https://gitlab.com/tezos/tezos/-/issues/3233 +(* FIXME: https://gitlab.com/tezos/tezos/-/issues/3199 For the moment, the rollup node ignores L1 to L2 messages. *) let get_messages cctxt head rollup = -- GitLab From 65b8eb35814fc07b55e21cbb423810ffcf61d916 Mon Sep 17 00:00:00 2001 From: Joel Bjornson Date: Mon, 20 Jun 2022 13:54:44 +0000 Subject: [PATCH 10/11] Proto,SCORU: Improve code quality --- .../lib_protocol/test/pbt/test_refutation_game.ml | 6 +++--- .../lib_protocol/test/unit/test_sc_rollup_arith.ml | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) 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 957630d69c9b..bc5ff20abb8a 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 @@ -413,9 +413,9 @@ end) : TestPVM = struct module Utils = struct let make_external_inbox_message str = - match Inbox.Message.(External str |> to_bytes) with - | Ok s -> s - | _ -> assert false + WithExceptions.Result.get_ok + ~loc:__LOC__ + Inbox.Message.(External str |> to_bytes) let default_state = let promise = 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 f608611f9eff..cfaaf9e6df6c 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 @@ -131,9 +131,9 @@ let test_boot () = failwith "After booting, the machine must be waiting for input." let make_external_inbox_message str = - match Sc_rollup_inbox_message_repr.(External str |> to_bytes) with - | Ok s -> s - | _ -> assert false + WithExceptions.Result.get_ok + ~loc:__LOC__ + Sc_rollup_inbox_message_repr.(External str |> to_bytes) let test_input_message () = let open Sc_rollup_PVM_sem in -- GitLab From c4aecfb098e536e0f657baa26187346b33eab4c2 Mon Sep 17 00:00:00 2001 From: Joel Bjornson Date: Tue, 21 Jun 2022 09:09:18 +0000 Subject: [PATCH 11/11] Proto,SCORU: Improve code quality --- src/proto_alpha/lib_protocol/sc_rollup_arith.ml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/proto_alpha/lib_protocol/sc_rollup_arith.ml b/src/proto_alpha/lib_protocol/sc_rollup_arith.ml index 327c0745adca..781c520042a1 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_arith.ml +++ b/src/proto_alpha/lib_protocol/sc_rollup_arith.ml @@ -797,12 +797,9 @@ module Make (Context : P) : let get_is_stuck = result_of ~default:None @@ is_stuck - let set_input_monadic input = - let open PS in - let open Sc_rollup_inbox_message_repr in + let set_input_monadic {PS.inbox_level; message_counter; payload} = let open Monad.Syntax in - let {inbox_level; message_counter; payload} = input in - match of_bytes payload with + match Sc_rollup_inbox_message_repr.of_bytes payload with | Ok (External payload) -> let* boot_sector = Boot_sector.get in let msg = boot_sector ^ payload in -- GitLab