hardhat 2.22.2 → 2.23.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 (183) hide show
  1. package/builtin-tasks/compile.js +2 -2
  2. package/builtin-tasks/compile.js.map +1 -1
  3. package/common/napi-rs.d.ts +2 -0
  4. package/common/napi-rs.d.ts.map +1 -0
  5. package/common/napi-rs.js +19 -0
  6. package/common/napi-rs.js.map +1 -0
  7. package/internal/core/errors-list.js +1 -1
  8. package/internal/core/errors-list.js.map +1 -1
  9. package/internal/core/params/argumentTypes.d.ts +6 -0
  10. package/internal/core/params/argumentTypes.d.ts.map +1 -1
  11. package/internal/core/params/argumentTypes.js +40 -1
  12. package/internal/core/params/argumentTypes.js.map +1 -1
  13. package/internal/core/tasks/task-definitions.d.ts +2 -2
  14. package/internal/core/tasks/task-definitions.js +2 -2
  15. package/internal/hardhat-network/provider/BlockchainBase.d.ts +29 -0
  16. package/internal/hardhat-network/provider/BlockchainBase.d.ts.map +1 -0
  17. package/internal/hardhat-network/provider/BlockchainBase.js +144 -0
  18. package/internal/hardhat-network/provider/BlockchainBase.js.map +1 -0
  19. package/internal/hardhat-network/provider/BlockchainData.d.ts +58 -0
  20. package/internal/hardhat-network/provider/BlockchainData.d.ts.map +1 -0
  21. package/internal/hardhat-network/provider/BlockchainData.js +178 -0
  22. package/internal/hardhat-network/provider/BlockchainData.js.map +1 -0
  23. package/internal/hardhat-network/provider/HardhatBlockchain.d.ts +24 -0
  24. package/internal/hardhat-network/provider/HardhatBlockchain.d.ts.map +1 -0
  25. package/internal/hardhat-network/provider/HardhatBlockchain.js +73 -0
  26. package/internal/hardhat-network/provider/HardhatBlockchain.js.map +1 -0
  27. package/internal/hardhat-network/provider/PoolState.d.ts +26 -0
  28. package/internal/hardhat-network/provider/PoolState.d.ts.map +1 -0
  29. package/internal/hardhat-network/provider/PoolState.js +41 -0
  30. package/internal/hardhat-network/provider/PoolState.js.map +1 -0
  31. package/internal/hardhat-network/provider/TransactionQueue.d.ts +32 -0
  32. package/internal/hardhat-network/provider/TransactionQueue.d.ts.map +1 -0
  33. package/internal/hardhat-network/provider/TransactionQueue.js +130 -0
  34. package/internal/hardhat-network/provider/TransactionQueue.js.map +1 -0
  35. package/internal/hardhat-network/provider/TxPool.d.ts +83 -0
  36. package/internal/hardhat-network/provider/TxPool.d.ts.map +1 -0
  37. package/internal/hardhat-network/provider/TxPool.js +470 -0
  38. package/internal/hardhat-network/provider/TxPool.js.map +1 -0
  39. package/internal/hardhat-network/provider/ethereumjs-workarounds.d.ts +2 -0
  40. package/internal/hardhat-network/provider/ethereumjs-workarounds.d.ts.map +1 -0
  41. package/internal/hardhat-network/provider/ethereumjs-workarounds.js +15 -0
  42. package/internal/hardhat-network/provider/ethereumjs-workarounds.js.map +1 -0
  43. package/internal/hardhat-network/provider/filter.d.ts +29 -0
  44. package/internal/hardhat-network/provider/filter.d.ts.map +1 -0
  45. package/internal/hardhat-network/provider/filter.js +97 -0
  46. package/internal/hardhat-network/provider/filter.js.map +1 -0
  47. package/internal/hardhat-network/provider/fork/ForkBlockchain.d.ts +33 -0
  48. package/internal/hardhat-network/provider/fork/ForkBlockchain.d.ts.map +1 -0
  49. package/internal/hardhat-network/provider/fork/ForkBlockchain.js +272 -0
  50. package/internal/hardhat-network/provider/fork/ForkBlockchain.js.map +1 -0
  51. package/internal/hardhat-network/provider/fork/ForkStateManager.d.ts +51 -0
  52. package/internal/hardhat-network/provider/fork/ForkStateManager.d.ts.map +1 -0
  53. package/internal/hardhat-network/provider/fork/ForkStateManager.js +300 -0
  54. package/internal/hardhat-network/provider/fork/ForkStateManager.js.map +1 -0
  55. package/internal/hardhat-network/provider/fork/rpcToBlockData.d.ts +4 -0
  56. package/internal/hardhat-network/provider/fork/rpcToBlockData.d.ts.map +1 -0
  57. package/internal/hardhat-network/provider/fork/rpcToBlockData.js +32 -0
  58. package/internal/hardhat-network/provider/fork/rpcToBlockData.js.map +1 -0
  59. package/internal/hardhat-network/provider/fork/rpcToTxData.d.ts +10 -0
  60. package/internal/hardhat-network/provider/fork/rpcToTxData.d.ts.map +1 -0
  61. package/internal/hardhat-network/provider/fork/rpcToTxData.js +29 -0
  62. package/internal/hardhat-network/provider/fork/rpcToTxData.js.map +1 -0
  63. package/internal/hardhat-network/provider/modules/base.d.ts +17 -0
  64. package/internal/hardhat-network/provider/modules/base.d.ts.map +1 -0
  65. package/internal/hardhat-network/provider/modules/base.js +127 -0
  66. package/internal/hardhat-network/provider/modules/base.js.map +1 -0
  67. package/internal/hardhat-network/provider/modules/debug.d.ts +12 -0
  68. package/internal/hardhat-network/provider/modules/debug.d.ts.map +1 -0
  69. package/internal/hardhat-network/provider/modules/debug.js +52 -0
  70. package/internal/hardhat-network/provider/modules/debug.js.map +1 -0
  71. package/internal/hardhat-network/provider/modules/eth.d.ts +107 -0
  72. package/internal/hardhat-network/provider/modules/eth.d.ts.map +1 -0
  73. package/internal/hardhat-network/provider/modules/eth.js +1034 -0
  74. package/internal/hardhat-network/provider/modules/eth.js.map +1 -0
  75. package/internal/hardhat-network/provider/modules/evm.d.ts +32 -0
  76. package/internal/hardhat-network/provider/modules/evm.d.ts.map +1 -0
  77. package/internal/hardhat-network/provider/modules/evm.js +180 -0
  78. package/internal/hardhat-network/provider/modules/evm.js.map +1 -0
  79. package/internal/hardhat-network/provider/modules/hardhat.d.ts +54 -0
  80. package/internal/hardhat-network/provider/modules/hardhat.d.ts.map +1 -0
  81. package/internal/hardhat-network/provider/modules/hardhat.js +309 -0
  82. package/internal/hardhat-network/provider/modules/hardhat.js.map +1 -0
  83. package/internal/hardhat-network/provider/modules/net.d.ts +13 -0
  84. package/internal/hardhat-network/provider/modules/net.d.ts.map +1 -0
  85. package/internal/hardhat-network/provider/modules/net.js +47 -0
  86. package/internal/hardhat-network/provider/modules/net.js.map +1 -0
  87. package/internal/hardhat-network/provider/modules/personal.d.ts +9 -0
  88. package/internal/hardhat-network/provider/modules/personal.d.ts.map +1 -0
  89. package/internal/hardhat-network/provider/modules/personal.js +31 -0
  90. package/internal/hardhat-network/provider/modules/personal.js.map +1 -0
  91. package/internal/hardhat-network/provider/modules/web3.d.ts +11 -0
  92. package/internal/hardhat-network/provider/modules/web3.d.ts.map +1 -0
  93. package/internal/hardhat-network/provider/modules/web3.js +38 -0
  94. package/internal/hardhat-network/provider/modules/web3.js.map +1 -0
  95. package/internal/hardhat-network/provider/node.d.ts +197 -0
  96. package/internal/hardhat-network/provider/node.d.ts.map +1 -0
  97. package/internal/hardhat-network/provider/node.js +1866 -0
  98. package/internal/hardhat-network/provider/node.js.map +1 -0
  99. package/internal/hardhat-network/provider/provider.d.ts +1 -1
  100. package/internal/hardhat-network/provider/provider.d.ts.map +1 -1
  101. package/internal/hardhat-network/provider/provider.js +34 -27
  102. package/internal/hardhat-network/provider/provider.js.map +1 -1
  103. package/internal/hardhat-network/provider/transactions/FakeSenderAccessListEIP2930Transaction.d.ts +29 -0
  104. package/internal/hardhat-network/provider/transactions/FakeSenderAccessListEIP2930Transaction.d.ts.map +1 -0
  105. package/internal/hardhat-network/provider/transactions/FakeSenderAccessListEIP2930Transaction.js +137 -0
  106. package/internal/hardhat-network/provider/transactions/FakeSenderAccessListEIP2930Transaction.js.map +1 -0
  107. package/internal/hardhat-network/provider/transactions/FakeSenderEIP1559Transaction.d.ts +27 -0
  108. package/internal/hardhat-network/provider/transactions/FakeSenderEIP1559Transaction.d.ts.map +1 -0
  109. package/internal/hardhat-network/provider/transactions/FakeSenderEIP1559Transaction.js +137 -0
  110. package/internal/hardhat-network/provider/transactions/FakeSenderEIP1559Transaction.js.map +1 -0
  111. package/internal/hardhat-network/provider/transactions/FakeSenderTransaction.d.ts +33 -0
  112. package/internal/hardhat-network/provider/transactions/FakeSenderTransaction.d.ts.map +1 -0
  113. package/internal/hardhat-network/provider/transactions/FakeSenderTransaction.js +141 -0
  114. package/internal/hardhat-network/provider/transactions/FakeSenderTransaction.js.map +1 -0
  115. package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP1559Transaction.d.ts +30 -0
  116. package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP1559Transaction.d.ts.map +1 -0
  117. package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP1559Transaction.js +97 -0
  118. package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP1559Transaction.js.map +1 -0
  119. package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP2930Transaction.d.ts +30 -0
  120. package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP2930Transaction.d.ts.map +1 -0
  121. package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP2930Transaction.js +98 -0
  122. package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP2930Transaction.js.map +1 -0
  123. package/internal/hardhat-network/provider/transactions/ReadOnlyValidTransaction.d.ts +40 -0
  124. package/internal/hardhat-network/provider/transactions/ReadOnlyValidTransaction.d.ts.map +1 -0
  125. package/internal/hardhat-network/provider/transactions/ReadOnlyValidTransaction.js +91 -0
  126. package/internal/hardhat-network/provider/transactions/ReadOnlyValidTransaction.js.map +1 -0
  127. package/internal/hardhat-network/provider/transactions/ReadOnlyValidUnknownTypeTransaction.d.ts +32 -0
  128. package/internal/hardhat-network/provider/transactions/ReadOnlyValidUnknownTypeTransaction.d.ts.map +1 -0
  129. package/internal/hardhat-network/provider/transactions/ReadOnlyValidUnknownTypeTransaction.js +87 -0
  130. package/internal/hardhat-network/provider/transactions/ReadOnlyValidUnknownTypeTransaction.js.map +1 -0
  131. package/internal/hardhat-network/provider/types/HardhatBlockchainInterface.d.ts +17 -0
  132. package/internal/hardhat-network/provider/types/HardhatBlockchainInterface.d.ts.map +1 -0
  133. package/internal/hardhat-network/provider/types/HardhatBlockchainInterface.js +3 -0
  134. package/internal/hardhat-network/provider/types/HardhatBlockchainInterface.js.map +1 -0
  135. package/internal/hardhat-network/provider/utils/convertToEdr.d.ts +1 -1
  136. package/internal/hardhat-network/provider/utils/convertToEdr.d.ts.map +1 -1
  137. package/internal/hardhat-network/provider/utils/convertToEdr.js +4 -0
  138. package/internal/hardhat-network/provider/utils/convertToEdr.js.map +1 -1
  139. package/internal/hardhat-network/provider/utils/makeFakeSignature.d.ts +7 -0
  140. package/internal/hardhat-network/provider/utils/makeFakeSignature.d.ts.map +1 -0
  141. package/internal/hardhat-network/provider/utils/makeFakeSignature.js +31 -0
  142. package/internal/hardhat-network/provider/utils/makeFakeSignature.js.map +1 -0
  143. package/internal/hardhat-network/provider/utils/makeStateTrie.d.ts +4 -0
  144. package/internal/hardhat-network/provider/utils/makeStateTrie.d.ts.map +1 -0
  145. package/internal/hardhat-network/provider/utils/makeStateTrie.js +20 -0
  146. package/internal/hardhat-network/provider/utils/makeStateTrie.js.map +1 -0
  147. package/internal/hardhat-network/provider/utils/putGenesisBlock.d.ts +8 -0
  148. package/internal/hardhat-network/provider/utils/putGenesisBlock.d.ts.map +1 -0
  149. package/internal/hardhat-network/provider/utils/putGenesisBlock.js +37 -0
  150. package/internal/hardhat-network/provider/utils/putGenesisBlock.js.map +1 -0
  151. package/internal/hardhat-network/provider/utils/reorganizeTransactionsLists.d.ts +12 -0
  152. package/internal/hardhat-network/provider/utils/reorganizeTransactionsLists.d.ts.map +1 -0
  153. package/internal/hardhat-network/provider/utils/reorganizeTransactionsLists.js +62 -0
  154. package/internal/hardhat-network/provider/utils/reorganizeTransactionsLists.js.map +1 -0
  155. package/internal/hardhat-network/provider/utils/txMapToArray.d.ts +3 -0
  156. package/internal/hardhat-network/provider/utils/txMapToArray.d.ts.map +1 -0
  157. package/internal/hardhat-network/provider/utils/txMapToArray.js +12 -0
  158. package/internal/hardhat-network/provider/utils/txMapToArray.js.map +1 -0
  159. package/internal/hardhat-network/provider/vm/exit.d.ts +1 -1
  160. package/internal/hardhat-network/provider/vm/exit.d.ts.map +1 -1
  161. package/internal/hardhat-network/provider/vm/exit.js +4 -0
  162. package/internal/hardhat-network/provider/vm/exit.js.map +1 -1
  163. package/internal/hardhat-network/stack-traces/vm-debug-tracer.d.ts +46 -0
  164. package/internal/hardhat-network/stack-traces/vm-debug-tracer.d.ts.map +1 -0
  165. package/internal/hardhat-network/stack-traces/vm-debug-tracer.js +421 -0
  166. package/internal/hardhat-network/stack-traces/vm-debug-tracer.js.map +1 -0
  167. package/internal/hardhat-network/stack-traces/vm-tracer.d.ts +1 -1
  168. package/internal/hardhat-network/stack-traces/vm-tracer.d.ts.map +1 -1
  169. package/internal/solidity/parse.d.ts.map +1 -1
  170. package/internal/solidity/parse.js +5 -15
  171. package/internal/solidity/parse.js.map +1 -1
  172. package/package.json +8 -8
  173. package/recommended-gitignore.txt +3 -0
  174. package/src/builtin-tasks/compile.ts +2 -2
  175. package/src/common/napi-rs.ts +15 -0
  176. package/src/internal/core/errors-list.ts +1 -1
  177. package/src/internal/core/params/argumentTypes.ts +44 -0
  178. package/src/internal/core/tasks/task-definitions.ts +2 -2
  179. package/src/internal/hardhat-network/provider/provider.ts +52 -38
  180. package/src/internal/hardhat-network/provider/utils/convertToEdr.ts +14 -1
  181. package/src/internal/hardhat-network/provider/vm/exit.ts +15 -1
  182. package/src/internal/hardhat-network/stack-traces/vm-tracer.ts +1 -1
  183. package/src/internal/solidity/parse.ts +7 -16
