-
Notifications
You must be signed in to change notification settings - Fork 269
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
Improve Trie Node Retrieve and Save #1526
base: master
Are you sure you want to change the base?
Conversation
@@ -55,33 +57,62 @@ public TrieStoreImpl(KeyValueDataSource store) { | |||
*/ | |||
@Override | |||
public void save(Trie trie) { | |||
noRetrievesInSaveTrie = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't this part be thread-safe? what about keeping this tracing data in some object and passing this object as param in the void save(Trie trie, boolean isRootNode, int level)
method recursively?
if (savedTries.contains(trie)) { | ||
// it is guaranteed that the children of a saved node are also saved | ||
private void save(Trie trie, boolean isRootNode, int level) { | ||
if (trie.wasSaved()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess there could be cases when multiple sub-tries in a trie have same hash but in fact are different java objects, so this flag wasSaved
wouldn't work. Could be a problem when importing an entire state via the --import
flag.
Also looks like this wasSaved
flag prevents the import feature to work, as it uses Trie.fromMessage
to load raw data from a file here
4010516
to
0b917ce
Compare
Amazing work! I will test the performance improvement |
blockExecutor.execute(block, parent.getHeader(), false, false); | ||
BlockResult blockResult = blockExecutor.execute(block, parent.getHeader(), false, false); | ||
|
||
if (!Arrays.equals(blockResult.getFinalState().getHash().getBytes(), block.getStateRoot())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check will fail for blocks before 1591000 because those blockstate roots are either not validated, or converted with TrieConeverter
@@ -151,7 +154,10 @@ public static Trie fromMessage(byte[] message, TrieStore store) { | |||
trie = fromMessageRskip107(ByteBuffer.wrap(message), store); | |||
} | |||
|
|||
trie.saved = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this saved
redundant as it is gonna pass from either frommessacheOrchid
or fromMessageRskip107
which already mark the trie as saved
?
Description
It removes a trie node set, add an internal boolean flag to each trie node to knows if the node was already saved, improve the retrieval of the node (no get hash calculation is needed for adding the retrieved node to the removed set), improve save trie without visiting unloaded child nodes
Motivation and Context
It solves #1509 and #1510
How Has This Been Tested?
Additionally to the usual code tests, the execution of blocks from a testnet node was executed:
There are new logs, to obtain some additional information from
TrieStoreImpl
andDataSourceWithCache
. The above command was executed withOnly for testing purpose.
Some additional logs obtained:
With this additional logs we have more information about the effectivity of having a cache (and the Trie getHash issue #1511 was discovered using these logs)
Types of changes
Checklist:
It is recommended to test with a long synchronization and also with some blocks added in production environment