trufflesuite / truffle

:warning: The Truffle Suite is being sunset. For information on ongoing support, migration options and FAQs, visit the Consensys blog. Thank you for all the support over the years.
https://consensys.io/blog/consensys-announces-the-sunset-of-truffle-and-ganache-and-new-hardhat?utm_source=github&utm_medium=referral&utm_campaign=2023_Sep_truffle-sunset-2023_announcement_
MIT License
14.02k stars 2.31k forks source link

When deploying on main net I get "Exceeds block gas limit" #271

Closed xavierlepretre closed 5 years ago

xavierlepretre commented 7 years ago

Issue

I ran truffle migrate --network main, with my Geth running the main net. At every step, I would get:

Error encountered, bailing. Network state unknown. Review successful transactions manually.
Error: Exceeds block gas limit

Steps to Reproduce

Do truffle migrate targeting the main net.

Expected Behaviour

I would have thought that a reasonable amount of gas would be given to the transactions.

Actual Results

On my Geth console, I noticed the following:

> eth.getBlock("pending").gasLimit
4709181
// Wait for a block
> eth.getBlock("pending").gasLimit
4704588

Environment

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 14.04.5 LTS
Release:        14.04
Codename:       trusty
$ truffle version
Truffle v2.0.7
$ ~/go-ethereum/build/bin/geth version
Geth
Version: 1.4.12-stable-421df866
Protocol Versions: [63 62]
Network Id: 1
Go Version: go1.6
OS: linux
GOPATH=
GOROOT=/usr/lib/go
$ nodejs --version
v4.5.0
$ npm version
{ npm: '2.15.9',
  ares: '1.10.1-DEV',
  http_parser: '2.7.0',
  icu: '56.1',
  modules: '46',
  node: '4.5.0',
  openssl: '1.0.2h',
  uv: '1.9.1',
  v8: '4.5.103.37',
  zlib: '1.2.8' }
chevdor commented 7 years ago

In your truffle.js, can you reduce rpc.gas a tiny bit and see if that helps?

xavierlepretre commented 7 years ago

Like so?

  rpc: {
    host: "localhost",
    port: 8545
  },
  networks: {
    "main": {
      network_id: 1,
      gas: 500000
    }
  }
chevdor commented 7 years ago

Your value (500000) seems rather low. The default value is 4712388. Try with the default or lower it to 4612388. Not sure why but it then worked on my end...

zmitton commented 7 years ago

+1

makoto commented 7 years ago

I get the same message even when I set gas limit to 1 ether

salekali commented 7 years ago

I'm getting the same error. Unable to migrate contracts.

kingcocomango commented 7 years ago

I am also having this issue. Unable to deploy contracts

foo@Moko:~/Git/bar$ truffle deploy
Using network 'development'.

Running migration: 1_initial_migration.js
  Deploying Migrations...
