diff --git a/src/lib_smart_rollup_node/rollup_node_errors.ml b/src/lib_smart_rollup_node/rollup_node_errors.ml index b2c24d61227b330b12752b4d2b2b8b4b9d6af1ab..61658ec927d9530012db0aa233c590dee3059d87 100644 --- a/src/lib_smart_rollup_node/rollup_node_errors.ml +++ b/src/lib_smart_rollup_node/rollup_node_errors.ml @@ -62,6 +62,10 @@ type error += | No_refutation_coordinator | Could_not_acquire_lock of string +type error += + | Could_not_open_preimage_file of String.t + | Could_not_encode_raw_data + type error += | Lost_game of lost_result | Unparsable_boot_sector of {path : string} @@ -353,4 +357,33 @@ let () = f) Data_encoding.(obj1 (req "lock_file" string)) (function Could_not_acquire_lock f -> Some f | _ -> None) - (fun f -> Could_not_acquire_lock f) + (fun f -> Could_not_acquire_lock f) ; + + register_error_kind + ~id:"sc_rollup.node.could_not_open_reveal_preimage_file" + ~title:"Could not open reveal preimage file" + ~description:"Could not open reveal preimage file." + ~pp:(fun ppf hash -> + Format.fprintf + ppf + "Could not open file containing preimage of reveal hash %s" + hash) + `Permanent + Data_encoding.(obj1 (req "hash" string)) + (function + | Could_not_open_preimage_file filename -> Some filename | _ -> None) + (fun filename -> Could_not_open_preimage_file filename) ; + + register_error_kind + ~id:"sc_rollup.node.could_not_encode_raw_data" + ~title:"Could not encode raw data to reveal" + ~description:"Could not encode raw data to reveal." + ~pp:(fun ppf () -> + Format.pp_print_string + ppf + "Could not encode raw data to reveal with the expected protocol \ + encoding") + `Permanent + Data_encoding.unit + (function Could_not_encode_raw_data -> Some () | _ -> None) + (fun () -> Could_not_encode_raw_data) diff --git a/src/proto_016_PtMumbai/lib_sc_rollup_node/daemon.ml b/src/proto_016_PtMumbai/lib_sc_rollup_node/daemon.ml index 03ee630ad4a43b61468b4372c47cde2568a6e6fa..f7bd8ddc57bf3347da36da3da1ac0637e92ccdf3 100644 --- a/src/proto_016_PtMumbai/lib_sc_rollup_node/daemon.ml +++ b/src/proto_016_PtMumbai/lib_sc_rollup_node/daemon.ml @@ -688,15 +688,46 @@ let run node_ctxt configuration ~mode:configuration.mode ~genesis_level:(Raw_level.to_int32 node_ctxt.genesis_info.level) ~pvm_kind:(Sc_rollup.Kind.to_string node_ctxt.kind) ; + let fatal_error_exit e = + Format.eprintf "%!%a@.Exiting.@." pp_print_trace e ; + let*! _ = Lwt_exit.exit_and_wait 1 in + return_unit + in + let error_to_degraded_mode e = + let*! () = Daemon_event.error e in + degraded_refutation_mode daemon_components node_ctxt + in + let handle_preimage_not_found e = + (* When running/initialising a rollup node with missing preimages + the rollup node enter in a degraded mode where actually there + isn't much that can be done with a non initialised rollup node, + hence it should exit after printing the error logs. + + A safe way to do this is to check if there was a processed head. + If not we can exit safely. If there was a processed head, we + go deeper and we check if the most recent commitment is actually + the genesis' one. If that's the case it means we're still on the + initialisation phase which means we can exit safely as well, if + not it means there is potential commitment(s) where refutation + can be played so we enter in degraded mode. *) + let* head = Node_context.last_processed_head_opt node_ctxt in + match head with + | Some head -> + if + Sc_rollup_block.most_recent_commitment head.header + = Sc_rollup_proto_types.Commitment_hash.to_octez + node_ctxt.genesis_info.commitment_hash + then fatal_error_exit e + else error_to_degraded_mode e + | None -> fatal_error_exit e + in protect start ~on_error:(function | Sc_rollup_node_errors.(Lost_game _ | Invalid_genesis_state _) :: _ as e -> - Format.eprintf "%!%a@.Exiting.@." pp_print_trace e ; - let*! _ = Lwt_exit.exit_and_wait 1 in - return_unit - | e -> - let*! () = Daemon_event.error e in - degraded_refutation_mode daemon_components node_ctxt) + fatal_error_exit e + | Sc_rollup_node_errors.Could_not_open_preimage_file _ :: _ as e -> + handle_preimage_not_found e + | e -> error_to_degraded_mode e) module Internal_for_tests = struct (** Same as {!process_head} but only builds and stores the L2 block diff --git a/src/proto_016_PtMumbai/lib_sc_rollup_node/reveals.ml b/src/proto_016_PtMumbai/lib_sc_rollup_node/reveals.ml index f96e79b238655b40b01b72bb46a52dc4199d31fc..b3aa7aaab6930e6ac57c89eb9624660e28fec76d 100644 --- a/src/proto_016_PtMumbai/lib_sc_rollup_node/reveals.ml +++ b/src/proto_016_PtMumbai/lib_sc_rollup_node/reveals.ml @@ -2,6 +2,7 @@ (* *) (* Open Source License *) (* Copyright (c) 2022 Nomadic Labs, *) +(* Copyright (c) 2023 Functori, *) (* *) (* Permission is hereby granted, free of charge, to any person obtaining a *) (* copy of this software and associated documentation files (the "Software"),*) @@ -26,10 +27,7 @@ open Protocol.Alpha_context module Reveal_hash = Protocol.Sc_rollup_reveal_hash -type error += - | Wrong_hash of {found : Reveal_hash.t; expected : Reveal_hash.t} - | Could_not_open_preimage_file of String.t - | Could_not_encode_raw_data +type error += Wrong_hash of {found : Reveal_hash.t; expected : Reveal_hash.t} let () = Sc_rollup_node_errors.register_error_kind @@ -51,34 +49,7 @@ let () = (req "expected" Reveal_hash.encoding)) (function | Wrong_hash {found; expected} -> Some (found, expected) | _ -> None) - (fun (found, expected) -> Wrong_hash {found; expected}) ; - Sc_rollup_node_errors.register_error_kind - ~id:"sc_rollup.node.could_not_open_reveal_preimage_file" - ~title:"Could not open reveal preimage file" - ~description:"Could not open reveal preimage file." - ~pp:(fun ppf hash -> - Format.fprintf - ppf - "Could not open file containing preimage of reveal hash %s" - hash) - `Permanent - Data_encoding.(obj1 (req "hash" string)) - (function - | Could_not_open_preimage_file filename -> Some filename | _ -> None) - (fun filename -> Could_not_open_preimage_file filename) ; - Sc_rollup_node_errors.register_error_kind - ~id:"sc_rollup.node.could_not_encode_raw_data" - ~title:"Could not encode raw data to reveal" - ~description:"Could not encode raw data to reveal." - ~pp:(fun ppf () -> - Format.pp_print_string - ppf - "Could not encode raw data to reveal with the expected protocol \ - encoding") - `Permanent - Data_encoding.unit - (function Could_not_encode_raw_data -> Some () | _ -> None) - (fun () -> Could_not_encode_raw_data) + (fun (found, expected) -> Wrong_hash {found; expected}) type source = String of string | File of string @@ -88,7 +59,8 @@ let file_contents filename = (fun () -> let*! contents = Lwt_utils_unix.read_file filename in return contents) - (fun _ -> tzfail @@ Could_not_open_preimage_file filename) + (fun _ -> + tzfail @@ Sc_rollup_node_errors.Could_not_open_preimage_file filename) let hash_to_hex hash = let (`Hex hash) = @@ -120,7 +92,7 @@ let get ~data_dir ~pvm_kind ~hash = let* _encoded = (* Check that the reveal input can be encoded within the bounds enforced by the protocol. *) - trace Could_not_encode_raw_data + trace Sc_rollup_node_errors.Could_not_encode_raw_data @@ protect @@ fun () -> Data_encoding.Binary.to_bytes_exn diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/daemon.ml b/src/proto_017_PtNairob/lib_sc_rollup_node/daemon.ml index 7a2dca4673b346a1550cdc6570c1452989f3223e..dc949dac91c4d6e186188f422d7828319674412d 100644 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/daemon.ml +++ b/src/proto_017_PtNairob/lib_sc_rollup_node/daemon.ml @@ -679,15 +679,46 @@ let run node_ctxt configuration ~mode:configuration.mode ~genesis_level:(Raw_level.to_int32 node_ctxt.genesis_info.level) ~pvm_kind:(Sc_rollup.Kind.to_string node_ctxt.kind) ; + let fatal_error_exit e = + Format.eprintf "%!%a@.Exiting.@." pp_print_trace e ; + let*! _ = Lwt_exit.exit_and_wait 1 in + return_unit + in + let error_to_degraded_mode e = + let*! () = Daemon_event.error e in + degraded_refutation_mode daemon_components node_ctxt + in + let handle_preimage_not_found e = + (* When running/initialising a rollup node with missing preimages + the rollup node enter in a degraded mode where actually there + isn't much that can be done with a non initialised rollup node, + hence it should exit after printing the error logs. + + A safe way to do this is to check if there was a processed head. + If not we can exit safely. If there was a processed head, we + go deeper and we check if the most recent commitment is actually + the genesis' one. If that's the case it means we're still on the + initialisation phase which means we can exit safely as well, if + not it means there is potential commitment(s) where refutation + can be played so we enter in degraded mode. *) + let* head = Node_context.last_processed_head_opt node_ctxt in + match head with + | Some head -> + if + Sc_rollup_block.most_recent_commitment head.header + = Sc_rollup_proto_types.Commitment_hash.to_octez + node_ctxt.genesis_info.commitment_hash + then fatal_error_exit e + else error_to_degraded_mode e + | None -> fatal_error_exit e + in protect start ~on_error:(function | Sc_rollup_node_errors.(Lost_game _ | Invalid_genesis_state _) :: _ as e -> - Format.eprintf "%!%a@.Exiting.@." pp_print_trace e ; - let*! _ = Lwt_exit.exit_and_wait 1 in - return_unit - | e -> - let*! () = Daemon_event.error e in - degraded_refutation_mode daemon_components node_ctxt) + fatal_error_exit e + | Sc_rollup_node_errors.Could_not_open_preimage_file _ :: _ as e -> + handle_preimage_not_found e + | e -> error_to_degraded_mode e) module Internal_for_tests = struct (** Same as {!process_head} but only builds and stores the L2 block diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/reveals.ml b/src/proto_017_PtNairob/lib_sc_rollup_node/reveals.ml index ad369bba3e4c2fb41a8a6eb6fd2740c18efb7c35..9e15def1223eff8b2424b29b9f7f977f417c5649 100644 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/reveals.ml +++ b/src/proto_017_PtNairob/lib_sc_rollup_node/reveals.ml @@ -2,6 +2,7 @@ (* *) (* Open Source License *) (* Copyright (c) 2022 Nomadic Labs, *) +(* Copyright (c) 2023 Functori, *) (* *) (* Permission is hereby granted, free of charge, to any person obtaining a *) (* copy of this software and associated documentation files (the "Software"),*) @@ -26,10 +27,7 @@ open Protocol.Alpha_context module Reveal_hash = Protocol.Sc_rollup_reveal_hash -type error += - | Wrong_hash of {found : Reveal_hash.t; expected : Reveal_hash.t} - | Could_not_open_preimage_file of String.t - | Could_not_encode_raw_data +type error += Wrong_hash of {found : Reveal_hash.t; expected : Reveal_hash.t} let () = Sc_rollup_node_errors.register_error_kind @@ -51,34 +49,7 @@ let () = (req "expected" Reveal_hash.encoding)) (function | Wrong_hash {found; expected} -> Some (found, expected) | _ -> None) - (fun (found, expected) -> Wrong_hash {found; expected}) ; - Sc_rollup_node_errors.register_error_kind - ~id:"sc_rollup.node.could_not_open_reveal_preimage_file" - ~title:"Could not open reveal preimage file" - ~description:"Could not open reveal preimage file." - ~pp:(fun ppf hash -> - Format.fprintf - ppf - "Could not open file containing preimage of reveal hash %s" - hash) - `Permanent - Data_encoding.(obj1 (req "hash" string)) - (function - | Could_not_open_preimage_file filename -> Some filename | _ -> None) - (fun filename -> Could_not_open_preimage_file filename) ; - Sc_rollup_node_errors.register_error_kind - ~id:"sc_rollup.node.could_not_encode_raw_data" - ~title:"Could not encode raw data to reveal" - ~description:"Could not encode raw data to reveal." - ~pp:(fun ppf () -> - Format.pp_print_string - ppf - "Could not encode raw data to reveal with the expected protocol \ - encoding") - `Permanent - Data_encoding.unit - (function Could_not_encode_raw_data -> Some () | _ -> None) - (fun () -> Could_not_encode_raw_data) + (fun (found, expected) -> Wrong_hash {found; expected}) type source = String of string | File of string @@ -88,7 +59,8 @@ let file_contents filename = (fun () -> let*! contents = Lwt_utils_unix.read_file filename in return contents) - (fun _ -> tzfail @@ Could_not_open_preimage_file filename) + (fun _ -> + tzfail @@ Sc_rollup_node_errors.Could_not_open_preimage_file filename) let path data_dir pvm_name hash = let hash = Protocol.Sc_rollup_reveal_hash.to_hex hash in @@ -111,7 +83,7 @@ let get ~data_dir ~pvm_kind ~hash = let* _encoded = (* Check that the reveal input can be encoded within the bounds enforced by the protocol. *) - trace Could_not_encode_raw_data + trace Sc_rollup_node_errors.Could_not_encode_raw_data @@ protect @@ fun () -> Data_encoding.Binary.to_bytes_exn diff --git a/src/proto_018_Proxford/lib_sc_rollup_node/daemon.ml b/src/proto_018_Proxford/lib_sc_rollup_node/daemon.ml index 78c9bc577c5ab9e303eda96249b24b4652f23098..042f606463dad7d17fea1c6efa9f75556328c957 100644 --- a/src/proto_018_Proxford/lib_sc_rollup_node/daemon.ml +++ b/src/proto_018_Proxford/lib_sc_rollup_node/daemon.ml @@ -680,16 +680,46 @@ let run node_ctxt configuration ~mode:configuration.mode ~genesis_level:(Raw_level.to_int32 node_ctxt.genesis_info.level) ~pvm_kind:(Sc_rollup.Kind.to_string node_ctxt.kind) ; + let fatal_error_exit e = + Format.eprintf "%!%a@.Exiting.@." pp_print_trace e ; + let*! _ = Lwt_exit.exit_and_wait 1 in + return_unit + in + let error_to_degraded_mode e = + let*! () = Daemon_event.error e in + degraded_refutation_mode daemon_components node_ctxt + in + let handle_preimage_not_found e = + (* When running/initialising a rollup node with missing preimages + the rollup node enter in a degraded mode where actually there + isn't much that can be done with a non initialised rollup node, + hence it should exit after printing the error logs. + + A safe way to do this is to check if there was a processed head. + If not we can exit safely. If there was a processed head, we + go deeper and we check if the most recent commitment is actually + the genesis' one. If that's the case it means we're still on the + initialisation phase which means we can exit safely as well, if + not it means there is potential commitment(s) where refutation + can be played so we enter in degraded mode. *) + let* head = Node_context.last_processed_head_opt node_ctxt in + match head with + | Some head -> + if + Sc_rollup_block.most_recent_commitment head.header + = node_ctxt.genesis_info.commitment_hash + then fatal_error_exit e + else error_to_degraded_mode e + | None -> fatal_error_exit e + in protect start ~on_error:(function | Sc_rollup_node_errors.( Lost_game _ | Unparsable_boot_sector _ | Invalid_genesis_state _) :: _ as e -> - Format.eprintf "%!%a@.Exiting.@." pp_print_trace e ; - let*! _ = Lwt_exit.exit_and_wait 1 in - return_unit - | e -> - let*! () = Daemon_event.error e in - degraded_refutation_mode daemon_components node_ctxt) + fatal_error_exit e + | Sc_rollup_node_errors.Could_not_open_preimage_file _ :: _ as e -> + handle_preimage_not_found e + | e -> error_to_degraded_mode e) module Internal_for_tests = struct (** Same as {!process_head} but only builds and stores the L2 block diff --git a/src/proto_018_Proxford/lib_sc_rollup_node/reveals.ml b/src/proto_018_Proxford/lib_sc_rollup_node/reveals.ml index 5193b0e452283c6937da5f7566390ad49b5edd57..77d6937abfc0f422545f85c6b6300f1e835c6d8c 100644 --- a/src/proto_018_Proxford/lib_sc_rollup_node/reveals.ml +++ b/src/proto_018_Proxford/lib_sc_rollup_node/reveals.ml @@ -2,6 +2,7 @@ (* *) (* Open Source License *) (* Copyright (c) 2022 Nomadic Labs, *) +(* Copyright (c) 2023 Functori, *) (* *) (* Permission is hereby granted, free of charge, to any person obtaining a *) (* copy of this software and associated documentation files (the "Software"),*) @@ -26,10 +27,7 @@ open Protocol.Alpha_context module Reveal_hash = Protocol.Sc_rollup_reveal_hash -type error += - | Wrong_hash of {found : Reveal_hash.t; expected : Reveal_hash.t} - | Could_not_open_preimage_file of String.t - | Could_not_encode_raw_data +type error += Wrong_hash of {found : Reveal_hash.t; expected : Reveal_hash.t} let () = Sc_rollup_node_errors.register_error_kind @@ -51,34 +49,7 @@ let () = (req "expected" Reveal_hash.encoding)) (function | Wrong_hash {found; expected} -> Some (found, expected) | _ -> None) - (fun (found, expected) -> Wrong_hash {found; expected}) ; - Sc_rollup_node_errors.register_error_kind - ~id:"sc_rollup.node.could_not_open_reveal_preimage_file" - ~title:"Could not open reveal preimage file" - ~description:"Could not open reveal preimage file." - ~pp:(fun ppf hash -> - Format.fprintf - ppf - "Could not open file containing preimage of reveal hash %s" - hash) - `Permanent - Data_encoding.(obj1 (req "hash" string)) - (function - | Could_not_open_preimage_file filename -> Some filename | _ -> None) - (fun filename -> Could_not_open_preimage_file filename) ; - Sc_rollup_node_errors.register_error_kind - ~id:"sc_rollup.node.could_not_encode_raw_data" - ~title:"Could not encode raw data to reveal" - ~description:"Could not encode raw data to reveal." - ~pp:(fun ppf () -> - Format.pp_print_string - ppf - "Could not encode raw data to reveal with the expected protocol \ - encoding") - `Permanent - Data_encoding.unit - (function Could_not_encode_raw_data -> Some () | _ -> None) - (fun () -> Could_not_encode_raw_data) + (fun (found, expected) -> Wrong_hash {found; expected}) type source = String of string | File of string @@ -108,7 +79,8 @@ let get ?dac_client ~data_dir ~pvm_kind hash = | Some contents -> return contents | None -> ( match dac_client with - | None -> tzfail (Could_not_open_preimage_file filename) + | None -> + tzfail (Sc_rollup_node_errors.Could_not_open_preimage_file filename) | Some dac_client -> let dac_plugin = WithExceptions.Option.get ~loc:__LOC__ @@ -130,7 +102,7 @@ let get ?dac_client ~data_dir ~pvm_kind hash = let* _encoded = (* Check that the reveal input can be encoded within the bounds enforced by the protocol. *) - trace Could_not_encode_raw_data + trace Sc_rollup_node_errors.Could_not_encode_raw_data @@ protect @@ fun () -> Data_encoding.Binary.to_bytes_exn diff --git a/src/proto_alpha/lib_sc_rollup_node/daemon.ml b/src/proto_alpha/lib_sc_rollup_node/daemon.ml index 78c9bc577c5ab9e303eda96249b24b4652f23098..042f606463dad7d17fea1c6efa9f75556328c957 100644 --- a/src/proto_alpha/lib_sc_rollup_node/daemon.ml +++ b/src/proto_alpha/lib_sc_rollup_node/daemon.ml @@ -680,16 +680,46 @@ let run node_ctxt configuration ~mode:configuration.mode ~genesis_level:(Raw_level.to_int32 node_ctxt.genesis_info.level) ~pvm_kind:(Sc_rollup.Kind.to_string node_ctxt.kind) ; + let fatal_error_exit e = + Format.eprintf "%!%a@.Exiting.@." pp_print_trace e ; + let*! _ = Lwt_exit.exit_and_wait 1 in + return_unit + in + let error_to_degraded_mode e = + let*! () = Daemon_event.error e in + degraded_refutation_mode daemon_components node_ctxt + in + let handle_preimage_not_found e = + (* When running/initialising a rollup node with missing preimages + the rollup node enter in a degraded mode where actually there + isn't much that can be done with a non initialised rollup node, + hence it should exit after printing the error logs. + + A safe way to do this is to check if there was a processed head. + If not we can exit safely. If there was a processed head, we + go deeper and we check if the most recent commitment is actually + the genesis' one. If that's the case it means we're still on the + initialisation phase which means we can exit safely as well, if + not it means there is potential commitment(s) where refutation + can be played so we enter in degraded mode. *) + let* head = Node_context.last_processed_head_opt node_ctxt in + match head with + | Some head -> + if + Sc_rollup_block.most_recent_commitment head.header + = node_ctxt.genesis_info.commitment_hash + then fatal_error_exit e + else error_to_degraded_mode e + | None -> fatal_error_exit e + in protect start ~on_error:(function | Sc_rollup_node_errors.( Lost_game _ | Unparsable_boot_sector _ | Invalid_genesis_state _) :: _ as e -> - Format.eprintf "%!%a@.Exiting.@." pp_print_trace e ; - let*! _ = Lwt_exit.exit_and_wait 1 in - return_unit - | e -> - let*! () = Daemon_event.error e in - degraded_refutation_mode daemon_components node_ctxt) + fatal_error_exit e + | Sc_rollup_node_errors.Could_not_open_preimage_file _ :: _ as e -> + handle_preimage_not_found e + | e -> error_to_degraded_mode e) module Internal_for_tests = struct (** Same as {!process_head} but only builds and stores the L2 block diff --git a/src/proto_alpha/lib_sc_rollup_node/reveals.ml b/src/proto_alpha/lib_sc_rollup_node/reveals.ml index 5193b0e452283c6937da5f7566390ad49b5edd57..77d6937abfc0f422545f85c6b6300f1e835c6d8c 100644 --- a/src/proto_alpha/lib_sc_rollup_node/reveals.ml +++ b/src/proto_alpha/lib_sc_rollup_node/reveals.ml @@ -2,6 +2,7 @@ (* *) (* Open Source License *) (* Copyright (c) 2022 Nomadic Labs, *) +(* Copyright (c) 2023 Functori, *) (* *) (* Permission is hereby granted, free of charge, to any person obtaining a *) (* copy of this software and associated documentation files (the "Software"),*) @@ -26,10 +27,7 @@ open Protocol.Alpha_context module Reveal_hash = Protocol.Sc_rollup_reveal_hash -type error += - | Wrong_hash of {found : Reveal_hash.t; expected : Reveal_hash.t} - | Could_not_open_preimage_file of String.t - | Could_not_encode_raw_data +type error += Wrong_hash of {found : Reveal_hash.t; expected : Reveal_hash.t} let () = Sc_rollup_node_errors.register_error_kind @@ -51,34 +49,7 @@ let () = (req "expected" Reveal_hash.encoding)) (function | Wrong_hash {found; expected} -> Some (found, expected) | _ -> None) - (fun (found, expected) -> Wrong_hash {found; expected}) ; - Sc_rollup_node_errors.register_error_kind - ~id:"sc_rollup.node.could_not_open_reveal_preimage_file" - ~title:"Could not open reveal preimage file" - ~description:"Could not open reveal preimage file." - ~pp:(fun ppf hash -> - Format.fprintf - ppf - "Could not open file containing preimage of reveal hash %s" - hash) - `Permanent - Data_encoding.(obj1 (req "hash" string)) - (function - | Could_not_open_preimage_file filename -> Some filename | _ -> None) - (fun filename -> Could_not_open_preimage_file filename) ; - Sc_rollup_node_errors.register_error_kind - ~id:"sc_rollup.node.could_not_encode_raw_data" - ~title:"Could not encode raw data to reveal" - ~description:"Could not encode raw data to reveal." - ~pp:(fun ppf () -> - Format.pp_print_string - ppf - "Could not encode raw data to reveal with the expected protocol \ - encoding") - `Permanent - Data_encoding.unit - (function Could_not_encode_raw_data -> Some () | _ -> None) - (fun () -> Could_not_encode_raw_data) + (fun (found, expected) -> Wrong_hash {found; expected}) type source = String of string | File of string @@ -108,7 +79,8 @@ let get ?dac_client ~data_dir ~pvm_kind hash = | Some contents -> return contents | None -> ( match dac_client with - | None -> tzfail (Could_not_open_preimage_file filename) + | None -> + tzfail (Sc_rollup_node_errors.Could_not_open_preimage_file filename) | Some dac_client -> let dac_plugin = WithExceptions.Option.get ~loc:__LOC__ @@ -130,7 +102,7 @@ let get ?dac_client ~data_dir ~pvm_kind hash = let* _encoded = (* Check that the reveal input can be encoded within the bounds enforced by the protocol. *) - trace Could_not_encode_raw_data + trace Sc_rollup_node_errors.Could_not_encode_raw_data @@ protect @@ fun () -> Data_encoding.Binary.to_bytes_exn diff --git a/tezt/tests/dac.ml b/tezt/tests/dac.ml index 79128b04a6852c0e485c239f96ddec88c531a1f7..34ae9d55986a1e6ab303a7bc555884418f5cd557 100644 --- a/tezt/tests/dac.ml +++ b/tezt/tests/dac.ml @@ -598,48 +598,6 @@ module Legacy = struct (value = nadd) int ~error_msg:"Invalid value in rollup state (%L <> %R)") ; unit - let test_reveals_fails_on_wrong_hash _protocol dac_node sc_rollup_node - sc_rollup_address _node client _pvm_name _threshold _committee_members = - let payload = "Some data that is not related to the hash" in - let _actual_rh = - Dac_helper.Call_endpoint.V0.post_store_preimage - dac_node - ~payload - ~pagination_scheme:"Hash_chain_V0" - in - let errorneous_hash = - "0027782d2a7020be332cc42c4e66592ec50305f559a4011981f1d5af81428ecafe" - in - let* genesis_info = - RPC.Client.call ~hooks client - @@ RPC.get_chain_block_context_smart_rollups_smart_rollup_genesis_info - sc_rollup_address - in - let init_level = JSON.(genesis_info |-> "level" |> as_int) in - let* () = Sc_rollup_node.run sc_rollup_node sc_rollup_address [] in - let error_promise = - Sc_rollup_node.wait_for - sc_rollup_node - "sc_rollup_daemon_error.v0" - (fun e -> - let id = JSON.(e |=> 0 |-> "id" |> as_string) in - if id =~ rex "could_not_open_reveal_preimage_file" then Some (Ok ()) - else Some (Error id)) - in - let* _level = - Sc_rollup_node.wait_for_level ~timeout:120. sc_rollup_node init_level - in - let* () = - send_messages - client - ["hash:" ^ errorneous_hash] - ~alter_final_msg:(fun s -> "text:" ^ s) - in - let* ok = error_promise in - match ok with - | Ok () -> unit - | Error id -> Test.fail "Rollup node failed with unexpected error %s" id - (* The following tests involve multiple legacy DAC nodes running at the same time and playing either the coordinator, committee member or observer role. *) @@ -3048,15 +3006,6 @@ let register ~protocols = protocols ~threshold:1 ~committee_size:1 ; - scenario_with_layer1_legacy_and_rollup_nodes - ~hooks - ~__FILE__ - ~tags:["dac"; "dac_node"] - "dac_rollup_arith_wrong_hash" - Legacy.test_reveals_fails_on_wrong_hash - ~threshold:1 - ~committee_size:1 - protocols ; scenario_with_layer1_and_legacy_dac_nodes ~__FILE__ ~threshold:0 diff --git a/tezt/tests/expected/dac.ml/Alpha- Testing DAC rollup and node with L1 (dac_rollup_arith_wrong_hash).out b/tezt/tests/expected/dac.ml/Alpha- Testing DAC rollup and node with L1 (dac_rollup_arith_wrong_hash).out deleted file mode 100644 index f266d5fbbd37cdb2a35b623091ebfec1f9cd4ca8..0000000000000000000000000000000000000000 --- a/tezt/tests/expected/dac.ml/Alpha- Testing DAC rollup and node with L1 (dac_rollup_arith_wrong_hash).out +++ /dev/null @@ -1,64 +0,0 @@ - -./octez-client --wait none originate smart rollup rollup from '[PUBLIC_KEY_HASH]' of kind arith of type string with kernel --burn-cap 9999999 -Node is bootstrapped. -Estimated gas: 1929.997 units (will add 100 for safety) -Estimated storage: 6552 bytes added (will add 20 for safety) -Operation successfully injected in the node. -Operation hash is '[OPERATION_HASH]' -NOT waiting for the operation to be included. -Use command - octez-client wait for [OPERATION_HASH] to be included --confirmations 1 --branch [BLOCK_HASH] -and/or an external block explorer to make sure that it has been included. -This sequence of operations was run: - Manager signed operations: - From: [PUBLIC_KEY_HASH] - Fee to the baker: ꜩ0.000439 - Expected counter: 1 - Gas limit: 2030 - Storage limit: 6572 bytes - Balance updates: - [PUBLIC_KEY_HASH] ... -ꜩ0.000439 - payload fees(the block proposer) ....... +ꜩ0.000439 - Smart rollup origination: - Kind: arith - Parameter type: string - Kernel Blake2B hash: '0e5751c026e543b2e8ab2eb06099daa1d1e5df47778f7787faab45cdf12fe3a8' - This smart rollup origination was successfully applied - Consumed gas: 1929.964 - Storage size: 6552 bytes - Address: [SMART_ROLLUP_HASH] - Genesis commitment hash: [SC_ROLLUP_COMMITMENT_HASH] - Balance updates: - [PUBLIC_KEY_HASH] ... -ꜩ1.638 - storage fees ........................... +ꜩ1.638 - -Smart rollup [SMART_ROLLUP_HASH] memorized as "rollup" - -./octez-client rpc get '/chains/main/blocks/head/context/smart_rollups/smart_rollup/[SMART_ROLLUP_HASH]/genesis_info' -{ "level": 2, - "commitment_hash": "[SC_ROLLUP_COMMITMENT_HASH]" } - -./octez-client --wait none send smart rollup message 'text:["hash:0027782d2a7020be332cc42c4e66592ec50305f559a4011981f1d5af81428ecafe"]' from bootstrap2 -Node is bootstrapped. -Estimated gas: 172.901 units (will add 100 for safety) -Estimated storage: no bytes added -Operation successfully injected in the node. -Operation hash is '[OPERATION_HASH]' -NOT waiting for the operation to be included. -Use command - octez-client wait for [OPERATION_HASH] to be included --confirmations 1 --branch [BLOCK_HASH] -and/or an external block explorer to make sure that it has been included. -This sequence of operations was run: - Manager signed operations: - From: [PUBLIC_KEY_HASH] - Fee to the baker: ꜩ0.000331 - Expected counter: 1 - Gas limit: 273 - Storage limit: 0 bytes - Balance updates: - [PUBLIC_KEY_HASH] ... -ꜩ0.000331 - payload fees(the block proposer) ....... +ꜩ0.000331 - Smart rollup messages submission: - This smart rollup messages submission was successfully applied - Consumed gas: 172.835 - diff --git a/tezt/tests/sc_rollup.ml b/tezt/tests/sc_rollup.ml index a644efb5b2f291e4f95130a7feecb53e70837d27..379da6d2e6bb57d1af026362e791026723a7d8c0 100644 --- a/tezt/tests/sc_rollup.ml +++ b/tezt/tests/sc_rollup.ml @@ -3,6 +3,7 @@ (* Open Source License *) (* Copyright (c) 2021-2023 Nomadic Labs *) (* Copyright (c) 2022-2023 TriliTech *) +(* Copyright (c) 2023 Functori *) (* *) (* Permission is hereby granted, free of charge, to any person obtaining a *) (* copy of this software and associated documentation files (the "Software"),*) @@ -5413,6 +5414,48 @@ let test_bootstrap_smart_rollup_originated = ~error_msg:"Expected %R bootstrapped smart rollups, got %L") ; unit +let test_rollup_node_missing_preimage_exit_at_initialisation = + register_test + ~supports:(From_protocol 016) + ~__FILE__ + ~tags:["node"; "preimage"; "boot_sector"] + ~title: + "Rollup node exit if at initialisation, there is one or multiple \ + preimage(s) missing." + @@ fun protocol -> + let* node, client = setup_l1 protocol in + let rollup_node = + Sc_rollup_node.create + ~protocol + ~base_dir:(Client.base_dir client) + ~default_operator:Constant.bootstrap1.alias + Operator + node + in + let* boot_sector = + (* The preimages will be saved in the rollup node's data directory + ROLLUP_NODE_DATA_DIR, whereas the rollup node will try to look + for the preimages in ROLLUP_NODE_DATA_DIR/wasm_2_0_0. *) + let preimages_dir = Sc_rollup_node.data_dir rollup_node in + Sc_rollup_helpers.prepare_installer_kernel ~preimages_dir "echo" + in + let* rollup_address = + originate_sc_rollup + ~kind:"wasm_2_0_0" + ~boot_sector + ~src:Constant.bootstrap1.alias + client + in + let* _ = Sc_rollup_node.config_init rollup_node rollup_address in + let run_process = Sc_rollup_node.spawn_run rollup_node rollup_address [] in + let* () = Client.bake_for_and_wait client in + let* () = + Process.check_error + ~msg:(rex "Could not open file containing preimage of reveal hash") + run_process + in + Lwt.return_unit + let register ~kind ~protocols = test_origination ~kind protocols ; test_rollup_node_running ~kind protocols ; @@ -5543,6 +5586,7 @@ let register ~protocols = (* PVM-independent tests. We still need to specify a PVM kind because the tezt will need to originate a rollup. However, the tezt will not test for PVM kind specific featued. *) + test_rollup_node_missing_preimage_exit_at_initialisation protocols ; test_rollup_node_configuration protocols ~kind:"wasm_2_0_0" ; test_rollup_list protocols ~kind:"wasm_2_0_0" ; test_rollup_client_wallet protocols ~kind:"wasm_2_0_0" ;