Skip to content
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

Conversation

HristoStaykov
Copy link
Contributor

@HristoStaykov HristoStaykov commented Mar 10, 2023

Added assertion to check for collisions + fix.
Added the address field to the InternalNodeKey's serialization.

  • Problem Overview
    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.
  • Testing Done
    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

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.
@HristoStaykov HristoStaykov requested a review from vrancurel March 16, 2023 13:32
@@ -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
Copy link
Contributor

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 ?

Copy link
Contributor Author

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).

Copy link
Contributor

@teoparvanov teoparvanov left a 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);
Copy link
Contributor

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).

Copy link
Contributor Author

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.

@cloudnoize cloudnoize force-pushed the storage/changes_for_eth_support branch from 37f2266 to 2a769b8 Compare March 27, 2023 08:36
kvbc/cmf/categorized_kvbc_msgs.cmf Outdated Show resolved Hide resolved
Created types (Address and PaddedAddress) to hold addresses in LeafKey and InternalNodeKey.
We need to take in consideration the newly added PaddedAddress field.
Copy link
Contributor

@teoparvanov teoparvanov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @HristoStaykov !

@HristoStaykov HristoStaykov merged commit fe408d5 into vmware:storage/changes_for_eth_support Mar 31, 2023
size_t size() const { return prefix_.size(); }

protected:
Type prefix_;
Copy link
Contributor

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)) {}
Copy link
Contributor

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>
Copy link
Contributor

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);
Copy link
Contributor

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?

Copy link
Contributor Author

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

HristoStaykov added a commit to HristoStaykov/concord-bft that referenced this pull request Apr 11, 2023
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.
cloudnoize pushed a commit that referenced this pull request Apr 13, 2023
#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.
cloudnoize pushed a commit that referenced this pull request Apr 24, 2023
#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.
HristoStaykov added a commit to HristoStaykov/concord-bft that referenced this pull request Apr 24, 2023
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.
cloudnoize pushed a commit that referenced this pull request Apr 27, 2023
#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.
mdarade pushed a commit to mdarade/concord-bft that referenced this pull request Apr 28, 2023
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.
mdarade pushed a commit to mdarade/concord-bft that referenced this pull request Apr 30, 2023
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.
mdarade pushed a commit to mdarade/concord-bft that referenced this pull request May 1, 2023
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants