Truffle: Migration error on mining Geth client even though contract was successfully deployed (v5)

Created on 30 Aug 2018  路  21Comments  路  Source: trufflesuite/truffle

Issue

I've encountered another issue with Geth and Truffle v5 馃槩.

When running the default Truffle migration (1_run_migrations.js), the dry-run completes successfully, but the actual deployment of Migrations.sol throws an error. However, the contract is deployed to the network anyway.

This occurs when using Geth, but not Ganache.

Steps to Reproduce

  1. truffle init
  2. Add a network targeting Geth:
    geth: {
      provider: () =>
        new HDWallet("recipe flock effort test evil card identify grab shift venture movie tonight", "http://localhost:8545"),
      network_id: "*"
    }
  1. Run Geth locally:
geth \
    --port 38545 \
    --mine\
    --minerthreads=1 \
    --rpc \
    --rpcport 8545 \
    --rpccorsdomain "*" \
    --datadir .testnet/data/ \
    --port 30303 \
    --nodiscover \
    --rpcapi web3,eth,net,debug,personal \
    --networkid 99
  1. Attempt a migration: truffle migrate --reset --network geth

Expected Behavior

The migration to complete successfully, as it does with Ganache:

Starting migrations...
======================
> Network name:    'development'
> Network id:      5777
> Block gas limit: 10000000000


1_run_migrations.js
===================

   Replacing 'Migrations'
   ----------------------
   > transaction hash:    0x1b76f7e93d008b9901966b1a4d5fd299f2f185d28e61ad1de727d74c507df3ed
   > Blocks: 0            Seconds: 0
   > contract address:    0x4eFcED2f6dD322AE12EafEc96b2664a3011D16b5
   > account:             0x2e18Dba2a20913Be8901F7b054879eAbE8968009
   > balance:             99.94972496
   > gas used:            277462
   > gas price:           20 gwei
   > value sent:          0 ETH
   > total cost:          0.00554924 ETH


   > Saving migration to chain.
   > Saving artifacts
   -------------------------------------
   > Total cost:          0.00554924 ETH


Summary
=======
> Total deployments:   1
> Final cost:          0.00554924 ETH

Actual Results

The migration fails with an error:

Migrations dry-run (simulation)
===============================
> Network name:    'geth-fork'
> Network id:      99
> Block gas limit: 55821070


1_run_migrations.js
===================

   Deploying 'Migrations'
   ----------------------
   > account:             0x2e18Dba2a20913Be8901F7b054879eAbE8968009
   > balance:             100605063.179322811987365888
   > gas used:            262462
   > gas price:           20 gwei
   > value sent:          0 ETH
   > total cost:          0.00524924 ETH

   -------------------------------------
   > Total cost:          0.00524924 ETH


Summary
=======
> Total deployments:   1
> Final cost:          0.00524924 ETH


Starting migrations...
======================
> Network name:    'geth'
> Network id:      99
> Block gas limit: 55821070


1_run_migrations.js
===================

   Deploying 'Migrations'
   ----------------------
   > transaction hash:    0x8d77046ce0cd92a6a53e57c8faca7700cd3d54acd73b3444982d0b4e74e3379d
Error:  *** Deployment Failed ***

"Migrations" hit a require or revert statement somewhere in its constructor. Try:
   * Verifying that your constructor params satisfy all require conditions.
   * Adding reason strings to your require statements.

    at /home/cadel/.nvm/versions/node/v9.11.1/lib/node_modules/truffle/build/webpack:/packages/truffle-deployer/src/deployment.js:361:1
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:182:7)

Since the default Migrations.sol doesn't contain any require or revert statements, this seems like a bug.

Checking the Geth logs shows:

INFO [08-30|09:05:48.955] Submitted contract creation              fullhash=0x8d77046ce0cd92a6a53e57c8faca7700cd3d54acd73b3444982d0b4e74e3379d contract=0x0dD0C6BB23E4b528dA98c08D52813f1D25f14750
INFO [08-30|09:05:56.606] Successfully sealed new block            number=899 hash=462b4b鈥8aaec
INFO [08-30|09:05:56.607] 馃敆 block reached canonical chain          number=894 hash=54654f鈥b6ec3
INFO [08-30|09:05:56.607] 馃敤 mined potential block                  number=899 hash=462b4b鈥8aaec
INFO [08-30|09:05:56.608] Commit new mining work                   number=900 txs=1 uncles=0 elapsed=461碌s

So it seems that the contract is being successfully deployed after all, but Truffle thinks it fails and exits before saving the deployed address.

I've confirmed the issue is not with the HD wallet provider, as the same network configuration works perfectly with Ganache.

