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

Fix iterator #2412

Merged
merged 2 commits into from
May 26, 2021
Merged

Fix iterator #2412

merged 2 commits into from
May 26, 2021

Conversation

spencercorwin
Copy link
Collaborator

@spencercorwin spencercorwin commented May 26, 2021

Description of the Change

  • Does all the work necessary to remove System.Iterator.Create from our compiler. To get around this API being removed we do this:
    • Iterator over the map (using a for loop)
    • Serialize each key/value pair
    • Append 6 random bytes to the key which will be used later for lookup
    • Put each item into storage
    • Then call System.Storage.Find using the pref-defined prefix
    • Get back a StorageIterator with all the items we just put into storage
    • Ta-da! We have our iterator. The only problem is that now every key has 6 random bytes appended to it. So anywhere that we get key values from an iterator we first slice off the first 6 bytes, then deserialize it, and we have our original key (which is also usually serialized and thus needs to be deserialized again)
    • Then, finally, we add every key used to set an item into contract storage to the global DeleteIteratorCacheStorage, so that it will be deleted from contract storage at the end of every contract call.
  • Fixes compiler test infrastructure
  • Add compiler test helper for running basics tests inside of a smart contract (used for when you need to test something that uses storage)
  • Add print syscall for printing iterator contents (note that this will deplete the iterator upon use)
  • Fixes minor bug in ContractManifest
  • Changes Magic to Network in CS Dispatcher/ReturnHelper code
  • Adds a new GlobalProperty and helper for DeleteIteratorCache. This is used just like DeleteCacheStorage except just for this new case

Test Plan

  • map/forEach.test.ts
  • map/iterator.test.ts
  • set/forEach.test.ts
  • set/iterator.test.ts
  • array/entries.test.ts
  • array/iterator.test.ts

Alternate Designs

None. See TODO notes in CreateMapIteratorHelper.ts

Benefits

Compiler compatible with RC2.

Possible Drawbacks

Unknown bugs. Also see TODO notes in CreateMapIteratorHelper.ts

Applicable Issues

#2410

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant