From acae5f62114ed286f22c69d31346ed9bc9059bec Mon Sep 17 00:00:00 2001 From: Dmitri Tsumak Date: Sun, 19 Dec 2021 17:11:58 +0200 Subject: [PATCH] Fix validator registration query --- deploy/docker-compose.yml | 2 +- oracle/oracle/graphql_queries.py | 24 +++++++++++++++++++++--- oracle/oracle/validators/controller.py | 4 ++-- oracle/oracle/validators/eth1.py | 8 ++++---- oracle/oracle/validators/types.py | 3 ++- 5 files changed, 30 insertions(+), 11 deletions(-) diff --git a/deploy/docker-compose.yml b/deploy/docker-compose.yml index 57f1060..4684b33 100644 --- a/deploy/docker-compose.yml +++ b/deploy/docker-compose.yml @@ -100,7 +100,7 @@ services: soft: 8192 hard: 8192 volumes: ["ipfs:/data/ipfs","./configs/ipfs-entrypoint.sh:/usr/local/bin/start_ipfs"] - profiles: ["graph"] + profiles: ["oracle"] geth: container_name: geth diff --git a/oracle/oracle/graphql_queries.py b/oracle/oracle/graphql_queries.py index 1432406..8f1ec81 100644 --- a/oracle/oracle/graphql_queries.py +++ b/oracle/oracle/graphql_queries.py @@ -56,13 +56,18 @@ VALIDATOR_VOTING_PARAMETERS_QUERY = gql( """ - query getVotingParameters($block_number: Int) { - networks(block: { number: $block_number }) { + query getVotingParameters { + networks { oraclesValidatorsNonce } - pools(block: { number: $block_number }) { + pools { balance } + _meta { + block { + number + } + } } """ ) @@ -361,6 +366,19 @@ """ ) +VALIDATOR_REGISTRATIONS_QUERY = gql( + """ + query getValidatorRegistrations($block_number: Int, $public_key: Bytes) { + validatorRegistrations( + block: { number: $block_number } + where: { id: $public_key } + ) { + id + } + } +""" +) + VALIDATOR_REGISTRATIONS_LATEST_INDEX_QUERY = gql( """ query getValidatorRegistrations($block_number: Int) { diff --git a/oracle/oracle/validators/controller.py b/oracle/oracle/validators/controller.py index d3800b8..86bce5e 100644 --- a/oracle/oracle/validators/controller.py +++ b/oracle/oracle/validators/controller.py @@ -7,7 +7,7 @@ from oracle.common.settings import VALIDATOR_VOTE_FILENAME -from ..eth1 import get_latest_block, submit_vote +from ..eth1 import submit_vote from .eth1 import get_validators_count, get_voting_parameters, select_validator from .types import ValidatorVote @@ -26,8 +26,8 @@ def __init__(self, oracle: LocalAccount) -> None: async def process(self) -> None: """Process validators registration.""" - latest_block_number = (await get_latest_block())["block_number"] voting_params = await get_voting_parameters() + latest_block_number = voting_params["latest_block_number"] pool_balance = voting_params["pool_balance"] if pool_balance < self.validator_deposit: # not enough balance to register next validator diff --git a/oracle/oracle/validators/eth1.py b/oracle/oracle/validators/eth1.py index f649c4a..e6d2e0e 100644 --- a/oracle/oracle/validators/eth1.py +++ b/oracle/oracle/validators/eth1.py @@ -21,19 +21,19 @@ @backoff.on_exception(backoff.expo, Exception, max_time=900) -async def get_voting_parameters(block_number: BlockNumber) -> ValidatorVotingParameters: +async def get_voting_parameters() -> ValidatorVotingParameters: """Fetches validator voting parameters.""" result: Dict = await execute_sw_gql_query( query=VALIDATOR_VOTING_PARAMETERS_QUERY, - variables=dict( - block_number=block_number, - ), + variables={}, ) network = result["networks"][0] pool = result["pools"][0] + meta = result["_meta"] return ValidatorVotingParameters( validators_nonce=int(network["oraclesValidatorsNonce"]), pool_balance=Wei(int(pool["balance"])), + latest_block_number=BlockNumber(int(meta["block"]["number"])), ) diff --git a/oracle/oracle/validators/types.py b/oracle/oracle/validators/types.py index c5f8560..ab7d30b 100644 --- a/oracle/oracle/validators/types.py +++ b/oracle/oracle/validators/types.py @@ -1,12 +1,13 @@ from typing import List, TypedDict -from eth_typing import ChecksumAddress, HexStr +from eth_typing import BlockNumber, ChecksumAddress, HexStr from web3.types import Wei class ValidatorVotingParameters(TypedDict): validators_nonce: int pool_balance: Wei + latest_block_number: BlockNumber class MerkleDepositData(TypedDict):