I need to rate limit our tendermint-rpc HttpClient to not DOS our cometbft node. Unfortunately, tendermint_rpc::client::http::Builder and tendermint_rpc::client::http::HttpClient do not provide ways to set a tower middleware like its RateLimitLayer.
I am going to try and work around it using the techniques described in this reqwest issue tracker here: https://github.com/seanmonstar/reqwest/issues/491 (specifically using tower::ServiceBuilder::service_fn), but that requires a lot of extra boilerplate at the application level.
Definition of "done"
Being able to rate-limit outgoing requests over http. The general solution would be to allow setting arbitrary tower::Services, but rate limiting would be great.
Description
I need to rate limit our tendermint-rpc
HttpClient
to not DOS our cometbft node. Unfortunately,tendermint_rpc::client::http::Builder
andtendermint_rpc::client::http::HttpClient
do not provide ways to set a tower middleware like itsRateLimitLayer
.Prior art for how this could be achieved is for example by providing a
set_middleware
method as is done by jsonrpsee here: https://docs.rs/jsonrpsee-http-client/0.22.5/jsonrpsee_http_client/struct.HttpClientBuilder.html#method.set_http_middlewareInternally, they wrap their hyper client in the provided
ServiceBuilder
: https://docs.rs/jsonrpsee-http-client/0.22.5/src/jsonrpsee_http_client/transport.rs.html#254I am going to try and work around it using the techniques described in this reqwest issue tracker here: https://github.com/seanmonstar/reqwest/issues/491 (specifically using
tower::ServiceBuilder::service_fn
), but that requires a lot of extra boilerplate at the application level.Definition of "done"
Being able to rate-limit outgoing requests over http. The general solution would be to allow setting arbitrary
tower::Service
s, but rate limiting would be great.