tezos-proxy-server: read store to save a RPC call to the node, when possible
In %"Light mode v2 + Proxy/Light pimping", we made tezos-proxy-server
read the node's data-dir. This contributed to reducing the node's load, by avoiding many RPCs. But tezos-proxy-server
is still doing an RPC call to get the block's header here in protocol code. This issue concerns getting rid of all RPC communications (in terms of tezos-proxy-server
CLI, this amounts to making --endpoint
exclusive with --data-dir
).
We could instead read the node's store (data-dir/store
) and load it with Tezos_store.Store.init, something like this:
let init ~data_dir =
let ( / ) = Filename.concat in
let context_dir = data_dir ( / ) "context" in
let store_dir = data_dir ( / ) "store" in
Tezos_store.Store.init
~readonly:true
~store_dir
~context_dir
~allow_testchains:true
Then we would be able to use lib_store's read_block_opt
to obtain the header of a given block hash.
but this causes two problems:
- we need to pass a
Genesis.t
value toStore.init
. Victor indicated here how to obtain one, but it inverts dependencies, since we would need to call code inbin_node
, that is why it was not done in the first version of tezos-proxy-server+data-dir reading. - it adds a dependency to
tezos-store
intezos-proxy
. Becausetezos-store
depends on*unix
stuff, we can't do that; as it would break the possibility of compilingtezos-client
to Javascript (work by @hhugo1). To circumvent that, we can either: 1/ move out fromlib_proxy
things that are specific totezos-proxy-server
to a new librarytezos-proxy.server
(on the model oftezos-proxy.rpc
) where*unix
dependencies are fine. or we can 2/ move the dependency totezos-store
tosrc/bin_proxy_server
(on the model of the dependency totezos-shell-context
, which is limited tosrc/bin_proxy_server
even if it is really used insrc/lib_proxy
).
But it would be good to do it, it would save RPC calls to the node, hereby reducing IO consumption of the node.