@@ -0,0 +1,58 @@
1
+ /// <reference types="node" />
2
+ import { Block } from "@nomicfoundation/ethereumjs-block";
3
+ import { Common } from "@nomicfoundation/ethereumjs-common";
4
+ import { TypedTransaction } from "@nomicfoundation/ethereumjs-tx";
5
+ import { FilterParams } from "./node-types";
6
+ import { RpcLogOutput, RpcReceiptOutput } from "./output";
7
+ interface Reservation {
8
+ first: bigint;
9
+ last: bigint;
10
+ interval: bigint;
11
+ previousBlockStateRoot: Buffer;
12
+ previousBlockTotalDifficulty: bigint;
13
+ previousBlockBaseFeePerGas: bigint | undefined;
14
+ }
15
+ export declare class BlockchainData {
16
+ private _common;
17
+ private _blocksByNumber;
18
+ private _blocksByHash;
19
+ private _blocksByTransactions;
20
+ private _transactions;
21
+ private _transactionReceipts;
22
+ private _totalDifficulty;
23
+ private _blockReservations;
24
+ constructor(_common: Common);
25
+ reserveBlocks(first: bigint, count: bigint, interval: bigint, previousBlockStateRoot: Buffer, previousBlockTotalDifficulty: bigint, previousBlockBaseFeePerGas: bigint | undefined): void;
26
+ getBlockByNumber(blockNumber: bigint): Block | undefined;
27
+ getBlockByHash(blockHash: Buffer): Block | undefined;
28
+ getBlockByTransactionHash(transactionHash: Buffer): Block | undefined;
29
+ getTransaction(transactionHash: Buffer): TypedTransaction | undefined;
30
+ getTransactionReceipt(transactionHash: Buffer): RpcReceiptOutput | undefined;
31
+ getTotalDifficulty(blockHash: Buffer): bigint | undefined;
32
+ getLogs(filterParams: FilterParams): RpcLogOutput[];
33
+ addBlock(block: Block, totalDifficulty: bigint): void;
34
+ /**
35
+ * WARNING: this method can leave the blockchain in an invalid state where
36
+ * there are gaps between blocks. Ideally we should have a method that removes
37
+ * the given block and all the following blocks.
38
+ */
39
+ removeBlock(block: Block): void;
40
+ addTransaction(transaction: TypedTransaction): void;
41
+ addTransactionReceipt(receipt: RpcReceiptOutput): void;
42
+ isReservedBlock(blockNumber: bigint): boolean;
43
+ private _findBlockReservation;
44
+ /**
45
+ * WARNING: this method only removes the given reservation and can result in
46
+ * gaps in the reservations array. Ideally we should have a method that
47
+ * removes the given reservation and all the following reservations.
48
+ */
49
+ private _removeReservation;
50
+ /**
51
+ * Cancel and return the reservation that has block `blockNumber`
52
+ */
53
+ cancelReservationWithBlock(blockNumber: bigint): Reservation;
54
+ fulfillBlockReservation(blockNumber: bigint): void;
55
+ private _calculateTimestampForReservedBlock;
56
+ }
57
+ export {};
58
+ //# sourceMappingURL=BlockchainData.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BlockchainData.d.ts","sourceRoot":"","sources":["../../../src/internal/hardhat-network/provider/BlockchainData.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAC;AAC1D,OAAO,EAAE,MAAM,EAAE,MA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IG;IACI,WAAW,CAAC,KAAK,EAAE,KAAK;IAexB,cAAc,CAAC,WAAW,EAAE,gBAAgB;IAI5C,qBAAqB,CAAC,OAAO,EAAE,gBAAgB;IAI/C,eAAe,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO;IAIpD,OAAO,CAAC,qBAAqB;IAO7B;;;;OAIG;IACH,OAAO,CAAC,kBAAkB;IAY1B;;OAEG;IACI,0BAA0B,CAAC,WAAW,EAAE,MAAM,GAAG,WAAW;IAI5D,uBAAuB,CAAC,WAAW,EAAE,MAAM;IAiDlD,OAAO,CAAC,mCAAmC;CA6B5C"}
@@ -0,0 +1,178 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BlockchainData = void 0;
4
+ const ethereumjs_block_1 = require("@nomicfoundation/ethereumjs-block");
5
+ const ethereumjs_util_1 = require("@nomicfoundation/ethereumjs-util");
6
+ const ethereumjs_vm_1 = require("@nomicfoundation/ethereumjs-vm");
7
+ const errors_1 = require("../../core/errors");
8
+ const filter_1 = require("./filter");
9
+ class BlockchainData {
10
+ constructor(_common) {
11
+ this._common = _common;
12
+ this._blocksByNumber = new Map();
13
+ this._blocksByHash = new Map();
14
+ this._blocksByTransactions = new Map();
15
+ this._transactions = new Map();
16
+ this._transactionReceipts = new Map();
17
+ this._totalDifficulty = new Map();
18
+ this._blockReservations = new Array();
19
+ }
20
+ reserveBlocks(first, count, interval, previousBlockStateRoot, previousBlockTotalDifficulty, previousBlockBaseFeePerGas) {
21
+ const reservation = {
22
+ first,
23
+ last: first + count - 1n,
24
+ interval,
25
+ previousBlockStateRoot,
26
+ previousBlockTotalDifficulty,
27
+ previousBlockBaseFeePerGas,
28
+ };
29
+ this._blockReservations.push(reservation);
30
+ }
31
+ getBlockByNumber(blockNumber) {
32
+ return this._blocksByNumber.get(blockNumber);
33
+ }
34
+ getBlockByHash(blockHash) {
35
+ return this._blocksByHash.get((0, ethereumjs_util_1.bufferToHex)(blockHash));
36
+ }
37
+ getBlockByTransactionHash(transactionHash) {
38
+ return this._blocksByTransactions.get((0, ethereumjs_util_1.bufferToHex)(transactionHash));
39
+ }
40
+ getTransaction(transactionHash) {
41
+ return this._transactions.get((0, ethereumjs_util_1.bufferToHex)(transactionHash));
42
+ }
43
+ getTransactionReceipt(transactionHash) {
44
+ return this._transactionReceipts.get((0, ethereumjs_util_1.bufferToHex)(transactionHash));
45
+ }
46
+ getTotalDifficulty(blockHash) {
47
+ return this._totalDifficulty.get((0, ethereumjs_util_1.bufferToHex)(blockHash));
48
+ }
49
+ getLogs(filterParams) {
50
+ const logs = [];
51
+ for (let i = filterParams.fromBlock; i <= filterParams.toBlock; i++) {
52
+ const block = this.getBlockByNumber(i);
53
+ if (block === undefined ||
54
+ !(0, filter_1.bloomFilter)(new ethereumjs_vm_1.Bloom(block.header.logsBloom), filterParams.addresses, filterParams.normalizedTopics)) {
55
+ continue;
56
+ }
57
+ for (const transaction of block.transactions) {
58
+ const receipt = this.getTransactionReceipt(transaction.hash());
59
+ if (receipt !== undefined) {
60
+ logs.push(...(0, filter_1.filterLogs)(receipt.logs, {
61
+ fromBlock: filterParams.fromBlock,
62
+ toBlock: filterParams.toBlock,
63
+ addresses: filterParams.addresses,
64
+ normalizedTopics: filterParams.normalizedTopics,
65
+ }));
66
+ }
67
+ }
68
+ }
69
+ return logs;
70
+ }
71
+ addBlock(block, totalDifficulty) {
72
+ const blockHash = (0, ethereumjs_util_1.bufferToHex)(block.hash());
73
+ const blockNumber = block.header.number;
74
+ this._blocksByNumber.set(blockNumber, block);
75
+ this._blocksByHash.set(blockHash, block);
76
+ this._totalDifficulty.set(blockHash, totalDifficulty);
77
+ for (const transaction of block.transactions) {
78
+ const transactionHash = (0, ethereumjs_util_1.bufferToHex)(transaction.hash());
79
+ this._transactions.set(transactionHash, transaction);
80
+ this._blocksByTransactions.set(transactionHash, block);
81
+ }
82
+ }
83
+ /**
84
+ * WARNING: this method can leave the blockchain in an invalid state where
85
+ * there are gaps between blocks. Ideally we should have a method that removes
86
+ * the given block and all the following blocks.
87
+ */
88
+ removeBlock(block) {
89
+ const blockHash = (0, ethereumjs_util_1.bufferToHex)(block.hash());
90
+ const blockNumber = block.header.number;
91
+ this._blocksByNumber.delete(blockNumber);
92
+ this._blocksByHash.delete(blockHash);
93
+ this._totalDifficulty.delete(blockHash);
94
+ for (const transaction of block.transactions) {
95
+ const transactionHash = (0, ethereumjs_util_1.bufferToHex)(transaction.hash());
96
+ this._transactions.delete(transactionHash);
97
+ this._transactionReceipts.delete(transactionHash);
98
+ this._blocksByTransactions.delete(transactionHash);
99
+ }
100
+ }
101
+ addTransaction(transaction) {
102
+ this._transactions.set((0, ethereumjs_util_1.bufferToHex)(transaction.hash()), transaction);
103
+ }
104
+ addTransactionReceipt(receipt) {
105
+ this._transactionReceipts.set(receipt.transactionHash, receipt);
106
+ }
107
+ isReservedBlock(blockNumber) {
108
+ return this._findBlockReservation(blockNumber) !== -1;
109
+ }
110
+ _findBlockReservation(blockNumber) {
111
+ return this._blockReservations.findIndex((reservation) => reservation.first <= blockNumber && blockNumber <= reservation.last);
112
+ }
113
+ /**
114
+ * WARNING: this method only removes the given reservation and can result in
115
+ * gaps in the reservations array. Ideally we should have a method that
116
+ * removes the given reservation and all the following reservations.
117
+ */
118
+ _removeReservation(index) {
119
+ (0, errors_1.assertHardhatInvariant)(index in this._blockReservations, `Reservation ${index} does not exist`);
120
+ const reservation = this._blockReservations[index];
121
+ this._blockReservations.splice(index, 1);
122
+ return reservation;
123
+ }
124
+ /**
125
+ * Cancel and return the reservation that has block `blockNumber`
126
+ */
127
+ cancelReservationWithBlock(blockNumber) {
128
+ return this._removeReservation(this._findBlockReservation(blockNumber));
129
+ }
130
+ fulfillBlockReservation(blockNumber) {
131
+ // in addition to adding the given block, the reservation needs to be split
132
+ // in two in order to accomodate access to the given block.
133
+ const reservationIndex = this._findBlockReservation(blockNumber);
134
+ (0, errors_1.assertHardhatInvariant)(reservationIndex !== -1, `No reservation to fill for block number ${blockNumber.toString()}`);
135
+ // capture the timestamp before removing the reservation:
136
+ const timestamp = this._calculateTimestampForReservedBlock(blockNumber);
137
+ // split the block reservation:
138
+ const oldReservation = this._removeReservation(reservationIndex);
139
+ if (blockNumber !== oldReservation.first) {
140
+ this._blockReservations.push({
141
+ ...oldReservation,
142
+ last: blockNumber - 1n,
143
+ });
144
+ }
145
+ if (blockNumber !== oldReservation.last) {
146
+ this._blockReservations.push({
147
+ ...oldReservation,
148
+ first: blockNumber + 1n,
149
+ });
150
+ }
151
+ this.addBlock(ethereumjs_block_1.Block.fromBlockData({
152
+ header: {
153
+ number: blockNumber,
154
+ stateRoot: oldReservation.previousBlockStateRoot,
155
+ baseFeePerGas: oldReservation.previousBlockBaseFeePerGas,
156
+ timestamp,
157
+ },
158
+ }, {
159
+ common: this._common,
160
+ skipConsensusFormatValidation: true,
161
+ }), oldReservation.previousBlockTotalDifficulty);
162
+ }
163
+ _calculateTimestampForReservedBlock(blockNumber) {
164
+ const reservationIndex = this._findBlockReservation(blockNumber);
165
+ (0, errors_1.assertHardhatInvariant)(reservationIndex !== -1, `Block ${blockNumber.toString()} does not lie within any of the reservations.`);
166
+ const reservation = this._blockReservations[reservationIndex];
167
+ const blockNumberBeforeReservation = reservation.first - 1n;
168
+ const blockBeforeReservation = this.getBlockByNumber(blockNumberBeforeReservation);
169
+ (0, errors_1.assertHardhatInvariant)(blockBeforeReservation !== undefined, `Reservation after block ${blockNumberBeforeReservation.toString()} cannot be created because that block does not exist`);
170
+ const previousTimestamp = this.isReservedBlock(blockNumberBeforeReservation)
171
+ ? this._calculateTimestampForReservedBlock(blockNumberBeforeReservation)
172
+ : blockBeforeReservation.header.timestamp;
173
+ return (previousTimestamp +
174
+ reservation.interval * (blockNumber - reservation.first + 1n));
175
+ }
176
+ }
177
+ exports.BlockchainData = BlockchainData;
178
+ //# sourceMappingURL=BlockchainData.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BlockchainData.js","sourceRoot":"","sources":["../../../src/intern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,CAAC;QAEjE,IAAA,+BAAsB,EACpB,gBAAgB,KAAK,CAAC,CAAC,EACvB,SAAS,WAAW,CAAC,QAAQ,EAAE,+CAA+C,CAC/E,CAAC;QAEF,MAAM,WAAW,GAAG,IAAI,CAAC,kBAAkB,CAAC,gBAAgB,CAAC,CAAC;QAE9D,MAAM,4BAA4B,GAAG,WAAW,CAAC,KAAK,GAAG,EAAE,CAAC;QAE5D,MAAM,sBAAsB,GAAG,IAAI,CAAC,gBAAgB,CAClD,4BAA4B,CAC7B,CAAC;QACF,IAAA,+BAAsB,EACpB,sBAAsB,KAAK,SAAS,EACpC,2BAA2B,4BAA4B,CAAC,QAAQ,EAAE,sDAAsD,CACzH,CAAC;QAEF,MAAM,iBAAiB,GAAG,IAAI,CAAC,eAAe,CAAC,4BAA4B,CAAC;YAC1E,CAAC,CAAC,IAAI,CAAC,mCAAmC,CAAC,4BAA4B,CAAC;YACxE,CAAC,CAAC,sBAAsB,CAAC,MAAM,CAAC,SAAS,CAAC;QAE5C,OAAO,CACL,iBAAiB;YACjB,WAAW,CAAC,QAAQ,GAAG,CAAC,WAAW,GAAG,WAAW,CAAC,KAAK,GAAG,EAAE,CAAC,CAC9D,CAAC;IACJ,CAAC;CACF;AAhPD,wCAgPC"}
@@ -0,0 +1,24 @@
1
+ /// <reference types="node" />
2
+ import { Block } from "@nomicfoundation/ethereumjs-block";
3
+ import { Common } from "@nomicfoundation/ethereumjs-common";
4
+ import { TypedTransaction } from "@nomicfoundation/ethereumjs-tx";
5
+ import { BlockchainBase } from "./BlockchainBase";
6
+ import { FilterParams } from "./node-types";
7
+ import { RpcLogOutput } from "./output";
8
+ import { HardhatBlockchainInterface } from "./types/HardhatBlockchainInterface";
9
+ export declare class HardhatBlockchain extends BlockchainBase implements HardhatBlockchainInterface {
10
+ private _length;
11
+ constructor(common: Common);
12
+ getLatestBlockNumber(): bigint;
13
+ addBlock(block: Block): Promise<Block>;
14
+ reserveBlocks(count: bigint, interval: bigint, previousBlockStateRoot: Buffer, previousBlockTotalDifficulty: bigint, previousBlockBaseFeePerGas: bigint | undefined): void;
15
+ deleteLaterBlocks(block: Block): void;
16
+ getTotalDifficulty(blockHash: Buffer): Promise<bigint>;
17
+ getTransaction(transactionHash: Buffer): Promise<TypedTransaction | undefined>;
18
+ getBlockByTransactionHash(transactionHash: Buffer): Promise<Block | null>;
19
+ getTransactionReceipt(transactionHash: Buffer): Promise<import("./output").RpcReceiptOutput | null>;
20
+ getLogs(filterParams: FilterParams): Promise<RpcLogOutput[]>;
21
+ private _validateBlock;
22
+ protected _delBlock(blockNumber: bigint): void;
23
+ }
24
+ //# sourceMappingURL=HardhatBlockchain.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HardhatBlockchain.d.ts","sourceRoot":"","sources":["../../../src/internal/hardhat-network/provider/HardhatBlockchain.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAC;AAC1D,OAAO,EAAE,MAAM,EAAE,MAAM,oCAAoC,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAGlE,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,0BAA0B,EAAE,MAAM,oCAAoC,CAAC;AAIhF,qBAAa,iBACX,SAAQ,cACR,YAAW,0BAA0B;IAErC,OAAO,CAAC,OAAO,CAAM;gBAET,MAAM,EAAE,MAAM;IAInB,oBAAoB,IAAI,MAAM;IAIxB,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;IAQ5C,aAAa,CAClB,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,EAChB,sBAAsB,EAAE,MAAM,EAC9B,4BAA4B,EAAE,MAAM,EACpC,0BAA0B,EAAE,MAAM,GAAG,SAAS;IAYzC,iBAAiB,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI;IAS/B,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAQtD,cAAc,CACzB,eAAe,EAAE,MAAM,GACtB,OAAO,CAAC,gBAAgB,GAAG,SAAS,CAAC;IAI3B,yBAAyB,CACpC,eAAe,EAAE,MAAM,GACtB,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC;IAKX,qBAAqB,CAAC,eAAe,EAAE,MAAM;IAI7C,OAAO,CAAC,YAAY,EAAE,YAAY,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC;IAIzE,OAAO,CAAC,cAAc;IAqBtB,SAAS,CAAC,SAAS,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI;CAI/C"}
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HardhatBlockchain = void 0;
4
+ const ethereumjs_util_1 = require("@nomicfoundation/ethereumjs-util");
5
+ const BlockchainBase_1 = require("./BlockchainBase");
6
+ /* eslint-disable @nomicfoundation/hardhat-internal-rules/only-hardhat-error */
7
+ class HardhatBlockchain extends BlockchainBase_1.BlockchainBase {
8
+ constructor(common) {
9
+ super(common);
10
+ this._length = 0n;
11
+ }
12
+ getLatestBlockNumber() {
13
+ return BigInt(this._length - 1n);
14
+ }
15
+ async addBlock(block) {
16
+ this._validateBlock(block);
17
+ const totalDifficulty = await this._computeTotalDifficulty(block);
18
+ this._data.addBlock(block, totalDifficulty);
19
+ this._length += 1n;
20
+ return block;
21
+ }
22
+ reserveBlocks(count, interval, previousBlockStateRoot, previousBlockTotalDifficulty, previousBlockBaseFeePerGas) {
23
+ super.reserveBlocks(count, interval, previousBlockStateRoot, previousBlockTotalDifficulty, previousBlockBaseFeePerGas);
24
+ this._length += count;
25
+ }
26
+ deleteLaterBlocks(block) {
27
+ const actual = this._data.getBlockByHash(block.hash());
28
+ if (actual === undefined) {
29
+ throw new Error("Invalid block");
30
+ }
31
+ this._delBlock(actual.header.number + 1n);
32
+ }
33
+ async getTotalDifficulty(blockHash) {
34
+ const totalDifficulty = this._data.getTotalDifficulty(blockHash);
35
+ if (totalDifficulty === undefined) {
36
+ throw new Error("Block not found");
37
+ }
38
+ return totalDifficulty;
39
+ }
40
+ async getTransaction(transactionHash) {
41
+ return this.getLocalTransaction(transactionHash);
42
+ }
43
+ async getBlockByTransactionHash(transactionHash) {
44
+ const block = this._data.getBlockByTransactionHash(transactionHash);
45
+ return block ?? null;
46
+ }
47
+ async getTransactionReceipt(transactionHash) {
48
+ return this._data.getTransactionReceipt(transactionHash) ?? null;
49
+ }
50
+ async getLogs(filterParams) {
51
+ return this._data.getLogs(filterParams);
52
+ }
53
+ _validateBlock(block) {
54
+ const blockNumber = block.header.number;
55
+ const parentHash = block.header.parentHash;
56
+ const parent = this._data.getBlockByNumber(BigInt(blockNumber - 1n));
57
+ if (BigInt(this._length) !== blockNumber) {
58
+ throw new Error(`Invalid block number ${blockNumber}. Expected ${this._length}.`);
59
+ }
60
+ if ((blockNumber === 0n && !parentHash.equals((0, ethereumjs_util_1.zeros)(32))) ||
61
+ (blockNumber > 0 &&
62
+ parent !== undefined &&
63
+ !parentHash.equals(parent.hash()))) {
64
+ throw new Error("Invalid parent hash");
65
+ }
66
+ }
67
+ _delBlock(blockNumber) {
68
+ super._delBlock(blockNumber);
69
+ this._length = blockNumber;
70
+ }
71
+ }
72
+ exports.HardhatBlockchain = HardhatBlockchain;
73
+ //# sourceMappingURL=HardhatBlockchain.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HardhatBlockchain.js","sourceRoot":"","sources":["../../../src/internal/hardhat-network/provider/HardhatBlockchain.ts"],"names":[],"mappings":";;;AAGA,sEAAyD;AAEzD,qDAAkD;AAKlD,+EAA+E;AAE/E,MAAa,iBACX,SAAQ,+BAAc;IAKtB,YAAY,MAAc;QACxB,KAAK,CAAC,MAAM,CAAC,CAAC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BAAqB,CAAC,CAAC;SACxC;IACH,CAAC;IAES,SAAS,CAAC,WAAmB;QACrC,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;QAC7B,IAAI,CAAC,OAAO,GAAG,WAAW,CAAC;IAC7B,CAAC;CACF;AAtGD,8CAsGC"}
@@ -0,0 +1,26 @@
1
+ import { TypedTransaction } from "@nomicfoundation/ethereumjs-tx";
2
+ import { List as ImmutableList, Map as ImmutableMap, Record as ImmutableRecord } from "immutable";
3
+ export interface OrderedTransaction {
4
+ orderId: number;
5
+ data: TypedTransaction;
6
+ }
7
+ interface ImmutableOrderedTransaction {
8
+ orderId: number;
9
+ fakeFrom: string | undefined;
10
+ data: string;
11
+ txType: number;
12
+ }
13
+ export declare const makeSerializedTransaction: ImmutableRecord.Factory<ImmutableOrderedTransaction>;
14
+ export type SerializedTransaction = ImmutableRecord<ImmutableOrderedTransaction>;
15
+ export type SenderTransactions = ImmutableList<SerializedTransaction>;
16
+ export type AddressToTransactions = ImmutableMap<string, SenderTransactions>;
17
+ export type HashToTransaction = ImmutableMap<string, SerializedTransaction>;
18
+ export interface PoolState {
19
+ pendingTransactions: AddressToTransactions;
20
+ queuedTransactions: AddressToTransactions;
21
+ hashToTransaction: HashToTransaction;
22
+ blockGasLimit: string;
23
+ }
24
+ export declare const makePoolState: ImmutableRecord.Factory<PoolState>;
25
+ export {};
26
+ //# sourceMappingURL=PoolState.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PoolState.d.ts","sourceRoot":"","sources":["../../../src/internal/hardhat-network/provider/PoolState.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAClE,OAAO,EACL,IAAI,IAAI,aAAa,EACrB,GAAG,IAAI,YAAY,EACnB,MAAM,IAAI,eAAe,EAC1B,MAAM,WAAW,CAAC;AAInB,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,gBAAgB,CAAC;CACxB;AAED,UAAU,2BAA2B;IACnC,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,eAAO,MAAM,yBAAyB,sDAMlC,CAAC;AAEL,MAAM,MAAM,qBAAqB,GAC/B,eAAe,CAAC,2BAA2B,CAAC,CAAC;AAC/C,MAAM,MAAM,kBAAkB,GAAG,aAAa,CAAC,qBAAqB,CAAC,CAAC;AACtE,MAAM,MAAM,qBAAqB,GAAG,YAAY,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;AAC7E,MAAM,MAAM,iBAAiB,GAAG,YAAY,CAAC,MAAM,EAAE,qBAAqB,CAAC,CAAC;AAE5E,MAAM,WAAW,SAAS;IACxB,mBAAmB,EAAE,qBAAqB,CAAC;IAC3C,kBAAkB,EAAE,qBAAqB,CAAC;IAC1C,iBAAiB,EAAE,iBAAiB,CAAC;IACrC,aAAa,EAAE,MAAM,CAAC;CACvB;AAED,eAAO,MAAM,aAAa,oCAKxB,CAAC"}
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.makePoolState = exports.makeSerializedTransaction = void 0;
27
+ const immutable_1 = require("immutable");
28
+ const BigIntUtils = __importStar(require("../../util/bigint"));
29
+ exports.makeSerializedTransaction = (0, immutable_1.Record)({
30
+ orderId: 0,
31
+ fakeFrom: undefined,
32
+ data: "",
33
+ txType: 0,
34
+ });
35
+ exports.makePoolState = (0, immutable_1.Record)({
36
+ pendingTransactions: (0, immutable_1.Map)(),
37
+ queuedTransactions: (0, immutable_1.Map)(),
38
+ hashToTransaction: (0, immutable_1.Map)(),
39
+ blockGasLimit: BigIntUtils.toHex(9500000),
40
+ });
41
+ //# sourceMappingURL=PoolState.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PoolState.js","sourceRoot":"","sources":["../../../src/internal/hardhat-network/provider/PoolState.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,yCAImB;AAEnB,+DAAiD;AAcpC,QAAA,yBAAyB,GACpC,IAAA,kBAAe,EAA8B;IAC3C,OAAO,EAAE,CAAC;IACV,QAAQ,EAAE,SAAS;IACnB,IAAI,EAAE,EAAE;IACR,MAAM,EAAE,CAAC;CACV,CAAC,CAAC;AAeQ,QAAA,aAAa,GAAG,IAAA,kBAAe,EAAY;IACtD,mBAAmB,EAAE,IAAA,eAAY,GAA8B;IAC/D,kBAAkB,EAAE,IAAA,eAAY,GAA8B;IAC9D,iBAAiB,EAAE,IAAA,eAAY,GAAiC;IAChE,aAAa,EAAE,WAAW,CAAC,KAAK,CAAC,OAAO,CAAC;CAC1C,CAAC,CAAC"}
@@ -0,0 +1,32 @@
1
+ import { TypedTransaction } from "@nomicfoundation/ethereumjs-tx";
2
+ import { MempoolOrder } from "./node-types";
3
+ import { OrderedTransaction } from "./PoolState";
4
+ /**
5
+ * A queue of transactions in the order that they could be mined in the next
6
+ * block.
7
+ *
8
+ * A transaction being part of this queue doesn't mean that it will be mined in
9
+ * the next block, as it may not meet the required criteria to be included or
10
+ * may not fit within the block.
11
+ *
12
+ * If after getting the next transaction in the queue you decided not to mine
13
+ * it, the other transactions that belong to that sender MUST be removed from
14
+ * the queue by calling the #removeLastSenderTransactions() method.
15
+ **/
16
+ export declare class TransactionQueue {
17
+ private readonly _queuedTransactions;
18
+ private readonly _heap;
19
+ private _lastTransactionSender?;
20
+ /**
21
+ * Creates a TransactionQueue.
22
+ *
23
+ * @param pendingTransactions A map of sender to a list of their transactions,
24
+ * sorted by nonce and without nonce gaps.
25
+ * @param baseFee The base fee of the next block, if it's going to use EIP-1559
26
+ */
27
+ constructor(pendingTransactions: Map<string, OrderedTransaction[]>, mempoolOrder: MempoolOrder, baseFee?: bigint);
28
+ getNextTransaction(): TypedTransaction | undefined;
29
+ removeLastSenderTransactions(): void;
30
+ private _moveFirstEnqueuedTransactionToHeap;
31
+ }
32
+ //# sourceMappingURL=TransactionQueue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TransactionQueue.d.ts","sourceRoot":"","sources":["../../../src/internal/hardhat-network/provider/TransactionQueue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAKlE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAmEjD;;;;;;;;;;;IAWI;AACJ,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CACxB;IAEZ,OAAO,CAAC,QAAQ,CAAC,KAAK,CAA2B;IAEjD,OAAO,CAAC,sBAAsB,CAAC,CAAS;IAExC;;;;;;OAMG;gBAED,mBAAmB,EAAE,GAAG,CAAC,MAAM,EAAE,kBAAkB,EAAE,CAAC,EACtD,YAAY,EAAE,YAAY,EAC1B,OAAO,CAAC,EAAE,MAAM;IAkBX,kBAAkB,IAAI,gBAAgB,GAAG,SAAS;IAclD,4BAA4B;IAYnC,OAAO,CAAC,mCAAmC;CAU5C"}
@@ -0,0 +1,130 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.TransactionQueue = void 0;
30
+ const heap_1 = __importDefault(require("mnemonist/heap"));
31
+ const errors_1 = require("../../core/providers/errors");
32
+ const BigIntUtils = __importStar(require("../../util/bigint"));
33
+ function getEffectiveMinerFee(tx, baseFee) {
34
+ // This mimics the EIP-1559 normalize_transaction function
35
+ const maxFeePerGas = "gasPrice" in tx.data ? tx.data.gasPrice : tx.data.maxFeePerGas;
36
+ const maxPriorityFeePerGas = "gasPrice" in tx.data ? tx.data.gasPrice : tx.data.maxPriorityFeePerGas;
37
+ if (baseFee === undefined) {
38
+ return maxFeePerGas;
39
+ }
40
+ return BigIntUtils.min(maxPriorityFeePerGas, maxFeePerGas - baseFee);
41
+ }
42
+ function decreasingOrderEffectiveMinerFeeComparator(left, right, baseFee) {
43
+ const leftEffectiveMinerFee = getEffectiveMinerFee(left, baseFee);
44
+ const rightEffectiveMinerFee = getEffectiveMinerFee(right, baseFee);
45
+ const cmp = BigIntUtils.cmp(rightEffectiveMinerFee, leftEffectiveMinerFee);
46
+ if (cmp !== 0) {
47
+ return cmp;
48
+ }
49
+ // If two txs have the same effective miner fee we want to sort them
50
+ // in increasing order by orderId.
51
+ return left.orderId - right.orderId;
52
+ }
53
+ function decreasingOrderComparator(left, right) {
54
+ return left.orderId - right.orderId;
55
+ }
56
+ function getOrderedTransactionHeap(mempoolOrder, baseFee) {
57
+ switch (mempoolOrder) {
58
+ case "priority":
59
+ return new heap_1.default((a, b) => decreasingOrderEffectiveMinerFeeComparator(a, b, baseFee));
60
+ case "fifo":
61
+ return new heap_1.default((a, b) => decreasingOrderComparator(a, b));
62
+ default:
63
+ // eslint-disable-next-line @nomicfoundation/hardhat-internal-rules/only-hardhat-error
64
+ throw new errors_1.InvalidInputError(`Invalid mempool order: ${mempoolOrder}`);
65
+ }
66
+ }
67
+ /**
68
+ * A queue of transactions in the order that they could be mined in the next
69
+ * block.
70
+ *
71
+ * A transaction being part of this queue doesn't mean that it will be mined in
72
+ * the next block, as it may not meet the required criteria to be included or
73
+ * may not fit within the block.
74
+ *
75
+ * If after getting the next transaction in the queue you decided not to mine
76
+ * it, the other transactions that belong to that sender MUST be removed from
77
+ * the queue by calling the #removeLastSenderTransactions() method.
78
+ **/
79
+ class TransactionQueue {
80
+ /**
81
+ * Creates a TransactionQueue.
82
+ *
83
+ * @param pendingTransactions A map of sender to a list of their transactions,
84
+ * sorted by nonce and without nonce gaps.
85
+ * @param baseFee The base fee of the next block, if it's going to use EIP-1559
86
+ */
87
+ constructor(pendingTransactions, mempoolOrder, baseFee) {
88
+ this._queuedTransactions = new Map();
89
+ this._heap = getOrderedTransactionHeap(mempoolOrder, baseFee);
90
+ for (const [address, txList] of pendingTransactions) {
91
+ if (baseFee === undefined && txList.some((tx) => tx.data.type === 2)) {
92
+ // eslint-disable-next-line @nomicfoundation/hardhat-internal-rules/only-hardhat-error
93
+ throw new errors_1.InternalError("Trying to initialize and sort a mempool with an EIP-1559 tx but no base fee");
94
+ }
95
+ const [firstTx, ...remainingTxs] = txList;
96
+ this._heap.push(firstTx);
97
+ this._queuedTransactions.set(address, remainingTxs);
98
+ }
99
+ }
100
+ getNextTransaction() {
101
+ if (this._lastTransactionSender !== undefined) {
102
+ this._moveFirstEnqueuedTransactionToHeap(this._lastTransactionSender);
103
+ }
104
+ const nextTx = this._heap.pop();
105
+ if (nextTx === undefined) {
106
+ return undefined;
107
+ }
108
+ this._lastTransactionSender = nextTx.data.getSenderAddress().toString();
109
+ return nextTx.data;
110
+ }
111
+ removeLastSenderTransactions() {
112
+ if (this._lastTransactionSender === undefined) {
113
+ // eslint-disable-next-line @nomicfoundation/hardhat-internal-rules/only-hardhat-error
114
+ throw new errors_1.InternalError("TransactionQueue#removeLastSenderTransactions called before TransactionQueue#getNextTransaction");
115
+ }
116
+ this._queuedTransactions.delete(this._lastTransactionSender);
117
+ this._lastTransactionSender = undefined;
118
+ }
119
+ _moveFirstEnqueuedTransactionToHeap(sender) {
120
+ const queue = this._queuedTransactions.get(sender);
121
+ if (queue === undefined || queue.length === 0) {
122
+ return;
123
+ }
124
+ const [first, ...rest] = queue;
125
+ this._heap.push(first);
126
+ this._queuedTransactions.set(sender, rest);
127
+ }
128
+ }
129
+ exports.TransactionQueue = TransactionQueue;
130
+ //# sourceMappingURL=TransactionQueue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TransactionQueue.js","sourceRoot":"","sources":["../../../src/internal/hardhat-network/provider/TransactionQueue.ts"],"names":[],"mappings":";;;;;;;;;;;;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