edr
edr copied to clipboard
Optimise EDR Account initialisation
Per Pato's comments: There's a ~200-300ms optimization opportunity in the initialization of EDR with custom config values. Note that the default values use pre-derived keys instead of deriving them just in time, and do not incur this time penalty.
Currently EDR accepts an array of OwnedAccounts, which have this shape:
export interface OwnedAccount {
/** Account secret key */
secretKey: string
/** Account balance */
balance: bigint
}
If it also accepted something like
// See BIP32: https://github.com/bitcoin/bips/blob/5333e5e9514aa9f92810cfbde830da79c44051bf/bip-0032.mediawiki#L15
export interface HierarchicalDeterministicAccountsConfig {
mnemonic: string;
accountsBalance: bigint;
count: bigint;
initialIndex: bigint;
passphrase: string;
path: string;
}
we could move a CPU-intensive operation from Hardhat into EDR, and probably run those derivations in parallel. On my system (a devcontainer on an Apple M2 Max) those derivations take 350ms (in JS). (edited)
Tested with the following params
{
initialIndex: 0,
count: 20,
path: "m/44'/60'/0'/0",
passphrase: '',
mnemonic: 'test test test test test test test test test test test junk',
accountsBalance: 10000000000000000000000n
}