解决Migrations过程中的exceeded the block limit

前言

这是一个罕见问题,发生在私有链ETH环境下,当执行truffle migrate --network development

Error:  *** Deployment Failed ***

"Migrations" exceeded the block limit (with a gas value you set).
   * Block limit:  0x31d836
   * Gas sent:     6721975
   * Try:
      + Sending less gas.
      + Setting a higher network block limit if you are on a
        private network or test client (like ganache).

问题的原因是block limit小于gas花费。

> eth.getBlock(583)
{
  difficulty: 173805,
  extraData: "0xd883010907846765746888676f312e31332e34856c696e7578",
  gasLimit: 5548767,
  gasUsed: 0,
  hash: "0x18b004737ac869ceb16a80a29072bdabb2557601a166153d155b6add2f42f1c5",
  logsBloom: "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
  miner: "0xde18b50eb2eb9d718f857b05af9d823ec09bb3d6",
  mixHash: "0x5830b3e71f46c55920a4e42337fc27f7217fdd7fe13e2a62116ab0cc1125550b",
  nonce: "0x096ee30294dc378f",
  number: 583,
  parentHash: "0x92514cf81550666e2355329841b6181a19cc2b814a5224bf8ab1c007819b501a",
  receiptsRoot: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
  sha3Uncles: "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
  size: 538,
  stateRoot: "0x065c4b9884d690673241e9a38658d41f4d7ab8dc7fdd1f25e90526f2eb9be077",
  timestamp: 1574494459,
  totalDifficulty: 88415771,
  transactions: [],
  transactionsRoot: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
  uncles: []
}

当时,我才挖出来583个,那个时候 gasLimit: 5548767,但是部署合约消耗,6721975。于是,我就各种查资料,然后,又再一次执行了部署程序,神奇的通过了。

truffle migrate --network development

Compiling your contracts...
===========================
> Everything is up to date, there is nothing to compile.



Starting migrations...
======================
> Network name:    'development'
> Network id:      96574
> Block gas limit: 0x732323


1_initial_migration.js
======================

   Deploying 'Migrations'
   ----------------------
   > transaction hash:    0x1f0ef48bf22d7acf4414ed7a3291bd42ae85fa9db245816302aed800ce7374ed
   > Blocks: 0            Seconds: 0
   > contract address:    0x01Ad2c65798768f15BdA034350a96e8A3b16508F
   > block number:        899
   > block timestamp:     1574494923
   > account:             0xDE18B50EB2eB9d718F857B05af9D823EC09bB3D6
   > balance:             4505
   > 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


2_deploy_contracts.js
=====================

   Deploying 'RCT'
   ---------------
   > transaction hash:    0x29e38fe815ad5931272dbc26cfd843def5efeb60d02c96ac97162766635688bd
   > Blocks: 0            Seconds: 0
   > contract address:    0xC0398b54898aeAC946966b845b2693544Bd34DF4
   > block number:        904
   > block timestamp:     1574494931
   > account:             0xDE18B50EB2eB9d718F857B05af9D823EC09bB3D6
   > balance:             4525
   > gas used:            2471410
   > gas price:           20 gwei
   > value sent:          0 ETH
   > total cost:          0.0494282 ETH


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


Summary
=======
> Total deployments:   2
> Final cost:          0.05497744 ETH

此时的block limit 是

> eth.getBlock(864)
{
  difficulty: 199208,
  extraData: "0xd883010907846765746888676f312e31332e34856c696e7578",
  gasLimit: 7299375,
  gasUsed: 0,
  hash: "0xd13863e0d5a7ac29f5635352c2b43c40e79f195137bbb4b45b400827f455b337",
  logsBloom: "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
  miner: "0xde18b50eb2eb9d718f857b05af9d823ec09bb3d6",
  mixHash: "0xcb800a3cdf5430eef2a03ba7256cd741f1574839ee147d3a1542417a2ca9ccc4",
  nonce: "0x0523739c86f08ba8",
  number: 864,
  parentHash: "0x2bbe6987e43d5366918c2a4dce2d62311d25bfacdcfc5d87742030c5c305e7de",
  receiptsRoot: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
  sha3Uncles: "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
  size: 538,
  stateRoot: "0x5d38b3f52b2cf219ac0ee1ed02c107a102e35033c71ab72a8e90e9b165af8475",
  timestamp: 1574494869,
  totalDifficulty: 140755143,
  transactions: [],
  transactionsRoot: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
  uncles: []
}

解决问题了。这个问题的解决方案就是等一会.....

还可以关注一个文章https://www.jianshu.com/p/f030338a0c31

你可能感兴趣的:(解决Migrations过程中的exceeded the block limit)