Skip to content

Commit

Permalink
Merge pull request #10 from kasrakhosravi/main
Browse files Browse the repository at this point in the history
feat: add erpc as rpc proxy and caching tool for wvm
  • Loading branch information
charmful0x authored Aug 16, 2024
2 parents 9ef3eee + 59132a4 commit 8cfae5f
Show file tree
Hide file tree
Showing 3 changed files with 163 additions and 0 deletions.
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,30 @@ To start archiving your network block data on WeaveVM:
5. Choose a unique `archive_pool_address` that's different from your `archiver_address`.
6. Set up your PlanetScale DB according to `db_schema.sql`.

### RPC Proxy and Caching

You can use [eRPC](https://github.com/erpc/erpc) to cache, load-balance and failover between as many RPC endpoints and use eRPC's proxy URL in each network's config for WeaveVM. This will increase performance and resiliency and reduce RPC usage cost while fetching network's block data via WeaveVM.

```bash
# modify erpc.yaml
cp erpc.yaml.dist erpc.yaml
code erpc.yaml

# run docker-compose
docker-compose up -d
```

Finally, you can set eRPC's proxy URL in each relative network config.
```optimism.json
{
"name": "Optimism",
"network_chain_id": 10,
"network_rpc": "http://erpc:4000/main/evm/10",
...
}
```


## How it works

The WeaveVM Archiver node operates as follows:
Expand Down
15 changes: 15 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: "3"

networks:
erpc:
driver: bridge

services:
erpc:
image: ghcr.io/erpc/erpc:latest
platform: linux/amd64
volumes:
- "${PWD}/erpc.yaml:/root/erpc.yaml"
ports:
- "4000:4000"
restart: always
124 changes: 124 additions & 0 deletions erpc.yaml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
logLevel: warn
database:
evmJsonRpcCache:
driver: memory
# driver: postgresql
# postgresql:
# connectionUri: >-
# postgres://YOUR_USERNAME_HERE:YOUR_PASSWORD_HERE@your.postgres.hostname.here.com:5432/your_database_name
# table: rpc_cache
server:
httpHost: 0.0.0.0
httpPort: 4000
metrics:
enabled: true
host: 0.0.0.0
port: 4001
projects:
- id: main
networks:
- architecture: evm
evm:
chainId: 1
failsafe:
timeout:
duration: 30s
retry:
maxCount: 3
delay: 500ms
backoffMaxDelay: 10s
backoffFactor: 0.3
jitter: 500ms
hedge:
delay: 3000ms
maxCount: 2
- architecture: evm
evm:
chainId: 42161
failsafe:
timeout:
duration: 30s
retry:
maxCount: 5
delay: 500ms
backoffMaxDelay: 10s
backoffFactor: 0.3
jitter: 200ms
hedge:
delay: 1000ms
maxCount: 2
upstreams:
- id: alchemy-multi-chain-example-1
endpoint: alchemy://XXXX_YOUR_ALCHEMY_API_KEY_HERE_XXXX
rateLimitBudget: global
failsafe:
timeout:
duration: 15s
retry:
maxCount: 2
delay: 1000ms
backoffMaxDelay: 10s
backoffFactor: 0.3
jitter: 500ms
- id: blastapi-chain-42161
type: evm
endpoint: https://arbitrum-one.blastapi.io/xxxxxxx-xxxxxx-xxxxxxx
rateLimitBudget: global-blast
evm:
chainId: 42161
failsafe:
timeout:
duration: 15s
retry:
maxCount: 2
delay: 1000ms
backoffMaxDelay: 10s
backoffFactor: 0.3
jitter: 500ms
- id: blastapi-chain-1
type: evm
endpoint: https://eth-mainnet.blastapi.io/xxxxxxx-xxxxxx-xxxxxxx
rateLimitBudget: global-blast
evm:
chainId: 1
failsafe:
timeout:
duration: 15s
retry:
maxCount: 2
delay: 1000ms
backoffMaxDelay: 10s
backoffFactor: 0.3
jitter: 500ms
- id: quiknode-chain-42161
type: evm
endpoint: https://xxxxxx-xxxxxx.arbitrum-mainnet.quiknode.pro/xxxxxxxxxxxxxxxxxxxxxxxx/
rateLimitBudget: global-quicknode
evm:
chainId: 42161
failsafe:
timeout:
duration: 15s
retry:
maxCount: 2
delay: 1000ms
backoffMaxDelay: 10s
backoffFactor: 0.3
jitter: 500ms
rateLimiters:
budgets:
- id: default-budget
rules:
- method: '*'
maxCount: 10000
period: 1s
- id: global-blast
rules:
- method: '*'
maxCount: 1000
period: 1s
- id: global-quicknode
rules:
- method: '*'
maxCount: 300
period: 1s

0 comments on commit 8cfae5f

Please sign in to comment.