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

Rework maps #818

Merged
merged 3 commits into from
Apr 1, 2020
Merged

Rework maps #818

merged 3 commits into from
Apr 1, 2020

Conversation

roman-khimov
Copy link
Member

Problem

#809 and unstable map serialization (neo-project/neo#1513).

Solution

This patchset allows us to proceed with mainnet dump up to #817.

Fixes #809.

Basically, there are three alternative approaches to fixing it:
 * allowing both []byte and string for ByteArrayType value
   minimal invasion into existing code, but ugly as hell and will probably
   backfire at some point
 * storing string values in ByteArrayType
   incurs quite a number of type conversions (and associated data copying),
   though note that these values are not changed usually, so dynamic
   properties of []byte are almost irrelevant here
 * storing only []byte values in ByteArrayType
   makes it impossible to use them as map keys which can be solved in several
   ways:
   - via an interface (Marshalable)
     which is good, but makes testing and comparing values in general harder,
     because of keys mismatch
   - using serialized Parameter as a key (in a string)
     which will need some additional marshaling/unmarshaling
   - converting MapType from map to a slice of key-value pairs
     not a bad idea as we don't use this map as a map really, the type
     itself is all about input/output for real VM types and this approach is
     also a bit closer to JSON representation of the Map
pkg/vm/stack_item.go Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Apr 1, 2020

Codecov Report

Merging #818 into master will increase coverage by <.01%.
The diff coverage is 94.44%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #818      +/-   ##
==========================================
+ Coverage   67.65%   67.66%   +<.01%     
==========================================
  Files         141      141              
  Lines       13205    13165      -40     
==========================================
- Hits         8934     8908      -26     
+ Misses       3859     3849      -10     
+ Partials      412      408       -4
Impacted Files Coverage Δ
pkg/core/interop_neo.go 59.11% <100%> (+0.07%) ⬆️
pkg/vm/stack.go 89.31% <100%> (+0.85%) ⬆️
pkg/vm/interop.go 90% <100%> (-0.33%) ⬇️
pkg/vm/serialization.go 95.29% <100%> (ø) ⬆️
pkg/vm/interop_iterators.go 95.23% <66.66%> (ø) ⬆️
pkg/vm/vm.go 77.99% <91.66%> (-0.03%) ⬇️
pkg/smartcontract/parameter.go 81.53% <93.75%> (+1.15%) ⬆️
pkg/vm/stack_item.go 96.84% <96.42%> (+0.67%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b502210...2d0ad30. Read the comment docs.

Which makes iterating over map stable which is important for serialization and
and even fixes occasional test failures. We use the same ordering here as
NEO 3.0 uses, but it should also be fine for NEO 2.0 because it has no
defined order.
@roman-khimov roman-khimov merged commit 20fcbda into master Apr 1, 2020
@roman-khimov roman-khimov deleted the rework-maps branch April 1, 2020 19:04
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.

4 participants