@feelyourprotocol/block 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 +466 -0
- package/dist/cjs/block/block.d.ts +147 -0
- package/dist/cjs/block/block.d.ts.map +1 -0
- package/dist/cjs/block/block.js +415 -0
- package/dist/cjs/block/block.js.map +1 -0
- package/dist/cjs/block/constructors.d.ts +77 -0
- package/dist/cjs/block/constructors.d.ts.map +1 -0
- package/dist/cjs/block/constructors.js +298 -0
- package/dist/cjs/block/constructors.js.map +1 -0
- package/dist/cjs/block/index.d.ts +3 -0
- package/dist/cjs/block/index.d.ts.map +1 -0
- package/dist/cjs/block/index.js +19 -0
- package/dist/cjs/block/index.js.map +1 -0
- package/dist/cjs/consensus/clique.d.ts +52 -0
- package/dist/cjs/consensus/clique.d.ts.map +1 -0
- package/dist/cjs/consensus/clique.js +144 -0
- package/dist/cjs/consensus/clique.js.map +1 -0
- package/dist/cjs/consensus/ethash.d.ts +9 -0
- package/dist/cjs/consensus/ethash.d.ts.map +1 -0
- package/dist/cjs/consensus/ethash.js +13 -0
- package/dist/cjs/consensus/ethash.js.map +1 -0
- package/dist/cjs/consensus/index.d.ts +3 -0
- package/dist/cjs/consensus/index.d.ts.map +1 -0
- package/dist/cjs/consensus/index.js +29 -0
- package/dist/cjs/consensus/index.js.map +1 -0
- package/dist/cjs/from-beacon-payload.d.ts +36 -0
- package/dist/cjs/from-beacon-payload.d.ts.map +1 -0
- package/dist/cjs/from-beacon-payload.js +48 -0
- package/dist/cjs/from-beacon-payload.js.map +1 -0
- package/dist/cjs/header/constructors.d.ts +39 -0
- package/dist/cjs/header/constructors.d.ts.map +1 -0
- package/dist/cjs/header/constructors.js +127 -0
- package/dist/cjs/header/constructors.js.map +1 -0
- package/dist/cjs/header/header.d.ts +134 -0
- package/dist/cjs/header/header.d.ts.map +1 -0
- package/dist/cjs/header/header.js +699 -0
- package/dist/cjs/header/header.js.map +1 -0
- package/dist/cjs/header/index.d.ts +3 -0
- package/dist/cjs/header/index.d.ts.map +1 -0
- package/dist/cjs/header/index.js +19 -0
- package/dist/cjs/header/index.js.map +1 -0
- package/dist/cjs/helpers.d.ts +59 -0
- package/dist/cjs/helpers.d.ts.map +1 -0
- package/dist/cjs/helpers.js +172 -0
- package/dist/cjs/helpers.js.map +1 -0
- package/dist/cjs/index.d.ts +8 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +31 -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 +97 -0
- package/dist/cjs/params.js.map +1 -0
- package/dist/cjs/types.d.ts +228 -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/esm/block/block.d.ts +147 -0
- package/dist/esm/block/block.d.ts.map +1 -0
- package/dist/esm/block/block.js +411 -0
- package/dist/esm/block/block.js.map +1 -0
- package/dist/esm/block/constructors.d.ts +77 -0
- package/dist/esm/block/constructors.d.ts.map +1 -0
- package/dist/esm/block/constructors.js +286 -0
- package/dist/esm/block/constructors.js.map +1 -0
- package/dist/esm/block/index.d.ts +3 -0
- package/dist/esm/block/index.d.ts.map +1 -0
- package/dist/esm/block/index.js +3 -0
- package/dist/esm/block/index.js.map +1 -0
- package/dist/esm/consensus/clique.d.ts +52 -0
- package/dist/esm/consensus/clique.d.ts.map +1 -0
- package/dist/esm/consensus/clique.js +132 -0
- package/dist/esm/consensus/clique.js.map +1 -0
- package/dist/esm/consensus/ethash.d.ts +9 -0
- package/dist/esm/consensus/ethash.d.ts.map +1 -0
- package/dist/esm/consensus/ethash.js +10 -0
- package/dist/esm/consensus/ethash.js.map +1 -0
- package/dist/esm/consensus/index.d.ts +3 -0
- package/dist/esm/consensus/index.d.ts.map +1 -0
- package/dist/esm/consensus/index.js +3 -0
- package/dist/esm/consensus/index.js.map +1 -0
- package/dist/esm/from-beacon-payload.d.ts +36 -0
- package/dist/esm/from-beacon-payload.d.ts.map +1 -0
- package/dist/esm/from-beacon-payload.js +45 -0
- package/dist/esm/from-beacon-payload.js.map +1 -0
- package/dist/esm/header/constructors.d.ts +39 -0
- package/dist/esm/header/constructors.d.ts.map +1 -0
- package/dist/esm/header/constructors.js +120 -0
- package/dist/esm/header/constructors.js.map +1 -0
- package/dist/esm/header/header.d.ts +134 -0
- package/dist/esm/header/header.d.ts.map +1 -0
- package/dist/esm/header/header.js +695 -0
- package/dist/esm/header/header.js.map +1 -0
- package/dist/esm/header/index.d.ts +3 -0
- package/dist/esm/header/index.d.ts.map +1 -0
- package/dist/esm/header/index.js +3 -0
- package/dist/esm/header/index.js.map +1 -0
- package/dist/esm/helpers.d.ts +59 -0
- package/dist/esm/helpers.d.ts.map +1 -0
- package/dist/esm/helpers.js +161 -0
- package/dist/esm/helpers.js.map +1 -0
- package/dist/esm/index.d.ts +8 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +8 -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 +94 -0
- package/dist/esm/params.js.map +1 -0
- package/dist/esm/types.d.ts +228 -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/tsconfig.prod.cjs.tsbuildinfo +1 -0
- package/dist/tsconfig.prod.esm.tsbuildinfo +1 -0
- package/package.json +75 -0
- package/src/block/block.ts +526 -0
- package/src/block/constructors.ts +407 -0
- package/src/block/index.ts +2 -0
- package/src/consensus/clique.ts +171 -0
- package/src/consensus/ethash.ts +11 -0
- package/src/consensus/index.ts +12 -0
- package/src/from-beacon-payload.ts +82 -0
- package/src/header/constructors.ts +169 -0
- package/src/header/header.ts +890 -0
- package/src/header/index.ts +2 -0
- package/src/helpers.ts +223 -0
- package/src/index.ts +13 -0
- package/src/params.ts +95 -0
- package/src/types.ts +254 -0
|
@@ -0,0 +1,411 @@
|
|
|
1
|
+
import { ConsensusType } from '@feelyourprotocol/common';
|
|
2
|
+
import { MerklePatriciaTrie } from '@feelyourprotocol/mpt';
|
|
3
|
+
import { RLP } from '@feelyourprotocol/rlp';
|
|
4
|
+
import { Blob4844Tx, Capability } from '@feelyourprotocol/tx';
|
|
5
|
+
import { BIGINT_0, EthereumJSErrorWithoutCode, KECCAK256_RLP, KECCAK256_RLP_ARRAY, bytesToHex, equalsBytes, } from '@feelyourprotocol/util';
|
|
6
|
+
import { sha256 } from '@noble/hashes/sha2.js';
|
|
7
|
+
import { keccak_256 } from '@noble/hashes/sha3.js';
|
|
8
|
+
/* eslint-disable */
|
|
9
|
+
// This is to allow for a proper and linked collection of constructors for the class header.
|
|
10
|
+
// For tree shaking/code size this should be no problem since types go away on transpilation.
|
|
11
|
+
// TODO: See if there is an easier way to achieve the same result.
|
|
12
|
+
// See: https://github.com/microsoft/TypeScript/issues/47558
|
|
13
|
+
// (situation will eventually improve on Typescript and/or Eslint update)
|
|
14
|
+
import { BlockHeader, genTransactionsTrieRoot, genWithdrawalsTrieRoot, } from "../index.js";
|
|
15
|
+
/**
|
|
16
|
+
* Class representing a block in the Ethereum network. The {@link BlockHeader} has its own
|
|
17
|
+
* class and can be used independently, for a block it is included in the form of the
|
|
18
|
+
* {@link Block.header} property.
|
|
19
|
+
*
|
|
20
|
+
* A block object can be created with one of the following constructor methods
|
|
21
|
+
* (separate from the Block class to allow for tree shaking):
|
|
22
|
+
*
|
|
23
|
+
* - {@link createBlock }
|
|
24
|
+
* - {@link createBlockFromBytesArray }
|
|
25
|
+
* - {@link createBlockFromRLP }
|
|
26
|
+
* - {@link createBlockFromRPC }
|
|
27
|
+
* - {@link createBlockFromJSONRPCProvider }
|
|
28
|
+
* - {@link createBlockFromExecutionPayload }
|
|
29
|
+
* - {@link createBlockFromBeaconPayloadJSON }
|
|
30
|
+
*/
|
|
31
|
+
export class Block {
|
|
32
|
+
/**
|
|
33
|
+
* This constructor takes the values, validates them, assigns them and freezes the object.
|
|
34
|
+
*
|
|
35
|
+
* @deprecated Use the static factory methods (see {@link Block} for an overview) to assist in creating
|
|
36
|
+
* a Block object from varying data types and options.
|
|
37
|
+
*/
|
|
38
|
+
constructor(header, transactions = [], uncleHeaders = [], withdrawals, opts = {}) {
|
|
39
|
+
this.transactions = [];
|
|
40
|
+
this.uncleHeaders = [];
|
|
41
|
+
this.cache = {};
|
|
42
|
+
this.header = header ?? new BlockHeader({}, opts);
|
|
43
|
+
this.common = this.header.common;
|
|
44
|
+
this.keccakFunction = this.common.customCrypto.keccak256 ?? keccak_256;
|
|
45
|
+
this.sha256Function = this.common.customCrypto.sha256 ?? sha256;
|
|
46
|
+
this.transactions = transactions;
|
|
47
|
+
this.withdrawals = withdrawals ?? (this.common.isActivatedEIP(4895) ? [] : undefined);
|
|
48
|
+
this.uncleHeaders = uncleHeaders;
|
|
49
|
+
if (uncleHeaders.length > 0) {
|
|
50
|
+
this.validateUncles();
|
|
51
|
+
if (this.common.consensusType() === ConsensusType.ProofOfAuthority) {
|
|
52
|
+
const msg = this._errorMsg('Block initialization with uncleHeaders on a PoA network is not allowed');
|
|
53
|
+
throw EthereumJSErrorWithoutCode(msg);
|
|
54
|
+
}
|
|
55
|
+
if (this.common.consensusType() === ConsensusType.ProofOfStake) {
|
|
56
|
+
const msg = this._errorMsg('Block initialization with uncleHeaders on a PoS network is not allowed');
|
|
57
|
+
throw EthereumJSErrorWithoutCode(msg);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (!this.common.isActivatedEIP(4895) && withdrawals !== undefined) {
|
|
61
|
+
throw EthereumJSErrorWithoutCode('Cannot have a withdrawals field if EIP 4895 is not active');
|
|
62
|
+
}
|
|
63
|
+
const freeze = opts?.freeze ?? true;
|
|
64
|
+
if (freeze) {
|
|
65
|
+
Object.freeze(this);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Returns an array of the raw byte arrays for this block, in order.
|
|
70
|
+
*/
|
|
71
|
+
raw() {
|
|
72
|
+
const bytesArray = [
|
|
73
|
+
this.header.raw(),
|
|
74
|
+
this.transactions.map((tx) => tx.supports(Capability.EIP2718TypedTransaction) ? tx.serialize() : tx.raw()),
|
|
75
|
+
this.uncleHeaders.map((uh) => uh.raw()),
|
|
76
|
+
];
|
|
77
|
+
const withdrawalsRaw = this.withdrawals?.map((wt) => wt.raw());
|
|
78
|
+
if (withdrawalsRaw) {
|
|
79
|
+
bytesArray.push(withdrawalsRaw);
|
|
80
|
+
}
|
|
81
|
+
return bytesArray;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Returns the hash of the block.
|
|
85
|
+
*/
|
|
86
|
+
hash() {
|
|
87
|
+
return this.header.hash();
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Determines if this block is the genesis block.
|
|
91
|
+
*/
|
|
92
|
+
isGenesis() {
|
|
93
|
+
return this.header.isGenesis();
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Returns the rlp encoding of the block.
|
|
97
|
+
*/
|
|
98
|
+
serialize() {
|
|
99
|
+
return RLP.encode(this.raw());
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Generates transaction trie for validation.
|
|
103
|
+
*/
|
|
104
|
+
async genTxTrie() {
|
|
105
|
+
return genTransactionsTrieRoot(this.transactions, new MerklePatriciaTrie({ common: this.common }));
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Validates the transaction trie by generating a trie
|
|
109
|
+
* and do a check on the root hash.
|
|
110
|
+
* @returns True if the transaction trie is valid, false otherwise
|
|
111
|
+
*/
|
|
112
|
+
async transactionsTrieIsValid() {
|
|
113
|
+
let result;
|
|
114
|
+
if (this.transactions.length === 0) {
|
|
115
|
+
result = equalsBytes(this.header.transactionsTrie, KECCAK256_RLP);
|
|
116
|
+
return result;
|
|
117
|
+
}
|
|
118
|
+
if (this.cache.txTrieRoot === undefined) {
|
|
119
|
+
this.cache.txTrieRoot = await this.genTxTrie();
|
|
120
|
+
}
|
|
121
|
+
result = equalsBytes(this.cache.txTrieRoot, this.header.transactionsTrie);
|
|
122
|
+
return result;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Validates transaction signatures and minimum gas requirements.
|
|
126
|
+
* @returns {string[]} an array of error strings
|
|
127
|
+
*/
|
|
128
|
+
getTransactionsValidationErrors() {
|
|
129
|
+
const errors = [];
|
|
130
|
+
let blobGasUsed = BIGINT_0;
|
|
131
|
+
// eslint-disable-next-line prefer-const
|
|
132
|
+
for (let [i, tx] of this.transactions.entries()) {
|
|
133
|
+
const errs = tx.getValidationErrors();
|
|
134
|
+
if (this.common.isActivatedEIP(1559)) {
|
|
135
|
+
if (tx.supports(Capability.EIP1559FeeMarket)) {
|
|
136
|
+
tx = tx;
|
|
137
|
+
if (tx.maxFeePerGas < this.header.baseFeePerGas) {
|
|
138
|
+
errs.push('tx unable to pay base fee (EIP-1559 tx)');
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
tx = tx;
|
|
143
|
+
if (tx.gasPrice < this.header.baseFeePerGas) {
|
|
144
|
+
errs.push('tx unable to pay base fee (non EIP-1559 tx)');
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if (this.common.isActivatedEIP(4844)) {
|
|
149
|
+
const blobGasLimit = this.common.getBlobGasSchedule().maxBlobGasPerBlock;
|
|
150
|
+
const blobGasPerBlob = this.common.param('blobGasPerBlob');
|
|
151
|
+
if (tx instanceof Blob4844Tx) {
|
|
152
|
+
blobGasUsed += BigInt(tx.numBlobs()) * blobGasPerBlob;
|
|
153
|
+
if (blobGasUsed > blobGasLimit) {
|
|
154
|
+
errs.push(`tx causes total blob gas of ${blobGasUsed} to exceed maximum blob gas per block of ${blobGasLimit}`);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
if (errs.length > 0) {
|
|
159
|
+
errors.push(`errors at tx ${i}: ${errs.join(', ')}`);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
if (this.common.isActivatedEIP(4844)) {
|
|
163
|
+
if (blobGasUsed !== this.header.blobGasUsed) {
|
|
164
|
+
errors.push(`invalid blobGasUsed expected=${this.header.blobGasUsed} actual=${blobGasUsed}`);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return errors;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Validates transaction signatures and minimum gas requirements.
|
|
171
|
+
* @returns True if all transactions are valid, false otherwise
|
|
172
|
+
*/
|
|
173
|
+
transactionsAreValid() {
|
|
174
|
+
const errors = this.getTransactionsValidationErrors();
|
|
175
|
+
return errors.length === 0;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Validates the block data, throwing if invalid.
|
|
179
|
+
* This can be checked on the Block itself without needing access to any parent block
|
|
180
|
+
* It checks:
|
|
181
|
+
* - All transactions are valid
|
|
182
|
+
* - The transactions trie is valid
|
|
183
|
+
* - The uncle hash is valid
|
|
184
|
+
* - Block size limit (EIP-7934)
|
|
185
|
+
* @param onlyHeader if only passed the header, skip validating txTrie and unclesHash (default: false)
|
|
186
|
+
* @param verifyTxs if set to `false`, will not check for transaction validation errors (default: true)
|
|
187
|
+
* @param validateBlockSize if set to `true`, will check for block size limit (EIP-7934) (default: false)
|
|
188
|
+
*/
|
|
189
|
+
async validateData(onlyHeader = false, verifyTxs = true, validateBlockSize = false) {
|
|
190
|
+
// EIP-7934: RLP Execution Block Size Limit validation
|
|
191
|
+
if (validateBlockSize && this.common.isActivatedEIP(7934)) {
|
|
192
|
+
const rlpEncoded = this.serialize();
|
|
193
|
+
const maxRlpBlockSize = this.common.param('maxRlpBlockSize');
|
|
194
|
+
if (rlpEncoded.length > maxRlpBlockSize) {
|
|
195
|
+
const msg = this._errorMsg(`Block size exceeds maximum RLP block size limit: ${rlpEncoded.length} bytes > ${maxRlpBlockSize} bytes`);
|
|
196
|
+
throw EthereumJSErrorWithoutCode(msg);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
if (verifyTxs) {
|
|
200
|
+
const txErrors = this.getTransactionsValidationErrors();
|
|
201
|
+
if (txErrors.length > 0) {
|
|
202
|
+
const msg = this._errorMsg(`invalid transactions: ${txErrors.join(' ')}`);
|
|
203
|
+
throw EthereumJSErrorWithoutCode(msg);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
if (onlyHeader) {
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
if (verifyTxs) {
|
|
210
|
+
for (const [index, tx] of this.transactions.entries()) {
|
|
211
|
+
if (!tx.isSigned()) {
|
|
212
|
+
const msg = this._errorMsg(`invalid transactions: transaction at index ${index} is unsigned`);
|
|
213
|
+
throw EthereumJSErrorWithoutCode(msg);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
if (!(await this.transactionsTrieIsValid())) {
|
|
218
|
+
const msg = this._errorMsg('invalid transaction trie');
|
|
219
|
+
throw EthereumJSErrorWithoutCode(msg);
|
|
220
|
+
}
|
|
221
|
+
if (!this.uncleHashIsValid()) {
|
|
222
|
+
const msg = this._errorMsg('invalid uncle hash');
|
|
223
|
+
throw EthereumJSErrorWithoutCode(msg);
|
|
224
|
+
}
|
|
225
|
+
if (this.common.isActivatedEIP(4895) && !(await this.withdrawalsTrieIsValid())) {
|
|
226
|
+
const msg = this._errorMsg('invalid withdrawals trie');
|
|
227
|
+
throw EthereumJSErrorWithoutCode(msg);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Validates that blob gas fee for each transaction is greater than or equal to the
|
|
232
|
+
* blobGasPrice for the block and that total blob gas in block is less than maximum
|
|
233
|
+
* blob gas per block
|
|
234
|
+
* @param parentHeader header of parent block
|
|
235
|
+
*/
|
|
236
|
+
validateBlobTransactions(parentHeader) {
|
|
237
|
+
if (this.common.isActivatedEIP(4844)) {
|
|
238
|
+
const blobGasLimit = this.common.getBlobGasSchedule().maxBlobGasPerBlock;
|
|
239
|
+
const blobGasPerBlob = this.common.param('blobGasPerBlob');
|
|
240
|
+
let blobGasUsed = BIGINT_0;
|
|
241
|
+
const expectedExcessBlobGas = parentHeader.calcNextExcessBlobGas(this.common);
|
|
242
|
+
if (this.header.excessBlobGas !== expectedExcessBlobGas) {
|
|
243
|
+
throw EthereumJSErrorWithoutCode(`block excessBlobGas mismatch: have ${this.header.excessBlobGas}, want ${expectedExcessBlobGas}`);
|
|
244
|
+
}
|
|
245
|
+
let blobGasPrice;
|
|
246
|
+
for (const tx of this.transactions) {
|
|
247
|
+
if (tx instanceof Blob4844Tx) {
|
|
248
|
+
blobGasPrice = blobGasPrice ?? this.header.getBlobGasPrice();
|
|
249
|
+
if (tx.maxFeePerBlobGas < blobGasPrice) {
|
|
250
|
+
throw EthereumJSErrorWithoutCode(`blob transaction maxFeePerBlobGas ${tx.maxFeePerBlobGas} < than block blob gas price ${blobGasPrice} - ${this.errorStr()}`);
|
|
251
|
+
}
|
|
252
|
+
blobGasUsed += BigInt(tx.blobVersionedHashes.length) * blobGasPerBlob;
|
|
253
|
+
if (blobGasUsed > blobGasLimit) {
|
|
254
|
+
throw EthereumJSErrorWithoutCode(`tx causes total blob gas of ${blobGasUsed} to exceed maximum blob gas per block of ${blobGasLimit}`);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
if (this.header.blobGasUsed !== blobGasUsed) {
|
|
259
|
+
throw EthereumJSErrorWithoutCode(`block blobGasUsed mismatch: have ${this.header.blobGasUsed}, want ${blobGasUsed}`);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Validates the uncle's hash.
|
|
265
|
+
* @returns true if the uncle's hash is valid, false otherwise.
|
|
266
|
+
*/
|
|
267
|
+
uncleHashIsValid() {
|
|
268
|
+
if (this.uncleHeaders.length === 0) {
|
|
269
|
+
return equalsBytes(KECCAK256_RLP_ARRAY, this.header.uncleHash);
|
|
270
|
+
}
|
|
271
|
+
const uncles = this.uncleHeaders.map((uh) => uh.raw());
|
|
272
|
+
const raw = RLP.encode(uncles);
|
|
273
|
+
return equalsBytes(this.keccakFunction(raw), this.header.uncleHash);
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Validates the withdrawal root
|
|
277
|
+
* @returns true if the withdrawals trie root is valid, false otherwise
|
|
278
|
+
*/
|
|
279
|
+
async withdrawalsTrieIsValid() {
|
|
280
|
+
if (!this.common.isActivatedEIP(4895)) {
|
|
281
|
+
throw EthereumJSErrorWithoutCode('EIP 4895 is not activated');
|
|
282
|
+
}
|
|
283
|
+
let result;
|
|
284
|
+
if (this.withdrawals.length === 0) {
|
|
285
|
+
result = equalsBytes(this.header.withdrawalsRoot, KECCAK256_RLP);
|
|
286
|
+
return result;
|
|
287
|
+
}
|
|
288
|
+
if (this.cache.withdrawalsTrieRoot === undefined) {
|
|
289
|
+
this.cache.withdrawalsTrieRoot = await genWithdrawalsTrieRoot(this.withdrawals, new MerklePatriciaTrie({ common: this.common }));
|
|
290
|
+
}
|
|
291
|
+
result = equalsBytes(this.cache.withdrawalsTrieRoot, this.header.withdrawalsRoot);
|
|
292
|
+
return result;
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* Consistency checks for uncles included in the block, if any.
|
|
296
|
+
*
|
|
297
|
+
* Throws if invalid.
|
|
298
|
+
*
|
|
299
|
+
* The rules for uncles checked are the following:
|
|
300
|
+
* Header has at most 2 uncles.
|
|
301
|
+
* Header does not count an uncle twice.
|
|
302
|
+
*/
|
|
303
|
+
validateUncles() {
|
|
304
|
+
if (this.isGenesis()) {
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
// Header has at most 2 uncles
|
|
308
|
+
if (this.uncleHeaders.length > 2) {
|
|
309
|
+
const msg = this._errorMsg('too many uncle headers');
|
|
310
|
+
throw EthereumJSErrorWithoutCode(msg);
|
|
311
|
+
}
|
|
312
|
+
// Header does not count an uncle twice.
|
|
313
|
+
const uncleHashes = this.uncleHeaders.map((header) => bytesToHex(header.hash()));
|
|
314
|
+
if (!(new Set(uncleHashes).size === uncleHashes.length)) {
|
|
315
|
+
const msg = this._errorMsg('duplicate uncles');
|
|
316
|
+
throw EthereumJSErrorWithoutCode(msg);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* Validates if the block gasLimit remains in the boundaries set by the protocol.
|
|
321
|
+
* Throws if invalid
|
|
322
|
+
*
|
|
323
|
+
* @param parentBlock - the parent of this `Block`
|
|
324
|
+
*/
|
|
325
|
+
validateGasLimit(parentBlock) {
|
|
326
|
+
return this.header.validateGasLimit(parentBlock.header);
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Returns the block in JSON format.
|
|
330
|
+
*/
|
|
331
|
+
toJSON() {
|
|
332
|
+
const withdrawalsAttr = this.withdrawals
|
|
333
|
+
? {
|
|
334
|
+
withdrawals: this.withdrawals.map((wt) => wt.toJSON()),
|
|
335
|
+
}
|
|
336
|
+
: {};
|
|
337
|
+
return {
|
|
338
|
+
header: this.header.toJSON(),
|
|
339
|
+
transactions: this.transactions.map((tx) => tx.toJSON()),
|
|
340
|
+
uncleHeaders: this.uncleHeaders.map((uh) => uh.toJSON()),
|
|
341
|
+
...withdrawalsAttr,
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Maps the block properties to the execution payload structure from the beacon chain,
|
|
346
|
+
* see https://github.com/ethereum/consensus-specs/blob/dev/specs/bellatrix/beacon-chain.md#ExecutionPayload
|
|
347
|
+
*
|
|
348
|
+
* @returns dict with the execution payload parameters with camel case naming
|
|
349
|
+
*/
|
|
350
|
+
toExecutionPayload() {
|
|
351
|
+
const blockJSON = this.toJSON();
|
|
352
|
+
const header = blockJSON.header;
|
|
353
|
+
const transactions = this.transactions.map((tx) => bytesToHex(tx.serialize())) ?? [];
|
|
354
|
+
const withdrawalsArr = blockJSON.withdrawals ? { withdrawals: blockJSON.withdrawals } : {};
|
|
355
|
+
const executionPayload = {
|
|
356
|
+
blockNumber: header.number,
|
|
357
|
+
parentHash: header.parentHash,
|
|
358
|
+
feeRecipient: header.coinbase,
|
|
359
|
+
stateRoot: header.stateRoot,
|
|
360
|
+
receiptsRoot: header.receiptTrie,
|
|
361
|
+
logsBloom: header.logsBloom,
|
|
362
|
+
gasLimit: header.gasLimit,
|
|
363
|
+
gasUsed: header.gasUsed,
|
|
364
|
+
timestamp: header.timestamp,
|
|
365
|
+
extraData: header.extraData,
|
|
366
|
+
baseFeePerGas: header.baseFeePerGas,
|
|
367
|
+
blobGasUsed: header.blobGasUsed,
|
|
368
|
+
excessBlobGas: header.excessBlobGas,
|
|
369
|
+
blockHash: bytesToHex(this.hash()),
|
|
370
|
+
prevRandao: header.mixHash,
|
|
371
|
+
transactions,
|
|
372
|
+
...withdrawalsArr,
|
|
373
|
+
parentBeaconBlockRoot: header.parentBeaconBlockRoot,
|
|
374
|
+
requestsHash: header.requestsHash,
|
|
375
|
+
};
|
|
376
|
+
return executionPayload;
|
|
377
|
+
}
|
|
378
|
+
/**
|
|
379
|
+
* Return a compact error string representation of the object
|
|
380
|
+
*/
|
|
381
|
+
errorStr() {
|
|
382
|
+
let hash = '';
|
|
383
|
+
try {
|
|
384
|
+
hash = bytesToHex(this.hash());
|
|
385
|
+
}
|
|
386
|
+
catch {
|
|
387
|
+
hash = 'error';
|
|
388
|
+
}
|
|
389
|
+
let hf = '';
|
|
390
|
+
try {
|
|
391
|
+
hf = this.common.hardfork();
|
|
392
|
+
}
|
|
393
|
+
catch {
|
|
394
|
+
hf = 'error';
|
|
395
|
+
}
|
|
396
|
+
let errorStr = `block number=${this.header.number} hash=${hash} `;
|
|
397
|
+
errorStr += `hf=${hf} baseFeePerGas=${this.header.baseFeePerGas ?? 'none'} `;
|
|
398
|
+
errorStr += `txs=${this.transactions.length} uncles=${this.uncleHeaders.length}`;
|
|
399
|
+
return errorStr;
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* Internal helper function to create an annotated error message
|
|
403
|
+
*
|
|
404
|
+
* @param msg Base error message
|
|
405
|
+
* @hidden
|
|
406
|
+
*/
|
|
407
|
+
_errorMsg(msg) {
|
|
408
|
+
return `${msg} (${this.errorStr()})`;
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
//# sourceMappingURL=block.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"block.js","sourceRoot":"","sources":["../../../src/block/block.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AACpD,OAAO,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAA;AACrC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AACvD,OAAO,EACL,QAAQ,EACR,0BAA0B,EAC1B,aAAa,EACb,mBAAmB,EACnB,UAAU,EACV,WAAW,GACZ,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAA;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAKlD,oBAAoB;AACpB,4FAA4F;AAC5F,6FAA6F;AAC7F,kEAAkE;AAClE,4DAA4D;AAC5D,yEAAyE;AACzE,OAAO,EACL,WAAW,EAQX,uBAAuB,EACvB,sBAAsB,GACvB,MAAM,aAAa,CAAA;AAIpB;;;;;;;;;;;;;;;GAeG;AACH,MAAM,OAAO,KAAK;IAchB;;;;;OAKG;IACH,YACE,MAAoB,EACpB,eAAmC,EAAE,EACrC,eAA8B,EAAE,EAChC,WAA0B,EAC1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CAAC,qBAAqB;YACnD,YAAY,EAAE,MAAM,CAAC,YAAY;SAClC,CAAA;QAED,OAAO,gBAAgB,CAAA;IACzB,CAAC;IAED;;OAEG;IACI,QAAQ;QACb,IAAI,IAAI,GAAG,EAAE,CAAA;QACb,IAAI,CAAC;YACH,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAA;QAChC,CAAC;QAAC,MAAM,CAAC;YACP,IAAI,GAAG,OAAO,CAAA;QAChB,CAAC;QACD,IAAI,EAAE,GAAG,EAAE,CAAA;QACX,IAAI,CAAC;YACH,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAA;QAC7B,CAAC;QAAC,MAAM,CAAC;YACP,EAAE,GAAG,OAAO,CAAA;QACd,CAAC;QACD,IAAI,QAAQ,GAAG,gBAAgB,IAAI,CAAC,MAAM,CAAC,MAAM,SAAS,IAAI,GAAG,CAAA;QACjE,QAAQ,IAAI,MAAM,EAAE,kBAAkB,IAAI,CAAC,MAAM,CAAC,aAAa,IAAI,MAAM,GAAG,CAAA;QAC5E,QAAQ,IAAI,OAAO,IAAI,CAAC,YAAY,CAAC,MAAM,WAAW,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,CAAA;QAChF,OAAO,QAAQ,CAAA;IACjB,CAAC;IAED;;;;;OAKG;IACO,SAAS,CAAC,GAAW;QAC7B,OAAO,GAAG,GAAG,KAAK,IAAI,CAAC,QAAQ,EAAE,GAAG,CAAA;IACtC,CAAC;CACF"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { Block } from '../index.ts';
|
|
2
|
+
import type { EthersProvider } from '@feelyourprotocol/util';
|
|
3
|
+
import type { BeaconPayloadJSON } from '../from-beacon-payload.ts';
|
|
4
|
+
import type { BlockBytes, BlockData, BlockOptions, ExecutionPayload, HeaderData, JSONRPCBlock } from '../types.ts';
|
|
5
|
+
/**
|
|
6
|
+
* Static constructor to create a block from a block data dictionary
|
|
7
|
+
*
|
|
8
|
+
* @param blockData
|
|
9
|
+
* @param opts
|
|
10
|
+
* @returns a new {@link Block} object
|
|
11
|
+
*/
|
|
12
|
+
export declare function createBlock(blockData?: BlockData, opts?: BlockOptions): Block;
|
|
13
|
+
/**
|
|
14
|
+
* Simple static constructor if only an empty block is needed
|
|
15
|
+
* (tree shaking advantages since it does not draw all the tx constructors in)
|
|
16
|
+
*
|
|
17
|
+
* @param headerData
|
|
18
|
+
* @param opts
|
|
19
|
+
* @returns a new {@link Block} object
|
|
20
|
+
*/
|
|
21
|
+
export declare function createEmptyBlock(headerData: HeaderData, opts?: BlockOptions): Block;
|
|
22
|
+
/**
|
|
23
|
+
* Static constructor to create a block from an array of Bytes values
|
|
24
|
+
*
|
|
25
|
+
* @param values
|
|
26
|
+
* @param opts
|
|
27
|
+
* @returns a new {@link Block} object
|
|
28
|
+
*/
|
|
29
|
+
export declare function createBlockFromBytesArray(values: BlockBytes, opts?: BlockOptions): Block;
|
|
30
|
+
/**
|
|
31
|
+
* Static constructor to create a block from a RLP-serialized block
|
|
32
|
+
*
|
|
33
|
+
* @param serialized
|
|
34
|
+
* @param opts
|
|
35
|
+
* @returns a new {@link Block} object
|
|
36
|
+
*/
|
|
37
|
+
export declare function createBlockFromRLP(serialized: Uint8Array, opts?: BlockOptions): Block;
|
|
38
|
+
/**
|
|
39
|
+
* Creates a new block object from Ethereum JSON RPC.
|
|
40
|
+
*
|
|
41
|
+
* @param blockParams - Ethereum JSON RPC of block (eth_getBlockByNumber)
|
|
42
|
+
* @param uncles - Optional list of Ethereum JSON RPC of uncles (eth_getUncleByBlockHashAndIndex)
|
|
43
|
+
* @param opts - An object describing the blockchain
|
|
44
|
+
* @returns a new {@link Block} object
|
|
45
|
+
*/
|
|
46
|
+
export declare function createBlockFromRPC(blockParams: JSONRPCBlock, uncles?: any[], options?: BlockOptions): Block;
|
|
47
|
+
/**
|
|
48
|
+
* Method to retrieve a block from a JSON-RPC provider and format as a {@link Block}
|
|
49
|
+
* @param provider either a url for a remote provider or an Ethers JSONRPCProvider object
|
|
50
|
+
* @param blockTag block hash or block number to be run
|
|
51
|
+
* @param opts {@link BlockOptions}
|
|
52
|
+
* @returns a new {@link Block} object specified by `blockTag`
|
|
53
|
+
*/
|
|
54
|
+
export declare const createBlockFromJSONRPCProvider: (provider: string | EthersProvider, blockTag: string | bigint, opts: BlockOptions) => Promise<Block>;
|
|
55
|
+
/**
|
|
56
|
+
* Method to retrieve a block from an execution payload
|
|
57
|
+
* @param payload Execution payload constructed from beacon payload data
|
|
58
|
+
* @param opts {@link BlockOptions}
|
|
59
|
+
* @returns The constructed {@link Block} object
|
|
60
|
+
*/
|
|
61
|
+
export declare function createBlockFromExecutionPayload(payload: ExecutionPayload, opts?: BlockOptions): Promise<Block>;
|
|
62
|
+
/**
|
|
63
|
+
* Method to retrieve a block from a beacon payload JSON
|
|
64
|
+
* @param payload JSON of a beacon block fetched from beacon APIs
|
|
65
|
+
* @param opts {@link BlockOptions}
|
|
66
|
+
* @returns The constructed {@link Block} object
|
|
67
|
+
*/
|
|
68
|
+
export declare function createBlockFromBeaconPayloadJSON(payload: BeaconPayloadJSON, opts?: BlockOptions): Promise<Block>;
|
|
69
|
+
/**
|
|
70
|
+
* Creates a block for Clique networks with the seal applied during instantiation.
|
|
71
|
+
* @param blockData Block fields used to build the block
|
|
72
|
+
* @param cliqueSigner Private key bytes used to sign the header
|
|
73
|
+
* @param opts {@link BlockOptions}
|
|
74
|
+
* @returns A sealed Clique {@link Block} object
|
|
75
|
+
*/
|
|
76
|
+
export declare function createSealedCliqueBlock(blockData: BlockData | undefined, cliqueSigner: Uint8Array, opts?: BlockOptions): Block;
|
|
77
|
+
//# sourceMappingURL=constructors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constructors.d.ts","sourceRoot":"","sources":["../../../src/block/constructors.ts"],"names":[],"mappings":"AAwBA,OAAO,EACL,KAAK,EAKN,MAAM,aAAa,CAAA;AAEpB,OAAO,K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