Skip to content

Commit

Permalink
Fix validator registration query
Browse files Browse the repository at this point in the history
  • Loading branch information
tsudmi committed Dec 19, 2021
1 parent ee1e8c2 commit acae5f6
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 11 deletions.
2 changes: 1 addition & 1 deletion deploy/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 21 additions & 3 deletions oracle/oracle/graphql_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
"""
)
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions oracle/oracle/validators/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions oracle/oracle/validators/eth1.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])),
)


Expand Down
3 changes: 2 additions & 1 deletion oracle/oracle/validators/types.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down

0 comments on commit acae5f6

Please sign in to comment.