Environment

  • Operating System: Ubuntu (Windows Subsystem for Linux)
  • Ethereum client: Geth (Geth/v1.8.13-stable-225171a4/linux-amd64/go1.10)
  • Truffle versio: Truffle v5.0.0-beta.0 (core: 5.0.0-beta.0)
  • Solidity version: Solidity v0.4.24 (solc-js)
  • node version: v9.11.1
  • npm version: 5.6.0

I've uploaded the full script I'm using to initialise and start Geth here: https://gist.github.com/kdelwat/fd4ba9b78013805b03a5ca395b6b9e71

Migrations bug needs reproduced priority3 馃敡

All 21 comments

@kdelwat This is a bit difficult to reproduce because it takes a while to get a node running the way you've configured it . Could you fetch the transaction receipt for the deployment that errors and post it to this thread? You should be able to do that by launching `truffle console --network and running:

> web3.eth.getTransactionReceipt(<transactionHash>)

Also could you verify that the Migrations is saving to the build file by looking the network section of the .json and checking to see if there is a listing for the network the geth node is running on?

Also could you post your truffle.js, sorry.

@cgewecke No problem, I know how annoying this is to track down.

The transaction receipt:

{ blockHash: '0x3907972798f8634f2b8652c0ad95454e4903eeef604cad6f2f7bfb7b38d7690b',
  blockNumber: 900,
  contractAddress: '0x0dD0C6BB23E4b528dA98c08D52813f1D25f14750',
  cumulativeGasUsed: 277462,
  from: '0x2e18dba2a20913be8901f7b054879eabe8968009',
  gasUsed: 277462,
  logs: [],
  logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
  root: '0x990e4f18b0658ce65a49109b51888baf38e6534fcc91f8d514b0fec4ab7a433a',
  to: null,
  transactionHash: '0x8d77046ce0cd92a6a53e57c8faca7700cd3d54acd73b3444982d0b4e74e3379d',
  transactionIndex: 0 }

There is no listing for the Geth node in networks so it isn't getting to the save stage.

My Truffle config: https://gist.github.com/kdelwat/26d9049adbe6e165e8ba774e7034d231

@kdelwat Ah that's just bizarre. The receipt looks good. I don't understand why this configuration is producing a different response than geth dev (or Infura for that matter). I'll have to spin up a node with your config overnight and take a look.

Thanks for finding this!

@kdelwat Unfortunately I ran out of disk space trying to run the node locally. . . Don't know if you're interested but we could set up a chat session where I ask you to insert random debugging lines in Truffle and we try to figure out how the error is getting thrown. You could also look into this on your own if you feel like it.

The place I'd start is here - inspecting the error and then work back into truffle-contract.

Unfortunately installed truffle is a little unwieldy because its a single giant webpacked file called cli.bundled.js in the build folder. [Edit - misnamed the bundle]

Editing the issue slightly to identify the error context.

@cgewecke I'm happy to try to do some debugging myself, and failing that will collaborate with you. Is there a way to link the development repo for Truffle to debug against that instead of the installed file?

@kdelwat Ok sounds good. The equivalent of truffle at the repo is in packages/truffle/build/cli.bundled.js. To generate a build of the current state of your edits you:

cd packages/truffle
npm run build
chmod +x build/cli.bundled.js

With the truffle repo in an outer folder you would alias within your 'real' project using something like:

../truffle/packages/truffle/build/cli.bundled.js

The only thing that's annoying about this is that you have to remember to run the build command and make it executable after each change, otherwise it doesn't get included in the new bundle.

@cgewecke I've worked it out (finally).

The issue is the eth_getTransactionReceipt RPC call.

We can see this when manually sending the same deployment transaction that Truffle sends:

const params = {
  from: '0x2e18Dba2a20913Be8901F7b054879eAbE8968009',
  gas: 6721975,
  gasPrice: 20000000000,
  data: '0x608060405234801561001057600080fd5b50336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506102f8806100606000396000f300608060405260043610610062576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680630900f01014610067578063445df0ac146100aa5780638da5cb5b146100d5578063fdacd5761461012c575b600080fd5b34801561007357600080fd5b506100a8600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610159565b005b3480156100b657600080fd5b506100bf610241565b6040518082815260200191505060405180910390f35b3480156100e157600080fd5b506100ea610247565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561013857600080fd5b506101576004803603810190808035906020019092919050505061026c565b005b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16141561023d578190508073ffffffffffffffffffffffffffffffffffffffff1663fdacd5766001546040518263ffffffff167c010000000000000000000000000000000000000000000000000000000002815260040180828152602001915050600060405180830381600087803b15801561022457600080fd5b505af1158015610238573d6000803e3d6000fd5b505050505b5050565b60015481565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614156102c957806001819055505b505600a165627a7a72305820449918ffa92571543a8a2ada5265bc64364cc43ae24c5492c7cab53281a5fa910029' }

web3.eth.sendTransaction(params)

When connected to Ganache, this returns:

{
  transactionHash: '0xbc79966729c22cb03d6e3cf0ac9a1c8dcada6a3bf66ba90b6e7464001f4f7129',
  transactionIndex: 0,
  blockHash: '0x4d4b6af853cfadf3ab798fdd4b8a39d203b712b56def8848c23f47f011470514',
  blockNumber: 11,
  gasUsed: 277462,
  cumulativeGasUsed: 277462,
  contractAddress: '0x74F9CC18F443ea793a19735B69Cf6F0c5091111E',
  logs: [],
  status: true,
  logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'
}

But connected to Geth it returns:

{
  blockHash: '0x54d9b8270140dfb94ae9029766756b86257cb5c39160517c88e20a5dabadfda7',
  blockNumber: 2140,
  contractAddress: '0x87966Fea4132099cbCB751eE3B5D191C2Ee5A806',
  cumulativeGasUsed: 277462,
  from: '0x2e18dba2a20913be8901f7b054879eabe8968009',
  gasUsed: 277462,
  logs: [],
  logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
  root: '0x0bd1ed8adaddbaf8129c360447b759c4c152a98af7c05e7d984bb497a5d561f8',
  to: null,
  transactionHash: '0x66341e0f1e1368a8e812ef2b0a9adb49ccb8215b211a31b44ea991c62d7a1cd2',
  transactionIndex: 0
}

The breaking difference is the lack of status field from Geth, which breaks the check in truffle-contract here.

According to the JSON RPC spec:

[the receipt] also returns either :

root : DATA 32 bytes of post-transaction stateroot (pre Byzantium)
status: QUANTITY either 1 (success) or 0 (failure)

Since the Geth receipt returns root, it is also correct, but Truffle thinks it has failed.

This seems like an easy fix, by changing the execute check from if (!receipt.status) to if(receipt.status !== undefined && !receipt.status).

Happy to put in a PR if that's helpful / the change makes sense, or feel free to make the change yourself :) Thanks for the help

@kdelwat Fantastic! Thank you - such great work. If you don't open the PR by tomorrow I'll put it in but I really feel you deserve credit for this.

Everything for V5 targets the next branch (in case you end up doing it.)

There's one other place in truffle-contract we check the status....

https://github.com/trufflesuite/truffle/blob/next/packages/truffle-contract/lib/handlers.js#L105

Thank you for raising this issue! It has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. If you would like to keep this issue open, please respond with information about the current state of this problem.

There has been no new activity on this issue since it was marked as stale 7 days ago, so it is being automatically closed. If you'd like help with this or a different problem, please open a new issue. Thanks!

I am getting the same error now.

@princesinha19 What truffle version?

I try to deploy to my local parity node and I get the following error:

Saving migration to chain.Error: Error: StatusError: Transaction: 0x5880cd00f7f616bca41e335f6606de2ff82b0dfdf56d02717e19103734cd0ce3 exited with an error (status 0).
Please check that the transaction:
- satisfies all conditions set by Solidity require statements.
- does not trigger a Solidity revert statement.

at Object.run (/home/andre/.nvm/versions/node/v12.3.1/lib/node_modules/truffle/build/webpack:/packages/truffle-migrate/index.js:92:1)
at processTicksAndRejections (internal/process/task_queues.js:89:5)

Truffle v5.0.20 (core: 5.0.20)
Node v12.3.1

Hey @aawaken, can you share a repo for bug reproduction?

@CruzMolina have no public repo for now.. This is a very simple project with standard migrations script.

By the way, I've tested just now - the deployment works well until Truffle 5.0.5, from 5.0.6 on the error comes.

$truffle version
Truffle v5.0.6 (core: 5.0.6)
Solidity v0.5.0 (solc-js)
Node v12.3.1

Ah, can you try the latest version of truffle?

wasn't that 5.0.20, which I started with? The problem occurs likely everywhere between 5.0.6 and 5.20.0. I tested 5.0.6, 5.0.7, 5.10.0 and 5.20.0. So, may be the delta between 5.0.5 and 5.0.6 gives you the idea what went broken.

Ah, missed this bit:

from 5.0.6 on the error comes.

Thanks for reporting this, can you open a new issue specific to parity?

@princesinha19 are you still experiencing this error and if so is it while using geth?

2075

@princesinha19 are you still experiencing this error and if so is it while using geth?

@CruzMolina sorry for late response.
Yes, I am experiencing the same issue and I am using Geth.

Was this page helpful?
0 / 5 - 0 ratings