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

Add Array.ID() and OrderedMap.ID() #321

Merged
merged 1 commit into from
Jul 6, 2023

Conversation

fxamacker
Copy link
Member

@fxamacker fxamacker commented Jun 29, 2023

Closes #320
Updates #296 #292 onflow/flow-go#1744

Description

Currently Array.StorageID() and OrderedMap.StorageID() are used as identifier in client because storage IDs are guaranteed to unique. However, storage ID should be only used to retrieve slabs (registers) from storage.

Also, when Atree register inlining is implemented in the future, some resources may not be stored in separate slabs, so they will not have storage IDs anymore.

This PR adds ID() to uniquly identify Array and OrderedMap. For now, this is implemented to be identical to StorageID() in raw bytes ([16]bytes). In the future, this can be changed to be decoupled from storage ID completely.

Clients should use ID() instead of StorageID() to identify Atree composite values.

NEXT PR AS FOLLOWUP

A separate PR will be opened to do a lot of renamings such as:

  • StorageID to SlabID (thanks @turbolent!)
  • ID to ValueID
  • StorageIndex to SlabIndex
  • and etc.

So we'll have something like:

func (*Array) ValueID() ValueID {}
func (*Array) SlabID() SlabID {}

  • Targeted PR against main branch
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work
  • Code follows the standards mentioned here
  • Updated relevant documentation
  • Re-reviewed Files changed in the Github PR explorer
  • Added appropriate labels

Currently Array.StorageID() and OrderedMap.StorageID() are used as
identifier in client because storage IDs are guaranteed to unique.
However, storage ID should be only used to retrieve slabs (registers)
from storage.

In the future, when Atree register inlining is implemented,
some resources may not be stored in separate slabs, so they
will not have storage IDs anymore.

This commit adds ID() to uniquly identify Array and OrderedMap.  For now,
this is implemented as identical to StorageID in raw bytes ([16]bytes).
In the future, this can be changed to be decoupled from storage ID
completely.  Clients should use ID instead of StorageID to identify
atree composite values.
@fxamacker fxamacker added the enhancement New feature or request label Jun 29, 2023
@fxamacker fxamacker requested a review from ramtinms as a code owner June 29, 2023 21:11
@fxamacker fxamacker self-assigned this Jun 29, 2023
@codecov-commenter
Copy link

Codecov Report

Merging #321 (116c959) into main (a996413) will increase coverage by 1.38%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #321      +/-   ##
==========================================
+ Coverage   64.55%   65.93%   +1.38%     
==========================================
  Files          14       14              
  Lines        8019     8385     +366     
==========================================
+ Hits         5177     5529     +352     
+ Misses       2164     2120      -44     
- Partials      678      736      +58     
Impacted Files Coverage Δ
storage.go 78.85% <ø> (+4.33%) ⬆️
array.go 69.92% <100.00%> (+0.12%) ⬆️
map.go 66.88% <100.00%> (+0.17%) ⬆️

... and 2 files with indirect coverage changes

Copy link
Member

@turbolent turbolent left a comment

Choose a reason for hiding this comment

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

👍

@@ -31,6 +31,8 @@ import (

const LedgerBaseStorageSlabPrefix = "$"

type ID [16]byte
Copy link
Member

@turbolent turbolent Jul 5, 2023

Choose a reason for hiding this comment

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

Given there are now multiple IDs in the package, it might make sense to make this name a bit more descriptive to reduce the likelihood of confusing it with another ID.

Maybe StorableID?

In addition, maybe we can also rename StorageID to SlabID to make it clearer that it just identifies a slab, and cannot always identify something that is stored.

Copy link
Member Author

Choose a reason for hiding this comment

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

@turbolent Good point! 👍. I'll open separate PR for renaming to keep changes in this PR simple.

In addition, maybe we can also rename StorageID to SlabID to make it clearer that it just identifies a slab, and cannot always identify something that is stored.

I will rename both function and type name from StorageID to SlabID.

While at it, I will also rename related function and variable names such as StorageIndex to SlabIndex.

Given there are now multiple IDs in the package, it might make sense to make this name a bit more descriptive to reduce the likelihood of confusing it with another ID.

Maybe StorableID?

Actually, ID is only for Array and OrderedMap, which are Value (not Storable).

So maybe I can rename ID to ValueID. For example,

func (*Array) ValueID() ValueID {}
func (*Array) SlabID() SlabID {}

Thoughts?

Copy link
Contributor

@ramtinms ramtinms left a comment

Choose a reason for hiding this comment

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

Looks good to me

@fxamacker
Copy link
Member Author

Merging this and will open separate PR for suggested renaming (and other similar related renamings) to keep changes in this PR simple.

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

Successfully merging this pull request may close these issues.

Add Array.ID() and OrderedMap.ID()
4 participants