From bf2a685ba9f94f6ee19f1573492fab1664c332d6 Mon Sep 17 00:00:00 2001 From: Victor Allombert Date: Fri, 24 Feb 2023 09:22:45 +0100 Subject: [PATCH] Store: improve v3_0_0 upgrade error --- src/lib_shell_services/store_errors.ml | 16 ++++++++++++++++ src/lib_store/unix/store.ml | 5 +++++ 2 files changed, 21 insertions(+) diff --git a/src/lib_shell_services/store_errors.ml b/src/lib_shell_services/store_errors.ml index 86fb7614076b..f77f0d727a47 100644 --- a/src/lib_shell_services/store_errors.ml +++ b/src/lib_shell_services/store_errors.ml @@ -1299,6 +1299,7 @@ let () = (* Storage upgrade errors *) type error += + | Cannot_find_chain_dir of string | V_3_0_upgrade_missing_floating_block of { block_hash : Block_hash.t; block_level : Int32.t; @@ -1306,6 +1307,21 @@ type error += } let () = + Error_monad.register_error_kind + `Permanent + ~id:"store.cannot_find_chain_dir" + ~title:"Cannot find chain dir" + ~description:"Cannot find chain dir while upgrading storage" + ~pp:(fun ppf path -> + Format.fprintf + ppf + "Failed to upgrade the storage. The chain directory %s cannot be \ + found. Make sure that the data directory contains data of the \ + expected network." + path) + Data_encoding.(obj1 (req "path" string)) + (function Cannot_find_chain_dir p -> Some p | _ -> None) + (fun p -> Cannot_find_chain_dir p) ; register_error_kind `Permanent ~id:"block_store.v_3_0_upgrade_missing_floating_block" diff --git a/src/lib_store/unix/store.ml b/src/lib_store/unix/store.ml index 197e06286805..008ca4364b82 100644 --- a/src/lib_store/unix/store.ml +++ b/src/lib_store/unix/store.ml @@ -2985,6 +2985,11 @@ let v_3_0_upgrade ~store_dir genesis = let*! () = List.iter_s (fun f -> f ()) !cleanups in Lwt.return_error err) (fun () -> + let* () = + let chain_dir_path = Naming.dir_path chain_dir in + let*! chain_dir_exists = Lwt_unix.file_exists chain_dir_path in + fail_unless chain_dir_exists (Cannot_find_chain_dir chain_dir_path) + in let* () = upgrade_protocol_levels ~chain_dir ~cleanups ~finalizers in let* () = Block_store.v_3_0_upgrade chain_dir ~cleanups ~finalizers in let*! () = List.iter_s (fun f -> f ()) !finalizers in -- GitLab