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
8 changes: 8 additions & 0 deletions oracle/networks.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from datetime import timedelta

from decouple import Csv, config
from ens.constants import EMPTY_ADDR_HEX
from eth_typing import HexStr
from web3 import Web3

Expand Down Expand Up @@ -68,6 +69,9 @@
"0x0100000000000000000000002296e122c1a20fca3cac3371357bdad3be0df079"
),
ORACLE_PRIVATE_KEY=config("ORACLE_PRIVATE_KEY", default=""),
ORACLE_STAKEWISE_OPERATOR=Web3.toChecksumAddress(
"0x5fc60576b92c5ce5c341c43e3b2866eb9e0cddd1"
),
AWS_BUCKET_NAME=config("AWS_BUCKET_NAME", default="oracle-votes-mainnet"),
AWS_REGION=config("AWS_REGION", default="eu-central-1"),
AWS_ACCESS_KEY_ID=config("AWS_ACCESS_KEY_ID", default=""),
Expand Down Expand Up @@ -138,6 +142,7 @@
"0x0100000000000000000000005c631621b897f467dd6a91855a0bc97d77b78dc0"
),
ORACLE_PRIVATE_KEY=config("ORACLE_PRIVATE_KEY", default=""),
ORACLE_STAKEWISE_OPERATOR=EMPTY_ADDR_HEX,
AWS_BUCKET_NAME=config(
"AWS_BUCKET_NAME",
default="oracle-votes-harbour-mainnet",
Expand Down Expand Up @@ -211,6 +216,7 @@
"0x010000000000000000000000040f15c6b5bfc5f324ecab5864c38d4e1eef4218"
),
ORACLE_PRIVATE_KEY=config("ORACLE_PRIVATE_KEY", default=""),
ORACLE_STAKEWISE_OPERATOR=EMPTY_ADDR_HEX,
AWS_BUCKET_NAME=config("AWS_BUCKET_NAME", default="oracle-votes-goerli"),
AWS_REGION=config("AWS_REGION", default="eu-central-1"),
AWS_ACCESS_KEY_ID=config("AWS_ACCESS_KEY_ID", default=""),
Expand Down Expand Up @@ -281,6 +287,7 @@
"0x0100000000000000000000006dfc9682e3c3263758ad96e2b2ba9822167f81ee"
),
ORACLE_PRIVATE_KEY=config("ORACLE_PRIVATE_KEY", default=""),
ORACLE_STAKEWISE_OPERATOR=EMPTY_ADDR_HEX,
AWS_BUCKET_NAME=config(
"AWS_BUCKET_NAME",
default="oracle-votes-perm-goerli",
Expand Down Expand Up @@ -354,6 +361,7 @@
"0x010000000000000000000000fc9b67b6034f6b306ea9bd8ec1baf3efa2490394"
),
ORACLE_PRIVATE_KEY=config("ORACLE_PRIVATE_KEY", default=""),
ORACLE_STAKEWISE_OPERATOR=EMPTY_ADDR_HEX,
AWS_BUCKET_NAME=config("AWS_BUCKET_NAME", default="oracle-votes-gnosis"),
AWS_REGION=config("AWS_REGION", default="eu-north-1"),
AWS_ACCESS_KEY_ID=config("AWS_ACCESS_KEY_ID", default=""),
Expand Down
20 changes: 19 additions & 1 deletion oracle/oracle/common/graphql_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@
operators(
block: { number: $block_number }
where: { committed: true }
orderBy: validatorsCount
orderBy: id
orderDirection: asc
) {
id
Expand All @@ -411,6 +411,24 @@
"""
)

LAST_VALIDATORS_QUERY = gql(
"""
query getValidators($block_number: Int) {
validators(
block: { number: $block_number }
orderBy: createdAtBlock
orderDirection: desc
first: 1
) {
operator {
id
}
}
}
"""
)


PARTNERS_QUERY = gql(
"""
query getPartners($block_number: Int) {
Expand Down
38 changes: 37 additions & 1 deletion oracle/oracle/validators/eth1.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import Dict, Set, Union

from ens.constants import EMPTY_ADDR_HEX
from eth_typing import HexStr
from web3 import Web3
from web3.types import BlockNumber
Expand All @@ -9,12 +10,13 @@
execute_sw_gql_query,
)
from oracle.oracle.common.graphql_queries import (
LAST_VALIDATORS_QUERY,
OPERATORS_QUERY,
VALIDATOR_REGISTRATIONS_LATEST_INDEX_QUERY,
VALIDATOR_REGISTRATIONS_QUERY,
)
from oracle.oracle.common.ipfs import ipfs_fetch
from oracle.settings import NETWORK
from oracle.settings import NETWORK, NETWORK_CONFIG

from .types import ValidatorDepositData

Expand All @@ -29,6 +31,21 @@ async def select_validator(
variables=dict(block_number=block_number),
)
operators = result["operators"]
result: Dict = await execute_sw_gql_query(
network=NETWORK,
query=LAST_VALIDATORS_QUERY,
variables=dict(block_number=block_number),
)

last_validators = result["validators"]
if last_validators:
last_operator_id = last_validators[0]["operator"]["id"]
index = _find_operator_index(operators, last_operator_id)
if index is not None and index != len(operators) - 1:
operators = operators[index + 1 :] + [operators[index]] + operators[:index]

_move_to_bottom(operators, NETWORK_CONFIG["ORACLE_STAKEWISE_OPERATOR"])

for operator in operators:
merkle_proofs = operator["depositDataMerkleProofs"]
if not merkle_proofs:
Expand Down Expand Up @@ -90,3 +107,22 @@ async def get_validators_deposit_root(block_number: BlockNumber) -> HexStr:
variables=dict(block_number=block_number),
)
return result["validatorRegistrations"][0]["validatorsDepositRoot"]


def _move_to_bottom(operators, operator_id):
if operator_id == EMPTY_ADDR_HEX:
return

index = _find_operator_index(operators, operator_id)
if index is not None:
operators.append(operators.pop(index))


def _find_operator_index(operators, operator_id):
index = None
operator_id = Web3.toChecksumAddress(operator_id)
for i, operator in enumerate(operators):
if Web3.toChecksumAddress(operator["id"]) == operator_id:
index = i
break
return index
9 changes: 7 additions & 2 deletions oracle/oracle/validators/tests/test_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
block_number = faker.random_int(150000, 250000)


def select_validator(operator, *args, **kwargs):
def select_operators(operator, *args, **kwargs):
return {
"operators": [
{
Expand All @@ -25,6 +25,10 @@ def select_validator(operator, *args, **kwargs):
}


def select_validators(*args, **kwargs):
return {"validators": []}


def can_registor_validator(*args, **kwargs):
return {"validatorRegistrations": []}

Expand Down Expand Up @@ -71,7 +75,8 @@ def get_validators_deposit_root(validatorsDepositRoot, *args, **kwargs):

def sw_gql_query(operator):
return [
select_validator(operator),
select_operators(operator),
select_validators(),
]


Expand Down