hardhat 2.10.1 → 2.11.0-dev.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/builtin-tasks/compile.js +6 -8
- package/builtin-tasks/compile.js.map +1 -1
- package/builtin-tasks/node.js +9 -12
- package/builtin-tasks/node.js.map +1 -1
- package/builtin-tasks/test.js +2 -3
- package/builtin-tasks/test.js.map +1 -1
- package/console.sol +444 -444
- package/internal/artifacts.js +1 -1
- package/internal/artifacts.js.map +1 -1
- package/internal/cli/ArgumentsParser.js +5 -2
- package/internal/cli/ArgumentsParser.js.map +1 -1
- package/internal/cli/analytics.js +2 -2
- package/internal/cli/analytics.js.map +1 -1
- package/internal/cli/autocomplete.js +20 -32
- package/internal/cli/autocomplete.js.map +1 -1
- package/internal/cli/cli.js +1 -1
- package/internal/cli/cli.js.map +1 -1
- package/internal/cli/project-creation.js +14 -4
- package/internal/cli/project-creation.js.map +1 -1
- package/internal/constants.d.ts.map +1 -1
- package/internal/constants.js +2 -0
- package/internal/constants.js.map +1 -1
- package/internal/core/config/config-loading.js +2 -3
- package/internal/core/config/config-loading.js.map +1 -1
- package/internal/core/config/config-resolution.d.ts.map +1 -1
- package/internal/core/config/config-resolution.js +84 -35
- package/internal/core/config/config-resolution.js.map +1 -1
- package/internal/core/config/config-validation.js +38 -20
- package/internal/core/config/config-validation.js.map +1 -1
- package/internal/core/config/default-config.d.ts.map +1 -1
- package/internal/core/config/default-config.js +17 -4
- package/internal/core/config/default-config.js.map +1 -1
- package/internal/core/errors.js +4 -2
- package/internal/core/errors.js.map +1 -1
- package/internal/core/execution-mode.js +2 -2
- package/internal/core/execution-mode.js.map +1 -1
- package/internal/core/flamegraph.d.ts +10 -0
- package/internal/core/flamegraph.d.ts.map +1 -0
- package/internal/core/flamegraph.js +245 -0
- package/internal/core/flamegraph.js.map +1 -0
- package/internal/core/jsonrpc/types/base-types.d.ts +7 -8
- package/internal/core/jsonrpc/types/base-types.d.ts.map +1 -1
- package/internal/core/jsonrpc/types/base-types.js +24 -24
- package/internal/core/jsonrpc/types/base-types.js.map +1 -1
- package/internal/core/jsonrpc/types/input/blockTag.d.ts +15 -10
- package/internal/core/jsonrpc/types/input/blockTag.d.ts.map +1 -1
- package/internal/core/jsonrpc/types/input/blockTag.js +2 -0
- package/internal/core/jsonrpc/types/input/blockTag.js.map +1 -1
- package/internal/core/jsonrpc/types/input/callRequest.d.ts +5 -6
- package/internal/core/jsonrpc/types/input/callRequest.d.ts.map +1 -1
- package/internal/core/jsonrpc/types/input/callRequest.js.map +1 -1
- package/internal/core/jsonrpc/types/input/filterRequest.d.ts +6 -7
- package/internal/core/jsonrpc/types/input/filterRequest.d.ts.map +1 -1
- package/internal/core/jsonrpc/types/input/filterRequest.js.map +1 -1
- package/internal/core/jsonrpc/types/input/transactionRequest.d.ts +7 -8
- package/internal/core/jsonrpc/types/input/transactionRequest.d.ts.map +1 -1
- package/internal/core/jsonrpc/types/input/transactionRequest.js.map +1 -1
- package/internal/core/jsonrpc/types/output/block.d.ts +29 -30
- package/internal/core/jsonrpc/types/output/block.d.ts.map +1 -1
- package/internal/core/jsonrpc/types/output/block.js +8 -2
- package/internal/core/jsonrpc/types/output/block.js.map +1 -1
- package/internal/core/jsonrpc/types/output/log.d.ts +3 -4
- package/internal/core/jsonrpc/types/output/log.d.ts.map +1 -1
- package/internal/core/jsonrpc/types/output/log.js.map +1 -1
- package/internal/core/jsonrpc/types/output/receipt.d.ts +10 -11
- package/internal/core/jsonrpc/types/output/receipt.d.ts.map +1 -1
- package/internal/core/jsonrpc/types/output/receipt.js.map +1 -1
- package/internal/core/jsonrpc/types/output/transaction.d.ts +13 -14
- package/internal/core/jsonrpc/types/output/transaction.d.ts.map +1 -1
- package/internal/core/jsonrpc/types/output/transaction.js.map +1 -1
- package/internal/core/providers/accounts.d.ts.map +1 -1
- package/internal/core/providers/accounts.js +30 -24
- package/internal/core/providers/accounts.js.map +1 -1
- package/internal/core/providers/chainId.js +1 -1
- package/internal/core/providers/chainId.js.map +1 -1
- package/internal/core/providers/construction.d.ts.map +1 -1
- package/internal/core/providers/construction.js +5 -5
- package/internal/core/providers/construction.js.map +1 -1
- package/internal/core/providers/gas-providers.d.ts +4 -4
- package/internal/core/providers/gas-providers.d.ts.map +1 -1
- package/internal/core/providers/gas-providers.js +16 -15
- package/internal/core/providers/gas-providers.js.map +1 -1
- package/internal/core/providers/http.js +7 -2
- package/internal/core/providers/http.js.map +1 -1
- package/internal/core/providers/util.js +5 -8
- package/internal/core/providers/util.js.map +1 -1
- package/internal/core/runtime-environment.js +1 -1
- package/internal/core/runtime-environment.js.map +1 -1
- package/internal/core/task-profiling.d.ts +18 -0
- package/internal/core/task-profiling.d.ts.map +1 -0
- package/internal/core/task-profiling.js +50 -0
- package/internal/core/task-profiling.js.map +1 -0
- package/internal/core/typescript-support.js +3 -3
- package/internal/core/typescript-support.js.map +1 -1
- package/internal/hardhat-network/jsonrpc/client.d.ts +39 -39
- package/internal/hardhat-network/jsonrpc/client.d.ts.map +1 -1
- package/internal/hardhat-network/jsonrpc/client.js +14 -14
- package/internal/hardhat-network/jsonrpc/client.js.map +1 -1
- package/internal/hardhat-network/provider/BlockchainBase.d.ts +13 -10
- package/internal/hardhat-network/provider/BlockchainBase.d.ts.map +1 -1
- package/internal/hardhat-network/provider/BlockchainBase.js +38 -16
- package/internal/hardhat-network/provider/BlockchainBase.js.map +1 -1
- package/internal/hardhat-network/provider/BlockchainData.d.ts +15 -16
- package/internal/hardhat-network/provider/BlockchainData.d.ts.map +1 -1
- package/internal/hardhat-network/provider/BlockchainData.js +33 -29
- package/internal/hardhat-network/provider/BlockchainData.js.map +1 -1
- package/internal/hardhat-network/provider/HardhatBlockchain.d.ts +7 -8
- package/internal/hardhat-network/provider/HardhatBlockchain.d.ts.map +1 -1
- package/internal/hardhat-network/provider/HardhatBlockchain.js +13 -14
- package/internal/hardhat-network/provider/HardhatBlockchain.js.map +1 -1
- package/internal/hardhat-network/provider/PoolState.d.ts +1 -1
- package/internal/hardhat-network/provider/PoolState.d.ts.map +1 -1
- package/internal/hardhat-network/provider/PoolState.js +2 -3
- package/internal/hardhat-network/provider/PoolState.js.map +1 -1
- package/internal/hardhat-network/provider/TransactionQueue.d.ts +2 -3
- package/internal/hardhat-network/provider/TransactionQueue.d.ts.map +1 -1
- package/internal/hardhat-network/provider/TransactionQueue.js +3 -3
- package/internal/hardhat-network/provider/TransactionQueue.js.map +1 -1
- package/internal/hardhat-network/provider/TxPool.d.ts +8 -8
- package/internal/hardhat-network/provider/TxPool.d.ts.map +1 -1
- package/internal/hardhat-network/provider/TxPool.js +66 -68
- package/internal/hardhat-network/provider/TxPool.js.map +1 -1
- package/internal/hardhat-network/provider/ethereumjs-workarounds.js +2 -2
- package/internal/hardhat-network/provider/ethereumjs-workarounds.js.map +1 -1
- package/internal/hardhat-network/provider/filter.d.ts +5 -6
- package/internal/hardhat-network/provider/filter.d.ts.map +1 -1
- package/internal/hardhat-network/provider/filter.js +7 -8
- package/internal/hardhat-network/provider/filter.js.map +1 -1
- package/internal/hardhat-network/provider/fork/ForkBlockchain.d.ts +10 -11
- package/internal/hardhat-network/provider/fork/ForkBlockchain.d.ts.map +1 -1
- package/internal/hardhat-network/provider/fork/ForkBlockchain.js +51 -47
- package/internal/hardhat-network/provider/fork/ForkBlockchain.js.map +1 -1
- package/internal/hardhat-network/provider/fork/ForkStateManager.d.ts +8 -10
- package/internal/hardhat-network/provider/fork/ForkStateManager.d.ts.map +1 -1
- package/internal/hardhat-network/provider/fork/ForkStateManager.js +51 -69
- package/internal/hardhat-network/provider/fork/ForkStateManager.js.map +1 -1
- package/internal/hardhat-network/provider/fork/rpcToBlockData.d.ts +1 -1
- package/internal/hardhat-network/provider/fork/rpcToBlockData.d.ts.map +1 -1
- package/internal/hardhat-network/provider/fork/rpcToBlockData.js +2 -3
- package/internal/hardhat-network/provider/fork/rpcToBlockData.js.map +1 -1
- package/internal/hardhat-network/provider/fork/rpcToTxData.d.ts +2 -2
- package/internal/hardhat-network/provider/fork/rpcToTxData.d.ts.map +1 -1
- package/internal/hardhat-network/provider/fork/rpcToTxData.js +7 -11
- package/internal/hardhat-network/provider/fork/rpcToTxData.js.map +1 -1
- package/internal/hardhat-network/provider/modules/eth.d.ts +2 -1
- package/internal/hardhat-network/provider/modules/eth.d.ts.map +1 -1
- package/internal/hardhat-network/provider/modules/eth.js +92 -68
- package/internal/hardhat-network/provider/modules/eth.js.map +1 -1
- package/internal/hardhat-network/provider/modules/evm.d.ts.map +1 -1
- package/internal/hardhat-network/provider/modules/evm.js +14 -14
- package/internal/hardhat-network/provider/modules/evm.js.map +1 -1
- package/internal/hardhat-network/provider/modules/hardhat.d.ts.map +1 -1
- package/internal/hardhat-network/provider/modules/hardhat.js +13 -13
- package/internal/hardhat-network/provider/modules/hardhat.js.map +1 -1
- package/internal/hardhat-network/provider/modules/logger.d.ts +7 -8
- package/internal/hardhat-network/provider/modules/logger.d.ts.map +1 -1
- package/internal/hardhat-network/provider/modules/logger.js +29 -32
- package/internal/hardhat-network/provider/modules/logger.js.map +1 -1
- package/internal/hardhat-network/provider/modules/net.d.ts +1 -1
- package/internal/hardhat-network/provider/modules/net.d.ts.map +1 -1
- package/internal/hardhat-network/provider/modules/personal.d.ts.map +1 -1
- package/internal/hardhat-network/provider/modules/personal.js +3 -3
- package/internal/hardhat-network/provider/modules/personal.js.map +1 -1
- package/internal/hardhat-network/provider/modules/web3.d.ts.map +1 -1
- package/internal/hardhat-network/provider/modules/web3.js +5 -4
- package/internal/hardhat-network/provider/modules/web3.js.map +1 -1
- package/internal/hardhat-network/provider/node-types.d.ts +30 -29
- package/internal/hardhat-network/provider/node-types.d.ts.map +1 -1
- package/internal/hardhat-network/provider/node.d.ts +47 -42
- package/internal/hardhat-network/provider/node.d.ts.map +1 -1
- package/internal/hardhat-network/provider/node.js +262 -208
- package/internal/hardhat-network/provider/node.js.map +1 -1
- package/internal/hardhat-network/provider/output.d.ts +5 -6
- package/internal/hardhat-network/provider/output.d.ts.map +1 -1
- package/internal/hardhat-network/provider/output.js +39 -36
- package/internal/hardhat-network/provider/output.js.map +1 -1
- package/internal/hardhat-network/provider/provider.d.ts +1 -2
- package/internal/hardhat-network/provider/provider.d.ts.map +1 -1
- package/internal/hardhat-network/provider/provider.js.map +1 -1
- package/internal/hardhat-network/provider/return-data.d.ts +2 -2
- package/internal/hardhat-network/provider/return-data.d.ts.map +1 -1
- package/internal/hardhat-network/provider/return-data.js +4 -1
- package/internal/hardhat-network/provider/return-data.js.map +1 -1
- package/internal/hardhat-network/provider/transactions/FakeSenderAccessListEIP2930Transaction.d.ts +5 -5
- package/internal/hardhat-network/provider/transactions/FakeSenderAccessListEIP2930Transaction.d.ts.map +1 -1
- package/internal/hardhat-network/provider/transactions/FakeSenderAccessListEIP2930Transaction.js +60 -17
- package/internal/hardhat-network/provider/transactions/FakeSenderAccessListEIP2930Transaction.js.map +1 -1
- package/internal/hardhat-network/provider/transactions/FakeSenderEIP1559Transaction.d.ts +4 -4
- package/internal/hardhat-network/provider/transactions/FakeSenderEIP1559Transaction.d.ts.map +1 -1
- package/internal/hardhat-network/provider/transactions/FakeSenderEIP1559Transaction.js +59 -16
- package/internal/hardhat-network/provider/transactions/FakeSenderEIP1559Transaction.js.map +1 -1
- package/internal/hardhat-network/provider/transactions/FakeSenderTransaction.d.ts +3 -3
- package/internal/hardhat-network/provider/transactions/FakeSenderTransaction.d.ts.map +1 -1
- package/internal/hardhat-network/provider/transactions/FakeSenderTransaction.js +41 -9
- package/internal/hardhat-network/provider/transactions/FakeSenderTransaction.js.map +1 -1
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP1559Transaction.d.ts +4 -4
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP1559Transaction.d.ts.map +1 -1
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP1559Transaction.js +7 -23
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP1559Transaction.js.map +1 -1
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP2930Transaction.d.ts +3 -3
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP2930Transaction.d.ts.map +1 -1
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP2930Transaction.js +7 -22
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP2930Transaction.js.map +1 -1
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidTransaction.d.ts +3 -3
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidTransaction.d.ts.map +1 -1
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidTransaction.js +1 -1
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidTransaction.js.map +1 -1
- package/internal/hardhat-network/provider/types/HardhatBlockchainInterface.d.ts +5 -6
- package/internal/hardhat-network/provider/types/HardhatBlockchainInterface.d.ts.map +1 -1
- package/internal/hardhat-network/provider/utils/fork-recomendations-banner.js +2 -3
- package/internal/hardhat-network/provider/utils/fork-recomendations-banner.js.map +1 -1
- package/internal/hardhat-network/provider/utils/getCurrentTimestamp.d.ts +1 -0
- package/internal/hardhat-network/provider/utils/getCurrentTimestamp.d.ts.map +1 -1
- package/internal/hardhat-network/provider/utils/getCurrentTimestamp.js +5 -1
- package/internal/hardhat-network/provider/utils/getCurrentTimestamp.js.map +1 -1
- package/internal/hardhat-network/provider/utils/makeAccount.d.ts +1 -1
- package/internal/hardhat-network/provider/utils/makeAccount.d.ts.map +1 -1
- package/internal/hardhat-network/provider/utils/makeAccount.js +6 -6
- package/internal/hardhat-network/provider/utils/makeAccount.js.map +1 -1
- package/internal/hardhat-network/provider/utils/makeCommon.d.ts +2 -2
- package/internal/hardhat-network/provider/utils/makeCommon.d.ts.map +1 -1
- package/internal/hardhat-network/provider/utils/makeCommon.js +7 -23
- package/internal/hardhat-network/provider/utils/makeCommon.js.map +1 -1
- package/internal/hardhat-network/provider/utils/makeForkClient.d.ts +1 -2
- package/internal/hardhat-network/provider/utils/makeForkClient.d.ts.map +1 -1
- package/internal/hardhat-network/provider/utils/makeForkClient.js +7 -8
- package/internal/hardhat-network/provider/utils/makeForkClient.js.map +1 -1
- package/internal/hardhat-network/provider/utils/makeStateTrie.d.ts +1 -1
- package/internal/hardhat-network/provider/utils/makeStateTrie.d.ts.map +1 -1
- package/internal/hardhat-network/provider/utils/makeStateTrie.js +4 -4
- package/internal/hardhat-network/provider/utils/makeStateTrie.js.map +1 -1
- package/internal/hardhat-network/provider/utils/putGenesisBlock.d.ts +6 -3
- package/internal/hardhat-network/provider/utils/putGenesisBlock.d.ts.map +1 -1
- package/internal/hardhat-network/provider/utils/putGenesisBlock.js +22 -4
- package/internal/hardhat-network/provider/utils/putGenesisBlock.js.map +1 -1
- package/internal/hardhat-network/provider/utils/random.d.ts +15 -0
- package/internal/hardhat-network/provider/utils/random.d.ts.map +1 -0
- package/internal/hardhat-network/provider/utils/random.js +48 -0
- package/internal/hardhat-network/provider/utils/random.js.map +1 -0
- package/internal/hardhat-network/provider/utils/reorganizeTransactionsLists.d.ts +1 -2
- package/internal/hardhat-network/provider/utils/reorganizeTransactionsLists.d.ts.map +1 -1
- package/internal/hardhat-network/provider/utils/reorganizeTransactionsLists.js +5 -4
- package/internal/hardhat-network/provider/utils/reorganizeTransactionsLists.js.map +1 -1
- package/internal/hardhat-network/provider/utils/reorgs-protection.d.ts +2 -2
- package/internal/hardhat-network/provider/utils/reorgs-protection.d.ts.map +1 -1
- package/internal/hardhat-network/provider/utils/reorgs-protection.js +7 -7
- package/internal/hardhat-network/provider/utils/reorgs-protection.js.map +1 -1
- package/internal/hardhat-network/provider/utils/txMapToArray.d.ts +1 -1
- package/internal/hardhat-network/provider/utils/txMapToArray.d.ts.map +1 -1
- package/internal/hardhat-network/stack-traces/compiler-to-model.js +6 -8
- package/internal/hardhat-network/stack-traces/compiler-to-model.js.map +1 -1
- package/internal/hardhat-network/stack-traces/consoleLogger.d.ts.map +1 -1
- package/internal/hardhat-network/stack-traces/consoleLogger.js +51 -47
- package/internal/hardhat-network/stack-traces/consoleLogger.js.map +1 -1
- package/internal/hardhat-network/stack-traces/constants.d.ts +3 -0
- package/internal/hardhat-network/stack-traces/constants.d.ts.map +1 -0
- package/internal/hardhat-network/stack-traces/constants.js +6 -0
- package/internal/hardhat-network/stack-traces/constants.js.map +1 -0
- package/internal/hardhat-network/stack-traces/contracts-identifier.js +2 -2
- package/internal/hardhat-network/stack-traces/contracts-identifier.js.map +1 -1
- package/internal/hardhat-network/stack-traces/debug.js +29 -19
- package/internal/hardhat-network/stack-traces/debug.js.map +1 -1
- package/internal/hardhat-network/stack-traces/error-inferrer.d.ts.map +1 -1
- package/internal/hardhat-network/stack-traces/error-inferrer.js +48 -26
- package/internal/hardhat-network/stack-traces/error-inferrer.js.map +1 -1
- package/internal/hardhat-network/stack-traces/logger.d.ts +223 -2
- package/internal/hardhat-network/stack-traces/logger.d.ts.map +1 -1
- package/internal/hardhat-network/stack-traces/logger.js +445 -224
- package/internal/hardhat-network/stack-traces/logger.js.map +1 -1
- package/internal/hardhat-network/stack-traces/message-trace.d.ts +6 -7
- package/internal/hardhat-network/stack-traces/message-trace.d.ts.map +1 -1
- package/internal/hardhat-network/stack-traces/message-trace.js.map +1 -1
- package/internal/hardhat-network/stack-traces/model.js +6 -6
- package/internal/hardhat-network/stack-traces/model.js.map +1 -1
- package/internal/hardhat-network/stack-traces/panic-errors.d.ts +1 -2
- package/internal/hardhat-network/stack-traces/panic-errors.d.ts.map +1 -1
- package/internal/hardhat-network/stack-traces/panic-errors.js +1 -1
- package/internal/hardhat-network/stack-traces/panic-errors.js.map +1 -1
- package/internal/hardhat-network/stack-traces/solidity-errors.d.ts.map +1 -1
- package/internal/hardhat-network/stack-traces/solidity-errors.js +21 -12
- package/internal/hardhat-network/stack-traces/solidity-errors.js.map +1 -1
- package/internal/hardhat-network/stack-traces/solidity-stack-trace.d.ts +6 -5
- package/internal/hardhat-network/stack-traces/solidity-stack-trace.d.ts.map +1 -1
- package/internal/hardhat-network/stack-traces/solidity-stack-trace.js.map +1 -1
- package/internal/hardhat-network/stack-traces/solidityTracer.d.ts +1 -1
- package/internal/hardhat-network/stack-traces/solidityTracer.d.ts.map +1 -1
- package/internal/hardhat-network/stack-traces/solidityTracer.js +5 -1
- package/internal/hardhat-network/stack-traces/solidityTracer.js.map +1 -1
- package/internal/hardhat-network/stack-traces/vm-debug-tracer.d.ts +2 -1
- package/internal/hardhat-network/stack-traces/vm-debug-tracer.d.ts.map +1 -1
- package/internal/hardhat-network/stack-traces/vm-debug-tracer.js +79 -78
- package/internal/hardhat-network/stack-traces/vm-debug-tracer.js.map +1 -1
- package/internal/hardhat-network/stack-traces/vm-trace-decoder.js +5 -1
- package/internal/hardhat-network/stack-traces/vm-trace-decoder.js.map +1 -1
- package/internal/hardhat-network/stack-traces/vm-tracer.d.ts +3 -2
- package/internal/hardhat-network/stack-traces/vm-tracer.d.ts.map +1 -1
- package/internal/hardhat-network/stack-traces/vm-tracer.js +15 -16
- package/internal/hardhat-network/stack-traces/vm-tracer.js.map +1 -1
- package/internal/reset.js +1 -1
- package/internal/reset.js.map +1 -1
- package/internal/sentry/anonymizer.js +2 -3
- package/internal/sentry/anonymizer.js.map +1 -1
- package/internal/sentry/subprocess.js +1 -1
- package/internal/sentry/subprocess.js.map +1 -1
- package/internal/sentry/transport.js +3 -4
- package/internal/sentry/transport.js.map +1 -1
- package/internal/solidity/compilation-job.js +2 -4
- package/internal/solidity/compilation-job.js.map +1 -1
- package/internal/solidity/compiler/downloader.d.ts.map +1 -1
- package/internal/solidity/compiler/downloader.js +6 -6
- package/internal/solidity/compiler/downloader.js.map +1 -1
- package/internal/solidity/dependencyGraph.js +3 -5
- package/internal/solidity/dependencyGraph.js.map +1 -1
- package/internal/solidity/parse.js +1 -1
- package/internal/solidity/parse.js.map +1 -1
- package/internal/solidity/resolver.js +4 -1
- package/internal/solidity/resolver.js.map +1 -1
- package/internal/util/abi-helpers.js +1 -1
- package/internal/util/abi-helpers.js.map +1 -1
- package/internal/util/bigint.d.ts +25 -0
- package/internal/util/bigint.d.ts.map +1 -0
- package/internal/util/bigint.js +67 -0
- package/internal/util/bigint.js.map +1 -0
- package/internal/util/download.js +1 -1
- package/internal/util/download.js.map +1 -1
- package/internal/util/fs-utils.d.ts +32 -0
- package/internal/util/fs-utils.d.ts.map +1 -0
- package/internal/util/fs-utils.js +151 -0
- package/internal/util/fs-utils.js.map +1 -0
- package/internal/util/hardforks.d.ts +3 -3
- package/internal/util/hardforks.d.ts.map +1 -1
- package/internal/util/hardforks.js +5 -28
- package/internal/util/hardforks.js.map +1 -1
- package/internal/util/jsonrpc.js +1 -1
- package/internal/util/jsonrpc.js.map +1 -1
- package/internal/util/lazy.js +2 -2
- package/internal/util/lazy.js.map +1 -1
- package/internal/util/packageInfo.js +1 -1
- package/internal/util/packageInfo.js.map +1 -1
- package/internal/util/scripts-runner.js +5 -2
- package/internal/util/scripts-runner.js.map +1 -1
- package/internal/util/wei-values.d.ts +1 -2
- package/internal/util/wei-values.d.ts.map +1 -1
- package/internal/util/wei-values.js +9 -10
- package/internal/util/wei-values.js.map +1 -1
- package/internal/vendor/await-semaphore/index.d.ts +12 -0
- package/internal/vendor/await-semaphore/index.d.ts.map +1 -0
- package/internal/vendor/await-semaphore/index.js +64 -0
- package/internal/vendor/await-semaphore/index.js.map +1 -0
- package/package.json +13 -9
- package/profiling.d.ts +18 -0
- package/profiling.d.ts.map +1 -0
- package/profiling.js +32 -0
- package/profiling.js.map +1 -0
- package/sample-projects/javascript/scripts/deploy.js +3 -1
- package/sample-projects/javascript/test/Lock.js +1 -1
- package/sample-projects/typescript/scripts/deploy.ts +1 -1
- package/sample-projects/typescript/test/Lock.ts +1 -1
- package/src/builtin-tasks/node.ts +4 -6
- package/src/internal/constants.ts +3 -1
- package/src/internal/core/config/config-resolution.ts +30 -7
- package/src/internal/core/config/default-config.ts +12 -4
- package/src/internal/core/jsonrpc/types/base-types.ts +23 -24
- package/src/internal/core/jsonrpc/types/input/blockTag.ts +2 -4
- package/src/internal/core/jsonrpc/types/input/callRequest.ts +0 -4
- package/src/internal/core/jsonrpc/types/input/filterRequest.ts +0 -4
- package/src/internal/core/jsonrpc/types/input/transactionRequest.ts +0 -4
- package/src/internal/core/jsonrpc/types/output/block.ts +0 -4
- package/src/internal/core/jsonrpc/types/output/log.ts +0 -4
- package/src/internal/core/jsonrpc/types/output/receipt.ts +0 -4
- package/src/internal/core/jsonrpc/types/output/transaction.ts +0 -4
- package/src/internal/core/providers/accounts.ts +16 -26
- package/src/internal/core/providers/construction.ts +5 -3
- package/src/internal/core/providers/gas-providers.ts +25 -33
- package/src/internal/core/providers/util.ts +1 -1
- package/src/internal/hardhat-network/jsonrpc/client.ts +22 -22
- package/src/internal/hardhat-network/provider/BlockchainBase.ts +62 -25
- package/src/internal/hardhat-network/provider/BlockchainData.ts +39 -42
- package/src/internal/hardhat-network/provider/HardhatBlockchain.ts +21 -21
- package/src/internal/hardhat-network/provider/PoolState.ts +3 -4
- package/src/internal/hardhat-network/provider/TransactionQueue.ts +11 -8
- package/src/internal/hardhat-network/provider/TxPool.ts +62 -64
- package/src/internal/hardhat-network/provider/ethereumjs-workarounds.ts +3 -3
- package/src/internal/hardhat-network/provider/filter.ts +9 -12
- package/src/internal/hardhat-network/provider/fork/ForkBlockchain.ts +52 -50
- package/src/internal/hardhat-network/provider/fork/ForkStateManager.ts +35 -60
- package/src/internal/hardhat-network/provider/fork/rpcToBlockData.ts +2 -2
- package/src/internal/hardhat-network/provider/fork/rpcToTxData.ts +3 -3
- package/src/internal/hardhat-network/provider/modules/eth.ts +88 -63
- package/src/internal/hardhat-network/provider/modules/evm.ts +19 -22
- package/src/internal/hardhat-network/provider/modules/hardhat.ts +21 -19
- package/src/internal/hardhat-network/provider/modules/logger.ts +33 -40
- package/src/internal/hardhat-network/provider/modules/net.ts +1 -1
- package/src/internal/hardhat-network/provider/modules/personal.ts +2 -1
- package/src/internal/hardhat-network/provider/modules/web3.ts +5 -4
- package/src/internal/hardhat-network/provider/node-types.ts +32 -31
- package/src/internal/hardhat-network/provider/node.ts +379 -343
- package/src/internal/hardhat-network/provider/output.ts +32 -37
- package/src/internal/hardhat-network/provider/provider.ts +5 -6
- package/src/internal/hardhat-network/provider/return-data.ts +6 -3
- package/src/internal/hardhat-network/provider/transactions/FakeSenderAccessListEIP2930Transaction.ts +51 -24
- package/src/internal/hardhat-network/provider/transactions/FakeSenderEIP1559Transaction.ts +50 -23
- package/src/internal/hardhat-network/provider/transactions/FakeSenderTransaction.ts +29 -11
- package/src/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP1559Transaction.ts +12 -24
- package/src/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP2930Transaction.ts +11 -22
- package/src/internal/hardhat-network/provider/transactions/ReadOnlyValidTransaction.ts +3 -3
- package/src/internal/hardhat-network/provider/types/HardhatBlockchainInterface.ts +8 -9
- package/src/internal/hardhat-network/provider/utils/getCurrentTimestamp.ts +4 -0
- package/src/internal/hardhat-network/provider/utils/makeAccount.ts +4 -10
- package/src/internal/hardhat-network/provider/utils/makeCommon.ts +8 -34
- package/src/internal/hardhat-network/provider/utils/makeForkClient.ts +8 -9
- package/src/internal/hardhat-network/provider/utils/makeStateTrie.ts +3 -3
- package/src/internal/hardhat-network/provider/utils/putGenesisBlock.ts +34 -6
- package/src/internal/hardhat-network/provider/utils/random.ts +54 -0
- package/src/internal/hardhat-network/provider/utils/reorganizeTransactionsLists.ts +6 -7
- package/src/internal/hardhat-network/provider/utils/reorgs-protection.ts +8 -8
- package/src/internal/hardhat-network/stack-traces/consoleLogger.ts +16 -6
- package/src/internal/hardhat-network/stack-traces/contracts-identifier.ts +1 -1
- package/src/internal/hardhat-network/stack-traces/debug.ts +1 -1
- package/src/internal/hardhat-network/stack-traces/error-inferrer.ts +11 -7
- package/src/internal/hardhat-network/stack-traces/logger.ts +444 -223
- package/src/internal/hardhat-network/stack-traces/message-trace.ts +6 -7
- package/src/internal/hardhat-network/stack-traces/model.ts +1 -1
- package/src/internal/hardhat-network/stack-traces/panic-errors.ts +3 -5
- package/src/internal/hardhat-network/stack-traces/solidity-errors.ts +16 -1
- package/src/internal/hardhat-network/stack-traces/solidity-stack-trace.ts +6 -6
- package/src/internal/hardhat-network/stack-traces/solidityTracer.ts +6 -1
- package/src/internal/hardhat-network/stack-traces/vm-debug-tracer.ts +106 -103
- package/src/internal/hardhat-network/stack-traces/vm-tracer.ts +23 -18
- package/src/internal/solidity/compiler/downloader.ts +5 -2
- package/src/internal/util/bigint.ts +84 -0
- package/src/internal/util/hardforks.ts +4 -29
- package/src/internal/util/wei-values.ts +11 -13
- package/src/types/config.ts +8 -10
- package/types/config.d.ts +8 -9
- package/types/config.d.ts.map +1 -1
- package/src/internal/hardhat-network/provider/fork/random.ts +0 -33
- package/src/internal/hardhat-network/provider/utils/bnToHex.ts +0 -5
- package/src/internal/hardhat-network/provider/utils/makeForkCommon.ts +0 -15
|
@@ -4,18 +4,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.HardhatNode = void 0;
|
|
7
|
-
const block_1 = require("@
|
|
8
|
-
const common_1 =
|
|
9
|
-
const tx_1 = require("@
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
7
|
+
const block_1 = require("@ignored/block");
|
|
8
|
+
const common_1 = require("@ignored/common");
|
|
9
|
+
const tx_1 = require("@ignored/tx");
|
|
10
|
+
const util_1 = require("@ignored/util");
|
|
11
|
+
const vm_1 = require("@ignored/vm");
|
|
12
|
+
const evm_1 = require("@ignored/evm");
|
|
13
|
+
const exceptions_1 = require("@ignored/evm/dist/exceptions");
|
|
14
|
+
const statemanager_1 = require("@ignored/statemanager");
|
|
14
15
|
const eth_sig_util_1 = require("@metamask/eth-sig-util");
|
|
15
16
|
const chalk_1 = __importDefault(require("chalk"));
|
|
16
17
|
const debug_1 = __importDefault(require("debug"));
|
|
17
|
-
const ethereumjs_util_1 = require("ethereumjs-util");
|
|
18
18
|
const events_1 = __importDefault(require("events"));
|
|
19
|
+
const bigint_1 = require("../../util/bigint");
|
|
19
20
|
const constants_1 = require("../../constants");
|
|
20
21
|
const default_config_1 = require("../../core/config/default-config");
|
|
21
22
|
const errors_1 = require("../../core/errors");
|
|
@@ -51,13 +52,13 @@ const getCurrentTimestamp_1 = require("./utils/getCurrentTimestamp");
|
|
|
51
52
|
const makeCommon_1 = require("./utils/makeCommon");
|
|
52
53
|
const makeForkClient_1 = require("./utils/makeForkClient");
|
|
53
54
|
const makeStateTrie_1 = require("./utils/makeStateTrie");
|
|
54
|
-
const makeForkCommon_1 = require("./utils/makeForkCommon");
|
|
55
55
|
const putGenesisBlock_1 = require("./utils/putGenesisBlock");
|
|
56
56
|
const txMapToArray_1 = require("./utils/txMapToArray");
|
|
57
|
+
const random_1 = require("./utils/random");
|
|
57
58
|
const log = (0, debug_1.default)("hardhat:core:hardhat-network:node");
|
|
58
59
|
/* eslint-disable @nomiclabs/hardhat-internal-rules/only-hardhat-error */
|
|
59
60
|
class HardhatNode extends events_1.default {
|
|
60
|
-
constructor(_vm, _stateManager, _blockchain, _txPool, _automine, _minGasPrice, _blockTimeOffsetSeconds =
|
|
61
|
+
constructor(_vm, _stateManager, _blockchain, _txPool, _automine, _minGasPrice, _blockTimeOffsetSeconds = 0n, _mempoolOrder, _coinbase, genesisAccounts, _configNetworkId, _configChainId, hardfork, _hardforkActivations, _mixHashGenerator, tracingConfig, _forkNetworkId, _forkBlockNumber, nextBlockBaseFee, _forkClient) {
|
|
61
62
|
super();
|
|
62
63
|
this._vm = _vm;
|
|
63
64
|
this._stateManager = _stateManager;
|
|
@@ -70,20 +71,23 @@ class HardhatNode extends events_1.default {
|
|
|
70
71
|
this._coinbase = _coinbase;
|
|
71
72
|
this._configNetworkId = _configNetworkId;
|
|
72
73
|
this._configChainId = _configChainId;
|
|
74
|
+
this.hardfork = hardfork;
|
|
73
75
|
this._hardforkActivations = _hardforkActivations;
|
|
76
|
+
this._mixHashGenerator = _mixHashGenerator;
|
|
74
77
|
this._forkNetworkId = _forkNetworkId;
|
|
75
78
|
this._forkBlockNumber = _forkBlockNumber;
|
|
76
79
|
this._forkClient = _forkClient;
|
|
77
80
|
this._localAccounts = new Map(); // address => private key
|
|
78
81
|
this._impersonatedAccounts = new Set(); // address
|
|
79
|
-
this._nextBlockTimestamp =
|
|
80
|
-
this._lastFilterId =
|
|
82
|
+
this._nextBlockTimestamp = 0n;
|
|
83
|
+
this._lastFilterId = 0n;
|
|
81
84
|
this._filters = new Map();
|
|
82
85
|
this._nextSnapshotId = 1; // We start in 1 to mimic Ganache
|
|
83
86
|
this._snapshots = [];
|
|
84
87
|
this._consoleLogger = new consoleLogger_1.ConsoleLogger();
|
|
85
88
|
this._failedStackTraces = 0;
|
|
86
|
-
|
|
89
|
+
// blockNumber => state root
|
|
90
|
+
this._irregularStatesByBlockNumber = new Map();
|
|
87
91
|
this._initLocalAccounts(genesisAccounts);
|
|
88
92
|
if (nextBlockBaseFee !== undefined) {
|
|
89
93
|
this.setUserProvidedNextBlockBaseFeePerGas(nextBlockBaseFee);
|
|
@@ -114,7 +118,6 @@ class HardhatNode extends events_1.default {
|
|
|
114
118
|
}
|
|
115
119
|
static async create(config) {
|
|
116
120
|
const { automine, genesisAccounts, blockGasLimit, allowUnlimitedContractSize, tracingConfig, minGasPrice, mempoolOrder, networkId, chainId, } = config;
|
|
117
|
-
let common;
|
|
118
121
|
let stateManager;
|
|
119
122
|
let blockchain;
|
|
120
123
|
let initialBlockTimeOffset;
|
|
@@ -123,22 +126,23 @@ class HardhatNode extends events_1.default {
|
|
|
123
126
|
let forkBlockNum;
|
|
124
127
|
let hardforkActivations = new Map();
|
|
125
128
|
const initialBaseFeePerGasConfig = config.initialBaseFeePerGas !== undefined
|
|
126
|
-
?
|
|
129
|
+
? BigInt(config.initialBaseFeePerGas)
|
|
127
130
|
: undefined;
|
|
128
131
|
const hardfork = (0, hardforks_1.getHardforkName)(config.hardfork);
|
|
132
|
+
const mixHashGenerator = random_1.RandomBufferGenerator.create("randomMixHashSeed");
|
|
129
133
|
let forkClient;
|
|
134
|
+
const common = (0, makeCommon_1.makeCommon)(config);
|
|
130
135
|
if ((0, node_types_1.isForkedNodeConfig)(config)) {
|
|
131
136
|
const { forkClient: _forkClient, forkBlockNumber, forkBlockTimestamp, } = await (0, makeForkClient_1.makeForkClient)(config.forkConfig, config.forkCachePath);
|
|
132
137
|
forkClient = _forkClient;
|
|
133
|
-
common = await (0, makeForkCommon_1.makeForkCommon)(config);
|
|
134
138
|
forkNetworkId = forkClient.getNetworkId();
|
|
135
|
-
forkBlockNum = forkBlockNumber
|
|
136
|
-
this._validateHardforks(config.forkConfig.blockNumber, common, forkNetworkId);
|
|
139
|
+
forkBlockNum = forkBlockNumber;
|
|
140
|
+
this._validateHardforks(bigint_1.BigIntUtils.mapNumberToBigInt(config.forkConfig.blockNumber), common, forkNetworkId);
|
|
137
141
|
const forkStateManager = new ForkStateManager_1.ForkStateManager(forkClient, forkBlockNumber);
|
|
138
142
|
await forkStateManager.initializeGenesisAccounts(genesisAccounts);
|
|
139
143
|
stateManager = forkStateManager;
|
|
140
144
|
blockchain = new ForkBlockchain_1.ForkBlockchain(forkClient, forkBlockNumber, common);
|
|
141
|
-
initialBlockTimeOffset =
|
|
145
|
+
initialBlockTimeOffset = BigInt((0, date_1.getDifferenceInSeconds)(new Date(forkBlockTimestamp), new Date()));
|
|
142
146
|
// If the hardfork is London or later we need a base fee per gas for the
|
|
143
147
|
// first local block. If initialBaseFeePerGas config was provided we use
|
|
144
148
|
// that. Otherwise, what we do depends on the block we forked from. If
|
|
@@ -151,7 +155,7 @@ class HardhatNode extends events_1.default {
|
|
|
151
155
|
else {
|
|
152
156
|
const latestBlock = await blockchain.getLatestBlock();
|
|
153
157
|
if (latestBlock.header.baseFeePerGas === undefined) {
|
|
154
|
-
nextBlockBaseFeePerGas =
|
|
158
|
+
nextBlockBaseFeePerGas = BigInt(default_config_1.HARDHAT_NETWORK_DEFAULT_INITIAL_BASE_FEE_PER_GAS);
|
|
155
159
|
}
|
|
156
160
|
}
|
|
157
161
|
}
|
|
@@ -161,30 +165,35 @@ class HardhatNode extends events_1.default {
|
|
|
161
165
|
}
|
|
162
166
|
else {
|
|
163
167
|
const stateTrie = await (0, makeStateTrie_1.makeStateTrie)(genesisAccounts);
|
|
164
|
-
|
|
165
|
-
stateManager = new state_1.DefaultStateManager({
|
|
166
|
-
common,
|
|
168
|
+
stateManager = new statemanager_1.DefaultStateManager({
|
|
167
169
|
trie: stateTrie,
|
|
168
170
|
});
|
|
169
171
|
const hardhatBlockchain = new HardhatBlockchain_1.HardhatBlockchain(common);
|
|
170
172
|
const genesisBlockBaseFeePerGas = (0, hardforks_1.hardforkGte)(hardfork, hardforks_1.HardforkName.LONDON)
|
|
171
|
-
? initialBaseFeePerGasConfig
|
|
173
|
+
? initialBaseFeePerGasConfig ??
|
|
174
|
+
BigInt(default_config_1.HARDHAT_NETWORK_DEFAULT_INITIAL_BASE_FEE_PER_GAS)
|
|
172
175
|
: undefined;
|
|
173
|
-
await (0, putGenesisBlock_1.putGenesisBlock)(hardhatBlockchain, common, genesisBlockBaseFeePerGas);
|
|
176
|
+
await (0, putGenesisBlock_1.putGenesisBlock)(hardhatBlockchain, common, config, stateTrie, hardfork, mixHashGenerator.next(), genesisBlockBaseFeePerGas);
|
|
174
177
|
if (config.initialDate !== undefined) {
|
|
175
|
-
initialBlockTimeOffset =
|
|
178
|
+
initialBlockTimeOffset = BigInt((0, date_1.getDifferenceInSeconds)(config.initialDate, new Date()));
|
|
176
179
|
}
|
|
177
180
|
blockchain = hardhatBlockchain;
|
|
178
181
|
}
|
|
179
|
-
const txPool = new TxPool_1.TxPool(stateManager,
|
|
180
|
-
const
|
|
182
|
+
const txPool = new TxPool_1.TxPool(stateManager, BigInt(blockGasLimit), common);
|
|
183
|
+
const eei = new vm_1.EEI(stateManager, common, blockchain);
|
|
184
|
+
const evm = await evm_1.EVM.create({
|
|
185
|
+
eei,
|
|
186
|
+
allowUnlimitedContractSize,
|
|
181
187
|
common,
|
|
188
|
+
});
|
|
189
|
+
const vm = await vm_1.VM.create({
|
|
190
|
+
evm,
|
|
182
191
|
activatePrecompiles: true,
|
|
192
|
+
common,
|
|
183
193
|
stateManager,
|
|
184
|
-
blockchain
|
|
185
|
-
allowUnlimitedContractSize,
|
|
194
|
+
blockchain,
|
|
186
195
|
});
|
|
187
|
-
const node = new HardhatNode(vm, stateManager, blockchain, txPool, automine, minGasPrice, initialBlockTimeOffset, mempoolOrder, config.coinbase, genesisAccounts, networkId, chainId, hardforkActivations, tracingConfig, forkNetworkId, forkBlockNum, nextBlockBaseFeePerGas, forkClient);
|
|
196
|
+
const node = new HardhatNode(vm, stateManager, blockchain, txPool, automine, minGasPrice, initialBlockTimeOffset, mempoolOrder, config.coinbase, genesisAccounts, networkId, chainId, hardfork, hardforkActivations, mixHashGenerator, tracingConfig, forkNetworkId, forkBlockNum, nextBlockBaseFeePerGas, forkClient);
|
|
188
197
|
return [common, node];
|
|
189
198
|
}
|
|
190
199
|
static _validateHardforks(forkBlockNumber, common, remoteChainId) {
|
|
@@ -196,9 +205,9 @@ The hardfork must be at least spuriousDragon, but ${common.hardfork()} was given
|
|
|
196
205
|
if (forkBlockNumber !== undefined) {
|
|
197
206
|
let upstreamCommon;
|
|
198
207
|
try {
|
|
199
|
-
upstreamCommon = new common_1.
|
|
208
|
+
upstreamCommon = new common_1.Common({ chain: remoteChainId });
|
|
200
209
|
}
|
|
201
|
-
catch
|
|
210
|
+
catch {
|
|
202
211
|
// If ethereumjs doesn't have a common it will throw and we won't have
|
|
203
212
|
// info about the activation block of each hardfork, so we don't run
|
|
204
213
|
// this validation.
|
|
@@ -213,7 +222,7 @@ Hardhat Network's forking functionality only works with blocks from at least spu
|
|
|
213
222
|
}
|
|
214
223
|
}
|
|
215
224
|
async getSignedTransaction(txParams) {
|
|
216
|
-
const senderAddress = (0,
|
|
225
|
+
const senderAddress = (0, util_1.bufferToHex)(txParams.from);
|
|
217
226
|
const pk = this._localAccounts.get(senderAddress);
|
|
218
227
|
if (pk !== undefined) {
|
|
219
228
|
let tx;
|
|
@@ -249,10 +258,12 @@ Hardhat Network's forking functionality only works with blocks from at least spu
|
|
|
249
258
|
return this._mineTransaction(tx);
|
|
250
259
|
}
|
|
251
260
|
async mineBlock(timestamp) {
|
|
252
|
-
const
|
|
261
|
+
const timestampAndOffset = this._calculateTimestampAndOffset(timestamp);
|
|
262
|
+
let [blockTimestamp] = timestampAndOffset;
|
|
263
|
+
const [, offsetShouldChange, newOffset] = timestampAndOffset;
|
|
253
264
|
const needsTimestampIncrease = await this._timestampClashesWithPreviousBlockOne(blockTimestamp);
|
|
254
265
|
if (needsTimestampIncrease) {
|
|
255
|
-
blockTimestamp
|
|
266
|
+
blockTimestamp += 1n;
|
|
256
267
|
}
|
|
257
268
|
let result;
|
|
258
269
|
try {
|
|
@@ -260,7 +271,7 @@ Hardhat Network's forking functionality only works with blocks from at least spu
|
|
|
260
271
|
}
|
|
261
272
|
catch (err) {
|
|
262
273
|
if (err instanceof Error) {
|
|
263
|
-
if (err
|
|
274
|
+
if (err?.message.includes("sender doesn't have enough funds")) {
|
|
264
275
|
throw new errors_2.InvalidInputError(err.message, err);
|
|
265
276
|
}
|
|
266
277
|
// Some network errors are HardhatErrors, and can end up here when forking
|
|
@@ -274,7 +285,7 @@ Hardhat Network's forking functionality only works with blocks from at least spu
|
|
|
274
285
|
}
|
|
275
286
|
await this._saveBlockAsSuccessfullyRun(result.block, result.blockResult);
|
|
276
287
|
if (needsTimestampIncrease) {
|
|
277
|
-
this.increaseTime(
|
|
288
|
+
this.increaseTime(1n);
|
|
278
289
|
}
|
|
279
290
|
if (offsetShouldChange) {
|
|
280
291
|
this.setTimeIncrement(newOffset);
|
|
@@ -290,8 +301,8 @@ Hardhat Network's forking functionality only works with blocks from at least spu
|
|
|
290
301
|
* Returns an array with the results of the blocks that were really mined (the
|
|
291
302
|
* ones that were reserved are not included).
|
|
292
303
|
*/
|
|
293
|
-
async mineBlocks(count =
|
|
294
|
-
if (count
|
|
304
|
+
async mineBlocks(count = 1n, interval = 1n) {
|
|
305
|
+
if (count === 0n) {
|
|
295
306
|
// nothing to do
|
|
296
307
|
return [];
|
|
297
308
|
}
|
|
@@ -301,67 +312,77 @@ Hardhat Network's forking functionality only works with blocks from at least spu
|
|
|
301
312
|
// helper function to mine a block with a timstamp that respects the
|
|
302
313
|
// interval
|
|
303
314
|
const mineBlock = async () => {
|
|
304
|
-
const nextTimestamp = (await this.getLatestBlock()).header.timestamp
|
|
315
|
+
const nextTimestamp = (await this.getLatestBlock()).header.timestamp + interval;
|
|
305
316
|
mineBlockResults.push(await this.mineBlock(nextTimestamp));
|
|
306
317
|
};
|
|
307
318
|
// then we mine any pending transactions
|
|
308
|
-
while (count
|
|
319
|
+
while (count > mineBlockResults.length &&
|
|
309
320
|
this._txPool.hasPendingTransactions()) {
|
|
310
321
|
await mineBlock();
|
|
311
322
|
}
|
|
312
323
|
// If there is at least one remaining block, we mine one. This way, we
|
|
313
324
|
// guarantee that there's an empty block immediately before and after the
|
|
314
325
|
// reservation. This makes the logging easier to get right.
|
|
315
|
-
if (count
|
|
326
|
+
if (count > mineBlockResults.length) {
|
|
316
327
|
await mineBlock();
|
|
317
328
|
}
|
|
318
|
-
const remainingBlockCount = count
|
|
329
|
+
const remainingBlockCount = count - BigInt(mineBlockResults.length);
|
|
319
330
|
// There should be at least 2 blocks left for the reservation to work,
|
|
320
331
|
// because we always mine a block after it. But here we use a bigger
|
|
321
332
|
// number to err on the safer side.
|
|
322
|
-
if (remainingBlockCount
|
|
333
|
+
if (remainingBlockCount <= 5) {
|
|
323
334
|
// if there are few blocks left to mine, we just mine them
|
|
324
|
-
while (count
|
|
335
|
+
while (count > mineBlockResults.length) {
|
|
325
336
|
await mineBlock();
|
|
326
337
|
}
|
|
327
338
|
return mineBlockResults;
|
|
328
339
|
}
|
|
329
340
|
// otherwise, we reserve a range and mine the last one
|
|
330
341
|
const latestBlock = await this.getLatestBlock();
|
|
331
|
-
this._blockchain.reserveBlocks(remainingBlockCount
|
|
342
|
+
this._blockchain.reserveBlocks(remainingBlockCount - 1n, interval, await this._stateManager.getStateRoot(), await this.getBlockTotalDifficulty(latestBlock), (await this.getLatestBlock()).header.baseFeePerGas);
|
|
332
343
|
await mineBlock();
|
|
333
344
|
return mineBlockResults;
|
|
334
345
|
}
|
|
335
346
|
async runCall(call, blockNumberOrPending) {
|
|
336
|
-
var _a, _b, _c, _d;
|
|
337
347
|
let txParams;
|
|
338
|
-
const nonce = await this._getNonce(new
|
|
348
|
+
const nonce = await this._getNonce(new util_1.Address(call.from), blockNumberOrPending);
|
|
339
349
|
if (call.gasPrice !== undefined ||
|
|
340
350
|
!this.isEip1559Active(blockNumberOrPending)) {
|
|
341
|
-
txParams =
|
|
351
|
+
txParams = {
|
|
352
|
+
gasPrice: 0n,
|
|
353
|
+
nonce,
|
|
354
|
+
...call,
|
|
355
|
+
};
|
|
342
356
|
}
|
|
343
357
|
else {
|
|
344
|
-
const maxFeePerGas =
|
|
345
|
-
const maxPriorityFeePerGas =
|
|
346
|
-
txParams =
|
|
358
|
+
const maxFeePerGas = call.maxFeePerGas ?? call.maxPriorityFeePerGas ?? 0n;
|
|
359
|
+
const maxPriorityFeePerGas = call.maxPriorityFeePerGas ?? 0n;
|
|
360
|
+
txParams = {
|
|
361
|
+
...call,
|
|
362
|
+
nonce,
|
|
347
363
|
maxFeePerGas,
|
|
348
|
-
maxPriorityFeePerGas,
|
|
364
|
+
maxPriorityFeePerGas,
|
|
365
|
+
accessList: call.accessList ?? [],
|
|
366
|
+
};
|
|
349
367
|
}
|
|
350
368
|
const tx = await this._getFakeTransaction(txParams);
|
|
351
369
|
const result = await this._runInBlockContext(blockNumberOrPending, async () => this._runTxAndRevertMutations(tx, blockNumberOrPending, true));
|
|
352
370
|
const traces = await this._gatherTraces(result.execResult);
|
|
353
|
-
return
|
|
371
|
+
return {
|
|
372
|
+
...traces,
|
|
373
|
+
result: new return_data_1.ReturnData(result.execResult.returnValue),
|
|
374
|
+
};
|
|
354
375
|
}
|
|
355
376
|
async getAccountBalance(address, blockNumberOrPending) {
|
|
356
377
|
if (blockNumberOrPending === undefined) {
|
|
357
378
|
blockNumberOrPending = this.getLatestBlockNumber();
|
|
358
379
|
}
|
|
359
380
|
const account = await this._runInBlockContext(blockNumberOrPending, () => this._stateManager.getAccount(address));
|
|
360
|
-
return
|
|
381
|
+
return account.balance;
|
|
361
382
|
}
|
|
362
383
|
async getNextConfirmedNonce(address, blockNumberOrPending) {
|
|
363
384
|
const account = await this._runInBlockContext(blockNumberOrPending, () => this._stateManager.getAccount(address));
|
|
364
|
-
return
|
|
385
|
+
return account.nonce;
|
|
365
386
|
}
|
|
366
387
|
async getAccountNextPendingNonce(address) {
|
|
367
388
|
return this._txPool.getNextPendingNonce(address);
|
|
@@ -372,7 +393,7 @@ Hardhat Network's forking functionality only works with blocks from at least spu
|
|
|
372
393
|
(0, message_trace_1.isCreateTrace)(trace)) {
|
|
373
394
|
return Buffer.from("");
|
|
374
395
|
}
|
|
375
|
-
return this.getCode(new
|
|
396
|
+
return this.getCode(new util_1.Address(trace.address), blockNumberOrPending);
|
|
376
397
|
}
|
|
377
398
|
async getLatestBlock() {
|
|
378
399
|
return this._blockchain.getLatestBlock();
|
|
@@ -394,10 +415,9 @@ Hardhat Network's forking functionality only works with blocks from at least spu
|
|
|
394
415
|
return this._txPool.getBlockGasLimit();
|
|
395
416
|
}
|
|
396
417
|
async estimateGas(callParams, blockNumberOrPending) {
|
|
397
|
-
var _a, _b;
|
|
398
418
|
// We get the CallParams and transform it into a TransactionParams to be
|
|
399
419
|
// able to run it.
|
|
400
|
-
const nonce = await this._getNonce(new
|
|
420
|
+
const nonce = await this._getNonce(new util_1.Address(callParams.from), blockNumberOrPending);
|
|
401
421
|
// TODO: This is more complex in Geth, we should make sure we aren't missing
|
|
402
422
|
// anything here.
|
|
403
423
|
const feePriceFields = await this._getEstimateGasFeePriceFields(callParams, blockNumberOrPending);
|
|
@@ -405,16 +425,31 @@ Hardhat Network's forking functionality only works with blocks from at least spu
|
|
|
405
425
|
if ("gasPrice" in feePriceFields) {
|
|
406
426
|
if (callParams.accessList === undefined) {
|
|
407
427
|
// Legacy tx
|
|
408
|
-
txParams =
|
|
428
|
+
txParams = {
|
|
429
|
+
...callParams,
|
|
430
|
+
nonce,
|
|
431
|
+
gasPrice: feePriceFields.gasPrice,
|
|
432
|
+
};
|
|
409
433
|
}
|
|
410
434
|
else {
|
|
411
435
|
// Access list tx
|
|
412
|
-
txParams =
|
|
436
|
+
txParams = {
|
|
437
|
+
...callParams,
|
|
438
|
+
nonce,
|
|
439
|
+
gasPrice: feePriceFields.gasPrice,
|
|
440
|
+
accessList: callParams.accessList ?? [],
|
|
441
|
+
};
|
|
413
442
|
}
|
|
414
443
|
}
|
|
415
444
|
else {
|
|
416
445
|
// EIP-1559 tx
|
|
417
|
-
txParams =
|
|
446
|
+
txParams = {
|
|
447
|
+
...callParams,
|
|
448
|
+
nonce,
|
|
449
|
+
maxFeePerGas: feePriceFields.maxFeePerGas,
|
|
450
|
+
maxPriorityFeePerGas: feePriceFields.maxPriorityFeePerGas,
|
|
451
|
+
accessList: callParams.accessList ?? [],
|
|
452
|
+
};
|
|
418
453
|
}
|
|
419
454
|
const tx = await this._getFakeTransaction(txParams);
|
|
420
455
|
// TODO: This may not work if there are multiple txs in the mempool and
|
|
@@ -439,7 +474,7 @@ Hardhat Network's forking functionality only works with blocks from at least spu
|
|
|
439
474
|
consoleLogMessages,
|
|
440
475
|
};
|
|
441
476
|
}
|
|
442
|
-
const initialEstimation = result.
|
|
477
|
+
const initialEstimation = result.totalGasSpent;
|
|
443
478
|
return {
|
|
444
479
|
estimation: await this._correctInitialEstimation(blockNumberOrPending, txParams, initialEstimation),
|
|
445
480
|
trace: vmTrace,
|
|
@@ -450,19 +485,19 @@ Hardhat Network's forking functionality only works with blocks from at least spu
|
|
|
450
485
|
const nextBlockBaseFeePerGas = await this.getNextBlockBaseFeePerGas();
|
|
451
486
|
if (nextBlockBaseFeePerGas === undefined) {
|
|
452
487
|
// We return a hardcoded value for networks without EIP-1559
|
|
453
|
-
return
|
|
488
|
+
return 8n * 10n ** 9n;
|
|
454
489
|
}
|
|
455
|
-
const suggestedPriorityFeePerGas =
|
|
456
|
-
return nextBlockBaseFeePerGas
|
|
490
|
+
const suggestedPriorityFeePerGas = 10n ** 9n;
|
|
491
|
+
return nextBlockBaseFeePerGas + suggestedPriorityFeePerGas;
|
|
457
492
|
}
|
|
458
493
|
async getMaxPriorityFeePerGas() {
|
|
459
|
-
return
|
|
494
|
+
return BigInt(default_config_1.HARDHAT_NETWORK_DEFAULT_MAX_PRIORITY_FEE_PER_GAS);
|
|
460
495
|
}
|
|
461
496
|
getCoinbaseAddress() {
|
|
462
|
-
return
|
|
497
|
+
return util_1.Address.fromString(this._coinbase);
|
|
463
498
|
}
|
|
464
499
|
async getStorageAt(address, positionIndex, blockNumberOrPending) {
|
|
465
|
-
const key =
|
|
500
|
+
const key = (0, util_1.setLengthLeft)((0, util_1.bigIntToBuffer)(positionIndex), 32);
|
|
466
501
|
const data = await this._runInBlockContext(blockNumberOrPending, () => this._stateManager.getContractStorage(address, key));
|
|
467
502
|
const EXPECTED_DATA_SIZE = 32;
|
|
468
503
|
if (data.length < EXPECTED_DATA_SIZE) {
|
|
@@ -475,15 +510,15 @@ Hardhat Network's forking functionality only works with blocks from at least spu
|
|
|
475
510
|
return this._runInPendingBlockContext(() => this._blockchain.getLatestBlock());
|
|
476
511
|
}
|
|
477
512
|
const block = await this._blockchain.getBlock(blockNumberOrPending);
|
|
478
|
-
return block
|
|
513
|
+
return block ?? undefined;
|
|
479
514
|
}
|
|
480
515
|
async getBlockByHash(blockHash) {
|
|
481
516
|
const block = await this._blockchain.getBlock(blockHash);
|
|
482
|
-
return block
|
|
517
|
+
return block ?? undefined;
|
|
483
518
|
}
|
|
484
519
|
async getBlockByTransactionHash(hash) {
|
|
485
520
|
const block = await this._blockchain.getBlockByTransactionHash(hash);
|
|
486
|
-
return block
|
|
521
|
+
return block ?? undefined;
|
|
487
522
|
}
|
|
488
523
|
async getBlockTotalDifficulty(block) {
|
|
489
524
|
return this._blockchain.getTotalDifficulty(block.hash());
|
|
@@ -492,19 +527,19 @@ Hardhat Network's forking functionality only works with blocks from at least spu
|
|
|
492
527
|
return this._runInBlockContext(blockNumberOrPending, () => this._stateManager.getContractCode(address));
|
|
493
528
|
}
|
|
494
529
|
getNextBlockTimestamp() {
|
|
495
|
-
return this._nextBlockTimestamp
|
|
530
|
+
return this._nextBlockTimestamp;
|
|
496
531
|
}
|
|
497
532
|
setNextBlockTimestamp(timestamp) {
|
|
498
|
-
this._nextBlockTimestamp =
|
|
533
|
+
this._nextBlockTimestamp = timestamp;
|
|
499
534
|
}
|
|
500
535
|
getTimeIncrement() {
|
|
501
|
-
return this._blockTimeOffsetSeconds
|
|
536
|
+
return this._blockTimeOffsetSeconds;
|
|
502
537
|
}
|
|
503
538
|
setTimeIncrement(timeIncrement) {
|
|
504
539
|
this._blockTimeOffsetSeconds = timeIncrement;
|
|
505
540
|
}
|
|
506
541
|
increaseTime(increment) {
|
|
507
|
-
this._blockTimeOffsetSeconds
|
|
542
|
+
this._blockTimeOffsetSeconds += increment;
|
|
508
543
|
}
|
|
509
544
|
setUserProvidedNextBlockBaseFeePerGas(baseFeePerGas) {
|
|
510
545
|
this._userProvidedNextBlockBaseFeePerGas = baseFeePerGas;
|
|
@@ -527,13 +562,12 @@ Hardhat Network's forking functionality only works with blocks from at least spu
|
|
|
527
562
|
return latestBlock.header.calcNextBaseFee();
|
|
528
563
|
}
|
|
529
564
|
async getPendingTransaction(hash) {
|
|
530
|
-
|
|
531
|
-
return (_a = this._txPool.getTransactionByHash(hash)) === null || _a === void 0 ? void 0 : _a.data;
|
|
565
|
+
return this._txPool.getTransactionByHash(hash)?.data;
|
|
532
566
|
}
|
|
533
567
|
async getTransactionReceipt(hash) {
|
|
534
|
-
const hashBuffer = hash instanceof Buffer ? hash : (0,
|
|
568
|
+
const hashBuffer = hash instanceof Buffer ? hash : (0, util_1.toBuffer)(hash);
|
|
535
569
|
const receipt = await this._blockchain.getTransactionReceipt(hashBuffer);
|
|
536
|
-
return receipt
|
|
570
|
+
return receipt ?? undefined;
|
|
537
571
|
}
|
|
538
572
|
async getPendingTransactions() {
|
|
539
573
|
const txPoolPending = (0, txMapToArray_1.txMapToArray)(this._txPool.getPendingTransactions());
|
|
@@ -541,9 +575,9 @@ Hardhat Network's forking functionality only works with blocks from at least spu
|
|
|
541
575
|
return txPoolPending.concat(txPoolQueued);
|
|
542
576
|
}
|
|
543
577
|
async signPersonalMessage(address, data) {
|
|
544
|
-
const messageHash = (0,
|
|
578
|
+
const messageHash = (0, util_1.hashPersonalMessage)(data);
|
|
545
579
|
const privateKey = this._getLocalAccountPrivateKey(address);
|
|
546
|
-
return (0,
|
|
580
|
+
return (0, util_1.ecsign)(messageHash, privateKey);
|
|
547
581
|
}
|
|
548
582
|
async signTypedDataV4(address, typedData) {
|
|
549
583
|
const privateKey = this._getLocalAccountPrivateKey(address);
|
|
@@ -569,6 +603,7 @@ Hardhat Network's forking functionality only works with blocks from at least spu
|
|
|
569
603
|
irregularStatesByBlockNumber: this._irregularStatesByBlockNumber,
|
|
570
604
|
userProvidedNextBlockBaseFeePerGas: this.getUserProvidedNextBlockBaseFeePerGas(),
|
|
571
605
|
coinbase: this.getCoinbaseAddress().toString(),
|
|
606
|
+
mixHashGenerator: this._mixHashGenerator.clone(),
|
|
572
607
|
};
|
|
573
608
|
this._irregularStatesByBlockNumber = new Map(this._irregularStatesByBlockNumber);
|
|
574
609
|
this._snapshots.push(snapshot);
|
|
@@ -586,7 +621,7 @@ Hardhat Network's forking functionality only works with blocks from at least spu
|
|
|
586
621
|
const now = new Date();
|
|
587
622
|
const offsetToSnapshotInMillis = snapshot.date.valueOf() - now.valueOf();
|
|
588
623
|
const offsetToSnapshotInSecs = Math.ceil(offsetToSnapshotInMillis / 1000);
|
|
589
|
-
const newOffset = snapshot.blockTimeOffsetSeconds
|
|
624
|
+
const newOffset = snapshot.blockTimeOffsetSeconds + BigInt(offsetToSnapshotInSecs);
|
|
590
625
|
// We delete all following blocks, changes the state root, and all the
|
|
591
626
|
// relevant Node fields.
|
|
592
627
|
//
|
|
@@ -594,8 +629,8 @@ Hardhat Network's forking functionality only works with blocks from at least spu
|
|
|
594
629
|
// used once
|
|
595
630
|
this._blockchain.deleteLaterBlocks(snapshot.latestBlock);
|
|
596
631
|
this._irregularStatesByBlockNumber = snapshot.irregularStatesByBlockNumber;
|
|
597
|
-
const irregularStateOrUndefined = this._irregularStatesByBlockNumber.get((await this.getLatestBlock()).header.number
|
|
598
|
-
await this._stateManager.setStateRoot(irregularStateOrUndefined
|
|
632
|
+
const irregularStateOrUndefined = this._irregularStatesByBlockNumber.get((await this.getLatestBlock()).header.number);
|
|
633
|
+
await this._stateManager.setStateRoot(irregularStateOrUndefined ?? snapshot.stateRoot);
|
|
599
634
|
this.setTimeIncrement(newOffset);
|
|
600
635
|
this.setNextBlockTimestamp(snapshot.nextBlockTimestamp);
|
|
601
636
|
this._txPool.revert(snapshot.txPoolSnapshotId);
|
|
@@ -606,6 +641,7 @@ Hardhat Network's forking functionality only works with blocks from at least spu
|
|
|
606
641
|
this._resetUserProvidedNextBlockBaseFeePerGas();
|
|
607
642
|
}
|
|
608
643
|
this._coinbase = snapshot.coinbase;
|
|
644
|
+
this._mixHashGenerator = snapshot.mixHashGenerator;
|
|
609
645
|
// We delete this and the following snapshots, as they can only be used
|
|
610
646
|
// once in Ganache
|
|
611
647
|
this._snapshots.splice(snapshotIndex);
|
|
@@ -637,7 +673,7 @@ Hardhat Network's forking functionality only works with blocks from at least spu
|
|
|
637
673
|
id: filterId,
|
|
638
674
|
type: filter_1.Type.BLOCK_SUBSCRIPTION,
|
|
639
675
|
deadline: this._newDeadline(),
|
|
640
|
-
hashes: [(0,
|
|
676
|
+
hashes: [(0, util_1.bufferToHex)(block.header.hash())],
|
|
641
677
|
logs: [],
|
|
642
678
|
subscription: isSubscription,
|
|
643
679
|
});
|
|
@@ -719,11 +755,11 @@ Hardhat Network's forking functionality only works with blocks from at least spu
|
|
|
719
755
|
return true;
|
|
720
756
|
}
|
|
721
757
|
addImpersonatedAccount(address) {
|
|
722
|
-
this._impersonatedAccounts.add((0,
|
|
758
|
+
this._impersonatedAccounts.add((0, util_1.bufferToHex)(address));
|
|
723
759
|
return true;
|
|
724
760
|
}
|
|
725
761
|
removeImpersonatedAccount(address) {
|
|
726
|
-
return this._impersonatedAccounts.delete((0,
|
|
762
|
+
return this._impersonatedAccounts.delete((0, util_1.bufferToHex)(address));
|
|
727
763
|
}
|
|
728
764
|
setAutomine(automine) {
|
|
729
765
|
this._automine = automine;
|
|
@@ -745,7 +781,7 @@ Hardhat Network's forking functionality only works with blocks from at least spu
|
|
|
745
781
|
}
|
|
746
782
|
const isTransactionMined = await this._isTransactionMined(hash);
|
|
747
783
|
if (isTransactionMined) {
|
|
748
|
-
throw new errors_2.InvalidArgumentsError(`Transaction ${(0,
|
|
784
|
+
throw new errors_2.InvalidArgumentsError(`Transaction ${(0, util_1.bufferToHex)(hash)} cannot be dropped because it's already mined`);
|
|
749
785
|
}
|
|
750
786
|
return false;
|
|
751
787
|
}
|
|
@@ -764,7 +800,7 @@ Hardhat Network's forking functionality only works with blocks from at least spu
|
|
|
764
800
|
throw new errors_2.InternalError("Cannot set account nonce when the transaction pool is not empty");
|
|
765
801
|
}
|
|
766
802
|
const account = await this._stateManager.getAccount(address);
|
|
767
|
-
if (newNonce
|
|
803
|
+
if (newNonce < account.nonce) {
|
|
768
804
|
throw new errors_2.InvalidInputError(`New nonce (${newNonce.toString()}) must not be smaller than the existing nonce (${account.nonce.toString()})`);
|
|
769
805
|
}
|
|
770
806
|
account.nonce = newNonce;
|
|
@@ -772,23 +808,23 @@ Hardhat Network's forking functionality only works with blocks from at least spu
|
|
|
772
808
|
await this._persistIrregularWorldState();
|
|
773
809
|
}
|
|
774
810
|
async setStorageAt(address, positionIndex, value) {
|
|
775
|
-
await this._stateManager.putContractStorage(address,
|
|
811
|
+
await this._stateManager.putContractStorage(address, (0, util_1.setLengthLeft)((0, util_1.bigIntToBuffer)(positionIndex), 32), value);
|
|
776
812
|
await this._persistIrregularWorldState();
|
|
777
813
|
}
|
|
778
814
|
async traceTransaction(hash, config) {
|
|
779
815
|
const block = await this.getBlockByTransactionHash(hash);
|
|
780
816
|
if (block === undefined) {
|
|
781
|
-
throw new errors_2.InvalidInputError(`Unable to find a block containing transaction ${(0,
|
|
817
|
+
throw new errors_2.InvalidInputError(`Unable to find a block containing transaction ${(0, util_1.bufferToHex)(hash)}`);
|
|
782
818
|
}
|
|
783
|
-
return this._runInBlockContext(
|
|
784
|
-
const blockNumber = block.header.number
|
|
819
|
+
return this._runInBlockContext(block.header.number - 1n, async () => {
|
|
820
|
+
const blockNumber = block.header.number;
|
|
785
821
|
const blockchain = this._blockchain;
|
|
786
822
|
let vm = this._vm;
|
|
787
823
|
if (blockchain instanceof ForkBlockchain_1.ForkBlockchain &&
|
|
788
|
-
blockNumber <= blockchain.getForkBlockNumber()
|
|
824
|
+
blockNumber <= blockchain.getForkBlockNumber()) {
|
|
789
825
|
(0, errors_1.assertHardhatInvariant)(this._forkNetworkId !== undefined, "this._forkNetworkId should exist if the blockchain is an instance of ForkBlockchain");
|
|
790
826
|
const common = this._getCommonForTracing(this._forkNetworkId, blockNumber);
|
|
791
|
-
vm =
|
|
827
|
+
vm = await vm_1.VM.create({
|
|
792
828
|
common,
|
|
793
829
|
activatePrecompiles: true,
|
|
794
830
|
stateManager: this._vm.stateManager,
|
|
@@ -817,7 +853,7 @@ Hardhat Network's forking functionality only works with blocks from at least spu
|
|
|
817
853
|
});
|
|
818
854
|
}
|
|
819
855
|
else if (tx.type === 2) {
|
|
820
|
-
txWithCommon = new FakeSenderEIP1559Transaction_1.FakeSenderEIP1559Transaction(sender,
|
|
856
|
+
txWithCommon = new FakeSenderEIP1559Transaction_1.FakeSenderEIP1559Transaction(sender, { ...tx, gasPrice: undefined }, {
|
|
821
857
|
common: vm._common,
|
|
822
858
|
});
|
|
823
859
|
}
|
|
@@ -837,23 +873,22 @@ Hardhat Network's forking functionality only works with blocks from at least spu
|
|
|
837
873
|
});
|
|
838
874
|
}
|
|
839
875
|
async getFeeHistory(blockCount, newestBlock, rewardPercentiles) {
|
|
840
|
-
var _a;
|
|
841
876
|
const latestBlock = this.getLatestBlockNumber();
|
|
842
|
-
const pendingBlockNumber = latestBlock
|
|
877
|
+
const pendingBlockNumber = latestBlock + 1n;
|
|
843
878
|
const resolvedNewestBlock = newestBlock === "pending" ? pendingBlockNumber : newestBlock;
|
|
844
|
-
const oldestBlock =
|
|
879
|
+
const oldestBlock = bigint_1.BigIntUtils.max(resolvedNewestBlock - blockCount + 1n, 0n);
|
|
845
880
|
// This is part of a temporary fix to https://github.com/NomicFoundation/hardhat/issues/2380
|
|
846
881
|
const rangeIncludesRemoteBlocks = this._forkBlockNumber !== undefined &&
|
|
847
|
-
oldestBlock
|
|
882
|
+
oldestBlock <= this._forkBlockNumber;
|
|
848
883
|
const baseFeePerGas = [];
|
|
849
884
|
const gasUsedRatio = [];
|
|
850
885
|
const reward = [];
|
|
851
|
-
const lastBlock = resolvedNewestBlock
|
|
886
|
+
const lastBlock = resolvedNewestBlock + 1n;
|
|
852
887
|
// This is part of a temporary fix to https://github.com/NomicFoundation/hardhat/issues/2380
|
|
853
888
|
if (rangeIncludesRemoteBlocks) {
|
|
854
889
|
try {
|
|
855
|
-
const lastRemoteBlock =
|
|
856
|
-
const remoteBlockCount = lastRemoteBlock
|
|
890
|
+
const lastRemoteBlock = bigint_1.BigIntUtils.min(BigInt(this._forkBlockNumber), lastBlock);
|
|
891
|
+
const remoteBlockCount = lastRemoteBlock - oldestBlock + 1n;
|
|
857
892
|
const remoteValues = await this._forkClient.getFeeHistory(remoteBlockCount, lastRemoteBlock, rewardPercentiles);
|
|
858
893
|
baseFeePerGas.push(...remoteValues.baseFeePerGas);
|
|
859
894
|
gasUsedRatio.push(...remoteValues.gasUsedRatio);
|
|
@@ -869,39 +904,39 @@ Hardhat Network's forking functionality only works with blocks from at least spu
|
|
|
869
904
|
// We get the pending block here, and only if necessary, as it's something
|
|
870
905
|
// costly to do.
|
|
871
906
|
let pendingBlock;
|
|
872
|
-
if (lastBlock
|
|
907
|
+
if (lastBlock >= pendingBlockNumber) {
|
|
873
908
|
pendingBlock = await this.getBlockByNumber("pending");
|
|
874
909
|
}
|
|
875
910
|
// This is part of a temporary fix to https://github.com/NomicFoundation/hardhat/issues/2380
|
|
876
911
|
const firstLocalBlock = !rangeIncludesRemoteBlocks
|
|
877
912
|
? oldestBlock
|
|
878
|
-
:
|
|
913
|
+
: bigint_1.BigIntUtils.min(BigInt(this._forkBlockNumber), lastBlock) + 1n;
|
|
879
914
|
for (let blockNumber = firstLocalBlock; // This is part of a temporary fix to https://github.com/NomicFoundation/hardhat/issues/2380
|
|
880
|
-
blockNumber
|
|
881
|
-
if (blockNumber
|
|
915
|
+
blockNumber <= lastBlock; blockNumber++) {
|
|
916
|
+
if (blockNumber < pendingBlockNumber) {
|
|
882
917
|
// We know the block exists
|
|
883
918
|
const block = (await this.getBlockByNumber(blockNumber));
|
|
884
|
-
baseFeePerGas.push(
|
|
885
|
-
if (blockNumber
|
|
919
|
+
baseFeePerGas.push(block.header.baseFeePerGas ?? 0n);
|
|
920
|
+
if (blockNumber < lastBlock) {
|
|
886
921
|
gasUsedRatio.push(this._getGasUsedRatio(block));
|
|
887
922
|
if (rewardPercentiles.length > 0) {
|
|
888
923
|
reward.push(await this._getRewards(block, rewardPercentiles));
|
|
889
924
|
}
|
|
890
925
|
}
|
|
891
926
|
}
|
|
892
|
-
else if (blockNumber
|
|
927
|
+
else if (blockNumber === pendingBlockNumber) {
|
|
893
928
|
// This can only be run with EIP-1559, so this exists
|
|
894
929
|
baseFeePerGas.push((await this.getNextBlockBaseFeePerGas()));
|
|
895
|
-
if (blockNumber
|
|
930
|
+
if (blockNumber < lastBlock) {
|
|
896
931
|
gasUsedRatio.push(this._getGasUsedRatio(pendingBlock));
|
|
897
932
|
if (rewardPercentiles.length > 0) {
|
|
898
933
|
// We don't compute this for the pending block, as there's no
|
|
899
934
|
// effective miner fee yet.
|
|
900
|
-
reward.push(rewardPercentiles.map((_) =>
|
|
935
|
+
reward.push(rewardPercentiles.map((_) => 0n));
|
|
901
936
|
}
|
|
902
937
|
}
|
|
903
938
|
}
|
|
904
|
-
else if (blockNumber
|
|
939
|
+
else if (blockNumber === pendingBlockNumber + 1n) {
|
|
905
940
|
baseFeePerGas.push(pendingBlock.header.calcNextBaseFee());
|
|
906
941
|
}
|
|
907
942
|
else {
|
|
@@ -920,49 +955,45 @@ Hardhat Network's forking functionality only works with blocks from at least spu
|
|
|
920
955
|
}
|
|
921
956
|
_getGasUsedRatio(block) {
|
|
922
957
|
const FLOATS_PRECISION = 100000;
|
|
923
|
-
return (block.header.gasUsed
|
|
924
|
-
.
|
|
925
|
-
.div(block.header.gasLimit)
|
|
926
|
-
.toNumber() / FLOATS_PRECISION);
|
|
958
|
+
return (Number((block.header.gasUsed * BigInt(FLOATS_PRECISION)) /
|
|
959
|
+
block.header.gasLimit) / FLOATS_PRECISION);
|
|
927
960
|
}
|
|
928
961
|
async _getRewards(block, rewardPercentiles) {
|
|
929
962
|
const FLOATS_PRECISION = 100000;
|
|
930
963
|
if (block.transactions.length === 0) {
|
|
931
|
-
return rewardPercentiles.map((_) =>
|
|
964
|
+
return rewardPercentiles.map((_) => 0n);
|
|
932
965
|
}
|
|
933
966
|
const receipts = await Promise.all(block.transactions
|
|
934
967
|
.map((tx) => tx.hash())
|
|
935
968
|
.map((hash) => this.getTransactionReceipt(hash)));
|
|
936
969
|
const effectiveGasRewardAndGas = receipts
|
|
937
970
|
.map((r, i) => {
|
|
938
|
-
var _a;
|
|
939
971
|
const tx = block.transactions[i];
|
|
940
|
-
const baseFeePerGas =
|
|
972
|
+
const baseFeePerGas = block.header.baseFeePerGas ?? 0n;
|
|
941
973
|
// reward = min(maxPriorityFeePerGas, maxFeePerGas - baseFeePerGas)
|
|
942
974
|
let effectiveGasReward;
|
|
943
975
|
if ("maxPriorityFeePerGas" in tx) {
|
|
944
|
-
effectiveGasReward = tx.maxFeePerGas
|
|
945
|
-
if (tx.maxPriorityFeePerGas
|
|
976
|
+
effectiveGasReward = tx.maxFeePerGas - baseFeePerGas;
|
|
977
|
+
if (tx.maxPriorityFeePerGas < effectiveGasReward) {
|
|
946
978
|
effectiveGasReward = tx.maxPriorityFeePerGas;
|
|
947
979
|
}
|
|
948
980
|
}
|
|
949
981
|
else {
|
|
950
|
-
effectiveGasReward = tx.gasPrice
|
|
982
|
+
effectiveGasReward = tx.gasPrice - baseFeePerGas;
|
|
951
983
|
}
|
|
952
984
|
return {
|
|
953
985
|
effectiveGasReward,
|
|
954
|
-
gasUsed: (0, base_types_1.
|
|
986
|
+
gasUsed: (0, base_types_1.rpcQuantityToBigInt)(r?.gasUsed),
|
|
955
987
|
};
|
|
956
988
|
})
|
|
957
|
-
.sort((a, b) =>
|
|
989
|
+
.sort((a, b) => bigint_1.BigIntUtils.cmp(a.effectiveGasReward, b.effectiveGasReward));
|
|
958
990
|
return rewardPercentiles.map((p) => {
|
|
959
|
-
let gasUsed =
|
|
960
|
-
const targetGas = block.header.gasLimit
|
|
961
|
-
|
|
962
|
-
.divn(100 * FLOATS_PRECISION);
|
|
991
|
+
let gasUsed = 0n;
|
|
992
|
+
const targetGas = (block.header.gasLimit * BigInt(Math.ceil(p * FLOATS_PRECISION))) /
|
|
993
|
+
BigInt(100 * FLOATS_PRECISION);
|
|
963
994
|
for (const values of effectiveGasRewardAndGas) {
|
|
964
|
-
gasUsed
|
|
965
|
-
if (targetGas
|
|
995
|
+
gasUsed += values.gasUsed;
|
|
996
|
+
if (targetGas <= gasUsed) {
|
|
966
997
|
return values.effectiveGasReward;
|
|
967
998
|
}
|
|
968
999
|
}
|
|
@@ -973,7 +1004,7 @@ Hardhat Network's forking functionality only works with blocks from at least spu
|
|
|
973
1004
|
async _addPendingTransaction(tx) {
|
|
974
1005
|
await this._txPool.addTransaction(tx);
|
|
975
1006
|
await this._notifyPendingTransaction(tx);
|
|
976
|
-
return (0,
|
|
1007
|
+
return (0, util_1.bufferToHex)(tx.hash());
|
|
977
1008
|
}
|
|
978
1009
|
async _mineTransaction(tx) {
|
|
979
1010
|
await this._addPendingTransaction(tx);
|
|
@@ -1037,29 +1068,29 @@ Hardhat Network's forking functionality only works with blocks from at least spu
|
|
|
1037
1068
|
}
|
|
1038
1069
|
// validate nonce
|
|
1039
1070
|
const nextPendingNonce = await this._txPool.getNextPendingNonce(sender);
|
|
1040
|
-
const txNonce =
|
|
1071
|
+
const txNonce = tx.nonce;
|
|
1041
1072
|
const expectedNonceMsg = `Expected nonce to be ${nextPendingNonce.toString()} but got ${txNonce.toString()}.`;
|
|
1042
|
-
if (txNonce
|
|
1073
|
+
if (txNonce > nextPendingNonce) {
|
|
1043
1074
|
throw new errors_2.InvalidInputError(`Nonce too high. ${expectedNonceMsg} Note that transactions can't be queued when automining.`);
|
|
1044
1075
|
}
|
|
1045
|
-
if (txNonce
|
|
1076
|
+
if (txNonce < nextPendingNonce) {
|
|
1046
1077
|
throw new errors_2.InvalidInputError(`Nonce too low. ${expectedNonceMsg}`);
|
|
1047
1078
|
}
|
|
1048
1079
|
// validate gas price
|
|
1049
|
-
const txPriorityFee =
|
|
1050
|
-
if (txPriorityFee
|
|
1080
|
+
const txPriorityFee = "gasPrice" in tx ? tx.gasPrice : tx.maxPriorityFeePerGas;
|
|
1081
|
+
if (txPriorityFee < this._minGasPrice) {
|
|
1051
1082
|
throw new errors_2.InvalidInputError(`Transaction gas price is ${txPriorityFee.toString()}, which is below the minimum of ${this._minGasPrice.toString()}`);
|
|
1052
1083
|
}
|
|
1053
1084
|
// Validate that maxFeePerGas >= next block's baseFee
|
|
1054
1085
|
const nextBlockGasFee = await this.getNextBlockBaseFeePerGas();
|
|
1055
1086
|
if (nextBlockGasFee !== undefined) {
|
|
1056
1087
|
if ("maxFeePerGas" in tx) {
|
|
1057
|
-
if (nextBlockGasFee
|
|
1088
|
+
if (nextBlockGasFee > tx.maxFeePerGas) {
|
|
1058
1089
|
throw new errors_2.InvalidInputError(`Transaction maxFeePerGas (${tx.maxFeePerGas.toString()}) is too low for the next block, which has a baseFeePerGas of ${nextBlockGasFee.toString()}`);
|
|
1059
1090
|
}
|
|
1060
1091
|
}
|
|
1061
1092
|
else {
|
|
1062
|
-
if (nextBlockGasFee
|
|
1093
|
+
if (nextBlockGasFee > tx.gasPrice) {
|
|
1063
1094
|
throw new errors_2.InvalidInputError(`Transaction gasPrice (${tx.gasPrice.toString()}) is too low for the next block, which has a baseFeePerGas of ${nextBlockGasFee.toString()}`);
|
|
1064
1095
|
}
|
|
1065
1096
|
}
|
|
@@ -1076,9 +1107,14 @@ Hardhat Network's forking functionality only works with blocks from at least spu
|
|
|
1076
1107
|
const headerData = {
|
|
1077
1108
|
gasLimit: this.getBlockGasLimit(),
|
|
1078
1109
|
coinbase: this.getCoinbaseAddress(),
|
|
1079
|
-
nonce:
|
|
1110
|
+
nonce: this.isPostMergeHardfork()
|
|
1111
|
+
? "0x0000000000000000"
|
|
1112
|
+
: "0x0000000000000042",
|
|
1080
1113
|
timestamp: blockTimestamp,
|
|
1081
1114
|
};
|
|
1115
|
+
if (this.isPostMergeHardfork()) {
|
|
1116
|
+
headerData.mixHash = this._getNextMixHash();
|
|
1117
|
+
}
|
|
1082
1118
|
headerData.baseFeePerGas = await this.getNextBlockBaseFeePerGas();
|
|
1083
1119
|
const blockBuilder = await this._vm.buildBlock({
|
|
1084
1120
|
parentBlock,
|
|
@@ -1094,10 +1130,10 @@ Hardhat Network's forking functionality only works with blocks from at least spu
|
|
|
1094
1130
|
let tx = transactionQueue.getNextTransaction();
|
|
1095
1131
|
const results = [];
|
|
1096
1132
|
const receipts = [];
|
|
1097
|
-
while (blockGasLimit
|
|
1133
|
+
while (blockGasLimit - blockBuilder.gasUsed >= minTxFee &&
|
|
1098
1134
|
tx !== undefined) {
|
|
1099
1135
|
if (!this._isTxMinable(tx, headerData.baseFeePerGas) ||
|
|
1100
|
-
tx.gasLimit
|
|
1136
|
+
tx.gasLimit > blockGasLimit - blockBuilder.gasUsed) {
|
|
1101
1137
|
transactionQueue.removeLastSenderTransactions();
|
|
1102
1138
|
}
|
|
1103
1139
|
else {
|
|
@@ -1116,7 +1152,7 @@ Hardhat Network's forking functionality only works with blocks from at least spu
|
|
|
1116
1152
|
results,
|
|
1117
1153
|
receipts,
|
|
1118
1154
|
stateRoot: block.header.stateRoot,
|
|
1119
|
-
logsBloom: block.header.
|
|
1155
|
+
logsBloom: block.header.logsBloom,
|
|
1120
1156
|
receiptRoot: block.header.receiptTrie,
|
|
1121
1157
|
gasUsed: block.header.gasUsed,
|
|
1122
1158
|
},
|
|
@@ -1130,10 +1166,10 @@ Hardhat Network's forking functionality only works with blocks from at least spu
|
|
|
1130
1166
|
}
|
|
1131
1167
|
_getMinimalTransactionFee() {
|
|
1132
1168
|
// Typically 21_000 gas
|
|
1133
|
-
return
|
|
1169
|
+
return this._vm._common.param("gasPrices", "tx");
|
|
1134
1170
|
}
|
|
1135
1171
|
async _getFakeTransaction(txParams) {
|
|
1136
|
-
const sender = new
|
|
1172
|
+
const sender = new util_1.Address(txParams.from);
|
|
1137
1173
|
if ("maxFeePerGas" in txParams && txParams.maxFeePerGas !== undefined) {
|
|
1138
1174
|
return new FakeSenderEIP1559Transaction_1.FakeSenderEIP1559Transaction(sender, txParams, {
|
|
1139
1175
|
common: this._vm._common,
|
|
@@ -1168,9 +1204,9 @@ Hardhat Network's forking functionality only works with blocks from at least spu
|
|
|
1168
1204
|
this._snapshots.splice(snapshotIndex);
|
|
1169
1205
|
}
|
|
1170
1206
|
_initLocalAccounts(genesisAccounts) {
|
|
1171
|
-
const privateKeys = genesisAccounts.map((acc) => (0,
|
|
1207
|
+
const privateKeys = genesisAccounts.map((acc) => (0, util_1.toBuffer)(acc.privateKey));
|
|
1172
1208
|
for (const pk of privateKeys) {
|
|
1173
|
-
this._localAccounts.set((0,
|
|
1209
|
+
this._localAccounts.set((0, util_1.bufferToHex)((0, util_1.privateToAddress)(pk)), pk);
|
|
1174
1210
|
}
|
|
1175
1211
|
}
|
|
1176
1212
|
async _getConsoleLogMessages(vmTrace, vmTracerError) {
|
|
@@ -1221,7 +1257,7 @@ Hardhat Network's forking functionality only works with blocks from at least spu
|
|
|
1221
1257
|
returnDataExplanation = `with reason "${returnData.decodeError()}"`;
|
|
1222
1258
|
}
|
|
1223
1259
|
else if (returnData.isPanicReturnData()) {
|
|
1224
|
-
const panicCode = returnData.decodePanic().toString(
|
|
1260
|
+
const panicCode = returnData.decodePanic().toString(16);
|
|
1225
1261
|
returnDataExplanation = `with panic code "0x${panicCode}"`;
|
|
1226
1262
|
}
|
|
1227
1263
|
else {
|
|
@@ -1247,14 +1283,14 @@ Hardhat Network's forking functionality only works with blocks from at least spu
|
|
|
1247
1283
|
_calculateTimestampAndOffset(timestamp) {
|
|
1248
1284
|
let blockTimestamp;
|
|
1249
1285
|
let offsetShouldChange;
|
|
1250
|
-
let newOffset =
|
|
1251
|
-
const currentTimestamp =
|
|
1286
|
+
let newOffset = 0n;
|
|
1287
|
+
const currentTimestamp = BigInt((0, getCurrentTimestamp_1.getCurrentTimestamp)());
|
|
1252
1288
|
// if timestamp is not provided, we check nextBlockTimestamp, if it is
|
|
1253
1289
|
// set, we use it as the timestamp instead. If it is not set, we use
|
|
1254
1290
|
// time offset + real time as the timestamp.
|
|
1255
|
-
if (timestamp === undefined || timestamp
|
|
1256
|
-
if (this.getNextBlockTimestamp()
|
|
1257
|
-
blockTimestamp = currentTimestamp
|
|
1291
|
+
if (timestamp === undefined || timestamp === 0n) {
|
|
1292
|
+
if (this.getNextBlockTimestamp() === 0n) {
|
|
1293
|
+
blockTimestamp = currentTimestamp + this.getTimeIncrement();
|
|
1258
1294
|
offsetShouldChange = false;
|
|
1259
1295
|
}
|
|
1260
1296
|
else {
|
|
@@ -1267,17 +1303,17 @@ Hardhat Network's forking functionality only works with blocks from at least spu
|
|
|
1267
1303
|
blockTimestamp = timestamp;
|
|
1268
1304
|
}
|
|
1269
1305
|
if (offsetShouldChange) {
|
|
1270
|
-
newOffset = blockTimestamp
|
|
1306
|
+
newOffset = blockTimestamp - currentTimestamp;
|
|
1271
1307
|
}
|
|
1272
1308
|
return [blockTimestamp, offsetShouldChange, newOffset];
|
|
1273
1309
|
}
|
|
1274
1310
|
_resetNextBlockTimestamp() {
|
|
1275
|
-
this.setNextBlockTimestamp(
|
|
1311
|
+
this.setNextBlockTimestamp(0n);
|
|
1276
1312
|
}
|
|
1277
1313
|
async _notifyPendingTransaction(tx) {
|
|
1278
1314
|
this._filters.forEach((filter) => {
|
|
1279
1315
|
if (filter.type === filter_1.Type.PENDING_TRANSACTION_SUBSCRIPTION) {
|
|
1280
|
-
const hash = (0,
|
|
1316
|
+
const hash = (0, util_1.bufferToHex)(tx.hash());
|
|
1281
1317
|
if (filter.subscription) {
|
|
1282
1318
|
this._emitEthEvent(filter.id, hash);
|
|
1283
1319
|
return;
|
|
@@ -1316,10 +1352,10 @@ Hardhat Network's forking functionality only works with blocks from at least spu
|
|
|
1316
1352
|
this._emitEthEvent(filter.id, (0, output_1.getRpcBlock)(block, td, (0, output_1.shouldShowTransactionTypeForHardfork)(this._vm._common), false));
|
|
1317
1353
|
return;
|
|
1318
1354
|
}
|
|
1319
|
-
filter.hashes.push((0,
|
|
1355
|
+
filter.hashes.push((0, util_1.bufferToHex)(hash));
|
|
1320
1356
|
break;
|
|
1321
1357
|
case filter_1.Type.LOGS_SUBSCRIPTION:
|
|
1322
|
-
if ((0, filter_1.bloomFilter)(new
|
|
1358
|
+
if ((0, filter_1.bloomFilter)(new vm_1.Bloom(block.header.logsBloom), filter.criteria.addresses, filter.criteria.normalizedTopics)) {
|
|
1323
1359
|
const logs = (0, filter_1.filterLogs)(rpcLogs, filter.criteria);
|
|
1324
1360
|
if (logs.length === 0) {
|
|
1325
1361
|
return;
|
|
@@ -1338,14 +1374,14 @@ Hardhat Network's forking functionality only works with blocks from at least spu
|
|
|
1338
1374
|
}
|
|
1339
1375
|
async _timestampClashesWithPreviousBlockOne(blockTimestamp) {
|
|
1340
1376
|
const latestBlock = await this.getLatestBlock();
|
|
1341
|
-
const latestBlockTimestamp =
|
|
1342
|
-
return latestBlockTimestamp
|
|
1377
|
+
const latestBlockTimestamp = latestBlock.header.timestamp;
|
|
1378
|
+
return latestBlockTimestamp === blockTimestamp;
|
|
1343
1379
|
}
|
|
1344
1380
|
async _runInBlockContext(blockNumberOrPending, action) {
|
|
1345
1381
|
if (blockNumberOrPending === "pending") {
|
|
1346
1382
|
return this._runInPendingBlockContext(action);
|
|
1347
1383
|
}
|
|
1348
|
-
if (blockNumberOrPending
|
|
1384
|
+
if (blockNumberOrPending === this.getLatestBlockNumber()) {
|
|
1349
1385
|
return action();
|
|
1350
1386
|
}
|
|
1351
1387
|
const block = await this.getBlockByNumber(blockNumberOrPending);
|
|
@@ -1373,11 +1409,11 @@ Hardhat Network's forking functionality only works with blocks from at least spu
|
|
|
1373
1409
|
}
|
|
1374
1410
|
}
|
|
1375
1411
|
async _setBlockContext(block) {
|
|
1376
|
-
const irregularStateOrUndefined = this._irregularStatesByBlockNumber.get(block.header.number
|
|
1412
|
+
const irregularStateOrUndefined = this._irregularStatesByBlockNumber.get(block.header.number);
|
|
1377
1413
|
if (this._stateManager instanceof ForkStateManager_1.ForkStateManager) {
|
|
1378
1414
|
return this._stateManager.setBlockContext(block.header.stateRoot, block.header.number, irregularStateOrUndefined);
|
|
1379
1415
|
}
|
|
1380
|
-
return this._stateManager.setStateRoot(irregularStateOrUndefined
|
|
1416
|
+
return this._stateManager.setStateRoot(irregularStateOrUndefined ?? block.header.stateRoot);
|
|
1381
1417
|
}
|
|
1382
1418
|
async _restoreBlockContext(stateRoot) {
|
|
1383
1419
|
if (this._stateManager instanceof ForkStateManager_1.ForkStateManager) {
|
|
@@ -1386,10 +1422,16 @@ Hardhat Network's forking functionality only works with blocks from at least spu
|
|
|
1386
1422
|
return this._stateManager.setStateRoot(stateRoot);
|
|
1387
1423
|
}
|
|
1388
1424
|
async _correctInitialEstimation(blockNumberOrPending, txParams, initialEstimation) {
|
|
1389
|
-
let tx = await this._getFakeTransaction(
|
|
1390
|
-
|
|
1391
|
-
initialEstimation
|
|
1392
|
-
|
|
1425
|
+
let tx = await this._getFakeTransaction({
|
|
1426
|
+
...txParams,
|
|
1427
|
+
gasLimit: initialEstimation,
|
|
1428
|
+
});
|
|
1429
|
+
if (tx.getBaseFee() >= initialEstimation) {
|
|
1430
|
+
initialEstimation = tx.getBaseFee() + 1n;
|
|
1431
|
+
tx = await this._getFakeTransaction({
|
|
1432
|
+
...txParams,
|
|
1433
|
+
gasLimit: initialEstimation,
|
|
1434
|
+
});
|
|
1393
1435
|
}
|
|
1394
1436
|
const result = await this._runInBlockContext(blockNumberOrPending, () => this._runTxAndRevertMutations(tx, blockNumberOrPending));
|
|
1395
1437
|
if (result.execResult.exceptionError === undefined) {
|
|
@@ -1398,40 +1440,43 @@ Hardhat Network's forking functionality only works with blocks from at least spu
|
|
|
1398
1440
|
return this._binarySearchEstimation(blockNumberOrPending, txParams, initialEstimation, this.getBlockGasLimit());
|
|
1399
1441
|
}
|
|
1400
1442
|
async _binarySearchEstimation(blockNumberOrPending, txParams, highestFailingEstimation, lowestSuccessfulEstimation, roundNumber = 0) {
|
|
1401
|
-
if (lowestSuccessfulEstimation
|
|
1443
|
+
if (lowestSuccessfulEstimation <= highestFailingEstimation) {
|
|
1402
1444
|
// This shouldn't happen, but we don't want to go into an infinite loop
|
|
1403
1445
|
// if it ever happens
|
|
1404
1446
|
return lowestSuccessfulEstimation;
|
|
1405
1447
|
}
|
|
1406
1448
|
const MAX_GAS_ESTIMATION_IMPROVEMENT_ROUNDS = 20;
|
|
1407
|
-
const diff = lowestSuccessfulEstimation
|
|
1408
|
-
const minDiff = highestFailingEstimation
|
|
1449
|
+
const diff = lowestSuccessfulEstimation - highestFailingEstimation;
|
|
1450
|
+
const minDiff = highestFailingEstimation >= 4000000n
|
|
1409
1451
|
? 50000
|
|
1410
|
-
: highestFailingEstimation
|
|
1452
|
+
: highestFailingEstimation >= 1000000n
|
|
1411
1453
|
? 10000
|
|
1412
|
-
: highestFailingEstimation
|
|
1454
|
+
: highestFailingEstimation >= 100000n
|
|
1413
1455
|
? 1000
|
|
1414
|
-
: highestFailingEstimation
|
|
1456
|
+
: highestFailingEstimation >= 50000n
|
|
1415
1457
|
? 500
|
|
1416
|
-
: highestFailingEstimation
|
|
1458
|
+
: highestFailingEstimation >= 30000n
|
|
1417
1459
|
? 300
|
|
1418
1460
|
: 200;
|
|
1419
|
-
if (diff
|
|
1461
|
+
if (diff <= minDiff) {
|
|
1420
1462
|
return lowestSuccessfulEstimation;
|
|
1421
1463
|
}
|
|
1422
1464
|
if (roundNumber > MAX_GAS_ESTIMATION_IMPROVEMENT_ROUNDS) {
|
|
1423
1465
|
return lowestSuccessfulEstimation;
|
|
1424
1466
|
}
|
|
1425
|
-
const binSearchNewEstimation = highestFailingEstimation
|
|
1467
|
+
const binSearchNewEstimation = highestFailingEstimation + diff / 2n;
|
|
1426
1468
|
const optimizedEstimation = roundNumber === 0
|
|
1427
|
-
? highestFailingEstimation
|
|
1469
|
+
? 3n * highestFailingEstimation
|
|
1428
1470
|
: binSearchNewEstimation;
|
|
1429
|
-
const newEstimation = optimizedEstimation
|
|
1471
|
+
const newEstimation = optimizedEstimation > binSearchNewEstimation
|
|
1430
1472
|
? binSearchNewEstimation
|
|
1431
1473
|
: optimizedEstimation;
|
|
1432
1474
|
// Let other things execute
|
|
1433
1475
|
await new Promise((resolve) => setImmediate(resolve));
|
|
1434
|
-
const tx = await this._getFakeTransaction(
|
|
1476
|
+
const tx = await this._getFakeTransaction({
|
|
1477
|
+
...txParams,
|
|
1478
|
+
gasLimit: newEstimation,
|
|
1479
|
+
});
|
|
1435
1480
|
const result = await this._runInBlockContext(blockNumberOrPending, () => this._runTxAndRevertMutations(tx, blockNumberOrPending));
|
|
1436
1481
|
if (result.execResult.exceptionError === undefined) {
|
|
1437
1482
|
return this._binarySearchEstimation(blockNumberOrPending, txParams, highestFailingEstimation, newEstimation, roundNumber + 1);
|
|
@@ -1443,7 +1488,6 @@ Hardhat Network's forking functionality only works with blocks from at least spu
|
|
|
1443
1488
|
* makes.
|
|
1444
1489
|
*/
|
|
1445
1490
|
async _runTxAndRevertMutations(tx, blockNumberOrPending, forceBaseFeeZero = false) {
|
|
1446
|
-
var _a;
|
|
1447
1491
|
const initialStateRoot = await this._stateManager.getStateRoot();
|
|
1448
1492
|
let blockContext;
|
|
1449
1493
|
let originalCommon;
|
|
@@ -1461,7 +1505,7 @@ Hardhat Network's forking functionality only works with blocks from at least spu
|
|
|
1461
1505
|
// we don't need to add the tx to the block because runTx doesn't
|
|
1462
1506
|
// know anything about the txs in the current block
|
|
1463
1507
|
}
|
|
1464
|
-
// NOTE: This is a workaround of both an @
|
|
1508
|
+
// NOTE: This is a workaround of both an @ignored/vm limitation, and
|
|
1465
1509
|
// a bug in Hardhat Network.
|
|
1466
1510
|
//
|
|
1467
1511
|
// See: https://github.com/nomiclabs/hardhat/issues/1666
|
|
@@ -1480,14 +1524,16 @@ Hardhat Network's forking functionality only works with blocks from at least spu
|
|
|
1480
1524
|
freeze: false,
|
|
1481
1525
|
common: this._vm._common,
|
|
1482
1526
|
});
|
|
1483
|
-
blockContext.header.baseFeePerGas =
|
|
1527
|
+
blockContext.header.baseFeePerGas = 0n;
|
|
1484
1528
|
}
|
|
1485
1529
|
originalCommon = this._vm._common;
|
|
1486
|
-
this._vm._common =
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1530
|
+
this._vm._common = common_1.Common.custom({
|
|
1531
|
+
chainId: this._forkBlockNumber === undefined ||
|
|
1532
|
+
blockContext.header.number >= this._forkBlockNumber
|
|
1533
|
+
? this._configChainId
|
|
1534
|
+
: this._forkNetworkId,
|
|
1535
|
+
networkId: this._forkNetworkId ?? this._configNetworkId,
|
|
1536
|
+
}, {
|
|
1491
1537
|
hardfork: this._selectHardfork(blockContext.header.number),
|
|
1492
1538
|
});
|
|
1493
1539
|
return await this._vm.runTx({
|
|
@@ -1507,17 +1553,17 @@ Hardhat Network's forking functionality only works with blocks from at least spu
|
|
|
1507
1553
|
}
|
|
1508
1554
|
async _computeFilterParams(filterParams, isFilter) {
|
|
1509
1555
|
const latestBlockNumber = this.getLatestBlockNumber();
|
|
1510
|
-
const newFilterParams =
|
|
1556
|
+
const newFilterParams = { ...filterParams };
|
|
1511
1557
|
if (newFilterParams.fromBlock === filter_1.LATEST_BLOCK) {
|
|
1512
1558
|
newFilterParams.fromBlock = latestBlockNumber;
|
|
1513
1559
|
}
|
|
1514
1560
|
if (!isFilter && newFilterParams.toBlock === filter_1.LATEST_BLOCK) {
|
|
1515
1561
|
newFilterParams.toBlock = latestBlockNumber;
|
|
1516
1562
|
}
|
|
1517
|
-
if (newFilterParams.toBlock
|
|
1563
|
+
if (newFilterParams.toBlock > latestBlockNumber) {
|
|
1518
1564
|
newFilterParams.toBlock = latestBlockNumber;
|
|
1519
1565
|
}
|
|
1520
|
-
if (newFilterParams.fromBlock
|
|
1566
|
+
if (newFilterParams.fromBlock > latestBlockNumber) {
|
|
1521
1567
|
newFilterParams.fromBlock = latestBlockNumber;
|
|
1522
1568
|
}
|
|
1523
1569
|
return newFilterParams;
|
|
@@ -1528,7 +1574,7 @@ Hardhat Network's forking functionality only works with blocks from at least spu
|
|
|
1528
1574
|
return dt;
|
|
1529
1575
|
}
|
|
1530
1576
|
_getNextFilterId() {
|
|
1531
|
-
this._lastFilterId
|
|
1577
|
+
this._lastFilterId++;
|
|
1532
1578
|
return this._lastFilterId;
|
|
1533
1579
|
}
|
|
1534
1580
|
_filterIdToFiltersKey(filterId) {
|
|
@@ -1556,13 +1602,13 @@ Hardhat Network's forking functionality only works with blocks from at least spu
|
|
|
1556
1602
|
_isTxMinable(tx, nextBlockBaseFeePerGas) {
|
|
1557
1603
|
const txMaxFee = "gasPrice" in tx ? tx.gasPrice : tx.maxFeePerGas;
|
|
1558
1604
|
const canPayBaseFee = nextBlockBaseFeePerGas !== undefined
|
|
1559
|
-
? txMaxFee
|
|
1605
|
+
? txMaxFee >= nextBlockBaseFeePerGas
|
|
1560
1606
|
: true;
|
|
1561
|
-
const atLeastMinGasPrice = txMaxFee
|
|
1607
|
+
const atLeastMinGasPrice = txMaxFee >= this._minGasPrice;
|
|
1562
1608
|
return canPayBaseFee && atLeastMinGasPrice;
|
|
1563
1609
|
}
|
|
1564
1610
|
async _persistIrregularWorldState() {
|
|
1565
|
-
this._irregularStatesByBlockNumber.set(this.getLatestBlockNumber()
|
|
1611
|
+
this._irregularStatesByBlockNumber.set(this.getLatestBlockNumber(), await this._stateManager.getStateRoot());
|
|
1566
1612
|
}
|
|
1567
1613
|
isEip1559Active(blockNumberOrPending) {
|
|
1568
1614
|
if (blockNumberOrPending !== undefined &&
|
|
@@ -1571,35 +1617,41 @@ Hardhat Network's forking functionality only works with blocks from at least spu
|
|
|
1571
1617
|
}
|
|
1572
1618
|
return this._vm._common.gteHardfork("london");
|
|
1573
1619
|
}
|
|
1620
|
+
isPostMergeHardfork() {
|
|
1621
|
+
return (0, hardforks_1.hardforkGte)(this.hardfork, hardforks_1.HardforkName.MERGE);
|
|
1622
|
+
}
|
|
1623
|
+
_getNextMixHash() {
|
|
1624
|
+
return this._mixHashGenerator.next();
|
|
1625
|
+
}
|
|
1574
1626
|
async _getEstimateGasFeePriceFields(callParams, blockNumberOrPending) {
|
|
1575
|
-
var _a, _b;
|
|
1576
1627
|
if (!this.isEip1559Active(blockNumberOrPending) ||
|
|
1577
1628
|
callParams.gasPrice !== undefined) {
|
|
1578
|
-
return { gasPrice:
|
|
1629
|
+
return { gasPrice: callParams.gasPrice ?? (await this.getGasPrice()) };
|
|
1579
1630
|
}
|
|
1580
1631
|
let maxFeePerGas = callParams.maxFeePerGas;
|
|
1581
1632
|
let maxPriorityFeePerGas = callParams.maxPriorityFeePerGas;
|
|
1582
1633
|
if (maxPriorityFeePerGas === undefined) {
|
|
1583
1634
|
maxPriorityFeePerGas = await this.getMaxPriorityFeePerGas();
|
|
1584
|
-
if (maxFeePerGas !== undefined && maxFeePerGas
|
|
1635
|
+
if (maxFeePerGas !== undefined && maxFeePerGas < maxPriorityFeePerGas) {
|
|
1585
1636
|
maxPriorityFeePerGas = maxFeePerGas;
|
|
1586
1637
|
}
|
|
1587
1638
|
}
|
|
1588
1639
|
if (maxFeePerGas === undefined) {
|
|
1589
1640
|
if (blockNumberOrPending === "pending") {
|
|
1590
1641
|
const baseFeePerGas = await this.getNextBlockBaseFeePerGas();
|
|
1591
|
-
maxFeePerGas = baseFeePerGas
|
|
1642
|
+
maxFeePerGas = 2n * baseFeePerGas + maxPriorityFeePerGas;
|
|
1592
1643
|
}
|
|
1593
1644
|
else {
|
|
1594
1645
|
const block = await this.getBlockByNumber(blockNumberOrPending);
|
|
1595
|
-
maxFeePerGas =
|
|
1646
|
+
maxFeePerGas =
|
|
1647
|
+
maxPriorityFeePerGas + (block.header.baseFeePerGas ?? 0n);
|
|
1596
1648
|
}
|
|
1597
1649
|
}
|
|
1598
1650
|
return { maxFeePerGas, maxPriorityFeePerGas };
|
|
1599
1651
|
}
|
|
1600
1652
|
_selectHardfork(blockNumber) {
|
|
1601
1653
|
if (this._forkBlockNumber === undefined ||
|
|
1602
|
-
blockNumber
|
|
1654
|
+
blockNumber >= this._forkBlockNumber) {
|
|
1603
1655
|
return this._vm._common.hardfork();
|
|
1604
1656
|
}
|
|
1605
1657
|
if (this._hardforkActivations.size === 0) {
|
|
@@ -1609,10 +1661,10 @@ Hardhat Network's forking functionality only works with blocks from at least spu
|
|
|
1609
1661
|
* isn't higher than blockNumber, and then return that found block number's
|
|
1610
1662
|
* associated hardfork name. */
|
|
1611
1663
|
const hardforkHistory = Array.from(this._hardforkActivations.entries());
|
|
1612
|
-
const [hardfork, activationBlock] = hardforkHistory.reduce(([highestHardfork, highestBlock], [thisHardfork, thisBlock]) => thisBlock > highestBlock &&
|
|
1664
|
+
const [hardfork, activationBlock] = hardforkHistory.reduce(([highestHardfork, highestBlock], [thisHardfork, thisBlock]) => thisBlock > highestBlock && thisBlock <= blockNumber
|
|
1613
1665
|
? [thisHardfork, thisBlock]
|
|
1614
1666
|
: [highestHardfork, highestBlock]);
|
|
1615
|
-
if (hardfork === undefined || blockNumber
|
|
1667
|
+
if (hardfork === undefined || blockNumber < activationBlock) {
|
|
1616
1668
|
throw new errors_2.InternalError(`Could not find a hardfork to run for block ${blockNumber.toString()}, after having looked for one in the HardhatNode's hardfork activation history, which was: ${JSON.stringify(hardforkHistory)}. For more information, see https://hardhat.org/hardhat-network/reference/#config`);
|
|
1617
1669
|
}
|
|
1618
1670
|
if (!constants_1.HARDHAT_NETWORK_SUPPORTED_HARDFORKS.includes(hardfork)) {
|
|
@@ -1622,13 +1674,15 @@ Hardhat Network's forking functionality only works with blocks from at least spu
|
|
|
1622
1674
|
}
|
|
1623
1675
|
_getCommonForTracing(networkId, blockNumber) {
|
|
1624
1676
|
try {
|
|
1625
|
-
const common =
|
|
1626
|
-
|
|
1627
|
-
|
|
1677
|
+
const common = common_1.Common.custom({
|
|
1678
|
+
chainId: networkId,
|
|
1679
|
+
networkId,
|
|
1680
|
+
}, {
|
|
1681
|
+
hardfork: this._selectHardfork(BigInt(blockNumber)),
|
|
1628
1682
|
});
|
|
1629
1683
|
return common;
|
|
1630
1684
|
}
|
|
1631
|
-
catch
|
|
1685
|
+
catch {
|
|
1632
1686
|
throw new errors_2.InternalError(`Network id ${networkId} does not correspond to a network that Hardhat can trace`);
|
|
1633
1687
|
}
|
|
1634
1688
|
}
|