Skip to content
This repository has been archived by the owner on Feb 13, 2024. It is now read-only.

Commit

Permalink
Using different ports for http and ws connections
Browse files Browse the repository at this point in the history
  • Loading branch information
ochaloup committed Jan 5, 2022
1 parent 3947e33 commit ab65855
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
19 changes: 16 additions & 3 deletions mango/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,11 +290,12 @@ def is_acceptable(self, slot_to_check: int) -> bool:
# A `RPCCaller` extends the HTTPProvider with better error handling.
#
class RPCCaller(HTTPProvider):
def __init__(self, name: str, cluster_url: str, stale_data_pauses_before_retry: typing.Sequence[float], slot_holder: SlotHolder, instruction_reporter: InstructionReporter):
def __init__(self, name: str, cluster_url: str, cluster_url_ws: str, stale_data_pauses_before_retry: typing.Sequence[float], slot_holder: SlotHolder, instruction_reporter: InstructionReporter):
super().__init__(cluster_url)
self._logger: logging.Logger = logging.getLogger(self.__class__.__name__)
self.name: str = name
self.cluster_url: str = cluster_url
self.cluster_url_ws: str = cluster_url_ws
self.stale_data_pauses_before_retry: typing.Sequence[float] = stale_data_pauses_before_retry
self.slot_holder: SlotHolder = slot_holder
self.instruction_reporter: InstructionReporter = instruction_reporter
Expand Down Expand Up @@ -531,11 +532,15 @@ def __init__(self, client: Client, name: str, cluster_name: str, commitment: Com
self.rpc_caller: CompoundRPCCaller = rpc_caller

@staticmethod
def from_configuration(name: str, cluster_name: str, cluster_urls: typing.Sequence[str], commitment: Commitment, skip_preflight: bool, encoding: str, blockhash_cache_duration: int, stale_data_pauses_before_retry: typing.Sequence[float], instruction_reporter: InstructionReporter) -> "BetterClient":
def from_configuration(name: str, cluster_name: str, cluster_urls: typing.Sequence[str], cluster_urls_wss: typing.Optional[typing.Dict[str, str]], commitment: Commitment, skip_preflight: bool, encoding: str, blockhash_cache_duration: int, stale_data_pauses_before_retry: typing.Sequence[float], instruction_reporter: InstructionReporter) -> "BetterClient":
slot_holder: SlotHolder = SlotHolder()
rpc_callers: typing.List[RPCCaller] = []
for cluster_url in cluster_urls:
rpc_caller: RPCCaller = RPCCaller(name, cluster_url, stale_data_pauses_before_retry,
cluster_url_wss = cluster_url.replace("https", "wss", 1)
if cluster_urls_wss is not None and cluster_url in cluster_urls_wss:
cluster_url_wss = cluster_urls_wss[cluster_url]

rpc_caller: RPCCaller = RPCCaller(name, cluster_url, cluster_url_wss, stale_data_pauses_before_retry,
slot_holder, instruction_reporter)
rpc_callers += [rpc_caller]

Expand Down Expand Up @@ -566,6 +571,14 @@ def cluster_url(self) -> str:
def cluster_urls(self) -> typing.Sequence[str]:
return [rpc_caller.cluster_url for rpc_caller in self.rpc_caller.all_providers]

@property
def cluster_url_ws(self) -> str:
return self.rpc_caller.current.cluster_url_ws

@property
def cluster_urls_ws(self) -> typing.Sequence[str]:
return [rpc_caller.cluster_url_ws for rpc_caller in self.rpc_caller.all_providers]

@property
def instruction_reporter(self) -> InstructionReporter:
return self.rpc_caller.current.instruction_reporter
Expand Down
10 changes: 7 additions & 3 deletions mango/contextbuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def from_command_line_parameters(args: argparse.Namespace) -> Context:
actual_stale_data_pauses_before_retry = [
float(stale_data_pause_before_retry)] * actual_maximum_stale_data_pauses

context: Context = ContextBuilder.build(name, cluster_name, cluster_urls, skip_preflight, commitment,
context: Context = ContextBuilder.build(name, cluster_name, cluster_urls, None, skip_preflight, commitment,
encoding, blockhash_cache_duration,
actual_stale_data_pauses_before_retry,
group_name, group_address, mango_program_address,
Expand All @@ -138,6 +138,7 @@ def default() -> Context:
@staticmethod
def from_group_name(context: Context, group_name: str) -> Context:
return ContextBuilder.build(context.name, context.client.cluster_name, context.client.cluster_urls,
context.client.cluster_urls_ws,
context.client.skip_preflight, context.client.commitment,
context.client.encoding, context.client.blockhash_cache_duration,
context.client.stale_data_pauses_before_retry,
Expand All @@ -153,6 +154,7 @@ def forced_to_devnet(context: Context) -> Context:
fresh_context.client = BetterClient.from_configuration(context.name,
cluster_name,
[cluster_url],
None,
context.client.commitment,
context.client.skip_preflight,
context.client.encoding,
Expand Down Expand Up @@ -181,7 +183,9 @@ def forced_to_mainnet_beta(context: Context) -> Context:

@staticmethod
def build(name: typing.Optional[str] = None, cluster_name: typing.Optional[str] = None,
cluster_urls: typing.Optional[typing.Sequence[str]] = None, skip_preflight: bool = False,
cluster_urls: typing.Optional[typing.Sequence[str]] = None,
cluster_urls_wss: typing.Optional[typing.Dict[str, str]] = None,
skip_preflight: bool = False,
commitment: typing.Optional[str] = None, encoding: typing.Optional[str] = None,
blockhash_cache_duration: typing.Optional[int] = None,
stale_data_pauses_before_retry: typing.Optional[typing.Sequence[float]] = None,
Expand Down Expand Up @@ -304,4 +308,4 @@ def __public_key_or_none(address: typing.Optional[str]) -> typing.Optional[Publi
devnet_serum_market_lookup])
market_lookup: MarketLookup = all_market_lookup

return Context(actual_name, actual_cluster, actual_cluster_urls, actual_skip_preflight, actual_commitment, actual_encoding, actual_blockhash_cache_duration, actual_stale_data_pauses_before_retry, actual_program_address, actual_serum_program_address, actual_group_name, actual_group_address, actual_gma_chunk_size, actual_gma_chunk_pause, instrument_lookup, market_lookup)
return Context(actual_name, actual_cluster, actual_cluster_urls, cluster_urls_wss, actual_skip_preflight, actual_commitment, actual_encoding, actual_blockhash_cache_duration, actual_stale_data_pauses_before_retry, actual_program_address, actual_serum_program_address, actual_group_name, actual_group_address, actual_gma_chunk_size, actual_gma_chunk_pause, instrument_lookup, market_lookup)

0 comments on commit ab65855

Please sign in to comment.