Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subdivide runState, refactor loop #498

Merged
merged 11 commits into from
Apr 25, 2019
56 changes: 23 additions & 33 deletions lib/evm/loop.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,29 @@ module.exports = class Loop {
}
}

return this.parseVmResults(err, opts.message.gasLimit)
let gasUsed = opts.message.gasLimit.sub(this._runState.gasLeft)
if (err) {
if (err.error !== ERROR.REVERT) {
gasUsed = opts.message.gasLimit
}

// remove any logs on error
this._result = Object.assign({}, this._result, {
logs: [],
vmError: true,
gasRefund: null,
selfdestruct: null
})
}

return Object.assign({}, this._result, {
runState: Object.assign({}, this._runState, this._result, this._runState.eei._env),
exception: err ? 0 : 1,
exceptionError: err,
gas: this._runState.gasLeft,
gasUsed,
'return': this._result.returnValue ? this._result.returnValue : Buffer.alloc(0)
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inlined parseVmResults, ok.

}

canContinueExecution () {
Expand Down Expand Up @@ -141,38 +163,6 @@ module.exports = class Loop {
return opFns[opInfo.name]
}

async parseVmResults (err, gasLimit) {
// remove any logs on error
if (err) {
this._result.logs = []
this._result.vmError = true
}

const results = {
runState: Object.assign({}, this._runState, this._result, this._runState.eei._env),
selfdestruct: this._result.selfdestruct,
gasRefund: this._result.gasRefund,
exception: err ? 0 : 1,
exceptionError: err,
logs: this._result.logs,
gas: this._runState.gasLeft,
'return': this._result.returnValue ? this._result.returnValue : Buffer.alloc(0)
}

if (results.exceptionError) {
delete results.gasRefund
delete results.selfdestruct
}

if (err && err.error !== ERROR.REVERT) {
results.gasUsed = gasLimit
} else {
results.gasUsed = gasLimit.sub(this._runState.gasLeft)
}

return results
}

async runStepHook () {
const eventObj = {
pc: this._runState.programCounter,
Expand Down
2 changes: 1 addition & 1 deletion lib/evm/opFns.js
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ module.exports = {

function describeLocation (runState) {
var hash = utils.keccak256(runState.eei.getCode()).toString('hex')
var address = runState.address.toString('hex')
var address = runState.eei.getAddress().toString('hex')
var pc = runState.programCounter - 1
return hash + '/' + address + ':' + pc
}
Expand Down