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 asyncio
|
||||||
import logging
|
import logging
|
||||||
|
from time import sleep
|
||||||
from typing import Dict, List, Optional, Tuple
|
from typing import Dict, List, Optional, Tuple
|
||||||
|
|
||||||
from sqlalchemy import orm
|
from sqlalchemy import orm
|
||||||
@ -22,17 +23,23 @@ UNI_TOKEN_1 = "0xd21220a7"
|
|||||||
|
|
||||||
|
|
||||||
async def _get_logs_for_topics(base_provider, after_block, before_block, topics):
|
async def _get_logs_for_topics(base_provider, after_block, before_block, topics):
|
||||||
logs = await base_provider.make_request(
|
while True:
|
||||||
"eth_getLogs",
|
try:
|
||||||
[
|
logs = await base_provider.make_request(
|
||||||
{
|
"eth_getLogs",
|
||||||
"fromBlock": hex(after_block),
|
[
|
||||||
"toBlock": hex(before_block),
|
{
|
||||||
"topics": topics,
|
"fromBlock": hex(after_block),
|
||||||
}
|
"toBlock": hex(before_block),
|
||||||
],
|
"topics": topics,
|
||||||
)
|
}
|
||||||
return logs["result"]
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
return logs["result"]
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error, retrying {e}")
|
||||||
|
sleep(0.05)
|
||||||
|
|
||||||
|
|
||||||
def _logs_by_tx(logs):
|
def _logs_by_tx(logs):
|
||||||
@ -83,13 +90,19 @@ async def classify_logs(logs, pool_reserves, w3):
|
|||||||
token0, token1 = pool_reserves[pool_address]
|
token0, token1 = pool_reserves[pool_address]
|
||||||
else:
|
else:
|
||||||
addr = Web3.toChecksumAddress(pool_address)
|
addr = Web3.toChecksumAddress(pool_address)
|
||||||
token0, token1 = await asyncio.gather(
|
while True:
|
||||||
w3.eth.call({"to": addr, "data": UNI_TOKEN_0}),
|
try:
|
||||||
w3.eth.call({"to": addr, "data": UNI_TOKEN_1}),
|
token0, token1 = await asyncio.gather(
|
||||||
)
|
w3.eth.call({"to": addr, "data": UNI_TOKEN_0}),
|
||||||
token0 = w3.toHex(token0)
|
w3.eth.call({"to": addr, "data": UNI_TOKEN_1}),
|
||||||
token1 = w3.toHex(token1)
|
)
|
||||||
pool_reserves[pool_address] = (token0, token1)
|
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"])
|
am0in, am1in, am0out, am1out = get_swap(log["data"])
|
||||||
swap = Swap(
|
swap = Swap(
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import datetime
|
import datetime
|
||||||
|
from time import sleep
|
||||||
|
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
from profit_analysis.column_names import BLOCK_KEY, TIMESTAMP_KEY
|
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):
|
def get_block_timestamp(w3, block):
|
||||||
block_info = w3.eth.get_block(int(block))
|
while True:
|
||||||
ts = block_info[TIMESTAMP_KEY]
|
try:
|
||||||
dt = datetime.datetime.fromtimestamp(ts)
|
block_info = w3.eth.get_block(int(block))
|
||||||
return dt
|
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