Created
February 6, 2022 21:17
-
-
Save nicholasaiello/9052585b516ef405466aba615cc02574 to your computer and use it in GitHub Desktop.
Check sync state of local node
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import subprocess | |
# TODO: support chcking s1,s2,s3 nodes | |
REMOTE_NODE_URL = 'https://api.harmony.one' | |
def get_latest_headers(api=None): | |
cmd = ['./hmy', 'blockchain', 'latest-header'] | |
if api != None: | |
cmd = cmd + ['-n', api] | |
res = subprocess.run(cmd, capture_output=True, encoding='utf8') | |
return json.loads(res.stdout).get('result') | |
def print_block_info(label, block_headers): | |
print(label + ": ", block_headers['blockNumber'], " @ ", block_headers['timestamp']) | |
local_headers = get_latest_headers() | |
beacon_headers = get_latest_headers(REMOTE_NODE_URL) | |
print_block_info("Local", local_headers) | |
print_block_info("Beacon", beacon_headers) | |
print("Delta: ", int(beacon_headers['blockNumber']) - int(local_headers['blockNumber'])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment