Skip to content

Commit

Permalink
Use fixed to_block in rewards calculation (#142)
Browse files Browse the repository at this point in the history
Signed-off-by: cyc60 <[email protected]>
  • Loading branch information
cyc60 authored Apr 13, 2023
1 parent 60ad651 commit 4af1386
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 14 deletions.
4 changes: 2 additions & 2 deletions deploy/goerli/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ networks:
services:
oracle:
container_name: oracle_goerli
image: europe-west4-docker.pkg.dev/stakewiselabs/public/oracle:v2.9.3
image: europe-west4-docker.pkg.dev/stakewiselabs/public/oracle:v2.9.4
restart: always
entrypoint: ["python"]
command: ["oracle/oracle/main.py"]
Expand All @@ -36,7 +36,7 @@ services:

keeper:
container_name: keeper_goerli
image: europe-west4-docker.pkg.dev/stakewiselabs/public/oracle:v2.9.3
image: europe-west4-docker.pkg.dev/stakewiselabs/public/oracle:v2.9.4
restart: always
entrypoint: ["python"]
command: ["oracle/keeper/main.py"]
Expand Down
4 changes: 2 additions & 2 deletions deploy/harbour_goerli/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ networks:
services:
oracle:
container_name: oracle_harbour_goerli
image: europe-west4-docker.pkg.dev/stakewiselabs/public/oracle:v2.9.3
image: europe-west4-docker.pkg.dev/stakewiselabs/public/oracle:v2.9.4
restart: always
entrypoint: ["python"]
command: ["oracle/oracle/main.py"]
Expand All @@ -36,7 +36,7 @@ services:

keeper:
container_name: keeper_harbour_goerli
image: europe-west4-docker.pkg.dev/stakewiselabs/public/oracle:v2.9.3
image: europe-west4-docker.pkg.dev/stakewiselabs/public/oracle:v2.9.4
restart: always
entrypoint: ["python"]
command: ["oracle/keeper/main.py"]
Expand Down
4 changes: 2 additions & 2 deletions deploy/harbour_mainnet/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ networks:
services:
oracle:
container_name: oracle_harbour_mainnet
image: europe-west4-docker.pkg.dev/stakewiselabs/public/oracle:v2.9.3
image: europe-west4-docker.pkg.dev/stakewiselabs/public/oracle:v2.9.4
restart: always
entrypoint: ["python"]
command: ["oracle/oracle/main.py"]
Expand All @@ -36,7 +36,7 @@ services:

keeper:
container_name: keeper_harbour_mainnet
image: europe-west4-docker.pkg.dev/stakewiselabs/public/oracle:v2.9.3
image: europe-west4-docker.pkg.dev/stakewiselabs/public/oracle:v2.9.4
restart: always
entrypoint: ["python"]
command: ["oracle/keeper/main.py"]
Expand Down
4 changes: 2 additions & 2 deletions deploy/mainnet/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ networks:
services:
oracle:
container_name: oracle_mainnet
image: europe-west4-docker.pkg.dev/stakewiselabs/public/oracle:v2.9.3
image: europe-west4-docker.pkg.dev/stakewiselabs/public/oracle:v2.9.4
restart: always
entrypoint: ["python"]
command: ["oracle/oracle/main.py"]
Expand All @@ -36,7 +36,7 @@ services:

keeper:
container_name: keeper_mainnet
image: europe-west4-docker.pkg.dev/stakewiselabs/public/oracle:v2.9.3
image: europe-west4-docker.pkg.dev/stakewiselabs/public/oracle:v2.9.4
restart: always
entrypoint: ["python"]
command: ["oracle/keeper/main.py"]
Expand Down
19 changes: 17 additions & 2 deletions oracle/oracle/rewards/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ async def process(
):
withdrawals_rewards = await self.calculate_withdrawal_rewards(
validator_indexes=validator_indexes,
to_block=current_block_number,
current_slot=int(state_id),
)
total_rewards += withdrawals_rewards
Expand Down Expand Up @@ -208,13 +207,18 @@ async def calculate_balance_rewards(
return validator_indexes, Wei(rewards)

async def calculate_withdrawal_rewards(
self, validator_indexes: set[int], to_block: BlockNumber, current_slot: int
self, validator_indexes: set[int], current_slot: int
) -> Wei:
withdrawals_amount = 0
from_block = await self.get_withdrawals_from_block(current_slot)
to_block = await self.get_withdrawals_to_block(current_slot)
if not from_block or from_block >= to_block:
return Wei(0)

logger.info(
f"Retrieving pool validator withdrawals "
f"from block: {from_block} to block: {to_block}"
)
execution_client = get_web3_client()

with concurrent.futures.ThreadPoolExecutor(max_workers=10) as executor:
Expand Down Expand Up @@ -244,6 +248,17 @@ async def get_withdrawals_from_block(self, current_slot: int) -> BlockNumber | N
return from_block
slot_number += 1

async def get_withdrawals_to_block(self, current_slot: int) -> BlockNumber | None:
slot_number = current_slot
withdrawals_slot_number = self.withdrawals_genesis_epoch * self.slots_per_epoch
while slot_number >= withdrawals_slot_number:
to_block = await get_execution_block(
session=self.aiohttp_session, slot_number=slot_number
)
if to_block:
return to_block
slot_number -= 1

def format_ether(self, value: Union[str, int, Wei]) -> str:
"""Converts Wei value."""
_value = int(value)
Expand Down
6 changes: 3 additions & 3 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
@@ -1,6 +1,6 @@
[tool.poetry]
name = "oracle"
version = "2.9.3"
version = "2.9.4"
description = "StakeWise Oracles are responsible for submitting off-chain data."
authors = ["Dmitri Tsumak <[email protected]>"]
license = "AGPL-3.0-only"
Expand Down

0 comments on commit 4af1386

Please sign in to comment.