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

Fix validators check #304

Merged
merged 1 commit into from
Mar 13, 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
3 changes: 3 additions & 0 deletions src/validators/api/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ async def get_validators(request: Request) -> Response:
)
validators = [v for v in validators if v.public_key not in pending_validator_registrations]

if not validators:
return JSONResponse([])

# get next validator index for exit signature
latest_public_keys = await get_latest_network_validator_public_keys()
next_validator_index = NetworkValidatorCrud().get_next_validator_index(list(latest_public_keys))
Expand Down
30 changes: 20 additions & 10 deletions src/validators/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,25 @@ async def register_validators(
)
return None

_, update_state_call = await get_withdrawable_assets()

if validators is None and keystore is None:
raise RuntimeError('validators or keystore must be set')

if validators is None:
validators = await get_available_validators_for_registration(
keystore=keystore, deposit_data=deposit_data
)
validators_count, update_state_call = await get_validators_count_from_vault_assets()

if not validators_count:
# not enough balance to register validators
return None

# get latest oracles
oracles = await get_oracles()

validators_count = min(oracles.validators_approval_batch_limit, validators_count)

validators = await get_available_validators(
keystore=keystore,
deposit_data=deposit_data,
count=validators_count,
)

if not validators:
logger.warning(
Expand Down Expand Up @@ -225,7 +235,7 @@ async def get_available_validators_for_registration(
deposit_data: DepositData,
run_check_deposit_data_root: bool = True,
) -> list[Validator]:
validators_count = await get_validators_count_from_vault_assets()
validators_count, _ = await get_validators_count_from_vault_assets()

if not validators_count:
# not enough balance to register validators
Expand All @@ -245,8 +255,8 @@ async def get_available_validators_for_registration(
return validators


async def get_validators_count_from_vault_assets() -> int:
vault_balance, _ = await get_withdrawable_assets()
async def get_validators_count_from_vault_assets() -> tuple[int, HexStr | None]:
vault_balance, update_state_call = await get_withdrawable_assets()
if settings.network == GNOSIS:
# apply GNO -> mGNO exchange rate
vault_balance = Wei(int(vault_balance * MGNO_RATE // WAD))
Expand All @@ -255,7 +265,7 @@ async def get_validators_count_from_vault_assets() -> int:

# calculate number of validators that can be registered
validators_count = vault_balance // DEPOSIT_AMOUNT
return validators_count
return validators_count, update_state_call


# pylint: disable-next=too-many-arguments
Expand Down
Loading