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

testrpc falls over - "Cannot read property 'gasPrice' of undefined"? #293

Closed
ghost opened this issue Apr 17, 2017 · 19 comments
Closed

testrpc falls over - "Cannot read property 'gasPrice' of undefined"? #293

ghost opened this issue Apr 17, 2017 · 19 comments

Comments

@ghost
Copy link

ghost commented Apr 17, 2017

I'm getting the following failure of testrpc:

...
eth_getLogs
eth_getLogs
/Users/ehynes/.nvm/versions/node/v6.10.2/lib/node_modules/ethereumjs-testrpc/node_modules/solc/soljson.js:1
(function (exports, require, module, __filename, __dirname) { var Module;if(!Module)Module=(typeof Module!=="undefined"?Module:null)||{};var moduleOverrides={};for(var key in Module){if(Module.hasOwnProperty(key)){moduleOverrides[key]=Module[key]}}var ENVIRONMENT_IS_WEB=typeof window==="object";var ENVIRONMENT_IS_WORKER=typeof importScripts==="function";var ENVIRONMENT_IS_NODE=typeof process==="object"&&typeof require==="function"&&!ENVIRONMENT_IS_WEB&&!ENVIRONMENT_IS_WORKER;var ENVIRONMENT_IS_SHELL=!ENVIRONMENT_IS_WEB&&!ENVIRONMENT_IS_NODE&&!ENVIRONMENT_IS_WORKER;if(ENVIRONMENT_IS_NODE){if(!Module["print"])Module["print"]=function print(x){process["stdout"].write(x+"\n")};if(!Module["printErr"])Module["printErr"]=function printErr(x){process["stderr"].write(x+"\n")};var nodeFS=require("fs");var nodePath=require("path");Module["read"]=function read(filename,binary){filename=nodePath["normalize"](filen

TypeError: Cannot read property 'gasPrice' of undefined
    at priceSort (/Users/ehynes/.nvm/versions/node/v6.10.2/lib/node_modules/ethereumjs-testrpc/lib/blockchain_double.js:251:61)
    at _siftdown (/Users/ehynes/.nvm/versions/node/v6.10.2/lib/node_modules/ethereumjs-testrpc/node_modules/heap/lib/heap.js:240:11)
    at heappush (/Users/ehynes/.nvm/versions/node/v6.10.2/lib/node_modules/ethereumjs-testrpc/node_modules/heap/lib/heap.js:67:12)
    at Heap.push (/Users/ehynes/.nvm/versions/node/v6.10.2/lib/node_modules/ethereumjs-testrpc/node_modules/heap/lib/heap.js:295:14)
    at BlockchainDouble.sortByPriceAndNonce (/Users/ehynes/.nvm/versions/node/v6.10.2/lib/node_modules/ethereumjs-testrpc/lib/blockchain_double.js:277:12)
    at BlockchainDouble.processNextBlock (/Users/ehynes/.nvm/versions/node/v6.10.2/lib/node_modules/ethereumjs-testrpc/lib/blockchain_double.js:291:8)
    at /Users/ehynes/.nvm/versions/node/v6.10.2/lib/node_modules/ethereumjs-testrpc/lib/statemanager.js:427:21
    at Object.async.whilst (/Users/ehynes/.nvm/versions/node/v6.10.2/lib/node_modules/ethereumjs-testrpc/node_modules/async/lib/async.js:792:13)
    at StateManager.processBlocks (/Users/ehynes/.nvm/versions/node/v6.10.2/lib/node_modules/ethereumjs-testrpc/lib/statemanager.js:416:9)
    at Timeout._onTimeout (/Users/ehynes/.nvm/versions/node/v6.10.2/lib/node_modules/ethereumjs-testrpc/lib/statemanager.js:131:10)

I'm running testrpc -b 3

truffle is driving a test script. I'm totally stuck by the failure/error and can't see a way forward...

Your Environment

node v6.10.2
OSX 10.12.4
testrpc v3.0.3

@ammini-ctrl
Copy link

I have exactly the same issue. However I am able to find a workaround to the problem. In my case I have two transactions to be mined in one block, and the execution of second transaction depends directly on the first one. (The first one is an initialization and the second transaction requires the contract to be initialized.)

The workaround (took me a few hours although simple) is to put a delay equal to mining interval between the two transactions so that they will be mined in separate block. After doing so the error is gone. I am not sure if it is correct though, but since mine is just a local setup script for testing, I did not pursue further.

@benjamincburns
Copy link
Contributor

@hynese thanks for reporting this!

@ntulsy & @hynese - is there an immediate reason that either of you need to be using interval mining? If not, I highly recommend dropping the -b flag.

It seems like for some reason we've queued an invalid (undefined) transaction. I'll look into this and see what might've caused it.

@yarrumretep
Copy link

Same result here when using miner_stop to stop auto mining and then either calling evm_mine or miner_start after queueing a couple of contract function invoking transactions. I was not able to recreate with just ether moving transactions.

NOTE: the same behavior was observed with truffle develop using inline ganache.

This is using:

Truffle v4.0.4 (core: 4.0.4)
Solidity v0.4.18 (solc-js)

PLATFORM: darwin
GANACHE VERSION: 1.0.2

EXCEPTION:

Blockchain process exited prematurely with code '7', due to signal 'null'.

APPLICATION LOG:

T+336026ms:   Block Number: 75
T+336026ms:   Block Time: Mon Jan 15 2018 21:13:14 GMT-0500 (EST)
T+336030ms: eth_getTransactionReceipt
T+336230ms: evm_snapshot
T+504903ms: net_version
T+504911ms: eth_accounts
T+504943ms: eth_accounts
T+504997ms: eth_accounts
T+505006ms: net_version
T+505011ms: net_version
T+505019ms: eth_sendTransaction
T+505057ms:   Transaction: 0xdbfcf3d62a90db133357033090a366c28b49b3a093b9bede9ea8827e8283a206
T+505057ms:   Contract created: 0x82d50ad3c1091866e258fd0f1a7cc9674609d254
T+505057ms:   Gas usage: 269607
T+505057ms:   Block Number: 76
T+505057ms:   Block Time: Mon Jan 15 2018 21:16:03 GMT-0500 (EST)
T+505062ms: eth_newBlockFilter
T+505067ms: eth_getFilterChanges
T+505075ms: eth_getTransactionReceipt
T+505081ms: eth_getCode
T+505096ms: eth_uninstallFilter
T+505100ms: eth_sendTransaction
T+505134ms:   Transaction: 0x289ae161be6b6cdcea57476a531d45daf5e590a20fecca05e88e1bf699ba2558
T+505139ms:   Gas usage: 41981
T+505139ms:   Block Number: 77
T+505139ms:   Block Time: Mon Jan 15 2018 21:16:03 GMT-0500 (EST)
T+505145ms: eth_getTransactionReceipt
T+505248ms: evm_snapshot
T+505350ms: eth_blockNumber
T+505355ms: net_version
T+505360ms: net_version
T+505366ms: eth_sendTransaction
T+505369ms: eth_sendTransaction
T+505408ms:   Transaction: 0x63d5d514fce3a6287426f434e0f938a4183f1f59333054c06fc9753574f5fb24
T+505408ms:   Contract created: 0x1e5fa5deec9aef3bba765d00b41f41ba618e519a
T+505408ms:   Gas usage: 1462020
T+505408ms:   Block Number: 78
T+505408ms:   Block Time: Mon Jan 15 2018 21:16:03 GMT-0500 (EST)
T+505414ms: eth_newBlockFilter
T+505461ms:   Transaction: 0xb25dee545887ec986b090b6ad68f715d761736ef60ddb064547ee305e2202678
T+505461ms:   Contract created: 0x6f2eac0b32f36ac895acad0da1d378ae146f02bb
T+505461ms:   Gas usage: 1462020
T+505461ms:   Block Number: 79
T+505461ms:   Block Time: Mon Jan 15 2018 21:16:03 GMT-0500 (EST)
T+505466ms: eth_newBlockFilter
T+505470ms: eth_getFilterChanges
T+505474ms: eth_getTransactionReceipt
T+505481ms: eth_getCode
T+505486ms: eth_uninstallFilter
T+505972ms: eth_getFilterChanges
T+505985ms: eth_getTransactionReceipt
T+505993ms: eth_getCode
T+505999ms: eth_uninstallFilter
T+506006ms: net_version
T+506012ms: eth_sendTransaction
T+506097ms:   Transaction: 0x794d5fce69e53de32aea065ccbe617bdeb48f3c2d0f847d073254010ed5e6935
T+506097ms:   Contract created: 0xeec918d74c746167564401103096d45bbd494b74
T+506097ms:   Gas usage: 2943885
T+506097ms:   Block Number: 80
T+506097ms:   Block Time: Mon Jan 15 2018 21:16:04 GMT-0500 (EST)
T+506101ms: eth_newBlockFilter
T+506107ms: eth_getFilterChanges
T+506112ms: eth_getTransactionReceipt
T+506119ms: eth_getCode
T+506126ms: eth_uninstallFilter
T+506130ms: miner_stop
T+506133ms: net_version
T+506136ms: eth_sendTransaction
T+506141ms: net_version
T+506145ms: eth_sendTransaction
T+506150ms: net_version
T+506154ms: eth_sendTransaction
T+508164ms: evm_mine
T+508217ms: miner_start
T+508224ms: eth_getLogs
T+555002ms: net_version
T+555011ms: eth_accounts
T+555041ms: eth_accounts
T+555084ms: eth_accounts
T+555094ms: net_version
T+555100ms: net_version
T+555108ms: eth_sendTransaction
T+555113ms: /node_modules/ganache-cli/build/lib.node.js:63898
T+555113ms: var Module;if(!Module)Module=(typeof Module!=="undefined"?Module:null)||{};var moduleOverrides={};for(var key in Module){if(Module.hasOwnProperty(key)){moduleOverrides[key]=Module[key]}}var ENVIRONMENT_IS_WEB=false;var ENVIRONMENT_IS_WORKER=false;var ENVIRONMENT_IS_NODE=false;var ENVIRONMENT_IS_SHELL=false;if(Module["ENVIRONMENT"]){if(Module["ENVIRONMENT"]==="WEB"){ENVIRONMENT_IS_WEB=true}else if(Module["ENVIRONMENT"]==="WORKER"){ENVIRONMENT_IS_WORKER=true}else if(Module["ENVIRONMENT"]==="NODE"){ENVIRONMENT_IS_NODE=true}else if(Module["ENVIRONMENT"]==="SHELL"){ENVIRONMENT_IS_SHELL=true}else{throw new Error("The provided Module['ENVIRONMENT'] value is not valid. It must be one of: WEB|WORKER|NODE|SHELL.")}}else{ENVIRONMENT_IS_WEB=typeof window==="object";ENVIRONMENT_IS_WORKER=typeof importScripts==="function";ENVIRONMENT_IS_NODE=typeof process==="object"&&"function"==="function"&&!ENVIRONMENT_IS_WEB&&!ENVIRONMEN
T+555113ms: 
T+555113ms: TypeError: Cannot read property 'gasPrice' of undefined
T+555113ms:     at priceSort (/node_modules/ganache-cli/build/lib.node.js:21947:61)
T+555113ms:     at _siftdown (/node_modules/ganache-cli/build/lib.node.js:74832:11)
T+555113ms:     at heappush (/node_modules/ganache-cli/build/lib.node.js:74659:12)
T+555113ms:     at Heap.push (/node_modules/ganache-cli/build/lib.node.js:74887:14)
T+555113ms:     at BlockchainDouble.sortByPriceAndNonce (/node_modules/ganache-cli/build/lib.node.js:21973:12)
T+555113ms:     at BlockchainDouble.processNextBlock (/node_modules/ganache-cli/build/lib.node.js:22163:8)
T+555113ms:     at /node_modules/ganache-cli/build/lib.node.js:80489:21
T+555113ms:     at Object.async.whilst (/node_modules/ganache-cli/build/lib.node.js:8279:13)
T+555113ms:     at StateManager.processBlocks (/node_modules/ganache-cli/build/lib.node.js:80478:9)
T+555113ms:     at StateManager.processTransaction (/node_modules/ganache-cli/build/lib.node.js:80568:8)

@benjamincburns
Copy link
Contributor

benjamincburns commented Jan 16, 2018

@yarrumretep if you're keen, can you please try running this on ganache-cli@beta? That release fixes a number of widespread issues, one of which may be responsible for this problem.

Also would be interesting to know whether this is a problem on [email protected]

@yarrumretep
Copy link

@benjamincburns same result. Let me see if i can make a mini-project that shows this.

@yarrumretep
Copy link

@benjamincburns here you go: https://github.com/yarrumretep/ganache293

Also, I noticed that if you comment out the third 'transfer' transaction, the mining will go through (no gasPrice issue). HOWEVER, it seems the evm_mine invocation will only mine 1 transaction per block (hence the 3 mine() calls). Do you want a separate ticket for the 1 transaction per evm_mine call?

Also, evm_mine does not give a proper JSONRPC response (at least in the @beta) - see the mine() function which swallows the error. I think I saw this issue in another ticket...

@benjamincburns
Copy link
Contributor

Do you want a separate ticket for the 1 transaction per evm_mine call?

Not unless it's causing you trouble. This is expected behavior.

I'll have a look at the project, thanks a lot for that - will make sorting this out much easier!

@yarrumretep
Copy link

@benjamincburns - hrm - yeah, the idea was that we would queue up some transactions and then call evm_mine to cause them to be mined in the same block. We are looking to exercise conditions in our contracts which could be an issue if multiple transactions executed in the same block. Would it make sense to see about getting the evm_mine call to do as many xas as will fit? Or is there some other strategy for doing this sort of testing?

@benjamincburns
Copy link
Contributor

when using miner_stop to stop auto mining and then either calling evm_mine or miner_start after queueing a couple of contract function invoking transactions

@yarrumretep just to help me understand how people are using ganache, can you please explain why you're doing this? Most people don't tend to want or need to control the creation of blocks within Ganache in this way

@benjamincburns
Copy link
Contributor

benjamincburns commented Jan 16, 2018

Looks like you might've already answered my question! Can you elaborate a bit on those "conditions in [your] contracts which could be an issue if multiple transactions executed in the same block?" I'd love to understand further.

Edit: Also if you have need for testing multiple transactions in one block, please raise an issue for that, as it sounds like our current way of doing things is problematic for you.

@yarrumretep
Copy link

Hi @benjamincburns - yeah, any time you condition based on block.number (as you might, for instance, if you are using minime style Checkpoint structures), you could run into problems with 'concurrent' (same block) transaction mining. We want to be able to synthesise these sorts of diabolical conditions to build robust test suites.

@benjamincburns
Copy link
Contributor

Sounds like a problem to avoid altogether if possible! Either way, see the edit to my last comment - sounds like you should raise that issue, and I'll look into why we're crashing here!

@yarrumretep
Copy link

yarrumretep commented Jan 16, 2018

See this comment: trufflesuite/ganache#108 (comment)

Seems to imply that evm_mine should pick up as many transactions as will fit in a block - which is analogous to what a real-world miner might do, right?

@benjamincburns
Copy link
Contributor

I still need to test that evm_mine works correctly with the new flow, especially when handling error cases.

Sounds like he either never got around to that, or we (I?) broke it after the fact. I'll double check the code, but I think even when calling evm_mine manually you still only get one tx per block. This would be a relatively easy change to make though - just need to enforce a max block size. Good PR fodder!

@benjamincburns
Copy link
Contributor

benjamincburns commented Jan 16, 2018

https://github.com/trufflesuite/ganache-core/blob/develop/test/mining.js#L169-L204
^ looks like we never validate that the transactions occur in the same block number... whoops!

Edit: I just added the check and the test passes - it seems that we do mine multiple transactions into one block. However I don't think this occurs if you call evm_mine, rather, you have to omit that step and call mining_start.

Edit2: also I misread that test to begin with - he checked that the current block number only advanced by 1 after those transactions. Also I replaced startMining with mineSingleBlock and that test still passes.

@benjamincburns
Copy link
Contributor

If you're only getting one TX per block, I suspect you're running into this scenario. Try increasing your block gas limit: https://github.com/trufflesuite/ganache-core/blob/develop/test/mining.js#L249-L286

@benjamincburns
Copy link
Contributor

@hynese thanks for reporting this one, and @yarrumretep thanks for that sample project, it was really illustrative, and I learned a lot from our conversation!

@yarrumretep I've confirmed that with this change your test should work, and that you should only need to call evm_mine once per batch of transactions, provided they fit within the block gas limit.

The fix in 8e080b4 will go out with our next release!

@yarrumretep
Copy link

this is great @benjamincburns - thank you for the quick fix. When do you think the next release will be released? In the meantime, is there a straightforward way for us to use the development version of ganache-core with ganache-cli?

@benjamincburns
Copy link
Contributor

benjamincburns commented Jan 22, 2018

is there a straightforward way for us to use the development version of ganache-core with ganache-cli

Yes, have a look at the npm link command.

In short, you'll want to clone both ganache-core and ganache-cli then run the following ( assuming both are cloned to a common parent directory):

cd $PARENT_DIRECTORY/ganache-core
npm install
npm link
cd ../ganache-cli
npm install
npm link ganache-core
npm run build
npm start

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