-
Notifications
You must be signed in to change notification settings - Fork 382
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(gnovm): load map from state #932
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Fix gnolang#817 There was actually 2 bugs in the code responsible for loading a map from the state: - `UnmarshalAmino` doesn't check that `ml.Tail` is nil before accessing it. It is correctly done for instance in `MapList.Append` for instance. The fix just ensures that `ml.Tail` is not nil. - `fillTypesOfValue` which is called just after the store data is unmarshalSized, resets the map data by calling `MapValue.MakeMap()`. So at the end the map is always empty, whatever was stored before the transaction. The fix replaces the call of `MakeMap` to a simple map creation. This has to be confirmed, but this change may also fix gnolang#311, because I'm not convinced that the indetermenistic behavior of the golang map can be a problem when saved to the store. Indeed, a gno map is serialized with the help of a slice, which should remove any indetermenistic problem.
moul
approved these changes
Jun 27, 2023
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.
Thank you, better than my own version of the same fix 👍
Can you update the docs/ folder which says that maps are temporarily not persisted? |
@tbruyelle confirmed #311 is fixed |
Doozers
pushed a commit
to Doozers/gno
that referenced
this pull request
Aug 31, 2023
thehowl
pushed a commit
that referenced
this pull request
Mar 4, 2024
<!-- please provide a detailed description of the changes made in this pull request. --> ```go package mapindex var mapus map[uint64]string = make(map[uint64]string) func init() { mapus[3] = "three" mapus[5] = "five" mapus[9] = "nine" } func FindMapWithKey(k uint64) string { return mapus[k] } ``` `println(mapus[5])` will return 'five' in test cases run by `gno test` which is expected HOWEVER, with deployed package ```bash $ gnokey maketx addpkg \ -remote 127.0.0.1:26657 \ -broadcast=true \ -chainid dev \ -gas-fee 1ugnot \ -gas-wanted 9000000 \ -memo "" \ -pkgdir ./ \ -pkgpath gno.land/r/demo/mapindex \ test1 ``` calling ```bash $ gnokey maketx call \ -remote 127.0.0.1:26657 \ -broadcast=true \ -chainid dev \ -gas-fee 1ugnot \ -gas-wanted 9000000 \ -memo "" \ -pkgpath gno.land/r/demo/mapindex \ -func FindMapWithKey \ -args "3" \ test1 ``` will return nothing for value, and 'string' for type ```bash $ gnokey maketx call \ -remote 127.0.0.1:26657 \ -broadcast=true \ -chainid dev \ -gas-fee 1ugnot \ -gas-wanted 9000000 \ -memo "" \ -pkgpath gno.land/r/demo/mapindex \ -func FindMapWithKey \ -args "3" \ test1 Enter password. ( string) OK! GAS WANTED: 9000000 GAS USED: 73301 ``` ## Related PR - [x] #932 @tbruyelle <details><summary>Contributors' checklist...</summary> - [x] Added new tests, or not needed, or not feasible - [x] Provided an example (e.g. screenshot) to aid review or the PR is self-explanatory - [x] Updated the official documentation or not needed - [x] No breaking changes were made, or a `BREAKING CHANGE: xxx` message was included in the description - [x] Added references to related issues and PRs - [ ] Provided any useful hints for running manual tests - [ ] Added new benchmarks to [generated graphs](https://gnoland.github.io/benchmarks), if any. More info [here](https://github.com/gnolang/gno/blob/master/.benchmarks/README.md). </details>
leohhhn
pushed a commit
to leohhhn/gno
that referenced
this pull request
Mar 6, 2024
<!-- please provide a detailed description of the changes made in this pull request. --> ```go package mapindex var mapus map[uint64]string = make(map[uint64]string) func init() { mapus[3] = "three" mapus[5] = "five" mapus[9] = "nine" } func FindMapWithKey(k uint64) string { return mapus[k] } ``` `println(mapus[5])` will return 'five' in test cases run by `gno test` which is expected HOWEVER, with deployed package ```bash $ gnokey maketx addpkg \ -remote 127.0.0.1:26657 \ -broadcast=true \ -chainid dev \ -gas-fee 1ugnot \ -gas-wanted 9000000 \ -memo "" \ -pkgdir ./ \ -pkgpath gno.land/r/demo/mapindex \ test1 ``` calling ```bash $ gnokey maketx call \ -remote 127.0.0.1:26657 \ -broadcast=true \ -chainid dev \ -gas-fee 1ugnot \ -gas-wanted 9000000 \ -memo "" \ -pkgpath gno.land/r/demo/mapindex \ -func FindMapWithKey \ -args "3" \ test1 ``` will return nothing for value, and 'string' for type ```bash $ gnokey maketx call \ -remote 127.0.0.1:26657 \ -broadcast=true \ -chainid dev \ -gas-fee 1ugnot \ -gas-wanted 9000000 \ -memo "" \ -pkgpath gno.land/r/demo/mapindex \ -func FindMapWithKey \ -args "3" \ test1 Enter password. ( string) OK! GAS WANTED: 9000000 GAS USED: 73301 ``` ## Related PR - [x] gnolang#932 @tbruyelle <details><summary>Contributors' checklist...</summary> - [x] Added new tests, or not needed, or not feasible - [x] Provided an example (e.g. screenshot) to aid review or the PR is self-explanatory - [x] Updated the official documentation or not needed - [x] No breaking changes were made, or a `BREAKING CHANGE: xxx` message was included in the description - [x] Added references to related issues and PRs - [ ] Provided any useful hints for running manual tests - [ ] Added new benchmarks to [generated graphs](https://gnoland.github.io/benchmarks), if any. More info [here](https://github.com/gnolang/gno/blob/master/.benchmarks/README.md). </details>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix #817
There was actually 2 bugs in the code responsible for loading a map from the state:
UnmarshalAmino
doesn't check thatml.Tail
is nil before accessing it. It is correctly done inMapList.Append
for instance. The fix just ensures thatml.Tail
is not nil.fillTypesOfValue
which is called just after the store data is unmarshalSized, resets the map data by callingMapValue.MakeMap()
. So at the end the map is always empty, whatever was stored before the transaction. The fix replaces the call ofMakeMap
to a simple map creation.This has to be confirmed, but this change may also fix #311, because I'm not convinced that the indetermenistic behavior of the golang map can be a problem when saved to the store. Indeed, a gno map is serialized with the help of a slice, which should remove any indetermenistic problem.
Contributors Checklist
BREAKING CHANGE: xxx
message was included in the descriptionMaintainers Checklist
CONTRIBUTING.md
BREAKING CHANGE:
in the body)