Skip to content
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
4 changes: 2 additions & 2 deletions deploy/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ volumes:
services:
oracle:
container_name: oracle
image: europe-west4-docker.pkg.dev/stakewiselabs/public/oracle:v2.0.0-rc.2
image: europe-west4-docker.pkg.dev/stakewiselabs/public/oracle:v2.0.0-rc.4
restart: always
entrypoint: ["python"]
command: ["oracle/oracle/main.py"]
Expand All @@ -30,7 +30,7 @@ services:

keeper:
container_name: keeper
image: europe-west4-docker.pkg.dev/stakewiselabs/public/oracle:v2.0.0-rc.2
image: europe-west4-docker.pkg.dev/stakewiselabs/public/oracle:v2.0.0-rc.4
restart: always
entrypoint: ["python"]
command: ["oracle/keeper/main.py"]
Expand Down
12 changes: 12 additions & 0 deletions oracle/oracle/graphql_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,18 @@
"""
)

VALIDATOR_REGISTRATIONS_SYNC_BLOCK_QUERY = gql(
"""
query getMeta {
_meta {
block {
number
}
}
}
"""
)

REGISTERED_VALIDATORS_QUERY = gql(
"""
query getValidators($block_number: Int, $last_id: ID) {
Expand Down
11 changes: 10 additions & 1 deletion oracle/oracle/validators/controller.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import asyncio
import logging

from eth_account.signers.local import LocalAccount
Expand All @@ -8,7 +9,12 @@
from oracle.common.settings import VALIDATOR_VOTE_FILENAME

from ..eth1 import submit_vote
from .eth1 import get_validators_count, get_voting_parameters, select_validator
from .eth1 import (
get_validators_count,
get_voting_parameters,
has_synced_block,
select_validator,
)
from .types import ValidatorVote

logger = logging.getLogger(__name__)
Expand All @@ -33,6 +39,9 @@ async def process(self) -> None:
# not enough balance to register next validator
return

while not (await has_synced_block(latest_block_number)):
await asyncio.sleep(5)

# select next validator
# TODO: implement scoring system based on the operators performance
validator_deposit_data = await select_validator(latest_block_number)
Expand Down
11 changes: 11 additions & 0 deletions oracle/oracle/validators/eth1.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
OPERATORS_QUERY,
VALIDATOR_REGISTRATIONS_LATEST_INDEX_QUERY,
VALIDATOR_REGISTRATIONS_QUERY,
VALIDATOR_REGISTRATIONS_SYNC_BLOCK_QUERY,
VALIDATOR_VOTING_PARAMETERS_QUERY,
)

Expand Down Expand Up @@ -96,6 +97,16 @@ async def can_register_validator(block_number: BlockNumber, public_key: HexStr)
return len(registrations) == 0


async def has_synced_block(block_number: BlockNumber) -> bool:
result: Dict = await execute_ethereum_gql_query(
query=VALIDATOR_REGISTRATIONS_SYNC_BLOCK_QUERY,
variables={},
)
meta = result["_meta"]

return block_number <= BlockNumber(int(meta["block"]["number"]))


@backoff.on_exception(backoff.expo, Exception, max_time=900)
async def get_validators_count(block_number: BlockNumber) -> HexStr:
"""Fetches validators count for protecting against operator submitting deposit prior to registration."""
Expand Down