From 80bdd837c8ff51cbd10b16adf46eead326b682eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20Kr=C3=BCger?= Date: Tue, 5 Apr 2022 16:00:44 +0100 Subject: [PATCH] SCORU: Use bootsector in L2 node (#2722) --- src/proto_alpha/bin_sc_rollup_node/daemon.ml | 18 +-- .../bin_sc_rollup_node/interpreter.ml | 49 +++--- src/proto_alpha/lib_plugin/plugin.ml | 16 ++ .../lib_protocol/alpha_context.mli | 2 + .../lib_protocol/sc_rollup_storage.ml | 7 + .../lib_protocol/sc_rollup_storage.mli | 5 +- .../sc_rollup_node_uses_boot_sector.out | 147 ++++++++++++++++++ .../sc_rollup_origination_bootsector.out | 34 ++++ tezt/lib_tezos/RPC.ml | 5 + tezt/lib_tezos/RPC.mli | 10 ++ tezt/tests/sc_rollup.ml | 146 ++++++++++++++--- 11 files changed, 388 insertions(+), 51 deletions(-) create mode 100644 tezt/_regressions/sc_rollup_node_uses_boot_sector.out create mode 100644 tezt/_regressions/sc_rollup_origination_bootsector.out diff --git a/src/proto_alpha/bin_sc_rollup_node/daemon.ml b/src/proto_alpha/bin_sc_rollup_node/daemon.ml index 8c07ed1807ab..80d50414132c 100644 --- a/src/proto_alpha/bin_sc_rollup_node/daemon.ml +++ b/src/proto_alpha/bin_sc_rollup_node/daemon.ml @@ -76,7 +76,7 @@ let process_head node_ctxt store head_state = let* () = Inbox.process_head node_ctxt store head in (* Avoid storing and publishing commitments if the head is not final *) (* Avoid triggering the pvm execution if this has been done before for this head *) - Interpreter.Arith.process_head store head + Interpreter.Arith.process_head node_ctxt store head in let* () = if finalized then @@ -90,16 +90,16 @@ let process_head node_ctxt store head_state = (* [on_layer_1_chain_event node_ctxt store chain_event old_heads] processes a list of heads, coming from either a list of [old_heads] or from the current - [chain_event]. [old_heads] is the list of heads returned by the previous + [chain_event]. [old_heads] is the list of heads returned by the previous iteration of [on_layer_1_chain_event] in the [daemonize function]. These are - heads included in the branch currently tracked by the rollup node, and that - have only been partially processed, due to the rollup node not being able - to establish their finality. The function returns a list of heads from the - current branch tracked by the rollup node, whose finality cannot be - established at the time the function is invoked. Those heads will be - processed again at the next iteration of [on_layer_1_chain_event] in the + heads included in the branch currently tracked by the rollup node, and that + have only been partially processed, due to the rollup node not being able + to establish their finality. The function returns a list of heads from the + current branch tracked by the rollup node, whose finality cannot be + established at the time the function is invoked. Those heads will be + processed again at the next iteration of [on_layer_1_chain_event] in the [daemonize] function. If [chain_event] is a rollback event, then no head - needs to be returned to be included as the rollup node started tracking a + needs to be returned to be included as the rollup node started tracking a new branch. *) let on_layer_1_chain_event node_ctxt store chain_event old_heads = diff --git a/src/proto_alpha/bin_sc_rollup_node/interpreter.ml b/src/proto_alpha/bin_sc_rollup_node/interpreter.ml index 57b2e2d34c97..42ca377eee41 100644 --- a/src/proto_alpha/bin_sc_rollup_node/interpreter.ml +++ b/src/proto_alpha/bin_sc_rollup_node/interpreter.ml @@ -28,12 +28,11 @@ open Alpha_context module Inbox = Store.Inbox module type S = sig - (** [process_head store head] interprets the messages associated with a [head] - from a chain [event]. This requires the inbox to be updated beforehand. *) - - val process_head : Store.t -> Layer1.head -> unit tzresult Lwt.t - - (** [start store] sets up the initial state for the PVM interpreter to work. *) + (** [process_head node_ctxt store head] interprets the messages associated + with a [head] from a chain [event]. This requires the inbox to be updated + beforehand. *) + val process_head : + Node_context.t -> Store.t -> Layer1.head -> unit tzresult Lwt.t end module Make (PVM : Pvm.S) : S = struct @@ -62,25 +61,31 @@ module Make (PVM : Pvm.S) : S = struct let* state = eval_until_input state in return state - (** [transition_pvm store predecessor_hash hash] runs a PVM at the previous state from block + (** [transition_pvm node_ctxt store predecessor_hash hash] runs a PVM at the previous state from block [predecessor_hash] by consuming as many messages as possible from block [hash]. *) - let transition_pvm store predecessor_hash hash = + let transition_pvm node_ctxt store predecessor_hash hash = + let open Node_context in let open Lwt_result_syntax in (* Retrieve the previous PVM state from store. *) let*! predecessor_state = Store.PVMState.find store predecessor_hash in - let*! predecessor_state = + let* predecessor_state = match predecessor_state with | None -> - (* The predecessor is before the origination. *) - PVM.initial_state - store - (* TODO: #2722 - This initial state is a stub. We must figure out the bootsector (part of the - origination message for a SC rollup) first - only then can the initial state be - constructed. - *) - "" - | Some predecessor_state -> Lwt.return predecessor_state + (* The predecessor is before the origination. + Here we use an RPC to get the boot sector instead of doing this + before and packing it into the [node_ctxt] because the bootsector + might be very large and we don't want to keep that in memory for + ever. + *) + let* boot_sector = + Plugin.RPC.Sc_rollup.boot_sector + node_ctxt.cctxt + (node_ctxt.cctxt#chain, node_ctxt.cctxt#block) + node_ctxt.rollup_address + in + let*! initial_state = PVM.initial_state store boot_sector in + return initial_state + | Some predecessor_state -> return predecessor_state in (* Obtain inbox and its messages for this block. *) @@ -122,11 +127,11 @@ module Make (PVM : Pvm.S) : S = struct return_unit - (** [process_head store head] runs the PVM for the given head. *) - let process_head store (Layer1.Head {hash; _} as head) = + (** [process_head node_ctxt store head] runs the PVM for the given head. *) + let process_head node_ctxt store (Layer1.Head {hash; _} as head) = let open Lwt_result_syntax in let*! predecessor_hash = Layer1.predecessor store head in - transition_pvm store predecessor_hash hash + transition_pvm node_ctxt store predecessor_hash hash end module Arith = Make (Arith_pvm) diff --git a/src/proto_alpha/lib_plugin/plugin.ml b/src/proto_alpha/lib_plugin/plugin.ml index 26b7b444f4c9..62afbe7ea6ca 100644 --- a/src/proto_alpha/lib_plugin/plugin.ml +++ b/src/proto_alpha/lib_plugin/plugin.ml @@ -2917,6 +2917,13 @@ module RPC = struct ~output:(obj1 (opt "kind" Sc_rollup.Kind.encoding)) RPC_path.(path /: Sc_rollup.Address.rpc_arg / "kind") + let boot_sector = + RPC_service.get_service + ~description:"Boot sector of smart-contract rollup" + ~query:RPC_query.empty + ~output:Data_encoding.string + RPC_path.(path /: Sc_rollup.Address.rpc_arg / "boot_sector") + let inbox = RPC_service.get_service ~description:"Inbox for a smart-contract rollup" @@ -2960,6 +2967,11 @@ module RPC = struct @@ fun ctxt address () () -> Alpha_context.Sc_rollup.initial_level ctxt address + let register_boot_sector () = + Registration.register1 ~chunked:true S.boot_sector + @@ fun ctxt address () () -> + Alpha_context.Sc_rollup.get_boot_sector ctxt address + let register_root () = Registration.register0 ~chunked:true S.root (fun context () () -> Sc_rollup.list context) @@ -2968,12 +2980,16 @@ module RPC = struct register_kind () ; register_inbox () ; register_initial_level () ; + register_boot_sector () ; register_root () let list ctxt block = RPC_context.make_call0 S.root ctxt block () () let initial_level ctxt block sc_rollup_address = RPC_context.make_call1 S.initial_level ctxt block sc_rollup_address () () + + let boot_sector ctxt block sc_rollup_address = + RPC_context.make_call1 S.boot_sector ctxt block sc_rollup_address () () end module Forge = struct diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index b806e5f5429f..f5a24ee1a077 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -2641,6 +2641,8 @@ module Sc_rollup : sig val initial_level : context -> t -> Raw_level.t tzresult Lwt.t + val get_boot_sector : context -> t -> string tzresult Lwt.t + module Internal_for_tests : sig val originated_sc_rollup : Origination_nonce.Internal_for_tests.t -> t end diff --git a/src/proto_alpha/lib_protocol/sc_rollup_storage.ml b/src/proto_alpha/lib_protocol/sc_rollup_storage.ml index c3f26c51001c..80d247b1000d 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_storage.ml +++ b/src/proto_alpha/lib_protocol/sc_rollup_storage.ml @@ -768,3 +768,10 @@ let initial_level ctxt rollup = match level with | None -> fail (Sc_rollup_does_not_exist rollup) | Some level -> return level + +let get_boot_sector ctxt rollup = + let open Lwt_tzresult_syntax in + let* boot_sector = Storage.Sc_rollup.Boot_sector.find ctxt rollup in + match boot_sector with + | None -> fail (Sc_rollup_does_not_exist rollup) + | Some boot_sector -> return boot_sector diff --git a/src/proto_alpha/lib_protocol/sc_rollup_storage.mli b/src/proto_alpha/lib_protocol/sc_rollup_storage.mli index 0e574dcdd953..2cbc5653873b 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_storage.mli +++ b/src/proto_alpha/lib_protocol/sc_rollup_storage.mli @@ -409,7 +409,10 @@ val remove_staker : (* [list context] returns a list of all rollups that have been originated. *) val list : Raw_context.t -> Sc_rollup_repr.t list tzresult Lwt.t -(* [initial_level ctxt sc_rollup] returns the level at which a [sc_rollup] was +(* [initial_level ctxt sc_rollup] returns the level at which a [sc_rollup] was originated. *) val initial_level : Raw_context.t -> Sc_rollup_repr.t -> Raw_level_repr.t tzresult Lwt.t + +(** [get_boot_sector ctxt sc_rollup] retrieves the boot sector for [sc_rollup]. *) +val get_boot_sector : Raw_context.t -> Sc_rollup_repr.t -> string tzresult Lwt.t diff --git a/tezt/_regressions/sc_rollup_node_uses_boot_sector.out b/tezt/_regressions/sc_rollup_node_uses_boot_sector.out new file mode 100644 index 000000000000..850f619244d8 --- /dev/null +++ b/tezt/_regressions/sc_rollup_node_uses_boot_sector.out @@ -0,0 +1,147 @@ +sc_rollup_node_uses_boot_sector.out + +./tezos-client --wait none originate sc rollup from '[PUBLIC_KEY_HASH]' of kind arith booting with '10 10 10 + +' --burn-cap 9999999 +Node is bootstrapped. +Estimated gas: 1600.648 units (will add 100 for safety) +Estimated storage: 6534 bytes added (will add 20 for safety) +Operation successfully injected in the node. +Operation hash is '[OPERATION_HASH]' +NOT waiting for the operation to be included. +Use command + tezos-client wait for [OPERATION_HASH] to be included --confirmations 1 --branch [BLOCK_HASH] +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.000414 + Expected counter: 1 + Gas limit: 1701 + Storage limit: 6554 bytes + Balance updates: + [PUBLIC_KEY_HASH] ... -ꜩ0.000414 + payload fees(the block proposer) ....... +ꜩ0.000414 + Originate smart contract rollup of kind arith with boot sector '10 10 10 + +' + This smart contract rollup origination was successfully applied + Consumed gas: 1600.648 + Storage size: 6534 bytes + Address: [SC_ROLLUP_HASH] + Balance updates: + [PUBLIC_KEY_HASH] ... -ꜩ1.6335 + storage fees ........................... +ꜩ1.6335 + + +./tezos-client rpc get '/chains/main/blocks/head/context/sc_rollup/[SC_ROLLUP_HASH]/initial_level' +2 + +./tezos-client --wait none send sc rollup message 'text:["3130202b"]' from bootstrap1 to '[SC_ROLLUP_HASH]' +Node is bootstrapped. +Estimated gas: 1651.589 units (will add 100 for safety) +Estimated storage: no bytes added +Operation successfully injected in the node. +Operation hash is '[OPERATION_HASH]' +NOT waiting for the operation to be included. +Use command + tezos-client wait for [OPERATION_HASH] to be included --confirmations 1 --branch [BLOCK_HASH] +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.000457 + Expected counter: 2 + Gas limit: 1752 + Storage limit: 0 bytes + Balance updates: + [PUBLIC_KEY_HASH] ... -ꜩ0.000457 + payload fees(the block proposer) ....... +ꜩ0.000457 + Add a message to the inbox of the smart contract rollup at address [SC_ROLLUP_HASH] + This operation sending a message to a smart contract rollup was successfully applied + Consumed gas: 1651.717 + Resulting inbox state: + rollup = [SC_ROLLUP_HASH] + level = 3 + current messages hash = CoWa8bU1F5LUoL6URwdZbNFvmLhFGNvdJHkNkPJLjEZKF6EwtMVr + nb_available_messages = 1 + message_counter = 1 + old_levels_messages = + content = CoUkdBQ53N7FWav8LuTvrcp3jyoxnpqk3xnEo3gSCgNwia4fq44j + index = 1 + back_pointers = CoVawGHT9AxoKnd7hDBCii5PEcM2U3WbtL4L5HGD6PC9BWcLnzqD + + + + +./tezos-sc-rollup-client-alpha rpc get /state_hash +"[SC_ROLLUP_STATE_HASH]" + +./tezos-client --wait none originate sc rollup from '[PUBLIC_KEY_HASH]' of kind arith booting with 31 --burn-cap 9999999 +Node is bootstrapped. +Estimated gas: 1600.648 units (will add 100 for safety) +Estimated storage: 6524 bytes added (will add 20 for safety) +Operation successfully injected in the node. +Operation hash is '[OPERATION_HASH]' +NOT waiting for the operation to be included. +Use command + tezos-client wait for [OPERATION_HASH] to be included --confirmations 1 --branch [BLOCK_HASH] +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.000404 + Expected counter: 3 + Gas limit: 1701 + Storage limit: 6544 bytes + Balance updates: + [PUBLIC_KEY_HASH] ... -ꜩ0.000404 + payload fees(the block proposer) ....... +ꜩ0.000404 + Originate smart contract rollup of kind arith with boot sector '31' + This smart contract rollup origination was successfully applied + Consumed gas: 1600.648 + Storage size: 6524 bytes + Address: [SC_ROLLUP_HASH] + Balance updates: + [PUBLIC_KEY_HASH] ... -ꜩ1.631 + storage fees ........................... +ꜩ1.631 + + +./tezos-client rpc get '/chains/main/blocks/head/context/sc_rollup/[SC_ROLLUP_HASH]/initial_level' +4 + +./tezos-client --wait none send sc rollup message 'text:["3130202b"]' from bootstrap1 to '[SC_ROLLUP_HASH]' +Node is bootstrapped. +Estimated gas: 1651.589 units (will add 100 for safety) +Estimated storage: no bytes added +Operation successfully injected in the node. +Operation hash is '[OPERATION_HASH]' +NOT waiting for the operation to be included. +Use command + tezos-client wait for [OPERATION_HASH] to be included --confirmations 1 --branch [BLOCK_HASH] +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.000457 + Expected counter: 4 + Gas limit: 1752 + Storage limit: 0 bytes + Balance updates: + [PUBLIC_KEY_HASH] ... -ꜩ0.000457 + payload fees(the block proposer) ....... +ꜩ0.000457 + Add a message to the inbox of the smart contract rollup at address [SC_ROLLUP_HASH] + This operation sending a message to a smart contract rollup was successfully applied + Consumed gas: 1651.717 + Resulting inbox state: + rollup = [SC_ROLLUP_HASH] + level = 5 + current messages hash = CoWa8bU1F5LUoL6URwdZbNFvmLhFGNvdJHkNkPJLjEZKF6EwtMVr + nb_available_messages = 1 + message_counter = 1 + old_levels_messages = + content = CoUkdBQ53N7FWav8LuTvrcp3jyoxnpqk3xnEo3gSCgNwia4fq44j + index = 1 + back_pointers = CoVawGHT9AxoKnd7hDBCii5PEcM2U3WbtL4L5HGD6PC9BWcLnzqD + + + + +./tezos-sc-rollup-client-alpha rpc get /state_hash +"[SC_ROLLUP_STATE_HASH]" diff --git a/tezt/_regressions/sc_rollup_origination_bootsector.out b/tezt/_regressions/sc_rollup_origination_bootsector.out new file mode 100644 index 000000000000..901b193838a4 --- /dev/null +++ b/tezt/_regressions/sc_rollup_origination_bootsector.out @@ -0,0 +1,34 @@ +sc_rollup_origination_bootsector.out + +./tezos-client --wait none originate sc rollup from '[PUBLIC_KEY_HASH]' of kind arith booting with '10 10 10 + +' --burn-cap 9999999 +Node is bootstrapped. +Estimated gas: 1600.648 units (will add 100 for safety) +Estimated storage: 6534 bytes added (will add 20 for safety) +Operation successfully injected in the node. +Operation hash is '[OPERATION_HASH]' +NOT waiting for the operation to be included. +Use command + tezos-client wait for [OPERATION_HASH] to be included --confirmations 1 --branch [BLOCK_HASH] +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.000414 + Expected counter: 1 + Gas limit: 1701 + Storage limit: 6554 bytes + Balance updates: + [PUBLIC_KEY_HASH] ... -ꜩ0.000414 + payload fees(the block proposer) ....... +ꜩ0.000414 + Originate smart contract rollup of kind arith with boot sector '10 10 10 + +' + This smart contract rollup origination was successfully applied + Consumed gas: 1600.648 + Storage size: 6534 bytes + Address: [SC_ROLLUP_HASH] + Balance updates: + [PUBLIC_KEY_HASH] ... -ꜩ1.6335 + storage fees ........................... +ꜩ1.6335 + + +./tezos-client rpc get '/chains/main/blocks/head/context/sc_rollup/[SC_ROLLUP_HASH]/boot_sector' +"10 10 10 + +" diff --git a/tezt/lib_tezos/RPC.ml b/tezt/lib_tezos/RPC.ml index 1a364cd9c6cb..38b6e092aa51 100644 --- a/tezt/lib_tezos/RPC.ml +++ b/tezt/lib_tezos/RPC.ml @@ -744,6 +744,11 @@ module Sc_rollup = struct ~sc_rollup_address client = let path = path ~chain ~block ~sc_rollup_address @ ["initial_level"] in Client.rpc ?endpoint ?hooks GET path client + + let get_boot_sector ?endpoint ?hooks ?(chain = "main") ?(block = "head") + ~sc_rollup_address client = + let path = path ~chain ~block ~sc_rollup_address @ ["boot_sector"] in + Client.rpc ?endpoint ?hooks GET path client end let raw_bytes ?endpoint ?hooks ?(chain = "main") ?(block = "head") ?(path = []) diff --git a/tezt/lib_tezos/RPC.mli b/tezt/lib_tezos/RPC.mli index 7413f6f52d17..8f2b87e2192a 100644 --- a/tezt/lib_tezos/RPC.mli +++ b/tezt/lib_tezos/RPC.mli @@ -1022,6 +1022,16 @@ module Sc_rollup : sig sc_rollup_address:string -> Client.t -> JSON.t Lwt.t + + (** Call RPC /chain/[chain]/blocks/[block]/context/sc_rollup/[rollup_hash]/boot_sector *) + val get_boot_sector : + ?endpoint:Client.endpoint -> + ?hooks:Process.hooks -> + ?chain:string -> + ?block:string -> + sc_rollup_address:string -> + Client.t -> + JSON.t Lwt.t end val raw_bytes : diff --git a/tezt/tests/sc_rollup.ml b/tezt/tests/sc_rollup.ml index de93a3eaa90b..5ecdf81a2685 100644 --- a/tezt/tests/sc_rollup.ml +++ b/tezt/tests/sc_rollup.ml @@ -101,19 +101,7 @@ let with_fresh_rollup f tezos_node tezos_client bootstrap1_key = let* () = Client.bake_for tezos_client in f rollup_address sc_rollup_node configuration_filename -let with_fresh_rollups n f node client bootstrap1 = - let rec go n addrs k = - if n < 1 then k addrs - else - with_fresh_rollup - (fun addr _ _ -> go (n - 1) (String_set.add addr addrs) k) - node - client - bootstrap1 - in - go n String_set.empty f - -(* TODO: create and insert issue number. Many tests +(* TODO: create and insert issue number. Many tests can be refactored using test_scenario.*) let test_scenario {output_file_prefix; variant; tags; description} scenario = let output_file _ = output_file_prefix ^ "_" ^ variant in @@ -177,6 +165,37 @@ let test_origination = A rollup node has a configuration file that must be initialized. *) +let with_fresh_rollup ?(boot_sector = "") f tezos_node tezos_client + bootstrap1_key = + let* rollup_address = + Client.Sc_rollup.originate + ~hooks + ~burn_cap:Tez.(of_int 9999999) + ~src:bootstrap1_key + ~kind:"arith" + ~boot_sector + tezos_client + in + let sc_rollup_node = + Sc_rollup_node.create tezos_node tezos_client ~operator_pkh:bootstrap1_key + in + let* configuration_filename = + Sc_rollup_node.config_init sc_rollup_node rollup_address + in + let* () = Client.bake_for tezos_client in + f rollup_address sc_rollup_node configuration_filename + +let with_fresh_rollups n f node client bootstrap1 = + let rec go n addrs k = + if n < 1 then k addrs + else + with_fresh_rollup + (fun addr _ _ -> go (n - 1) (String_set.add addr addrs) k) + node + client + bootstrap1 + in + go n String_set.empty f let test_rollup_node_configuration = let output_file _ = "sc_rollup_node_configuration" in @@ -833,11 +852,11 @@ let test_rollup_node_advances_pvm_state = (* Ensure that commitments are stored and published properly. ---------------------------------------------------------- - Every 20 level, a commitment is computed and stored by the - rollup node. The rollup node will also publish previously - computed commitments on the layer1, in a first in first out - fashion. To ensure that commitments are robust to chain - reorganisations, only finalized block are processed when + Every 20 level, a commitment is computed and stored by the + rollup node. The rollup node will also publish previously + computed commitments on the layer1, in a first in first out + fashion. To ensure that commitments are robust to chain + reorganisations, only finalized block are processed when trying to publish a commitment. *) @@ -1186,6 +1205,93 @@ let commitments_reorgs protocol sc_rollup_node sc_rollup_address node client = Option.map (fun c2 -> (c1, c2)) stored_commitment) ; Lwt.return_unit +(* Check that the SC rollup is correctly originated with a boot sector. + ------------------------------------------------------- + + Originate a rollup with a custom boot sector and check if the RPC returns it. + +*) +let test_rollup_origination_boot_sector = + let boot_sector = "10 10 10 + +" in + + let go client sc_rollup_address = + let* client_boot_sector = + RPC.Sc_rollup.get_boot_sector ~hooks ~sc_rollup_address client + in + let client_boot_sector = JSON.as_string client_boot_sector in + Check.(boot_sector = client_boot_sector) + Check.string + ~error_msg:"expected value %L, got %R" ; + Lwt.return_unit + in + + let output_file _ = "sc_rollup_origination_bootsector" in + test + ~__FILE__ + ~output_file + ~tags:["run"] + "originate with boot sector" + (fun protocol -> + setup ~protocol @@ fun node client -> + with_fresh_rollup + ~boot_sector + (fun sc_rollup_address _sc_rollup_node _filename -> + go client sc_rollup_address) + node + client) + +(* Check that a node makes use of the boot sector. + ------------------------------------------------------- + + Originate 2 rollups with different boot sectors to check if the are + actually different. + +*) +let test_rollup_node_uses_boot_sector = + let go_boot client sc_rollup_address sc_rollup_node = + let* init_level = + RPC.Sc_rollup.get_initial_level ~hooks ~sc_rollup_address client + in + let init_level = init_level |> JSON.as_int in + + let* () = Sc_rollup_node.run sc_rollup_node in + + let sc_rollup_client = Sc_rollup_client.create sc_rollup_node in + let* level = Sc_rollup_node.wait_for_level sc_rollup_node init_level in + + let* () = send_text_messages client sc_rollup_address ["10 +"] in + let* _ = Sc_rollup_node.wait_for_level sc_rollup_node (level + 1) in + + Sc_rollup_client.state_hash ~hooks sc_rollup_client + in + + let with_booted ~boot_sector node client = + with_fresh_rollup + ~boot_sector + (fun sc_rollup_address sc_rollup_node _filename -> + go_boot client sc_rollup_address sc_rollup_node) + node + client + in + + let output_file _ = "sc_rollup_node_uses_boot_sector" in + test + ~__FILE__ + ~output_file + ~tags:["run"; "node"] + "ensure boot sector is used" + (fun protocol -> + setup ~protocol @@ fun node client x -> + let* state_hash1 = + with_booted ~boot_sector:"10 10 10 + +" node client x + in + let* state_hash2 = with_booted ~boot_sector:"31" node client x in + Check.(state_hash1 <> state_hash2) + Check.string + ~error_msg:"State hashes should be different! (%L, %R)" ; + + Lwt.return_unit) + let register ~protocols = test_origination protocols ; test_rollup_node_configuration protocols ; @@ -1212,4 +1318,6 @@ let register ~protocols = commitment_not_stored_if_non_final protocols ; test_commitment_scenario "messages_reset" commitments_messages_reset protocols ; - test_commitment_scenario "handles_chain_reorgs" commitments_reorgs protocols + test_commitment_scenario "handles_chain_reorgs" commitments_reorgs protocols ; + test_rollup_origination_boot_sector protocols ; + test_rollup_node_uses_boot_sector protocols -- GitLab