-
Notifications
You must be signed in to change notification settings - Fork 286
feat: support multiple JITO endpoints with round-robin retry #2664
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
c117aa3
e6d98c2
216ac29
7939a9d
d4bf8e9
02bfef5
a4907a3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) { | ||
|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do we need to wait between different endpoints There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah true we don't, will remove |
||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (aside) cc @ali-bahjati There was a problem hiding this comment. Choose a reason for hiding this commentThe 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") | ||
); | ||
} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.