Skip to content

Commit 03ee08a

Browse files
ryanioholgerd77
authored andcommitted
develop: ci fix, some last backwards compatibility removals (#1834)
* move ethash depBrowserWorkaround fix for bigint-crypto-utils to blockchain karma.conf.js (karma has trouble with the default browser esm import without es6 transform, so it is easier to tell it to use umd) * new DefaultStateManager will init a trie if not supplied, so we don't need to init one here * remove backwards compatibility note (we will keep this property) * trie: remove old backwards compat methods * client: do undefined check first * vm: undo doc change * client: improve receipt size calculation * vm: resolve more todos * vm: more hardfork enum usage * dedupe receipt rlp encoding * lint * runCall, runCode: add more param typedocs, simplify * also add karma workaround to vm
1 parent e59d4e7 commit 03ee08a

File tree

20 files changed

+150
-123
lines changed

20 files changed

+150
-123
lines changed

packages/blockchain/karma.conf.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module.exports = function(config) {
1+
module.exports = function (config) {
22
config.set({
33
browserNoActivityTimeout: 60000,
44
frameworks: ['karma-typescript', 'tap'],
@@ -11,8 +11,13 @@ module.exports = function(config) {
1111
bundlerOptions: {
1212
entrypoints: /\.spec\.ts$/,
1313
acornOptions: {
14-
ecmaVersion: 11
15-
}
14+
ecmaVersion: 11,
15+
},
16+
resolve: {
17+
alias: {
18+
'bigint-crypto-utils': '../../node_modules/bigint-crypto-utils/dist/bundles/umd.js',
19+
},
20+
},
1621
},
1722
},
1823
concurrency: 1,

packages/client/lib/net/protocol/ethprotocol.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import {
66
BlockBodyBuffer,
77
} from '@ethereumjs/block'
88
import { TransactionFactory, TypedTransaction } from '@ethereumjs/tx'
9-
import { bigIntToBuffer, bufferToBigInt, bufferToInt, intToBuffer, rlp } from 'ethereumjs-util'
9+
import { encodeReceipt } from '@ethereumjs/vm/dist/runBlock'
10+
import { bigIntToBuffer, bufferToBigInt, bufferToInt, rlp } from 'ethereumjs-util'
1011
import { Chain } from './../../blockchain'
1112
import { Message, Protocol, ProtocolOptions } from './protocol'
1213
import type { TxReceiptWithType } from '../../execution/receipt'
@@ -231,18 +232,7 @@ export class EthProtocol extends Protocol {
231232
encode: ({ reqId, receipts }: { reqId: bigint; receipts: TxReceiptWithType[] }) => {
232233
const serializedReceipts = []
233234
for (const receipt of receipts) {
234-
let encodedReceipt = rlp.encode([
235-
(receipt as PreByzantiumTxReceipt).stateRoot ??
236-
(receipt as PostByzantiumTxReceipt).status,
237-
bigIntToBuffer(receipt.gasUsed),
238-
receipt.bitvector,
239-
receipt.logs,
240-
])
241-
if (receipt.txType > 0) {
242-
// Serialize receipt according to EIP-2718:
243-
// `typed-receipt = tx-type || receipt-data`
244-
encodedReceipt = Buffer.concat([intToBuffer(receipt.txType), encodedReceipt])
245-
}
235+
const encodedReceipt = encodeReceipt(receipt, receipt.txType)
246236
serializedReceipts.push(encodedReceipt)
247237
}
248238
return [bigIntToBuffer(reqId), serializedReceipts]

packages/client/lib/service/fullethereumservice.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Hardfork } from '@ethereumjs/common'
22
import { Skeleton } from '../sync/skeleton'
3-
import { bigIntToBuffer } from 'ethereumjs-util'
3+
import { encodeReceipt } from '@ethereumjs/vm/dist/runBlock'
44
import { EthereumService, EthereumServiceOptions } from './ethereumservice'
55
import { TxPool } from './txpool'
66
import { BeaconSynchronizer, FullSynchronizer } from '../sync'
@@ -260,10 +260,10 @@ export class FullEthereumService extends EthereumService {
260260
let receiptsSize = 0
261261
for (const hash of hashes) {
262262
const blockReceipts = await receiptsManager.getReceipts(hash, true, true)
263-
blockReceipts.forEach((r) => (r.gasUsed = bigIntToBuffer(r.gasUsed) as any))
264263
if (!blockReceipts) continue
265264
receipts.push(...blockReceipts)
266-
receiptsSize += Buffer.byteLength(JSON.stringify(blockReceipts))
265+
const receiptsBuffer = Buffer.concat(receipts.map((r) => encodeReceipt(r, r.txType)))
266+
receiptsSize += Buffer.byteLength(receiptsBuffer)
267267
// From spec: The recommended soft limit for Receipts responses is 2 MiB.
268268
if (receiptsSize >= 2097152) {
269269
break

packages/ethash/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
"types": "dist/index.d.ts",
1919
"browser": "dist.browser/index.js",
2020
"scripts": {
21-
"postinstall": "npm run depBrowserWorkaround",
22-
"depBrowserWorkaround": "npx json -I -f ../../node_modules/bigint-crypto-utils/package.json -e \"this.browser='./dist/bundles/umd.js'\"",
2321
"build": "npm run build:node && npm run build:browser",
2422
"build:node": "../../config/cli/ts-build.sh node",
2523
"build:browser": "../../config/cli/ts-build.sh browser",

packages/trie/src/baseTrie.ts

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export class Trie {
104104
*/
105105
async checkRoot(root: Buffer): Promise<boolean> {
106106
try {
107-
const value = await this._lookupNode(root)
107+
const value = await this.lookupNode(root)
108108
return value !== null
109109
} catch (error: any) {
110110
if (error.message == 'Missing node in DB') {
@@ -244,7 +244,7 @@ export class Trie {
244244
}
245245
}
246246

247-
// Resolve if _walkTrie finishes without finding any nodes
247+
// Resolve if walkTrie finishes without finding any nodes
248248
resolve({ node: null, remaining: [], stack })
249249
})
250250
}
@@ -259,16 +259,6 @@ export class Trie {
259259
await WalkController.newWalk(onFound, this, root)
260260
}
261261

262-
/**
263-
* @hidden
264-
* Backwards compatibility
265-
* @param root -
266-
* @param onFound -
267-
*/
268-
async _walkTrie(root: Buffer, onFound: FoundNodeFunction): Promise<void> {
269-
await this.walkTrie(root, onFound)
270-
}
271-
272262
/**
273263
* Creates the initial node from an empty tree.
274264
* @private
@@ -298,15 +288,6 @@ export class Trie {
298288
return foundNode
299289
}
300290

301-
/**
302-
* @hidden
303-
* Backwards compatibility
304-
* @param node The node hash to lookup from the DB
305-
*/
306-
async _lookupNode(node: Buffer | Buffer[]): Promise<TrieNode | null> {
307-
return this.lookupNode(node)
308-
}
309-
310291
/**
311292
* Updates a node.
312293
* @private
@@ -517,7 +498,7 @@ export class Trie {
517498
const branchNodeKey = branchNodes[0][0]
518499

519500
// look up node
520-
const foundNode = await this._lookupNode(branchNode)
501+
const foundNode = await this.lookupNode(branchNode)
521502
if (foundNode) {
522503
key = processBranchNode(
523504
key,

packages/trie/src/util/walkController.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export class WalkController {
5151
this.reject = reject
5252
let node
5353
try {
54-
node = await this.trie._lookupNode(root)
54+
node = await this.trie.lookupNode(root)
5555
} catch (error: any) {
5656
return this.reject(error)
5757
}
@@ -98,7 +98,7 @@ export class WalkController {
9898
async (taskFinishedCallback: Function) => {
9999
let childNode
100100
try {
101-
childNode = await this.trie._lookupNode(nodeRef)
101+
childNode = await this.trie.lookupNode(nodeRef)
102102
} catch (error: any) {
103103
return this.reject(error)
104104
}

packages/vm/karma.conf.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,13 @@ module.exports = function (config) {
2424
bundlerOptions: {
2525
entrypoints: /\.spec\.ts$/,
2626
acornOptions: {
27-
ecmaVersion: 11
28-
}
27+
ecmaVersion: 11,
28+
},
29+
resolve: {
30+
alias: {
31+
'bigint-crypto-utils': '../../node_modules/bigint-crypto-utils/dist/bundles/umd.js',
32+
},
33+
},
2934
},
3035
},
3136

packages/vm/src/buildBlock.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ export class BlockBuilder {
139139
const receiptTrie = new Trie()
140140
for (const [i, txResult] of this.transactionResults.entries()) {
141141
const tx = this.transactions[i]
142-
const encodedReceipt = encodeReceipt(tx, txResult.receipt)
142+
const encodedReceipt = encodeReceipt(txResult.receipt, tx.type)
143143
await receiptTrie.put(rlp.encode(i), encodedReceipt)
144144
}
145145
return receiptTrie.root

packages/vm/src/evm/evm.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export interface ExecResult {
5959
*/
6060
gas?: bigint
6161
/**
62-
* Amount of gas the transaction used to run
62+
* Amount of gas the code used to run
6363
*/
6464
gasUsed: bigint
6565
/**

packages/vm/src/evm/interpreter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ export default class Interpreter {
243243
address: this._eei._env.address,
244244
account: this._eei._env.contract,
245245
stateManager: this._runState.stateManager,
246-
memory: this._runState.memory._store, // Return underlying array for backwards-compatibility
246+
memory: this._runState.memory._store,
247247
memoryWordCount: this._runState.memoryWordCount,
248248
codeAddress: this._eei._env.codeAddress,
249249
}

0 commit comments

Comments
 (0)