-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Remove empty keys #825
Remove empty keys #825
Conversation
Codecov Report
@@ Coverage Diff @@
## master #825 +/- ##
=========================================
- Coverage 38.41% 38.4% -0.02%
=========================================
Files 176 176
Lines 12459 12463 +4
=========================================
Hits 4786 4786
- Misses 7673 7677 +4
Continue to review full report at Codecov.
|
neo/SmartContract/InteropService.cs
Outdated
// If is empty, we try to remove it | ||
|
||
engine.Snapshot.Storages.Delete(skey); | ||
return true; |
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.
If I put an empty bytes with StorageFlags.Constant
flag, what will happen?
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 expected behaviour is: write nothing, read empty bytes
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's an example use case for const
? I think you're right... logically speaking, if someone wants to keep a constant value, that value could be zero. So we need to keep it allow it to be unchanged in the future. We cannot pre-reap const empty values @shargon, because it may be part of contract logic, and perhaps be re-written in the future because we accidentally pre-dropped its "constness".
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.
Only explicit Delete
will destroy them, right @erikzhang ? I just noticed Delete
cannot reap const values too. So these are contract-lifetime values, correct? Only Contract.Destroy
or Migrate
can reap them.
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.
Looks good for me, a huge advance for NEP-5!
@shargon this will guarantee that value zero will always be converted to an empty array, thus, ripped out automatically 💪 |
Such a nice PR and quick, Shargon. |
@erikzhang I just noticed this will be useless for NEP5 Native Tokens, because each Key is being mapped to a TState object, not a BigInteger as I thought before... |
I think that i have an optimization |
item.Value = value; | ||
item.IsConstant = flags.HasFlag(StorageFlags.Constant); | ||
|
||
if (engine.Snapshot.Storages.TryGet(skey)?.IsConstant == true) return false; |
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.
If we could access here to TrackableItem, we can save the GetAndChange
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.
GetAndChange
here doesn't access the internal storage. It read from the cache because we call TryGet
before.
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.
But if we can know if the item has trackable.State = TrackState.Added;
we can avoid the two reads
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.
If it is TrackState.Added
, both the TryGet
and GetAndChange
calls read from the cache. These are all automatic.
* Close neo-project#824 * optimize * remove redundancy * simplified * allow const empty array * Update InteropService.cs * Update InteropService.cs
Close #824