diff --git a/packages/hardhat-core/src/internal/hardhat-network/provider/provider.ts b/packages/hardhat-core/src/internal/hardhat-network/provider/provider.ts index 18f24aea8a..3dda0ab27f 100644 --- a/packages/hardhat-core/src/internal/hardhat-network/provider/provider.ts +++ b/packages/hardhat-core/src/internal/hardhat-network/provider/provider.ts @@ -83,14 +83,18 @@ export const DEFAULT_COINBASE = "0xc014ba5ec014ba5ec014ba5ec014ba5ec014ba5e"; let _globalEdrContext: EdrContext | undefined; // Lazy initialize the global EDR context. -export function getGlobalEdrContext(): EdrContext { - const { EdrContext } = requireNapiRsModule( +export async function getGlobalEdrContext(): Promise { + const { EdrContext, L1_CHAIN_TYPE, l1ProviderFactory } = requireNapiRsModule( "@nomicfoundation/edr" ) as typeof import("@nomicfoundation/edr"); if (_globalEdrContext === undefined) { // Only one is allowed to exist _globalEdrContext = new EdrContext(); + await _globalEdrContext.registerProviderFactory( + L1_CHAIN_TYPE, + l1ProviderFactory() + ); } return _globalEdrContext; @@ -192,7 +196,7 @@ export class EdrProviderWrapper loggerConfig: LoggerConfig, tracingConfig?: TracingConfig ): Promise { - const { Provider } = requireNapiRsModule( + const { L1_CHAIN_TYPE } = requireNapiRsModule( "@nomicfoundation/edr" ) as typeof import("@nomicfoundation/edr"); @@ -226,8 +230,9 @@ export class EdrProviderWrapper const hardforkName = getHardforkName(config.hardfork); - const provider = await Provider.withConfig( - getGlobalEdrContext(), + const context = await getGlobalEdrContext(); + const provider = await context.createProvider( + L1_CHAIN_TYPE, { allowBlocksWithSameTimestamp: config.allowBlocksWithSameTimestamp ?? false, @@ -298,8 +303,10 @@ export class EdrProviderWrapper } }, }, - (event: SubscriptionEvent) => { - eventAdapter.emit("ethEvent", event); + { + subscriptionCallback: (event: SubscriptionEvent) => { + eventAdapter.emit("ethEvent", event); + }, } ); @@ -479,18 +486,20 @@ export class EdrProviderWrapper } // temporarily added to make smock work with HH+EDR - private _setCallOverrideCallback(callback: CallOverrideCallback) { + private async _setCallOverrideCallback( + callback: CallOverrideCallback + ): Promise { this._callOverrideCallback = callback; - this._provider.setCallOverrideCallback( + await this._provider.setCallOverrideCallback( async (address: Buffer, data: Buffer) => { return this._callOverrideCallback?.(address, data); } ); } - private _setVerboseTracing(enabled: boolean) { - this._provider.setVerboseTracing(enabled); + private async _setVerboseTracing(enabled: boolean): Promise { + await this._provider.setVerboseTracing(enabled); } private _ethEventListener(event: SubscriptionEvent) { diff --git a/packages/hardhat-core/src/internal/hardhat-network/provider/utils/convertToEdr.ts b/packages/hardhat-core/src/internal/hardhat-network/provider/utils/convertToEdr.ts index a955ef1225..702b9e9ca9 100644 --- a/packages/hardhat-core/src/internal/hardhat-network/provider/utils/convertToEdr.ts +++ b/packages/hardhat-core/src/internal/hardhat-network/provider/utils/convertToEdr.ts @@ -1,11 +1,28 @@ -import type { - SpecId, - MineOrdering, - IntervalRange, - DebugTraceResult, - TracingMessage, - TracingMessageResult, - TracingStep, +import { + type SpecId, + type MineOrdering, + type IntervalRange, + type DebugTraceResult, + type TracingMessage, + type TracingMessageResult, + type TracingStep, + FRONTIER, + HOMESTEAD, + DAO_FORK, + TANGERINE, + SPURIOUS_DRAGON, + BYZANTIUM, + CONSTANTINOPLE, + PETERSBURG, + ISTANBUL, + MUIR_GLACIER, + BERLIN, + LONDON, + ARROW_GLACIER, + GRAY_GLACIER, + MERGE, + SHANGHAI, + CANCUN, } from "@nomicfoundation/edr"; import { Address } from "@nomicfoundation/ethereumjs-util"; @@ -21,46 +38,42 @@ import { /* eslint-disable @nomicfoundation/hardhat-internal-rules/only-hardhat-error */ -export function ethereumsjsHardforkToEdrSpecId(hardfork: HardforkName): SpecId { - const { SpecId } = requireNapiRsModule( - "@nomicfoundation/edr" - ) as typeof import("@nomicfoundation/edr"); - +export function ethereumsjsHardforkToEdrSpecId(hardfork: HardforkName): string { switch (hardfork) { case HardforkName.FRONTIER: - return SpecId.Frontier; + return FRONTIER; case HardforkName.HOMESTEAD: - return SpecId.Homestead; + return HOMESTEAD; case HardforkName.DAO: - return SpecId.DaoFork; + return DAO_FORK; case HardforkName.TANGERINE_WHISTLE: - return SpecId.Tangerine; + return TANGERINE; case HardforkName.SPURIOUS_DRAGON: - return SpecId.SpuriousDragon; + return SPURIOUS_DRAGON; case HardforkName.BYZANTIUM: - return SpecId.Byzantium; + return BYZANTIUM; case HardforkName.CONSTANTINOPLE: - return SpecId.Constantinople; + return CONSTANTINOPLE; case HardforkName.PETERSBURG: - return SpecId.Petersburg; + return PETERSBURG; case HardforkName.ISTANBUL: - return SpecId.Istanbul; + return ISTANBUL; case HardforkName.MUIR_GLACIER: - return SpecId.MuirGlacier; + return MUIR_GLACIER; case HardforkName.BERLIN: - return SpecId.Berlin; + return BERLIN; case HardforkName.LONDON: - return SpecId.London; + return LONDON; case HardforkName.ARROW_GLACIER: - return SpecId.ArrowGlacier; + return ARROW_GLACIER; case HardforkName.GRAY_GLACIER: - return SpecId.GrayGlacier; + return GRAY_GLACIER; case HardforkName.MERGE: - return SpecId.Merge; + return MERGE; case HardforkName.SHANGHAI: - return SpecId.Shanghai; + return SHANGHAI; case HardforkName.CANCUN: - return SpecId.Cancun; + return CANCUN; default: const _exhaustiveCheck: never = hardfork; throw new Error(