diff --git a/etherlink/CHANGES_NODE.md b/etherlink/CHANGES_NODE.md index 6980d837576464dd7d106dec65717444e41ac2d4..07ef79498bd5be0a60b5253104f81df4878547e9 100644 --- a/etherlink/CHANGES_NODE.md +++ b/etherlink/CHANGES_NODE.md @@ -81,6 +81,8 @@ estimation of DA fees no longer require to run the kernel. (!14165) - Add a private RPC method to by-pass node validation when injecting a transaction to the TX pool. (!13856). +- Add a debug command to print the SQLite schemas currently is use by the node. + (!14509) ## Version for ec7c3b349624896b269e179384d0a45cf39e1145 diff --git a/etherlink/bin_node/lib_dev/evm_store.ml b/etherlink/bin_node/lib_dev/evm_store.ml index 1ffe16096eb45a635453c6037a2d4ff81df0d27a..254bfd874a7edc5a72f39312853854dd94acff83 100644 --- a/etherlink/bin_node/lib_dev/evm_store.ml +++ b/etherlink/bin_node/lib_dev/evm_store.ml @@ -200,6 +200,13 @@ module Q = struct let vacuum_request = (string ->. unit) @@ {|VACUUM main INTO ?|} + module Schemas = struct + let get_all = + (unit ->* string) + @@ {|SELECT sql FROM sqlite_schema WHERE name + NOT LIKE 'sqlite_%' AND name != 'migrations'|} + end + module Migrations = struct let create_table = (unit ->. unit) @@ -225,7 +232,14 @@ module Q = struct (with leading 0s) followed by the name of the migration (e.g. [005_create_blueprints_table.sql]) - Run [etherlink/scripts/check_evm_store_migrations.sh promote] + - Regenerate the schemas, using [[ + dune exec -- etherlink/tezt/tests/main.exe --file evm_sequencer.ml \ + evm store schemas regression --reset-regressions + ]] - Increment [version] + + You can review the result at + [etherlink/tezt/tests/expected/evm_sequencer.ml/EVM Node- debug print store schemas.out]. *) let version = 9 @@ -408,6 +422,12 @@ module Journal_mode = struct return_unit end +module Schemas = struct + let get_all store = + with_connection store @@ fun conn -> + Db.collect_list conn Q.Schemas.get_all () +end + module Migrations = struct let create_table store = with_connection store @@ fun conn -> diff --git a/etherlink/bin_node/lib_dev/evm_store.mli b/etherlink/bin_node/lib_dev/evm_store.mli index 71a031cfd4da9001d097a97c89e805edb376eda3..e6d00cbf18cbc5dfbf40e02fc68573e425459d20 100644 --- a/etherlink/bin_node/lib_dev/evm_store.mli +++ b/etherlink/bin_node/lib_dev/evm_store.mli @@ -45,6 +45,12 @@ val with_transaction : conn -> (conn -> 'a tzresult Lwt.t) -> 'a tzresult Lwt.t @raise Assert_failure *) val assert_in_transaction : conn -> unit +module Schemas : sig + (** [get_all conn] returns the list of SQL statements allowing to recreate + the tables in the current store. *) + val get_all : conn -> string list tzresult Lwt.t +end + module Blueprints : sig val store : conn -> Blueprint_types.t -> unit tzresult Lwt.t diff --git a/etherlink/bin_node/main.ml b/etherlink/bin_node/main.ml index 1638bce0148807886f933f646b021ccd9f8919aa..4d3193573421aeaba87a85fcff51f8ded147faad 100644 --- a/etherlink/bin_node/main.ml +++ b/etherlink/bin_node/main.ml @@ -2460,6 +2460,22 @@ let preemptive_kernel_download_command = ~preimages_endpoint ~root_hash) +let debug_print_store_schemas_command = + let open Tezos_clic in + command + ~desc:"Print SQL statements describing the tables created in the store" + no_options + (prefixes ["debug"; "print"; "store"; "schemas"] @@ stop) + (fun () () -> + let open Lwt_result_syntax in + let open Evm_node_lib_dev in + Lwt_utils_unix.with_tempdir "store" @@ fun data_dir -> + let* store = Evm_store.init ~data_dir ~perm:`Read_write () in + let* schemas = Evm_store.(use store Schemas.get_all) in + let output = String.concat ";\n\n" schemas in + Format.printf "%s\n" output ; + return_unit) + (* List of program commands *) let commands = [ @@ -2486,6 +2502,7 @@ let commands = export_snapshot_named_command; patch_state_command; preemptive_kernel_download_command; + debug_print_store_schemas_command; ] let global_options = Tezos_clic.no_options diff --git a/etherlink/tezt/lib/evm_node.ml b/etherlink/tezt/lib/evm_node.ml index 565d10a3fff3e5a47b2491685e98409fd2e149da..513cbd714a0c8f2fb8ce838e95954fa9da800b9b 100644 --- a/etherlink/tezt/lib/evm_node.ml +++ b/etherlink/tezt/lib/evm_node.ml @@ -1065,6 +1065,12 @@ let sequencer_upgrade_payload ?client ~public_key ~pool_address let* payload = Process.check_and_read_stdout process in return (String.trim payload) +let debug_print_store_schemas ?(path = Uses.path Constant.octez_evm_node) ?hooks + () = + let args = ["debug"; "print"; "store"; "schemas"] in + let process = Process.spawn ?hooks path @@ args in + Process.check process + let chunk_data ~rollup_address ?sequencer_key ?timestamp ?parent_hash ?number ?client data = let args = "chunk" :: "data" :: data in diff --git a/etherlink/tezt/lib/evm_node.mli b/etherlink/tezt/lib/evm_node.mli index 0136a64806ecf6d4f162cb8b55d17bcf9c736122..4d139cde13f17f3693486fa8fab63a9f913303c9 100644 --- a/etherlink/tezt/lib/evm_node.mli +++ b/etherlink/tezt/lib/evm_node.mli @@ -438,6 +438,9 @@ val make_kernel_installer_config : unit -> (Process.t, unit) Runnable.t +val debug_print_store_schemas : + ?path:string -> ?hooks:Process_hooks.t -> unit -> unit Lwt.t + module Agent : sig val create : ?path:string -> diff --git a/etherlink/tezt/tests/evm_sequencer.ml b/etherlink/tezt/tests/evm_sequencer.ml index 18ce299c5b427c3b45e058e80e7817518d29b442..d45a908594fe50f324f9c2c1f0934e5a26a24709 100644 --- a/etherlink/tezt/tests/evm_sequencer.ml +++ b/etherlink/tezt/tests/evm_sequencer.ml @@ -5997,6 +5997,19 @@ let test_batch_limit_size_rpc = unit +let test_debug_print_store_schemas () = + Regression.register + ~__FILE__ + ~title:"EVM Node: debug print store schemas" + ~tags:["evm"; "store"; "schemas"] + ~uses:[Constant.octez_evm_node] + ~uses_node:false + ~uses_client:false + ~uses_admin_client:false + @@ fun () -> + let hooks = Tezos_regression.hooks in + Evm_node.debug_print_store_schemas ~hooks () + let test_relay_restricted_rpcs = register_all ~bootstrap_accounts:Eth_account.lots_of_address @@ -6099,4 +6112,5 @@ let () = test_trace_transaction_calltracer_all_types protocols ; test_trace_transaction_call_tracer_with_logs protocols ; test_trace_transaction_call_trace_certain_depth protocols ; - test_trace_transaction_call_trace_revert protocols + test_trace_transaction_call_trace_revert protocols ; + test_debug_print_store_schemas () diff --git a/etherlink/tezt/tests/expected/evm_sequencer.ml/EVM Node- debug print store schemas.out b/etherlink/tezt/tests/expected/evm_sequencer.ml/EVM Node- debug print store schemas.out new file mode 100644 index 0000000000000000000000000000000000000000..d74c16de3cd8b22a4fe4d13423adadfaccd4a87e --- /dev/null +++ b/etherlink/tezt/tests/expected/evm_sequencer.ml/EVM Node- debug print store schemas.out @@ -0,0 +1,39 @@ + +./octez-evm-node debug print store schemas +CREATE TABLE context_hashes ( + id SERIAL PRIMARY KEY, + context_hash VARCHAR(52) NOT NULL +); + +CREATE TABLE kernel_upgrades ( + injected_before INT NOT NULL, + root_hash TEXT NOT NULL, + activation_timestamp INT NOT NULL, + applied_before INT +); + +CREATE TABLE blueprints ( + id SERIAL PRIMARY KEY, + payload BLOB NOT NULL, + timestamp DATETIME NOT NULL +); + +CREATE TABLE delayed_transactions ( + injected_before INT NOT NULL, + hash TEXT NOT NULL, + payload TEXT NOT NULL +); + +CREATE TABLE "l1_l2_levels_relationships" ( + latest_l2_level PRIMARY KEY ON CONFLICT REPLACE, + l1_level INT NOT NULL UNIQUE ON CONFLICT ABORT +, finalized_l2_level INT DEFAULT 0); + +CREATE TABLE metadata ( + smart_rollup_address TEXT NOT NULL +); + +CREATE UNIQUE INDEX unapplied_upgrade +ON kernel_upgrades ( + COALESCE(applied_before, -1) +)