trufflesuite / ganache

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

Home Page: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_

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`evm_mine` is with thousands of blocks is way too slow

ianrowan opened this issue · comments

Issue

While running the latest version of ganache running in GitHub actions and using the evm_mine with blocks param sometimes does not advance the specified amount of blocks.

Evidence and Usage

Block advancement is currently executed as follows:

 await axios.post(
    providerUrl,
    {
      jsonrpc: '2.0',
      id: 1,
      method: 'evm_mine',
      params: [{ blocks: blocks }],
    },
    {
      headers: {
        'Content-Type': 'application/json',
      },
    }
  );

A typical amount of blocks to advance would be ~27000. Block number is then polled until it reaches expected blocks number before moving to next step in tests. An example of the output after polling for 120 secs is:
image
And block reached before timing out
image
Not this is only ~130 blocks

Ganache is run with the the following config
--fork --miner.blockTime 12

Hm, I couldn't reproduce.

I ran ganache:

ganache --fork --miner.blockTime 12

and then ran these curl commands:

curl -X post --data '{"jsonrpc":"2.0","id":1,"method":"evm_mine","params":[{"blocks":27000}]}' http://localhost:8545 && curl -X post --data '{"jsonrpc":"2.0","id":1,"method":"eth_blockNumber","params":[]}' http://localhost:8545

and the block number advanced 27000 blocks as expected.

I wonder if there is another bug related to #3248 lurking here.

Hey @davidmurdoch,
It may be difficult to reproduce as it occurs variably, I think the blocks are being mined but the call is taking varying amounts of time, sometimes very long(> 60s). The only reason for the failure is a timeout we have set up. So problem isnt exactly that the blocks arent being mined but the performance

And re: #3248 I believe we are properly awaiting everything and should have a single evm_mine call active at any given time.

Ah ok, in that case this is certainly related to the TODO in the code that mines the blocks:

// TODO(perf): add an option to mine a bunch of blocks in a batch so
// we can save them all to the database in one go.
// Developers like to move the blockchain forward by thousands of blocks
// at a time and doing this would make it way faster