feat: add retries for jsonrpc requests (#40)
* feat: add jsonrpc retries for logs extraction Signed-off-by: Luca Georges Francois <luca@quartz.technology> * feat: add jsonrpc retries for analysis Signed-off-by: Luca Georges Francois <luca@quartz.technology> Signed-off-by: Luca Georges Francois <luca@quartz.technology>
This commit is contained in:
parent
3a58c82327
commit
24ea73a0b2
@ -1,5 +1,6 @@
|
||||
import asyncio
|
||||
import logging
|
||||
from time import sleep
|
||||
from typing import Dict, List, Optional, Tuple
|
||||
|
||||
from sqlalchemy import orm
|
||||
@ -22,6 +23,8 @@ UNI_TOKEN_1 = "0xd21220a7"
|
||||
|
||||
|
||||
async def _get_logs_for_topics(base_provider, after_block, before_block, topics):
|
||||
while True:
|
||||
try:
|
||||
logs = await base_provider.make_request(
|
||||
"eth_getLogs",
|
||||
[
|
||||
@ -32,7 +35,11 @@ async def _get_logs_for_topics(base_provider, after_block, before_block, topics)
|
||||
}
|
||||
],
|
||||
)
|
||||
|
||||
return logs["result"]
|
||||
except Exception as e:
|
||||
print(f"Error, retrying {e}")
|
||||
sleep(0.05)
|
||||
|
||||
|
||||
def _logs_by_tx(logs):
|
||||
@ -83,6 +90,8 @@ async def classify_logs(logs, pool_reserves, w3):
|
||||
token0, token1 = pool_reserves[pool_address]
|
||||
else:
|
||||
addr = Web3.toChecksumAddress(pool_address)
|
||||
while True:
|
||||
try:
|
||||
token0, token1 = await asyncio.gather(
|
||||
w3.eth.call({"to": addr, "data": UNI_TOKEN_0}),
|
||||
w3.eth.call({"to": addr, "data": UNI_TOKEN_1}),
|
||||
@ -90,6 +99,10 @@ async def classify_logs(logs, pool_reserves, w3):
|
||||
token0 = w3.toHex(token0)
|
||||
token1 = w3.toHex(token1)
|
||||
pool_reserves[pool_address] = (token0, token1)
|
||||
break
|
||||
except Exception as e:
|
||||
print(f"Error, retrying {e}")
|
||||
sleep(0.05)
|
||||
|
||||
am0in, am1in, am0out, am1out = get_swap(log["data"])
|
||||
swap = Swap(
|
||||
|
@ -1,4 +1,5 @@
|
||||
import datetime
|
||||
from time import sleep
|
||||
|
||||
import pandas as pd
|
||||
from profit_analysis.column_names import BLOCK_KEY, TIMESTAMP_KEY
|
||||
@ -15,7 +16,13 @@ def add_block_timestamp(w3, profit_by_block):
|
||||
|
||||
|
||||
def get_block_timestamp(w3, block):
|
||||
while True:
|
||||
try:
|
||||
block_info = w3.eth.get_block(int(block))
|
||||
ts = block_info[TIMESTAMP_KEY]
|
||||
dt = datetime.datetime.fromtimestamp(ts)
|
||||
|
||||
return dt
|
||||
except Exception as e:
|
||||
print(f"Error, retrying {e}")
|
||||
sleep(0.05)
|
||||
|
Loading…
x
Reference in New Issue
Block a user