hardhat 2.20.0 → 2.21.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.
Files changed (271) hide show
  1. package/internal/core/jsonrpc/types/input/blockTag.d.ts +3 -3
  2. package/internal/core/jsonrpc/types/input/filterRequest.d.ts +6 -6
  3. package/internal/core/providers/construction.d.ts.map +1 -1
  4. package/internal/core/providers/construction.js +28 -4
  5. package/internal/core/providers/construction.js.map +1 -1
  6. package/internal/core/providers/http.d.ts +2 -0
  7. package/internal/core/providers/http.d.ts.map +1 -1
  8. package/internal/core/providers/http.js +2 -1
  9. package/internal/core/providers/http.js.map +1 -1
  10. package/internal/core/runtime-environment.d.ts.map +1 -1
  11. package/internal/core/runtime-environment.js.map +1 -1
  12. package/internal/hardhat-network/jsonrpc/client.d.ts +0 -2
  13. package/internal/hardhat-network/jsonrpc/client.d.ts.map +1 -1
  14. package/internal/hardhat-network/jsonrpc/client.js +0 -16
  15. package/internal/hardhat-network/jsonrpc/client.js.map +1 -1
  16. package/internal/hardhat-network/jsonrpc/handler.js +9 -1
  17. package/internal/hardhat-network/jsonrpc/handler.js.map +1 -1
  18. package/internal/hardhat-network/provider/BlockchainData.d.ts +5 -5
  19. package/internal/hardhat-network/provider/BlockchainData.d.ts.map +1 -1
  20. package/internal/hardhat-network/provider/BlockchainData.js +10 -10
  21. package/internal/hardhat-network/provider/BlockchainData.js.map +1 -1
  22. package/internal/hardhat-network/provider/HardhatBlockchain.d.ts +0 -7
  23. package/internal/hardhat-network/provider/HardhatBlockchain.d.ts.map +1 -1
  24. package/internal/hardhat-network/provider/HardhatBlockchain.js +2 -14
  25. package/internal/hardhat-network/provider/HardhatBlockchain.js.map +1 -1
  26. package/internal/hardhat-network/provider/TxPool.d.ts +3 -2
  27. package/internal/hardhat-network/provider/TxPool.d.ts.map +1 -1
  28. package/internal/hardhat-network/provider/TxPool.js +16 -16
  29. package/internal/hardhat-network/provider/TxPool.js.map +1 -1
  30. package/internal/hardhat-network/provider/ethereumjs-workarounds.js +1 -1
  31. package/internal/hardhat-network/provider/ethereumjs-workarounds.js.map +1 -1
  32. package/internal/hardhat-network/provider/filter.d.ts +6 -5
  33. package/internal/hardhat-network/provider/filter.d.ts.map +1 -1
  34. package/internal/hardhat-network/provider/filter.js +2 -2
  35. package/internal/hardhat-network/provider/filter.js.map +1 -1
  36. package/internal/hardhat-network/provider/fork/ForkBlockchain.d.ts +0 -7
  37. package/internal/hardhat-network/provider/fork/ForkBlockchain.d.ts.map +1 -1
  38. package/internal/hardhat-network/provider/fork/ForkBlockchain.js +4 -21
  39. package/internal/hardhat-network/provider/fork/ForkBlockchain.js.map +1 -1
  40. package/internal/hardhat-network/provider/fork/ForkStateManager.d.ts +13 -19
  41. package/internal/hardhat-network/provider/fork/ForkStateManager.d.ts.map +1 -1
  42. package/internal/hardhat-network/provider/fork/ForkStateManager.js +61 -59
  43. package/internal/hardhat-network/provider/fork/ForkStateManager.js.map +1 -1
  44. package/internal/hardhat-network/provider/fork/rpcToBlockData.d.ts.map +1 -1
  45. package/internal/hardhat-network/provider/fork/rpcToBlockData.js +0 -3
  46. package/internal/hardhat-network/provider/fork/rpcToBlockData.js.map +1 -1
  47. package/internal/hardhat-network/provider/fork/rpcToTxData.d.ts +2 -2
  48. package/internal/hardhat-network/provider/fork/rpcToTxData.d.ts.map +1 -1
  49. package/internal/hardhat-network/provider/fork/rpcToTxData.js +1 -1
  50. package/internal/hardhat-network/provider/fork/rpcToTxData.js.map +1 -1
  51. package/internal/hardhat-network/provider/modules/base.js +4 -4
  52. package/internal/hardhat-network/provider/modules/base.js.map +1 -1
  53. package/internal/hardhat-network/provider/modules/eth.d.ts.map +1 -1
  54. package/internal/hardhat-network/provider/modules/eth.js +9 -16
  55. package/internal/hardhat-network/provider/modules/eth.js.map +1 -1
  56. package/internal/hardhat-network/provider/modules/logger.d.ts +6 -84
  57. package/internal/hardhat-network/provider/modules/logger.d.ts.map +1 -1
  58. package/internal/hardhat-network/provider/modules/logger.js +3 -530
  59. package/internal/hardhat-network/provider/modules/logger.js.map +1 -1
  60. package/internal/hardhat-network/provider/node-types.d.ts +2 -65
  61. package/internal/hardhat-network/provider/node-types.d.ts.map +1 -1
  62. package/internal/hardhat-network/provider/node-types.js +0 -5
  63. package/internal/hardhat-network/provider/node-types.js.map +1 -1
  64. package/internal/hardhat-network/provider/node.d.ts +2 -6
  65. package/internal/hardhat-network/provider/node.d.ts.map +1 -1
  66. package/internal/hardhat-network/provider/node.js +79 -148
  67. package/internal/hardhat-network/provider/node.js.map +1 -1
  68. package/internal/hardhat-network/provider/output.d.ts +0 -14
  69. package/internal/hardhat-network/provider/output.d.ts.map +1 -1
  70. package/internal/hardhat-network/provider/output.js +0 -264
  71. package/internal/hardhat-network/provider/output.js.map +1 -1
  72. package/internal/hardhat-network/provider/provider.d.ts +26 -25
  73. package/internal/hardhat-network/provider/provider.d.ts.map +1 -1
  74. package/internal/hardhat-network/provider/provider.js +342 -186
  75. package/internal/hardhat-network/provider/provider.js.map +1 -1
  76. package/internal/hardhat-network/provider/transactions/FakeSenderAccessListEIP2930Transaction.d.ts +10 -8
  77. package/internal/hardhat-network/provider/transactions/FakeSenderAccessListEIP2930Transaction.d.ts.map +1 -1
  78. package/internal/hardhat-network/provider/transactions/FakeSenderAccessListEIP2930Transaction.js +9 -9
  79. package/internal/hardhat-network/provider/transactions/FakeSenderAccessListEIP2930Transaction.js.map +1 -1
  80. package/internal/hardhat-network/provider/transactions/FakeSenderEIP1559Transaction.d.ts +10 -8
  81. package/internal/hardhat-network/provider/transactions/FakeSenderEIP1559Transaction.d.ts.map +1 -1
  82. package/internal/hardhat-network/provider/transactions/FakeSenderEIP1559Transaction.js +9 -9
  83. package/internal/hardhat-network/provider/transactions/FakeSenderEIP1559Transaction.js.map +1 -1
  84. package/internal/hardhat-network/provider/transactions/FakeSenderTransaction.d.ts +10 -9
  85. package/internal/hardhat-network/provider/transactions/FakeSenderTransaction.d.ts.map +1 -1
  86. package/internal/hardhat-network/provider/transactions/FakeSenderTransaction.js +7 -6
  87. package/internal/hardhat-network/provider/transactions/FakeSenderTransaction.js.map +1 -1
  88. package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP1559Transaction.d.ts +6 -5
  89. package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP1559Transaction.d.ts.map +1 -1
  90. package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP1559Transaction.js +1 -1
  91. package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP1559Transaction.js.map +1 -1
  92. package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP2930Transaction.d.ts +5 -4
  93. package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP2930Transaction.d.ts.map +1 -1
  94. package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP2930Transaction.js +1 -1
  95. package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP2930Transaction.js.map +1 -1
  96. package/internal/hardhat-network/provider/transactions/ReadOnlyValidTransaction.d.ts +8 -7
  97. package/internal/hardhat-network/provider/transactions/ReadOnlyValidTransaction.d.ts.map +1 -1
  98. package/internal/hardhat-network/provider/transactions/ReadOnlyValidTransaction.js +2 -2
  99. package/internal/hardhat-network/provider/transactions/ReadOnlyValidTransaction.js.map +1 -1
  100. package/internal/hardhat-network/provider/transactions/ReadOnlyValidUnknownTypeTransaction.d.ts +8 -7
  101. package/internal/hardhat-network/provider/transactions/ReadOnlyValidUnknownTypeTransaction.d.ts.map +1 -1
  102. package/internal/hardhat-network/provider/transactions/ReadOnlyValidUnknownTypeTransaction.js +2 -2
  103. package/internal/hardhat-network/provider/transactions/ReadOnlyValidUnknownTypeTransaction.js.map +1 -1
  104. package/internal/hardhat-network/provider/types/HardhatBlockchainInterface.d.ts +5 -4
  105. package/internal/hardhat-network/provider/types/HardhatBlockchainInterface.d.ts.map +1 -1
  106. package/internal/hardhat-network/provider/utils/convertToEdr.d.ts +14 -0
  107. package/internal/hardhat-network/provider/utils/convertToEdr.d.ts.map +1 -0
  108. package/internal/hardhat-network/provider/utils/convertToEdr.js +191 -0
  109. package/internal/hardhat-network/provider/utils/convertToEdr.js.map +1 -0
  110. package/internal/hardhat-network/provider/utils/getCurrentTimestamp.d.ts +0 -1
  111. package/internal/hardhat-network/provider/utils/getCurrentTimestamp.d.ts.map +1 -1
  112. package/internal/hardhat-network/provider/utils/getCurrentTimestamp.js +1 -5
  113. package/internal/hardhat-network/provider/utils/getCurrentTimestamp.js.map +1 -1
  114. package/internal/hardhat-network/provider/utils/makeCommon.d.ts +1 -1
  115. package/internal/hardhat-network/provider/utils/makeCommon.d.ts.map +1 -1
  116. package/internal/hardhat-network/provider/utils/makeCommon.js +1 -3
  117. package/internal/hardhat-network/provider/utils/makeCommon.js.map +1 -1
  118. package/internal/hardhat-network/provider/utils/makeFakeSignature.d.ts +2 -2
  119. package/internal/hardhat-network/provider/utils/makeFakeSignature.d.ts.map +1 -1
  120. package/internal/hardhat-network/provider/utils/makeFakeSignature.js +1 -15
  121. package/internal/hardhat-network/provider/utils/makeFakeSignature.js.map +1 -1
  122. package/internal/hardhat-network/provider/utils/makeForkClient.d.ts +10 -1
  123. package/internal/hardhat-network/provider/utils/makeForkClient.d.ts.map +1 -1
  124. package/internal/hardhat-network/provider/utils/makeForkClient.js +38 -18
  125. package/internal/hardhat-network/provider/utils/makeForkClient.js.map +1 -1
  126. package/internal/hardhat-network/provider/utils/makeStateTrie.js +2 -2
  127. package/internal/hardhat-network/provider/utils/makeStateTrie.js.map +1 -1
  128. package/internal/hardhat-network/provider/utils/putGenesisBlock.d.ts +3 -1
  129. package/internal/hardhat-network/provider/utils/putGenesisBlock.d.ts.map +1 -1
  130. package/internal/hardhat-network/provider/utils/putGenesisBlock.js +2 -6
  131. package/internal/hardhat-network/provider/utils/putGenesisBlock.js.map +1 -1
  132. package/internal/hardhat-network/provider/utils/random.d.ts +1 -0
  133. package/internal/hardhat-network/provider/utils/random.d.ts.map +1 -1
  134. package/internal/hardhat-network/provider/utils/random.js +7 -1
  135. package/internal/hardhat-network/provider/utils/random.js.map +1 -1
  136. package/internal/hardhat-network/provider/utils/reorgs-protection.d.ts +1 -1
  137. package/internal/hardhat-network/provider/utils/reorgs-protection.d.ts.map +1 -1
  138. package/internal/hardhat-network/provider/utils/reorgs-protection.js +5 -5
  139. package/internal/hardhat-network/provider/utils/reorgs-protection.js.map +1 -1
  140. package/internal/hardhat-network/provider/vm/exit.d.ts +22 -0
  141. package/internal/hardhat-network/provider/vm/exit.d.ts.map +1 -0
  142. package/internal/hardhat-network/provider/vm/exit.js +93 -0
  143. package/internal/hardhat-network/provider/vm/exit.js.map +1 -0
  144. package/internal/hardhat-network/provider/vm/minimal-vm.d.ts +29 -0
  145. package/internal/hardhat-network/provider/vm/minimal-vm.d.ts.map +1 -0
  146. package/internal/hardhat-network/provider/vm/minimal-vm.js +46 -0
  147. package/internal/hardhat-network/provider/vm/minimal-vm.js.map +1 -0
  148. package/internal/hardhat-network/provider/vm/proxy-vm.d.ts +36 -0
  149. package/internal/hardhat-network/provider/vm/proxy-vm.d.ts.map +1 -0
  150. package/internal/hardhat-network/provider/vm/proxy-vm.js +73 -0
  151. package/internal/hardhat-network/provider/vm/proxy-vm.js.map +1 -0
  152. package/internal/hardhat-network/provider/vm/types.d.ts +27 -0
  153. package/internal/hardhat-network/provider/vm/types.d.ts.map +1 -0
  154. package/internal/hardhat-network/provider/vm/types.js +3 -0
  155. package/internal/hardhat-network/provider/vm/types.js.map +1 -0
  156. package/internal/hardhat-network/stack-traces/consoleLogger.d.ts +6 -0
  157. package/internal/hardhat-network/stack-traces/consoleLogger.d.ts.map +1 -1
  158. package/internal/hardhat-network/stack-traces/consoleLogger.js +33 -16
  159. package/internal/hardhat-network/stack-traces/consoleLogger.js.map +1 -1
  160. package/internal/hardhat-network/stack-traces/contracts-identifier.d.ts +1 -2
  161. package/internal/hardhat-network/stack-traces/contracts-identifier.d.ts.map +1 -1
  162. package/internal/hardhat-network/stack-traces/contracts-identifier.js +6 -7
  163. package/internal/hardhat-network/stack-traces/contracts-identifier.js.map +1 -1
  164. package/internal/hardhat-network/stack-traces/debug.js +6 -6
  165. package/internal/hardhat-network/stack-traces/debug.js.map +1 -1
  166. package/internal/hardhat-network/stack-traces/error-inferrer.d.ts.map +1 -1
  167. package/internal/hardhat-network/stack-traces/error-inferrer.js +13 -7
  168. package/internal/hardhat-network/stack-traces/error-inferrer.js.map +1 -1
  169. package/internal/hardhat-network/stack-traces/message-trace.d.ts +8 -3
  170. package/internal/hardhat-network/stack-traces/message-trace.d.ts.map +1 -1
  171. package/internal/hardhat-network/stack-traces/message-trace.js +22 -1
  172. package/internal/hardhat-network/stack-traces/message-trace.js.map +1 -1
  173. package/internal/hardhat-network/stack-traces/model.d.ts +8 -0
  174. package/internal/hardhat-network/stack-traces/model.d.ts.map +1 -1
  175. package/internal/hardhat-network/stack-traces/model.js +52 -0
  176. package/internal/hardhat-network/stack-traces/model.js.map +1 -1
  177. package/internal/hardhat-network/stack-traces/opcodes.d.ts +1 -0
  178. package/internal/hardhat-network/stack-traces/opcodes.d.ts.map +1 -1
  179. package/internal/hardhat-network/stack-traces/opcodes.js +5 -1
  180. package/internal/hardhat-network/stack-traces/opcodes.js.map +1 -1
  181. package/internal/hardhat-network/stack-traces/solidity-errors.js +2 -2
  182. package/internal/hardhat-network/stack-traces/solidity-errors.js.map +1 -1
  183. package/internal/hardhat-network/stack-traces/solidityTracer.d.ts.map +1 -1
  184. package/internal/hardhat-network/stack-traces/solidityTracer.js +5 -5
  185. package/internal/hardhat-network/stack-traces/solidityTracer.js.map +1 -1
  186. package/internal/hardhat-network/stack-traces/vm-debug-tracer.d.ts.map +1 -1
  187. package/internal/hardhat-network/stack-traces/vm-debug-tracer.js +28 -34
  188. package/internal/hardhat-network/stack-traces/vm-debug-tracer.js.map +1 -1
  189. package/internal/hardhat-network/stack-traces/vm-trace-decoder.d.ts +7 -0
  190. package/internal/hardhat-network/stack-traces/vm-trace-decoder.d.ts.map +1 -1
  191. package/internal/hardhat-network/stack-traces/vm-trace-decoder.js +69 -2
  192. package/internal/hardhat-network/stack-traces/vm-trace-decoder.js.map +1 -1
  193. package/internal/hardhat-network/stack-traces/vm-tracer.d.ts +7 -12
  194. package/internal/hardhat-network/stack-traces/vm-tracer.d.ts.map +1 -1
  195. package/internal/hardhat-network/stack-traces/vm-tracer.js +46 -65
  196. package/internal/hardhat-network/stack-traces/vm-tracer.js.map +1 -1
  197. package/internal/util/date.d.ts +1 -0
  198. package/internal/util/date.d.ts.map +1 -1
  199. package/internal/util/date.js +5 -1
  200. package/internal/util/date.js.map +1 -1
  201. package/internal/util/hardforks.d.ts +2 -0
  202. package/internal/util/hardforks.d.ts.map +1 -1
  203. package/internal/util/hardforks.js +27 -1
  204. package/internal/util/hardforks.js.map +1 -1
  205. package/package.json +18 -16
  206. package/src/internal/core/providers/construction.ts +7 -9
  207. package/src/internal/core/providers/http.ts +3 -1
  208. package/src/internal/core/runtime-environment.ts +2 -1
  209. package/src/internal/hardhat-network/jsonrpc/client.ts +1 -28
  210. package/src/internal/hardhat-network/jsonrpc/handler.ts +9 -1
  211. package/src/internal/hardhat-network/provider/modules/logger.ts +6 -801
  212. package/src/internal/hardhat-network/provider/node-types.ts +2 -89
  213. package/src/internal/hardhat-network/provider/output.ts +0 -352
  214. package/src/internal/hardhat-network/provider/provider.ts +482 -263
  215. package/src/internal/hardhat-network/provider/utils/convertToEdr.ts +228 -0
  216. package/src/internal/hardhat-network/provider/utils/getCurrentTimestamp.ts +0 -4
  217. package/src/internal/hardhat-network/provider/utils/makeCommon.ts +1 -12
  218. package/src/internal/hardhat-network/provider/utils/makeForkClient.ts +63 -24
  219. package/src/internal/hardhat-network/provider/utils/random.ts +8 -1
  220. package/src/internal/hardhat-network/provider/utils/reorgs-protection.ts +5 -5
  221. package/src/internal/hardhat-network/provider/vm/exit.ts +101 -0
  222. package/src/internal/hardhat-network/provider/vm/minimal-vm.ts +101 -0
  223. package/src/internal/hardhat-network/provider/vm/types.ts +31 -0
  224. package/src/internal/hardhat-network/stack-traces/consoleLogger.ts +40 -21
  225. package/src/internal/hardhat-network/stack-traces/contracts-identifier.ts +10 -12
  226. package/src/internal/hardhat-network/stack-traces/debug.ts +6 -6
  227. package/src/internal/hardhat-network/stack-traces/error-inferrer.ts +15 -8
  228. package/src/internal/hardhat-network/stack-traces/message-trace.ts +40 -4
  229. package/src/internal/hardhat-network/stack-traces/model.ts +61 -0
  230. package/src/internal/hardhat-network/stack-traces/opcodes.ts +4 -0
  231. package/src/internal/hardhat-network/stack-traces/solidity-errors.ts +2 -2
  232. package/src/internal/hardhat-network/stack-traces/solidityTracer.ts +6 -5
  233. package/src/internal/hardhat-network/stack-traces/vm-trace-decoder.ts +113 -4
  234. package/src/internal/hardhat-network/stack-traces/vm-tracer.ts +67 -95
  235. package/src/internal/util/date.ts +4 -0
  236. package/src/internal/util/hardforks.ts +52 -0
  237. package/src/internal/hardhat-network/provider/BlockchainBase.ts +0 -185
  238. package/src/internal/hardhat-network/provider/BlockchainData.ts +0 -261
  239. package/src/internal/hardhat-network/provider/HardhatBlockchain.ts +0 -140
  240. package/src/internal/hardhat-network/provider/PoolState.ts +0 -48
  241. package/src/internal/hardhat-network/provider/TransactionQueue.ts +0 -158
  242. package/src/internal/hardhat-network/provider/TxPool.ts +0 -715
  243. package/src/internal/hardhat-network/provider/ethereumjs-workarounds.ts +0 -21
  244. package/src/internal/hardhat-network/provider/filter.ts +0 -142
  245. package/src/internal/hardhat-network/provider/fork/ForkBlockchain.ts +0 -433
  246. package/src/internal/hardhat-network/provider/fork/ForkStateManager.ts +0 -480
  247. package/src/internal/hardhat-network/provider/fork/rpcToBlockData.ts +0 -35
  248. package/src/internal/hardhat-network/provider/fork/rpcToTxData.ts +0 -44
  249. package/src/internal/hardhat-network/provider/modules/base.ts +0 -156
  250. package/src/internal/hardhat-network/provider/modules/debug.ts +0 -104
  251. package/src/internal/hardhat-network/provider/modules/eth.ts +0 -1781
  252. package/src/internal/hardhat-network/provider/modules/evm.ts +0 -249
  253. package/src/internal/hardhat-network/provider/modules/hardhat.ts +0 -481
  254. package/src/internal/hardhat-network/provider/modules/net.ts +0 -60
  255. package/src/internal/hardhat-network/provider/modules/personal.ts +0 -40
  256. package/src/internal/hardhat-network/provider/modules/web3.ts +0 -49
  257. package/src/internal/hardhat-network/provider/node.ts +0 -2993
  258. package/src/internal/hardhat-network/provider/transactions/FakeSenderAccessListEIP2930Transaction.ts +0 -226
  259. package/src/internal/hardhat-network/provider/transactions/FakeSenderEIP1559Transaction.ts +0 -224
  260. package/src/internal/hardhat-network/provider/transactions/FakeSenderTransaction.ts +0 -216
  261. package/src/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP1559Transaction.ts +0 -143
  262. package/src/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP2930Transaction.ts +0 -144
  263. package/src/internal/hardhat-network/provider/transactions/ReadOnlyValidTransaction.ts +0 -171
  264. package/src/internal/hardhat-network/provider/transactions/ReadOnlyValidUnknownTypeTransaction.ts +0 -169
  265. package/src/internal/hardhat-network/provider/types/HardhatBlockchainInterface.ts +0 -25
  266. package/src/internal/hardhat-network/provider/utils/makeFakeSignature.ts +0 -60
  267. package/src/internal/hardhat-network/provider/utils/makeStateTrie.ts +0 -29
  268. package/src/internal/hardhat-network/provider/utils/putGenesisBlock.ts +0 -61
  269. package/src/internal/hardhat-network/provider/utils/reorganizeTransactionsLists.ts +0 -45
  270. package/src/internal/hardhat-network/provider/utils/txMapToArray.ts +0 -7
  271. package/src/internal/hardhat-network/stack-traces/vm-debug-tracer.ts +0 -630
