Skip to content

Commit

Permalink
Revert "Revert "PLAT-955: default to local RPC and fallback to gatewa…
Browse files Browse the repository at this point in the history
…y"" (#5247)
  • Loading branch information
alecsavvy committed May 18, 2023
1 parent 9712f84 commit e9a9179
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 12 deletions.
Expand Up @@ -245,7 +245,7 @@ def setup_search(app_module):
capture_output=True,
text=True,
cwd="es-indexer",
timeout=10,
timeout=30,
)


Expand Down
Expand Up @@ -49,7 +49,7 @@ def test_search_track_tags(app_module):
capture_output=True,
text=True,
cwd="es-indexer",
timeout=10,
timeout=30,
)

result = search_tags_es("pop", kind="tracks")
Expand Down
Expand Up @@ -42,7 +42,7 @@ def test_search_user_tags(app):
capture_output=True,
text=True,
cwd="es-indexer",
timeout=10,
timeout=30,
)

result = search_tags_es("pop", kind="users")
Expand Down
Expand Up @@ -86,7 +86,7 @@ def test_get_feed_es(app):
capture_output=True,
text=True,
cwd="es-indexer",
timeout=10,
timeout=30,
)
esclient.indices.refresh(index="*")
search_res = esclient.search(index="*", query={"match_all": {}})["hits"]["hits"]
Expand Down
4 changes: 1 addition & 3 deletions discovery-provider/src/queries/get_health.py
Expand Up @@ -383,9 +383,7 @@ def get_health(args: GetHealthArgs, use_redis_cache: bool = True) -> Tuple[Dict,
if latest_block_num is not None and latest_indexed_block_num is not None:
# adjust latest block if web3 is pointed to ACDC
# indicating POA has finished indexing
if final_poa_block and web3.provider.endpoint_uri == os.getenv(
"audius_web3_nethermind_rpc"
):
if final_poa_block:
latest_block_num += final_poa_block
block_difference = abs(
latest_block_num - latest_indexed_block_num
Expand Down
21 changes: 16 additions & 5 deletions discovery-provider/src/utils/web3_provider.py
Expand Up @@ -2,26 +2,36 @@
Interface for using a web3 provider
"""

import logging
import os
from typing import Optional

import requests
from src.utils.config import shared_config
from src.utils.multi_provider import MultiProvider
from web3 import HTTPProvider, Web3
from web3.middleware import geth_poa_middleware

logger = logging.getLogger(__name__)

web3: Optional[Web3] = None
LOCAL_RPC = "http://chain:8545" # TODO: Needs nethermind locally I think
LOCAL_RPC = "http://chain:8545"


def get_web3(web3endpoint=None):
# only use ACDC web3 provider when
# final_poa_block is indexed

# pylint: disable=W0603
global web3
if not web3endpoint:
web3endpoint = os.getenv("audius_web3_host")
# attempt local rpc, check if healthy
try:
if requests.get(LOCAL_RPC + "/health").status_code == 200:
web3endpoint = LOCAL_RPC
logger.info("web3_provider.py | using local RPC")
else:
raise Exception("local RPC unhealthy or unreachable")
except Exception as e:
web3endpoint = os.getenv("audius_web3_host")
logger.warn(e)
web3 = Web3(HTTPProvider(web3endpoint))

# required middleware for POA
Expand All @@ -33,6 +43,7 @@ def get_web3(web3endpoint=None):
eth_web3: Optional[Web3] = None


# mainnet eth, not ACDC
def get_eth_web3():
# pylint: disable=W0603
global eth_web3
Expand Down

0 comments on commit e9a9179

Please sign in to comment.