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

Fixing return payload for reverts #31

Merged
merged 6 commits into from
Mar 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/core-db/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@eth-optimism/core-db",
"version": "0.0.1-alpha.15",
"version": "0.0.1-alpha.16",
"description": "Optimism DB Utils",
"main": "build/index.js",
"files": [
Expand Down Expand Up @@ -29,7 +29,7 @@
"url": "https://github.com/ethereum-optimism/optimism-monorepo.git"
},
"dependencies": {
"@eth-optimism/core-utils": "^0.0.1-alpha.15",
"@eth-optimism/core-utils": "^0.0.1-alpha.16",
"abstract-leveldown": "^6.2.2",
"async-lock": "^1.2.2",
"chai": "^4.2.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/core-utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@eth-optimism/core-utils",
"version": "0.0.1-alpha.15",
"version": "0.0.1-alpha.16",
"description": "Optimism Core Utils",
"main": "build/index.js",
"files": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ export const JSONRPC_ERRORS = {
code: -32603,
message: 'Internal error',
},
REVERT_ERROR: {
code: -32015,
message: 'revert: requested action reverted',
},
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/docs/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@eth-optimism/docs",
"private": true,
"version": "0.0.1-alpha.15",
"version": "0.0.1-alpha.16",
"description": "Optimism docs",
"author": "Optimism",
"license": "MIT",
Expand Down
6 changes: 3 additions & 3 deletions packages/optimistic-game-semantics/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@eth-optimism/optimistic-game-semantics",
"version": "0.0.1-alpha.15",
"version": "0.0.1-alpha.16",
"description": "Optimism Optimistic Game Semantics",
"main": "build/index.js",
"files": [
Expand Down Expand Up @@ -29,8 +29,8 @@
"url": "https://github.com/ethereum-optimism/optimism-monorepo.git"
},
"dependencies": {
"@eth-optimism/core-db": "^0.0.1-alpha.15",
"@eth-optimism/core-utils": "^0.0.1-alpha.15",
"@eth-optimism/core-db": "^0.0.1-alpha.16",
"@eth-optimism/core-utils": "^0.0.1-alpha.16",
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"debug": "^4.1.1",
Expand Down
4 changes: 2 additions & 2 deletions packages/ovm-truffle-provider-wrapper/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@eth-optimism/ovm-truffle-provider-wrapper",
"version": "0.0.1-alpha.15",
"version": "0.0.1-alpha.16",
"description": "Optimism Truffle Provider Wrapper",
"main": "build/index.js",
"files": [
Expand Down Expand Up @@ -28,7 +28,7 @@
"url": "https://github.com/ethereum-optimism/optimism-monorepo.git"
},
"dependencies": {
"@eth-optimism/rollup-full-node": "^0.0.1-alpha.15"
"@eth-optimism/rollup-full-node": "^0.0.1-alpha.16"
},
"devDependencies": {
"@types/node": "^12.0.7",
Expand Down
8 changes: 4 additions & 4 deletions packages/ovm/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@eth-optimism/ovm",
"version": "0.0.1-alpha.15",
"version": "0.0.1-alpha.16",
"description": "An optimistic execution-compatible EVM",
"main": "build/index.js",
"files": [
Expand Down Expand Up @@ -50,9 +50,9 @@
"typescript": "^3.3.3333"
},
"dependencies": {
"@eth-optimism/core-db": "^0.0.1-alpha.15",
"@eth-optimism/core-utils": "^0.0.1-alpha.15",
"@eth-optimism/rollup-core": "^0.0.1-alpha.15",
"@eth-optimism/core-db": "^0.0.1-alpha.16",
"@eth-optimism/core-utils": "^0.0.1-alpha.16",
"@eth-optimism/rollup-core": "^0.0.1-alpha.16",
"@types/sinon-chai": "^3.2.2",
"chai": "^4.2.0",
"ethereum-waffle": "2.1.0",
Expand Down
1 change: 0 additions & 1 deletion packages/ovm/src/app/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ export const getOvmTransactionMetadata = (
/**
* Converts an EVM receipt to an OVM receipt.
*
* @param executionManager The EM contract to use to parse th logs.
* @param internalTxReceipt The EVM tx receipt to convert to an OVM tx receipt
* @returns The converted receipt
*/
Expand Down
8 changes: 4 additions & 4 deletions packages/rollup-contracts/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@eth-optimism/rollup-contracts",
"version": "0.0.1-alpha.15",
"version": "0.0.1-alpha.16",
"description": "Optimistic Rollup smart contracts",
"main": "build/index.js",
"files": [
Expand Down Expand Up @@ -43,9 +43,9 @@
"typescript": "^3.3.3333"
},
"dependencies": {
"@eth-optimism/core-db": "^0.0.1-alpha.15",
"@eth-optimism/core-utils": "^0.0.1-alpha.15",
"@eth-optimism/rollup-core": "^0.0.1-alpha.15",
"@eth-optimism/core-db": "^0.0.1-alpha.16",
"@eth-optimism/core-utils": "^0.0.1-alpha.16",
"@eth-optimism/rollup-core": "^0.0.1-alpha.16",
"@types/sinon-chai": "^3.2.2",
"chai": "^4.2.0",
"ethereum-waffle": "2.1.0",
Expand Down
6 changes: 3 additions & 3 deletions packages/rollup-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@eth-optimism/rollup-core",
"version": "0.0.1-alpha.15",
"version": "0.0.1-alpha.16",
"description": "[Optimism] Optimistic Rollup Core Library",
"main": "build/index.js",
"files": [
Expand Down Expand Up @@ -29,8 +29,8 @@
"url": "https://github.com/ethereum-optimism/optimism-monorepo.git"
},
"dependencies": {
"@eth-optimism/core-db": "^0.0.1-alpha.15",
"@eth-optimism/core-utils": "^0.0.1-alpha.15",
"@eth-optimism/core-db": "^0.0.1-alpha.16",
"@eth-optimism/core-utils": "^0.0.1-alpha.16",
"async-lock": "^1.2.2",
"ethers": "^4.0.39"
},
Expand Down
6 changes: 3 additions & 3 deletions packages/rollup-dev-tools/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@eth-optimism/rollup-dev-tools",
"version": "0.0.1-alpha.15",
"version": "0.0.1-alpha.16",
"description": "[Optimism] Optimistic Rollup Dev Tools Library",
"main": "build/index.js",
"files": [
Expand Down Expand Up @@ -33,8 +33,8 @@
"url": "https://github.com/ethereum-optimism/optimism-monorepo.git"
},
"dependencies": {
"@eth-optimism/core-utils": "^0.0.1-alpha.15",
"@eth-optimism/rollup-core": "^0.0.1-alpha.15",
"@eth-optimism/core-utils": "^0.0.1-alpha.16",
"@eth-optimism/rollup-core": "^0.0.1-alpha.16",
"async-lock": "^1.2.2",
"bn.js": "^5.1.1",
"dotenv": "^8.2.0",
Expand Down
12 changes: 6 additions & 6 deletions packages/rollup-full-node/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@eth-optimism/rollup-full-node",
"version": "0.0.1-alpha.15",
"version": "0.0.1-alpha.16",
"description": "[Optimism] Optimistic Rollup Full Node Library",
"main": "build/index.js",
"files": [
Expand Down Expand Up @@ -34,10 +34,10 @@
"url": "https://github.com/ethereum-optimism/optimism-monorepo.git"
},
"dependencies": {
"@eth-optimism/core-db": "^0.0.1-alpha.15",
"@eth-optimism/core-utils": "^0.0.1-alpha.15",
"@eth-optimism/ovm": "^0.0.1-alpha.15",
"@eth-optimism/rollup-core": "^0.0.1-alpha.15",
"@eth-optimism/core-db": "^0.0.1-alpha.16",
"@eth-optimism/core-utils": "^0.0.1-alpha.16",
"@eth-optimism/ovm": "^0.0.1-alpha.16",
"@eth-optimism/rollup-core": "^0.0.1-alpha.16",
"async-lock": "^1.2.2",
"axios": "^0.19.0",
"cors": "^2.8.5",
Expand All @@ -47,7 +47,7 @@
"fastpriorityqueue": "^0.6.3"
},
"devDependencies": {
"@eth-optimism/solc-transpiler": "^0.0.1-alpha.15",
"@eth-optimism/solc-transpiler": "^0.0.1-alpha.16",
"@types/abstract-leveldown": "^5.0.1",
"@types/chai": "^4.1.7",
"@types/mocha": "^5.2.7",
Expand Down
5 changes: 5 additions & 0 deletions packages/rollup-full-node/src/app/fullnode-rpc-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
import {
FullnodeHandler,
InvalidParametersError,
RevertError,
UnsupportedMethodError,
} from '../types'

Expand Down Expand Up @@ -65,6 +66,10 @@ export class FullnodeRpcServer extends ExpressHttpServer {
result,
})
} catch (err) {
if (err instanceof RevertError) {
log.debug(`Request reverted. Request: ${JSON.stringify(request)}`)
return res.json(buildJsonRpcError('REVERT_ERROR', request.id))
}
if (err instanceof UnsupportedMethodError) {
log.debug(
`Received request with unsupported method: [${JSON.stringify(
Expand Down
2 changes: 2 additions & 0 deletions packages/rollup-full-node/src/app/test-web3-rpc-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ export class TestWeb3Handler extends DefaultWeb3Handler {
case Web3RpcMethods.getTimestamp:
this.assertParameters(params, 0)
return add0x(this.getTimestamp().toString(16))
case Web3RpcMethods.mine:
return this.provider.send(Web3RpcMethods.mine, params)
case Web3RpcMethods.snapshot:
this.assertParameters(params, 0)
return this.snapshot()
Expand Down
19 changes: 17 additions & 2 deletions packages/rollup-full-node/src/app/web3-rpc-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
} from '@eth-optimism/ovm'

import { Contract, ethers, utils, Wallet } from 'ethers'
import { Web3Provider } from 'ethers/providers'
import { TransactionReceipt, Web3Provider } from 'ethers/providers'
import { createMockProvider, deployContract, getWallets } from 'ethereum-waffle'

import AsyncLock from 'async-lock'
Expand All @@ -26,6 +26,7 @@ import { DEFAULT_ETHNODE_GAS_LIMIT } from '.'
import {
FullnodeHandler,
InvalidParametersError,
RevertError,
UnsupportedMethodError,
Web3Handler,
Web3RpcMethods,
Expand Down Expand Up @@ -272,7 +273,10 @@ export class DefaultWeb3Handler implements Web3Handler, FullnodeHandler {
defaultBlock: string
): Promise<string> {
if (defaultBlock !== 'latest') {
throw new Error('No support for historical code lookups!')
log.info(
`No support for historical code lookups! Anything returned from this may be very wrong.`
)
//throw new Error('No support for historical code lookups!')
}
log.debug(
`Getting code for address: [${address}], defaultBlock: [${defaultBlock}]`
Expand Down Expand Up @@ -396,6 +400,17 @@ export class DefaultWeb3Handler implements Web3Handler, FullnodeHandler {
throw Error(msg)
}

const receipt: TransactionReceipt = await this.getTransactionReceipt(
ovmTxHash
)
log.info(
`Transaction receipt for ${rawOvmTx}: ${JSON.stringify(receipt)}`
)
if (!receipt || !receipt.status) {
log.debug(`Transaction reverted: ${rawOvmTx}, ovmTxHash: ${ovmTxHash}`)
throw new RevertError()
}

log.debug(`Completed send raw tx [${rawOvmTx}]. Response: [${ovmTxHash}]`)
// Return the *OVM* tx hash. We can do this because we store a mapping to the ovmTxHashs in the EM contract.
return ovmTxHash
Expand Down
1 change: 1 addition & 0 deletions packages/rollup-full-node/src/exec/fullnode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const runFullnode = async (
const host = '0.0.0.0'
const port = 8545

log.info(`Starting fullnode in ${testFullnode ? 'TEST' : 'LIVE'} mode`)
const fullnodeHandler = testFullnode
? await TestWeb3Handler.create()
: await DefaultWeb3Handler.create()
Expand Down
6 changes: 6 additions & 0 deletions packages/rollup-full-node/src/types/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,9 @@ export class InvalidParametersError extends Error {
)
}
}

export class RevertError extends Error {
constructor(message?: string) {
super(message || 'Revert: The provided transaction reverted.')
}
}
5 changes: 3 additions & 2 deletions packages/rollup-full-node/src/types/web3-rpc-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ export enum Web3RpcMethods {
getTransactionReceipt = 'eth_getTransactionReceipt',
networkVersion = 'net_version',
sendRawTransaction = 'eth_sendRawTransaction',
snapshot = 'evm_snapshot',
revert = 'evm_revert',

// Test methods:
snapshot = 'evm_snapshot',
revert = 'evm_revert',
mine = 'evm_mine',
increaseTimestamp = 'evm_increaseTime',
getTimestamp = 'evm_getTime',
}
38 changes: 36 additions & 2 deletions packages/rollup-full-node/test/app/fullnode-rpc-server.spec.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
/* External Imports */
import { AxiosHttpClient, getLogger } from '@eth-optimism/core-utils/build/src'
import {
AxiosHttpClient,
getLogger,
JSONRPC_ERRORS,
} from '@eth-optimism/core-utils/build/src'
import { AxiosResponse } from 'axios'

/* Internal Imports */
import { FullnodeRpcServer } from '../../src/app'
import { FullnodeHandler, UnsupportedMethodError } from '../../src/types'
import {
FullnodeHandler,
RevertError,
UnsupportedMethodError,
} from '../../src/types'
import { should } from '../setup'

const log = getLogger('fullnode-rpc-server', true)

const dummyResponse: string = 'Dummy Response =D'

const unsupportedMethod: string = 'unsupported!'
const revertMethod: string = 'revert!'
class DummyFullnodeHandler implements FullnodeHandler {
public async handleRequest(
method: string,
Expand All @@ -20,6 +29,9 @@ class DummyFullnodeHandler implements FullnodeHandler {
if (method === unsupportedMethod) {
throw new UnsupportedMethodError()
}
if (method === revertMethod) {
throw new RevertError()
}
return dummyResponse
}
}
Expand Down Expand Up @@ -114,4 +126,26 @@ describe('FullnodeHandler RPC Server', () => {
r.data['jsonrpc'].should.equal('2.0')
})
})

it('reverts properly', async () => {
const result: AxiosResponse = await request(client, {
id: 1,
jsonrpc: '2.0',
method: revertMethod,
})

result.status.should.equal(200)

result.data.should.haveOwnProperty('id')
result.data.should.haveOwnProperty('jsonrpc')
result.data.should.haveOwnProperty('error')
result.data['error'].should.haveOwnProperty('message')
result.data['error'].should.haveOwnProperty('code')
result.data['error']['message'].should.equal(
JSONRPC_ERRORS.REVERT_ERROR.message
)
result.data['error']['code'].should.equal(JSONRPC_ERRORS.REVERT_ERROR.code)

result.data['jsonrpc'].should.equal('2.0')
})
})
4 changes: 2 additions & 2 deletions packages/rollup-full-node/test/app/test-handler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ import {
FullnodeRpcServer,
DefaultWeb3Handler,
} from '../../src'
import * as SimpleStorage from '../contracts/build/SimpleStorage.json'
import * as SimpleStorage from '../contracts/build/untranspiled/SimpleStorage.json'

const log = getLogger('test-web3-handler', true)

const secondsSinceEopch = (): number => {
return Math.round(Date.now() / 1000)
}
const host = '0.0.0.0'
const port = 9999
const port = 9998
const baseUrl = `http://${host}:${port}`

describe('TestHandler', () => {
Expand Down
Loading