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.
If I put an empty bytes with StorageFlags.Constant flag, what will happen?
There was a problem hiding this comment.
The expected behaviour is: write nothing, read empty bytes
There was a problem hiding this comment.
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.
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.
igormcoelho
left a comment
There was a problem hiding this comment.
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.
If we could access here to TrackableItem, we can save the GetAndChange
There was a problem hiding this comment.
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.
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.
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