truffle icon indicating copy to clipboard operation
truffle copied to clipboard

truffle migrate calls `eth_estimateGas` twice per contract

Open cds-amal opened this issue 3 years ago • 7 comments

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
image

cds-amal avatar Jun 16 '22 15:06 cds-amal

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.)

haltman-at avatar Jun 21 '22 17:06 haltman-at

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.

eggplantzzz avatar Jul 11 '22 21:07 eggplantzzz

Thanks, @eggplantzzz! Is it time to drop Migrations.sol and 1_initial_migrations.js from truffle init?

cds-amal avatar Jul 12 '22 02:07 cds-amal

I think we decided to do this, didn't we? Or maybe we decided to drop it for Truffle Boxes?

eggplantzzz avatar Jul 12 '22 14:07 eggplantzzz

Oh, OK, so there's still a bug here then, even without Migrations?

haltman-at avatar Jul 12 '22 17:07 haltman-at

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.

eggplantzzz avatar Jul 13 '22 20:07 eggplantzzz

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.

cds-amal avatar Jul 13 '22 20:07 cds-amal