Error encountered, bailing. Network state unknown. Review successful transactions manually.
Error: Error: Exceeds block gas limit
    at StateManager.queueTransaction (/home/foo/.nvm/versions/node/v7.9.0/lib/node_modules/ethereumjs-testrpc/lib/statemanager.js:291:21)
    at GethApiDouble.eth_sendTransaction (/home/foo/.nvm/versions/node/v7.9.0/lib/node_modules/ethereumjs-testrpc/lib/subproviders/geth_api_double.js:232:14)
    at GethApiDouble.handleRequest (/home/foo/.nvm/versions/node/v7.9.0/lib/node_modules/ethereumjs-testrpc/lib/subproviders/geth_api_double.js:61:10)
    at next (/home/foo/.nvm/versions/node/v7.9.0/lib/node_modules/ethereumjs-testrpc/node_modules/web3-provider-engine/index.js:95:18)
    at SolcSubprovider.handleRequest (/home/foo/.nvm/versions/node/v7.9.0/lib/node_modules/ethereumjs-testrpc/node_modules/web3-provider-engine/subproviders/solc.js:28:7)
    at next (/home/foo/.nvm/versions/node/v7.9.0/lib/node_modules/ethereumjs-testrpc/node_modules/web3-provider-engine/index.js:95:18)
    at VmSubprovider.handleRequest (/home/foo/.nvm/versions/node/v7.9.0/lib/node_modules/ethereumjs-testrpc/node_modules/web3-provider-engine/subproviders/vm.js:40:12)
    at next (/home/foo/.nvm/versions/node/v7.9.0/lib/node_modules/ethereumjs-testrpc/node_modules/web3-provider-engine/index.js:95:18)
    at GethDefaults.handleRequest (/home/foo/.nvm/versions/node/v7.9.0/lib/node_modules/ethereumjs-testrpc/lib/subproviders/gethdefaults.js:17:12)
    at next (/home/foo/.nvm/versions/node/v7.9.0/lib/node_modules/ethereumjs-testrpc/node_modules/web3-provider-engine/index.js:95:18)
    at Object.InvalidResponse (/home/foo/.nvm/versions/node/v7.9.0/lib/node_modules/truffle/node_modules/web3/lib/web3/errors.js:35:16)
    at /home/foo/.nvm/versions/node/v7.9.0/lib/node_modules/truffle/node_modules/web3/lib/web3/requestmanager.js:86:36
    at XMLHttpRequest.request.onreadystatechange (/home/foo/.nvm/versions/node/v7.9.0/lib/node_modules/truffle/node_modules/web3/lib/web3/httpprovider.js:118:13)
    at XMLHttpRequestEventTarget.dispatchEvent (/home/foo/.nvm/versions/node/v7.9.0/lib/node_modules/truffle/node_modules/xhr2/lib/xhr2.js:64:18)
    at XMLHttpRequest._setReadyState (/home/foo/.nvm/versions/node/v7.9.0/lib/node_modules/truffle/node_modules/xhr2/lib/xhr2.js:354:12)
    at XMLHttpRequest._onHttpResponseEnd (/home/foo/.nvm/versions/node/v7.9.0/lib/node_modules/truffle/node_modules/xhr2/lib/xhr2.js:509:12)
    at IncomingMessage.<anonymous> (/home/foo/.nvm/versions/node/v7.9.0/lib/node_modules/truffle/node_modules/xhr2/lib/xhr2.js:469:24)
    at emitNone (events.js:91:20)
    at IncomingMessage.emit (events.js:188:7)
    at endReadableNT (_stream_readable.js:975:12)

Resolved by the solution found @ stackoverflow from user Matthew Schmidt

Possibility two: you're giving the transaction too high of a gasLimit. If the transaction has a limit of 2,000,000, it'd stop you since it could theoretically go over the block gas limit, even if in practice it won't. If this is the case, see if you can reduce the transaction's gasLimit while remaining above the amount it actually needs--that might do the trick.

lorepieri8 commented 7 years ago

For me modifying the gas in truffle.js worked.

smatthewenglish commented 7 years ago

yeeaaa @chevdor! modifying the gas in truffle.js worked for me as well :)

felixwatts commented 6 years ago

If I set the gas in truffle.js to 4500000 I get out of gas. If I set it to 4750000 i get exceeds block gas limit. I could continue the trial and error binary search of the gas space, but I suspect there may be no gas number that satisfies both constraints. What do I do?

xavierlepretre commented 6 years ago

As you describe it, your problem is with your contract constructor.

flockonus commented 6 years ago

Also had this gas deployment issue with truffle 3.4.11. Changing the gas limit didn't help me (already had mine at 4M), but two things did the trick:

katopz commented 6 years ago

Here's result for truffle 4.0 with testrpc, at old MetaCoin example.

4712388 = out of gas
4712389 = Exceeds block gas limit

But it working fine in truffle develop just broke external testrpc

Any idea for magic number?

kevinbluer commented 6 years ago

@katopz gas: 2900000 worked for me.

robbins commented 6 years ago

I get this error too, none of these gas values work for me.

ledinhhuy88 commented 6 years ago

I had the same issue with truffle 4.0.1

this is my workaround

$ truffle console
truffle(development)> web3.eth.getBlock("pending").gasLimit
6712390

then in the truffle.js:

module.exports = {
  networks: {
    development: {
      host: "localhost",
      port: 8545,
      gas: 6712390,
      network_id: "*" // Match any network id
    }
  }
};
robbins commented 6 years ago

@ledinhhuy88 I followed the above steps you just posted, and I still got the same error (truffle version 4.0.1)

xavierlepretre commented 6 years ago

Some of you guys have contracts that just don't deploy. Either because you have a mammoth one that has too big a bytecode or because you throw in the constructor. This thread is not what you are looking for.

robbins commented 6 years ago

Nope, mines issue #650 and I basically followed a tutorial, so it should compile properly.

On Nov 5, 2017 3:57 PM, "Xavier Leprêtre" notifications@github.com wrote:

Some of you guys have contracts that just don't deploy. Either because you have a mammoth one that has too big a bytecode or because you throw in the constructor. This thread is not what you are looking for.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/trufflesuite/truffle/issues/271#issuecomment-342004932, or mute the thread https://github.com/notifications/unsubscribe-auth/AeABokRHqUNpsOCegfcG4Yaatox0HxhEks5sziFPgaJpZM4KC3bx .

xavierlepretre commented 6 years ago

@NateDev100 So perhaps you can remove your comments to avoid misleading subsequent visitors.

robbins commented 6 years ago

How's it misleading? That's the error I'm getting

On Nov 6, 2017 9:19 AM, "Xavier Leprêtre" notifications@github.com wrote:

@NateDev100 https://github.com/natedev100 So perhaps you can remove your comments to avoid misleading subsequent visitors.

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/trufflesuite/truffle/issues/271#issuecomment-342161943, or mute the thread https://github.com/notifications/unsubscribe-auth/AeABooqiO2IBzO6GJ8Z4KyAdc62ealynks5szxWKgaJpZM4KC3bx .

xavierlepretre commented 6 years ago

This issue here is specifically for main net. Not just "deployment".

robbins commented 6 years ago

Well I get the same error with main net as well so... Yeah

On Nov 6, 2017 10:54 AM, "Xavier Leprêtre" notifications@github.com wrote:

This issue here is specifically for main net. Not just "deployment".

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/trufflesuite/truffle/issues/271#issuecomment-342191901, or mute the thread https://github.com/notifications/unsubscribe-auth/AeABohaNWam2tlzhkPR6mwscygZ3oTimks5szyu0gaJpZM4KC3bx .

xavierlepretre commented 6 years ago

Of course, if you get an error on any net, it has nothing to do with the net, or the main net.

zulhfreelancer commented 6 years ago

@ledinhhuy88's solution worked for me.

sarthak-mishra-se commented 6 years ago

In config file, try with

module.exports = { networks: { development: { host: 'localhost', port: 8545, network_id: '*', gas:4712388 } } };

it worked for me

tirthb commented 6 years ago

@flockonus solution to update testrpc worked for me.

swapnilpuri commented 6 years ago

@sarthakmis solution resolved my issue.

djudjuu commented 6 years ago

i had the same issue with either running out of gas or exceeding block gas limit (on the development-network). my contracts were big. With truffle 4.x, the solc-optimizer got switched off by default. switching it back on solved it for me:

in truffle.js solc: { optimizer: { enabled: true, runs: 200 } }

maybe without optimizing they exceeded the max stack-depth?...not sure, happy it works

adrobson commented 6 years ago

I got an error message with gas:6700000. I changed it to 670000 and it worked.

itoonx commented 6 years ago

Just add the value of gas to manual

mandarvaze commented 6 years ago

I think the error is too generic and misleading. That is why it works for some people and does not for some others, because the root cause is different, but the error is same. (too generic) I blogged about my experience here : https://mandarvaze.bitbucket.io/posts/please-check-your-gas-amount-maybe-misleading.html tl;dr : It was "code" issue (Should have been compile error IMO)

res-Q commented 6 years ago

This worked for me

ropsten: { host: "127.0.0.1", port: 8545, network_id: 3, gas: 4712388, // gasPrice: xxx, from: "0x689bb9068f12BfaCEF6aeeC6f37d9fa5963d4bd7" // }

liuis commented 6 years ago

try eth.getBlock("latest").gasLimit
my : 2257178

then truffle.js: gas: 2257177, It's worked for me

071bctajay commented 6 years ago

I found that my cause of the error was missing '0x' in .deploy( ) parameter So I had to use web3.eth.Contract(JSON.parse(filename.interface)).deploy({data:'0x' +bytecode}).send({gas:'1000000', from: accounts[0]});

gnidan commented 5 years ago

This issue is old. Closing for maintenance. Thanks!

sugalivijaychari commented 5 years ago

I get the same message even when I set gas limit to 1 ether

how to set gas limit to 1 ether