Skip to content

Commit ee846f0

Browse files
authored
Merge pull request #12 from stakewise/ws-endpoint-timeout
Add setting to change WS endpoint timeout
2 parents 3f674ee + e5737d9 commit ee846f0

File tree

4 files changed

+9
-2
lines changed

4 files changed

+9
-2
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ where `settings.txt` is an environment file with [Settings](#settings).
7070
|----------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------|---------|
7171
| LOG_LEVEL | The log level of the program. | No | DEBUG |
7272
| WEB3_WS_ENDPOINT | The WS endpoint to the ETH1 client. Must be specified if `WEB3_HTTP_ENDPOINT` endpoint is not provided. | No | - |
73+
| WEB3_WS_ENDPOINT_TIMEOUT | The WS endpoint timeout in seconds. | No | 60 |
7374
| WEB3_HTTP_ENDPOINT | The HTTP endpoint to the ETH1 client. Must be specified if `WEB3_WS_ENDPOINT` endpoint is not provided. | No | - |
7475
| BEACON_CHAIN_RPC_ENDPOINT | The Beacon Chain RPC HTTP endpoint. | Yes | - |
7576
| INJECT_POA_MIDDLEWARE | Whether to inject POA middleware into Web3 client (see [POA middleware](https://web3py.readthedocs.io/en/stable/middleware.html#geth-style-proof-of-authority)). | No | False |
@@ -104,7 +105,7 @@ BALANCE_WARNING_THRESHOLD=0.05
104105
BALANCE_ERROR_THRESHOLD=0.008
105106
APPLY_GAS_PRICE_STRATEGY=True
106107
MAX_TX_WAIT_SECONDS=180
107-
TRANSACTION_TIMEOUT=3600
108+
TRANSACTION_TIMEOUT=10800
108109
PROCESS_INTERVAL=30
109110
ORACLES_CONTRACT_ADDRESS=0x2f1C5E86B13a74f5A6E7B4b35DD77fe29Aa47514
110111
POOL_CONTRACT_ADDRESS=0xC874b064f465bdD6411D45734b56fac750Cda29A

main.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from src.reward_token import RewardToken
88
from src.settings import (
99
WEB3_WS_ENDPOINT,
10+
WEB3_WS_ENDPOINT_TIMEOUT,
1011
WEB3_HTTP_ENDPOINT,
1112
INJECT_POA_MIDDLEWARE,
1213
INJECT_STALE_CHECK_MIDDLEWARE,
@@ -49,6 +50,7 @@ def main() -> None:
4950
web3_client = get_web3_client(
5051
http_endpoint=WEB3_HTTP_ENDPOINT,
5152
ws_endpoint=WEB3_WS_ENDPOINT,
53+
ws_endpoint_timeout=WEB3_WS_ENDPOINT_TIMEOUT,
5254
apply_gas_price_strategy=APPLY_GAS_PRICE_STRATEGY,
5355
max_tx_wait_seconds=MAX_TX_WAIT_SECONDS,
5456
inject_retry_request=INJECT_RETRY_REQUEST_MIDDLEWARE,

src/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# connections
1212
# use either WS or HTTP for Web3
1313
WEB3_WS_ENDPOINT: str = environ.get("WEB3_WS_ENDPOINT", "")
14+
WEB3_WS_ENDPOINT_TIMEOUT: int = int(environ.get("WEB3_WS_ENDPOINT_TIMEOUT", "60"))
1415
WEB3_HTTP_ENDPOINT: str = "" if WEB3_WS_ENDPOINT else environ["WEB3_HTTP_ENDPOINT"]
1516
BEACON_CHAIN_RPC_ENDPOINT: str = environ["BEACON_CHAIN_RPC_ENDPOINT"]
1617

src/utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ def ws_retry_request_middleware(
7878
def get_web3_client(
7979
http_endpoint: str = "",
8080
ws_endpoint: str = "",
81+
ws_endpoint_timeout: int = 60,
8182
apply_gas_price_strategy: bool = False,
8283
max_tx_wait_seconds: int = 120,
8384
inject_retry_request: bool = False,
@@ -89,7 +90,9 @@ def get_web3_client(
8990
"""Returns instance of the Web3 client."""
9091
# Either http or ws endpoint must be provided (prefer ws over http)
9192
if ws_endpoint:
92-
w3 = Web3(Web3.WebsocketProvider(ws_endpoint))
93+
w3 = Web3(
94+
Web3.WebsocketProvider(ws_endpoint, websocket_timeout=ws_endpoint_timeout)
95+
)
9396
logger.info(f"Using Web3 websocket endpoint {ws_endpoint}")
9497

9598
if inject_retry_request:

0 commit comments

Comments
 (0)