Skip to content

Commit ae45d2b

Browse files
ryanioholgerd77
andcommitted
vm, client: continuing v6 breaking changes (#1815)
* vm: v6 breaking changes * update benchmark util to use gasUsed as bigint * VM: fixed gasUsed rebase related bug Co-authored-by: Holger Drewes <Holger.Drewes@gmail.com>
1 parent 44f6bfe commit ae45d2b

29 files changed

+137
-244
lines changed

packages/client/lib/execution/receipt.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { PreByzantiumTxReceipt, PostByzantiumTxReceipt, TxReceipt } from '@ether
22
import { Log } from '@ethereumjs/vm/dist/evm/types'
33
import Bloom from '@ethereumjs/vm/dist/bloom'
44
import { TypedTransaction } from '@ethereumjs/tx'
5-
import { rlp, intToBuffer, bufferToInt } from 'ethereumjs-util'
5+
import { rlp, intToBuffer, bufferToInt, bigIntToBuffer, bufferToBigInt } from 'ethereumjs-util'
66
import { MetaDBManager, DBKey } from '../util/metaDBManager'
77
import type { Block } from '@ethereumjs/block'
88

@@ -302,7 +302,7 @@ export class ReceiptsManager extends MetaDBManager {
302302
value.map((r) => [
303303
(r as PreByzantiumTxReceipt).stateRoot ??
304304
intToBuffer((r as PostByzantiumTxReceipt).status),
305-
r.gasUsed,
305+
bigIntToBuffer(r.gasUsed),
306306
this.rlp(RlpConvert.Encode, RlpType.Logs, r.logs),
307307
])
308308
)
@@ -315,14 +315,14 @@ export class ReceiptsManager extends MetaDBManager {
315315
// Pre-Byzantium Receipt
316316
return {
317317
stateRoot: r[0],
318-
gasUsed,
318+
gasUsed: bufferToBigInt(gasUsed),
319319
logs,
320320
} as PreByzantiumTxReceipt
321321
} else {
322322
// Post-Byzantium Receipt
323323
return {
324324
status: bufferToInt(r[0]),
325-
gasUsed,
325+
gasUsed: bufferToBigInt(gasUsed),
326326
logs,
327327
} as PostByzantiumTxReceipt
328328
}

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ export class EthProtocol extends Protocol {
234234
let encodedReceipt = rlp.encode([
235235
(receipt as PreByzantiumTxReceipt).stateRoot ??
236236
(receipt as PostByzantiumTxReceipt).status,
237-
receipt.gasUsed,
237+
bigIntToBuffer(receipt.gasUsed),
238238
receipt.bitvector,
239239
receipt.logs,
240240
])
@@ -253,7 +253,11 @@ export class EthProtocol extends Protocol {
253253
// Legacy receipt if r[0] >= 0xc0, otherwise typed receipt with first byte as TransactionType
254254
const decoded = rlp.decode(r[0] >= 0xc0 ? r : r.slice(1)) as any
255255
const [stateRootOrStatus, cumulativeGasUsed, logsBloom, logs] = decoded
256-
const receipt = { gasUsed: cumulativeGasUsed, bitvector: logsBloom, logs } as TxReceipt
256+
const receipt = {
257+
gasUsed: bufferToBigInt(cumulativeGasUsed),
258+
bitvector: logsBloom,
259+
logs,
260+
} as TxReceipt
257261
if (stateRootOrStatus.length === 32) {
258262
;(receipt as PreByzantiumTxReceipt).stateRoot = stateRootOrStatus
259263
} else {

packages/client/lib/rpc/modules/eth.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ const jsonRpcReceipt = async (
263263
blockNumber: bigIntToHex(block.header.number),
264264
from: tx.getSenderAddress().toString(),
265265
to: tx.to?.toString() ?? null,
266-
cumulativeGasUsed: bufferToHex(receipt.gasUsed),
266+
cumulativeGasUsed: bigIntToHex(receipt.gasUsed),
267267
effectiveGasPrice: bigIntToHex(effectiveGasPrice),
268268
gasUsed: bigIntToHex(gasUsed),
269269
contractAddress: contractAddress?.toString() ?? null,

packages/client/lib/service/fullethereumservice.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Hardfork } from '@ethereumjs/common'
22
import { Skeleton } from '../sync/skeleton'
3+
import { bigIntToBuffer } from 'ethereumjs-util'
34
import { EthereumService, EthereumServiceOptions } from './ethereumservice'
45
import { TxPool } from './txpool'
56
import { BeaconSynchronizer, FullSynchronizer } from '../sync'
@@ -259,6 +260,7 @@ export class FullEthereumService extends EthereumService {
259260
let receiptsSize = 0
260261
for (const hash of hashes) {
261262
const blockReceipts = await receiptsManager.getReceipts(hash, true, true)
263+
blockReceipts.forEach((r) => (r.gasUsed = bigIntToBuffer(r.gasUsed) as any))
262264
if (!blockReceipts) continue
263265
receipts.push(...blockReceipts)
264266
receiptsSize += Buffer.byteLength(JSON.stringify(blockReceipts))

packages/client/lib/util/debug.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const main = async () => {
4343
const stateManager = new DefaultStateManager({ trie, common })
4444
// Ensure we run on the right root
4545
stateManager.setStateRoot(Buffer.from('${(
46-
await execution.vm.stateManager.getStateRoot(true)
46+
await execution.vm.stateManager.getStateRoot()
4747
).toString('hex')}', 'hex'))
4848
4949

packages/client/test/net/protocol/ethprotocol.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { FeeMarketEIP1559Transaction } from '@ethereumjs/tx'
55
import { Chain } from '../../../lib/blockchain/chain'
66
import { Config } from '../../../lib/config'
77
import { EthProtocol } from '../../../lib/net/protocol'
8-
import { bigIntToBuffer, bufferToBigInt, intToBuffer } from 'ethereumjs-util'
8+
import { bigIntToBuffer, bufferToBigInt } from 'ethereumjs-util'
99

1010
tape('[EthProtocol]', (t) => {
1111
t.test('should get properties', (t) => {
@@ -150,14 +150,14 @@ tape('[EthProtocol]', (t) => {
150150
const receipts = [
151151
{
152152
status: 1 as 0 | 1,
153-
gasUsed: intToBuffer(100),
153+
gasUsed: BigInt(100),
154154
bitvector: Buffer.alloc(256),
155155
logs: [[Buffer.alloc(20), [Buffer.alloc(32), Buffer.alloc(32, 1)], Buffer.alloc(10)]],
156156
txType: 2,
157157
},
158158
{
159159
status: 0 as 0 | 1,
160-
gasUsed: intToBuffer(1000),
160+
gasUsed: BigInt(1000),
161161
bitvector: Buffer.alloc(256, 1),
162162
logs: [[Buffer.alloc(20, 1), [Buffer.alloc(32, 1), Buffer.alloc(32, 1)], Buffer.alloc(10)]],
163163
txType: 0,

packages/client/test/service/fullethereumservice.spec.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import tape from 'tape'
22
import td from 'testdouble'
33
import Common from '@ethereumjs/common'
44
import { Log } from '@ethereumjs/vm/dist/evm/types'
5-
import { intToBuffer } from 'ethereumjs-util'
65
import { Config } from '../../lib/config'
76
import { Event } from '../../lib/types'
87
import { Chain } from '../../lib/blockchain'
@@ -161,7 +160,7 @@ tape('[FullEthereumService]', async (t) => {
161160
const receipts = [
162161
{
163162
status: 1 as 0 | 1,
164-
gasUsed: intToBuffer(100),
163+
gasUsed: BigInt(100),
165164
bitvector: Buffer.alloc(256),
166165
logs: [
167166
[Buffer.alloc(20), [Buffer.alloc(32), Buffer.alloc(32, 1)], Buffer.alloc(10)],
@@ -170,7 +169,7 @@ tape('[FullEthereumService]', async (t) => {
170169
},
171170
{
172171
status: 0 as 0 | 1,
173-
gasUsed: intToBuffer(1000),
172+
gasUsed: BigInt(1000),
174173
bitvector: Buffer.alloc(256, 1),
175174
logs: [
176175
[Buffer.alloc(20, 1), [Buffer.alloc(32, 1), Buffer.alloc(32, 1)], Buffer.alloc(10)],

packages/vm/benchmarks/util.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@ export const verifyResult = (block: Block, result: RunBlockResult) => {
6868
// check if there are receipts
6969
const { receipts } = result
7070
if (receipts) {
71-
let cumGasUsed = 0
71+
let cumGasUsed = BigInt(0)
7272
for (let index = 0; index < receipts.length; index++) {
73-
let gasUsedExpected = parseInt(receipts[index].gasUsed.toString('hex'), 16)
74-
let cumGasUsedActual = parseInt(receipts[index].gasUsed.toString('hex'), 16)
73+
let gasUsedExpected = receipts[index].gasUsed
74+
let cumGasUsedActual = receipts[index].gasUsed
7575
let gasUsed = cumGasUsedActual - cumGasUsed
7676
if (gasUsed !== gasUsedExpected) {
7777
console.log(`[DEBUG]

packages/vm/src/buildBlock.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ export class BlockBuilder {
226226
await this.rewardMiner()
227227
}
228228

229-
const stateRoot = await this.vm.stateManager.getStateRoot(true)
229+
const stateRoot = await this.vm.stateManager.getStateRoot()
230230
const transactionsTrie = await this.transactionsTrie()
231231
const receiptTrie = await this.receiptTrie()
232232
const logsBloom = this.logsBloom()

packages/vm/src/evm/eei.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -293,13 +293,7 @@ export default class EEI {
293293
getBlockCoinbase(): bigint {
294294
let coinbase: Address
295295
if (this._common.consensusAlgorithm() === ConsensusAlgorithm.Clique) {
296-
// Backwards-compatibilty check
297-
// TODO: can be removed along VM v5 release
298-
if ('cliqueSigner' in this._env.block.header) {
299-
coinbase = this._env.block.header.cliqueSigner()
300-
} else {
301-
coinbase = Address.zero()
302-
}
296+
coinbase = this._env.block.header.cliqueSigner()
303297
} else {
304298
coinbase = this._env.block.header.coinbase
305299
}
@@ -581,7 +575,7 @@ export default class EEI {
581575
}
582576

583577
// this should always be safe
584-
this.useGas(results.gasUsed, 'CALL, STATICCALL, DELEGATECALL, CALLCODE')
578+
this.useGas(results.execResult.gasUsed, 'CALL, STATICCALL, DELEGATECALL, CALLCODE')
585579

586580
// Set return value
587581
if (
@@ -654,7 +648,7 @@ export default class EEI {
654648
}
655649

656650
// this should always be safe
657-
this.useGas(results.gasUsed, 'CREATE')
651+
this.useGas(results.execResult.gasUsed, 'CREATE')
658652

659653
// Set return buffer in case revert happened
660654
if (

0 commit comments

Comments
 (0)