Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Port CW3 to Secret #1
base: main
Are you sure you want to change the base?
Port CW3 to Secret #1
Changes from 1 commit
2f21b42
ce7cce5
c01f7f1
9a9ec23
267f277
9934cdb
d25ae1d
70afacf
9492551
5543fd4
48a5522
995c9bc
6d41153
778cbf3
d890f21
56f2c1a
c2c08ed
c7d0eae
1282f06
3077125
9df8d89
23e6b88
42e926f
91c3224
065a81f
6c4e19d
6fbc029
11b28a2
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
curious why we need a separate storage item for map keys instead of using
Map::keys()
?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.
The addresses are stored in a BST to have persistent ordering and to avoid re-sorting every time we list votes or voters.
Also please note that the map structure used is
KeyMap
fromsecret-toolkit
as opposed to the regularMap
fromcw-storage-plus
;KeyMap
does not have the same interface.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.
what about using
.iter_keys()
? https://github.com/scrtlabs/secret-toolkit/blob/master/packages/storage/src/keymap.rs#L560-L565my concern is the keys from the VOTERS map going out of sync from the VOTER_ADDRESSES list, would be easier to manage one source of truth instead
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.
That works but then we're back to performing potentially prohibitively expensive sorting operations as the number of voters increases. The idea behind the BST was to allow the CW3 to scale to support an arbitrary amount of voters without significant increases in computational cost. But if that's not an intended use case I guess it doesn't matter. In that case the BST is pretty useless too.
I don't see how they are going to get out of sync as they are always mutated together; the only scenario I see is if
VOTERS
is successfully mutated andVOTER_ADDRESSES
fails with an error, but I now realize this was probably the motivation behind the other snippet you commented on:Although we probably need to swap the insertion order so that there are always at worst more addresses than voters: