Skip to content

Commit

Permalink
Merge pull request #64 from xian-network/crosschainer-patch-10
Browse files Browse the repository at this point in the history
Sometimes its busy.
  • Loading branch information
crosschainer authored Apr 3, 2024
2 parents ee72f64 + d6306fd commit 2a94c08
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions src/xian/tools/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,30 @@ def download_and_extract(self, url, target_path):

os.remove(tar_path)

def get_node_info(self, seed_node):
attempts = 0
max_attempts = 10
timeout = 3 # seconds
while attempts < max_attempts:
try:
response = requests.get(f'http://{seed_node}:26657/status', timeout=timeout)
response.raise_for_status() # Raises stored HTTPError, if one occurred.
return response.json()
except requests.exceptions.HTTPError as err:
print(f"HTTP error: {err}")
except requests.exceptions.ConnectionError as err:
print(f"Connection error: {err}")
except requests.exceptions.Timeout as err:
print(f"Timeout error: {err}")
except requests.exceptions.RequestException as err:
print(f"Error: {err}")

attempts += 1
sleep(1) # wait 1 second before trying again

return None # or raise an Exception indicating the request ultimately failed


def main(self):
# Make sure this is run in the tools directory
os.chdir(os.path.dirname(os.path.abspath(__file__)))
Expand All @@ -67,9 +91,12 @@ def main(self):
config['consensus']['create_empty_blocks'] = False

if self.args.seed_node:
info = requests.get(f'http://{self.args.seed_node}:26657/status')
id = info.json()['result']['node_info']['id']
config['p2p']['seeds'] = f'{id}@{self.args.seed_node}:26656'
info = self.get_node_info(self.args.seed_node)
if info:
id = info['result']['node_info']['id']
config['p2p']['seeds'] = f'{id}@{self.args.seed_node}:26656'
else:
print("Failed to get node information after 10 attempts.")

if self.args.moniker:
config['moniker'] = self.args.moniker
Expand Down

0 comments on commit 2a94c08

Please sign in to comment.