Skip to content

Commit 8dea1f9

Browse files
committed
backend: Use exponential backoff when accessing ETH-RPC
Without this, we will get HTTP 429 Errors before finishing the first sync, causing the backend to restart and running into the same error again.
1 parent a402582 commit 8dea1f9

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

backend/metrics_backend/metrics_cli.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
contracts_precompiled_path,
2424
get_contracts_deployment_info
2525
)
26+
from raiden_common.blockchain.middleware import http_retry_with_backoff_middleware
2627
from requests.exceptions import ConnectionError
2728
from web3 import HTTPProvider, Web3
2829

@@ -109,7 +110,14 @@ def main(
109110
log.info("Starting Raiden Metrics Server")
110111
try:
111112
log.info(f'Starting Web3 client for node at {eth_rpc}')
112-
web3 = Web3(HTTPProvider(eth_rpc))
113+
provider = HTTPProvider(eth_rpc)
114+
115+
# give web3 some time between retries before failing
116+
provider.middlewares.replace( # type: ignore
117+
"http_retry_request", http_retry_with_backoff_middleware
118+
)
119+
120+
web3 = Web3(provider)
113121
except ConnectionError:
114122
log.error(
115123
'Can not connect to the Ethereum client. Please check that it is running and that '

backend/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
raiden-common == 0.1.4
1+
raiden-common == 0.1.5
22

33
Click
44

0 commit comments

Comments
 (0)