From 29a1ca67b1cd4228812c3180ea15e96aed2a42af Mon Sep 17 00:00:00 2001 From: Dibassi Brahima Date: Wed, 14 May 2025 15:26:48 +0200 Subject: [PATCH] Tezlink : Add dummy simulate operation service to Tezlink --- .../lib_dev/tezlink/tezos_services.ml | 53 +++++++++++++++++++ .../Alpha- Test the -describe endpoint.out | 16 ++++++ 2 files changed, 69 insertions(+) diff --git a/etherlink/bin_node/lib_dev/tezlink/tezos_services.ml b/etherlink/bin_node/lib_dev/tezlink/tezos_services.ml index cdd4d226e648..44074a22f8b8 100644 --- a/etherlink/bin_node/lib_dev/tezlink/tezos_services.ml +++ b/etherlink/bin_node/lib_dev/tezlink/tezos_services.ml @@ -50,6 +50,33 @@ module Mock = struct let protocol_data : Imported_protocol.Block_header_repr.protocol_data = {contents; signature} + + let receipts = + Imported_protocol.Apply_results.Operation_metadata + { + contents = + Single_result + (Manager_operation_result + { + balance_updates = []; + operation_result = + Applied + (Transaction_result + (Transaction_to_contract_result + { + storage = None; + lazy_storage_diff = None; + balance_updates = []; + ticket_receipt = []; + originated_contracts = []; + consumed_gas = Alpha_context.Gas.Arith.zero; + storage_size = Z.zero; + paid_storage_size_diff = Z.zero; + allocated_destination_contract = true; + })); + internal_operation_results = []; + }); + } end (* Module importing, amending, and converting, protocol types. Those types @@ -373,6 +400,20 @@ module Imported_services = struct Constants_services.RPC_service.t = import_service Tezos_shell_services.Monitor_services.S.bootstrapped + (* TODO: https://gitlab.com/tezos/tezos/-/issues/7965 *) + (* We need a proper implementation *) + let simulate_operation : + ( [`POST], + tezlink_rpc_context, + tezlink_rpc_context, + < successor_level : bool + ; version : Imported_protocol_plugin.RPC.version option >, + int32 option * Alpha_context.packed_operation * Chain_id.t * int, + Alpha_context.packed_protocol_data * Imported_protocol.operation_receipt + ) + Constants_services.RPC_service.t = + import_service Imported_protocol_plugin.RPC.Scripts.S.simulate_operation + let monitor_heads : ( [`GET], unit, @@ -505,6 +546,18 @@ let register_block_services ~l2_chain_id let*? block = check_block block in Backend.block_hash chain block) ~convert_output:Protocol_types.ethereum_to_tezos_block_hash + |> register + (* TODO: https://gitlab.com/tezos/tezos/-/issues/7965 *) + (* We need a proper implementation *) + ~service:Imported_services.simulate_operation + ~impl:(fun + {block = _; chain = _} + _param + ( _blocks_before_activation, + operation, + _chain_id, + _operation_inclusion_latency ) + -> return (operation.protocol_data, Mock.receipts)) in Tezos_rpc.Directory.prefix block_directory_path 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 f72c787eb643..23b6ef1854cf 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 @@ -48,6 +48,14 @@ Available services: block located `offset` blocks after it in the chain. For instance, the next block if `offset` is 1. The offset cannot be negative. + - POST /tezlink/chains//blocks//helpers/scripts/simulate_operation + Simulate running an operation at some future moment (based on the + number of blocks given in the `latency` argument), and return the + operation application result. The result is the same as + run_operation except for the consumed gas, which depends on the + contents of the cache at that future moment. This RPC estimates + future gas consumption by trying to predict the state of the + cache using some heuristics. - GET /tezlink/chains//blocks//protocols Current and next protocol. - GET /tezlink/chains//chain_id @@ -123,6 +131,14 @@ Available services: Returns the level of the interrogated block, or the one of a block located `offset` blocks after it in the chain. For instance, the next block if `offset` is 1. The offset cannot be negative. + - POST /chains//blocks//helpers/scripts/simulate_operation + Simulate running an operation at some future moment (based on the + number of blocks given in the `latency` argument), and return the + operation application result. The result is the same as + run_operation except for the consumed gas, which depends on the + contents of the cache at that future moment. This RPC estimates + future gas consumption by trying to predict the state of the cache + using some heuristics. - GET /chains//blocks//protocols Current and next protocol. - GET /chains//chain_id -- GitLab