From 587e857ee09e468b8981c27041ff60b249311d2b Mon Sep 17 00:00:00 2001 From: vbot Date: Fri, 15 Sep 2023 14:35:40 +0200 Subject: [PATCH 1/4] Snapshot/Version: bump snapshot version to 6 --- src/lib_store/unix/snapshots.ml | 45 ++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/src/lib_store/unix/snapshots.ml b/src/lib_store/unix/snapshots.ml index e36eb081934c..eb7b64c9d96c 100644 --- a/src/lib_store/unix/snapshots.ml +++ b/src/lib_store/unix/snapshots.ml @@ -607,32 +607,37 @@ module Version = struct * - 1: snapshot exported with storage 0.0.1 to 0.0.4 * - 2: snapshot exported with storage 0.0.4 to 0.0.6 * - 3: snapshot exported with storage 0.0.7 - * - 4: snapshot exported with storage 0.0.8 to current + * - 4: snapshot exported with storage 0.0.8 * - 5: snapshot exported with new protocol tables and "à la GC" - context (storage 2.0 to current)*) + context (storage 2.0) + * - 6: new context representation introduced by irmin 3.7.2 + *) + (* Used for old snapshot format versions *) let legacy_version = 4 - let current_version = 5 + let current_version = 6 (* List of versions that are supported *) let supported_versions = - [(legacy_version, `Legacy); (current_version, `Current)] + [ + (legacy_version, `Legacy_format); (5, `Legacy); (current_version, `Current); + ] let is_supported version = match List.assq_opt version supported_versions with | Some _ -> true | None -> false - (* Returns true if the given version is considered as legacy. *) - let is_legacy version = + (* Returns true if the given version uses a legacy data format. *) + let is_legacy_format version = let open Lwt_result_syntax in match List.assq_opt version supported_versions with | None -> tzfail (Inconsistent_version_import {expected = List.map fst supported_versions; got = version}) - | Some `Legacy -> return_true + | Some `Legacy_format -> return_true | Some _ -> return_false end @@ -2919,8 +2924,8 @@ module Raw_loader : LOADER = struct let load_snapshot_header t = let open Lwt_result_syntax in let* version = load_snapshot_version t in - let* is_legacy = Version.is_legacy version in - if is_legacy then + let* is_legacy_format = Version.is_legacy_format version in + if is_legacy_format then let* legacy_metadata = load_snapshot_legacy_metadata t in return (Snapshot_header.Legacy (version, legacy_metadata)) else @@ -3019,8 +3024,8 @@ module Tar_loader : LOADER = struct let load_snapshot_header t = let open Lwt_result_syntax in let* version = load_snapshot_version t in - let* is_legacy = Version.is_legacy version in - if is_legacy then + let* is_legacy_format = Version.is_legacy_format version in + if is_legacy_format then let* legacy_metadata = load_snapshot_legacy_metadata t in return (Snapshot_header.Legacy (version, legacy_metadata)) else @@ -3160,9 +3165,9 @@ module Raw_importer : IMPORTER = struct match Data_encoding.Binary.of_string_opt block_data_encoding block_data with | Some block_data -> return block_data | None -> ( - let* is_legacy = Version.is_legacy t.version in + let* is_legacy_format = Version.is_legacy_format t.version in let* res = - if is_legacy then + if is_legacy_format then Data_encoding.Binary.of_string_opt legacy_block_data_encoding block_data @@ -3251,8 +3256,8 @@ module Raw_importer : IMPORTER = struct in let*! table_bytes = Lwt_utils_unix.read_file protocol_tbl_filename in let* res = - let* is_legacy = Version.is_legacy t.version in - if is_legacy then + let* is_legacy_format = Version.is_legacy_format t.version in + if is_legacy_format then (* Use the legacy encoding *) match Data_encoding.Binary.of_string_opt @@ -3518,9 +3523,9 @@ module Tar_importer : IMPORTER = struct let*! o = Onthefly.load_from_filename t.tar ~filename in match o with | Some str -> ( - let* is_legacy = Version.is_legacy t.version in + let* is_legacy_format = Version.is_legacy_format t.version in let* res = - if is_legacy then + if is_legacy_format then Data_encoding.Binary.of_string_opt legacy_block_data_encoding str |> Option.map (fun @@ -3600,8 +3605,8 @@ module Tar_importer : IMPORTER = struct match o with | Some str -> ( let* res = - let* is_legacy = Version.is_legacy t.version in - if is_legacy then + let* is_legacy_format = Version.is_legacy_format t.version in + if is_legacy_format then (* Use the legacy encoding *) match Data_encoding.Binary.of_string_opt @@ -4298,7 +4303,7 @@ module Make_snapshot_importer (Importer : IMPORTER) : Snapshot_importer = struct let* protocol_levels = restore_protocols snapshot_importer progress_display_mode in - let* legacy = Version.is_legacy snapshot_version in + let* legacy = Version.is_legacy_format snapshot_version in (* Restore context *) let* block_data, genesis_context_hash, block_validation_result = restore_and_apply_context -- GitLab From e958241a63eea755fe7032705451b899586f8ca8 Mon Sep 17 00:00:00 2001 From: vbot Date: Fri, 15 Sep 2023 14:41:52 +0200 Subject: [PATCH 2/4] Snapshot/UX: improve snapshot errors UX --- src/lib_store/unix/snapshots.ml | 39 ++++++++++++-------------------- src/lib_store/unix/snapshots.mli | 1 - 2 files changed, 14 insertions(+), 26 deletions(-) diff --git a/src/lib_store/unix/snapshots.ml b/src/lib_store/unix/snapshots.ml index eb7b64c9d96c..1f564852a816 100644 --- a/src/lib_store/unix/snapshots.ml +++ b/src/lib_store/unix/snapshots.ml @@ -88,7 +88,6 @@ type error += stored : History_mode.t; } | Inconsistent_imported_block of Block_hash.t * Block_hash.t - | Wrong_snapshot_file of {filename : string} | Invalid_chain_store_export of Chain_id.t * string | Cannot_export_snapshot_format @@ -543,20 +542,6 @@ let () = (function | Inconsistent_imported_block (got, exp) -> Some (got, exp) | _ -> None) (fun (got, exp) -> Inconsistent_imported_block (got, exp)) ; - register_error_kind - `Permanent - ~id:"Snapshot.wrong_snapshot_file" - ~title:"Wrong snapshot file" - ~description:"Error while opening snapshot file" - ~pp:(fun ppf filename -> - Format.fprintf - ppf - "Failed to read snapshot file %s. The provided file is inconsistent or \ - is from Octez 12 (or before) and it cannot be imported anymore." - filename) - Data_encoding.(obj1 (req "filename" string)) - (function Wrong_snapshot_file {filename} -> Some filename | _ -> None) - (fun filename -> Wrong_snapshot_file {filename}) ; register_error_kind `Permanent ~id:"Snapshot.invalid_chain_store_export" @@ -1376,7 +1361,12 @@ end = struct let files = None in Lwt.return {current_pos = 0L; data_pos; fd; files} - let close_in t = Lwt_unix.close t.fd + let close_in t = + Lwt.catch + (fun () -> Lwt_unix.close t.fd) + (function + | Unix.(Unix_error (EBADF, _, _)) -> Lwt.return_unit + | exn -> Lwt.fail exn) (*[list_files tar] returns the list of files contained in the [tar]. *) @@ -3052,15 +3042,14 @@ module Make_snapshot_loader (Loader : LOADER) : Snapshot_loader = struct let load_snapshot_header ~snapshot_path = let open Lwt_syntax in let* loader = load snapshot_path in - trace (Wrong_snapshot_file {filename = snapshot_path}) - @@ protect - (fun () -> - Lwt.finalize - (fun () -> Loader.load_snapshot_header loader) - (fun () -> close loader)) - ~on_error:(fun err -> - let* () = close loader in - Lwt.return_error err) + protect + (fun () -> + Lwt.finalize + (fun () -> Loader.load_snapshot_header loader) + (fun () -> close loader)) + ~on_error:(fun err -> + let* () = close loader in + Lwt.return_error err) end module type IMPORTER = sig diff --git a/src/lib_store/unix/snapshots.mli b/src/lib_store/unix/snapshots.mli index 7579bb4cbabd..0fe04faf0a8b 100644 --- a/src/lib_store/unix/snapshots.mli +++ b/src/lib_store/unix/snapshots.mli @@ -137,7 +137,6 @@ type error += got : Distributed_db_version.Name.t; } | Inconsistent_imported_block of Block_hash.t * Block_hash.t - | Wrong_snapshot_file of {filename : string} type snapshot_format = Tar | Raw -- GitLab From db3cc81e6ddcd09540e158e95022e9ae4e7c855e Mon Sep 17 00:00:00 2001 From: vbot Date: Fri, 15 Sep 2023 17:38:42 +0200 Subject: [PATCH 3/4] Tests: adapt checks to current snapshot version --- tezt/tests/storage_snapshots.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tezt/tests/storage_snapshots.ml b/tezt/tests/storage_snapshots.ml index b3062debbb0a..cf4953f4d437 100644 --- a/tezt/tests/storage_snapshots.ml +++ b/tezt/tests/storage_snapshots.ml @@ -451,7 +451,7 @@ let test_info_command = in let expected_hash = JSON.(head |-> "hash" |> as_string) in let expected_level = head_level in - let expected_version = 5 in + let expected_version = 6 in Log.info "Checks the human formatted output" ; (* Get the info line, which is the second line. *) let* () = -- GitLab From ed3e9af165181730bda86a6e17fc5996cdeb285b Mon Sep 17 00:00:00 2001 From: vbot Date: Fri, 15 Sep 2023 15:18:21 +0200 Subject: [PATCH 4/4] Changelog: add entry --- CHANGES.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index 64fe4b19584e..07558212c4d0 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -234,6 +234,11 @@ Node - Operations posting invalid WASM proofs are now discarded earlier by the Nairobi mempool plugin. (MR :gl:`!`) +- **Breaking change** Bumped the Octez snapshot version from ``5`` to + ``6`` to explicit the incompatibility with previous version + nodes. Also, improved the consistency of ``snapshot`` import errors + messages (MR :gl:`!10138`) + Client ------ - Adding client commands to generate, open and verify a time-lock. -- GitLab