Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions packages/multichain-account-service/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- Limit Bitcoin and Tron providers to 3 concurrent account creations by default when creating multichain account groups ([#7052](https://github.com/MetaMask/core/pull/7052))

## [2.1.0]

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export class BtcAccountProvider extends SnapAccountProvider {
constructor(
messenger: MultichainAccountServiceMessenger,
config: BtcAccountProviderConfig = {
maxConcurrency: 3,
createAccounts: {
timeoutMs: 3000,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const TEST_SNAP_ID = 'npm:@metamask/test-snap' as SnapId;
const TEST_ENTROPY_SOURCE = 'test-entropy-source' as EntropySourceId;

// Helper to create a tracked provider that monitors concurrent execution
const createTrackedProvider = (maxConcurrency: number) => {
const createTrackedProvider = (maxConcurrency?: number) => {
const tracker: {
startLog: number[];
endLog: number[];
Expand Down Expand Up @@ -67,7 +67,7 @@ const createTrackedProvider = (maxConcurrency: number) => {

const messenger = getMultichainAccountServiceMessenger(getRootMessenger());
const config = {
maxConcurrency,
...(maxConcurrency !== undefined && { maxConcurrency }),
createAccounts: {
timeoutMs: 5000,
},
Expand Down Expand Up @@ -197,5 +197,26 @@ describe('SnapAccountProvider', () => {
// With maxConcurrency=1, never more than 1 should run at a time
expect(tracker.maxActiveCount).toBe(1);
});

it('defaults to Infinity when maxConcurrency is not provided', async () => {
const { provider, tracker } = createTrackedProvider();

// Start 4 concurrent calls
const promises = [0, 1, 2, 3].map((index) =>
provider.createAccounts({
entropySource: TEST_ENTROPY_SOURCE,
groupIndex: index,
}),
);

await Promise.all(promises);

// All 4 operations should complete
expect(tracker.startLog).toHaveLength(4);

// Without maxConcurrency specified, should default to Infinity (no throttling)
// So all 4 should have been able to run concurrently
expect(tracker.maxActiveCount).toBe(4);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export class TrxAccountProvider extends SnapAccountProvider {
constructor(
messenger: MultichainAccountServiceMessenger,
config: TrxAccountProviderConfig = {
maxConcurrency: 3,
discovery: {
timeoutMs: 2000,
maxAttempts: 3,
Expand Down
Loading