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

chore: all: use golang.org/x/exp/maps.(Keys, Values) where necessary #13349

Merged
merged 1 commit into from
Sep 21, 2022

Conversation

odeke-em
Copy link
Collaborator

@odeke-em odeke-em commented Sep 20, 2022

Uses golang.org/x/exp/maps.(Keys, Values) to sort out flagged
potential non-determinism issues due to map iteration which is
randomized in maps.

These were flagged by cosmos/gosec in

which complained about potential non-determinism in
map iteration in which we only want appends in map iteration loops,
this change instead uses golang.org/x/exp/maps.Keys to retrieve
the keys then sort.Strings which simplifies the helper code.

This change fixes issues in:

  • orm/model/ormdb: non-determinism in ExportJSON
  • store/internal/proofs
  • types/module
  • x/auth/keeper
  • x/bank
  • x/genutil/client/cli

Fixes #13348

@odeke-em odeke-em requested a review from a team as a code owner September 20, 2022 22:37
@codecov
Copy link

codecov bot commented Sep 20, 2022

Codecov Report

Merging #13349 (57d9f1f) into main (56a49ab) will increase coverage by 0.95%.
The diff coverage is 100.00%.

❗ Current head 57d9f1f differs from pull request most recent head b0885e2. Consider uploading reports for the commit b0885e2 to get more accurate results

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #13349      +/-   ##
==========================================
+ Coverage   54.84%   55.80%   +0.95%     
==========================================
  Files         652      697      +45     
  Lines       55859    60070    +4211     
==========================================
+ Hits        30638    33521    +2883     
- Misses      22738    23710     +972     
- Partials     2483     2839     +356     
Impacted Files Coverage Δ
orm/model/ormdb/json.go 64.51% <100.00%> (ø)
store/internal/proofs/helpers.go 100.00% <100.00%> (ø)
types/module/module.go 66.07% <100.00%> (-0.30%) ⬇️
x/auth/keeper/keeper.go 62.72% <100.00%> (+0.34%) ⬆️
x/bank/module.go 61.16% <100.00%> (+0.38%) ⬆️
x/genutil/client/cli/migrate.go 65.33% <100.00%> (-2.96%) ⬇️
x/distribution/simulation/operations.go 80.64% <0.00%> (-9.68%) ⬇️
orm/model/ormtable/backend.go 66.07% <0.00%> (ø)
orm/model/ormtable/singleton.go 46.96% <0.00%> (ø)
orm/model/ormtable/unique.go 44.09% <0.00%> (ø)
... and 43 more

@odeke-em odeke-em changed the title chore: store/internal/proofs: simplify SortedKeys with golang.org/x/exp/maps.Keys chore: all: use golang.org/x/exp/maps.Keys where necessary Sep 20, 2022
@odeke-em odeke-em force-pushed the store-internal-proofs-use-maps.Keys branch from 1b8ca64 to 50c8600 Compare September 20, 2022 22:50
@github-actions github-actions bot added C:CLI C:orm C:x/genutil genutil module issues labels Sep 20, 2022
@odeke-em odeke-em changed the title chore: all: use golang.org/x/exp/maps.Keys where necessary chore: all: use golang.org/x/exp/maps.(Keys, Values) where necessary Sep 20, 2022
@odeke-em odeke-em force-pushed the store-internal-proofs-use-maps.Keys branch from 50c8600 to 2cee5b8 Compare September 20, 2022 23:03
@julienrbrt
Copy link
Member

lgtm!

Uses golang.org/x/exp/maps.(Keys, Values) to sort out flagged
potential non-determinism issues due to map iteration which is
randomized in maps.

These were flagged by cosmos/gosec in

* https://github.com/cosmos/cosmos-sdk/security/code-scanning/724
* https://github.com/cosmos/cosmos-sdk/security/code-scanning/725
* https://github.com/cosmos/cosmos-sdk/security/code-scanning/726
* https://github.com/cosmos/cosmos-sdk/security/code-scanning/727
* https://github.com/cosmos/cosmos-sdk/security/code-scanning/728
* https://github.com/cosmos/cosmos-sdk/security/code-scanning/729
* https://github.com/cosmos/cosmos-sdk/security/code-scanning/782
* https://github.com/cosmos/cosmos-sdk/security/code-scanning/813
* https://github.com/cosmos/cosmos-sdk/security/code-scanning/814
* https://github.com/cosmos/cosmos-sdk/security/code-scanning/816

which complained about potential non-determinism in
map iteration in which we only want appends in map iteration loops,
this change instead uses golang.org/x/exp/maps.Keys to retrieve
the keys then sort.Strings which simplifies the helper code.

This change fixes issues in:
* orm/model/ormdb: non-determinism in ExportJSON
* store/internal/proofs
* types/module
* x/auth/keeper
* x/bank
* x/genutil/client/cli

Fixes #13348
@odeke-em odeke-em force-pushed the store-internal-proofs-use-maps.Keys branch from 57d9f1f to b0885e2 Compare September 21, 2022 01:52
@odeke-em odeke-em enabled auto-merge (squash) September 21, 2022 01:52
@odeke-em
Copy link
Collaborator Author

Thank you for the review @julienrbrt!

@odeke-em odeke-em merged commit 9c2aef3 into main Sep 21, 2022
@odeke-em odeke-em deleted the store-internal-proofs-use-maps.Keys branch September 21, 2022 02:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

store/internal/proofs: SortedKeys could simply use golang.org/x/exp/maps.Keys and sort.Strings
2 participants