Skip to content

Commit

Permalink
Merge pull request #7 from stakewise/fix-reward-token-sync
Browse files Browse the repository at this point in the history
Fix reward token sync
  • Loading branch information
tsudmi authored Jan 31, 2021
2 parents 961ce04 + 4578382 commit f6a38a5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
2 changes: 1 addition & 1 deletion requirements/prod.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ notifiers==1.2.1
web3==5.15.0
grpcio==1.35.0
protobuf==3.14.0
google-api-core==1.24.1
google-api-core==1.25.1
6 changes: 3 additions & 3 deletions requirements/prod.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ eth-utils==1.10.0 \
# eth-rlp
# rlp
# web3
google-api-core==1.24.1 \
--hash=sha256:0f1dee446db2685863c3c493a90fefa5fc7f4defaf8e1a320b50ccaddfb5d469 \
--hash=sha256:a7f5794446a22ff7d36764959ba5f319f37628faf4da04fdc0dedf1598b556c1
google-api-core==1.25.1 \
--hash=sha256:0e152ec37b8481d1be1258d95844a5a7031cd3d83d7c7046d9e9b2d807042440 \
--hash=sha256:292dd636ed381098d24b7093ccb826b2278a12d886a3fc982084069aa24a8fbb
# via -r requirements/prod.in
google-auth==1.24.0 \
--hash=sha256:0b0e026b412a0ad096e753907559e4bdb180d9ba9f68dd9036164db4fdc4ad2e \
Expand Down
23 changes: 15 additions & 8 deletions src/reward_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,15 @@ def __init__(self, w3: Web3, interrupt_handler: InterruptHandler) -> None:
self.total_rewards_update_period: timedelta = timedelta(
seconds=self.oracles.functions.totalRewardsUpdatePeriod().call()
)
logger.debug(f"Total rewards update period: {self.total_rewards_update_period}")
if self.last_update_at < self.genesis_time:
logger.info(f"Total rewards update period: {self.total_rewards_update_period}")

next_update_at = self.last_update_at + self.total_rewards_update_period
while next_update_at <= datetime.now(tz=timezone.utc):
self.last_update_at = next_update_at
next_update_at = self.last_update_at + self.total_rewards_update_period
while next_update_at <= datetime.now(tz=timezone.utc):
self.last_update_at = next_update_at
next_update_at = self.last_update_at + self.total_rewards_update_period

self.next_update_at = self.last_update_at + self.total_rewards_update_period
logger.info(f"Next rewards update time: {self.next_update_at}")

def process(self) -> None:
"""Records new pool validators, updates total rewards."""
Expand All @@ -106,18 +107,24 @@ def process(self) -> None:
)
if total_rewards_update_period != self.total_rewards_update_period:
# adjust next update time based on new period
self.next_update_at = (
next_update_at = (
self.next_update_at
- self.total_rewards_update_period
+ total_rewards_update_period
)
self.total_rewards_update_period = total_rewards_update_period
logger.info(
f"Updated total rewards update period:"
f" previous={self.total_rewards_update_period},"
f" new={total_rewards_update_period}"
)

while next_update_at <= datetime.now(tz=timezone.utc):
self.last_update_at = next_update_at
next_update_at = self.last_update_at + self.total_rewards_update_period

self.next_update_at = self.last_update_at + self.total_rewards_update_period
logger.info(f"Scheduling next rewards update at {self.next_update_at}")
self.total_rewards_update_period = total_rewards_update_period

if self.next_update_at > datetime.now(tz=timezone.utc):
# it's not the time to update yet
Expand Down Expand Up @@ -165,7 +172,7 @@ def process(self) -> None:
)
return

logger.debug(
logger.info(
f"Retrieving balances for {len(active_public_keys)} / {len(public_keys)}"
f" validators at epoch={epoch}"
)
Expand Down

0 comments on commit f6a38a5

Please sign in to comment.