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

JSON-RPC call to miner_start is returning an error message #383

Closed
javimaravillas opened this issue Sep 7, 2017 · 2 comments
Closed

JSON-RPC call to miner_start is returning an error message #383

javimaravillas opened this issue Sep 7, 2017 · 2 comments

Comments

@javimaravillas
Copy link

After a successfull miner_start

curl -X POST --data '{"jsonrpc":"2.0","method":"miner_start","params":[]}' localhost:8545

I tried to do a miner stop:

curl -X POST --data '{"jsonrpc":"2.0","method":"miner_stop","params":[]}' localhost:8545

Expected Behavior

In the callback , response result should be true:
{"jsonrpc":"2.0","result":true}

Current Behavior

An error is returned in the CURL:
{"jsonrpc":"2.0","error":{"message":"TypeError: callback is not a function\n at /Users/Javi/.nvm/versions/node/v8.1.2/lib/node_modules/ethereumjs-testrpc/build/cli.node.js:82710:5\n at /Users/Javi/.nvm/versions/node/v8.1.2/lib/node_modules/ethereumjs-testrpc/build/cli.node.js:83302:5\n at Object.async.whilst (/Users/Javi/.nvm/versions/node/v8.1.2/lib/node_modules/ethereumjs-testrpc/build/cli.node.js:13850:13)\n at StateManager.processBlocks (/Users/Javi/.nvm/versions/node/v8.1.2/lib/node_modules/ethereumjs-testrpc/build/cli.node.js:83259:9)\n at StateManager.startMining (/Users/Javi/.nvm/versions/node/v8.1.2/lib/node_modules/ethereumjs-testrpc/build/cli.node.js:83488:10)\n at GethApiDouble.miner_start (/Users/Javi/.nvm/versions/node/v8.1.2/lib/node_modules/ethereumjs-testrpc/build/cli.node.js:82709:14)\n at GethApiDouble.handleRequest (/Users/Javi/.nvm/versions/node/v8.1.2/lib/node_modules/ethereumjs-testrpc/build/cli.node.js:82434:10)\n at next (/Users/Javi/.nvm/versions/node/v8.1.2/lib/node_modules/ethereumjs-testrpc/build/cli.node.js:52153:18)\n at VmSubprovider.handleRequest (/Users/Javi/.nvm/versions/node/v8.1.2/lib/node_modules/ethereumjs-testrpc/build/cli.node.js:59291:12)\n at next (/Users/Javi/.nvm/versions/node/v8.1.2/lib/node_modules/ethereumjs-testrpc/build/cli.node.js:52153:18)","code":-32000}}Javiers-MacBook-Pro:virtue-poker-auction Javi$ curl -X POST --data '{"jsonrpc":"2.0","method":"miner_stop","params":[]}' localhost:8545

Possible Solution

Steps to Reproduce (for bugs)

  1. Run testrpc
  2. Execute the curl: curl -X POST --data '{"jsonrpc":"2.0","method":"miner_start","params":[]}' localhost:8545

Context

This is broken a promise during a test, as I expect result.true to resolve the promise.

Your Environment

  • Version used: EthereumJS TestRPC v4.1.1 (ganache-core: 1.1.2)
  • Operating System and version: Mac OSX Sierra 10.12.6
  • Link to your project: Not public
@ltfschoen
Copy link

ltfschoen commented Jan 1, 2018

I have the same problem using ganache-cli 6.0.3.

I setup Ganache CLI with:

rm -rf ./db;
mkdir -p db/chaindb;
ganache-cli --account '0x0000000000000000000000000000000000000000000000000000000000000001, 10002471238800000000000' \
  --account '0x0000000000000000000000000000000000000000000000000000000000000002, 10004471238800000000000' \
  --unlock '0x0000000000000000000000000000000000000000000000000000000000000001' \
  --unlock '0x0000000000000000000000000000000000000000000000000000000000000002' \
  --unlock '0x7e5f4552091a69125d5dfcb7b8c2659029395bdf' \
  --unlock '0x2b5ad5c4795c026514f8317c7a215e218dccd6cf' \
  --blocktime 0 \
  --deterministic true \
  --port 8545 \
  --hostname localhost \
  --gasPrice 20000000000 \
  --gasLimit 0x8000000 \
  --debug true \
  --mem true \
  --networkId 1337 \
  --db './db/chaindb'

Then I try to use RPC with cURL to start mining with:

curl -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"miner_start","params":[], "id": 1337}' localhost:8545

This gives error:

{"id":1337,"jsonrpc":"2.0","error":{"message":"TypeError: callback is not a function\n    at /Users/Ls/.nvm/versions/node/v9.3.0/lib/node_modules/ganache-cli/build/cli.node.js:90160:5\n    at /Users/Ls/.nvm/versions/node/v9.3.0/lib/node_modules/ganache-cli/build/cli.node.js:90765:5\n    at Object.async.whilst (/Users/Ls/.nvm/versions/node/v9.3.0/lib/node_modules/ganache-cli/build/cli.node.js:8284:13)\n    at StateManager.processBlocks (/Users/Ls/.nvm/versions/node/v9.3.0/lib/node_modules/ganache-cli/build/cli.node.js:90722:9)\n    at StateManager.startMining (/Users/Ls/.nvm/versions/node/v9.3.0/lib/node_modules/ganache-cli/build/cli.node.js:90981:10)\n    at GethApiDouble.miner_start (/Users/Ls/.nvm/versions/node/v9.3.0/lib/node_modules/ganache-cli/build/cli.node.js:90159:14)\n    at GethApiDouble.handleRequest (/Users/Ls/.nvm/versions/node/v9.3.0/lib/node_modules/ganache-cli/build/cli.node.js:89869:10)\n    at next (/Users/Ls/.nvm/versions/node/v9.3.0/lib/node_modules/ganache-cli/build/cli.node.js:59377:18)\n    at GethDefaults.handleRequest (/Users/Ls/.nvm/versions/node/v9.3.0/lib/node_modules/ganache-cli/build/cli.node.js:89766:12)\n    at next (/Users/Ls/.nvm/versions/node/v9.3.0/lib/node_modules/ganache-cli/build/cli.node.js:59377:18)","code":-32000}}

I then tried to attach to Ganache TestRPC with Geth:

geth attach rpc:http://localhost:8545

When I run eth.mining it returns true. Does Ganache CLI only support automatic mining?
When I download Ganache 1.0.1 and run the App, it runs on "network_id":5777, and localhost "port":7545 (instead of 8545), and it shows a MINING STATUS: AUTOMINING. If I try the same cURL request as I did previously but change the id parameter to 5777 and the port to 7545, it returns the same error

@benjamincburns
Copy link
Contributor

benjamincburns commented Jan 16, 2018

The error/crash is almost certainly due to trufflesuite/ganache#255. miner_start expects a threads parameter, which is a bit sad, because it's unused.

You can work around this issue by doing the following: curl -X POST --data '{"jsonrpc":"2.0","method":"miner_start","params":[0x0]}' localhost:8545

The fix will be to 1) fix trufflesuite/ganache#51, and 2) edit evm_mine in geth_api_double.js to treat the threads parameter as optional.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants