Skip to content
This repository has been archived by the owner on May 11, 2023. It is now read-only.

Fix: SMT Node left_child and right_child return placeholder when key is zero sum #72

Merged
merged 2 commits into from
Mar 1, 2022

Conversation

bvrooman
Copy link
Contributor

@bvrooman bvrooman commented Feb 28, 2022

When retrieving a left child or right child from an SMT node, we must accommodate the case when the child is a placeholder. The placeholder node is a node with the zero sum key (000...). In the current design, all children must be present in the underlying data store; this includes placeholders. This assumes that the store will be initialized with a zero-sum key mapped to a placeholder, i.e.

...
let zero_sum_key = zero_sum()
assert!(storage[zero_sum_key].is_placeholder())

This has a few important drawbacks:

  • The store must be initialized properly to handle this edge case. This means a storage write when initializing an SMT
  • Reading a zero sum key incurs a round trip to the store, when the child can be resolved client side
  • Deleting path nodes or side nodes may involve deleting a placeholder; this will leave the storage in an invalid state as no further placeholders can be loaded

These drawbacks are all neatly resolved by ensuring that a placeholder is retuned when encountering a zero sum key at the library level.

@bvrooman bvrooman changed the title Fix SMT Node left_child and right_child return placeholder when key is zero sum Fix: SMT Node left_child and right_child return placeholder when key is zero sum Feb 28, 2022
@bvrooman bvrooman self-assigned this Feb 28, 2022
@bvrooman bvrooman linked an issue Feb 28, 2022 that may be closed by this pull request
@bvrooman bvrooman removed a link to an issue Feb 28, 2022
@bvrooman bvrooman merged commit e46dc76 into master Mar 1, 2022
@bvrooman bvrooman deleted the bvrooman-fix-storage-node-zero-sum branch March 1, 2022 02:09
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants