Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: sparse Merkle tree key querying (tari-project#5566)
Description --- Fixes key querying on sparse Merkle trees. Adds a test. Closes tari-project#5565. Motivation and Context --- It's possible to ask a sparse Merkle tree if it [contains](https://github.com/tari-project/tari/blob/87c070305951152c62a0179e13fadc55065cc318/base_layer/mmr/src/sparse_merkle_tree/tree.rs#L256-L259) a particular key. However, the query returns `true` whether or not the key is in the tree. This PR fixes the incorrect behavior. The query returns `true` if and only if the tree search yields a leaf node with the given key. If the tree is malformed such that the search returns an error, the query fails safe and returns `false`. Interestingly, the existing unit tests did not detect the incorrect behavior, as no test checked for the case where a key did not exist in a tree. We add a test that checks this for a few cases of interest. How Has This Been Tested? --- Existing tests pass. A new test asserts the expected behavior (and would have caught the previous incorrect behavior). What process can a PR reviewer use to test or verify this change? --- Confirm that the detection logic in the `contains` function is correct. Breaking Changes --- None.
- Loading branch information