diff --git a/src/lib_smart_rollup_node/layer1.ml b/src/lib_smart_rollup_node/layer1.ml index 974a26c7742e93fced1524ae8f1b0ef22acf82f8..7a3a1157e17e01681d4a9bf582a2104b2d5c2a96 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: diff --git a/src/lib_smart_rollup_node/refutation_coordinator.ml b/src/lib_smart_rollup_node/refutation_coordinator.ml index 1a53e69bfaa0d9a542254b5d88dc592fdd2bfdd9..c981947b4cae0dbefd10eca1d5ff714de5229b18 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 c615511eb3b727db26bdcd6681111c571b33e26e..0eca27506b7b0624fccba91664aef141dd08778a 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