Skip to content

Commit

Permalink
Fix registry root changed error (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
tsudmi authored Feb 27, 2023
1 parent 037602a commit 9044538
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "v3-operator"
version = "0.1.3"
version = "0.1.4"
description = "StakeWise operator service for registering vault validators"
authors = ["StakeWise Labs <info@stakewise.io>"]

Expand Down
11 changes: 9 additions & 2 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from src.validators.database import setup as validators_db_setup
from src.validators.execution import NetworkValidatorsProcessor
from src.validators.tasks import load_genesis_validators, register_validators
from src.validators.utils import load_deposit_data, load_keystores
from src.validators.utils import load_deposit_data, load_keystores, REGISTRY_ROOT_CHANGED_ERROR

logging.basicConfig(
format='%(asctime)s %(levelname)-8s %(message)s',
Expand Down Expand Up @@ -83,7 +83,14 @@ async def main() -> None:
# check and register new validators
await register_validators(keystores, deposit_data)
except Exception as e:
logger.exception(e)
if (
isinstance(e, ValueError)
and len(e.args)
and e.args[0] == REGISTRY_ROOT_CHANGED_ERROR
):
logger.warning(REGISTRY_ROOT_CHANGED_ERROR)
else:
logger.exception(e)

block_processing_time = time.time() - start_time
sleep_time = max(int(NETWORK_CONFIG.SECONDS_PER_BLOCK) - int(block_processing_time), 0)
Expand Down
4 changes: 3 additions & 1 deletion src/validators/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@

logger = logging.getLogger(__name__)

REGISTRY_ROOT_CHANGED_ERROR = 'Validators registry root has changed'


class KeystoreException(Exception):
...
Expand Down Expand Up @@ -89,7 +91,7 @@ async def send_approval_request(
except ClientError as e:
registry_root = await get_validators_registry_root()
if Web3.to_hex(registry_root) != payload['validators_root']:
raise ValueError('Validators registry root has changed') from e
raise ValueError(REGISTRY_ROOT_CHANGED_ERROR) from e

latest_public_keys = await get_latest_network_validator_public_keys()
validator_index = get_next_validator_index(list(latest_public_keys))
Expand Down

0 comments on commit 9044538

Please sign in to comment.