Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adopt EDR multichain #5684

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,19 @@ export const DEFAULT_COINBASE = "0xc014ba5ec014ba5ec014ba5ec014ba5ec014ba5e";
let _globalEdrContext: EdrContext | undefined;

// Lazy initialize the global EDR context.
export function getGlobalEdrContext(): EdrContext {
const { EdrContext } = requireNapiRsModule(
"@nomicfoundation/edr"
) as typeof import("@nomicfoundation/edr");
export async function getGlobalEdrContext(): Promise<EdrContext> {
const { EdrContext, GENERIC_CHAIN_TYPE, genericChainProviderFactory } =
requireNapiRsModule(
"@nomicfoundation/edr"
) as typeof import("@nomicfoundation/edr");

if (_globalEdrContext === undefined) {
// Only one is allowed to exist
_globalEdrContext = new EdrContext();
await _globalEdrContext.registerProviderFactory(
GENERIC_CHAIN_TYPE,
genericChainProviderFactory()
);
}

return _globalEdrContext;
Expand Down Expand Up @@ -193,7 +198,7 @@ export class EdrProviderWrapper
loggerConfig: LoggerConfig,
tracingConfig?: TracingConfig
): Promise<EdrProviderWrapper> {
const { Provider } = requireNapiRsModule(
const { GENERIC_CHAIN_TYPE } = requireNapiRsModule(
"@nomicfoundation/edr"
) as typeof import("@nomicfoundation/edr");

Expand Down Expand Up @@ -226,8 +231,9 @@ export class EdrProviderWrapper

const hardforkName = getHardforkName(config.hardfork);

const provider = await Provider.withConfig(
getGlobalEdrContext(),
const context = await getGlobalEdrContext();
const provider = await context.createProvider(
GENERIC_CHAIN_TYPE,
{
allowBlocksWithSameTimestamp:
config.allowBlocksWithSameTimestamp ?? false,
Expand Down Expand Up @@ -298,8 +304,10 @@ export class EdrProviderWrapper
}
},
},
(event: SubscriptionEvent) => {
eventAdapter.emit("ethEvent", event);
{
subscriptionCallback: (event: SubscriptionEvent) => {
eventAdapter.emit("ethEvent", event);
},
}
);

Expand Down Expand Up @@ -476,18 +484,20 @@ export class EdrProviderWrapper
}

// temporarily added to make smock work with HH+EDR
private _setCallOverrideCallback(callback: CallOverrideCallback) {
private async _setCallOverrideCallback(
callback: CallOverrideCallback
): Promise<void> {
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<void> {
await this._provider.setVerboseTracing(enabled);
}

private _ethEventListener(event: SubscriptionEvent) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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,

Check failure on line 9 in packages/hardhat-core/src/internal/hardhat-network/provider/utils/convertToEdr.ts

View workflow job for this annotation

GitHub Actions / Lint

Module '"@nomicfoundation/edr"' has no exported member 'FRONTIER'.
HOMESTEAD,

Check failure on line 10 in packages/hardhat-core/src/internal/hardhat-network/provider/utils/convertToEdr.ts

View workflow job for this annotation

GitHub Actions / Lint

Module '"@nomicfoundation/edr"' has no exported member 'HOMESTEAD'.
DAO_FORK,

Check failure on line 11 in packages/hardhat-core/src/internal/hardhat-network/provider/utils/convertToEdr.ts

View workflow job for this annotation

GitHub Actions / Lint

Module '"@nomicfoundation/edr"' has no exported member 'DAO_FORK'.
TANGERINE,

Check failure on line 12 in packages/hardhat-core/src/internal/hardhat-network/provider/utils/convertToEdr.ts

View workflow job for this annotation

GitHub Actions / Lint

Module '"@nomicfoundation/edr"' has no exported member 'TANGERINE'.
SPURIOUS_DRAGON,

Check failure on line 13 in packages/hardhat-core/src/internal/hardhat-network/provider/utils/convertToEdr.ts

View workflow job for this annotation

GitHub Actions / Lint

Module '"@nomicfoundation/edr"' has no exported member 'SPURIOUS_DRAGON'.
BYZANTIUM,

Check failure on line 14 in packages/hardhat-core/src/internal/hardhat-network/provider/utils/convertToEdr.ts

View workflow job for this annotation

GitHub Actions / Lint

Module '"@nomicfoundation/edr"' has no exported member 'BYZANTIUM'.
CONSTANTINOPLE,

Check failure on line 15 in packages/hardhat-core/src/internal/hardhat-network/provider/utils/convertToEdr.ts

View workflow job for this annotation

GitHub Actions / Lint

Module '"@nomicfoundation/edr"' has no exported member 'CONSTANTINOPLE'.
PETERSBURG,

Check failure on line 16 in packages/hardhat-core/src/internal/hardhat-network/provider/utils/convertToEdr.ts

View workflow job for this annotation

GitHub Actions / Lint

Module '"@nomicfoundation/edr"' has no exported member 'PETERSBURG'.
ISTANBUL,

Check failure on line 17 in packages/hardhat-core/src/internal/hardhat-network/provider/utils/convertToEdr.ts

View workflow job for this annotation

GitHub Actions / Lint

Module '"@nomicfoundation/edr"' has no exported member 'ISTANBUL'.
MUIR_GLACIER,

Check failure on line 18 in packages/hardhat-core/src/internal/hardhat-network/provider/utils/convertToEdr.ts

View workflow job for this annotation

GitHub Actions / Lint

Module '"@nomicfoundation/edr"' has no exported member 'MUIR_GLACIER'.
BERLIN,
LONDON,
ARROW_GLACIER,
GRAY_GLACIER,
MERGE,
SHANGHAI,
CANCUN,
} from "@nomicfoundation/edr";
import { Address } from "@nomicfoundation/ethereumjs-util";

Expand All @@ -21,46 +38,42 @@

/* 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(
Expand Down
Loading