Skip to content
This repository has been archived by the owner on Jan 21, 2022. It is now read-only.

evm_mine method fails to return a result field #354

Closed
xavierlepretre opened this issue Jul 23, 2017 · 10 comments
Closed

evm_mine method fails to return a result field #354

xavierlepretre opened this issue Jul 23, 2017 · 10 comments

Comments

@xavierlepretre
Copy link

A valid JSON RPC response must contain the result: field. When you call evm_mine, the result field is missing.

Expected Behavior

The evm_mine call should return a result field, even if empty.

Current Behavior

As of now, no result field is sent back.

Possible Solution

Steps to Reproduce (for bugs)

If you want to see how this becomes a problem, try to declare:

web3._extend({
    property: 'evm',
    methods: [
        new web3._extend.Method({
            name: 'mine',
            call: 'evm_mine',
            params: 0
        })
    ]
});

Then, when you call web3.evm.mine(myCallback), you get the error:

Error: Invalid JSON RPC response: {"id":58,"jsonrpc":"2.0"}
      at Object.InvalidResponse (/usr/lib/node_modules/truffle/node_modules/web3/lib/web3/errors.js:35:16)
      at /usr/lib/node_modules/truffle/node_modules/web3/lib/web3/requestmanager.js:86:36
      at XMLHttpRequest.request.onreadystatechange (/usr/lib/node_modules/truffle/node_modules/web3/lib/web3/httpprovider.js:118:13)
      at XMLHttpRequestEventTarget.dispatchEvent (/usr/lib/node_modules/truffle/node_modules/xhr2/lib/xhr2.js:64:18)
      at XMLHttpRequest._setReadyState (/usr/lib/node_modules/truffle/node_modules/xhr2/lib/xhr2.js:354:12)
      at XMLHttpRequest._onHttpResponseEnd (/usr/lib/node_modules/truffle/node_modules/xhr2/lib/xhr2.js:509:12)
      at IncomingMessage.<anonymous> (/usr/lib/node_modules/truffle/node_modules/xhr2/lib/xhr2.js:469:24)
      at endReadableNT (_stream_readable.js:975:12)
      at _combinedTickCallback (internal/process/next_tick.js:80:11)
      at process._tickCallback (internal/process/next_tick.js:104:9)

Context

I am declaring methods for the evm_ calls.

Your Environment

  • Version used:
  • Environment name and version (e.g. PHP 5.4 on nginx 1.9.1):
  • Server type and version:
  • Operating System and version:
  • Link to your project:
@yarrumretep
Copy link

@benjamincburns - we are hitting this as well (also worked around in the project i submitted for #293). we can work around it if necessary but shouldn't it return a list of the transactions it mines?

@xavierlepretre
Copy link
Author

I don't see why. This command is to order the miner to start. The response should be "ok started".

@yarrumretep
Copy link

@xavierlepretre - I believe the command is to mine a single block upon command. miner_stop & miner_start stop and re-start mining. evn_mine should mine a block and return receipts for the transactions it mines, methinks. Am I off base?

@benjamincburns
Copy link
Contributor

This is a pretty quick one to fix - great first time contribution for anyone who wants to submit a PR.

@xavierlepretre
Copy link
Author

@yarrumretep evm_mine orders the miner to start. You then have to wait for a block to be mined. Depending on the start-up settings of Ganache this can be a few seconds. Only when you have received a block would you consider stopping the mining. You understand that you cannot wait for a block to be mined to return from this evm_mine command.

@benjamincburns
Copy link
Contributor

evm_mine should mine a block and return receipts for the transactions it mines, methinks. Am I off base?

Sorry, I should've clarified earlier that I think this is out of scope for evm_mine - per @xavierlepretre's comment, evm_mine is meant to trigger mining of a new block. We don't want to add nonstandard functionality for getting transaction receipts and the like, as our goal is to be a testing tool which accurately simulates full blown Ethereum clients.

@yarrumretep
Copy link

OK - I think I'm clear on what you are saying @xavierlepretre - evm_mine only requests the miner to mine one block according to whatever settings it has (instamine, or periodic). Its up to the client to independently listen for that block to mine. Makes sense.

In this case it should just return empty result so web3 extend call doesn't fail.

I was thrown off by this discussion: trufflesuite/ganache#108 in which it seemed to me that evm_mine was synchronous by design (i.e. mined a block and returned the results).

@yarrumretep
Copy link

In looking at the code on ganache-core@develop, it appears that evm_mine indeed mines one block immediately (regardless of if the auto-mining setting is periodic). It then returns errors (including runtime errors) from the transactions mined.

I'll submit a PR that changes evm_mine to return true with the errors (if any). This is parallel to the miner_start function. Sound right?

yarrumretep referenced this issue in yarrumretep/ganache-core Jan 22, 2018
@benjamincburns
Copy link
Contributor

it appears that evm_mine indeed mines one block immediately (regardless of if the auto-mining setting is periodic)

Yes, that's the expected/intended behaviour.

I'll submit a PR that changes evm_mine to return true with the errors (if any).

I believe most rpc calls which have no real return value just set the result field of the JSONRPC response to '0x0' on success. That said, the exact value doesn't matter, so long as it's a hex number encoded as a string. On error the JSONRPC spec doesn't include the result field, so success is determined by the existence of result more so than the specific value.

yarrumretep referenced this issue in yarrumretep/ganache-core Jan 23, 2018
@benjamincburns
Copy link
Contributor

Fixed in current develop, meaning it'll go out with the next release. Thanks once again for your contribution, @yarrumretep!

benjamincburns referenced this issue in trufflesuite/ganache Jan 23, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants