diff --git a/etherlink/bin_node/lib_dev/block_storage_sig.ml b/etherlink/bin_node/lib_dev/block_storage_sig.ml index bf97f59ccb070c7ea7f497efc4fa66b1420aa0d6..f0aef9e94a854da30fa4f062d644ed1d7209e79a 100644 --- a/etherlink/bin_node/lib_dev/block_storage_sig.ml +++ b/etherlink/bin_node/lib_dev/block_storage_sig.ml @@ -21,10 +21,12 @@ module type S = sig Z.t -> Transaction_object.t Ethereum_types.block tzresult Lwt.t - (** [tez_nth_block n] returns the [n]th processed and stored tez block. - *) + (** [tez_nth_block n] returns the [n]th processed and stored tez block. *) val tez_nth_block : Z.t -> L2_types.Tezos_block.t tzresult Lwt.t + (** [nth_block_hash n] returns the hash of the [n]th processed and stored block. *) + val nth_block_hash : Z.t -> Ethereum_types.block_hash option tzresult Lwt.t + (** [block_by_hash ~full_transaction_object hash] returns the block with the given [hash]. diff --git a/etherlink/bin_node/lib_dev/evm_ro_context.ml b/etherlink/bin_node/lib_dev/evm_ro_context.ml index a45a186a8a16c6773986c5b6977816d679836d8a..a09624d74108fb76bb25a9e2bbace1f32dccb26a 100644 --- a/etherlink/bin_node/lib_dev/evm_ro_context.ml +++ b/etherlink/bin_node/lib_dev/evm_ro_context.ml @@ -509,6 +509,10 @@ let ro_backend ?evm_node_endpoint ctxt config : (module Services_backend_sig.S) | None -> failwith "Block %a not found" Z.pp_print level | Some block -> return block + let nth_block_hash level = + Evm_store.use ctxt.store @@ fun conn -> + Evm_store.Blocks.find_hash_of_number conn (Qty level) + let block_by_hash ~full_transaction_object hash = let open Lwt_result_syntax in Evm_store.use ctxt.store @@ fun conn -> @@ -551,6 +555,17 @@ let ro_backend ?evm_node_endpoint ctxt config : (module Services_backend_sig.S) failwith "Missing block %a" Ethereum_types.pp_block_hash hash) | param -> block_param_to_block_number param + (* Overwrites Tezlink_backend using the store instead of the durable_storage *) + module Tezlink_backend = Tezlink_services_impl.Make (struct + include Backend.Reader + + let block_param_to_block_number = block_param_to_block_number + + let tez_nth_block = Block_storage.tez_nth_block + + let nth_block_hash = Block_storage.nth_block_hash + end) + include Tracer_sig.Make (Executor) (Block_storage) (Tracer) end) else @@ -582,10 +597,9 @@ let ro_backend ?evm_node_endpoint ctxt config : (module Services_backend_sig.S) need to try to reconstruct the transaction objects. *) return block - let tez_nth_block level = - let open Lwt_result_syntax in - let* block = Block_storage.tez_nth_block level in - return block + let tez_nth_block = Block_storage.tez_nth_block + + let nth_block_hash = Block_storage.nth_block_hash let block_by_hash ~full_transaction_object hash = let open Lwt_result_syntax in diff --git a/etherlink/tezt/tests/evm_sequencer.ml b/etherlink/tezt/tests/evm_sequencer.ml index 65bf45e135006867ead79064c20226b32ec32300..c9f71c1568ed6e0454fd350bf20e62fe4abbe095 100644 --- a/etherlink/tezt/tests/evm_sequencer.ml +++ b/etherlink/tezt/tests/evm_sequencer.ml @@ -748,7 +748,9 @@ let test_tezlink_chain_id = unit let test_tezlink_header = - register_tezlink_test ~title:"Test of the header rpc" ~tags:["rpc"; "header"] + register_tezlink_test + ~title:"Test of the header rpc" + ~tags:["rpc"; "header"; "offset"] @@ fun {sequencer; client; l2_chains; _} _protocol -> let chain_id = match l2_chains with @@ -764,16 +766,16 @@ let test_tezlink_header = let*@ n = Rpc.produce_block sequencer in let* () = Evm_node.wait_for_blueprint_applied sequencer n in - let* block_1 = - Client.RPC.call ~hooks ~endpoint client @@ RPC.get_chain_block_header () - 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_1 = + Client.RPC.call ~hooks ~endpoint client + @@ RPC.get_chain_block_header ~block:"head~1" () + in let* block_2 = Client.RPC.call ~hooks ~endpoint client @@ RPC.get_chain_block_header () in