This PR adds a sender-based rate limiter to proxyd. This rate limiter throttles eth_sendRawTransaction requests based on sender in order to prevent abusive behavior on the sequencer.
Integration tests have been added to test this functionality.
Integrates the custom rate limiter in the previous PR into the rest of the application. Also takes the opportunity to clean up how we instantiate Redis clients so that we can share them among multiple different services.
There are some config changes in this PR. Specifically, you must specify a `base_rate` and `base_interval` in the rate limit config.
* proxyd: Add batch size metric and configurable max
The max batch size will be overwritten if it is over `MaxBatchRPCCallsHardLimit`.
Builds on https://github.com/ethereum-optimism/optimism/pull/3544.
* changeset
* fix lint
* fix test
* proxyd: Add customizable whitelist error message
Alchemy is asking for this so that we can include their affiliate link.
* add missing test case
* fix error message
* goimports
* proxyd: Fix error message in tests
The custom error message wasn't being carried over in batch responses.
* review fixes
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
* proxyd: Add frontend rate limiting
To give us more flexibiltiy with rate limiting, proxyd now supports rate limiting of client (frontend) requests in addition to upstream (backend) requests. This PR also gives us the ability to exempt certain user agents/origins from rate limiting.
* lint
We never want to expose Geth's accounts to the public internet, so proxyd will now return `[]` for `eth_accounts` RPC calls without hitting the backend.
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Fixes a panic in the websocket proxyd logic. Normally, the `clientPump` and `backendPump` methods in `WSProxier` send data in one direction. However, when the client sends an invalid RPC, the `clientPump` will send a response _directly to the client_ in order to avoid unnecessary roundtrips to the backend. This could be interleaved with concurrent writes to the client's WS in `backendPump`, and would cause a panic in the WS library.
To test this, this PR includes a dedicated integration test that reliably triggers the issue. In addition, this PR adds additional testing for WS functionality.
- Adopts Go workspaces for future compatibility with the Bedrock move into the monorepo
- Moves Go packages to the root of the repo in order to fix import paths
- Rewrites existing Go import paths
- Removes Stackman, since it's not needed anymore
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>