truffle
truffle copied to clipboard
truffle migrate calls `eth_estimateGas` twice per contract
I instrumented Ganache to track RPC calls per migations (1 contract, 2 contracts, 3 contracts ... 25 contracts) and observed Truffle called eth_estimateGas twice per contract.
| Num Contracts | eth_estimateGas |
|---|---|
| 1 | 2 |
| 2 | 4 |
| 3 | 6 |
| ... | ... |
| 24 | 48 |
| 25 | 50 |
![]() |
Hm -- could this be because migrate/deploy calls eth_estimateGas on its own, but these days Truffle Contract also calls eth_estimateGas, so it gets called twice? Would the solution then be to remove the first of those? (If I'm right, anyway.)
Testing this on the metacoin box I found that there were 5 calls for gas estimation (I checked in @truffle/contract's getGasEstimate function so is possible that it is being called from web3 separately?). It turns out that 3 were for the contract deployments. The other 2 I believe were for the transactions that call setCompleted on the Migrations contract. I deleted the Migrations contract and its associated migration file and there were only 3 calls for gas estimation.
Thanks, @eggplantzzz! Is it time to drop Migrations.sol and 1_initial_migrations.js from truffle init?
I think we decided to do this, didn't we? Or maybe we decided to drop it for Truffle Boxes?
Oh, OK, so there's still a bug here then, even without Migrations?
I'm not sure, @cds-amal you had some more information on this?
Update: It looks like it does indeed send 2 estimate gas calls with the same data.
Yes, there's still an issue. I did a sanity check with @davidmurdoch and @gnidan. We observed that ganache logs 2 eth_estimateGas per deployment. @gnidan's hunch is truffle-contract calls it once and web3 the second time.
You can set up a truffle project w/ one contract sans the migrations.sol it's associated migration file. In one terminal run ganache --verbose and in a second truffle console --url http://localhost:8545 to start a console env. In the console env run migrate and examine the ganache logs to see two eth_estimateGas calls with identical data.
