Skip to content

Commit 6e9f43f

Browse files
authored
Merge branch 'main' into release/577.0.0
2 parents c1ab3a7 + a43bf59 commit 6e9f43f

File tree

4 files changed

+43
-1
lines changed

4 files changed

+43
-1
lines changed

packages/multichain-account-service/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- Add a timeout around Solana account creation ([#6704](https://github.com/MetaMask/core/pull/6704))
13+
- This timeout can be configured at the client level through the config passed to the `MultichainAccountService`.
14+
1015
## [1.0.0]
1116

1217
### Changed

packages/multichain-account-service/src/MultichainAccountService.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,9 @@ describe('MultichainAccountService', () => {
207207
maxAttempts: 4,
208208
backOffMs: 2000,
209209
},
210+
createAccounts: {
211+
timeoutMs: 3000,
212+
},
210213
},
211214
};
212215

@@ -236,6 +239,9 @@ describe('MultichainAccountService', () => {
236239
maxAttempts: 4,
237240
backOffMs: 2000,
238241
},
242+
createAccounts: {
243+
timeoutMs: 3000,
244+
},
239245
},
240246
// No `EVM_ACCOUNT_PROVIDER_NAME`, cause it's optional in this test.
241247
};

packages/multichain-account-service/src/providers/SolAccountProvider.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,27 @@ describe('SolAccountProvider', () => {
225225
expect(newAccounts[0]).toStrictEqual(MOCK_SOL_ACCOUNT_1);
226226
});
227227

228+
it('throws if the account creation process takes too long', async () => {
229+
const { provider, mocks } = setup({
230+
accounts: [],
231+
});
232+
233+
mocks.keyring.createAccount.mockImplementation(() => {
234+
return new Promise((resolve) => {
235+
setTimeout(() => {
236+
resolve(MOCK_SOL_ACCOUNT_1);
237+
}, 4000);
238+
});
239+
});
240+
241+
await expect(
242+
provider.createAccounts({
243+
entropySource: MOCK_HD_KEYRING_1.metadata.id,
244+
groupIndex: 0,
245+
}),
246+
).rejects.toThrow('Timed out');
247+
});
248+
228249
// Skip this test for now, since we manually inject those options upon
229250
// account creation, so it cannot fails (until the Solana Snap starts
230251
// using the new typed options).

packages/multichain-account-service/src/providers/SolAccountProvider.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ export type SolAccountProviderConfig = {
2222
timeoutMs: number;
2323
backOffMs: number;
2424
};
25+
createAccounts: {
26+
timeoutMs: number;
27+
};
2528
};
2629

2730
export const SOL_ACCOUNT_PROVIDER_NAME = 'Solana' as const;
@@ -43,6 +46,9 @@ export class SolAccountProvider extends SnapAccountProvider {
4346
maxAttempts: 3,
4447
backOffMs: 1000,
4548
},
49+
createAccounts: {
50+
timeoutMs: 3000,
51+
},
4652
},
4753
) {
4854
super(SolAccountProvider.SOLANA_SNAP_ID, messenger);
@@ -90,7 +96,10 @@ export class SolAccountProvider extends SnapAccountProvider {
9096
derivationPath: string;
9197
}): Promise<Bip44Account<KeyringAccount>> {
9298
const createAccount = await this.getRestrictedSnapAccountCreator();
93-
const account = await createAccount({ entropySource, derivationPath });
99+
const account = await withTimeout(
100+
createAccount({ entropySource, derivationPath }),
101+
this.#config.createAccounts.timeoutMs,
102+
);
94103

95104
// Ensure entropy is present before type assertion validation
96105
account.options.entropy = {
@@ -117,6 +126,7 @@ export class SolAccountProvider extends SnapAccountProvider {
117126
groupIndex,
118127
derivationPath,
119128
});
129+
120130
return [account];
121131
}
122132

0 commit comments

Comments
 (0)