From 3d5327da4b195797cecd478e08437b05ac9e49e2 Mon Sep 17 00:00:00 2001 From: Alain Mebsout Date: Tue, 11 Jul 2023 14:04:43 +0200 Subject: [PATCH 1/2] SCORU/Node: protect worker handlers --- src/lib_smart_rollup_node/refutation_coordinator.ml | 3 ++- src/lib_smart_rollup_node/refutation_player.ml | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/lib_smart_rollup_node/refutation_coordinator.ml b/src/lib_smart_rollup_node/refutation_coordinator.ml index 1a53e69bfaa0..c981947b4cae 100644 --- a/src/lib_smart_rollup_node/refutation_coordinator.ml +++ b/src/lib_smart_rollup_node/refutation_coordinator.ml @@ -149,7 +149,8 @@ module Handlers = struct = fun w request -> let state = Worker.state w in - match request with Request.Process b -> on_process b state + match request with + | Request.Process b -> protect @@ fun () -> on_process b state type launch_error = error trace diff --git a/src/lib_smart_rollup_node/refutation_player.ml b/src/lib_smart_rollup_node/refutation_player.ml index c615511eb3b7..0eca27506b7b 100644 --- a/src/lib_smart_rollup_node/refutation_player.ml +++ b/src/lib_smart_rollup_node/refutation_player.ml @@ -70,8 +70,9 @@ module Handlers = struct fun w request -> let state = Worker.state w in match request with - | Request.Play game -> on_play game state - | Request.Play_opening conflict -> on_play_opening conflict state + | Request.Play game -> protect @@ fun () -> on_play game state + | Request.Play_opening conflict -> + protect @@ fun () -> on_play_opening conflict state type launch_error = error trace -- GitLab From 923f7f2a2b17544318d401bccf256c42e29196e6 Mon Sep 17 00:00:00 2001 From: Alain Mebsout Date: Thu, 20 Jul 2023 11:57:03 +0200 Subject: [PATCH 2/2] SCORU/Node: fix fetching tezos block wrong proto prefetch --- src/lib_smart_rollup_node/layer1.ml | 33 +++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/src/lib_smart_rollup_node/layer1.ml b/src/lib_smart_rollup_node/layer1.ml index 974a26c7742e..7a3a1157e17e 100644 --- a/src/lib_smart_rollup_node/layer1.ml +++ b/src/lib_smart_rollup_node/layer1.ml @@ -212,14 +212,35 @@ let fetch_tezos_block (fetch_rpc : fetch_block_rpc) extract_header cache_shell_header l1_ctxt hash (extract_header block) ; return block in - let* block = Blocks_cache.bind_or_put blocks_cache hash fetch Lwt.return in + let*! block = Blocks_cache.bind_or_put blocks_cache hash fetch Lwt.return in + (* TODO: https://gitlab.com/tezos/tezos/-/issues/6292 + Consider cleaner ways to "prefetch" tezos blocks: + - know before where are protocol boundaries + - prefetch blocks in binary form *) let is_of_expected_protocol = - try - let (_ : Block_header.shell_header) = extract_header block in - true - with _ -> false + match block with + | Error + (Tezos_rpc_http.RPC_client_errors.( + Request_failed {error = Unexpected_content _; _}) + :: _) -> + (* The promise cached failed to parse the block because it was for the + wrong protocol. *) + false + | Error _ -> + (* The promise cached failed for another reason. *) + true + | Ok block -> ( + (* We check if we are able to extract the header, which inherently + ensures that we are in the correct case of type {!type:block}. *) + try + let (_ : Block_header.shell_header) = extract_header block in + true + with _ -> + (* This can happen if the blocks for two protocols have the same + binary representation. *) + false) in - if is_of_expected_protocol then return block + if is_of_expected_protocol then Lwt.return block else (* It is possible for a value stored in the cache to have been parsed with the wrong protocol code because: -- GitLab