Skip to content

Optimise EDR Account initialisation #793

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

Open
nebasuke opened this issue Feb 6, 2025 · 0 comments
Open

Optimise EDR Account initialisation #793

nebasuke opened this issue Feb 6, 2025 · 0 comments

Comments

@nebasuke
Copy link
Member

nebasuke commented Feb 6, 2025

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
}
@nebasuke nebasuke added this to the Hardhat v3 alpha+ milestone Feb 6, 2025
@nebasuke nebasuke added this to EDR Feb 6, 2025
@github-project-automation github-project-automation bot moved this to Inbox in EDR Feb 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Inbox
Development

No branches or pull requests

1 participant