-
Notifications
You must be signed in to change notification settings - Fork 148
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
Added initial changes to support multiple Merkle trees in the storage. #2953
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.
kvbc/cmf/categorized_kvbc_msgs.cmf
Outdated
@@ -201,6 +201,7 @@ Msg BatchedInternalNodeKey 5002 { | |||
# 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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).
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.
Great job, thanks @HristoStaykov !
(please include the additional property-based testing you did over the weekend in the "Testing done" section)
@@ -105,6 +111,7 @@ inline std::string serializeImp(const sparse_merkle::Hash &hash) { | |||
} | |||
|
|||
inline void serializeImp(const sparse_merkle::InternalNodeKey &key, std::string &out) { | |||
serializeImp(key.address(), out); |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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.
LGTM, thanks @HristoStaykov !
size_t size() const { return prefix_.size(); } | ||
|
||
protected: | ||
Type prefix_; |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above, do we need to template it? As far as I only std::string satisfies it
@@ -274,7 +274,7 @@ TEST(tree_tests, insert_single_leaf_node) { | |||
// Only a single node was created. It's key is made up of an empty nibble | |||
// 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you have tests that create multiple trees?
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.
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