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

Commit

Permalink
Merge pull request #44 from ochaloup/max-retries-configurable
Browse files Browse the repository at this point in the history
[marketmaker] possible to configure tpu retransmissions (max retries in txn opts) when sending a transaction
  • Loading branch information
OpinionatedGeek committed Feb 15, 2022
2 parents 9d92ebb + 31c9cc6 commit fa21fff
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
7 changes: 7 additions & 0 deletions mango/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,7 @@ def __init__(
cluster_name: str,
commitment: Commitment,
skip_preflight: bool,
tpu_retransmissions: int,
encoding: str,
blockhash_cache_duration: int,
rpc_caller: CompoundRPCCaller,
Expand All @@ -855,6 +856,7 @@ def __init__(
self.cluster_name: str = cluster_name
self.commitment: Commitment = commitment
self.skip_preflight: bool = skip_preflight
self.tpu_retransmissions: int = tpu_retransmissions
self.encoding: str = encoding
self.blockhash_cache_duration: int = blockhash_cache_duration
self.rpc_caller: CompoundRPCCaller = rpc_caller
Expand All @@ -870,6 +872,7 @@ def from_configuration(
cluster_urls: typing.Sequence[ClusterUrlData],
commitment: Commitment,
skip_preflight: bool,
tpu_retransmissions: int,
encoding: str,
blockhash_cache_duration: int,
http_request_timeout: float,
Expand Down Expand Up @@ -919,6 +922,7 @@ def __on_provider_change() -> None:
cluster_name,
commitment,
skip_preflight,
tpu_retransmissions,
encoding,
blockhash_cache_duration,
provider,
Expand Down Expand Up @@ -1108,14 +1112,17 @@ def send_transaction(
try:
proper_commitment: Commitment = opts.preflight_commitment
proper_skip_preflight = opts.skip_preflight
proper_tpu_retransmissions = opts.tpu_retransmissions
if proper_commitment == UnspecifiedCommitment:
proper_commitment = self.commitment
proper_skip_preflight = self.skip_preflight
proper_tpu_retransmissions = self.tpu_retransmissions if self.tpu_retransmissions >= 0 else None

proper_opts = TxOpts(
preflight_commitment=proper_commitment,
skip_confirmation=opts.skip_confirmation,
skip_preflight=proper_skip_preflight,
tpu_retransmissions=proper_tpu_retransmissions
)

response = self.compatible_client.send_transaction(
Expand Down
2 changes: 2 additions & 0 deletions mango/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def __init__(
cluster_name: str,
cluster_urls: typing.Sequence[ClusterUrlData],
skip_preflight: bool,
tpu_retransmissions: int,
commitment: str,
encoding: str,
blockhash_cache_duration: int,
Expand Down Expand Up @@ -77,6 +78,7 @@ def __init__(
cluster_urls,
Commitment(commitment),
skip_preflight,
tpu_retransmissions,
encoding,
blockhash_cache_duration,
http_request_timeout,
Expand Down
16 changes: 16 additions & 0 deletions mango/contextbuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@ def add_command_line_parameters(parser: argparse.ArgumentParser) -> None:
action="store_true",
help="Skip pre-flight checks",
)
parser.add_argument(
"--tpu-retransmissions",
default=-1,
type=int,
help="Number of attempts the RPC node runs to deliver a transaction to TPU (default -1 means redelivering until success or recent blockhash expires)"
)
parser.add_argument(
"--commitment",
type=str,
Expand Down Expand Up @@ -207,6 +213,7 @@ def from_command_line_parameters(args: argparse.Namespace) -> Context:
mango_program_address: typing.Optional[PublicKey] = args.mango_program_address
serum_program_address: typing.Optional[PublicKey] = args.serum_program_address
skip_preflight: bool = bool(args.skip_preflight)
tpu_retransmissions: int = int(args.tpu_retransmissions)
commitment: typing.Optional[str] = args.commitment
encoding: typing.Optional[str] = args.encoding
blockhash_cache_duration: typing.Optional[int] = args.blockhash_cache_duration
Expand Down Expand Up @@ -237,6 +244,7 @@ def from_command_line_parameters(args: argparse.Namespace) -> Context:
cluster_name,
cluster_urls,
skip_preflight,
tpu_retransmissions,
commitment,
encoding,
blockhash_cache_duration,
Expand All @@ -249,6 +257,7 @@ def from_command_line_parameters(args: argparse.Namespace) -> Context:
gma_chunk_size,
gma_chunk_pause,
reflink,
NullTransactionStatusCollector()
)
logging.debug(f"{context}")

Expand All @@ -265,6 +274,7 @@ def from_group_name(context: Context, group_name: str) -> Context:
context.client.cluster_name,
context.client.cluster_urls,
context.client.skip_preflight,
context.client.tpu_retransmissions,
context.client.commitment,
context.client.encoding,
context.client.blockhash_cache_duration,
Expand All @@ -277,6 +287,7 @@ def from_group_name(context: Context, group_name: str) -> Context:
context.gma_chunk_size,
context.gma_chunk_pause,
context.reflink,
context.client.transaction_status_collector,
)

@staticmethod
Expand All @@ -292,6 +303,7 @@ def forced_to_devnet(context: Context) -> Context:
[cluster_url],
context.client.commitment,
context.client.skip_preflight,
context.client.tpu_retransmissions,
context.client.encoding,
context.client.blockhash_cache_duration,
-1,
Expand All @@ -315,6 +327,7 @@ def forced_to_mainnet_beta(context: Context) -> Context:
[cluster_url],
context.client.commitment,
context.client.skip_preflight,
context.client.tpu_retransmissions,
context.client.encoding,
context.client.blockhash_cache_duration,
-1,
Expand All @@ -331,6 +344,7 @@ def build(
cluster_name: typing.Optional[str] = None,
cluster_urls: typing.Optional[typing.Sequence[ClusterUrlData]] = None,
skip_preflight: bool = False,
tpu_retransmissions: int = -1,
commitment: typing.Optional[str] = None,
encoding: typing.Optional[str] = None,
blockhash_cache_duration: typing.Optional[int] = None,
Expand Down Expand Up @@ -375,6 +389,7 @@ def __public_key_or_none(
stale_data_pauses_before_retry or []
)
actual_http_request_timeout: float = http_request_timeout or -1
actual_tpu_retransmissions: int = int(tpu_retransmissions)

actual_cluster_urls: typing.Optional[
typing.Sequence[ClusterUrlData]
Expand Down Expand Up @@ -539,6 +554,7 @@ def __public_key_or_none(
actual_cluster,
actual_cluster_urls,
actual_skip_preflight,
actual_tpu_retransmissions,
actual_commitment,
actual_encoding,
actual_blockhash_cache_duration,
Expand Down
2 changes: 2 additions & 0 deletions tests/fakes.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def __init__(self) -> None:
"local",
Commitment("processed"),
False,
-1,
"base64",
0,
compound,
Expand Down Expand Up @@ -78,6 +79,7 @@ def fake_context(
mango.ClusterUrlData(rpc="http://localhost"),
],
skip_preflight=False,
tpu_retransmissions=-1,
commitment="processed",
encoding="base64",
blockhash_cache_duration=0,
Expand Down

0 comments on commit fa21fff

Please sign in to comment.