From af857c4ab4044f1f46a3218f8cb4b0b9eab63611 Mon Sep 17 00:00:00 2001 From: Thomas Letan Date: Sat, 4 Jan 2025 21:11:39 +0100 Subject: [PATCH] EVM Node: Support downloading snapshots on import Now that we have the function to download a file, we can use it in the `snapshot import` command. This should improve the overall UX of the command. --- etherlink/CHANGES_NODE.md | 2 ++ etherlink/bin_node/main.ml | 32 ++++++++++++++++++- .../evm_sequencer.ml/EVM Node- man.out | 4 +-- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/etherlink/CHANGES_NODE.md b/etherlink/CHANGES_NODE.md index 2547c101c19f..8026402aebfb 100644 --- a/etherlink/CHANGES_NODE.md +++ b/etherlink/CHANGES_NODE.md @@ -20,6 +20,8 @@ - If both `--network` and `--init-from-snapshot` are set, the EVM node in observer mode will download and import a recent snapshot from a trusted source for fresh data directories. (!16093) +- The `snapshot import` command can now download a snapshot if provided with a + URL instead of a path. (!16112) #### Experimental diff --git a/etherlink/bin_node/main.ml b/etherlink/bin_node/main.ml index f7d38280ad19..03e4f130224c 100644 --- a/etherlink/bin_node/main.ml +++ b/etherlink/bin_node/main.ml @@ -147,6 +147,13 @@ module Params = struct ~desc:"Snapshot archive file" string next + + let snapshot_file_or_url next = + Tezos_clic.param + ~name:"snapshot" + ~desc:"Snapshot archive file or URL" + string + next end let wallet_dir_arg = @@ -2283,9 +2290,32 @@ let import_snapshot_command = ~doc: "Allow importing snapshot in already populated data dir (previous \ contents is removed first, even if the snapshot is corrupted)")) - (prefixes ["snapshot"; "import"] @@ Params.snapshot_file @@ stop) + (prefixes ["snapshot"; "import"] @@ Params.snapshot_file_or_url @@ stop) (fun (data_dir, force) snapshot_file () -> + let open Lwt_result_syntax in + let with_snapshot k = + if + String.starts_with ~prefix:"http://" snapshot_file + || String.starts_with ~prefix:"https://" snapshot_file + then + Lwt_utils_unix.with_tempdir ~temp_dir:data_dir ".download_" + @@ fun working_dir -> + let* snapshot_file = + Evm_node_lib_dev.Misc.download_file + ~keep_alive:false + ~working_dir + snapshot_file + in + k snapshot_file + else k snapshot_file + in + let*! () = + let open Tezos_base_unix.Internal_event_unix in + let config = make_with_defaults ~verbosity:Notice () in + init ~config () + in Evm_node_lib_dev.Data_dir.use ~data_dir @@ fun () -> + with_snapshot @@ fun snapshot_file -> Evm_node_lib_dev.Snapshots.import ~cancellable:true ~force diff --git a/etherlink/tezt/tests/expected/evm_sequencer.ml/EVM Node- man.out b/etherlink/tezt/tests/expected/evm_sequencer.ml/EVM Node- man.out index 761d0266c3e7..9727a90cf23f 100644 --- a/etherlink/tezt/tests/expected/evm_sequencer.ml/EVM Node- man.out +++ b/etherlink/tezt/tests/expected/evm_sequencer.ml/EVM Node- man.out @@ -29,9 +29,9 @@ Snapshots commands: --compress-on-the-fly: Produce a compressed snapshot on the fly. The rollup node will use less disk space to produce the snapshot but will lock the rollup node (if running) for a longer time. Without this option, producing a snaphsot requires the available disk space to be around the size of the data dir. --uncompressed: Produce an uncompressed snapshot. - snapshot import [--data-dir ] [-f --force] + snapshot import [--data-dir ] [-f --force] Import a snapshot of the EVM node. - : Snapshot archive file + : Snapshot archive file or URL --data-dir : The path to the EVM node data directory -f --force: Allow importing snapshot in already populated data dir (previous contents is removed first, even if the snapshot is corrupted) -- GitLab