diff --git a/src/lib_shell_services/store_errors.ml b/src/lib_shell_services/store_errors.ml index f1fc6538f3553b21efd69b994e067590555c1b81..86fb7614076bcd66f3755e49582438999c086ed4 100644 --- a/src/lib_shell_services/store_errors.ml +++ b/src/lib_shell_services/store_errors.ml @@ -1296,3 +1296,40 @@ let () = Data_encoding.(obj1 (req "kind" corruption_kind_encoding)) (function Corrupted_store k -> Some k | _ -> None) (fun k -> Corrupted_store k) + +(* Storage upgrade errors *) +type error += + | V_3_0_upgrade_missing_floating_block of { + block_hash : Block_hash.t; + block_level : Int32.t; + floating_kind : string; + } + +let () = + register_error_kind + `Permanent + ~id:"block_store.v_3_0_upgrade_missing_floating_block" + ~title:"V.3.0 upgrade missing floating block" + ~description:"Failed to upgrade the floating store" + ~pp:(fun ppf (block_hash, block_level, floating_kind) -> + Format.fprintf + ppf + "Failed to upgrade block %a (level %ld) for %s floating store: block \ + not found in the index." + Block_hash.pp + block_hash + block_level + floating_kind) + Data_encoding.( + obj3 + (req "block_hash" Block_hash.encoding) + (req "block_level" int32) + (req "floating_kind" string)) + (function + | V_3_0_upgrade_missing_floating_block + {block_hash; block_level; floating_kind} -> + Some (block_hash, block_level, floating_kind) + | _ -> None) + (fun (block_hash, block_level, floating_kind) -> + V_3_0_upgrade_missing_floating_block + {block_hash; block_level; floating_kind}) diff --git a/src/lib_store/unix/block_store.ml b/src/lib_store/unix/block_store.ml index bc93155a325d4dd0ed95f4522fe10c2c336897f6..8ce88e3cebf6bd49fffe0fdc9fd543c32e864b99 100644 --- a/src/lib_store/unix/block_store.ml +++ b/src/lib_store/unix/block_store.ml @@ -1739,11 +1739,31 @@ let v_3_0_upgrade chain_dir ~cleanups ~finalizers = (fun (block_b, _len) -> let block_hash = Block_repr_unix.raw_get_block_hash block_b in let block_context = Block_repr_unix.raw_get_context block_b in - let { - Floating_block_index.Legacy.Legacy_block_info.offset; - predecessors; - } = - Floating_block_index.Legacy.find legacy_index block_hash + let* { + Floating_block_index.Legacy.Legacy_block_info.offset; + predecessors; + } = + try + return + @@ Floating_block_index.Legacy.find legacy_index block_hash + with + | Not_found -> + let block_level = + Block_repr_unix.raw_get_block_level block_b + in + let floating_kind = + (function + | Naming.RO -> "RO" + | RW -> "RW" + | RO_TMP -> "RO_TMP" + | RW_TMP -> "RW_TMP" + | Restore _ -> "Restored") + kind + in + tzfail + (V_3_0_upgrade_missing_floating_block + {block_hash; block_level; floating_kind}) + | e -> raise e in let resulting_context_hash = block_context in let new_value =