eth/tracers: fix callTracer fault handling (#23667)

* eth/tracers: fix calltracer fault handling

* eth/tracers: fix calltracer indentation
This commit is contained in:
Sina Mahmoodi 2021-10-01 13:03:24 +02:00 committed by GitHub
parent a47b8cf6f5
commit b522f5e091
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 64 additions and 76 deletions

File diff suppressed because one or more lines are too long

View File

@ -18,77 +18,68 @@
// callFrameTracer uses the new call frame tracing methods to report useful information // callFrameTracer uses the new call frame tracing methods to report useful information
// about internal messages of a transaction. // about internal messages of a transaction.
{ {
callstack: [{}], callstack: [{}],
fault: function(log, db) { fault: function(log, db) {},
var len = this.callstack.length result: function(ctx, db) {
if (len > 1) { // Prepare outer message info
var call = this.callstack.pop() var result = {
if (this.callstack[len-1].calls === undefined) { type: ctx.type,
this.callstack[len-1].calls = [] from: toHex(ctx.from),
} to: toHex(ctx.to),
this.callstack[len-1].calls.push(call) value: '0x' + ctx.value.toString(16),
} gas: '0x' + bigInt(ctx.gas).toString(16),
}, gasUsed: '0x' + bigInt(ctx.gasUsed).toString(16),
result: function(ctx, db) { input: toHex(ctx.input),
// Prepare outer message info output: toHex(ctx.output),
var result = { }
type: ctx.type, if (this.callstack[0].calls !== undefined) {
from: toHex(ctx.from), result.calls = this.callstack[0].calls
to: toHex(ctx.to), }
value: '0x' + ctx.value.toString(16), if (this.callstack[0].error !== undefined) {
gas: '0x' + bigInt(ctx.gas).toString(16), result.error = this.callstack[0].error
gasUsed: '0x' + bigInt(ctx.gasUsed).toString(16), } else if (ctx.error !== undefined) {
input: toHex(ctx.input), result.error = ctx.error
output: toHex(ctx.output), }
} if (result.error !== undefined && (result.error !== "execution reverted" || result.output ==="0x")) {
if (this.callstack[0].calls !== undefined) { delete result.output
result.calls = this.callstack[0].calls }
}
if (this.callstack[0].error !== undefined) {
result.error = this.callstack[0].error
} else if (ctx.error !== undefined) {
result.error = ctx.error
}
if (result.error !== undefined && (result.error !== "execution reverted" || result.output ==="0x")) {
delete result.output
}
return this.finalize(result) return this.finalize(result)
}, },
enter: function(frame) { enter: function(frame) {
var call = { var call = {
type: frame.getType(), type: frame.getType(),
from: toHex(frame.getFrom()), from: toHex(frame.getFrom()),
to: toHex(frame.getTo()), to: toHex(frame.getTo()),
input: toHex(frame.getInput()), input: toHex(frame.getInput()),
gas: '0x' + bigInt(frame.getGas()).toString('16'), gas: '0x' + bigInt(frame.getGas()).toString('16'),
} }
if (frame.getValue() !== undefined){ if (frame.getValue() !== undefined){
call.value='0x' + bigInt(frame.getValue()).toString(16) call.value='0x' + bigInt(frame.getValue()).toString(16)
} }
this.callstack.push(call) this.callstack.push(call)
}, },
exit: function(frameResult) { exit: function(frameResult) {
var len = this.callstack.length var len = this.callstack.length
if (len > 1) { if (len > 1) {
var call = this.callstack.pop() var call = this.callstack.pop()
call.gasUsed = '0x' + bigInt(frameResult.getGasUsed()).toString('16') call.gasUsed = '0x' + bigInt(frameResult.getGasUsed()).toString('16')
var error = frameResult.getError() var error = frameResult.getError()
if (error === undefined) { if (error === undefined) {
call.output = toHex(frameResult.getOutput()) call.output = toHex(frameResult.getOutput())
} else { } else {
call.error = error call.error = error
if (call.type === 'CREATE' || call.type === 'CREATE2') { if (call.type === 'CREATE' || call.type === 'CREATE2') {
delete call.to delete call.to
} }
} }
len -= 1 len -= 1
if (this.callstack[len-1].calls === undefined) { if (this.callstack[len-1].calls === undefined) {
this.callstack[len-1].calls = [] this.callstack[len-1].calls = []
} }
this.callstack[len-1].calls.push(call) this.callstack[len-1].calls.push(call)
} }
}, },
// finalize recreates a call object using the final desired field oder for json // finalize recreates a call object using the final desired field oder for json
// serialization. This is a nicety feature to pass meaningfully ordered results // serialization. This is a nicety feature to pass meaningfully ordered results
// to users who don't interpret it, just display it. // to users who don't interpret it, just display it.

View File

@ -795,9 +795,6 @@ func (jst *Tracer) CaptureExit(output []byte, gasUsed uint64, err error) {
if !jst.traceCallFrames { if !jst.traceCallFrames {
return return
} }
if jst.err != nil {
return
}
// If tracing was interrupted, set the error and stop // If tracing was interrupted, set the error and stop
if atomic.LoadUint32(&jst.interrupt) > 0 { if atomic.LoadUint32(&jst.interrupt) > 0 {
jst.err = jst.reason jst.err = jst.reason