diff --git a/.gitlab/ci/jobs/packaging/opam_package.yml b/.gitlab/ci/jobs/packaging/opam_package.yml index d693fe6d900d4153c68825614a5c4e08c748015a..c507111b158d13d9ca7a8e51db373b17517f9415 100644 --- a/.gitlab/ci/jobs/packaging/opam_package.yml +++ b/.gitlab/ci/jobs/packaging/opam_package.yml @@ -678,7 +678,7 @@ opam:tezos-client-base: opam:tezos-client-base-unix: extends: - .opam_template - - .rules_template__trigger_opam_batch_3 + - .rules_template__trigger_opam_batch_2 variables: package: tezos-client-base-unix @@ -699,7 +699,7 @@ opam:tezos-client-demo-counter: opam:tezos-client-genesis: extends: - .opam_template - - .rules_template__trigger_opam_batch_3 + - .rules_template__trigger_opam_batch_2 variables: package: tezos-client-genesis @@ -790,7 +790,7 @@ opam:tezos-embedded-protocol-005-PsBabyM1: opam:tezos-embedded-protocol-006-PsCARTHA: extends: - .opam_template - - .rules_template__trigger_opam_batch_3 + - .rules_template__trigger_opam_batch_4 variables: package: tezos-embedded-protocol-006-PsCARTHA @@ -1252,7 +1252,7 @@ opam:tezos-protocol-plugin-010-PtGRANAD: opam:tezos-protocol-plugin-010-PtGRANAD-registerer: extends: - .opam_template - - .rules_template__trigger_opam_batch_2 + - .rules_template__trigger_opam_batch_3 variables: package: tezos-protocol-plugin-010-PtGRANAD-registerer @@ -1266,7 +1266,7 @@ opam:tezos-protocol-plugin-011-PtHangz2: opam:tezos-protocol-plugin-011-PtHangz2-registerer: extends: - .opam_template - - .rules_template__trigger_opam_batch_2 + - .rules_template__trigger_opam_batch_3 variables: package: tezos-protocol-plugin-011-PtHangz2-registerer @@ -1350,7 +1350,7 @@ opam:tezos-protocol-updater: opam:tezos-proxy: extends: - .opam_template - - .rules_template__trigger_opam_batch_4 + - .rules_template__trigger_opam_batch_3 variables: package: tezos-proxy diff --git a/manifest/main.ml b/manifest/main.ml index 29097fa47fa99967f5e07da60fa05771a083f436..273f8edf7d647c2bb46cdd6d8305a3ad42876b70 100644 --- a/manifest/main.ml +++ b/manifest/main.ml @@ -2757,6 +2757,7 @@ let octez_proxy = octez_client_base; octez_protocol_environment; octez_rpc; + octez_store_unix; octez_shell_services; octez_context_memory; uri; @@ -5644,6 +5645,7 @@ let _octez_proxy_server = cmdliner; lwt_exit; lwt_unix; + octez_node_config; octez_proxy; octez_proxy_server_config; octez_rpc_http_client_unix; diff --git a/opam/octez-proxy-server.opam b/opam/octez-proxy-server.opam index dec1d9d9da2d2b6b3c70b9692a971f873b9f98bd..0f712d639bdf8d1148d99c3c0cb70752ecb20a7b 100644 --- a/opam/octez-proxy-server.opam +++ b/opam/octez-proxy-server.opam @@ -14,6 +14,7 @@ depends: [ "cmdliner" { >= "1.1.0" } "lwt-exit" "lwt" { >= "5.6.0" } + "octez-node-config" "tezos-proxy" "tezos-proxy-server-config" "tezos-rpc-http-client-unix" diff --git a/opam/tezos-proxy.opam b/opam/tezos-proxy.opam index 390c5ef782f6aff49645be78e95e6e4cb72d6567..a61d072749b3b1bac8ddb7e27396861e9bc2ca89 100644 --- a/opam/tezos-proxy.opam +++ b/opam/tezos-proxy.opam @@ -15,6 +15,7 @@ depends: [ "tezos-client-base" "tezos-protocol-environment" "tezos-rpc" + "tezos-store" "tezos-shell-services" "tezos-context" "uri" { >= "2.2.0" } diff --git a/src/bin_proxy_server/dune b/src/bin_proxy_server/dune index ec4fe219f6b193d229002bc862e50628936e191a..3699ed39af19caa84abbb40899b683b567c53165 100644 --- a/src/bin_proxy_server/dune +++ b/src/bin_proxy_server/dune @@ -13,6 +13,7 @@ cmdliner lwt-exit lwt.unix + octez-node-config tezos-proxy tezos-proxy-server-config tezos-rpc-http-client-unix diff --git a/src/bin_proxy_server/main_proxy_server.ml b/src/bin_proxy_server/main_proxy_server.ml index da1cb38b9bb50b7df8ff2a811ad8564f88827909..d12561b4297e18d489c78255050aab92f911a382 100644 --- a/src/bin_proxy_server/main_proxy_server.ml +++ b/src/bin_proxy_server/main_proxy_server.ml @@ -150,6 +150,22 @@ let main_promise (config_file : string option) let* (config_from_file : Proxy_server_config.t option) = Option.map_es load_config_from_file config_file in + let open Octez_node_config in + let* (node_config : Node_config_file.t option) = + Option.map_es + Node_config_file.read + (Option.map + (fun data_dir -> + Filename.concat data_dir Node_data_version.default_config_file_name) + config_args.data_dir) + in + let (genesis_opt : Genesis.t option) = + Option.map + (fun c -> + let open Node_config_file in + c.blockchain_network.genesis) + node_config + in let open Proxy_server_config in let* { endpoint; @@ -194,7 +210,7 @@ let main_promise (config_file : string option) let* (context_index : Tezos_context.Context.index option) = Option.map_es (fun data_dir -> - let context_path = Filename.concat data_dir "context" in + let context_path = Node_data_version.context_dir data_dir in Lwt.catch (fun () -> lift_lwt @@ -216,6 +232,27 @@ let main_promise (config_file : string option) context_path)) data_dir_opt in + let store_params = + Stdlib.Option.( + let ( let* ) = bind in + let* data_dir = data_dir_opt in + let* genesis = genesis_opt in + some (data_dir, genesis)) + in + let (get_store : (unit -> Tezos_store_unix.Store.t tzresult Lwt.t) option) = + Option.map + (fun (data_dir, genesis) () -> + let context_dir = Node_data_version.context_dir data_dir + and store_dir = Node_data_version.store_dir data_dir in + Tezos_store_unix.Store.init + ~readonly:true + ~store_dir + ~context_dir + ~allow_testchains:true + genesis) + store_params + in + (* Now we build the function that the proxy server can use to build a proxy delegate later, using [Tezos_shell_context.Proxy_delegate_maker.*] functions. This lets it not depend directly on [Tezos_shell_context]: if it did, it @@ -232,6 +269,7 @@ let main_promise (config_file : string option) let sleep = Lwt_unix.sleep in Tezos_proxy.Proxy_services.build_directory printer + get_store http_ctxt (Tezos_proxy.Proxy_services.Proxy_server {sleep; sym_block_caching_time; on_disk_proxy_builder}) diff --git a/src/lib_proxy/dune b/src/lib_proxy/dune index 9c3fa4a856ac165cbfd79ca70672ca8e40cab805..a983fb8766b8ca3f0d5f463e88db932d5a629240 100644 --- a/src/lib_proxy/dune +++ b/src/lib_proxy/dune @@ -12,6 +12,7 @@ tezos-client-base tezos-protocol-environment tezos-rpc + tezos-store.unix tezos-shell-services tezos-context.memory uri) diff --git a/src/lib_proxy/proxy_services.ml b/src/lib_proxy/proxy_services.ml index ac0bbedd1fdd896cde2415ac317c5b9e30d5446e..fb376c34b1d280593cb46dbe23d3d57c0bcc60e8 100644 --- a/src/lib_proxy/proxy_services.ml +++ b/src/lib_proxy/proxy_services.ml @@ -27,7 +27,7 @@ exception Rpc_dir_creation_failure of tztrace module Directory = Resto_directory.Make (RPC_encoding) -let hash_of_block ?cache (rpc_context : #RPC_context.simple) +let hash_of_block ?cache (rpc_context : #RPC_context.simple) store_opt (chain : Tezos_shell_services.Shell_services.chain) (block : Tezos_shell_services.Block_services.block) = let open Lwt_result_syntax in @@ -35,22 +35,43 @@ let hash_of_block ?cache (rpc_context : #RPC_context.simple) Option.bind cache (fun table -> Stdlib.Hashtbl.find_opt table (chain, block)) with - | Some hash -> - (* Result is in cache *) - return hash + | Some out -> return out (* Result is in cache *) | None -> - let* hash = - Tezos_shell_services.Block_services.Empty.hash - rpc_context - ~chain - ~block - () + let* out = + match store_opt with + | None -> + let* hash = + Tezos_shell_services.Block_services.Empty.hash + rpc_context + ~chain + ~block + () + in + return (hash, None) + | Some get_store -> + let* store = get_store () in + let open Tezos_store_unix.Store in + let* chain_store = + let chain_store = main_chain_store store in + match chain with + | `Main -> return chain_store + | `Hash chain_id -> get_chain_store store chain_id + | `Test -> + Lwt.bind (Chain.testchain chain_store) (function + | Some test_chain -> + return (Chain.testchain_store test_chain) + | None -> + tzfail + (error_of_fmt "test chain is missing from store")) + in + let* block = Chain.block_of_identifier chain_store block in + return (Block.hash block, Some block) in (* Fill cache with result *) Option.iter - (fun table -> Stdlib.Hashtbl.add table (chain, block) hash) + (fun table -> Stdlib.Hashtbl.add table (chain, block) out) cache ; - return hash + return out type mode = | Light_client of Light.sources @@ -116,6 +137,7 @@ module Env_cache = module Env_cache_lwt = Ringo_lwt.Functors.Make_result (Env_cache) let build_directory (printer : Tezos_client_base.Client_context.printer) + (store_opt : (unit -> Tezos_store_unix.Store.t tzresult Lwt.t) option) (rpc_context : RPC_context.generic) (mode : mode) expected_protocol : unit RPC_directory.t = let block_hash_cache = @@ -166,18 +188,21 @@ let build_directory (printer : Tezos_client_base.Client_context.printer) in let get_env_rpc_context chain block = let open Lwt_result_syntax in - let* block_hash = - hash_of_block ?cache:block_hash_cache rpc_context chain block + let* block_hash, block_opt = + hash_of_block ?cache:block_hash_cache rpc_context store_opt chain block in let key = (chain, block_hash) in let compute_value (chain, block_hash) = let block_key = `Hash (block_hash, 0) in let* block_header = - Tezos_shell_services.Block_services.Empty.Header.shell_header - rpc_context - ~chain - ~block:block_key - () + match block_opt with + | None -> + Tezos_shell_services.Block_services.Empty.Header.shell_header + rpc_context + ~chain + ~block:block_key + () + | Some block -> return (Tezos_store_unix.Store.Block.shell_header block) in let* protocols = get_protocols ?expected_protocol rpc_context chain block_key diff --git a/src/lib_proxy/proxy_services.mli b/src/lib_proxy/proxy_services.mli index 733afde2d66e5e063fce2624e16318ff97a57513..a220eb636e680da500a8f6fd92a0c22293303f52 100644 --- a/src/lib_proxy/proxy_services.mli +++ b/src/lib_proxy/proxy_services.mli @@ -60,12 +60,14 @@ type mode = by the proxy server. Parameters are: - [printer] is used for logging. + - [store] is used to retrieve information that is available locally. - [rpc_context] is used to perform RPCs to distant endpoints. - [mode] specifies whether [octez-client] (light or proxy mode) or [tezos-proxy-server] is running. - [env] is a protocol-specific module used to create the context passed when executing a RPC. *) val build_directory : Tezos_client_base.Client_context.printer -> + (unit -> Tezos_store_unix.Store.t tzresult Lwt.t) option -> RPC_context.generic -> mode -> Protocol_hash.t option -> diff --git a/src/lib_proxy/rpc/RPC_client.ml b/src/lib_proxy/rpc/RPC_client.ml index 13377189e5fba94dc595f56b6de3c49eb159e807..f8470715c12853243fe8fc22f6462b73aa865435 100644 --- a/src/lib_proxy/rpc/RPC_client.ml +++ b/src/lib_proxy/rpc/RPC_client.ml @@ -56,7 +56,7 @@ class http_local_ctxt (printer : Tezos_client_base.Client_context.printer) RPC_context.generic = let local_ctxt = Tezos_mockup_proxy.RPC_client.local_ctxt - (Proxy_services.build_directory printer http_ctxt mode protocol) + (Proxy_services.build_directory printer None http_ctxt mode protocol) in let dispatch_local_or_distant ~debug_name ~local ~distant meth path = let open Lwt_syntax in