Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
21 changes: 15 additions & 6 deletions apps/price_pusher/src/solana/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ export default {
type: "number",
default: 50000,
} as Options,
"jito-endpoint": {
description: "Jito endpoint",
"jito-endpoints": {
description: "Jito endpoint(s) - comma-separated list of endpoints",
type: "string",
optional: true,
} as Options,
Expand Down Expand Up @@ -117,7 +117,7 @@ export default {
pythContractAddress,
pushingFrequency,
pollingFrequency,
jitoEndpoint,
jitoEndpoints,
jitoKeypairFile,
jitoTipLamports,
dynamicJitoTips,
Expand Down Expand Up @@ -209,7 +209,13 @@ export default {
Uint8Array.from(JSON.parse(fs.readFileSync(jitoKeypairFile, "ascii"))),
);

const jitoClient = searcherClient(jitoEndpoint, jitoKeypair);
const jitoEndpointsList = jitoEndpoints
.split(",")
.map((endpoint: string) => endpoint.trim());
const jitoClients: SearcherClient[] = jitoEndpointsList.map(
(endpoint: string) => searcherClient(endpoint, jitoKeypair),
);

solanaPricePusher = new SolanaPricePusherJito(
pythSolanaReceiver,
hermesClient,
Expand All @@ -218,13 +224,16 @@ export default {
jitoTipLamports,
dynamicJitoTips,
maxJitoTipLamports,
jitoClient,
jitoClients,
jitoBundleSize,
updatesPerJitoBundle,
60000, // Default max retry time of 60 seconds
lookupTableAccount,
);

onBundleResult(jitoClient, logger.child({ module: "JitoClient" }));
jitoClients.forEach((client, index) => {
onBundleResult(client, logger.child({ module: `JitoClient-${index}` }));
});
} else {
solanaPricePusher = new SolanaPricePusher(
pythSolanaReceiver,
Expand Down
50 changes: 29 additions & 21 deletions apps/price_pusher/src/solana/solana.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,10 @@ export class SolanaPricePusherJito implements IPricePusher {
private defaultJitoTipLamports: number,
private dynamicJitoTips: boolean,
private maxJitoTipLamports: number,
private searcherClient: SearcherClient,
private searcherClients: SearcherClient[],
private jitoBundleSize: number,
private updatesPerJitoBundle: number,
private maxRetryTimeMs: number = 60000, // Default to 60 seconds max retry time
private addressLookupTableAccount?: AddressLookupTableAccount,
) {}

Expand Down Expand Up @@ -242,27 +243,34 @@ export class SolanaPricePusherJito implements IPricePusher {
jitoBundleSize: this.jitoBundleSize,
});

let retries = 60;
while (retries > 0) {
try {
await sendTransactionsJito(
transactions,
this.searcherClient,
this.pythSolanaReceiver.wallet,
);
break;
} catch (err: any) {
if (err.code === 8 && err.details?.includes("Rate limit exceeded")) {
this.logger.warn("Rate limit hit, waiting before retry...");
await this.sleep(1100); // Wait slightly more than 1 second
retries--;
if (retries === 0) {
this.logger.error("Max retries reached for rate limit");
throw err;
}
} else {
throw err;
try {
await sendTransactionsJito(
transactions,
this.searcherClients,
this.pythSolanaReceiver.wallet,
{ maxRetryTimeMs: this.maxRetryTimeMs },
);
} catch (err: any) {
if (err.code === 8 && err.details?.includes("Rate limit exceeded")) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tbh this "timeout" code path was added as an ducttape fix by ayaz so feel free to rework it into some more principled

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, and we'll actually only hit this if we're ratelimited across all endpoints which is pretty unlikely. i'll improve and simplify this.

this.logger.warn("Rate limit hit, waiting before retry...");
await this.sleep(1100); // Wait slightly more than 1 second
try {
await sendTransactionsJito(
transactions,
this.searcherClients,
this.pythSolanaReceiver.wallet,
{ maxRetryTimeMs: this.maxRetryTimeMs },
);
} catch (retryErr: any) {
this.logger.error("Failed after rate limit retry");
throw retryErr;
}
} else {
this.logger.error(
{ err },
"Failed to send transactions via all JITO endpoints",
);
throw err;
}
}

Expand Down
2 changes: 1 addition & 1 deletion target_chains/solana/sdk/js/solana_utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pythnetwork/solana-utils",
"version": "0.4.4",
"version": "0.4.5",
"description": "Utility functions for Solana",
"homepage": "https://pyth.network",
"main": "lib/index.js",
Expand Down
37 changes: 34 additions & 3 deletions target_chains/solana/sdk/js/solana_utils/src/jito.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,23 @@ export async function sendTransactionsJito(
tx: VersionedTransaction;
signers?: Signer[] | undefined;
}[],
searcherClient: SearcherClient,
searcherClients: SearcherClient | SearcherClient[],
wallet: Wallet,
options: {
maxRetryTimeMs?: number;
} = {},
): Promise<string> {
const clients = Array.isArray(searcherClients)
? searcherClients
: [searcherClients];

if (clients.length === 0) {
throw new Error("No searcher clients provided");
}

const maxRetryTimeMs = options.maxRetryTimeMs || 60000; // Default to 60 seconds
const startTime = Date.now();

const signedTransactions = [];

for (const transaction of transactions) {
Expand All @@ -64,7 +78,24 @@ export async function sendTransactionsJito(
);

const bundle = new Bundle(signedTransactions, 2);
await searcherClient.sendBundle(bundle);

return firstTransactionSignature;
let lastError: Error | null = null;
let clientIndex = 0;

while (Date.now() - startTime < maxRetryTimeMs) {
Copy link
Contributor

@guibescos guibescos Jun 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since the pushing frequency is 5 seconds in the production deployment, the scheduler will try to push a fresher bundle 5 seconds after.
60 seconds retry time seems too much, after 5 seconds the current bundle is stale and the current task should terminate

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point -- we can just use pushing frequency as the max timeout since we should stop retrying once the next interval comes around.

const currentClient = clients[clientIndex];
try {
await currentClient.sendBundle(bundle);
return firstTransactionSignature;
} catch (err: any) {
lastError = err;
clientIndex = (clientIndex + 1) % clients.length;
await new Promise((resolve) => setTimeout(resolve, 500));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need to wait between different endpoints

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah true we don't, will remove

}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(aside) @guibescos do you know how many jito endpoints we can round robin against? the ratelimit retry logic is a little funky here if there are only 2 or 3.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(aside) cc @ali-bahjati

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have never experimented with multiple jito endpoints so I don't have a good take on this!


throw (
lastError ||
new Error("Failed to send transactions via JITO after maximum retry time")
);
}
Loading