Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove stale endpoints #3409

Merged
merged 2 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions 8ball/chain.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,6 @@
{
"address": "https://8ball-rpc.genznodes.dev/",
"provider": "genznodes"
},
{
"address": "https://rpc-8ball.comunitynode.my.id",
"provider": "ComunityNode"
},
{
"address": "https://rpc-8ball.nodine.id",
"provider": "Nodine.ID"
},
{
"address": "https://rpc.8ball.nodexcapital.com",
"provider": "NodeX Validator"
}
],
"rest": [
Expand All @@ -129,17 +117,9 @@
"address": "https://8ball-api.genznodes.dev/",
"provider": "genznodes"
},
{
"address": "https://api-8ball.comunitynode.my.id",
"provider": "ComunityNode"
},
{
"address": "https://api-8ball.nodine.id/",
"provider": "Nodine.ID"
},
{
"address": "https://rest.8ball.nodexcapital.com",
"provider": "NodeX Validator"
}
],
"grpc": [
Expand Down
140 changes: 140 additions & 0 deletions _scripts/remove-stale-endpoints.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
import json
import os
import random as rand
import time
from multiprocessing import Pool

import requests

current_dir = os.path.dirname(os.path.realpath(__file__))
parent_dir = os.path.dirname(current_dir)
folders = [
folder
for folder in os.listdir(parent_dir)
if os.path.isdir(os.path.join(parent_dir, folder))
]

IGNORE_FOLDERS: list[str] = [
"_IBC",
"_memo_keys",
"_non-cosmos",
"_scripts",
"_template",
".github",
"testnets",
".git",
".mypy_cache",
]

IGNORE_CHAINS: list[str] = []

epoch_time = int(time.time()) * 1000
thirty_days_ago = epoch_time - (60 * 60 * 24 * 10 * 1_000)

TIMEOUT_SECONDS = 10


# endpoint_type == 'rpc' or 'rest'
def remove_endpoint(folder: str, endpoint_url, endpoint_type: str, iter_num: int = 0):
chain_dir = os.path.join(parent_dir, folder, f"chain.json")

if iter_num > 25:
print(f"ISSUE: {folder} {endpoint_type} {endpoint_url}")
return

with open(chain_dir, "r") as f:
try:
chain_data = json.load(f)
except Exception as e:
# multiprocessing 'patch'
time.sleep(rand.uniform(0.1, 5.0))
remove_endpoint(folder, endpoint_url, endpoint_type, iter_num + 1)
return

print(f"[-] {folder} {endpoint_type} {endpoint_url}")
apis: dict = chain_data.get("apis", {})
if len(apis) == 0:
return

# [{"address": "https://api.comdex.audit.one/rest","provider": "audit"},...]
endpoints = apis.get(endpoint_type, [])

apis[endpoint_type] = [
endpoint
for endpoint in endpoints
if endpoint.get("address", "") != endpoint_url
]
chain_data["apis"] = apis

with open(chain_dir, "w") as f:
json.dump(chain_data, f, indent=2, ensure_ascii=False)


def do_last_time(folder, _type, addr, last_time_endpoints):
# check when the last time it was on. If it is >30 days, remove from chain.json
last_online_time = last_time_endpoints[addr].get("lastSuccessAt", -1)

if last_online_time < thirty_days_ago:
try:
if addr.endswith("/"):
addr = addr[:-1]

query = requests.get(f"{addr}/", timeout=TIMEOUT_SECONDS)
if query.status_code not in [200, 501]: # 501 = default REST API
remove_endpoint(folder, addr, _type)

except Exception:
remove_endpoint(folder, addr, _type)


def api_check(folder: str, apis: dict) -> list[str]:
tasks = []
res = requests.get(f"https://status.cosmos.directory/{folder}").json()

for _type in ["rpc", "rest"]:
last_time_endpoints = res[_type]["current"]

for rpc1 in apis[_type]:
for rpc2 in last_time_endpoints.keys():
addr = rpc1["address"]
if addr == rpc2:
tasks.append([folder, _type, addr, last_time_endpoints])

return tasks


def main():
to_check: list[str, dict[str, str]] = []

for idx, folder in enumerate(folders):
if folder in IGNORE_FOLDERS + IGNORE_CHAINS:
continue

path = f"{parent_dir}/{folder}/chain.json"
if not os.path.exists(path):
continue

try:
apis: dict = json.loads(open(path).read())
except Exception:
print(f"[!] {folder} chain.json issue")
continue

apis = apis.get("apis", {}) # rpc, rest, grpc

if len(apis) == 0:
continue

to_check.append([folder, apis])

with Pool(os.cpu_count() * 2) as p:
tasks = p.starmap(api_check, to_check)

tasks = [task for sublist in tasks for task in sublist]

with Pool(os.cpu_count() * 2) as p:
p.starmap(do_last_time, tasks)


if __name__ == "__main__":
main()
24 changes: 0 additions & 24 deletions acrechain/chain.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,26 +128,14 @@
"address": "https://rpc.acre.nodestake.top",
"provider": "nodestake"
},
{
"address": "https://rpc-acre.d-stake.xyz",
"provider": "D-stake"
},
{
"address": "https://rpc-acre.synergynodes.com",
"provider": "Synergy Nodes"
},
{
"address": "https://acre-rpc.agoranodes.com",
"provider": "AgoraNodes"
},
{
"address": "https://acrechain-mainnet-rpc.autostake.com:443",
"provider": "AutoStake 🛡️ Slash Protected"
},
{
"address": "https://acre-rpc.genznodes.dev",
"provider": "genznodes"
},
{
"address": "https://rpc.acre.tcnetwork.io",
"provider": "TC Network"
Expand All @@ -162,10 +150,6 @@
}
],
"rest": [
{
"address": "https://api-acre.d-stake.xyz",
"provider": "D-stake"
},
{
"address": "https://lcd-acre.synergynodes.com",
"provider": "Synergy Nodes"
Expand All @@ -174,14 +158,6 @@
"address": "https://acrechain-mainnet-lcd.autostake.com:443",
"provider": "AutoStake 🛡️ Slash Protected"
},
{
"address": "https://acre-rest.agoranodes.com",
"provider": "AgoraNodes"
},
{
"address": "https://acre-api.genznodes.dev",
"provider": "genznodes"
},
{
"address": "https://rest.acre.tcnetwork.io",
"provider": "TC Network"
Expand Down
12 changes: 0 additions & 12 deletions agoric/chain.json
Original file line number Diff line number Diff line change
Expand Up @@ -134,18 +134,10 @@
"address": "https://agoric-rpc.0base.dev",
"provider": "0base.vc"
},
{
"address": "https://agoric.mellifera.network:26657",
"provider": "MELLIFERA"
},
{
"address": "https://agoric-rpc.stakeangle.com",
"provider": "StakeAngle"
},
{
"address": "agoric-rpc.nodeasy.com:31531",
"provider": "Nodeasy"
},
{
"address": "https://agoric-rpc.w3coins.io",
"provider": "w3coins"
Expand Down Expand Up @@ -187,10 +179,6 @@
"address": "https://agoric-rest.0base.dev",
"provider": "0base.vc"
},
{
"address": "https://agoric.mellifera.network:1317",
"provider": "MELLIFERA"
},
{
"address": "https://agoric-api.w3coins.io",
"provider": "w3coins"
Expand Down
24 changes: 0 additions & 24 deletions archway/chain.json
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,6 @@
"address": "https://rpc-1.archway.nodes.guru",
"provider": "Nodes.Guru"
},
{
"address": "http://archway.rpc.nodersteam.com:26657",
"provider": "[NODERS]TEAM"
},
{
"address": "https://archway.rpc.silknodes.io/",
"provider": "Silk Nodes"
Expand Down Expand Up @@ -302,10 +298,6 @@
"address": "https://archway-rpc.stake-town.com",
"provider": "StakeTown"
},
{
"address": "https://archway-rpc.huginn.tech",
"provider": "Huginn"
},
{
"address": "https://archway-rpc.0base.dev",
"provider": "0base.vc"
Expand All @@ -330,10 +322,6 @@
"address": "https://rpc.archway.stakeup.tech",
"provider": "StakeUp"
},
{
"address": "https://rpc-archway-mainnet.testnet-pride.com",
"provider": "TestnetPride"
},
{
"address": "https://archway.api.trivium.network:26657",
"provider": "TriviumX | Architech"
Expand All @@ -356,10 +344,6 @@
"address": "https://m-archway.api.utsa.tech",
"provider": "𝐥𝐞𝐬𝐧𝐢𝐤 | 𝐔𝐓𝐒𝐀"
},
{
"address": "http://archway.api.nodersteam.com:1317",
"provider": "[NODERS]TEAM"
},
{
"address": "https://api-1.archway.nodes.guru",
"provider": "Nodes.Guru"
Expand Down Expand Up @@ -412,10 +396,6 @@
"address": "https://archway-api.stake-town.com",
"provider": "StakeTown"
},
{
"address": "https://archway-lcd.huginn.tech",
"provider": "Huginn"
},
{
"address": "https://archway-rest.0base.dev",
"provider": "0base.vc"
Expand All @@ -436,10 +416,6 @@
"address": "https://api.archway.stakeup.tech",
"provider": "StakeUp"
},
{
"address": "https://api-archway-mainnet.testnet-pride.com",
"provider": "TestnetPride"
},
{
"address": "https://archway.api.trivium.network:1317",
"provider": "TriviumX | Architech"
Expand Down
24 changes: 0 additions & 24 deletions arkh/chain.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,6 @@
{
"address": "https://rpc.arkh.nodestake.top",
"provider": "NodeStake"
},
{
"address": "https://rpc-arkhadian.comunitynode.my.id",
"provider": "ComunityNode"
},
{
"address": "https://arkh-rpc.kynraze.com",
"provider": "Kynraze"
},
{
"address": "https://rpc.arkh.nodexcapital.com",
"provider": "NodeX Validator"
}
],
"rest": [
Expand All @@ -96,18 +84,6 @@
{
"address": "https://api.arkh.nodestake.top",
"provider": "NodeStake"
},
{
"address": "https://api-arkhadian.comunitynode.my.id",
"provider": "ComunityNode"
},
{
"address": "https://arkh-api.kynraze.com",
"provider": "Kynraze"
},
{
"address": "https://rest.arkh.nodexcapital.com",
"provider": "NodeX Validator"
}
],
"grpc": [
Expand Down
Loading