From 67bccb55663237786ff0456fb048041099c3a6ae Mon Sep 17 00:00:00 2001 From: Patricio Palladino Date: Mon, 22 Feb 2021 17:44:39 -0300 Subject: [PATCH 1/2] Fix race condition in HH Net's jsonrpc client --- .../src/internal/hardhat-network/jsonrpc/client.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/packages/hardhat-core/src/internal/hardhat-network/jsonrpc/client.ts b/packages/hardhat-core/src/internal/hardhat-network/jsonrpc/client.ts index e8da6b9ec9..a148437822 100644 --- a/packages/hardhat-core/src/internal/hardhat-network/jsonrpc/client.ts +++ b/packages/hardhat-core/src/internal/hardhat-network/jsonrpc/client.ts @@ -22,7 +22,6 @@ import { export class JsonRpcClient { private _cache: Map = new Map(); - private _scopedForkCacheFolderCreated?: boolean; constructor( private _httpProvider: HttpProvider, @@ -429,11 +428,7 @@ export class JsonRpcClient { ) { const requestPath = this._getDiskCachePathForKey(forkCachePath, cacheKey); - if (this._scopedForkCacheFolderCreated !== true) { - this._scopedForkCacheFolderCreated = true; - await fsExtra.ensureDir(path.dirname(requestPath)); - } - + await fsExtra.ensureDir(path.dirname(requestPath)); await fsExtra.writeJSON(requestPath, rawResult, { encoding: "utf8", }); From c6f8cdbb59aba576d514af7537f78797c57cf2a4 Mon Sep 17 00:00:00 2001 From: Patricio Palladino Date: Mon, 22 Feb 2021 17:51:08 -0300 Subject: [PATCH 2/2] Don't treat internal VM errors as reverts --- .../src/internal/hardhat-network/provider/node.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/hardhat-core/src/internal/hardhat-network/provider/node.ts b/packages/hardhat-core/src/internal/hardhat-network/provider/node.ts index 85df620c1b..3936d87a31 100644 --- a/packages/hardhat-core/src/internal/hardhat-network/provider/node.ts +++ b/packages/hardhat-core/src/internal/hardhat-network/provider/node.ts @@ -1,7 +1,7 @@ import VM from "@nomiclabs/ethereumjs-vm"; import Bloom from "@nomiclabs/ethereumjs-vm/dist/bloom"; import { EVMResult, ExecResult } from "@nomiclabs/ethereumjs-vm/dist/evm/evm"; -import { ERROR } from "@nomiclabs/ethereumjs-vm/dist/exceptions"; +import { ERROR, VmError } from "@nomiclabs/ethereumjs-vm/dist/exceptions"; import { RunBlockResult } from "@nomiclabs/ethereumjs-vm/dist/runBlock"; import { StateManager } from "@nomiclabs/ethereumjs-vm/dist/state"; import chalk from "chalk"; @@ -931,6 +931,13 @@ export class HardhatNode extends EventEmitter { const error = vmResult.exceptionError; + // If this is an internal VM error, or a different kind of error was + // thrown, we just rethrow. An example of a non-VmError being thrown here + // is an HTTP error coming from the ForkedStateManager. + if (!(error instanceof VmError) || error.error === ERROR.INTERNAL_ERROR) { + throw error; + } + if (error.error === ERROR.OUT_OF_GAS) { if (this._isContractTooLargeStackTrace(stackTrace)) { return encodeSolidityStackTrace(