Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce trie level cache & recorder (#157)
* optim aligned nibbleslices * Yep * Shitty implementation * Start cleaning up * New constructor * Switch to `&mut self` * Add `NodeCache` trait * Small fixes * Fix PartialEq implementation * Adds hacky fast cache * Revert "Switch to `&mut self`" This reverts commit 5ddba5d. * Use RefCell * Refactor a little bit more * Use reference * Revert "Use reference" This reverts commit 648d6b6. * Cache nodes in `TrieDbMut` * Use `Bytes` * Cache the data * Adds `from_existing_with_cache` function * Some more cleanups * Change `leaf_node` signature * Start implementing `to_encoded` for `NodeOwned` * Finish and fix `right_iter` for `NibbleVec` * Finish `to_encoded` and add test * Remove useless lifetime * Remove useless parameter * Introduce `TrieDBBuilder` * New recorder trait * Improve `Lookup` * Cleanups * Fix stupid casting error * Add recorder to Lookup * Make most tests work again * Fix all tests * Support cache in `TrieDBMut` * Adds `TrieDBMutBuilder` * Add some test * Adds `TrieCache` implementation * Adds test with recorder and caching * Use Vec to make generate function happy... * Fix recording with active cache. * Port recorder test to `TrieDBMut` * Add second test for triedbmut * Rename `TrieCache` to reflect that it should only be used in tests * Check that we cache data in triedbmut * Adds test for adding removing key values * Fix triedbmut data caching * Ensure the iterator works with the recorder * Switch to custom Bytes * Adds some failing test * FMT * Fmt again * Fixes * More fixes * Moare * Yep * Make it compile * Fix some tests * Fix more tests * Rework the tests * Fixes * Make all tests work * Support inline nodes better * Make value recording explicit and fix caching * Switch to `TrieAccess::Value` * Fix bug with recording * Cache values as node * Use`NodeCodec` as generic argument for `TrieCache` * Use borrow from alloc * Implement Debug * Also test cache when draining the recorder * Feature gate `Debug` * Provide functions to pass an optional recorder/cache * Start adding keys * Fixes * We don't need to pass full keys for nodes * Remove unnecessary argument of `Value::Node` * Also remove the variant from triedbmut * Small updates * Let `traverse_to` return if the key was found in the trie. * Remove warning * Ensure to also record the value access in triedbmut * Cache hash alongside the actual value data * Start fixing a test and adding more tests * Fix tests * More tests * Start adding `get_hash` * Introduce new `KeyTrieAccessValue` * Rework the `CachedValue` handling * Make it compile * Adds `exists` function * Do not check for root in `TrieDB` and `TrieDBMut` constructors This leads to one extra storage lookup before we are doing the actual key lookup. This leads to reading the `root` twice when just wanting to lookup one key in the trie. We also return an error on lookup anyway if `root` doesn't exists, so there is really no need to do this twice. * FMT * Update Changelog * Fix benchmarks * Do not check for `root` on construction of `TrieDB` or `TrieDBMut` * Take &mut self * Implement `size_in_bytes` * Also visit childs of childs * Ensure we check for nodes before inserting them into the cache * Ensure the lookup works when the data can not be upgraded anymore * Remove function that isn't required * 🙈 * FMT * Apply suggestions from code review Co-authored-by: cheme <emericchevalier.pro@gmail.com> * Fix compilation * Review comment * Update trie-db/src/node.rs Co-authored-by: cheme <emericchevalier.pro@gmail.com> * Prepare traverse to with hash only * Make recording with the cache deterministic * Add some requested test * More tests and bug fixes * Add `NonExisting` as variant to `TrieAccess` * Update trie-db/src/triedbmut.rs Co-authored-by: cheme <emericchevalier.pro@gmail.com> * Update trie-db/src/triedbmut.rs Co-authored-by: cheme <emericchevalier.pro@gmail.com> * Feedback * More feedback * Update trie-db/src/lib.rs Co-authored-by: David <dvdplm@gmail.com> * Update trie-db/src/lib.rs Co-authored-by: David <dvdplm@gmail.com> * Update trie-db/src/lib.rs Co-authored-by: David <dvdplm@gmail.com> * Update trie-db/src/lib.rs Co-authored-by: David <dvdplm@gmail.com> * Remove some redudant code * Some docs * Update test-support/keccak-hasher/src/lib.rs Co-authored-by: Andronik <write@reusable.software> * Update trie-db/src/lib.rs Co-authored-by: Andronik <write@reusable.software> * Apply suggestions from code review Co-authored-by: cheme <emericchevalier.pro@gmail.com> * Pr feedback Co-authored-by: cheme <emericchevalier.pro@gmail.com> Co-authored-by: David <dvdplm@gmail.com> Co-authored-by: Andronik <write@reusable.software>
- Loading branch information