Skip to content

Commit

Permalink
Updates to rpc endpoints
Browse files Browse the repository at this point in the history
- Change publicnode endpoints since old ones were being deprecated
- Reduce weight of etherscan as node
- Add merkle for eth
  • Loading branch information
yabirgb committed Aug 20, 2024
1 parent d89c632 commit 6d916bf
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
- name: Set up python
uses: actions/setup-python@v2
with:
python-version: '3.10.12'
python-version: '3.12'
- name: Install dependencies
run: |
python3 -m pip install --upgrade pip setuptools wheel
Expand Down
69 changes: 69 additions & 0 deletions tests/test_nodes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
from collections import defaultdict
from decimal import Decimal, getcontext
from http import HTTPStatus
import json
import urllib3

import warnings


def test_nodes():
"""Check that all the chains have nodes with weight summing 1"""

with open('updates/info.json') as index_file:
index_data = json.load(index_file)
latest_nodes = index_data['rpc_nodes']['latest']

getcontext().prec = 6
for i in range(1,latest_nodes + 1):
per_chain_weight = defaultdict(Decimal)
with open(f'updates/rpc_nodes/v{i}.json', 'r') as f:
for rpc in json.load(f)['rpc_nodes']:
per_chain_weight[rpc['blockchain']] += Decimal(rpc['weight'])

if i == latest_nodes:
if len(rpc['endpoint']) == 0:
continue

try:
resp = urllib3.request(
"POST",
rpc['endpoint'],
json={"method":"eth_chainId","params":[],"id":1,"jsonrpc":"2.0"},
retries=1,
timeout=5,
)
except urllib3.exceptions.MaxRetryError as e:
warnings.warn(f'Failed to connect to {rpc["endpoint"]} due to {e}')

if resp.status == (HTTPStatus.TOO_MANY_REQUESTS, HTTPStatus.GATEWAY_TIMEOUT):
warnings.warn(f'Failed to connect to {rpc["endpoint"]} due to {resp.status}')
continue

try:
chain = int(resp.json()['result'], 0)
except (json.decoder.JSONDecodeError, KeyError) as e:
warnings.warn(f'Failed to read response from {rpc["endpoint"]} due to {e}')
continue

match chain:
case 1:
assert rpc['blockchain'] == 'ETH'
case 10:
assert rpc['blockchain'] == 'OPTIMISM'
case 100:
assert rpc['blockchain'] == 'GNOSIS'
case 42161:
assert rpc['blockchain'] == 'ARBITRUM_ONE'
case 534352:
assert rpc['blockchain'] == 'SCROLL'
case 137:
assert rpc['blockchain'] == 'POLYGON_POS'
case 137:
assert rpc['blockchain'] == 'POLYGON_POS'
case 8453:
assert rpc['blockchain'] == 'BASE'
case _:
raise Exception(f'Unexpected chain version for {rpc}')

