Skip to content

Commit fa06b1a

Browse files
authored
vm: improve runTx and evm debug logs (#1677)
1 parent 1a49ee1 commit fa06b1a

File tree

2 files changed

+18
-23
lines changed

2 files changed

+18
-23
lines changed

packages/vm/src/evm/evm.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,11 @@ export default class EVM {
161161

162162
let result
163163
if (this._vm.DEBUG) {
164+
const { caller, gasLimit, to, value, delegatecall } = message
164165
debug(
165-
`New message caller=${message.caller} gasLimit=${message.gasLimit} to=${
166-
message.to ? message.to.toString() : ''
167-
} value=${message.value} delegatecall=${message.delegatecall ? 'yes' : 'no'}`
166+
`New message caller=${caller} gasLimit=${gasLimit} to=${
167+
to?.toString() ?? 'none'
168+
} value=${value} delegatecall=${delegatecall ? 'yes' : 'no'}`
168169
)
169170
}
170171
if (message.to) {
@@ -179,14 +180,11 @@ export default class EVM {
179180
result = await this._executeCreate(message)
180181
}
181182
if (this._vm.DEBUG) {
183+
const { gasUsed, exceptionError, returnValue, gasRefund } = result.execResult
182184
debug(
183-
`Received message results gasUsed=${result.gasUsed} execResult: [ gasUsed=${
184-
result.gasUsed
185-
} exceptionError=${
186-
result.execResult.exceptionError ? result.execResult.exceptionError.toString() : ''
187-
} returnValue=${short(result.execResult.returnValue)} gasRefund=${
188-
result.execResult.gasRefund
189-
} ]`
185+
`Received message execResult: [ gasUsed=${gasUsed} exceptionError=${
186+
exceptionError ? `'${exceptionError.error}'` : 'none'
187+
} returnValue=0x${short(returnValue)} gasRefund=${gasRefund ?? 0} ]`
190188
)
191189
}
192190
const err = result.execResult.exceptionError
@@ -258,7 +256,7 @@ export default class EVM {
258256
if (errorMessage) {
259257
exit = true
260258
if (this._vm.DEBUG) {
261-
debug(`Exit early on value tranfer overflowed`)
259+
debug(`Exit early on value transfer overflowed`)
262260
}
263261
}
264262
if (exit) {
@@ -357,7 +355,7 @@ export default class EVM {
357355
if (errorMessage) {
358356
exit = true
359357
if (this._vm.DEBUG) {
360-
debug(`Exit early on value tranfer overflowed`)
358+
debug(`Exit early on value transfer overflowed`)
361359
}
362360
}
363361
if (exit) {

packages/vm/src/runTx.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export interface RunTxOpts {
5353

5454
/**
5555
* If true, skips the validation of the tx's gas limit
56-
* agains the block's gas limit.
56+
* against the block's gas limit.
5757
*/
5858
skipBlockGasLimitValidation?: boolean
5959

@@ -395,22 +395,19 @@ async function _runTx(this: VM, opts: RunTxOpts): Promise<RunTxResult> {
395395
`Running tx=0x${
396396
tx.isSigned() ? tx.hash().toString('hex') : 'unsigned'
397397
} with caller=${caller} gasLimit=${gasLimit} to=${
398-
to ? to.toString() : ''
398+
to?.toString() ?? 'none'
399399
} value=${value} data=0x${short(data)}`
400400
)
401401
}
402402

403403
const results = (await evm.executeMessage(message)) as RunTxResult
404404
if (this.DEBUG) {
405+
const { gasUsed, exceptionError, returnValue, gasRefund } = results.execResult
405406
debug('-'.repeat(100))
406407
debug(
407-
`Received tx results gasUsed=${results.gasUsed} execResult: [ gasUsed=${
408-
results.gasUsed
409-
} exceptionError=${
410-
results.execResult.exceptionError ? results.execResult.exceptionError.error : ''
411-
} returnValue=${short(results.execResult.returnValue)} gasRefund=${
412-
results.execResult.gasRefund
413-
} ]`
408+
`Received tx execResult: [ gasUsed=${gasUsed} exceptionError=${
409+
exceptionError ? `'${exceptionError.error}'` : 'none'
410+
} returnValue=0x${short(returnValue)} gasRefund=${gasRefund ?? 0} ]`
414411
)
415412
}
416413

@@ -423,7 +420,7 @@ async function _runTx(this: VM, opts: RunTxOpts): Promise<RunTxResult> {
423420
debug(`Generated tx bloom with logs=${results.execResult.logs?.length}`)
424421
}
425422

426-
// Caculate the total gas used
423+
// Calculate the total gas used
427424
results.gasUsed.iadd(txBaseFee)
428425
if (this.DEBUG) {
429426
debugGas(`tx add baseFee ${txBaseFee} to gasUsed (-> ${results.gasUsed})`)
@@ -461,7 +458,7 @@ async function _runTx(this: VM, opts: RunTxOpts): Promise<RunTxResult> {
461458
// Update miner's balance
462459
let miner
463460
if (this._common.consensusType() === ConsensusType.ProofOfAuthority) {
464-
// Backwards-compatibilty check
461+
// Backwards-compatibility check
465462
// TODO: can be removed along VM v6 release
466463
if ('cliqueSigner' in block.header) {
467464
miner = block.header.cliqueSigner()

0 commit comments

Comments
 (0)