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

Fine-grained Pending state #1575

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

NingLin-P
Copy link

The Pending state is a list that is used to keep track of all the (transaction, status, receipt) in the block during block execution, and then in on_finalize these data are moved to CurrentBlock/CurrentReceipts/CurrentTransactionStatuses for RPC service usage.

Because the Pending state is a StorageValue<_, Vec<...>>, which presents as a single value in the trie, appending items to the list means read,update,write to the same value, which gets slower and slower as the list grows during block execution, and depend on the number of tx in the block it can result in 3-20x of slow (see below).

This PR fixes the issue by refactoring the Pending state, to replace StorageValue with StorageMap so each tx is present as a single value in the trie, although it results in more db delete in on_finalize but in practice, it is much faster than updating a big single list.

Below is a table about the block execution time of different Pending states where N represents the total number of Ethereum::transact in the block, each tx transfers funds from the same Alice account to a new different account. The test is running on a MacBook Pro, Apple M1 Pro, 10 Core(s)

Tx in block N = 1000 N = 2000 N = 4000 N = 5000 N = 6000 N = 8000
Current Pending state 690ms 2_498ms 9_493ms 14_921ms 21_383ms 37_426ms
No Pending state 194ms 382ms 780ms 1_047ms 1_187ms 1_596ms
Fine-grained Pending state 221ms 449ms 869ms 1_103ms 1_329ms 1_772ms

@NingLin-P NingLin-P requested a review from sorpaas as a code owner December 20, 2024 20:18
@conr2d
Copy link
Contributor

conr2d commented Dec 25, 2024

Interesting results. I thought the Polkadot SDK was optimized enough for this case, but the benchmark you shared suggests otherwise. Could you share the script you used for benchmarking?

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.

2 participants