Skip to content

Commit

Permalink
Merge pull request #19 from stakewise/fix-delayed-epoch
Browse files Browse the repository at this point in the history
Fix too far epoch sync
  • Loading branch information
tsudmi authored Oct 2, 2021
2 parents c079a67 + da1011f commit 03bc726
Show file tree
Hide file tree
Showing 6 changed files with 592 additions and 412 deletions.
2 changes: 1 addition & 1 deletion requirements/dev.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pip-tools==6.1.0
grpcio-tools==1.37.1
grpcio-tools==1.41.0
black==20.8b1
flake8==3.9.2
mypy==0.812
427 changes: 207 additions & 220 deletions requirements/dev.txt

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions requirements/prod.in
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
notifiers==1.2.1
web3==5.19.0
grpcio==1.37.1
protobuf==3.15.3
web3==5.24.0
grpcio==1.41.0
protobuf===3.18.0
google-api-core==1.27.0
tenacity==7.0.0
ipfshttpclient==0.7.0a1
ipfshttpclient==0.8.0a2
gql==2.0.0
543 changes: 361 additions & 182 deletions requirements/prod.txt

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@
# ~1 hour with block time of 13 seconds
SYNC_BLOCKS_DELAY: int = int(environ.get("SYNC_BLOCKS_DELAY", "277"))

# number of ETH2 epochs that won't be possible to fetch from the node starting from the current epoch
TOO_FAR_EPOCHS_SPAN: int = int(environ.get("TOO_FAR_EPOCHS_NUMBER", "15"))

# maximum gas spent on oracle vote
ORACLE_VOTE_GAS_LIMIT: Wei = Wei(int(environ.get("ORACLE_VOTE_GAS_LIMIT", "250000")))

Expand Down
21 changes: 16 additions & 5 deletions src/staking_rewards/rewards.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import time
from typing import Set

from eth_typing.bls import BLSPubkey
Expand All @@ -22,6 +23,7 @@
SYNC_BLOCKS_DELAY,
ETH1_CONFIRMATION_BLOCKS,
ETH2_CONFIRMATION_EPOCHS,
TOO_FAR_EPOCHS_SPAN,
)
from src.staking_rewards.utils import (
get_validator_stub,
Expand Down Expand Up @@ -155,11 +157,6 @@ def process(self) -> None:
# skip updating if the time hasn't come yet
return

# fetch pool validator BLS public keys
public_keys: Set[BLSPubkey] = get_pool_validator_public_keys(
pool_contract=self.pool, block_number=next_sync_block_number
)

# calculate finalized epoch to fetch validator balances at
next_sync_timestamp: Timestamp = get_block(
w3=self.w3, block_number=next_sync_block_number
Expand All @@ -175,6 +172,20 @@ def process(self) -> None:
f"Voting for new total rewards with parameters:"
f" block number={next_sync_block_number}, epoch={epoch}"
)
current_epoch: int = (
int((int(time.time()) - self.genesis_timestamp) / self.seconds_per_epoch)
- ETH2_CONFIRMATION_EPOCHS
)

if epoch < current_epoch - TOO_FAR_EPOCHS_SPAN:
# Wait for next update round as the required epoch is too far behind
logger.info("Waiting for the next rewards update...")
return

# fetch pool validator BLS public keys
public_keys: Set[BLSPubkey] = get_pool_validator_public_keys(
pool_contract=self.pool, block_number=next_sync_block_number
)

# fetch activated validators from the beacon chain
validator_statuses = get_pool_validator_statuses(
Expand Down

0 comments on commit 03bc726

Please sign in to comment.