From 4c74880d7ca7a859056444830367415845446abe Mon Sep 17 00:00:00 2001 From: Dibassi Brahima Date: Tue, 6 May 2025 14:21:44 +0200 Subject: [PATCH 1/2] Tezlink/Node : Implement bootstrapped in Tezlink backend and register it --- .../lib_dev/tezlink/tezlink_backend_sig.ml | 3 +++ .../bin_node/lib_dev/tezlink/tezos_services.ml | 17 +++++++++++++++++ .../bin_node/lib_dev/tezlink_services_impl.ml | 11 +++++++++++ .../Alpha- Test the -describe endpoint.out | 12 ++++++++++++ 4 files changed, 43 insertions(+) diff --git a/etherlink/bin_node/lib_dev/tezlink/tezlink_backend_sig.ml b/etherlink/bin_node/lib_dev/tezlink/tezlink_backend_sig.ml index 00d5b292cafc..47f14032d39b 100644 --- a/etherlink/bin_node/lib_dev/tezlink/tezlink_backend_sig.ml +++ b/etherlink/bin_node/lib_dev/tezlink/tezlink_backend_sig.ml @@ -29,4 +29,7 @@ module type S = sig [`Main] -> block_param -> Tezos_types.Contract.t -> Z.t tzresult Lwt.t val header : [`Main] -> block_param -> L2_types.Tezos_block.t tzresult Lwt.t + + val bootstrapped : + unit -> (Ethereum_types.block_hash * Time.Protocol.t) tzresult Lwt.t end diff --git a/etherlink/bin_node/lib_dev/tezlink/tezos_services.ml b/etherlink/bin_node/lib_dev/tezlink/tezos_services.ml index f9a505a7e672..c1730c7f7d82 100644 --- a/etherlink/bin_node/lib_dev/tezlink/tezos_services.ml +++ b/etherlink/bin_node/lib_dev/tezlink/tezos_services.ml @@ -343,6 +343,16 @@ module Imported_services = struct Block_services.block_header ) Tezos_rpc.Service.t = import_service Block_services.S.header + + let bootstrapped : + ( [`GET], + unit, + unit, + unit, + unit, + Block_hash.t * Time.Protocol.t ) + Constants_services.RPC_service.t = + import_service Tezos_shell_services.Monitor_services.S.bootstrapped end let chain_directory_path = Tezos_shell_services.Chain_services.path @@ -485,9 +495,16 @@ let register_chain_services ~l2_chain_id (** Builds the root directory. *) let build_dir ~l2_chain_id backend = + let (module Backend : Tezlink_backend_sig.S) = backend in Tezos_rpc.Directory.empty |> register_block_services ~l2_chain_id backend |> register_chain_services ~l2_chain_id backend + |> register_with_conversion + ~service:Imported_services.bootstrapped + ~impl:(fun () () () -> Backend.bootstrapped ()) + ~convert_output:(fun (input_hash, input_time) -> + Result_syntax.return + (Protocol_types.ethereum_to_tezos_block_hash input_hash, input_time)) |> register ~service:Imported_services.version ~impl:(fun () () () -> version ()) diff --git a/etherlink/bin_node/lib_dev/tezlink_services_impl.ml b/etherlink/bin_node/lib_dev/tezlink_services_impl.ml index 49110b8cfde2..3a6e9ddf1fcf 100644 --- a/etherlink/bin_node/lib_dev/tezlink_services_impl.ml +++ b/etherlink/bin_node/lib_dev/tezlink_services_impl.ml @@ -129,4 +129,15 @@ module Make (Backend : Backend) : Tezlink_backend_sig.S = struct let `Main = chain in let* block_number = shell_block_param_to_block_number block in Backend.tez_nth_block block_number + + (* TODO: #7963 Support Observer Mode + Here the catchup mechanism to fetch blueprints is not taken into account as + the observer mode is not supported yet *) + let bootstrapped () = + let open Lwt_result_syntax in + let* (Qty current_block_number) = + Backend.block_param_to_block_number (Block_parameter Latest) + in + let* block = Backend.tez_nth_block current_block_number in + return (block.hash, block.timestamp) end diff --git a/etherlink/tezt/tests/expected/evm_sequencer.ml/Alpha- Test the -describe endpoint.out b/etherlink/tezt/tests/expected/evm_sequencer.ml/Alpha- Test the -describe endpoint.out index 9414bba2e45d..0a0f0047da2a 100644 --- a/etherlink/tezt/tests/expected/evm_sequencer.ml/Alpha- Test the -describe endpoint.out +++ b/etherlink/tezt/tests/expected/evm_sequencer.ml/Alpha- Test the -describe endpoint.out @@ -52,6 +52,12 @@ Available services: The chain unique identifier. - GET /tezlink/describe RPCs documentation and input/output schema + - GET /tezlink/monitor/bootstrapped + Wait for the node to have synchronized its chain with a few peers + (configured by the node's administrator), streaming head updates that + happen during the bootstrapping process, and closing the stream at + the end. If the node was already bootstrapped, returns the current + head immediately. - GET /tezlink/version Get information on the node version - GET /version @@ -114,6 +120,12 @@ Available services: Current and next protocol. - GET /chains//chain_id The chain unique identifier. + - GET /monitor/bootstrapped + Wait for the node to have synchronized its chain with a few peers + (configured by the node's administrator), streaming head updates that + happen during the bootstrapping process, and closing the stream at the + end. If the node was already bootstrapped, returns the current head + immediately. - GET /version Get information on the node version -- GitLab From 85159c76fb110de6b06d6ba7f4aa3aa0a7442b5d Mon Sep 17 00:00:00 2001 From: Dibassi Brahima Date: Tue, 6 May 2025 15:52:13 +0200 Subject: [PATCH 2/2] Tezlink/Tezt : Add test for bootstrapped RPC in Tezlink --- etherlink/tezt/tests/evm_sequencer.ml | 41 +++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/etherlink/tezt/tests/evm_sequencer.ml b/etherlink/tezt/tests/evm_sequencer.ml index f1e4ccab38d2..238404ed3599 100644 --- a/etherlink/tezt/tests/evm_sequencer.ml +++ b/etherlink/tezt/tests/evm_sequencer.ml @@ -780,6 +780,46 @@ let test_tezlink_header = ~chain_id ~current_timestamp:(Some current_timestamp) +let test_tezlink_bootstrapped = + register_tezlink_test + ~title:"Test of the bootstrapped rpc" + ~tags:["rpc"; "bootstrapped"] + @@ fun {sequencer; client; _} _protocol -> + let endpoint = + Client.( + Foreign_endpoint + {(Evm_node.rpc_endpoint_record sequencer) with path = "/tezlink"}) + in + let current_timestamp = + Tezos_base.Time.( + System.now () |> System.to_protocol |> Protocol.to_notation) + in + let*@ n = Rpc.produce_block ~timestamp:current_timestamp sequencer in + let* () = Evm_node.wait_for_blueprint_applied sequencer n in + let* block = + Client.RPC.call ~hooks ~endpoint client @@ RPC.get_chain_block_header () + in + let* rpc_bootstrapped = + let path = "/tezlink/monitor/bootstrapped" in + let* res = + Curl.get_raw ~args:["-v"] (Evm_node.endpoint sequencer ^ path) + |> Runnable.run + in + return @@ JSON.parse ~origin:"curl_bootstrapped" res + in + Check.( + JSON.( + rpc_bootstrapped |-> "block" |> as_string = (block |-> "hash" |> as_string)) + string + ~error_msg:"Check block_hash is latest, Expected %R but got %L") ; + Check.( + JSON.( + rpc_bootstrapped |-> "timestamp" |> as_string + = (block |-> "timestamp" |> as_string)) + string + ~error_msg:"Check timestamp is latest, Expected %R but got %L") ; + unit + let test_make_l2_kernel_installer_config chain_family = Protocol.register_test ~__FILE__ @@ -13592,4 +13632,5 @@ let () = test_tezlink_constants [Alpha] ; test_tezlink_produceBlock [Alpha] ; test_tezlink_chain_id [Alpha] ; + test_tezlink_bootstrapped [Alpha] ; test_fa_deposit_can_be_claimed [Alpha] -- GitLab