From 78cc6eaa4debdcb8f3486d81ce5e00e662cf0936 Mon Sep 17 00:00:00 2001 From: Yabir Benchakhtir Date: Mon, 19 Aug 2024 19:31:58 +0200 Subject: [PATCH] Updates to rpc endpoints - Change publicnode endpoints since old ones were being deprecated - Reduce weight of etherscan as node - Add merkle for eth --- .github/workflows/verify.yml | 2 +- tests/test_nodes.py | 69 ++++++++++++++++++++++++++++++++++++ updates/info.json | 2 +- updates/rpc_nodes/v6.json | 1 + 4 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 tests/test_nodes.py create mode 100644 updates/rpc_nodes/v6.json diff --git a/.github/workflows/verify.yml b/.github/workflows/verify.yml index a3001a4..dbac123 100644 --- a/.github/workflows/verify.yml +++ b/.github/workflows/verify.yml @@ -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 diff --git a/tests/test_nodes.py b/tests/test_nodes.py new file mode 100644 index 0000000..bdc0366 --- /dev/null +++ b/tests/test_nodes.py @@ -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=}' diff --git a/updates/info.json b/updates/info.json index b6dd56d..cc83a03 100644 --- a/updates/info.json +++ b/updates/info.json @@ -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}} \ No newline at end of file diff --git a/updates/rpc_nodes/v6.json b/updates/rpc_nodes/v6.json new file mode 100644 index 0000000..522af10 --- /dev/null +++ b/updates/rpc_nodes/v6.json @@ -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"}]} \ No newline at end of file