Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decrease in Transaction Creation Speed Over Time in Fork #1706

Open
Akbar30Bill opened this issue Aug 28, 2023 · 0 comments
Open

Decrease in Transaction Creation Speed Over Time in Fork #1706

Akbar30Bill opened this issue Aug 28, 2023 · 0 comments

Comments

@Akbar30Bill
Copy link

Akbar30Bill commented Aug 28, 2023

Environment information

  • brownie Version: 1.19.3
  • ganache-cli Version: not using
  • Python Version: 3.8.16
  • OS: Tried on OSX, Ubuntu 22.04

What was wrong?

I use Brownie to create and execute transactions on a custom Anvil fork. Note that I am not using Brownie's development network cmd to run this fork; instead, I have forked the network separately and added the network using brownie networks add but generally, this case is also valid for other forking methods that I have tried such as ganache.

As I create more transactions, I've observed that the speed of transaction creation gradually decreases. After running my script for a while, hardware resource usage (CPU, RAM, Disk) significantly increases, and the CPU hits 100% usage (one entire core). This leads me to suspect that Brownie might have a bottleneck.

To Reproduce:

  1. Fork the network (anvil --base-fee 0 --fork-url <YOUR_FORK_URL> --port 42069 --auto-impersonate --compute-units-per-second 8000 --no-rate-limit)
  2. Add the network to brownie (brownie networks add Polygon anvil_polygon_mainnet_fork host='http://127.0.0.1:42069' chainid=137)
  3. Run the Brownie script to create transactions (brownie run scripts/bulktx.py --network anvil_polygon_mainnet_fork)
  4. Observe the decrease in transaction creation speed and increase in hardware resource usage over time.

Expected Behavior:

The transaction creation speed should remain consistent regardless of the number of transactions created without significant hardware resource increase.

Actual Behavior:

The transaction creation speed decreases over time, and hardware usage significantly increases, eventually hitting 100% CPU usage.

BulkTx script:

from brownie import accounts, web3
from web3.middleware import construct_simple_cache_middleware
from time import time

def main():
    web3.middleware_onion.add(construct_simple_cache_middleware(cache_class=dict))

    acc = accounts.at('<some public address that has balance in the forked network>', force=True)
    print(acc: {acc}')

    start_time, idx = time(), 0
    while idx := idx+1:
        tx = acc.transfer(acc.address, 1000000000000000)
        print(f'{idx}: {(time() - start_time)/idx}')

How it started:
Screenshot 2023-08-28 at 16 55 18
Screenshot 2023-08-28 at 16 58 08
How it's going:
Screenshot 2023-08-28 at 17 27 04
Screenshot 2023-08-28 at 17 26 07

Note: the speed in the screen shots shows the AVG time it takes to make a transaction and does not mean actual TPS speed

I am genuinely curious about why transaction creation slows down over time and would greatly appreciate any insights or solutions.

I appreciate your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant