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

performance: keep trie prefetch during validation phase #1954

Merged
merged 1 commit into from
Oct 31, 2023

Conversation

brilliant-lx
Copy link
Collaborator

@brilliant-lx brilliant-lx commented Oct 31, 2023

Description

Recently, we saw some nodes spent lots of time on block validation phase, could even longer than 6 seconds, which leads to slash of some validators. We found out it is caused by some giant transactions, like XenCrypto. Take this transaction for example: https://bscscan.com/tx/0x5d948f50b9f1245fc4c9feaff71e02c607468d9540c33606253fa89998e9b7d8, which consumed ~40M gas in a single transaction.
It is quite unfriendly to the current trie prefetch logic, which is terminated right after entering validation phase, since getTrie() will stop the trie prefetch.
This PR tries to keep trie prefetch until validation phase is completed, which will call StopPrefetcher() at the end of StateIntermediateRoot().

Test Result:

For these long time validation phase, the validation time could be reduced by more than 80%, which is a huge improve.

//= latest develop branch: import the trouble  block take ~12s
t=2023-10-30T17:11:19+0000 lvl=info msg="Imported new chain segment"            number=33,060,898 hash=0x59e91888d0b6a5aef78e961ef5eb7545eed3aad3409cc26a38625639f4225c89 miner=0xb218C5D6aF1F979aC42BC68d98A5A0D796C6aB01 blocks=1          txs=115           mgas=24.430  elapsed=11.968s      mgasps=2.041   dirty="86.95 MiB"

// develop with this patch: import the same  block take ~2.1s
t=2023-10-30T17:11:09+0000 lvl=info msg="Imported new chain segment"            number=33,060,898 hash=0x59e91888d0b6a5aef78e961ef5eb7545eed3aad3409cc26a38625639f4225c89 miner=0xb218C5D6aF1F979aC42BC68d98A5A0D796C6aB01 blocks=1          txs=115           mgas=24.430  elapsed=2.137s       mgasps=11.431  dirty="278.60 MiB"

Metrics of the test:
image

Rationale

NA

Example

NA

Changes

NA

@brilliant-lx brilliant-lx changed the title trie: keep trie prefetch during validation phase performance: keep trie prefetch during validation phase Oct 31, 2023
Copy link

@RenRick RenRick left a comment

Choose a reason for hiding this comment

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

LGTM

@brilliant-lx brilliant-lx merged commit 56424d3 into bnb-chain:develop Oct 31, 2023
5 checks passed
brilliant-lx added a commit to brilliant-lx/bsc that referenced this pull request Oct 31, 2023
brilliant-lx added a commit to brilliant-lx/bsc that referenced this pull request Nov 1, 2023
@brilliant-lx
Copy link
Collaborator Author

reference: #952

whw188 pushed a commit to tylerteea/mev-bsc that referenced this pull request Dec 6, 2023
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.

4 participants