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

Ci/fix peers #753

Merged
merged 3 commits into from
May 28, 2024
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
29 changes: 16 additions & 13 deletions .github/workflows/update-peers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ name: Update peers
on:
workflow_dispatch:

# Disable for now.
# schedule:
# - cron: "0 0 * * MON"
schedule:
- cron: "0 0 * * MON"

concurrency:
group: update-peers-${{ github.ref }}
Expand All @@ -17,8 +16,8 @@ jobs:
strategy:
matrix:
target:
- node: "http://rpc.okp.ppnv.space:36657"
chain: "nemeton-1"
- node: "https://rpc-t.okp4.nodestake.org"
chain: "drunemeton-1"
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -41,7 +40,7 @@ jobs:
run: |
pip install requests

- name: Display the path
- name: Retrieve peers
shell: python
run: |
import requests
Expand All @@ -64,28 +63,32 @@ jobs:

def get_peer_address(peer):
peerId = peer['node_info']['id']
_, _, listen_addr, listen_port, _ = re.split("(.+:\/\/)?(.+):(\d+)", peer['node_info']['listen_addr'])
remoteIp = peer['remote_ip']
listen_address = peer['node_info']['listen_addr']
match = re.match(r"(?:.+:\/\/)?(?:.+):(\d+)", listen_address)
if match:
listen_port = match.group(1)
else:
raise ValueError("Invalid listen address: {}".format(listen_address))

match ip_class(remoteIp):
case IPClass.IPv4:
return f"{peerId}@{remoteIp}:{listen_port}"
case IPClass.IPv6:
return f"{peerId}[@{remoteIp}]:{listen_port}"
case _:
raise ValueError
raise ValueError("Invalid IP address: {}".format(remoteIp))

response = requests.get('${{ matrix.target.node }}/net_info?')
response.raise_for_status()

json_response = json.loads(response.text)
peers = map(
get_peer_address,
json_response['result']['peers'])
peers = map(get_peer_address, json_response['result']['peers'])

os.makedirs(os.path.dirname("./chains/${{ matrix.target.chain }}/"), exist_ok=True)
with open("./chains/${{ matrix.target.chain }}/peers.txt", 'w') as f:
for value in peers:
f.write(value)
f.write('\n')
f.write(f"{value}\n")

- name: Add & Commit changes
uses: EndBug/add-and-commit@v9
Expand Down
8 changes: 6 additions & 2 deletions chains/drunemeton-1/peers.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
[email protected]:26656
[email protected]:26656
[email protected]:17656
[email protected]:55156
[email protected]:26656
[email protected]:26956
[email protected]:46656
[email protected]:27656
[email protected]:26636
[email protected]:19656
[email protected]:34656
Loading