@feelyourprotocol/vm 8141.0.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.
- package/LICENSE +373 -0
- package/README.md +583 -0
- package/dist/cjs/bloom/index.d.ts +29 -0
- package/dist/cjs/bloom/index.d.ts.map +1 -0
- package/dist/cjs/bloom/index.js +76 -0
- package/dist/cjs/bloom/index.js.map +1 -0
- package/dist/cjs/buildBlock.d.ts +118 -0
- package/dist/cjs/buildBlock.d.ts.map +1 -0
- package/dist/cjs/buildBlock.js +363 -0
- package/dist/cjs/buildBlock.js.map +1 -0
- package/dist/cjs/constructors.d.ts +9 -0
- package/dist/cjs/constructors.d.ts.map +1 -0
- package/dist/cjs/constructors.js +75 -0
- package/dist/cjs/constructors.js.map +1 -0
- package/dist/cjs/emitEVMProfile.d.ts +9 -0
- package/dist/cjs/emitEVMProfile.d.ts.map +1 -0
- package/dist/cjs/emitEVMProfile.js +130 -0
- package/dist/cjs/emitEVMProfile.js.map +1 -0
- package/dist/cjs/index.d.ts +11 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +36 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/params.d.ts +3 -0
- package/dist/cjs/params.d.ts.map +1 -0
- package/dist/cjs/params.js +105 -0
- package/dist/cjs/params.js.map +1 -0
- package/dist/cjs/requests.d.ts +11 -0
- package/dist/cjs/requests.d.ts.map +1 -0
- package/dist/cjs/requests.js +208 -0
- package/dist/cjs/requests.js.map +1 -0
- package/dist/cjs/runBlock.d.ts +35 -0
- package/dist/cjs/runBlock.d.ts.map +1 -0
- package/dist/cjs/runBlock.js +797 -0
- package/dist/cjs/runBlock.js.map +1 -0
- package/dist/cjs/runFrameTx.d.ts +18 -0
- package/dist/cjs/runFrameTx.d.ts.map +1 -0
- package/dist/cjs/runFrameTx.js +313 -0
- package/dist/cjs/runFrameTx.js.map +1 -0
- package/dist/cjs/runTx.d.ts +18 -0
- package/dist/cjs/runTx.d.ts.map +1 -0
- package/dist/cjs/runTx.js +900 -0
- package/dist/cjs/runTx.js.map +1 -0
- package/dist/cjs/types.d.ts +452 -0
- package/dist/cjs/types.d.ts.map +1 -0
- package/dist/cjs/types.js +3 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/cjs/vm.d.ts +75 -0
- package/dist/cjs/vm.d.ts.map +1 -0
- package/dist/cjs/vm.js +111 -0
- package/dist/cjs/vm.js.map +1 -0
- package/dist/esm/bloom/index.d.ts +29 -0
- package/dist/esm/bloom/index.d.ts.map +1 -0
- package/dist/esm/bloom/index.js +72 -0
- package/dist/esm/bloom/index.js.map +1 -0
- package/dist/esm/buildBlock.d.ts +118 -0
- package/dist/esm/buildBlock.d.ts.map +1 -0
- package/dist/esm/buildBlock.js +358 -0
- package/dist/esm/buildBlock.js.map +1 -0
- package/dist/esm/constructors.d.ts +9 -0
- package/dist/esm/constructors.d.ts.map +1 -0
- package/dist/esm/constructors.js +72 -0
- package/dist/esm/constructors.js.map +1 -0
- package/dist/esm/emitEVMProfile.d.ts +9 -0
- package/dist/esm/emitEVMProfile.d.ts.map +1 -0
- package/dist/esm/emitEVMProfile.js +127 -0
- package/dist/esm/emitEVMProfile.js.map +1 -0
- package/dist/esm/index.d.ts +11 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +11 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/params.d.ts +3 -0
- package/dist/esm/params.d.ts.map +1 -0
- package/dist/esm/params.js +102 -0
- package/dist/esm/params.js.map +1 -0
- package/dist/esm/requests.d.ts +11 -0
- package/dist/esm/requests.d.ts.map +1 -0
- package/dist/esm/requests.js +204 -0
- package/dist/esm/requests.js.map +1 -0
- package/dist/esm/runBlock.d.ts +35 -0
- package/dist/esm/runBlock.d.ts.map +1 -0
- package/dist/esm/runBlock.js +790 -0
- package/dist/esm/runBlock.js.map +1 -0
- package/dist/esm/runFrameTx.d.ts +18 -0
- package/dist/esm/runFrameTx.d.ts.map +1 -0
- package/dist/esm/runFrameTx.js +310 -0
- package/dist/esm/runFrameTx.js.map +1 -0
- package/dist/esm/runTx.d.ts +18 -0
- package/dist/esm/runTx.d.ts.map +1 -0
- package/dist/esm/runTx.js +896 -0
- package/dist/esm/runTx.js.map +1 -0
- package/dist/esm/types.d.ts +452 -0
- package/dist/esm/types.d.ts.map +1 -0
- package/dist/esm/types.js +2 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/vm.d.ts +75 -0
- package/dist/esm/vm.d.ts.map +1 -0
- package/dist/esm/vm.js +107 -0
- package/dist/esm/vm.js.map +1 -0
- package/dist/tsconfig.prod.cjs.tsbuildinfo +1 -0
- package/dist/tsconfig.prod.esm.tsbuildinfo +1 -0
- package/package.json +117 -0
- package/src/bloom/index.ts +83 -0
- package/src/buildBlock.ts +470 -0
- package/src/constructors.ts +91 -0
- package/src/emitEVMProfile.ts +151 -0
- package/src/index.ts +10 -0
- package/src/params.ts +104 -0
- package/src/requests.ts +293 -0
- package/src/runBlock.ts +1022 -0
- package/src/runFrameTx.ts +411 -0
- package/src/runTx.ts +1203 -0
- package/src/types.ts +511 -0
- package/src/vm.ts +147 -0
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
import { createBlock, createSealedCliqueBlock, genRequestsRoot, genTransactionsTrieRoot, genWithdrawalsTrieRoot, } from '@feelyourprotocol/block';
|
|
2
|
+
import { ConsensusType, Hardfork } from '@feelyourprotocol/common';
|
|
3
|
+
import { MerklePatriciaTrie } from '@feelyourprotocol/mpt';
|
|
4
|
+
import { RLP } from '@feelyourprotocol/rlp';
|
|
5
|
+
import { Blob4844Tx, NetworkWrapperType, createMinimal4844TxFromNetworkWrapper, } from '@feelyourprotocol/tx';
|
|
6
|
+
import { Address, BIGINT_0, BIGINT_1, BIGINT_2, EthereumJSErrorWithoutCode, GWEI_TO_WEI, KECCAK256_RLP, TypeOutput, createWithdrawal, createZeroAddress, toBytes, toType, } from '@feelyourprotocol/util';
|
|
7
|
+
import { sha256 } from '@noble/hashes/sha2.js';
|
|
8
|
+
import { Bloom } from "./bloom/index.js";
|
|
9
|
+
import { runTx } from "./index.js";
|
|
10
|
+
import { accumulateRequests } from "./requests.js";
|
|
11
|
+
import { accumulateParentBeaconBlockRoot, accumulateParentBlockHash, calculateMinerReward, encodeReceipt, rewardAccount, } from "./runBlock.js";
|
|
12
|
+
export const BuildStatus = {
|
|
13
|
+
Reverted: 'reverted',
|
|
14
|
+
Build: 'build',
|
|
15
|
+
Pending: 'pending',
|
|
16
|
+
};
|
|
17
|
+
export class BlockBuilder {
|
|
18
|
+
get transactionReceipts() {
|
|
19
|
+
return this.transactionResults.map((result) => result.receipt);
|
|
20
|
+
}
|
|
21
|
+
get minerValue() {
|
|
22
|
+
return this._minerValue;
|
|
23
|
+
}
|
|
24
|
+
constructor(vm, opts) {
|
|
25
|
+
/**
|
|
26
|
+
* The cumulative gas used by the transactions added to the block.
|
|
27
|
+
*/
|
|
28
|
+
this.gasUsed = BIGINT_0;
|
|
29
|
+
/**
|
|
30
|
+
* The cumulative blob gas used by the blobs in a block
|
|
31
|
+
*/
|
|
32
|
+
this.blobGasUsed = BIGINT_0;
|
|
33
|
+
/**
|
|
34
|
+
* Value of the block, represented by the final transaction fees
|
|
35
|
+
* accruing to the miner.
|
|
36
|
+
*/
|
|
37
|
+
this._minerValue = BIGINT_0;
|
|
38
|
+
this.transactions = [];
|
|
39
|
+
this.transactionResults = [];
|
|
40
|
+
this.checkpointed = false;
|
|
41
|
+
this.blockStatus = { status: BuildStatus.Pending };
|
|
42
|
+
this.vm = vm;
|
|
43
|
+
this.blockOpts = { putBlockIntoBlockchain: true, ...opts.blockOpts, common: this.vm.common };
|
|
44
|
+
this.headerData = {
|
|
45
|
+
...opts.headerData,
|
|
46
|
+
parentHash: opts.headerData?.parentHash ?? opts.parentBlock.hash(),
|
|
47
|
+
number: opts.headerData?.number ?? opts.parentBlock.header.number + BIGINT_1,
|
|
48
|
+
gasLimit: opts.headerData?.gasLimit ?? opts.parentBlock.header.gasLimit,
|
|
49
|
+
timestamp: opts.headerData?.timestamp ?? Math.round(Date.now() / 1000),
|
|
50
|
+
};
|
|
51
|
+
this.withdrawals = opts.withdrawals?.map(createWithdrawal);
|
|
52
|
+
if (this.vm.common.isActivatedEIP(1559) &&
|
|
53
|
+
typeof this.headerData.baseFeePerGas === 'undefined') {
|
|
54
|
+
if (this.headerData.number === vm.common.hardforkBlock(Hardfork.London)) {
|
|
55
|
+
this.headerData.baseFeePerGas = vm.common.param('initialBaseFee');
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
this.headerData.baseFeePerGas = opts.parentBlock.header.calcNextBaseFee();
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (typeof this.headerData.gasLimit === 'undefined') {
|
|
62
|
+
if (this.headerData.number === vm.common.hardforkBlock(Hardfork.London)) {
|
|
63
|
+
this.headerData.gasLimit = opts.parentBlock.header.gasLimit * BIGINT_2;
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
this.headerData.gasLimit = opts.parentBlock.header.gasLimit;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (this.vm.common.isActivatedEIP(4844) &&
|
|
70
|
+
typeof this.headerData.excessBlobGas === 'undefined') {
|
|
71
|
+
this.headerData.excessBlobGas = opts.parentBlock.header.calcNextExcessBlobGas(this.vm.common);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Throws if the block has already been built or reverted.
|
|
76
|
+
*/
|
|
77
|
+
checkStatus() {
|
|
78
|
+
if (this.blockStatus.status === BuildStatus.Build) {
|
|
79
|
+
throw EthereumJSErrorWithoutCode('Block has already been built');
|
|
80
|
+
}
|
|
81
|
+
if (this.blockStatus.status === BuildStatus.Reverted) {
|
|
82
|
+
throw EthereumJSErrorWithoutCode('State has already been reverted');
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
getStatus() {
|
|
86
|
+
return this.blockStatus;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Calculates and returns the transactionsTrie for the block.
|
|
90
|
+
*/
|
|
91
|
+
async transactionsTrie() {
|
|
92
|
+
return genTransactionsTrieRoot(this.transactions, new MerklePatriciaTrie({ common: this.vm.common }));
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Calculates and returns the logs bloom for the block.
|
|
96
|
+
*/
|
|
97
|
+
logsBloom() {
|
|
98
|
+
const bloom = new Bloom(undefined, this.vm.common);
|
|
99
|
+
for (const txResult of this.transactionResults) {
|
|
100
|
+
// Combine blooms via bitwise OR
|
|
101
|
+
bloom.or(txResult.bloom);
|
|
102
|
+
}
|
|
103
|
+
return bloom.bitvector;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Calculates and returns the receiptTrie for the block.
|
|
107
|
+
*/
|
|
108
|
+
async receiptTrie() {
|
|
109
|
+
if (this.transactionResults.length === 0) {
|
|
110
|
+
return KECCAK256_RLP;
|
|
111
|
+
}
|
|
112
|
+
const receiptTrie = new MerklePatriciaTrie({ common: this.vm.common });
|
|
113
|
+
for (const [i, txResult] of this.transactionResults.entries()) {
|
|
114
|
+
const tx = this.transactions[i];
|
|
115
|
+
const encodedReceipt = encodeReceipt(txResult.receipt, tx.type);
|
|
116
|
+
await receiptTrie.put(RLP.encode(i), encodedReceipt);
|
|
117
|
+
}
|
|
118
|
+
return receiptTrie.root();
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Adds the block miner reward to the coinbase account.
|
|
122
|
+
*/
|
|
123
|
+
async rewardMiner() {
|
|
124
|
+
const minerReward = this.vm.common.param('minerReward');
|
|
125
|
+
const reward = calculateMinerReward(minerReward, 0);
|
|
126
|
+
const coinbase = this.headerData.coinbase !== undefined
|
|
127
|
+
? new Address(toBytes(this.headerData.coinbase))
|
|
128
|
+
: createZeroAddress();
|
|
129
|
+
await rewardAccount(this.vm.evm, coinbase, reward, this.vm.common);
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Adds the withdrawal amount to the withdrawal address
|
|
133
|
+
*/
|
|
134
|
+
async processWithdrawals() {
|
|
135
|
+
for (const withdrawal of this.withdrawals ?? []) {
|
|
136
|
+
const { address, amount } = withdrawal;
|
|
137
|
+
// If there is no amount to add, skip touching the account
|
|
138
|
+
// as per the implementation of other clients geth/nethermind
|
|
139
|
+
// although this should never happen as no withdrawals with 0
|
|
140
|
+
// amount should ever land up here.
|
|
141
|
+
if (amount === BIGINT_0)
|
|
142
|
+
continue;
|
|
143
|
+
// Withdrawal amount is represented in Gwei so needs to be
|
|
144
|
+
// converted to wei
|
|
145
|
+
await rewardAccount(this.vm.evm, address, amount * GWEI_TO_WEI, this.vm.common);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Run and add a transaction to the block being built.
|
|
150
|
+
* Please note that this modifies the state of the VM.
|
|
151
|
+
* Throws if the transaction's gasLimit is greater than
|
|
152
|
+
* the remaining gas in the block.
|
|
153
|
+
*/
|
|
154
|
+
async addTransaction(tx, { skipHardForkValidation, allowNoBlobs, } = {}) {
|
|
155
|
+
this.checkStatus();
|
|
156
|
+
if (!this.checkpointed) {
|
|
157
|
+
await this.vm.evm.journal.checkpoint();
|
|
158
|
+
this.checkpointed = true;
|
|
159
|
+
}
|
|
160
|
+
// According to the Yellow Paper, a transaction's gas limit
|
|
161
|
+
// cannot be greater than the remaining gas in the block
|
|
162
|
+
const blockGasLimit = toType(this.headerData.gasLimit, TypeOutput.BigInt);
|
|
163
|
+
const blobGasPerBlob = this.vm.common.param('blobGasPerBlob');
|
|
164
|
+
const blockGasRemaining = blockGasLimit - this.gasUsed;
|
|
165
|
+
if (tx.gasLimit > blockGasRemaining) {
|
|
166
|
+
throw EthereumJSErrorWithoutCode('tx has a higher gas limit than the remaining gas in the block');
|
|
167
|
+
}
|
|
168
|
+
let blobGasUsed = undefined;
|
|
169
|
+
if (tx instanceof Blob4844Tx) {
|
|
170
|
+
const { maxBlobGasPerBlock: blobGasLimit } = this.vm.common.getBlobGasSchedule();
|
|
171
|
+
if (tx.networkWrapperVersion === NetworkWrapperType.EIP4844 &&
|
|
172
|
+
this.vm.common.isActivatedEIP(7594)) {
|
|
173
|
+
throw Error('eip4844 blob transaction for eip7594 activated fork');
|
|
174
|
+
}
|
|
175
|
+
else if (tx.networkWrapperVersion === NetworkWrapperType.EIP7594 &&
|
|
176
|
+
!this.vm.common.isActivatedEIP(7594)) {
|
|
177
|
+
throw Error('eip7594 blob transaction but eip not yet activated');
|
|
178
|
+
}
|
|
179
|
+
if (this.blockOpts.common?.isActivatedEIP(4844) === false) {
|
|
180
|
+
throw Error('eip4844 not activated yet for adding a blob transaction');
|
|
181
|
+
}
|
|
182
|
+
const blobTx = tx;
|
|
183
|
+
// Guard against the case if a tx came into the pool without blobs i.e. network wrapper payload
|
|
184
|
+
if (blobTx.blobs === undefined) {
|
|
185
|
+
// TODO: verify if we want this, do we want to allow the block builder to accept blob txs without the actual blobs?
|
|
186
|
+
// (these must have at least one `blobVersionedHashes`, this is verified at tx-level)
|
|
187
|
+
if (allowNoBlobs !== true) {
|
|
188
|
+
throw EthereumJSErrorWithoutCode('blobs missing for 4844 transaction');
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
if (this.blobGasUsed + BigInt(blobTx.numBlobs()) * blobGasPerBlob > blobGasLimit) {
|
|
192
|
+
throw EthereumJSErrorWithoutCode('block blob gas limit reached');
|
|
193
|
+
}
|
|
194
|
+
blobGasUsed = this.blobGasUsed;
|
|
195
|
+
}
|
|
196
|
+
const header = {
|
|
197
|
+
...this.headerData,
|
|
198
|
+
gasUsed: this.gasUsed,
|
|
199
|
+
// correct excessBlobGas should already part of headerData used above
|
|
200
|
+
blobGasUsed,
|
|
201
|
+
};
|
|
202
|
+
const blockData = { header, transactions: this.transactions };
|
|
203
|
+
const block = createBlock(blockData, this.blockOpts);
|
|
204
|
+
const result = await runTx(this.vm, { tx, block, skipHardForkValidation });
|
|
205
|
+
// If tx is a blob transaction, remove blobs/kzg commitments before adding to block per EIP-4844
|
|
206
|
+
if (tx instanceof Blob4844Tx) {
|
|
207
|
+
const txData = tx;
|
|
208
|
+
this.blobGasUsed += BigInt(txData.blobVersionedHashes.length) * blobGasPerBlob;
|
|
209
|
+
tx = createMinimal4844TxFromNetworkWrapper(txData, {
|
|
210
|
+
common: this.blockOpts.common,
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
this.transactions.push(tx);
|
|
214
|
+
this.transactionResults.push(result);
|
|
215
|
+
this.gasUsed += result.totalGasSpent;
|
|
216
|
+
this._minerValue += result.minerValue;
|
|
217
|
+
return result;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Reverts the checkpoint on the StateManager to reset the state from any transactions that have been run.
|
|
221
|
+
*/
|
|
222
|
+
async revert() {
|
|
223
|
+
if (this.checkpointed) {
|
|
224
|
+
await this.vm.evm.journal.revert();
|
|
225
|
+
this.checkpointed = false;
|
|
226
|
+
}
|
|
227
|
+
this.blockStatus = { status: BuildStatus.Reverted };
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* This method constructs the finalized block, including withdrawals and any CLRequests.
|
|
231
|
+
* It also:
|
|
232
|
+
* - Assigns the reward for miner (PoW)
|
|
233
|
+
* - Commits the checkpoint on the StateManager
|
|
234
|
+
* - Sets the tip of the VM's blockchain to this block
|
|
235
|
+
* For PoW, optionally seals the block with params `nonce` and `mixHash`,
|
|
236
|
+
* which is validated along with the block number and difficulty by ethash.
|
|
237
|
+
* For PoA, please pass `blockOption.cliqueSigner` into the buildBlock constructor,
|
|
238
|
+
* as the signer will be awarded the txs amount spent on gas as they are added.
|
|
239
|
+
*
|
|
240
|
+
* Note: we add CLRequests here because they can be generated at any time during the
|
|
241
|
+
* lifecycle of a pending block so need to be provided only when the block is finalized.
|
|
242
|
+
*/
|
|
243
|
+
async build(sealOpts) {
|
|
244
|
+
this.checkStatus();
|
|
245
|
+
const blockOpts = this.blockOpts;
|
|
246
|
+
const consensusType = this.vm.common.consensusType();
|
|
247
|
+
if (consensusType === ConsensusType.ProofOfWork) {
|
|
248
|
+
await this.rewardMiner();
|
|
249
|
+
}
|
|
250
|
+
await this.processWithdrawals();
|
|
251
|
+
const transactionsTrie = await this.transactionsTrie();
|
|
252
|
+
const withdrawalsRoot = this.withdrawals
|
|
253
|
+
? await genWithdrawalsTrieRoot(this.withdrawals, new MerklePatriciaTrie({ common: this.vm.common }))
|
|
254
|
+
: undefined;
|
|
255
|
+
const receiptTrie = await this.receiptTrie();
|
|
256
|
+
const logsBloom = this.logsBloom();
|
|
257
|
+
const gasUsed = this.gasUsed;
|
|
258
|
+
// timestamp should already be set in constructor
|
|
259
|
+
const timestamp = this.headerData.timestamp ?? BIGINT_0;
|
|
260
|
+
let blobGasUsed = undefined;
|
|
261
|
+
if (this.vm.common.isActivatedEIP(4844)) {
|
|
262
|
+
blobGasUsed = this.blobGasUsed;
|
|
263
|
+
}
|
|
264
|
+
let requests;
|
|
265
|
+
let requestsHash;
|
|
266
|
+
if (this.vm.common.isActivatedEIP(7685)) {
|
|
267
|
+
const sha256Function = this.vm.common.customCrypto.sha256 ?? sha256;
|
|
268
|
+
requests = await accumulateRequests(this.vm, this.transactionResults);
|
|
269
|
+
requestsHash = genRequestsRoot(requests, sha256Function);
|
|
270
|
+
}
|
|
271
|
+
// get stateRoot after all the accumulateRequests etc have been done
|
|
272
|
+
const stateRoot = await this.vm.stateManager.getStateRoot();
|
|
273
|
+
const headerData = {
|
|
274
|
+
...this.headerData,
|
|
275
|
+
stateRoot,
|
|
276
|
+
transactionsTrie,
|
|
277
|
+
withdrawalsRoot,
|
|
278
|
+
receiptTrie,
|
|
279
|
+
logsBloom,
|
|
280
|
+
gasUsed,
|
|
281
|
+
timestamp,
|
|
282
|
+
// correct excessBlobGas should already be part of headerData used above
|
|
283
|
+
blobGasUsed,
|
|
284
|
+
requestsHash,
|
|
285
|
+
};
|
|
286
|
+
if (consensusType === ConsensusType.ProofOfWork) {
|
|
287
|
+
headerData.nonce = sealOpts?.nonce ?? headerData.nonce;
|
|
288
|
+
headerData.mixHash = sealOpts?.mixHash ?? headerData.mixHash;
|
|
289
|
+
}
|
|
290
|
+
const blockData = {
|
|
291
|
+
header: headerData,
|
|
292
|
+
transactions: this.transactions,
|
|
293
|
+
withdrawals: this.withdrawals,
|
|
294
|
+
};
|
|
295
|
+
let block;
|
|
296
|
+
const cs = this.blockOpts.cliqueSigner;
|
|
297
|
+
if (cs !== undefined) {
|
|
298
|
+
block = createSealedCliqueBlock(blockData, cs, this.blockOpts);
|
|
299
|
+
}
|
|
300
|
+
else {
|
|
301
|
+
block = createBlock(blockData, blockOpts);
|
|
302
|
+
}
|
|
303
|
+
if (this.blockOpts.putBlockIntoBlockchain === true) {
|
|
304
|
+
await this.vm.blockchain.putBlock(block);
|
|
305
|
+
}
|
|
306
|
+
this.blockStatus = { status: BuildStatus.Build, block };
|
|
307
|
+
if (this.checkpointed) {
|
|
308
|
+
await this.vm.evm.journal.commit();
|
|
309
|
+
this.checkpointed = false;
|
|
310
|
+
}
|
|
311
|
+
return { block, requests };
|
|
312
|
+
}
|
|
313
|
+
async initState() {
|
|
314
|
+
if (this.vm.common.isActivatedEIP(4788)) {
|
|
315
|
+
if (!this.checkpointed) {
|
|
316
|
+
await this.vm.evm.journal.checkpoint();
|
|
317
|
+
this.checkpointed = true;
|
|
318
|
+
}
|
|
319
|
+
const { parentBeaconBlockRoot, timestamp } = this.headerData;
|
|
320
|
+
// timestamp should already be set in constructor
|
|
321
|
+
const timestampBigInt = toType(timestamp ?? 0, TypeOutput.BigInt);
|
|
322
|
+
const parentBeaconBlockRootBuf = toType(parentBeaconBlockRoot, TypeOutput.Uint8Array) ?? new Uint8Array(32);
|
|
323
|
+
await accumulateParentBeaconBlockRoot(this.vm, parentBeaconBlockRootBuf, timestampBigInt);
|
|
324
|
+
}
|
|
325
|
+
if (this.vm.common.isActivatedEIP(2935)) {
|
|
326
|
+
if (!this.checkpointed) {
|
|
327
|
+
await this.vm.evm.journal.checkpoint();
|
|
328
|
+
this.checkpointed = true;
|
|
329
|
+
}
|
|
330
|
+
const { parentHash, number } = this.headerData;
|
|
331
|
+
// timestamp should already be set in constructor
|
|
332
|
+
const numberBigInt = toType(number ?? 0, TypeOutput.BigInt);
|
|
333
|
+
const parentHashSanitized = toType(parentHash, TypeOutput.Uint8Array) ?? new Uint8Array(32);
|
|
334
|
+
await accumulateParentBlockHash(this.vm, numberBigInt, parentHashSanitized);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* Build a block on top of the current state
|
|
340
|
+
* by adding one transaction at a time.
|
|
341
|
+
*
|
|
342
|
+
* Creates a checkpoint on the StateManager and modifies the state
|
|
343
|
+
* as transactions are run. The checkpoint is committed on {@link BlockBuilder.build}
|
|
344
|
+
* or discarded with {@link BlockBuilder.revert}.
|
|
345
|
+
*
|
|
346
|
+
* @param {VM} vm
|
|
347
|
+
* @param {BuildBlockOpts} opts
|
|
348
|
+
* @returns An instance of {@link BlockBuilder} with methods:
|
|
349
|
+
* - {@link BlockBuilder.addTransaction}
|
|
350
|
+
* - {@link BlockBuilder.build}
|
|
351
|
+
* - {@link BlockBuilder.revert}
|
|
352
|
+
*/
|
|
353
|
+
export async function buildBlock(vm, opts) {
|
|
354
|
+
const blockBuilder = new BlockBuilder(vm, opts);
|
|
355
|
+
await blockBuilder.initState();
|
|
356
|
+
return blockBuilder;
|
|
357
|
+
}
|
|
358
|
+
//# sourceMappingURL=buildBlock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildBlock.js","sourceRoot":"","sources":["../../src/buildBlock.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,uBAAuB,EACvB,eAAe,EACf,uBAAuB,EACvB,sBAAsB,GACvB,MAAM,mBAAmB,CAAA;AAC1B,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KAAK,UAAU,UAAU,CAAC,EAAM,EAAE,IAAoB;IAC3D,MAAM,YAAY,GAAG,IAAI,YAAY,CAAC,EAAE,EAAE,IAAI,CAAC,CAAA;IAC/C,MAAM,YAAY,CAAC,SAAS,EAAE,CAAA;IAC9B,OAAO,YAAY,CAAA;AACrB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { VM } from './vm.ts';
|
|
2
|
+
import type { VMOpts } from './types.ts';
|
|
3
|
+
/**
|
|
4
|
+
* VM async constructor. Creates engine instance and initializes it.
|
|
5
|
+
*
|
|
6
|
+
* @param opts VM engine constructor options
|
|
7
|
+
*/
|
|
8
|
+
export declare function createVM(opts?: VMOpts): Promise<VM>;
|
|
9
|
+
//# sourceMappingURL=constructors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constructors.d.ts","sourceRoot":"","sources":["../../src/constructors.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAE5B,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AAExC;;;;GAIG;AACH,wBAAsB,QAAQ,CAAC,IAAI,GAAE,MAAW,GAAG,OAAO,CAAC,EAAE,CAAC,CAsE7D"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { Common, Mainnet } from '@feelyourprotocol/common';
|
|
2
|
+
import { EVMMockBlockchain, createEVM, getActivePrecompiles } from '@feelyourprotocol/evm';
|
|
3
|
+
import { MerkleStateManager } from '@feelyourprotocol/statemanager';
|
|
4
|
+
import { Account, Address, EthereumJSErrorWithoutCode, createAccount, unprefixedHexToBytes, } from '@feelyourprotocol/util';
|
|
5
|
+
import { VM } from "./vm.js";
|
|
6
|
+
/**
|
|
7
|
+
* VM async constructor. Creates engine instance and initializes it.
|
|
8
|
+
*
|
|
9
|
+
* @param opts VM engine constructor options
|
|
10
|
+
*/
|
|
11
|
+
export async function createVM(opts = {}) {
|
|
12
|
+
// Save if a `StateManager` was passed (for activatePrecompiles)
|
|
13
|
+
const didPassStateManager = opts.stateManager !== undefined;
|
|
14
|
+
// Add common, SM, blockchain, EVM here
|
|
15
|
+
if (opts.common === undefined) {
|
|
16
|
+
opts.common = new Common({ chain: Mainnet });
|
|
17
|
+
}
|
|
18
|
+
if (opts.stateManager === undefined) {
|
|
19
|
+
opts.stateManager = new MerkleStateManager({
|
|
20
|
+
common: opts.common,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
if (opts.blockchain === undefined) {
|
|
24
|
+
opts.blockchain = new EVMMockBlockchain();
|
|
25
|
+
}
|
|
26
|
+
if (opts.profilerOpts !== undefined) {
|
|
27
|
+
const profilerOpts = opts.profilerOpts;
|
|
28
|
+
if (profilerOpts.reportAfterBlock === true && profilerOpts.reportAfterTx === true) {
|
|
29
|
+
throw EthereumJSErrorWithoutCode('Cannot have `reportProfilerAfterBlock` and `reportProfilerAfterTx` set to `true` at the same time');
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (opts.evm !== undefined && opts.evmOpts !== undefined) {
|
|
33
|
+
throw EthereumJSErrorWithoutCode('the evm and evmOpts options cannot be used in conjunction');
|
|
34
|
+
}
|
|
35
|
+
if (opts.evm === undefined) {
|
|
36
|
+
let enableProfiler = false;
|
|
37
|
+
if (opts.profilerOpts?.reportAfterBlock === true || opts.profilerOpts?.reportAfterTx === true) {
|
|
38
|
+
enableProfiler = true;
|
|
39
|
+
}
|
|
40
|
+
const evmOpts = opts.evmOpts ?? {};
|
|
41
|
+
opts.evm = await createEVM({
|
|
42
|
+
common: opts.common,
|
|
43
|
+
stateManager: opts.stateManager,
|
|
44
|
+
blockchain: opts.blockchain,
|
|
45
|
+
profiler: {
|
|
46
|
+
enabled: enableProfiler,
|
|
47
|
+
},
|
|
48
|
+
...evmOpts,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
if (opts.activatePrecompiles === true && !didPassStateManager) {
|
|
52
|
+
await opts.evm.journal.checkpoint();
|
|
53
|
+
// put 1 wei in each of the precompiles in order to make the accounts non-empty and thus not have them deduct `callNewAccount` gas.
|
|
54
|
+
for (const [addressStr] of getActivePrecompiles(opts.common)) {
|
|
55
|
+
const address = new Address(unprefixedHexToBytes(addressStr));
|
|
56
|
+
let account = await opts.evm.stateManager.getAccount(address);
|
|
57
|
+
// Only do this if it is not overridden in genesis
|
|
58
|
+
// Note: in the case that custom genesis has storage fields, this is preserved
|
|
59
|
+
if (account === undefined) {
|
|
60
|
+
account = new Account();
|
|
61
|
+
const newAccount = createAccount({
|
|
62
|
+
balance: 1,
|
|
63
|
+
storageRoot: account.storageRoot,
|
|
64
|
+
});
|
|
65
|
+
await opts.evm.stateManager.putAccount(address, newAccount);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
await opts.evm.journal.commit();
|
|
69
|
+
}
|
|
70
|
+
return new VM(opts);
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=constructors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constructors.js","sourceRoot":"","sources":["../../src/constructors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAA;AACpD,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAA;AACpF,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAA;AAC7D,OAAO,EACL,OAAO,EACP,OAAO,EACP,0BAA0B,EAC1B,aAAa,EACb,oBAAoB,GACrB,MAAM,kBAAkB,CAAA;AAEzB,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAI5B;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ,CAAC,OAAe,EAAE;IAC9C,gEAAgE;IAChE,MAAM,mBAAmB,GAAG,IAAI,CAAC,YAAY,KAAK,SAAS,CAAA;IAE3D,uCAAuC;IACvC,IAAI,IA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
* @param logs
|
|
5
|
+
* @param profileTitle
|
|
6
|
+
* @hidden
|
|
7
|
+
*/
|
|
8
|
+
export declare function emitEVMProfile(logs: EVMPerformanceLogOutput[], profileTitle: string): void;
|
|
9
|
+
//# sourceMappingURL=emitEVMProfile.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emitEVMProfile.d.ts","sourceRoot":"","sources":["../../src/emitEVMProfile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAA;AAE9D;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,uBAAuB,EAAE,EAAE,YAAY,EAAE,MAAM,QA8InF"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Emit EVM profile logs
|
|
3
|
+
* @param logs
|
|
4
|
+
* @param profileTitle
|
|
5
|
+
* @hidden
|
|
6
|
+
*/
|
|
7
|
+
export function emitEVMProfile(logs, profileTitle) {
|
|
8
|
+
if (logs.length === 0) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
// Track total calls / time (ms) / gas
|
|
12
|
+
let calls = 0;
|
|
13
|
+
let totalMs = 0;
|
|
14
|
+
let totalGas = 0;
|
|
15
|
+
// Order of columns to report (see `EVMPerformanceLogOutput` type)
|
|
16
|
+
const colOrder = [
|
|
17
|
+
'tag',
|
|
18
|
+
'calls',
|
|
19
|
+
'avgTimePerCall',
|
|
20
|
+
'totalTime',
|
|
21
|
+
'staticGasUsed',
|
|
22
|
+
'dynamicGasUsed',
|
|
23
|
+
'gasUsed',
|
|
24
|
+
'staticGas',
|
|
25
|
+
'millionGasPerSecond',
|
|
26
|
+
'blocksPerSlot',
|
|
27
|
+
];
|
|
28
|
+
// The name of this column to report (saves space)
|
|
29
|
+
const colNames = [
|
|
30
|
+
'tag',
|
|
31
|
+
'calls',
|
|
32
|
+
'ms/call',
|
|
33
|
+
'total (ms)',
|
|
34
|
+
'sgas',
|
|
35
|
+
'dgas',
|
|
36
|
+
'total (s+d)',
|
|
37
|
+
'static fee',
|
|
38
|
+
'Mgas/s',
|
|
39
|
+
'BpS',
|
|
40
|
+
];
|
|
41
|
+
// Special padStr method which inserts whitespace left and right
|
|
42
|
+
// This ensures that there is at least one whitespace between the columns (denoted by pipe `|` chars)
|
|
43
|
+
function padStr(str, leftpad) {
|
|
44
|
+
return ' ' + str.toString().padStart(leftpad, ' ') + ' ';
|
|
45
|
+
}
|
|
46
|
+
// Returns the string length of this column. Used to calculate how big the header / footer should be
|
|
47
|
+
function strLen(str) {
|
|
48
|
+
return padStr(str, 0).length - 2;
|
|
49
|
+
}
|
|
50
|
+
// Step one: calculate the length of each column
|
|
51
|
+
const colLength = [];
|
|
52
|
+
for (const entry of logs) {
|
|
53
|
+
let ins = 0;
|
|
54
|
+
colLength[ins] = Math.max(colLength[ins] ?? 0, strLen(colNames[ins]));
|
|
55
|
+
for (const key of colOrder) {
|
|
56
|
+
if (entry[key] !== undefined) {
|
|
57
|
+
// If entry is available, max out the current column length (this will be the longest string of this column)
|
|
58
|
+
colLength[ins] = Math.max(colLength[ins] ?? 0, strLen(entry[key]));
|
|
59
|
+
ins++;
|
|
60
|
+
// In this switch statement update the total calls / time / gas used
|
|
61
|
+
switch (key) {
|
|
62
|
+
case 'calls':
|
|
63
|
+
calls += entry[key];
|
|
64
|
+
break;
|
|
65
|
+
case 'totalTime':
|
|
66
|
+
totalMs += entry[key];
|
|
67
|
+
break;
|
|
68
|
+
case 'gasUsed':
|
|
69
|
+
totalGas += entry[key];
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
// Ensure that the column names also fit on the column length
|
|
76
|
+
for (const i in colLength) {
|
|
77
|
+
colLength[i] = Math.max(colLength[i] ?? 0, strLen(colNames[i]));
|
|
78
|
+
}
|
|
79
|
+
// Calculate the total header length
|
|
80
|
+
// This is done by summing all columns together, plus adding three extra chars per column (two whitespace, one pipe)
|
|
81
|
+
// Remove the final pipe character since this is included in the header string (so subtract one)
|
|
82
|
+
const headerLength = colLength.reduce((pv, cv) => pv + cv, 0) + colLength.length * 3 - 1;
|
|
83
|
+
const blockGasLimit = 30000000; // Block gas limit
|
|
84
|
+
const slotTime = 12000; // Time in milliseconds (!) per slot
|
|
85
|
+
// Normalize constant to check if execution time is above one block per slot (>=1) or not (<1)
|
|
86
|
+
const bpsNormalizer = blockGasLimit / slotTime;
|
|
87
|
+
const avgGas = totalGas / totalMs; // Gas per millisecond
|
|
88
|
+
const mGasSAvg = Math.round(avgGas) / 1e3;
|
|
89
|
+
const bpSAvg = Math.round((avgGas / bpsNormalizer) * 1e3) / 1e3;
|
|
90
|
+
// Write the profile title
|
|
91
|
+
// eslint-disable-next-line
|
|
92
|
+
console.log('+== ' + profileTitle + ' ==+');
|
|
93
|
+
// Write the summary of this profile
|
|
94
|
+
// eslint-disable-next-line
|
|
95
|
+
console.log(`+== Calls: ${calls}, Total time: ${Math.round(totalMs * 1e3) / 1e3}ms, Total gas: ${totalGas}, MGas/s: ${mGasSAvg}, Blocks per Slot (BpS): ${bpSAvg} ==+`);
|
|
96
|
+
// Generate and write the header
|
|
97
|
+
const header = '|' + '-'.repeat(headerLength) + '|';
|
|
98
|
+
// eslint-disable-next-line
|
|
99
|
+
console.log(header);
|
|
100
|
+
// Write the columns
|
|
101
|
+
let str = '';
|
|
102
|
+
for (const i in colLength) {
|
|
103
|
+
str += '|' + padStr(colNames[i], colLength[i]);
|
|
104
|
+
}
|
|
105
|
+
str += '|';
|
|
106
|
+
// eslint-disable-next-line
|
|
107
|
+
console.log(str);
|
|
108
|
+
// Write each profile entry
|
|
109
|
+
for (const entry of logs) {
|
|
110
|
+
let str = '';
|
|
111
|
+
let i = 0;
|
|
112
|
+
for (const key of colOrder) {
|
|
113
|
+
if (entry[key] !== undefined) {
|
|
114
|
+
str += '|' + padStr(entry[key], colLength[i]);
|
|
115
|
+
i++;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
str += '|';
|
|
119
|
+
// eslint-disable-next-line
|
|
120
|
+
console.log(str);
|
|
121
|
+
}
|
|
122
|
+
// Finally, write the footer
|
|
123
|
+
const footer = '+' + '-'.repeat(headerLength) + '+';
|
|
124
|
+
// eslint-disable-next-line
|
|
125
|
+
console.log(footer);
|
|
126
|
+
}
|
|
127
|
+
//# sourceMappingURL=emitEVMProfile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emitEVMProfile.js","sourceRoot":"","sources":["../../src/emitEVMProfile.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,IAA+B,EAAE,YAAoB;IAClF,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACtB,OAAM;IACR,CAAC;IAED,sCAAsC;IAEtC,IAAI,KAAK,GAAG,CAAC,CAAA;IACb,IAAI,OAAO,GAAG,CAAC,CAAA;IACf,IAAI,QAAQ,GAAG,CAAC,CAAA;IAEhB,kEAAkE;IAElE,MAAM,QAAQ,GAAsC;QAClD,KAAK;QACL,OAAO;QACP,gBAAgB;QAChB,WAAW;QACX,eAAe;QACf,gBAAgB;QAChB,SAAS;QACT,WAAW;QACX,qBAAqB;QACrB,eAAe;KAChB,CAAA;IAED,kDAAkD;IAClD,MAAM,QAAQ,GAAG;QACf,KAAK;QACL,OAAO;QACP,SAAS;QACT,YAAY;QACZ,MAAM;QACN,MAAM;QACN,aAAa;QACb,YAAY;QACZ,QAAQ;QACR,KAAK;KACN,CAAA;IAED,gEAAgE;IAChE,qGAAqG;IACrG,SAAS,MAAM,CAAC,GAAoB,EAAE,OAAe;QACnD,OAAO,GAAG,GAAG,GAAG,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,OAAO,EAAE,GAAG,CAAC,GAAG,GAAG,CAAA;IAC1D,CAAC;IACD,oGAAoG;IACpG,SAAS,MAAM,CAAC,GAA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AAI,SAAS,EAAE,CAAC;QAC1B,GAAG,IAAI,GAAG,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,CAAA;IAChD,CAAC;IACD,GAAG,IAAI,GAAG,CAAA;IAEV,2BAA2B;IAC3B,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;IAEhB,2BAA2B;IAC3B,KAAK,MAAM,KAAK,IAAI,IAAI,EAAE,CAAC;QACzB,IAAI,GAAG,GAAG,EAAE,CAAA;QACZ,IAAI,CAAC,GAAG,CAAC,CAAA;QACT,KAAK,MAAM,GAAG,IAAI,QAAQ,EAAE,CAAC;YAC3B,IAAI,KAAK,CAAC,GAAG,CAAC,KAAK,SAAS,EAAE,CAAC;gBAC7B,GAAG,IAAI,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAE,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,CAAA;gBAC9C,CAAC,EAAE,CAAA;YACL,CAAC;QACH,CAAC;QACD,GAAG,IAAI,GAAG,CAAA;QACV,2BAA2B;QAC3B,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;IAClB,CAAC;IAED,4BAA4B;IAC5B,MAAM,MAAM,GAAG,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC,YAAY,CAAC,GAAG,GAAG,CAAA;IACnD,2BAA2B;IAC3B,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;AACrB,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { Bloom } from './bloom/index.ts';
|
|
2
|
+
export { BlockBuilder, BuildStatus } from './buildBlock.ts';
|
|
3
|
+
export { buildBlock } from './buildBlock.ts';
|
|
4
|
+
export * from './constructors.ts';
|
|
5
|
+
export * from './params.ts';
|
|
6
|
+
export { encodeReceipt } from './runBlock.ts';
|
|
7
|
+
export { runBlock } from './runBlock.ts';
|
|
8
|
+
export { runTx } from './runTx.ts';
|
|
9
|
+
export * from './types.ts';
|
|
10
|
+
export { VM } from './vm.ts';
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;AACxC,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,cAAc,mBAAmB,CAAA;AACjC,cAAc,aAAa,CAAA;AAC3B,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,cAAc,YAAY,CAAA;AAC1B,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { Bloom } from "./bloom/index.js";
|
|
2
|
+
export { BlockBuilder, BuildStatus } from "./buildBlock.js";
|
|
3
|
+
export { buildBlock } from "./buildBlock.js";
|
|
4
|
+
export * from "./constructors.js";
|
|
5
|
+
export * from "./params.js";
|
|
6
|
+
export { encodeReceipt } from "./runBlock.js";
|
|
7
|
+
export { runBlock } from "./runBlock.js";
|
|
8
|
+
export { runTx } from "./runTx.js";
|
|
9
|
+
export * from "./types.js";
|
|
10
|
+
export { VM } from "./vm.js";
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;AACxC,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,cAAc,mBAAmB,CAAA;AACjC,cAAc,aAAa,CAAA;AAC3B,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,cAAc,YAAY,CAAA;AAC1B,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA"}
|