Skip to content

Commit

Permalink
Protocol config (#310)
Browse files Browse the repository at this point in the history
* Add oracles cache (#238)

* Add oracles cache

* Review fix

* Use separate tasks for main functions (#230)

* Use separate tasks for main functions

Signed-off-by: cyc60 <[email protected]>

* Refactored func names

Signed-off-by: cyc60 <[email protected]>

* Run HarvestTask only if needed

Signed-off-by: cyc60 <[email protected]>

* Review fix

Signed-off-by: cyc60 <[email protected]>

* Move interrupt_handler processing to tasks

Signed-off-by: cyc60 <[email protected]>

---------

Signed-off-by: cyc60 <[email protected]>

* Move ipfs retries to client (#252)

* Move ipfs retries to client

* Fix test

* Add settings for genesis validators ipfs client

* Increase default GENESIS_VALIDATORS_IPFS_RETRY_TIMEOUT

* Refactored keystores (#249)

* Refactored keystores

Signed-off-by: cyc60 <[email protected]>

* Fix tests

Signed-off-by: cyc60 <[email protected]>

* Remove unused comment

Signed-off-by: cyc60 <[email protected]>

* Remove double log

Signed-off-by: cyc60 <[email protected]>

* Update packages in prod build (#256)

* Update packages in prod build

* Fix

* Remove goerli network (#257)

Signed-off-by: cyc60 <[email protected]>

---------

Signed-off-by: cyc60 <[email protected]>
Co-authored-by: antares-sw <[email protected]>

* Log format (#260)

* Add json log formatter

Signed-off-by: cyc60 <[email protected]>

* Poetry update

Signed-off-by: cyc60 <[email protected]>

* Use record.created for json logs

Signed-off-by: cyc60 <[email protected]>

* Review fixes

Signed-off-by: cyc60 <[email protected]>

* Review fix

Signed-off-by: cyc60 <[email protected]>

* Remove int conversion

Signed-off-by: cyc60 <[email protected]>

---------

Signed-off-by: cyc60 <[email protected]>

* Add log envs to example (#262)

Signed-off-by: cyc60 <[email protected]>

* Fixes after merge

* Rework signature rotation parallel (#273)

* Add flake8-datetimez plugin (#274)

* Add flake8-datetimez plugin

* Fix poetry.lock after merge

* Move protocol config to sw-utils

Signed-off-by: cyc60 <[email protected]>

* Update test

Signed-off-by: cyc60 <[email protected]>

* Merge cleanup

Signed-off-by: cyc60 <[email protected]>

---------

Signed-off-by: cyc60 <[email protected]>
Co-authored-by: evgeny-stakewise <[email protected]>
Co-authored-by: antares-sw <[email protected]>
Co-authored-by: Evgeny Gusarov <[email protected]>
  • Loading branch information
4 people authored Mar 25, 2024
1 parent cf6ef9f commit 0139700
Show file tree
Hide file tree
Showing 13 changed files with 145 additions and 198 deletions.
64 changes: 33 additions & 31 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ python-decouple = "==3.8"
sentry-sdk = "==1.32.0"
py-ecc = "==6.0.0"
multiproof = { git = "https://github.com/stakewise/multiproof.git", rev = "v0.1.7" }
sw-utils = { git = "https://github.com/stakewise/sw-utils.git", rev = "v0.6.1" }
sw-utils = { git = "https://github.com/stakewise/sw-utils.git", rev = "v0.6.3" }
staking-deposit = { git = "https://github.com/ethereum/staking-deposit-cli.git", rev = "v2.4.0" }
pycryptodomex = "3.19.1"
milagro-bls-binding = "==1.9.0"
Expand Down
54 changes: 9 additions & 45 deletions src/common/execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import click
from eth_typing import BlockNumber
from sw_utils import InterruptHandler
from sw_utils import InterruptHandler, ProtocolConfig, build_protocol_config
from web3 import Web3
from web3._utils.async_transactions import _max_fee_per_gas
from web3.exceptions import BadFunctionCallOutput
Expand All @@ -13,7 +13,7 @@
from src.common.contracts import keeper_contract, multicall_contract, vault_contract
from src.common.metrics import metrics
from src.common.tasks import BaseTask
from src.common.typings import Oracles, OraclesCache
from src.common.typings import OraclesCache
from src.common.wallet import hot_wallet
from src.config.settings import settings

Expand Down Expand Up @@ -101,53 +101,17 @@ async def update_oracles_cache() -> None:
)


async def get_oracles() -> Oracles:
async def get_protocol_config() -> ProtocolConfig:
await update_oracles_cache()

oracles_cache = cast(OraclesCache, _oracles_cache)

config = oracles_cache.config
rewards_threshold = oracles_cache.rewards_threshold
validators_threshold = oracles_cache.validators_threshold

endpoints = []
public_keys = []
for oracle in config['oracles']:
endpoints.append(oracle['endpoints'])
public_keys.append(oracle['public_key'])

if not 1 <= rewards_threshold <= len(config['oracles']):
raise ValueError('Invalid rewards threshold')

if not 1 <= validators_threshold <= len(config['oracles']):
raise ValueError('Invalid validators threshold')

exit_signature_recover_threshold = config['exit_signature_recover_threshold']

if exit_signature_recover_threshold > validators_threshold:
raise ValueError('Invalid exit signature threshold')

signature_validity_period = config['signature_validity_period']

if signature_validity_period < 0:
raise ValueError('Invalid signature validity period')

if len(public_keys) != len(set(public_keys)):
raise ValueError('Duplicate public keys in oracles config')

validators_approval_batch_limit = config['validators_approval_batch_limit']
validators_exit_rotation_batch_limit = config['validators_exit_rotation_batch_limit']

return Oracles(
rewards_threshold=rewards_threshold,
validators_threshold=validators_threshold,
exit_signature_recover_threshold=exit_signature_recover_threshold,
signature_validity_period=signature_validity_period,
public_keys=public_keys,
endpoints=endpoints,
validators_approval_batch_limit=validators_approval_batch_limit,
validators_exit_rotation_batch_limit=validators_exit_rotation_batch_limit,
pc = build_protocol_config(
config_data=oracles_cache.config,
rewards_threshold=oracles_cache.rewards_threshold,
validators_threshold=oracles_cache.validators_threshold,
)
pc.rewards_threshold = cast(int, pc.rewards_threshold)
return pc


async def get_high_priority_tx_params() -> TxParams:
Expand Down
5 changes: 3 additions & 2 deletions src/common/startup_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from src.common.execution import (
check_hot_wallet_balance,
check_vault_address,
get_oracles,
get_protocol_config,
)
from src.common.utils import format_error, warning_verbose
from src.common.wallet import hot_wallet
Expand Down Expand Up @@ -110,7 +110,8 @@ async def wait_for_execution_node() -> None:


async def collect_healthy_oracles() -> list:
endpoints = (await get_oracles()).endpoints
oracles = (await get_protocol_config()).oracles
endpoints = [oracle.endpoints for oracle in oracles]

async with ClientSession(timeout=ClientTimeout(60)) as session:
results = await asyncio.gather(
Expand Down
27 changes: 1 addition & 26 deletions src/common/typings.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,9 @@
from dataclasses import dataclass
from functools import cached_property

from eth_keys.datatypes import PublicKey
from eth_typing import BlockNumber, ChecksumAddress, HexStr
from web3 import Web3
from eth_typing import BlockNumber
from web3.types import Wei


@dataclass
# pylint: disable-next=too-many-instance-attributes
class Oracles:
rewards_threshold: int
validators_threshold: int
exit_signature_recover_threshold: int
signature_validity_period: int
public_keys: list[HexStr]
endpoints: list[list[str]]

validators_approval_batch_limit: int
validators_exit_rotation_batch_limit: int

@cached_property
def addresses(self) -> list[ChecksumAddress]:
res = []
for public_key in self.public_keys:
public_key_obj = PublicKey(Web3.to_bytes(hexstr=public_key))
res.append(public_key_obj.to_checksum_address())
return res


@dataclass
class OraclesCache:
checkpoint_block: BlockNumber
Expand Down
33 changes: 15 additions & 18 deletions src/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@
from Cryptodome.Protocol.KDF import scrypt as raw_scrypt
from eth_typing import HexAddress, HexStr
from sw_utils.tests import faker
from sw_utils.tests.factories import get_mocked_protocol_config
from sw_utils.typings import Oracle, ProtocolConfig

from src.commands.create_keys import create_keys
from src.commands.create_wallet import create_wallet
from src.commands.remote_signer_setup import remote_signer_setup
from src.common.credentials import CredentialManager, ScryptKeystore
from src.common.typings import Oracles
from src.common.vault_config import VaultConfig
from src.config.networks import HOLESKY
from src.config.settings import settings
from src.test_fixtures.hashi_vault import hashi_vault_url, mocked_hashi_vault
from src.test_fixtures.hashi_vault import hashi_vault_url, mocked_hashi_vault # noqa
from src.test_fixtures.remote_signer import mocked_remote_signer, remote_signer_url
from src.validators.keystores.remote import RemoteSignerKeystore
from src.validators.signing.tests.oracle_functions import OracleCommittee
Expand Down Expand Up @@ -156,7 +157,7 @@ def _remote_signer_setup(
remote_signer_url: str,
execution_endpoints: str,
runner: CliRunner,
mocked_oracles: Oracles,
mocked_protocol_config: ProtocolConfig,
mocked_remote_signer,
_create_keys,
) -> None:
Expand Down Expand Up @@ -247,24 +248,20 @@ def _mocked_oracle_committee(request: SubRequest) -> OracleCommittee:


@pytest.fixture
def mocked_oracles(
def mocked_protocol_config(
_mocked_oracle_committee: OracleCommittee,
) -> Oracles:
) -> ProtocolConfig:
exit_signature_recover_threshold = _mocked_oracle_committee.exit_signature_recover_threshold

return Oracles(
rewards_threshold=1,
validators_threshold=1,
oracles = []
for index, pub_key in enumerate(_mocked_oracle_committee.oracle_pubkeys):
oracle = Oracle(
public_key=HexStr(pub_key.format(compressed=False)[1:].hex()),
endpoints=[f'http://oracle-endpoint-{index}'],
)
oracles.append(oracle)
return get_mocked_protocol_config(
oracles=oracles,
exit_signature_recover_threshold=exit_signature_recover_threshold,
# Strip first byte (04 prefix) from pubkey
public_keys=[
HexStr(pubkey.format(compressed=False)[1:].hex())
for pubkey in _mocked_oracle_committee.oracle_pubkeys
],
endpoints=[
[f'http://oracle-endpoint-{i}']
for i in range(len(_mocked_oracle_committee.oracle_pubkeys))
],
validators_approval_batch_limit=1,
validators_exit_rotation_batch_limit=2,
signature_validity_period=60,
Expand Down
Loading

0 comments on commit 0139700

Please sign in to comment.