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

Commit

Permalink
[marketmaker] possible to configure max retries when sending transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
ochaloup committed Feb 11, 2022
1 parent 63e3a9d commit 21b2053
Show file tree
Hide file tree
Showing 4 changed files with 25 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,
max_retries: 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.max_retries: int = max_retries
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,
max_retries: 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,
max_retries,
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_max_retries = opts.max_retries
if proper_commitment == UnspecifiedCommitment:
proper_commitment = self.commitment
proper_skip_preflight = self.skip_preflight
proper_max_retries = self.max_retries if self.max_retries >= 0 else None

proper_opts = TxOpts(
preflight_commitment=proper_commitment,
skip_confirmation=opts.skip_confirmation,
skip_preflight=proper_skip_preflight,
max_retries=proper_max_retries
)

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,
max_retries: 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,
max_retries,
encoding,
blockhash_cache_duration,
http_request_timeout,
Expand Down
14 changes: 14 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(
"--max-retries",
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)
max_retries: int = int(args.max_retries)
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,
max_retries,
commitment,
encoding,
blockhash_cache_duration,
Expand Down Expand Up @@ -265,6 +273,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.max_retries,
context.client.commitment,
context.client.encoding,
context.client.blockhash_cache_duration,
Expand Down Expand Up @@ -292,6 +301,7 @@ def forced_to_devnet(context: Context) -> Context:
[cluster_url],
context.client.commitment,
context.client.skip_preflight,
context.client.max_retries,
context.client.encoding,
context.client.blockhash_cache_duration,
-1,
Expand All @@ -315,6 +325,7 @@ def forced_to_mainnet_beta(context: Context) -> Context:
[cluster_url],
context.client.commitment,
context.client.skip_preflight,
context.client.max_retries,
context.client.encoding,
context.client.blockhash_cache_duration,
-1,
Expand All @@ -331,6 +342,7 @@ def build(
cluster_name: typing.Optional[str] = None,
cluster_urls: typing.Optional[typing.Sequence[ClusterUrlData]] = None,
skip_preflight: bool = False,
max_retries: 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 +387,7 @@ def __public_key_or_none(
stale_data_pauses_before_retry or []
)
actual_http_request_timeout: float = http_request_timeout or -1
actual_max_retries: int = int(max_retries)

actual_cluster_urls: typing.Optional[
typing.Sequence[ClusterUrlData]
Expand Down Expand Up @@ -539,6 +552,7 @@ def __public_key_or_none(
actual_cluster,
actual_cluster_urls,
actual_skip_preflight,
actual_max_retries,
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,
max_retries=-1,
commitment="processed",
encoding="base64",
blockhash_cache_duration=0,
Expand Down

0 comments on commit 21b2053

Please sign in to comment.