Added initial changes to support multiple Merkle trees in the storage.#2953
Conversation
Added assertion to check for collisions + fix. Added the address field to the InternalNodeKey's serialization.
Fix to take in consideration the address field of the InternalNodeKey.
* Fix for correct reading of the size of nibbles. * Changes to the way we deserialize nibbles - we no longer rely on them being the last component in the buffer. * Fix for deserialization of the address field. * Added a non empty address in unit test serialization_unit_test/stale_db_key_internal for better code coverage.
| # The version of this key is the *tree* version, not block version | ||
| uint64 version | ||
| NibblePath path | ||
| string address |
There was a problem hiding this comment.
OK so we serialize all Merkle tree in the same collection, and we distinguish the merkle tree node keys by the account address ?
There was a problem hiding this comment.
Yes, we can have all MPT-s (the Global state, which will have an empty address field and each account's tree) in the same storage space (CF).
teoparvanov
left a comment
There was a problem hiding this comment.
Great job, thanks @HristoStaykov !
(please include the additional property-based testing you did over the weekend in the "Testing done" section)
| } | ||
|
|
||
| inline void serializeImp(const sparse_merkle::InternalNodeKey &key, std::string &out) { | ||
| serializeImp(key.address(), out); |
There was a problem hiding this comment.
Is it possible to have a prefix to distinguish for other types of nodes ? (we would have all the Merkle keys in the same CF).
There was a problem hiding this comment.
Yes, we will have to prefix the InternalNodeKey as well, this is a work in progress.
37f2266 to
2a769b8
Compare
Created types (Address and PaddedAddress) to hold addresses in LeafKey and InternalNodeKey.
We need to take in consideration the newly added PaddedAddress field.
| size_t size() const { return prefix_.size(); } | ||
|
|
||
| protected: | ||
| Type prefix_; |
There was a problem hiding this comment.
why not to use std::string directly?
| class PaddedCustomPrefix : public CustomPrefix { | ||
| public: | ||
| template <class T> | ||
| PaddedCustomPrefix(T&& arg) : CustomPrefix(std::forward<T>(arg)) {} |
There was a problem hiding this comment.
is this template can accept other types than std::string?
|
|
||
| // Return the root of a sparse merkle tree at a given version. | ||
| static InternalNodeKey root(Version version) { return InternalNodeKey(version, NibblePath()); } | ||
| template <class T> |
There was a problem hiding this comment.
same as above, do we need to template it? As far as I only std::string satisfies it
| // path, since there are no collisions requring going deeper into the tree. | ||
| auto& root = batch.internal_nodes.at(0); | ||
| ASSERT_EQ(InternalNodeKey(1, NibblePath()), root.first); | ||
| ASSERT_EQ(InternalNodeKey("", 1, NibblePath()), root.first); |
There was a problem hiding this comment.
do you have tests that create multiple trees?
There was a problem hiding this comment.
yes, a test covering multiple MPT-s is implemented here PR-3007
vmware#2953) * Added initial changes to support multiple Merkle trees in the storage. Added assertion to check for collisions + fix. Added the address field to the InternalNodeKey's serialization. * Fix for sparse_merkle_storage_serialization_unit_test. Fix to take in consideration the address field of the InternalNodeKey. * Serialization fixes. * Fix for correct reading of the size of nibbles. * Changes to the way we deserialize nibbles - we no longer rely on them being the last component in the buffer. * Fix for deserialization of the address field. * Added a non empty address in unit test serialization_unit_test/stale_db_key_internal for better code coverage. * Addressed clang-tidy warnings. * Moved address to be the first field in InternalNodeKey. * Added Address field to LeafKey. Created types (Address and PaddedAddress) to hold addresses in LeafKey and InternalNodeKey. * Fix for kvbc/test/sparse_merkle_storage/serialization_unit_test. We need to take in consideration the newly added PaddedAddress field. * Clang tidy report fixes. * Renamed address to custom_prefix.
#2953) * Added initial changes to support multiple Merkle trees in the storage. Added assertion to check for collisions + fix. Added the address field to the InternalNodeKey's serialization. * Fix for sparse_merkle_storage_serialization_unit_test. Fix to take in consideration the address field of the InternalNodeKey. * Serialization fixes. * Fix for correct reading of the size of nibbles. * Changes to the way we deserialize nibbles - we no longer rely on them being the last component in the buffer. * Fix for deserialization of the address field. * Added a non empty address in unit test serialization_unit_test/stale_db_key_internal for better code coverage. * Addressed clang-tidy warnings. * Moved address to be the first field in InternalNodeKey. * Added Address field to LeafKey. Created types (Address and PaddedAddress) to hold addresses in LeafKey and InternalNodeKey. * Fix for kvbc/test/sparse_merkle_storage/serialization_unit_test. We need to take in consideration the newly added PaddedAddress field. * Clang tidy report fixes. * Renamed address to custom_prefix.
#2953) * Added initial changes to support multiple Merkle trees in the storage. Added assertion to check for collisions + fix. Added the address field to the InternalNodeKey's serialization. * Fix for sparse_merkle_storage_serialization_unit_test. Fix to take in consideration the address field of the InternalNodeKey. * Serialization fixes. * Fix for correct reading of the size of nibbles. * Changes to the way we deserialize nibbles - we no longer rely on them being the last component in the buffer. * Fix for deserialization of the address field. * Added a non empty address in unit test serialization_unit_test/stale_db_key_internal for better code coverage. * Addressed clang-tidy warnings. * Moved address to be the first field in InternalNodeKey. * Added Address field to LeafKey. Created types (Address and PaddedAddress) to hold addresses in LeafKey and InternalNodeKey. * Fix for kvbc/test/sparse_merkle_storage/serialization_unit_test. We need to take in consideration the newly added PaddedAddress field. * Clang tidy report fixes. * Renamed address to custom_prefix.
vmware#2953) * Added initial changes to support multiple Merkle trees in the storage. Added assertion to check for collisions + fix. Added the address field to the InternalNodeKey's serialization. * Fix for sparse_merkle_storage_serialization_unit_test. Fix to take in consideration the address field of the InternalNodeKey. * Serialization fixes. * Fix for correct reading of the size of nibbles. * Changes to the way we deserialize nibbles - we no longer rely on them being the last component in the buffer. * Fix for deserialization of the address field. * Added a non empty address in unit test serialization_unit_test/stale_db_key_internal for better code coverage. * Addressed clang-tidy warnings. * Moved address to be the first field in InternalNodeKey. * Added Address field to LeafKey. Created types (Address and PaddedAddress) to hold addresses in LeafKey and InternalNodeKey. * Fix for kvbc/test/sparse_merkle_storage/serialization_unit_test. We need to take in consideration the newly added PaddedAddress field. * Clang tidy report fixes. * Renamed address to custom_prefix.
#2953) * Added initial changes to support multiple Merkle trees in the storage. Added assertion to check for collisions + fix. Added the address field to the InternalNodeKey's serialization. * Fix for sparse_merkle_storage_serialization_unit_test. Fix to take in consideration the address field of the InternalNodeKey. * Serialization fixes. * Fix for correct reading of the size of nibbles. * Changes to the way we deserialize nibbles - we no longer rely on them being the last component in the buffer. * Fix for deserialization of the address field. * Added a non empty address in unit test serialization_unit_test/stale_db_key_internal for better code coverage. * Addressed clang-tidy warnings. * Moved address to be the first field in InternalNodeKey. * Added Address field to LeafKey. Created types (Address and PaddedAddress) to hold addresses in LeafKey and InternalNodeKey. * Fix for kvbc/test/sparse_merkle_storage/serialization_unit_test. We need to take in consideration the newly added PaddedAddress field. * Clang tidy report fixes. * Renamed address to custom_prefix.
vmware#2953) * Added initial changes to support multiple Merkle trees in the storage. Added assertion to check for collisions + fix. Added the address field to the InternalNodeKey's serialization. * Fix for sparse_merkle_storage_serialization_unit_test. Fix to take in consideration the address field of the InternalNodeKey. * Serialization fixes. * Fix for correct reading of the size of nibbles. * Changes to the way we deserialize nibbles - we no longer rely on them being the last component in the buffer. * Fix for deserialization of the address field. * Added a non empty address in unit test serialization_unit_test/stale_db_key_internal for better code coverage. * Addressed clang-tidy warnings. * Moved address to be the first field in InternalNodeKey. * Added Address field to LeafKey. Created types (Address and PaddedAddress) to hold addresses in LeafKey and InternalNodeKey. * Fix for kvbc/test/sparse_merkle_storage/serialization_unit_test. We need to take in consideration the newly added PaddedAddress field. * Clang tidy report fixes. * Renamed address to custom_prefix.
vmware#2953) * Added initial changes to support multiple Merkle trees in the storage. Added assertion to check for collisions + fix. Added the address field to the InternalNodeKey's serialization. * Fix for sparse_merkle_storage_serialization_unit_test. Fix to take in consideration the address field of the InternalNodeKey. * Serialization fixes. * Fix for correct reading of the size of nibbles. * Changes to the way we deserialize nibbles - we no longer rely on them being the last component in the buffer. * Fix for deserialization of the address field. * Added a non empty address in unit test serialization_unit_test/stale_db_key_internal for better code coverage. * Addressed clang-tidy warnings. * Moved address to be the first field in InternalNodeKey. * Added Address field to LeafKey. Created types (Address and PaddedAddress) to hold addresses in LeafKey and InternalNodeKey. * Fix for kvbc/test/sparse_merkle_storage/serialization_unit_test. We need to take in consideration the newly added PaddedAddress field. * Clang tidy report fixes. * Renamed address to custom_prefix.
vmware#2953) * Added initial changes to support multiple Merkle trees in the storage. Added assertion to check for collisions + fix. Added the address field to the InternalNodeKey's serialization. * Fix for sparse_merkle_storage_serialization_unit_test. Fix to take in consideration the address field of the InternalNodeKey. * Serialization fixes. * Fix for correct reading of the size of nibbles. * Changes to the way we deserialize nibbles - we no longer rely on them being the last component in the buffer. * Fix for deserialization of the address field. * Added a non empty address in unit test serialization_unit_test/stale_db_key_internal for better code coverage. * Addressed clang-tidy warnings. * Moved address to be the first field in InternalNodeKey. * Added Address field to LeafKey. Created types (Address and PaddedAddress) to hold addresses in LeafKey and InternalNodeKey. * Fix for kvbc/test/sparse_merkle_storage/serialization_unit_test. We need to take in consideration the newly added PaddedAddress field. * Clang tidy report fixes. * Renamed address to custom_prefix.
Added assertion to check for collisions + fix.
Added the address field to the InternalNodeKey's serialization.
Initial work to support multiple Merkle trees in storage. This will be needed when we build a MPT per account and a global MPT where the keys will be the account addresses and the values will be the account storage Merkle roots.
All unit tests pass + added a non empty address in unit test
serialization_unit_test/stale_db_key_internal for better
code coverage.
Ran locally 200 times the property based test sparse_merkle_storage_db_adapter_property_test