diff --git a/src/lib_shell/block_validator.ml b/src/lib_shell/block_validator.ml index 23734b2829e6a74115546fb96ac6dcc33f8dda7a..5d9fe9ededdb03651c3f214a6eb8fb8f9367a8d1 100644 --- a/src/lib_shell/block_validator.ml +++ b/src/lib_shell/block_validator.ml @@ -470,20 +470,24 @@ let on_error (type a b) (_w : t) st (r : (a, b) Request.t) (errs : b) = (* Keep the worker alive. *) return_ok_unit -let errors_contains_inode_error errors = - let rex = Re.compile (Re.Perl.re "unknown inode key") in - let is_inode_error = function - | Exn (Failure s) -> ( - match Re.exec rex s with _ -> true | exception Not_found -> false) - | _ -> false +let errors_contains_context_error errors = + let rex = + (* Matching all the candidate to a context error: + - "[Ir]min|[Bb]rassaia": for any error from irmin or brassaia components + - "unknown inode key": to catch the so called inode error *) + Re.compile (Re.Perl.re "[Ii]rmin|[Bb]rassaia|unknown inode key") in - List.exists is_inode_error errors + let is_context_error error = + let error_s = Format.asprintf "%a" Error_monad.pp error in + match Re.exec rex error_s with exception Not_found -> false | _ -> true + in + List.exists is_context_error errors -(* This failsafe aims to look for an irmin error that is known to be +(* This failsafe aims to look for a context error that is known to be critical and, if found, stop the node gracefully. *) -let check_and_quit_on_irmin_errors errors = +let check_and_quit_on_context_errors errors = let open Lwt_syntax in - if errors_contains_inode_error errors then + if errors_contains_context_error errors then let* () = Events.(emit stopping_node_missing_context_key ()) in let* _ = Lwt_exit.exit_and_wait 1 in return_unit @@ -521,7 +525,7 @@ let on_completion : match Request.view request with | Preapplication v -> let* () = Events.(emit preapplication_failure) (v.level, st, errs) in - let* () = check_and_quit_on_irmin_errors errs in + let* () = check_and_quit_on_context_errors errs in return_unit | Validation _ -> (* assert false *) Lwt.return_unit) | Request.Request_validation _, Application_error_after_validation errs -> ( @@ -539,7 +543,7 @@ let on_completion : Events.(emit application_failure_after_validation) (v.block, st, errs) in - let* () = check_and_quit_on_irmin_errors errs in + let* () = check_and_quit_on_context_errors errs in return_unit) | Preapplication _ -> (* assert false *) Lwt.return_unit) | Request.Request_validation _, Validation_failed errs -> ( @@ -553,7 +557,7 @@ let on_completion : Events.(emit validation_canceled) (v.block, st) | errs -> let* () = Events.(emit validation_failure) (v.block, st, errs) in - let* () = check_and_quit_on_irmin_errors errs in + let* () = check_and_quit_on_context_errors errs in return_unit) | Preapplication _ -> (* assert false *) Lwt.return_unit) | Request.Request_validation _, Commit_block_failed errs -> ( @@ -569,7 +573,7 @@ let on_completion : let* () = Events.(emit commit_block_failure) (v.block, st, errs) in - let* () = check_and_quit_on_irmin_errors errs in + let* () = check_and_quit_on_context_errors errs in return_unit) | Preapplication _ -> (* assert false *) Lwt.return_unit) | Request.Request_validation _, (Preapplied _ | Preapplication_error _) diff --git a/src/lib_shell/block_validator.mli b/src/lib_shell/block_validator.mli index 962cd64b652878370b3e218fc3a24bb65e31a895..1258745e34cfedf3853d60b71944c72739df0c62 100644 --- a/src/lib_shell/block_validator.mli +++ b/src/lib_shell/block_validator.mli @@ -180,6 +180,5 @@ val current_request : (Time.System.t * Time.System.t * Block_validator_worker_state.Request.view) option -(** Checks if the errors contains the infamous 'unknown inode key' context - error to mitigate it. *) -val errors_contains_inode_error : error list -> bool +(** Checks if the errors contains context error to mitigate it. *) +val errors_contains_context_error : error list -> bool diff --git a/src/lib_shell/bootstrap_pipeline.ml b/src/lib_shell/bootstrap_pipeline.ml index 43c86c7a42b4478ac2586b7335f4bdf92bdca5cb..9c738feb843d30eeb537944f006db4fa83bd904c 100644 --- a/src/lib_shell/bootstrap_pipeline.ml +++ b/src/lib_shell/bootstrap_pipeline.ml @@ -507,7 +507,7 @@ let rec validation_worker_loop pipeline = | Inapplicable_after_validation errs -> if retry_on_context_error - && Block_validator.errors_contains_inode_error errs + && Block_validator.errors_contains_context_error errs then (* This is a special case where the block is valid but inapplicable because of a context error. We retry the diff --git a/src/lib_shell/peer_validator.ml b/src/lib_shell/peer_validator.ml index a440869f9702169014804504286b68aee57e1f89..1cc70d7eb655400482943b1512efd9f5e4ffb1f2 100644 --- a/src/lib_shell/peer_validator.ml +++ b/src/lib_shell/peer_validator.ml @@ -208,7 +208,7 @@ let validate_new_head w hash (header : Block_header.t) = | Inapplicable_after_validation errs -> if retry_on_context_error - && Block_validator.errors_contains_inode_error errs + && Block_validator.errors_contains_context_error errs then (* This is a special case where the block is valid but inapplicable because of a context error. We retry the