Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 inon_finalize
these data are moved toCurrentBlock/CurrentReceipts/CurrentTransactionStatuses
for RPC service usage.Because the
Pending
state is aStorageValue<_, 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 replaceStorageValue
withStorageMap
so each tx is present as a single value in the trie, although it results in more db delete inon_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 whereN
represents the total number ofEthereum::transact
in the block, each tx transfers funds from the sameAlice
account to a new different account. The test is running on aMacBook Pro, Apple M1 Pro, 10 Core(s)
Pending
statePending
statePending
state