Skip to content

Commit 04744d4

Browse files
author
abel
committed
(feat) Added gRPC keepalive options to all gRPC channels
1 parent b8be53c commit 04744d4

File tree

3 files changed

+37
-8
lines changed

3 files changed

+37
-8
lines changed

examples/SendToInjective.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ async def main() -> None:
2727

2828
data = '{"@type": "/injective.exchange.v1beta1.MsgDeposit","sender": "inj14au322k9munkmx5wrchz9q30juf5wjgz2cfqku","subaccountId": "0xaf79152ac5df276d9a8e1e2e22822f9713474902000000000000000000000000","amount": {"denom": "inj","amount": "1000000000000000000"}}'
2929

30-
import_peggo = pkg_resources.read_text(pyinjective, 'Peggo_ABI.json')
31-
peggo_abi = json.loads(import_peggo)
30+
with open("../pyinjective/Peggo_ABI.json") as pego_file:
31+
peggo_data = pego_file.read()
32+
peggo_abi = json.loads(peggo_data)
3233

3334
peggo_composer.sendToInjective(ethereum_endpoint=ethereum_endpoint, private_key=private_key, token_contract=token_contract,
3435
receiver=receiver, amount=amount, maxFeePerGas=maxFeePerGas_Gwei, maxPriorityFeePerGas=maxPriorityFeePerGas_Gwei, data=data, peggo_abi=peggo_abi)

examples/chain_client/48_WithdrawValidatorCommission_Rewards renamed to examples/chain_client/48_WithdrawValidatorCommissionAndRewards.py

File renamed without changes.

pyinjective/async_client.py

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@
7070
DEFAULT_SESSION_RENEWAL_OFFSET = 120 # seconds
7171
DEFAULT_BLOCK_TIME = 2 # seconds
7272

73+
GRPC_CHANNEL_OPTIONS = [
74+
("grpc.keepalive_time_ms", 45000),
75+
("grpc.keepalive_timeout_ms", 5000),
76+
("grpc.http2.max_pings_without_data", 5),
77+
("grpc.keepalive_permit_without_calls", 1),
78+
]
79+
7380

7481
class AsyncClient:
7582
def __init__(
@@ -88,9 +95,16 @@ def __init__(
8895

8996
# chain stubs
9097
self.chain_channel = (
91-
grpc.aio.secure_channel(network.grpc_endpoint, credentials)
98+
grpc.aio.secure_channel(
99+
target=network.grpc_endpoint,
100+
credentials=credentials,
101+
options=GRPC_CHANNEL_OPTIONS,
102+
)
92103
if (network.use_secure_connection and credentials is not None)
93-
else grpc.aio.insecure_channel(network.grpc_endpoint)
104+
else grpc.aio.insecure_channel(
105+
target=network.grpc_endpoint,
106+
options=GRPC_CHANNEL_OPTIONS,
107+
)
94108
)
95109

96110
self.stubCosmosTendermint = tendermint_query_grpc.ServiceStub(
@@ -106,9 +120,16 @@ def __init__(
106120

107121
# exchange stubs
108122
self.exchange_channel = (
109-
grpc.aio.secure_channel(network.grpc_exchange_endpoint, credentials)
123+
grpc.aio.secure_channel(
124+
target=network.grpc_exchange_endpoint,
125+
credentials=credentials,
126+
options=GRPC_CHANNEL_OPTIONS,
127+
)
110128
if (network.use_secure_connection and credentials is not None)
111-
else grpc.aio.insecure_channel(network.grpc_exchange_endpoint)
129+
else grpc.aio.insecure_channel(
130+
target=network.grpc_exchange_endpoint,
131+
options=GRPC_CHANNEL_OPTIONS,
132+
)
112133
)
113134
self.stubMeta = exchange_meta_rpc_grpc.InjectiveMetaRPCStub(
114135
self.exchange_channel
@@ -137,9 +158,16 @@ def __init__(
137158

138159
# explorer stubs
139160
self.explorer_channel = (
140-
grpc.aio.secure_channel(network.grpc_explorer_endpoint, credentials)
161+
grpc.aio.secure_channel(
162+
target=network.grpc_explorer_endpoint,
163+
credentials=credentials,
164+
options=GRPC_CHANNEL_OPTIONS,
165+
)
141166
if (network.use_secure_connection and credentials is not None)
142-
else grpc.aio.insecure_channel(network.grpc_explorer_endpoint)
167+
else grpc.aio.insecure_channel(
168+
target=network.grpc_explorer_endpoint,
169+
options=GRPC_CHANNEL_OPTIONS,
170+
)
143171
)
144172
self.stubExplorer = explorer_rpc_grpc.InjectiveExplorerRPCStub(
145173
self.explorer_channel

0 commit comments

Comments
 (0)