web3-proxy/README.md

71 lines
2.4 KiB
Markdown
Raw Normal View History

2022-03-05 06:55:16 +03:00
# web3-proxy
2022-03-05 07:59:11 +03:00
quick and dirty proxy for ethereum rpcs (or similar)
2022-03-05 06:58:00 +03:00
2022-05-07 04:53:16 +03:00
Signed transactions are sent to the configured private RPC (eden, flashbots, etc.). All other requests are sent to an RPC server on the latest block (alchemy, moralis, rivet, your own node, or one of many other providers).
2022-03-05 07:59:11 +03:00
```
2022-05-07 04:53:16 +03:00
cargo run --release -- --help
2022-03-05 07:59:11 +03:00
```
2022-03-05 06:58:00 +03:00
```
2022-05-07 04:53:16 +03:00
Finished release [optimized] target(s) in 0.13s
Running `target/release/web3-proxy --help`
Usage: web3-proxy [--listen-port <listen-port>] [--rpc-config-path <rpc-config-path>]
2022-03-05 06:58:00 +03:00
2022-05-07 04:53:16 +03:00
Reach new heights.
2022-03-05 06:58:00 +03:00
Options:
2022-05-07 04:53:16 +03:00
--listen-port what port the proxy should listen on
--rpc-config-path what port the proxy should listen on
2022-03-05 06:58:00 +03:00
--help display usage information
2022-03-05 07:59:11 +03:00
```
2022-03-05 06:58:00 +03:00
```
2022-05-07 04:53:16 +03:00
cargo run --release
2022-03-05 07:59:11 +03:00
```
```
2022-05-07 04:53:16 +03:00
curl -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"web3_clientVersion","params":[],"id":67}' 127.0.0.1:8544/eth
2022-03-05 07:59:11 +03:00
```
2022-04-28 22:30:22 +03:00
## Flame Graphs
$ cat /proc/sys/kernel/kptr_restrict
1
$ echo 0 |sudo tee /proc/sys/kernel/kptr_restrict
0
$ CARGO_PROFILE_RELEASE_DEBUG=true cargo flamegraph
## Load Testing
Test the proxy:
2022-05-07 04:53:16 +03:00
wrk -s ./data/wrk/getBlockNumber.lua -t12 -c400 -d30s --latency http://127.0.0.1:8544
wrk -s ./data/wrk/getLatestBlockByNumber.lua -t12 -c400 -d30s --latency http://127.0.0.1:8544
Test geth:
2022-04-28 22:30:22 +03:00
wrk -s ./data/wrk/getBlockNumber.lua -t12 -c400 -d30s --latency http://127.0.0.1:8545
wrk -s ./data/wrk/getLatestBlockByNumber.lua -t12 -c400 -d30s --latency http://127.0.0.1:8545
Test erigon:
2022-04-28 22:30:22 +03:00
wrk -s ./data/wrk/getBlockNumber.lua -t12 -c400 -d30s --latency http://127.0.0.1:8945
wrk -s ./data/wrk/getLatestBlockByNumber.lua -t12 -c400 -d30s --latency http://127.0.0.1:8945
2022-03-05 07:59:11 +03:00
## Todo
- [x] simple proxy
2022-05-07 04:53:16 +03:00
- [x] better locking. when lots of requests come in, we seem to be in the way of block updates
2022-03-05 07:59:11 +03:00
- [ ] proper logging
2022-05-07 04:53:16 +03:00
- [x] load balance between multiple RPC servers
- [x] support more than just ETH
- [x] option to disable private rpc and send everything to primary
- [x] health check nodes by block height
2022-03-05 07:59:11 +03:00
- [ ] measure latency to nodes
2022-05-07 04:53:16 +03:00
- [x] Dockerfile
- [ ] testing getLatestBlockByNumber is not great because the latest block changes and so one run is likely to be different than another
- [ ] if a request gets a socket timeout, try on another server
- maybe always try at least two servers in parallel? and then return the first? or only if the first one doesn't respond very quickly?