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

feat(metrics): calculate the real pending tx #983

Merged
merged 12 commits into from
Aug 20, 2024

Conversation

georgehao
Copy link
Member

@georgehao georgehao commented Aug 13, 2024

1. Purpose or design rationale of this PR

https://www.notion.so/scrollzkp/monitoring-Show-the-count-of-executable-transactions-on-txpool-graph-85e468811d334eed88466bddd043f3ac

because some pending tx's gasFeeCap less than the current baseFee, so add a metrics to calculate the real pending tx

2. PR title

Your PR title must follow conventional commits (as we are doing squash merge for each PR), so it must start with one of the following types:

  • build: Changes that affect the build system or external dependencies (example scopes: yarn, eslint, typescript)
  • ci: Changes to our CI configuration files and scripts (example scopes: vercel, github, cypress)
  • docs: Documentation-only changes
  • feat: A new feature
  • fix: A bug fix
  • perf: A code change that improves performance
  • refactor: A code change that doesn't fix a bug, or add a feature, or improves performance
  • style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
  • test: Adding missing tests or correcting existing tests

3. Deployment tag versioning

Has the version in params/version.go been updated?

  • This PR doesn't involve a new deployment, git tag, docker image tag, and it doesn't affect traces
  • Yes

4. Breaking change label

Does this PR have the breaking-change label?

  • This PR is not a breaking change
  • Yes

core/tx_pool.go Outdated Show resolved Hide resolved
core/tx_pool.go Outdated Show resolved Hide resolved
core/tx_pool.go Outdated Show resolved Hide resolved
@jonastheis
Copy link

Another option could be calling https://github.com/scroll-tech/go-ethereum/blob/develop/core/tx_pool.go#L505 periodically in a separate thread to not block/prolong txpool reorgs.

@0xmountaintop
Copy link
Member

Another option could be calling https://github.com/scroll-tech/go-ethereum/blob/develop/core/tx_pool.go#L505 periodically in a separate thread to not block/prolong txpool reorgs.

Yeah I agree with this approach

@omerfirmak
Copy link

omerfirmak commented Aug 14, 2024

Another option could be calling https://github.com/scroll-tech/go-ethereum/blob/develop/core/tx_pool.go#L505 periodically in a separate thread to not block/prolong txpool reorgs.

Even if this is called in another thread, it will hold the txpool lock and potentially interfere with block building and/or tx pool reorgs.

@georgehao
Copy link
Member Author

Another option could be calling https://github.com/scroll-tech/go-ethereum/blob/develop/core/tx_pool.go#L505 periodically in a separate thread to not block/prolong txpool reorgs.

Even if this is called in another thread, it will hold the txpool lock and potentially interfere with block building and/or tx pool reorgs.

maybe we can recover pending := w.eth.TxPool().PendingWithMax(false, w.config.MaxAccountsNum) to pending := w.eth.TxPool().PendingWithMax(true, w.config.MaxAccountsNum)

pending := w.eth.TxPool().PendingWithMax(false, w.config.MaxAccountsNum)

@jonastheis
Copy link

jonastheis commented Aug 15, 2024

Counting it in the worker might not actually yield the correct number of pending transactions depending on how w.config.MaxAccountsNum is configured. Which makes it quite complex to assess whether the number is correct or not. Also imo it seems out of place as it is a txpool metric and not every node might be running a worker in the future.

Let's not over complicate things. Why not just start simple with this approach and add an additional metric to see how long it blocks the txpool. If it turns out to be significant or we feel it interferes with block building and/or tx pool reorgs, we can still go the route @omerfirmak suggested and you implemented in c5df443

@georgehao
Copy link
Member Author

w.config.MaxAccountsNum

w.config.MaxAccountsNum is worker.config.MaxAccountsNum = math.MaxInt

@jonastheis
Copy link

Yes, by default worker.config.MaxAccountsNum = math.MaxInt but it's configurable with --miner.maxaccountsnum flag. This makes the result rely on side effects that don't have anything to do with what we're trying to achieve, makes it unreliable and much harder to reason about/complicated.

Also --miner.maxaccountsnum is set here in deployment: https://github.com/scroll-tech/testnet/blob/f459a3e4e558f456f3e60ffad07db70b8d2c0ad0/core/l2geth/l2geth_run.sh#L150

@georgehao
Copy link
Member Author

Yes, by default worker.config.MaxAccountsNum = math.MaxInt but it's configurable with --miner.maxaccountsnum flag. This makes the result rely on side effects that don't have anything to do with what we're trying to achieve, makes it unreliable and much harder to reason about/complicated.

Also --miner.maxaccountsnum is set here in deployment: https://github.com/scroll-tech/testnet/blob/f459a3e4e558f456f3e60ffad07db70b8d2c0ad0/core/l2geth/l2geth_run.sh#L150

you are right

@georgehao
Copy link
Member Author

So I'll follow @jonastheis 's approach, add another commit

Thegaram
Thegaram previously approved these changes Aug 16, 2024
Copy link

@Thegaram Thegaram left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works, but Jonas's suggestion would be more robust.

core/tx_pool.go Outdated Show resolved Hide resolved
jonastheis
jonastheis previously approved these changes Aug 19, 2024
colinlyguo
colinlyguo previously approved these changes Aug 19, 2024
@omerfirmak
Copy link

omerfirmak commented Aug 19, 2024

can we add a metric on how long statsWithMinBaseFee takes to run? Since it might interfere with worker, it is good to know if it is holding the txpool lock for a long period.

omerfirmak
omerfirmak previously approved these changes Aug 19, 2024
@georgehao
Copy link
Member Author

can we add a metric on how long statsWithMinBaseFee takes to run? Since it might interfere with worker, it is good to know if it is holding the txpool lock for a long period.

add cd5ed7a

colinlyguo
colinlyguo previously approved these changes Aug 19, 2024
core/tx_pool.go Outdated Show resolved Hide resolved
@georgehao georgehao merged commit 2ccacff into develop Aug 20, 2024
8 checks passed
@georgehao georgehao deleted the feat/real_pending_tx_metrcis branch August 20, 2024 07:39
0xmountaintop pushed a commit that referenced this pull request Aug 21, 2024
* calculate the real pending tx

* update

* move realPendingTx to miner

* update

* calculate the real pending tx by statsWithMinBaseFee

* update

* fix lint

* address comments

* add metrics to StatsWithMinBaseFee

* change read_lock to write_lock
lwedge99 pushed a commit to sentioxyz/scroll-geth that referenced this pull request Aug 27, 2024
* calculate the real pending tx

* update

* move realPendingTx to miner

* update

* calculate the real pending tx by statsWithMinBaseFee

* update

* fix lint

* address comments

* add metrics to StatsWithMinBaseFee

* change read_lock to write_lock
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

Successfully merging this pull request may close these issues.

6 participants