Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit 2ec04fa

Browse files
fix: add an upper limit to # of accounts that can be generated by ganache (#3361)
Co-authored-by: David Murdoch <[email protected]>
1 parent 5d5dad3 commit 2ec04fa

File tree

9 files changed

+25
-9
lines changed

9 files changed

+25
-9
lines changed

src/chains/ethereum/block/tests/index.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ describe("@ganache/ethereum-block", async () => {
3030
chain: { chainId: 1337 },
3131
logging: { logger: { log: (_message: string) => {} } } // ignore logging
3232
});
33-
const wallet = new Wallet(options.wallet);
33+
const wallet = new Wallet(options.wallet, options.logging);
3434
const [from, to] = wallet.addresses;
3535
const fromAddress = new Address(from);
3636
const tx: Transaction = {

src/chains/ethereum/ethereum/src/provider.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,10 @@ export class EthereumProvider
155155
options as EthereumProviderOptions
156156
));
157157

158-
const wallet = (this.#wallet = new Wallet(providerOptions.wallet));
158+
const wallet = (this.#wallet = new Wallet(
159+
providerOptions.wallet,
160+
providerOptions.logging
161+
));
159162
const accounts = wallet.initialAccounts;
160163
const fork =
161164
providerOptions.fork.url ||

src/chains/ethereum/ethereum/src/wallet.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const SCRYPT_PARAMS = {
3232
r: 1
3333
} as const;
3434
const CIPHER = "aes-128-ctr";
35+
const MAX_ACCOUNTS = 100000;
3536
//#endregion
3637

3738
type OmitLastType<T extends [unknown, ...Array<unknown>]> = T extends [
@@ -119,7 +120,15 @@ export default class Wallet {
119120
readonly unlockedAccounts = new Map<string, Data>();
120121
readonly lockTimers = new Map<string, NodeJS.Timeout>();
121122

122-
constructor(opts: EthereumInternalOptions["wallet"]) {
123+
constructor(
124+
opts: EthereumInternalOptions["wallet"],
125+
logging: EthereumInternalOptions["logging"]
126+
) {
127+
if (opts.totalAccounts > MAX_ACCOUNTS) {
128+
logging.logger.log(
129+
`wallet.totalAccounts exceeds MAX_ACCOUNTS (${MAX_ACCOUNTS}) and may affect performance.`
130+
);
131+
}
123132
// create a RNG from our initial starting conditions (opts.mnemonic)
124133
this.#randomRng = alea("ganache " + opts.mnemonic);
125134

@@ -271,6 +280,7 @@ export default class Wallet {
271280
}
272281
} else {
273282
const numberOfAccounts = options.totalAccounts;
283+
274284
if (numberOfAccounts != null) {
275285
for (let i = 0; i < numberOfAccounts; i++) {
276286
const acct = makeAccountAtIndex(i);

src/chains/ethereum/ethereum/tests/api/eth/call.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,7 @@ describe("api", () => {
862862
const options = EthereumOptionsConfig.normalize({
863863
logging: { quiet: true }
864864
});
865-
wallet = new Wallet(options.wallet);
865+
wallet = new Wallet(options.wallet, options.logging);
866866
[from, to] = wallet.addresses;
867867
blockchain = new Blockchain(
868868
options,

src/chains/ethereum/ethereum/tests/api/eth/sendTransaction.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ describe("api", () => {
329329
// https://eips.ethereum.org/EIPS/eip-2
330330

331331
const options = EthereumOptionsConfig.normalize({});
332-
const wallet = new Wallet(options.wallet);
332+
const wallet = new Wallet(options.wallet, options.logging);
333333

334334
function makeKeys(address: string) {
335335
const addressBuf = Data.toBuffer(address);

src/chains/ethereum/ethereum/tests/blockchain.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ describe("blockchain", async () => {
2727
const options = EthereumOptionsConfig.normalize(optionsJson);
2828

2929
// set up wallet/blockchain
30-
const wallet = new Wallet(options.wallet);
30+
const wallet = new Wallet(options.wallet, options.logging);
3131
const initialAccounts = wallet.initialAccounts;
3232
const blockchain = new Blockchain(options, initialAccounts[0].address);
3333
await blockchain.initialize(wallet.initialAccounts);

src/chains/ethereum/ethereum/tests/miner/miner.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ describe("miner", async () => {
4141
chain: { chainId: 1337 }
4242
};
4343
const options = EthereumOptionsConfig.normalize(optionsJson);
44-
const wallet = new Wallet(options.wallet);
44+
const wallet = new Wallet(options.wallet, options.logging);
4545
[from1, from2, from3, to] = wallet.addresses;
4646
const fromAddress = new Address(from1);
4747

src/chains/ethereum/ethereum/tests/transaction-pool.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ describe("transaction pool", async () => {
4242
const options = EthereumOptionsConfig.normalize(optionsJson);
4343
let futureNonceRpc, executableRpc: Transaction;
4444
before(function () {
45-
const wallet = new Wallet(options.wallet);
45+
const wallet = new Wallet(options.wallet, options.logging);
4646
[from] = wallet.addresses;
4747
secretKey = wallet.unlockedAccounts.get(from);
4848
rpcTx = {

src/chains/ethereum/transaction/tests/index.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,12 @@ describe("@ganache/ethereum-transaction", async () => {
4141
{ secretKey: `0x${"46".repeat(31)}47`, balance: 100n },
4242
{ secretKey: `0x${"46".repeat(31)}48`, balance: 100n }
4343
]
44+
},
45+
logging: {
46+
logger: console
4447
}
4548
});
46-
const wallet = new Wallet(options.wallet);
49+
const wallet = new Wallet(options.wallet, options.logging);
4750
const [from, to, accessListAcc] = wallet.addresses;
4851

4952
// #endregion configure accounts and private keys in wallet

0 commit comments

Comments
 (0)