Skip to content

chore: parallellize keychain and queryPromise #6136

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

Merged
merged 1 commit into from
May 30, 2025
Merged
Changes from all 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: 18 additions & 3 deletions modules/sdk-core/src/bitgo/wallet/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2185,7 +2185,7 @@ export class Wallet implements IWallet {
}

// Doing a sanity check for password here to avoid doing further work if we know it's wrong
const keychains = await this.getKeychainsAndValidatePassphrase({
const keychainPromise = this.getKeychainsAndValidatePassphrase({
reqId: params.reqId,
walletPassphrase: params.walletPassphrase,
customSigningFunction: params.customSigningFunction,
Expand All @@ -2201,9 +2201,24 @@ export class Wallet implements IWallet {
} else {
txPrebuildQuery = params.prebuildTx ? Promise.resolve(params.prebuildTx) : this.prebuildTransaction(params);
}
let keychains: Keychain[] = [];
let txPrebuild: PrebuildTransactionResult;

const results = await Promise.allSettled([keychainPromise, txPrebuildQuery]);

// the prebuild can be overridden by providing an explicit tx
const txPrebuild = (await txPrebuildQuery) as PrebuildTransactionResult;
// Handle keychain promise (index 0)
if (results[0].status === 'fulfilled') {
keychains = results[0].value as Keychain[];
} else {
throw results[0].reason;
}

// Handle txPrebuild promise (index 1)
if (results[1].status === 'fulfilled') {
txPrebuild = results[1].value as PrebuildTransactionResult;
} else {
throw results[1].reason;
Comment on lines +2207 to +2220
Copy link
Preview

Copilot AI May 30, 2025

Choose a reason for hiding this comment

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

[nitpick] Consider destructuring the results array into named variables (e.g., [keychainResult, txPrebuildResult]) for improved readability and to prevent potential confusion with index ordering.

Copilot uses AI. Check for mistakes.

}

try {
await this.baseCoin.verifyTransaction({
Expand Down