assert all(weight == 1 for weight in per_chain_weight.values()), f'Weights do not add for v{i}: {per_chain_weight=}'
2 changes: 1 addition & 1 deletion updates/info.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"spam_assets":{"latest":4},"rpc_nodes":{"latest":5},"contracts":{"latest":0},"global_addressbook":{"latest":0},"accounting_rules":{"latest":3},"location_asset_mappings":{"latest":3},"location_unsupported_assets":{"latest":1}}
{"spam_assets":{"latest":4},"rpc_nodes":{"latest":6},"contracts":{"latest":0},"global_addressbook":{"latest":0},"accounting_rules":{"latest":3},"location_asset_mappings":{"latest":3},"location_unsupported_assets":{"latest":1}}
1 change: 1 addition & 0 deletions updates/rpc_nodes/v6.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"rpc_nodes":[{"name":"etherscan","endpoint":"","weight":0.05,"owned":false,"active":true,"blockchain":"ETH"},{"name":"merkle","endpoint":"https://eth.merkle.io","weight":0.35,"owned":false,"active":true,"blockchain":"ETH"},{"name":"cloudflare","endpoint":"https://cloudflare-eth.com/","weight":0.2,"owned":false,"active":true,"blockchain":"ETH"},{"name":"LlamaNodes","endpoint":"https://eth.llamarpc.com","weight":0.2,"owned":false,"active":true,"blockchain":"ETH"},{"name":"flashbots","endpoint":"https://rpc.flashbots.net/","weight":0.05,"owned":false,"active":true,"blockchain":"ETH"},{"name":"ankr","endpoint":"https://rpc.ankr.com/eth","weight":0.1,"owned":false,"active":true,"blockchain":"ETH"},{"name":"myetherwallet","endpoint":"https://nodes.mewapi.io/rpc/eth","weight":0.05,"owned":false,"active":true,"blockchain":"ETH"},{"name":"optimism etherscan","endpoint":"","weight":0.05,"owned":false,"active":true,"blockchain":"OPTIMISM"},{"name":"optimism official","endpoint":"https://mainnet.optimism.io","weight":0.2,"owned":false,"active":true,"blockchain":"OPTIMISM"},{"name":"PublicNode","endpoint":"https://optimism-rpc.publicnode.com","weight":0.2,"owned":false,"active":true,"blockchain":"OPTIMISM"},{"name":"optimism blastapi","endpoint":"https://optimism-mainnet.public.blastapi.io","weight":0.2,"owned":false,"active":true,"blockchain":"OPTIMISM"},{"name":"optimism ankr","endpoint":"https://rpc.ankr.com/optimism","weight":0.1,"owned":false,"active":true,"blockchain":"OPTIMISM"},{"name":"optimism 1rpc","endpoint":"https://1rpc.io/op","weight":0.15,"owned":false,"active":true,"blockchain":"OPTIMISM"},{"name":"optimism meowrpc","endpoint":"https://optimism.meowrpc.comp","weight":0.1,"owned":false,"active":true,"blockchain":"OPTIMISM"},{"name":"polygon pos etherscan","endpoint":"","weight":0.05,"owned":false,"active":true,"blockchain":"POLYGON_POS"},{"name":"ankr","endpoint":"https://rpc.ankr.com/polygon","weight":0.2,"owned":false,"active":true,"blockchain":"POLYGON_POS"},{"name":"BlockPi","endpoint":"https://polygon.blockpi.network/v1/rpc/public","weight":0.2,"owned":false,"active":true,"blockchain":"POLYGON_POS"},{"name":"PublicNode","endpoint":"https://polygon-bor-rpc.publicnode.com","weight":0.2,"owned":false,"active":true,"blockchain":"POLYGON_POS"},{"name":"DefiLlama","endpoint":"https://polygon.llamarpc.com","weight":0.3,"owned":false,"active":true,"blockchain":"POLYGON_POS"},{"name":"1rpc","endpoint":"https://1rpc.io/matic","weight":0.05,"owned":false,"active":true,"blockchain":"POLYGON_POS"},{"name":"arbitrum one etherscan","endpoint":"","weight":0.05,"owned":0,"active":1,"blockchain":"ARBITRUM_ONE"},{"name":"arbitrum one ankr","endpoint":"https://rpc.ankr.com/arbitrum","weight":0.1,"owned":0,"active":1,"blockchain":"ARBITRUM_ONE"},{"name":"LlamaNodes","endpoint":"https://arbitrum.llamarpc.com","weight":0.3,"owned":0,"active":1,"blockchain":"ARBITRUM_ONE"},{"name":"arbitrum one BlockPi","endpoint":"https://arbitrum.blockpi.network/v1/rpc/public","weight":0.2,"owned":0,"active":1,"blockchain":"ARBITRUM_ONE"},{"name":"arbitrum one PublicNode","endpoint":"https://arbitrum-one-rpc.publicnode.com","weight":0.2,"owned":0,"active":1,"blockchain":"ARBITRUM_ONE"},{"name":"arbitrum one 1rpc","endpoint":"https://1rpc.io/arb","weight":0.1,"owned":0,"active":1,"blockchain":"ARBITRUM_ONE"},{"name":"meowrpc","endpoint":"https://arbitrum.meowrpc.com","weight":0.05,"owned":0,"active":1,"blockchain":"ARBITRUM_ONE"},{"name":"base etherscan","endpoint":"","weight":0.05,"owned":0,"active":1,"blockchain":"BASE"},{"name":"base ankr","endpoint":"https://rpc.ankr.com/base","weight":0.15,"owned":0,"active":1,"blockchain":"BASE"},{"name":"PublicNode","endpoint":"https://base-rpc.publicnode.com","weight":0.2,"owned":0,"active":1,"blockchain":"BASE"},{"name":"base BlockPi","endpoint":"https://base.blockpi.network/v1/rpc/public","weight":0.2,"owned":0,"active":1,"blockchain":"BASE"},{"name":"base 1rpc","endpoint":"https://1rpc.io/base","weight":0.1,"owned":0,"active":1,"blockchain":"BASE"},{"name":"LlamaNodes","endpoint":"https://base.llamarpc.com","weight":0.3,"owned":0,"active":1,"blockchain":"BASE"},{"name":"gnosis etherscan","endpoint":"","weight":0.05,"owned":0,"active":1,"blockchain":"GNOSIS"},{"name":"gnosis ankr","endpoint":"https://rpc.ankr.com/gnosis","weight":0.2,"owned":0,"active":1,"blockchain":"GNOSIS"},{"name":"gnosis BlockPi","endpoint":"https://gnosis.blockpi.network/v1/rpc/public","weight":0.2,"owned":0,"active":1,"blockchain":"GNOSIS"},{"name":"gnosis PublicNode","endpoint":"https://gnosis-rpc.publicnode.com","weight":0.2,"owned":0,"active":1,"blockchain":"GNOSIS"},{"name":"gnosis 1rpc","endpoint":"https://1rpc.io/gnosis","weight":0.2,"owned":0,"active":1,"blockchain":"GNOSIS"},{"name":"gnosischain","endpoint":"https://rpc.gnosischain.com","weight":0.15,"owned":0,"active":1,"blockchain":"GNOSIS"},{"name":"scroll etherscan","endpoint":"","weight":0.05,"owned":0,"active":1,"blockchain":"SCROLL"},{"name":"scroll official","endpoint":"https://rpc.scroll.io/","weight":0.3,"owned":0,"active":1,"blockchain":"SCROLL"},{"name":"scroll ankr","endpoint":"https://rpc.ankr.com/scroll","weight":0.2,"owned":0,"active":1,"blockchain":"SCROLL"},{"name":"scroll blockpi","endpoint":"https://scroll.blockpi.network/v1/rpc/public","weight":0.2,"owned":0,"active":1,"blockchain":"SCROLL"},{"name":"scroll drpc","endpoint":"https://scroll.drpc.org","weight":0.1,"owned":0,"active":1,"blockchain":"SCROLL"},{"name":"chainstacklabs","endpoint":"https://scroll-mainnet.chainstacklabs.com","weight":0.15,"owned":0,"active":1,"blockchain":"SCROLL"}]}

0 comments on commit 6d916bf

Please sign in to comment.