Skip to content

Commit 8a61f8f

Browse files
authored
Chunkify withdrawals records (#152)
* Chunkify withdrawals records Signed-off-by: cyc60 <avsysoev60@gmail.com> * Fix chunk call Signed-off-by: cyc60 <avsysoev60@gmail.com> * Version bump Signed-off-by: cyc60 <avsysoev60@gmail.com> * Move chunk size to settings Signed-off-by: cyc60 <avsysoev60@gmail.com> --------- Signed-off-by: cyc60 <avsysoev60@gmail.com>
1 parent b315e68 commit 8a61f8f

File tree

4 files changed

+417
-395
lines changed

4 files changed

+417
-395
lines changed

oracle/oracle/rewards/controller.py

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
MGNO_RATE,
2626
NETWORK,
2727
NETWORK_CONFIG,
28+
ORACLE_WITHDRAWAL_CHUNK_SIZE,
2829
REWARD_VOTE_FILENAME,
2930
WAD,
3031
)
@@ -221,6 +222,33 @@ async def calculate_withdrawal_rewards(
221222
)
222223
execution_client = get_web3_client()
223224

225+
chunk_size = ORACLE_WITHDRAWAL_CHUNK_SIZE
226+
for block_number in range(from_block, to_block, chunk_size):
227+
withdrawals_amount += await self.fetch_withdrawal_chunk(
228+
validator_indexes=validator_indexes,
229+
from_block=block_number,
230+
to_block=min(block_number + chunk_size, to_block),
231+
execution_client=execution_client,
232+
)
233+
234+
withdrawals_amount = Web3.toWei(withdrawals_amount, "gwei")
235+
if NETWORK == GNOSIS_CHAIN:
236+
# apply mGNO <-> GNO exchange rate
237+
withdrawals_amount = Wei(int(withdrawals_amount * WAD // MGNO_RATE))
238+
return withdrawals_amount
239+
240+
async def fetch_withdrawal_chunk(
241+
self,
242+
validator_indexes: set[int],
243+
from_block: int,
244+
to_block: int,
245+
execution_client,
246+
) -> int:
247+
logger.info(
248+
f"Retrieving pool validator withdrawals chunk "
249+
f"from block: {from_block} to block: {to_block}"
250+
)
251+
withdrawals_amount = 0
224252
with concurrent.futures.ThreadPoolExecutor(max_workers=10) as executor:
225253
futures = [
226254
executor.submit(get_withdrawals, execution_client, block_number)
@@ -231,11 +259,6 @@ async def calculate_withdrawal_rewards(
231259
for withdrawal in withdrawals:
232260
if withdrawal["validator_index"] in validator_indexes:
233261
withdrawals_amount += withdrawal["amount"]
234-
235-
withdrawals_amount = Web3.toWei(withdrawals_amount, "gwei")
236-
if NETWORK == GNOSIS_CHAIN:
237-
# apply mGNO <-> GNO exchange rate
238-
withdrawals_amount = Wei(int(withdrawals_amount * WAD // MGNO_RATE))
239262
return withdrawals_amount
240263

241264
async def get_withdrawals_from_block(self, current_slot: int) -> BlockNumber | None:

oracle/settings.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828

2929
# oracle
3030
ORACLE_PROCESS_INTERVAL = config("ORACLE_PROCESS_INTERVAL", default=15, cast=int)
31+
ORACLE_WITHDRAWAL_CHUNK_SIZE = config(
32+
"ORACLE_WITHDRAWAL_CHUNK_SIZE", default=50000, cast=int
33+
)
34+
3135

3236
IPFS_FETCH_ENDPOINTS = config(
3337
"IPFS_FETCH_ENDPOINTS",

0 commit comments

Comments
 (0)