@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
package/src/helpers.ts
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import { MerklePatriciaTrie } from '@feelyourprotocol/mpt'
|
|
2
|
+
import { RLP } from '@feelyourprotocol/rlp'
|
|
3
|
+
import { Blob4844Tx } from '@feelyourprotocol/tx'
|
|
4
|
+
import {
|
|
5
|
+
BIGINT_0,
|
|
6
|
+
BIGINT_1,
|
|
7
|
+
EthereumJSErrorWithoutCode,
|
|
8
|
+
TypeOutput,
|
|
9
|
+
concatBytes,
|
|
10
|
+
isHexString,
|
|
11
|
+
toType,
|
|
12
|
+
} from '@feelyourprotocol/util'
|
|
13
|
+
|
|
14
|
+
import { type Common } from '@feelyourprotocol/common'
|
|
15
|
+
import type { TypedTransaction } from '@feelyourprotocol/tx'
|
|
16
|
+
import type { CLRequest, CLRequestType, PrefixedHexString, Withdrawal } from '@feelyourprotocol/util'
|
|
17
|
+
import type { BlockHeaderBytes, HeaderData } from './types.ts'
|
|
18
|
+
/**
|
|
19
|
+
* Returns a 0x-prefixed hex number string from a hex string or string integer.
|
|
20
|
+
* @param {string} input string to check, convert, and return
|
|
21
|
+
*/
|
|
22
|
+
export const numberToHex = function (input?: string): PrefixedHexString | undefined {
|
|
23
|
+
if (input === undefined) return undefined
|
|
24
|
+
if (!isHexString(input)) {
|
|
25
|
+
const regex = new RegExp(/^\d+$/) // test to make sure input contains only digits
|
|
26
|
+
if (!regex.test(input)) {
|
|
27
|
+
const msg = `Cannot convert string to hex string. numberToHex only supports 0x-prefixed hex or integer strings but the given string was: ${input}`
|
|
28
|
+
throw EthereumJSErrorWithoutCode(msg)
|
|
29
|
+
}
|
|
30
|
+
return `0x${parseInt(input, 10).toString(16)}`
|
|
31
|
+
}
|
|
32
|
+
return input
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Converts the canonical byte-array representation of a header into structured {@link HeaderData}.
|
|
37
|
+
* @param values Header field values in canonical order
|
|
38
|
+
* @returns Parsed header data
|
|
39
|
+
*/
|
|
40
|
+
export function valuesArrayToHeaderData(values: BlockHeaderBytes): HeaderData {
|
|
41
|
+
const [
|
|
42
|
+
parentHash,
|
|
43
|
+
uncleHash,
|
|
44
|
+
coinbase,
|
|
45
|
+
stateRoot,
|
|
46
|
+
transactionsTrie,
|
|
47
|
+
receiptTrie,
|
|
48
|
+
logsBloom,
|
|
49
|
+
difficulty,
|
|
50
|
+
number,
|
|
51
|
+
gasLimit,
|
|
52
|
+
gasUsed,
|
|
53
|
+
timestamp,
|
|
54
|
+
extraData,
|
|
55
|
+
mixHash,
|
|
56
|
+
nonce,
|
|
57
|
+
baseFeePerGas,
|
|
58
|
+
withdrawalsRoot,
|
|
59
|
+
blobGasUsed,
|
|
60
|
+
excessBlobGas,
|
|
61
|
+
parentBeaconBlockRoot,
|
|
62
|
+
requestsHash,
|
|
63
|
+
blockAccessListHash,
|
|
64
|
+
slotNumber,
|
|
65
|
+
] = values
|
|
66
|
+
|
|
67
|
+
if (values.length > 23) {
|
|
68
|
+
throw EthereumJSErrorWithoutCode(
|
|
69
|
+
`invalid header. More values than expected were received. Max: 23, got: ${values.length}`,
|
|
70
|
+
)
|
|
71
|
+
}
|
|
72
|
+
if (values.length < 15) {
|
|
73
|
+
throw EthereumJSErrorWithoutCode(
|
|
74
|
+
`invalid header. Less values than expected were received. Min: 15, got: ${values.length}`,
|
|
75
|
+
)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return {
|
|
79
|
+
parentHash,
|
|
80
|
+
uncleHash,
|
|
81
|
+
coinbase,
|
|
82
|
+
stateRoot,
|
|
83
|
+
transactionsTrie,
|
|
84
|
+
receiptTrie,
|
|
85
|
+
logsBloom,
|
|
86
|
+
difficulty,
|
|
87
|
+
number,
|
|
88
|
+
gasLimit,
|
|
89
|
+
gasUsed,
|
|
90
|
+
timestamp,
|
|
91
|
+
extraData,
|
|
92
|
+
mixHash,
|
|
93
|
+
nonce,
|
|
94
|
+
baseFeePerGas,
|
|
95
|
+
withdrawalsRoot,
|
|
96
|
+
blobGasUsed,
|
|
97
|
+
excessBlobGas,
|
|
98
|
+
parentBeaconBlockRoot,
|
|
99
|
+
requestsHash,
|
|
100
|
+
blockAccessListHash,
|
|
101
|
+
slotNumber,
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Retrieves the header difficulty as a bigint if the field is provided.
|
|
107
|
+
* @param headerData Header data potentially containing a difficulty value
|
|
108
|
+
* @returns Difficulty as bigint, or `null` when unset
|
|
109
|
+
*/
|
|
110
|
+
export function getDifficulty(headerData: HeaderData): bigint | null {
|
|
111
|
+
const { difficulty } = headerData
|
|
112
|
+
if (difficulty !== undefined) {
|
|
113
|
+
return toType(difficulty, TypeOutput.BigInt)
|
|
114
|
+
}
|
|
115
|
+
return null
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Counts the total number of blob commitments contained in the provided transactions.
|
|
120
|
+
* @param transactions Transactions to inspect for blob data
|
|
121
|
+
* @returns Number of blob versioned hashes referenced
|
|
122
|
+
*/
|
|
123
|
+
export const getNumBlobs = (transactions: TypedTransaction[]) => {
|
|
124
|
+
let numBlobs = 0
|
|
125
|
+
for (const tx of transactions) {
|
|
126
|
+
if (tx instanceof Blob4844Tx) {
|
|
127
|
+
numBlobs += tx.blobVersionedHashes.length
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return numBlobs
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Approximates `factor * e ** (numerator / denominator)` using Taylor expansion
|
|
135
|
+
*/
|
|
136
|
+
export const fakeExponential = (factor: bigint, numerator: bigint, denominator: bigint) => {
|
|
137
|
+
let i = BIGINT_1
|
|
138
|
+
let output = BIGINT_0
|
|
139
|
+
let numerator_accumulator = factor * denominator
|
|
140
|
+
while (numerator_accumulator > BIGINT_0) {
|
|
141
|
+
output += numerator_accumulator
|
|
142
|
+
numerator_accumulator = (numerator_accumulator * numerator) / (denominator * i)
|
|
143
|
+
i++
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return output / denominator
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Returns the blob gas price depending upon the `excessBlobGas` value
|
|
151
|
+
* @param excessBlobGas
|
|
152
|
+
* @param common
|
|
153
|
+
*/
|
|
154
|
+
export const computeBlobGasPrice = (excessBlobGas: bigint, common: Common) => {
|
|
155
|
+
return fakeExponential(
|
|
156
|
+
common.param('minBlobGas'),
|
|
157
|
+
excessBlobGas,
|
|
158
|
+
common.param('blobGasPriceUpdateFraction'),
|
|
159
|
+
)
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Returns the withdrawals trie root for array of Withdrawal.
|
|
164
|
+
* @param wts array of Withdrawal to compute the root of
|
|
165
|
+
* @param emptyTrie Optional trie used to generate the root
|
|
166
|
+
*/
|
|
167
|
+
export async function genWithdrawalsTrieRoot(wts: Withdrawal[], emptyTrie?: MerklePatriciaTrie) {
|
|
168
|
+
const trie = emptyTrie ?? new MerklePatriciaTrie()
|
|
169
|
+
for (const [i, wt] of wts.entries()) {
|
|
170
|
+
await trie.put(RLP.encode(i), RLP.encode(wt.raw()))
|
|
171
|
+
}
|
|
172
|
+
return trie.root()
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Returns the txs trie root for array of TypedTransaction
|
|
177
|
+
* @param txs array of TypedTransaction to compute the root of
|
|
178
|
+
* @param emptyTrie Optional trie used to generate the root
|
|
179
|
+
*/
|
|
180
|
+
export async function genTransactionsTrieRoot(
|
|
181
|
+
txs: TypedTransaction[],
|
|
182
|
+
emptyTrie?: MerklePatriciaTrie,
|
|
183
|
+
) {
|
|
184
|
+
const trie = emptyTrie ?? new MerklePatriciaTrie()
|
|
185
|
+
for (const [i, tx] of txs.entries()) {
|
|
186
|
+
await trie.put(RLP.encode(i), tx.serialize())
|
|
187
|
+
}
|
|
188
|
+
return trie.root()
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Returns the requests trie root for an array of CLRequests
|
|
193
|
+
* @param requests - an array of CLRequests
|
|
194
|
+
* @param sha256Function Hash function used to derive the requests root
|
|
195
|
+
* @param emptyTrie optional empty trie used to generate the root
|
|
196
|
+
* @returns a 32 byte Uint8Array representing the requests trie root
|
|
197
|
+
*/
|
|
198
|
+
export function genRequestsRoot(
|
|
199
|
+
requests: CLRequest<CLRequestType>[],
|
|
200
|
+
sha256Function: (msg: Uint8Array) => Uint8Array,
|
|
201
|
+
) {
|
|
202
|
+
// Requests should be sorted in monotonically ascending order based on type
|
|
203
|
+
// and whatever internal sorting logic is defined by each request type
|
|
204
|
+
if (requests.length > 1) {
|
|
205
|
+
for (let x = 1; x < requests.length; x++) {
|
|
206
|
+
if (requests[x].type < requests[x - 1].type)
|
|
207
|
+
throw EthereumJSErrorWithoutCode('requests are not sorted in ascending order')
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// def compute_requests_hash(list):
|
|
212
|
+
// return keccak_256(rlp.encode([rlp.encode(req) for req in list]))
|
|
213
|
+
|
|
214
|
+
let flatRequests = new Uint8Array()
|
|
215
|
+
for (const req of requests) {
|
|
216
|
+
if (req.bytes.length > 1) {
|
|
217
|
+
// Only append requests if they have content
|
|
218
|
+
flatRequests = concatBytes(flatRequests, sha256Function(req.bytes))
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
return sha256Function(flatRequests)
|
|
223
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export * from './block/index.ts'
|
|
2
|
+
export * from './consensus/index.ts'
|
|
3
|
+
export { type BeaconPayloadJSON, executionPayloadFromBeaconPayload } from './from-beacon-payload.ts'
|
|
4
|
+
export * from './header/index.ts'
|
|
5
|
+
export {
|
|
6
|
+
genRequestsRoot,
|
|
7
|
+
genTransactionsTrieRoot,
|
|
8
|
+
genWithdrawalsTrieRoot,
|
|
9
|
+
getDifficulty,
|
|
10
|
+
valuesArrayToHeaderData,
|
|
11
|
+
} from './helpers.ts'
|
|
12
|
+
export * from './params.ts'
|
|
13
|
+
export * from './types.ts'
|
package/src/params.ts
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import type { ParamsDict } from '@feelyourprotocol/common'
|
|
2
|
+
|
|
3
|
+
export const paramsBlock: ParamsDict = {
|
|
4
|
+
/**
|
|
5
|
+
* Frontier/Chainstart
|
|
6
|
+
*/
|
|
7
|
+
1: {
|
|
8
|
+
// gasConfig
|
|
9
|
+
minGasLimit: 5000, // Minimum the gas limit may ever be
|
|
10
|
+
gasLimitBoundDivisor: 1024, // The bound divisor of the gas limit, used in update calculations
|
|
11
|
+
targetBlobGasPerBlock: 0, // Base value needed here since called pre-4844 in BlockHeader.calcNextExcessBlobGas()
|
|
12
|
+
blobGasPerBlob: 0,
|
|
13
|
+
maxBlobGasPerBlock: 0,
|
|
14
|
+
// format
|
|
15
|
+
maxExtraDataSize: 32, // Maximum size extra data may be after Genesis
|
|
16
|
+
// pow
|
|
17
|
+
minimumDifficulty: 131072, // The minimum that the difficulty may ever be
|
|
18
|
+
difficultyBoundDivisor: 2048, // The bound divisor of the difficulty, used in the update calculations
|
|
19
|
+
durationLimit: 13, // The decision boundary on the blocktime duration used to determine whether difficulty should go up or not
|
|
20
|
+
difficultyBombDelay: 0, // the amount of blocks to delay the difficulty bomb with
|
|
21
|
+
},
|
|
22
|
+
/**
|
|
23
|
+
* Byzantium HF Meta EIP
|
|
24
|
+
*/
|
|
25
|
+
609: {
|
|
26
|
+
// pow
|
|
27
|
+
difficultyBombDelay: 3000000, // the amount of blocks to delay the difficulty bomb with
|
|
28
|
+
},
|
|
29
|
+
/**
|
|
30
|
+
* Constantinople HF Meta EIP
|
|
31
|
+
*/
|
|
32
|
+
1013: {
|
|
33
|
+
// pow
|
|
34
|
+
difficultyBombDelay: 5000000, // the amount of blocks to delay the difficulty bomb with
|
|
35
|
+
},
|
|
36
|
+
/**
|
|
37
|
+
* MuirGlacier HF Meta EIP
|
|
38
|
+
*/
|
|
39
|
+
2384: {
|
|
40
|
+
// pow
|
|
41
|
+
difficultyBombDelay: 9000000, // the amount of blocks to delay the difficulty bomb with
|
|
42
|
+
},
|
|
43
|
+
/**
|
|
44
|
+
* Fee market change for ETH 1.0 chain
|
|
45
|
+
*/
|
|
46
|
+
1559: {
|
|
47
|
+
// gasConfig
|
|
48
|
+
baseFeeMaxChangeDenominator: 8, // Maximum base fee change denominator
|
|
49
|
+
elasticityMultiplier: 2, // Maximum block gas target elasticity
|
|
50
|
+
initialBaseFee: 1000000000, // Initial base fee on first EIP1559 block
|
|
51
|
+
},
|
|
52
|
+
/**
|
|
53
|
+
* Difficulty Bomb Delay to December 1st 2021
|
|
54
|
+
*/
|
|
55
|
+
3554: {
|
|
56
|
+
// pow
|
|
57
|
+
difficultyBombDelay: 9500000, // the amount of blocks to delay the difficulty bomb with
|
|
58
|
+
},
|
|
59
|
+
/**
|
|
60
|
+
* Difficulty Bomb Delay to June 2022
|
|
61
|
+
*/
|
|
62
|
+
4345: {
|
|
63
|
+
// pow
|
|
64
|
+
difficultyBombDelay: 10700000, // the amount of blocks to delay the difficulty bomb with
|
|
65
|
+
},
|
|
66
|
+
/**
|
|
67
|
+
* Shard Blob Transactions
|
|
68
|
+
*/
|
|
69
|
+
4844: {
|
|
70
|
+
// gasConfig
|
|
71
|
+
targetBlobGasPerBlock: 393216, // The target blob gas consumed per block
|
|
72
|
+
blobGasPerBlob: 131072, // The base fee for blob gas per blob
|
|
73
|
+
maxBlobGasPerBlock: 786432, // The max blob gas allowable per block
|
|
74
|
+
blobGasPriceUpdateFraction: 3338477, // The denominator used in the exponential when calculating a blob gas price
|
|
75
|
+
// gasPrices
|
|
76
|
+
minBlobGas: 1, // The minimum fee per blob gas
|
|
77
|
+
blobBaseCost: 8192, // EIP-7918: Blob base fee bounded by execution cost (2^13)
|
|
78
|
+
},
|
|
79
|
+
/**
|
|
80
|
+
* Delaying Difficulty Bomb to mid-September 2022
|
|
81
|
+
*/
|
|
82
|
+
5133: {
|
|
83
|
+
// pow
|
|
84
|
+
difficultyBombDelay: 11400000, // the amount of blocks to delay the difficulty bomb with
|
|
85
|
+
},
|
|
86
|
+
/**
|
|
87
|
+
* Blob throughput increase
|
|
88
|
+
*/
|
|
89
|
+
7691: {
|
|
90
|
+
// gasConfig
|
|
91
|
+
targetBlobGasPerBlock: 786432, // The target blob gas consumed per block
|
|
92
|
+
maxBlobGasPerBlock: 1179648, // The max blob gas allowable per block
|
|
93
|
+
blobGasPriceUpdateFraction: 5007716, // The denominator used in the exponential when calculating a blob gas price
|
|
94
|
+
},
|
|
95
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import type { Common, ParamsDict } from '@feelyourprotocol/common'
|
|
2
|
+
import type { JSONRPCTx, JSONTx, TransactionType, TxData } from '@feelyourprotocol/tx'
|
|
3
|
+
import type {
|
|
4
|
+
AddressLike,
|
|
5
|
+
BigIntLike,
|
|
6
|
+
BytesLike,
|
|
7
|
+
JSONRPCWithdrawal,
|
|
8
|
+
NumericString,
|
|
9
|
+
PrefixedHexString,
|
|
10
|
+
WithdrawalBytes,
|
|
11
|
+
WithdrawalData,
|
|
12
|
+
} from '@feelyourprotocol/util'
|
|
13
|
+
import type { BlockHeader } from './index.ts'
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* An object to set to which blockchain the blocks and their headers belong. This could be specified
|
|
17
|
+
* using a {@link Common} object, or `chain` and `hardfork`. Defaults to mainnet without specifying a
|
|
18
|
+
* hardfork.
|
|
19
|
+
*/
|
|
20
|
+
export interface BlockOptions {
|
|
21
|
+
/**
|
|
22
|
+
* A {@link Common} object defining the chain and the hardfork a block/block header belongs to.
|
|
23
|
+
*
|
|
24
|
+
* Object will be internally copied so that tx behavior don't incidentally
|
|
25
|
+
* change on future HF changes.
|
|
26
|
+
*
|
|
27
|
+
* Default: {@link Common} object set to `mainnet` and the HF currently defined as the default
|
|
28
|
+
* hardfork in the {@link Common} class.
|
|
29
|
+
*
|
|
30
|
+
* Current default hardfork: `merge`
|
|
31
|
+
*/
|
|
32
|
+
common?: Common
|
|
33
|
+
/**
|
|
34
|
+
* Set the hardfork either by timestamp (for HFs from Shanghai onwards) or by block number
|
|
35
|
+
* for older Hfs.
|
|
36
|
+
*
|
|
37
|
+
* Default: `false` (HF is set to whatever default HF is set by the {@link Common} instance)
|
|
38
|
+
*/
|
|
39
|
+
setHardfork?: boolean
|
|
40
|
+
/**
|
|
41
|
+
* Block parameters sorted by EIP can be found in the exported `paramsBlock` dictionary,
|
|
42
|
+
* which is internally passed to the associated `@feelyourprotocol/common` instance which
|
|
43
|
+
* manages parameter selection based on the hardfork and EIP settings.
|
|
44
|
+
*
|
|
45
|
+
* This option allows providing a custom set of parameters. Note that parameters
|
|
46
|
+
* get fully overwritten, so you need to extend the default parameter dict
|
|
47
|
+
* to provide the full parameter set.
|
|
48
|
+
*
|
|
49
|
+
* It is recommended to deep-clone the params object for this to avoid side effects:
|
|
50
|
+
*
|
|
51
|
+
* ```ts
|
|
52
|
+
* const params = JSON.parse(JSON.stringify(paramsBlock))
|
|
53
|
+
* params['1']['minGasLimit'] = 3000 // 5000
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
params?: ParamsDict
|
|
57
|
+
/**
|
|
58
|
+
* If a preceding {@link BlockHeader} (usually the parent header) is given the preceding
|
|
59
|
+
* header will be used to calculate the difficulty for this block and the calculated
|
|
60
|
+
* difficulty takes precedence over a provided static `difficulty` value.
|
|
61
|
+
*
|
|
62
|
+
* Note that this option has no effect on networks other than PoW/Ethash networks
|
|
63
|
+
* (respectively also deactivates on the Merge HF switching to PoS/Casper).
|
|
64
|
+
*/
|
|
65
|
+
calcDifficultyFromHeader?: BlockHeader
|
|
66
|
+
/**
|
|
67
|
+
* A block object by default gets frozen along initialization. This gives you
|
|
68
|
+
* strong additional security guarantees on the consistency of the block parameters.
|
|
69
|
+
* It also enables block hash caching when the `hash()` method is called multiple times.
|
|
70
|
+
*
|
|
71
|
+
* If you need to deactivate the block freeze - e.g. because you want to subclass block and
|
|
72
|
+
* add additional properties - it is strongly encouraged that you do the freeze yourself
|
|
73
|
+
* within your code instead.
|
|
74
|
+
*
|
|
75
|
+
* Default: true
|
|
76
|
+
*/
|
|
77
|
+
freeze?: boolean
|
|
78
|
+
/**
|
|
79
|
+
* Skip consensus format validation checks on header if set. Defaults to false.
|
|
80
|
+
*/
|
|
81
|
+
skipConsensusFormatValidation?: boolean
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* A block header's data.
|
|
86
|
+
*/
|
|
87
|
+
export interface HeaderData {
|
|
88
|
+
parentHash?: BytesLike
|
|
89
|
+
uncleHash?: BytesLike
|
|
90
|
+
coinbase?: AddressLike
|
|
91
|
+
stateRoot?: BytesLike
|
|
92
|
+
transactionsTrie?: BytesLike
|
|
93
|
+
receiptTrie?: BytesLike
|
|
94
|
+
logsBloom?: BytesLike
|
|
95
|
+
difficulty?: BigIntLike
|
|
96
|
+
number?: BigIntLike
|
|
97
|
+
gasLimit?: BigIntLike
|
|
98
|
+
gasUsed?: BigIntLike
|
|
99
|
+
timestamp?: BigIntLike
|
|
100
|
+
extraData?: BytesLike
|
|
101
|
+
mixHash?: BytesLike
|
|
102
|
+
nonce?: BytesLike
|
|
103
|
+
baseFeePerGas?: BigIntLike
|
|
104
|
+
withdrawalsRoot?: BytesLike
|
|
105
|
+
blobGasUsed?: BigIntLike
|
|
106
|
+
excessBlobGas?: BigIntLike
|
|
107
|
+
parentBeaconBlockRoot?: BytesLike
|
|
108
|
+
requestsHash?: BytesLike
|
|
109
|
+
/**
|
|
110
|
+
* 32 bytes hash of the block access list (EIP-7928)
|
|
111
|
+
*/
|
|
112
|
+
blockAccessListHash?: BytesLike
|
|
113
|
+
/**
|
|
114
|
+
* Slot number (EIP-7843)
|
|
115
|
+
*/
|
|
116
|
+
slotNumber?: BigIntLike
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* A block's data.
|
|
121
|
+
*/
|
|
122
|
+
export interface BlockData {
|
|
123
|
+
/**
|
|
124
|
+
* Header data for the block
|
|
125
|
+
*/
|
|
126
|
+
header?: HeaderData
|
|
127
|
+
transactions?: Array<TxData[TransactionType]>
|
|
128
|
+
uncleHeaders?: Array<HeaderData>
|
|
129
|
+
withdrawals?: Array<WithdrawalData>
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export type WithdrawalsBytes = WithdrawalBytes[]
|
|
133
|
+
|
|
134
|
+
export type BlockBytes =
|
|
135
|
+
| [BlockHeaderBytes, TransactionsBytes, UncleHeadersBytes]
|
|
136
|
+
| [BlockHeaderBytes, TransactionsBytes, UncleHeadersBytes, WithdrawalsBytes]
|
|
137
|
+
| [BlockHeaderBytes, TransactionsBytes, UncleHeadersBytes, WithdrawalsBytes]
|
|
138
|
+
|
|
139
|
+
export type BlockHeaderBytes = Uint8Array[]
|
|
140
|
+
export type BlockBodyBytes = [TransactionsBytes, UncleHeadersBytes, WithdrawalsBytes?]
|
|
141
|
+
/**
|
|
142
|
+
* TransactionsBytes can be an array of serialized txs for Typed Transactions or an array of Uint8Array Arrays for legacy transactions.
|
|
143
|
+
*/
|
|
144
|
+
export type TransactionsBytes = Uint8Array[][] | Uint8Array[]
|
|
145
|
+
export type UncleHeadersBytes = Uint8Array[][]
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* An object with the block's data represented as strings.
|
|
149
|
+
*/
|
|
150
|
+
export interface JSONBlock {
|
|
151
|
+
/**
|
|
152
|
+
* Header data for the block
|
|
153
|
+
*/
|
|
154
|
+
header?: JSONHeader
|
|
155
|
+
transactions?: JSONTx[]
|
|
156
|
+
uncleHeaders?: JSONHeader[]
|
|
157
|
+
withdrawals?: JSONRPCWithdrawal[]
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* An object with the block header's data represented as 0x-prefixed hex strings.
|
|
162
|
+
*/
|
|
163
|
+
export interface JSONHeader {
|
|
164
|
+
parentHash?: PrefixedHexString
|
|
165
|
+
uncleHash?: PrefixedHexString
|
|
166
|
+
coinbase?: PrefixedHexString
|
|
167
|
+
stateRoot?: PrefixedHexString
|
|
168
|
+
transactionsTrie?: PrefixedHexString
|
|
169
|
+
receiptTrie?: PrefixedHexString
|
|
170
|
+
logsBloom?: PrefixedHexString
|
|
171
|
+
difficulty?: PrefixedHexString
|
|
172
|
+
number?: PrefixedHexString
|
|
173
|
+
gasLimit?: PrefixedHexString
|
|
174
|
+
gasUsed?: PrefixedHexString
|
|
175
|
+
timestamp?: PrefixedHexString
|
|
176
|
+
extraData?: PrefixedHexString
|
|
177
|
+
mixHash?: PrefixedHexString
|
|
178
|
+
nonce?: PrefixedHexString
|
|
179
|
+
baseFeePerGas?: PrefixedHexString
|
|
180
|
+
withdrawalsRoot?: PrefixedHexString
|
|
181
|
+
blobGasUsed?: PrefixedHexString
|
|
182
|
+
excessBlobGas?: PrefixedHexString
|
|
183
|
+
parentBeaconBlockRoot?: PrefixedHexString
|
|
184
|
+
requestsHash?: PrefixedHexString
|
|
185
|
+
blockAccessListHash?: PrefixedHexString
|
|
186
|
+
slotNumber?: PrefixedHexString
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/*
|
|
190
|
+
* Based on https://ethereum.org/en/developers/docs/apis/json-rpc/
|
|
191
|
+
*/
|
|
192
|
+
export interface JSONRPCBlock {
|
|
193
|
+
number: PrefixedHexString // the block number.
|
|
194
|
+
hash: PrefixedHexString // hash of the block.
|
|
195
|
+
parentHash: PrefixedHexString // hash of the parent block.
|
|
196
|
+
mixHash?: PrefixedHexString // bit hash which proves combined with the nonce that a sufficient amount of computation has been carried out on this block.
|
|
197
|
+
nonce: PrefixedHexString // hash of the generated proof-of-work.
|
|
198
|
+
sha3Uncles: PrefixedHexString // SHA3 of the uncles data in the block.
|
|
199
|
+
logsBloom: PrefixedHexString // the bloom filter for the logs of the block.
|
|
200
|
+
transactionsRoot: PrefixedHexString // the root of the transaction trie of the block.
|
|
201
|
+
stateRoot: PrefixedHexString // the root of the final state trie of the block.
|
|
202
|
+
receiptsRoot: PrefixedHexString // the root of the receipts trie of the block.
|
|
203
|
+
miner: PrefixedHexString // the address of the beneficiary to whom the mining rewards were given.
|
|
204
|
+
difficulty: PrefixedHexString | NumericString // integer of the difficulty for this block. Can be a 0x-prefixed hex string or a string integer
|
|
205
|
+
totalDifficulty?: PrefixedHexString // integer of the total difficulty of the chain until this block.
|
|
206
|
+
extraData: PrefixedHexString // the “extra data” field of this block.
|
|
207
|
+
size: PrefixedHexString // integer the size of this block in bytes.
|
|
208
|
+
gasLimit: PrefixedHexString // the maximum gas allowed in this block.
|
|
209
|
+
gasUsed: PrefixedHexString // the total used gas by all transactions in this block.
|
|
210
|
+
timestamp: PrefixedHexString // the unix timestamp for when the block was collated.
|
|
211
|
+
transactions: Array<JSONRPCTx | PrefixedHexString> // Array of transaction objects, or 32 Bytes transaction hashes depending on the last given parameter.
|
|
212
|
+
uncles: PrefixedHexString[] // Array of uncle hashes
|
|
213
|
+
baseFeePerGas?: PrefixedHexString // If EIP-1559 is enabled for this block, returns the base fee per gas
|
|
214
|
+
withdrawals?: Array<JSONRPCWithdrawal> // If EIP-4895 is enabled for this block, array of withdrawals
|
|
215
|
+
withdrawalsRoot?: PrefixedHexString // If EIP-4895 is enabled for this block, the root of the withdrawal trie of the block.
|
|
216
|
+
blobGasUsed?: PrefixedHexString // If EIP-4844 is enabled for this block, returns the blob gas used for the block
|
|
217
|
+
excessBlobGas?: PrefixedHexString // If EIP-4844 is enabled for this block, returns the excess blob gas for the block
|
|
218
|
+
parentBeaconBlockRoot?: PrefixedHexString // If EIP-4788 is enabled for this block, returns parent beacon block root
|
|
219
|
+
requestsHash?: PrefixedHexString // If EIP-7685 is enabled for this block, returns the requests root
|
|
220
|
+
blockAccessListHash?: PrefixedHexString // If EIP-7928 is enabled for this block, returns the hash of the block access list
|
|
221
|
+
slotNumber?: PrefixedHexString // If EIP-7843 is enabled for this block, returns the slot number
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export type WithdrawalV1 = {
|
|
225
|
+
index: PrefixedHexString // Quantity, 8 Bytes
|
|
226
|
+
validatorIndex: PrefixedHexString // Quantity, 8 bytes
|
|
227
|
+
address: PrefixedHexString // DATA, 20 bytes
|
|
228
|
+
amount: PrefixedHexString // Quantity, 32 bytes
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// Note: all these strings are 0x-prefixed
|
|
232
|
+
export type ExecutionPayload = {
|
|
233
|
+
parentHash: PrefixedHexString // DATA, 32 Bytes
|
|
234
|
+
feeRecipient: PrefixedHexString // DATA, 20 Bytes
|
|
235
|
+
stateRoot: PrefixedHexString // DATA, 32 Bytes
|
|
236
|
+
receiptsRoot: PrefixedHexString // DATA, 32 bytes
|
|
237
|
+
logsBloom: PrefixedHexString // DATA, 256 Bytes
|
|
238
|
+
prevRandao: PrefixedHexString // DATA, 32 Bytes
|
|
239
|
+
blockNumber: PrefixedHexString // QUANTITY, 64 Bits
|
|
240
|
+
gasLimit: PrefixedHexString // QUANTITY, 64 Bits
|
|
241
|
+
gasUsed: PrefixedHexString // QUANTITY, 64 Bits
|
|
242
|
+
timestamp: PrefixedHexString // QUANTITY, 64 Bits
|
|
243
|
+
extraData: PrefixedHexString // DATA, 0 to 32 Bytes
|
|
244
|
+
baseFeePerGas: PrefixedHexString // QUANTITY, 256 Bits
|
|
245
|
+
blockHash: PrefixedHexString // DATA, 32 Bytes
|
|
246
|
+
transactions: PrefixedHexString[] // Array of DATA - Array of transaction rlp strings,
|
|
247
|
+
withdrawals?: WithdrawalV1[] // Array of withdrawal objects
|
|
248
|
+
blobGasUsed?: PrefixedHexString // QUANTITY, 64 Bits
|
|
249
|
+
excessBlobGas?: PrefixedHexString // QUANTITY, 64 Bits
|
|
250
|
+
parentBeaconBlockRoot?: PrefixedHexString // QUANTITY, 64 Bits
|
|
251
|
+
requestsHash?: PrefixedHexString
|
|
252
|
+
blockAccessListHash?: PrefixedHexString // DATA, 32 Bytes
|
|
253
|
+
slotNumber?: PrefixedHexString // QUANTITY, 64 Bits (EIP-7843)
|
|
254
|
+
}
|