Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Reuse connection to Solana #417 (#418)
* Reuse connection to Solana #417

* Fix patch #417

* Reuse connection in proxy & airdropper #417

Co-authored-by: Semen Medvedev <[email protected]>
  • Loading branch information
s-medvedev and Semen Medvedev authored Dec 28, 2021
commit fe8a463f67ec5f3b1139af539bb902f712d2c416
2 changes: 1 addition & 1 deletion proxy/common_neon/solana_interactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def _send_rpc_batch_request(self, method: str, params_list: List[Any]) -> List[R
request = {"jsonrpc": "2.0", "id": request_id, "method": method, "params": params}
request_data.append(request)

response = requests.post(self.client._provider.endpoint_uri, headers={"Content-Type": "application/json"}, json=request_data)
response = self.client._provider.session.post(self.client._provider.endpoint_uri, headers={"Content-Type": "application/json"}, json=request_data)
response.raise_for_status()

response_data = cast(List[RPCResponse], response.json())
Expand Down
3 changes: 2 additions & 1 deletion proxy/indexer/airdropper.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def __init__(self,
price_upd_interval, # seconds
mainnet_price_accounts)
self.neon_decimals = neon_decimals
self.session = requests.Session()


# helper function checking if given contract address is in whitelist
Expand Down Expand Up @@ -91,7 +92,7 @@ def _airdrop_to(self, create_acc):
airdrop_galans = int(airdrop_amount_neon * pow(10, self.neon_decimals))

json_data = { 'wallet': eth_address, 'amount': airdrop_galans }
resp = requests.post(self.faucet_url + '/request_neon_in_galans', json = json_data)
resp = self.session.post(self.faucet_url + '/request_neon_in_galans', json = json_data)
if not resp.ok:
logger.warning(f'Failed to airdrop: {resp.status_code}')
return
Expand Down
31 changes: 31 additions & 0 deletions proxy/solana-py.patch
Original file line number Diff line number Diff line change
@@ -1,3 +1,34 @@
diff --git a/solana/rpc/providers/http.py b/solana/rpc/providers/http.py
index 5fb68dd..e7ebafe 100644
--- solana/rpc/providers/http.py
+++ solana/rpc/providers/http.py
@@ -25,6 +25,7 @@ class HTTPProvider(BaseProvider, FriendlyJsonSerde):
"""Init HTTPProvider."""
self._request_counter = itertools.count()
self.endpoint_uri = get_default_endpoint() if not endpoint else URI(endpoint)
+ self.session = requests.Session()

def __str__(self) -> str:
"""String definition for HTTPProvider."""
@@ -42,7 +43,7 @@ class HTTPProvider(BaseProvider, FriendlyJsonSerde):
)
headers = {"Content-Type": "application/json"}
data = self.json_encode({"jsonrpc": "2.0", "id": request_id, "method": method, "params": params})
- raw_response = requests.post(self.endpoint_uri, headers=headers, data=data)
+ raw_response = self.session.post(self.endpoint_uri, headers=headers, data=data)
raw_response.raise_for_status()
self.logger.debug(
"Getting response HTTP. URI: %s, " "Method: %s, Response: %s", self.endpoint_uri, method, raw_response.text
@@ -52,7 +53,7 @@ class HTTPProvider(BaseProvider, FriendlyJsonSerde):
def is_connected(self) -> bool:
"""Health check."""
try:
- response = requests.get(f"{self.endpoint_uri}/health")
+ response = self.session.get(f"{self.endpoint_uri}/health")
response.raise_for_status()
except (IOError, requests.HTTPError) as err:
self.logger.error("Health check failed with error: %s", str(err))

--- solana/rpc/api.py 2021-05-25 13:08:52.430148672 +0300
+++ solana/rpc/api.py 2021-05-25 13:08:43.102202173 +0300
@@ -14,7 +14,7 @@
Expand Down