Skip to content

Commit

Permalink
Max Faucet Runs == 3 (#1560)
Browse files Browse the repository at this point in the history
add exceptions
  • Loading branch information
ifrit98 authored Oct 27, 2023
1 parent bd3307d commit 292b6a9
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions bittensor/extrinsics/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,14 @@ def burned_register_extrinsic(
)


class MaxSuccessException(Exception):
pass


class MaxAttemptsException(Exception):
pass


def run_faucet_extrinsic(
subtensor: "bittensor.subtensor",
wallet: "bittensor.wallet",
Expand Down Expand Up @@ -384,6 +392,7 @@ def run_faucet_extrinsic(

# Attempt rolling registration.
attempts = 1
successes = 1
while True:
try:
pow_result = None
Expand Down Expand Up @@ -441,6 +450,9 @@ def run_faucet_extrinsic(
bittensor.__console__.print(
f":cross_mark: [red]Failed[/red]: Error: {response.error_message}"
)
if attempts == max_allowed_attempts:
raise MaxAttemptsException
attempts += 1

# Successful registration
else:
Expand All @@ -450,5 +462,15 @@ def run_faucet_extrinsic(
)
old_balance = new_balance

if successes == 3:
raise MaxSuccessException
successes += 1

except KeyboardInterrupt:
return True, "Done"

except MaxSuccessException:
return True, f"Max successes reached: {3}"

except MaxAttemptedException:
return False, f"Max attempts reached: {max_allowed_attempts}"

0 comments on commit 292b6a9

Please sign in to comment.