-
Notifications
You must be signed in to change notification settings - Fork 56
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
Add indexerTimeoutSecs Config #166
Changes from all commits
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 | ||||
---|---|---|---|---|---|---|
|
@@ -19,7 +19,7 @@ import { | |||||
type TransactionResponse, | ||||||
WaitForTransactionOptions, | ||||||
} from "../types"; | ||||||
import { DEFAULT_TXN_TIMEOUT_SEC } from "../utils/const"; | ||||||
import { DEFAULT_INDEXER_SYNC_TIMEOUT_SEC, DEFAULT_TXN_TIMEOUT_SEC } from "../utils/const"; | ||||||
import { sleep } from "../utils/helpers"; | ||||||
import { memoizeAsync } from "../utils/memoize"; | ||||||
import { getIndexerLastSuccessVersion } from "./general"; | ||||||
|
@@ -105,6 +105,7 @@ export async function waitForTransaction(args: { | |||||
const timeoutSecs = options?.timeoutSecs ?? DEFAULT_TXN_TIMEOUT_SEC; | ||||||
const checkSuccess = options?.checkSuccess ?? true; | ||||||
const indexerVersionCheck = options?.indexerVersionCheck ?? true; | ||||||
const indexerTimeoutSecs = options?.indexerTimeoutSecs ?? DEFAULT_INDEXER_SYNC_TIMEOUT_SEC; | ||||||
|
||||||
let isPending = true; | ||||||
let timeElapsed = 0; | ||||||
|
@@ -175,7 +176,11 @@ export async function waitForTransaction(args: { | |||||
// Make sure indexer is synced with the latest ledger version | ||||||
if (indexerVersionCheck) { | ||||||
try { | ||||||
await waitForLastSuccessIndexerVersionSync({ aptosConfig, ledgerVersion: Number(lastTxn.version) }); | ||||||
await waitForLastSuccessIndexerVersionSync({ | ||||||
aptosConfig, | ||||||
ledgerVersion: Number(lastTxn.version), | ||||||
timeOutSecs: indexerTimeoutSecs, | ||||||
}); | ||||||
} catch (_e) { | ||||||
throw new WaitForTransactionError( | ||||||
// eslint-disable-next-line max-len | ||||||
|
@@ -190,14 +195,15 @@ export async function waitForTransaction(args: { | |||||
} | ||||||
|
||||||
/** | ||||||
* Waits for the indexer to sync up to the ledgerVersion. Timeout is 3 seconds. | ||||||
* Waits for the indexer to sync up to the ledgerVersion. Default timeout is 3 seconds. | ||||||
*/ | ||||||
async function waitForLastSuccessIndexerVersionSync(args: { | ||||||
aptosConfig: AptosConfig; | ||||||
ledgerVersion: number; | ||||||
timeOutSecs: number; | ||||||
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. Timeout is one word
Suggested change
|
||||||
}): Promise<void> { | ||||||
const { aptosConfig, ledgerVersion } = args; | ||||||
const timeoutMilliseconds = 3000; // 3 seconds | ||||||
const { aptosConfig, ledgerVersion, timeOutSecs } = args; | ||||||
const timeoutMilliseconds = timeOutSecs * 1000; | ||||||
const startTime = new Date().getTime(); | ||||||
let indexerVersion = -1; | ||||||
|
||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -996,6 +996,7 @@ export type WaitForTransactionOptions = { | |
timeoutSecs?: number; | ||
checkSuccess?: boolean; | ||
indexerVersionCheck?: boolean; | ||
indexerTimeoutSecs?: number; | ||
Comment on lines
998
to
+999
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 want to take a moment and propose a different name for indexerVersionCheck, to waitForIndexer. Possibly a different structure where:
I'm not sure we necessarily need a separate timeout for the indexer, just increasing the one to a larger number probably makes more sense. 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 agree- let's not rely too much on configuration options, because too many will be overwhelming and difficult for people to find. This is more true when the preferred config/option is going to be very consistent (i.e., 95%+ of developers will expect it by default) |
||
}; | ||
/** | ||
* Account input type to generate an account using Legacy | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,14 @@ export const DEFAULT_TXN_EXP_SEC_FROM_NOW = 20; | |
*/ | ||
export const DEFAULT_TXN_TIMEOUT_SEC = 20; | ||
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. We should just increase these two to 30, instead of 20. |
||
|
||
/** | ||
* The default number of seconds to wait for the indexer to sync. | ||
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. lets mention we use it for waitForTransaction |
||
* | ||
* This is the amount of time that the SDK will wait for the indexer to sync and catch up with the full node. | ||
* Based on the processor_status's last success version. | ||
*/ | ||
export const DEFAULT_INDEXER_SYNC_TIMEOUT_SEC = 3; | ||
|
||
/** | ||
* The default gas currency for the network. | ||
*/ | ||
|
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.
I wonder if we should update this and default to
false
. I feel like, only dev that relies on indexer API will probably want. But if they are only sending request to full node api, they probably want to have this off.Thought? cc: @0xmaayan @gregnazario
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.
hmm most of the sdk queries use indexer, so if a sdk developer uses the sdk to submit transactions and then fetch data, they/sdk should wait for indexer.
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.
Only annoying thing is... if it's by default on and the indexer is delayed / broken, the dapps will completely not work.
It's a strange tradeoff based on what your dapp does.
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, I am thinking about this trade off as well. Because I would hate to sdk to be broken b/c of indexer. Maybe we should just always return, but have error field saying that the indexer failed to sync?
For example:
const result = aptos.waitForTransaction();
and result looks like following:
{
indexerSyncError: "timeout"
...
}
Or we just relies on the developer to wrap
waitForTransaction
in a try-catch