@@ -1,261 +0,0 @@
1
- import { Block } from "@nomicfoundation/ethereumjs-block";
2
- import { Common } from "@nomicfoundation/ethereumjs-common";
3
- import { TypedTransaction } from "@nomicfoundation/ethereumjs-tx";
4
- import { bytesToHex as bufferToHex } from "@nomicfoundation/ethereumjs-util";
5
- import { Bloom } from "@nomicfoundation/ethereumjs-vm";
6
-
7
- import { assertHardhatInvariant } from "../../core/errors";
8
- import { bloomFilter, filterLogs } from "./filter";
9
- import { FilterParams } from "./node-types";
10
- import { RpcLogOutput, RpcReceiptOutput } from "./output";
11
-
12
- interface Reservation {
13
- first: bigint;
14
- last: bigint;
15
- interval: bigint;
16
- previousBlockStateRoot: Buffer;
17
- previousBlockTotalDifficulty: bigint;
18
- previousBlockBaseFeePerGas: bigint | undefined;
19
- }
20
-
21
- export class BlockchainData {
22
- private _blocksByNumber: Map<bigint, Block> = new Map();
23
- private _blocksByHash: Map<string, Block> = new Map();
24
- private _blocksByTransactions: Map<string, Block> = new Map();
25
- private _transactions: Map<string, TypedTransaction> = new Map();
26
- private _transactionReceipts: Map<string, RpcReceiptOutput> = new Map();
27
- private _totalDifficulty: Map<string, bigint> = new Map();
28
- private _blockReservations: Reservation[] = new Array();
29
-
30
- constructor(private _common: Common) {}
31
-
32
- public reserveBlocks(
33
- first: bigint,
34
- count: bigint,
35
- interval: bigint,
36
- previousBlockStateRoot: Buffer,
37
- previousBlockTotalDifficulty: bigint,
38
- previousBlockBaseFeePerGas: bigint | undefined
39
- ) {
40
- const reservation: Reservation = {
41
- first,
42
- last: first + count - 1n,
43
- interval,
44
- previousBlockStateRoot,
45
- previousBlockTotalDifficulty,
46
- previousBlockBaseFeePerGas,
47
- };
48
- this._blockReservations.push(reservation);
49
- }
50
-
51
- public getBlockByNumber(blockNumber: bigint) {
52
- return this._blocksByNumber.get(blockNumber);
53
- }
54
-
55
- public getBlockByHash(blockHash: Uint8Array) {
56
- return this._blocksByHash.get(bufferToHex(blockHash));
57
- }
58
-
59
- public getBlockByTransactionHash(transactionHash: Uint8Array) {
60
- return this._blocksByTransactions.get(bufferToHex(transactionHash));
61
- }
62
-
63
- public getTransaction(transactionHash: Uint8Array) {
64
- return this._transactions.get(bufferToHex(transactionHash));
65
- }
66
-
67
- public getTransactionReceipt(transactionHash: Uint8Array) {
68
- return this._transactionReceipts.get(bufferToHex(transactionHash));
69
- }
70
-
71
- public getTotalDifficulty(blockHash: Uint8Array) {
72
- return this._totalDifficulty.get(bufferToHex(blockHash));
73
- }
74
-
75
- public getLogs(filterParams: FilterParams) {
76
- const logs: RpcLogOutput[] = [];
77
- for (let i = filterParams.fromBlock; i <= filterParams.toBlock; i++) {
78
- const block = this.getBlockByNumber(i);
79
- if (
80
- block === undefined ||
81
- !bloomFilter(
82
- new Bloom(block.header.logsBloom),
83
- filterParams.addresses,
84
- filterParams.normalizedTopics
85
- )
86
- ) {
87
- continue;
88
- }
89
- for (const transaction of block.transactions) {
90
- const receipt = this.getTransactionReceipt(transaction.hash());
91
- if (receipt !== undefined) {
92
- logs.push(
93
- ...filterLogs(receipt.logs, {
94
- fromBlock: filterParams.fromBlock,
95
- toBlock: filterParams.toBlock,
96
- addresses: filterParams.addresses,
97
- normalizedTopics: filterParams.normalizedTopics,
98
- })
99
- );
100
- }
101
- }
102
- }
103
- return logs;
104
- }
105
-
106
- public addBlock(block: Block, totalDifficulty: bigint) {
107
- const blockHash = bufferToHex(block.hash());
108
- const blockNumber = block.header.number;
109
- this._blocksByNumber.set(blockNumber, block);
110
- this._blocksByHash.set(blockHash, block);
111
- this._totalDifficulty.set(blockHash, totalDifficulty);
112
-
113
- for (const transaction of block.transactions) {
114
- const transactionHash = bufferToHex(transaction.hash());
115
- this._transactions.set(transactionHash, transaction);
116
- this._blocksByTransactions.set(transactionHash, block);
117
- }
118
- }
119
-
120
- /**
121
- * WARNING: this method can leave the blockchain in an invalid state where
122
- * there are gaps between blocks. Ideally we should have a method that removes
123
- * the given block and all the following blocks.
124
- */
125
- public removeBlock(block: Block) {
126
- const blockHash = bufferToHex(block.hash());
127
- const blockNumber = block.header.number;
128
- this._blocksByNumber.delete(blockNumber);
129
- this._blocksByHash.delete(blockHash);
130
- this._totalDifficulty.delete(blockHash);
131
-
132
- for (const transaction of block.transactions) {
133
- const transactionHash = bufferToHex(transaction.hash());
134
- this._transactions.delete(transactionHash);
135
- this._transactionReceipts.delete(transactionHash);
136
- this._blocksByTransactions.delete(transactionHash);
137
- }
138
- }
139
-
140
- public addTransaction(transaction: TypedTransaction) {
141
- this._transactions.set(bufferToHex(transaction.hash()), transaction);
142
- }
143
-
144
- public addTransactionReceipt(receipt: RpcReceiptOutput) {
145
- this._transactionReceipts.set(receipt.transactionHash, receipt);
146
- }
147
-
148
- public isReservedBlock(blockNumber: bigint): boolean {
149
- return this._findBlockReservation(blockNumber) !== -1;
150
- }
151
-
152
- private _findBlockReservation(blockNumber: bigint): number {
153
- return this._blockReservations.findIndex(
154
- (reservation) =>
155
- reservation.first <= blockNumber && blockNumber <= reservation.last
156
- );
157
- }
158
-
159
- /**
160
- * WARNING: this method only removes the given reservation and can result in
161
- * gaps in the reservations array. Ideally we should have a method that
162
- * removes the given reservation and all the following reservations.
163
- */
164
- private _removeReservation(index: number): Reservation {
165
- assertHardhatInvariant(
166
- index in this._blockReservations,
167
- `Reservation ${index} does not exist`
168
- );
169
- const reservation = this._blockReservations[index];
170
-
171
- this._blockReservations.splice(index, 1);
172
-
173
- return reservation;
174
- }
175
-
176
- /**
177
- * Cancel and return the reservation that has block `blockNumber`
178
- */
179
- public cancelReservationWithBlock(blockNumber: bigint): Reservation {
180
- return this._removeReservation(this._findBlockReservation(blockNumber));
181
- }
182
-
183
- public fulfillBlockReservation(blockNumber: bigint) {
184
- // in addition to adding the given block, the reservation needs to be split
185
- // in two in order to accomodate access to the given block.
186
-
187
- const reservationIndex = this._findBlockReservation(blockNumber);
188
- assertHardhatInvariant(
189
- reservationIndex !== -1,
190
- `No reservation to fill for block number ${blockNumber.toString()}`
191
- );
192
-
193
- // capture the timestamp before removing the reservation:
194
- const timestamp = this._calculateTimestampForReservedBlock(blockNumber);
195
-
196
- // split the block reservation:
197
- const oldReservation = this._removeReservation(reservationIndex);
198
-
199
- if (blockNumber !== oldReservation.first) {
200
- this._blockReservations.push({
201
- ...oldReservation,
202
- last: blockNumber - 1n,
203
- });
204
- }
205
-
206
- if (blockNumber !== oldReservation.last) {
207
- this._blockReservations.push({
208
- ...oldReservation,
209
- first: blockNumber + 1n,
210
- });
211
- }
212
-
213
- this.addBlock(
214
- Block.fromBlockData(
215
- {
216
- header: {
217
- number: blockNumber,
218
- stateRoot: oldReservation.previousBlockStateRoot,
219
- baseFeePerGas: oldReservation.previousBlockBaseFeePerGas,
220
- timestamp,
221
- },
222
- },
223
- {
224
- common: this._common,
225
- skipConsensusFormatValidation: true,
226
- }
227
- ),
228
- oldReservation.previousBlockTotalDifficulty
229
- );
230
- }
231
-
232
- private _calculateTimestampForReservedBlock(blockNumber: bigint): bigint {
233
- const reservationIndex = this._findBlockReservation(blockNumber);
234
-
235
- assertHardhatInvariant(
236
- reservationIndex !== -1,
237
- `Block ${blockNumber.toString()} does not lie within any of the reservations.`
238
- );
239
-
240
- const reservation = this._blockReservations[reservationIndex];
241
-
242
- const blockNumberBeforeReservation = reservation.first - 1n;
243
-
244
- const blockBeforeReservation = this.getBlockByNumber(
245
- blockNumberBeforeReservation
246
- );
247
- assertHardhatInvariant(
248
- blockBeforeReservation !== undefined,
249
- `Reservation after block ${blockNumberBeforeReservation.toString()} cannot be created because that block does not exist`
250
- );
251
-
252
- const previousTimestamp = this.isReservedBlock(blockNumberBeforeReservation)
253
- ? this._calculateTimestampForReservedBlock(blockNumberBeforeReservation)
254
- : blockBeforeReservation.header.timestamp;
255
-
256
- return (
257
- previousTimestamp +
258
- reservation.interval * (blockNumber - reservation.first + 1n)
259
- );
260
- }
261
- }
@@ -1,140 +0,0 @@
1
- import { Block } from "@nomicfoundation/ethereumjs-block";
2
- import {
3
- BlockchainInterface,
4
- BlockchainEvents,
5
- } from "@nomicfoundation/ethereumjs-blockchain";
6
- import { Common } from "@nomicfoundation/ethereumjs-common";
7
- import { TypedTransaction } from "@nomicfoundation/ethereumjs-tx";
8
- import {
9
- AsyncEventEmitter,
10
- equalsBytes,
11
- zeros,
12
- } from "@nomicfoundation/ethereumjs-util";
13
-
14
- import { BlockchainBase } from "./BlockchainBase";
15
- import { FilterParams } from "./node-types";
16
- import { RpcLogOutput } from "./output";
17
- import { HardhatBlockchainInterface } from "./types/HardhatBlockchainInterface";
18
-
19
- /* eslint-disable @nomicfoundation/hardhat-internal-rules/only-hardhat-error */
20
-
21
- export class HardhatBlockchain
22
- extends BlockchainBase
23
- implements HardhatBlockchainInterface
24
- {
25
- private _length = 0n;
26
- public events?: AsyncEventEmitter<BlockchainEvents> | undefined;
27
-
28
- constructor(common: Common) {
29
- super(common);
30
- }
31
-
32
- public shallowCopy(): BlockchainInterface {
33
- return this;
34
- }
35
-
36
- public getIteratorHead(_name?: string | undefined): Promise<Block> {
37
- throw new Error("Method not implemented.");
38
- }
39
-
40
- public setIteratorHead(_tag: string, _headHash: Uint8Array): Promise<void> {
41
- throw new Error("Method not implemented.");
42
- }
43
-
44
- public getCanonicalHeadBlock(): Promise<Block> {
45
- throw new Error("Method not implemented.");
46
- }
47
-
48
- public getLatestBlockNumber(): bigint {
49
- return BigInt(this._length - 1n);
50
- }
51
-
52
- public async addBlock(block: Block): Promise<Block> {
53
- this._validateBlock(block);
54
- const totalDifficulty = await this._computeTotalDifficulty(block);
55
- this._data.addBlock(block, totalDifficulty);
56
- this._length += 1n;
57
- return block;
58
- }
59
-
60
- public reserveBlocks(
61
- count: bigint,
62
- interval: bigint,
63
- previousBlockStateRoot: Buffer,
64
- previousBlockTotalDifficulty: bigint,
65
- previousBlockBaseFeePerGas: bigint | undefined
66
- ) {
67
- super.reserveBlocks(
68
- count,
69
- interval,
70
- previousBlockStateRoot,
71
- previousBlockTotalDifficulty,
72
- previousBlockBaseFeePerGas
73
- );
74
- this._length += count;
75
- }
76
-
77
- public deleteLaterBlocks(block: Block): void {
78
- const actual = this._data.getBlockByHash(block.hash());
79
- if (actual === undefined) {
80
- throw new Error("Invalid block");
81
- }
82
-
83
- this._delBlock(actual.header.number + 1n);
84
- }
85
-
86
- public async getTotalDifficulty(blockHash: Buffer): Promise<bigint> {
87
- const totalDifficulty = this._data.getTotalDifficulty(blockHash);
88
- if (totalDifficulty === undefined) {
89
- throw new Error("Block not found");
90
- }
91
- return totalDifficulty;
92
- }
93
-
94
- public async getTransaction(
95
- transactionHash: Buffer
96
- ): Promise<TypedTransaction | undefined> {
97
- return this.getLocalTransaction(transactionHash);
98
- }
99
-
100
- public async getBlockByTransactionHash(
101
- transactionHash: Buffer
102
- ): Promise<Block | null> {
103
- const block = this._data.getBlockByTransactionHash(transactionHash);
104
- return block ?? null;
105
- }
106
-
107
- public async getTransactionReceipt(transactionHash: Buffer) {
108
- return this._data.getTransactionReceipt(transactionHash) ?? null;
109
- }
110
-
111
- public async getLogs(filterParams: FilterParams): Promise<RpcLogOutput[]> {
112
- return this._data.getLogs(filterParams);
113
- }
114
-
115
- private _validateBlock(block: Block) {
116
- const blockNumber = block.header.number;
117
- const parentHash = block.header.parentHash;
118
- const parent = this._data.getBlockByNumber(BigInt(blockNumber - 1n));
119
-
120
- if (BigInt(this._length) !== blockNumber) {
121
- throw new Error(
122
- `Invalid block number ${blockNumber}. Expected ${this._length}.`
123
- );
124
- }
125
-
126
- if (
127
- (blockNumber === 0n && !equalsBytes(parentHash, zeros(32))) ||
128
- (blockNumber > 0 &&
129
- parent !== undefined &&
130
- !equalsBytes(parentHash, parent.hash()))
131
- ) {
132
- throw new Error("Invalid parent hash");
133
- }
134
- }
135
-
136
- protected _delBlock(blockNumber: bigint): void {
137
- super._delBlock(blockNumber);
138
- this._length = blockNumber;
139
- }
140
- }
@@ -1,48 +0,0 @@
1
- import { TypedTransaction } from "@nomicfoundation/ethereumjs-tx";
2
- import {
3
- List as ImmutableList,
4
- Map as ImmutableMap,
5
- Record as ImmutableRecord,
6
- } from "immutable";
7
-
8
- import * as BigIntUtils from "../../util/bigint";
9
-
10
- export interface OrderedTransaction {
11
- orderId: number;
12
- data: TypedTransaction;
13
- }
14
-
15
- interface ImmutableOrderedTransaction {
16
- orderId: number;
17
- fakeFrom: string | undefined;
18
- data: string;
19
- txType: number;
20
- }
21
-
22
- export const makeSerializedTransaction =
23
- ImmutableRecord<ImmutableOrderedTransaction>({
24
- orderId: 0,
25
- fakeFrom: undefined,
26
- data: "",
27
- txType: 0,
28
- });
29
-
30
- export type SerializedTransaction =
31
- ImmutableRecord<ImmutableOrderedTransaction>;
32
- export type SenderTransactions = ImmutableList<SerializedTransaction>;
33
- export type AddressToTransactions = ImmutableMap<string, SenderTransactions>;
34
- export type HashToTransaction = ImmutableMap<string, SerializedTransaction>;
35
-
36
- export interface PoolState {
37
- pendingTransactions: AddressToTransactions; // address => list of serialized pending Transactions
38
- queuedTransactions: AddressToTransactions; // address => list of serialized queued Transactions
39
- hashToTransaction: HashToTransaction;
40
- blockGasLimit: string;
41
- }
42
-
43
- export const makePoolState = ImmutableRecord<PoolState>({
44
- pendingTransactions: ImmutableMap<string, SenderTransactions>(),
45
- queuedTransactions: ImmutableMap<string, SenderTransactions>(),
46
- hashToTransaction: ImmutableMap<string, SerializedTransaction>(),
47
- blockGasLimit: BigIntUtils.toHex(9500000),
48
- });
@@ -1,158 +0,0 @@
1
- import { TypedTransaction } from "@nomicfoundation/ethereumjs-tx";
2
- import Heap from "mnemonist/heap";
3
-
4
- import { InternalError, InvalidInputError } from "../../core/providers/errors";
5
- import * as BigIntUtils from "../../util/bigint";
6
- import { MempoolOrder } from "./node-types";
7
- import { OrderedTransaction } from "./PoolState";
8
-
9
- function getEffectiveMinerFee(
10
- tx: OrderedTransaction,
11
- baseFee?: bigint
12
- ): bigint {
13
- // This mimics the EIP-1559 normalize_transaction function
14
- const maxFeePerGas =
15
- "gasPrice" in tx.data ? tx.data.gasPrice : tx.data.maxFeePerGas;
16
-
17
- const maxPriorityFeePerGas =
18
- "gasPrice" in tx.data ? tx.data.gasPrice : tx.data.maxPriorityFeePerGas;
19
-
20
- if (baseFee === undefined) {
21
- return maxFeePerGas;
22
- }
23
-
24
- return BigIntUtils.min(maxPriorityFeePerGas, maxFeePerGas - baseFee);
25
- }
26
-
27
- function decreasingOrderEffectiveMinerFeeComparator(
28
- left: OrderedTransaction,
29
- right: OrderedTransaction,
30
- baseFee?: bigint
31
- ) {
32
- const leftEffectiveMinerFee = getEffectiveMinerFee(left, baseFee);
33
- const rightEffectiveMinerFee = getEffectiveMinerFee(right, baseFee);
34
-
35
- const cmp = BigIntUtils.cmp(rightEffectiveMinerFee, leftEffectiveMinerFee);
36
-
37
- if (cmp !== 0) {
38
- return cmp;
39
- }
40
-
41
- // If two txs have the same effective miner fee we want to sort them
42
- // in increasing order by orderId.
43
- return left.orderId - right.orderId;
44
- }
45
-
46
- function decreasingOrderComparator(
47
- left: OrderedTransaction,
48
- right: OrderedTransaction
49
- ) {
50
- return left.orderId - right.orderId;
51
- }
52
-
53
- function getOrderedTransactionHeap(
54
- mempoolOrder: MempoolOrder,
55
- baseFee?: bigint
56
- ): Heap<OrderedTransaction> {
57
- switch (mempoolOrder) {
58
- case "priority":
59
- return new Heap<OrderedTransaction>((a, b) =>
60
- decreasingOrderEffectiveMinerFeeComparator(a, b, baseFee)
61
- );
62
- case "fifo":
63
- return new Heap<OrderedTransaction>((a, b) =>
64
- decreasingOrderComparator(a, b)
65
- );
66
- default:
67
- // eslint-disable-next-line @nomicfoundation/hardhat-internal-rules/only-hardhat-error
68
- throw new InvalidInputError(
69
- `Invalid mempool order: ${mempoolOrder as any}`
70
- );
71
- }
72
- }
73
-
74
- /**
75
- * A queue of transactions in the order that they could be mined in the next
76
- * block.
77
- *
78
- * A transaction being part of this queue doesn't mean that it will be mined in
79
- * the next block, as it may not meet the required criteria to be included or
80
- * may not fit within the block.
81
- *
82
- * If after getting the next transaction in the queue you decided not to mine
83
- * it, the other transactions that belong to that sender MUST be removed from
84
- * the queue by calling the #removeLastSenderTransactions() method.
85
- **/
86
- export class TransactionQueue {
87
- private readonly _queuedTransactions: Map<string, OrderedTransaction[]> =
88
- new Map();
89
-
90
- private readonly _heap: Heap<OrderedTransaction>;
91
-
92
- private _lastTransactionSender?: string;
93
-
94
- /**
95
- * Creates a TransactionQueue.
96
- *
97
- * @param pendingTransactions A map of sender to a list of their transactions,
98
- * sorted by nonce and without nonce gaps.
99
- * @param baseFee The base fee of the next block, if it's going to use EIP-1559
100
- */
101
- constructor(
102
- pendingTransactions: Map<string, OrderedTransaction[]>,
103
- mempoolOrder: MempoolOrder,
104
- baseFee?: bigint
105
- ) {
106
- this._heap = getOrderedTransactionHeap(mempoolOrder, baseFee);
107
-
108
- for (const [address, txList] of pendingTransactions) {
109
- if (baseFee === undefined && txList.some((tx) => tx.data.type === 2)) {
110
- // eslint-disable-next-line @nomicfoundation/hardhat-internal-rules/only-hardhat-error
111
- throw new InternalError(
112
- "Trying to initialize and sort a mempool with an EIP-1559 tx but no base fee"
113
- );
114
- }
115
-
116
- const [firstTx, ...remainingTxs] = txList;
117
- this._heap.push(firstTx);
118
- this._queuedTransactions.set(address, remainingTxs);
119
- }
120
- }
121
-
122
- public getNextTransaction(): TypedTransaction | undefined {
123
- if (this._lastTransactionSender !== undefined) {
124
- this._moveFirstEnqueuedTransactionToHeap(this._lastTransactionSender);
125
- }
126
-
127
- const nextTx = this._heap.pop();
128
- if (nextTx === undefined) {
129
- return undefined;
130
- }
131
-
132
- this._lastTransactionSender = nextTx.data.getSenderAddress().toString();
133
- return nextTx.data;
134
- }
135
-
136
- public removeLastSenderTransactions() {
137
- if (this._lastTransactionSender === undefined) {
138
- // eslint-disable-next-line @nomicfoundation/hardhat-internal-rules/only-hardhat-error
139
- throw new InternalError(
140
- "TransactionQueue#removeLastSenderTransactions called before TransactionQueue#getNextTransaction"
141
- );
142
- }
143
-
144
- this._queuedTransactions.delete(this._lastTransactionSender);
145
- this._lastTransactionSender = undefined;
146
- }
147
-
148
- private _moveFirstEnqueuedTransactionToHeap(sender: string) {
149
- const queue = this._queuedTransactions.get(sender);
150
- if (queue === undefined || queue.length === 0) {
151
- return;
152
- }
153
-
154
- const [first, ...rest] = queue;
155
- this._heap.push(first);
156
- this._queuedTransactions.set(sender, rest);
157
- }
158
- }