Skip to content

Commit

Permalink
chore: upgrade web3 to latest version
Browse files Browse the repository at this point in the history
  • Loading branch information
xadahiya committed Jan 4, 2024
1 parent 43f954d commit 8b45196
Show file tree
Hide file tree
Showing 14 changed files with 551 additions and 440 deletions.
949 changes: 539 additions & 410 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ importlib = "^1.0.4"
pika = "^1.3.2"
gunicorn = "^20.1.0"
aiohttp = "^3.8.5"
web3 = "^5.31.4"
web3 = "^6.13.0"
async-limits = {git = "https://github.com/powerloom/limits.git"}
tenacity = "^8.2.2"
limits = "^2.8.0"
Expand Down
4 changes: 2 additions & 2 deletions snapshotter/core_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ async def startup_boilerplate():
await load_rate_limiter_scripts(app.state.auth_aioredis_pool)
app.state.anchor_rpc_helper = RpcHelper(rpc_settings=settings.anchor_chain_rpc)
app.state.protocol_state_contract = app.state.anchor_rpc_helper.get_current_node()['web3_client'].eth.contract(
address=Web3.toChecksumAddress(
address=Web3.to_checksum_address(
protocol_state_contract_address,
),
abi=protocol_state_contract_abi,
Expand Down Expand Up @@ -719,7 +719,7 @@ async def get_task_status_post(

# check wallet address is valid EVM address
try:
Web3.toChecksumAddress(task_status_request.wallet_address)
Web3.to_checksum_address(task_status_request.wallet_address)
except:
response.status_code = 400
return {
Expand Down
2 changes: 0 additions & 2 deletions snapshotter/process_hub_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@
from snapshotter.utils.models.data_models import SnapshotterReportState
from snapshotter.utils.models.message_models import ProcessHubCommand
from snapshotter.utils.rabbitmq_helpers import RabbitmqSelectLoopInteractor
from snapshotter.utils.redis.redis_conn import provide_async_redis_conn
from snapshotter.utils.redis.redis_conn import provide_redis_conn
from snapshotter.utils.redis.redis_conn import provide_redis_conn_repsawning_thread
from snapshotter.utils.redis.redis_conn import REDIS_CONN_CONF
from snapshotter.utils.redis.redis_keys import process_hub_core_start_timestamp
Expand Down
2 changes: 1 addition & 1 deletion snapshotter/processor_distributor.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ async def _load_projects_metadata(self):
with open(settings.protocol_state.abi, 'r') as f:
abi_dict = json.load(f)
protocol_state_contract = self._anchor_rpc_helper.get_current_node()['web3_client'].eth.contract(
address=Web3.toChecksumAddress(
address=Web3.to_checksum_address(
settings.protocol_state.address,
),
abi=abi_dict,
Expand Down
2 changes: 1 addition & 1 deletion snapshotter/snapshotter_id_ping.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async def main():
anchor_rpc = RpcHelper(settings.anchor_chain_rpc)
protocol_abi = read_json_file(settings.protocol_state.abi)
protocol_state_contract = anchor_rpc.get_current_node()['web3_client'].eth.contract(
address=Web3.toChecksumAddress(
address=Web3.to_checksum_address(
settings.protocol_state.address,
),
abi=protocol_abi,
Expand Down
2 changes: 1 addition & 1 deletion snapshotter/system_event_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def __init__(self, name, **kwargs):
)
self.contract_address = settings.protocol_state.address
self.contract = self.rpc_helper.get_current_node()['web3_client'].eth.contract(
address=Web3.toChecksumAddress(
address=Web3.to_checksum_address(
self.contract_address,
),
abi=self.contract_abi,
Expand Down
5 changes: 0 additions & 5 deletions snapshotter/tests/test_web3_async_provider.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import asyncio
import json

from aiohttp import ClientSession
from aiohttp import ClientTimeout
from aiohttp import TCPConnector
from eth_utils.address import to_checksum_address
from web3 import AsyncHTTPProvider
from web3 import HTTPProvider
from web3 import Web3
from web3.eth import AsyncEth

from snapshotter.settings.config import settings
from snapshotter.utils.default_logger import logger
Expand Down
2 changes: 0 additions & 2 deletions snapshotter/utils/aggregation_worker.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import asyncio
import hashlib
import importlib
import json
import time
Expand All @@ -14,7 +13,6 @@
from snapshotter.settings.config import aggregator_config
from snapshotter.settings.config import projects_config
from snapshotter.settings.config import settings
from snapshotter.utils import event_log_decoder
from snapshotter.utils.callback_helpers import send_failure_notifications_async
from snapshotter.utils.generic_worker import GenericAsyncWorker
from snapshotter.utils.models.data_models import SnapshotterIssue
Expand Down
1 change: 0 additions & 1 deletion snapshotter/utils/callback_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from abc import ABC
from abc import ABCMeta
from abc import abstractmethod
from abc import abstractproperty
from typing import Any
from typing import Dict
from typing import List
Expand Down
4 changes: 0 additions & 4 deletions snapshotter/utils/data_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import asyncio
import json
import os
from typing import List

import tenacity
Expand All @@ -11,10 +10,7 @@
from tenacity import stop_after_attempt
from tenacity import wait_random_exponential

from snapshotter.settings.config import settings
from snapshotter.utils.default_logger import logger
from snapshotter.utils.file_utils import read_json_file
from snapshotter.utils.file_utils import write_json_file
from snapshotter.utils.models.data_models import ProjectStatus
from snapshotter.utils.models.data_models import SnapshotterIncorrectSnapshotSubmission
from snapshotter.utils.models.data_models import SnapshotterMissedSnapshotSubmission
Expand Down
6 changes: 3 additions & 3 deletions snapshotter/utils/generic_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ async def _init_rpc_helper(self):
self._anchor_rpc_helper = RpcHelper(rpc_settings=settings.anchor_chain_rpc)

self._protocol_state_contract = self._anchor_rpc_helper.get_current_node()['web3_client'].eth.contract(
address=Web3.toChecksumAddress(
address=Web3.to_checksum_address(
self.protocol_state_contract_address,
),
abi=read_json_file(
Expand All @@ -423,7 +423,7 @@ async def _init_rpc_helper(self):
),
)

self._anchor_chain_id = self._anchor_rpc_helper.get_current_node()['web3_client'].eth.chainId
self._anchor_chain_id = self._anchor_rpc_helper.get_current_node()['web3_client'].eth.chain_id
self._keccak_hash = lambda x: sha3.keccak_256(x).digest()
self._domain_separator = make_domain(
name='PowerloomProtocolContract', version='0.1', chainId=self._anchor_chain_id,
Expand All @@ -432,7 +432,7 @@ async def _init_rpc_helper(self):
self._signer_private_key = PrivateKey.from_hex(settings.signer_private_key)

def generate_signature(self, snapshot_cid, epoch_id, project_id):
current_block = self._anchor_rpc_helper.get_current_node()['web3_client'].eth.blockNumber
current_block = self._anchor_rpc_helper.get_current_node()['web3_client'].eth.block_number

deadline = current_block + settings.protocol_state.deadline_buffer
request = Request(
Expand Down
1 change: 0 additions & 1 deletion snapshotter/utils/models/message_models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import uuid
from typing import Any
from typing import Dict
from typing import List
Expand Down
9 changes: 3 additions & 6 deletions snapshotter/utils/rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
from tenacity import retry_if_exception_type
from tenacity import stop_after_attempt
from tenacity import wait_random_exponential
from web3 import AsyncHTTPProvider
from web3 import AsyncWeb3
from web3 import Web3
from web3._utils.abi import map_abi_data
from web3._utils.events import get_event_data
from web3._utils.normalizers import BASE_RETURN_NORMALIZERS
from web3.eth import AsyncEth
from web3.types import TxParams
from web3.types import Wei

Expand Down Expand Up @@ -178,11 +179,7 @@ async def _load_async_web3_providers(self):
for node in self._nodes:
if node['web3_client_async'] is not None:
continue
node['web3_client_async'] = Web3(
Web3.AsyncHTTPProvider(node['rpc_url']),
modules={'eth': (AsyncEth,)},
middlewares=[],
)
node['web3_client_async'] = AsyncWeb3(AsyncHTTPProvider(node['rpc_url']))

async def init(self, redis_conn):
"""
Expand Down

0 comments on commit 8b45196

Please sign in to comment.