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

Problem: memiavl don't support CacheMultiStoreWithVersion #1114

Merged
merged 4 commits into from
Aug 9, 2023

Conversation

yihuang
Copy link
Collaborator

@yihuang yihuang commented Jul 28, 2023

CacheMultiStoreWithVersion is needed for grpc query service and cosmwasm snapshotting.

👮🏻👮🏻👮🏻 !!!! REFERENCE THE PROBLEM YOUR ARE SOLVING IN THE PR TITLE AND DESCRIBE YOUR SOLUTION HERE !!!! DO NOT FORGET !!!! 👮🏻👮🏻👮🏻

PR Checklist:

  • Have you read the CONTRIBUTING.md?
  • Does your PR follow the C4 patch requirements?
  • Have you rebased your work on top of the latest master?
  • Have you checked your code compiles? (make)
  • Have you included tests for any non-trivial functionality?
  • Have you checked your code passes the unit tests? (make test)
  • Have you checked your code formatting is correct? (go fmt)
  • Have you checked your basic code style is fine? (golangci-lint run)
  • If you added any dependencies, have you checked they do not contain any known vulnerabilities? (go list -json -m all | nancy sleuth)
  • If your changes affect the client infrastructure, have you run the integration test?
  • If your changes affect public APIs, does your PR follow the C4 evolution of public contracts?
  • If your code changes public APIs, have you incremented the crate version numbers and documented your changes in the CHANGELOG.md?
  • If you are contributing for the first time, please read the agreement in CONTRIBUTING.md now and add a comment to this pull request stating that your PR is in accordance with the Developer's Certificate of Origin.

Thank you for your code, it's appreciated! :)

`CacheMultiStoreWithVersion` is needed for grpc query service and cosmwasm snapshotting.
@yihuang yihuang requested a review from a team as a code owner July 28, 2023 02:45
@yihuang yihuang requested review from mmsqe and leejw51crypto and removed request for a team July 28, 2023 02:45
CHANGELOG.md Outdated Show resolved Hide resolved
Signed-off-by: yihuang <[email protected]>
Comment on lines +183 to +187
for k, store := range rs.stores {
if store.GetStoreType() != types.StoreTypeIAVL {
stores[k] = store
}
}

Check failure

Code scanning / gosec

the value in the range statement should be _ unless copying a map: want: for key := range m Error

the value in the range statement should be _ unless copying a map: want: for key := range m
return rs.CacheMultiStore(), nil
}
opts := rs.opts
opts.TargetVersion = uint32(version)

Check failure

Code scanning / gosec

Potential integer overflow by integer type conversion Error

Potential integer overflow by integer type conversion
Comment on lines +183 to +187
for k, store := range rs.stores {
if store.GetStoreType() != types.StoreTypeIAVL {
stores[k] = store
}
}

Check warning

Code scanning / CodeQL

Iteration over map Warning

Iteration over map may be a possible source of non-determinism
@codecov
Copy link

codecov bot commented Jul 28, 2023

Codecov Report

Merging #1114 (cdc8f69) into main (082feca) will decrease coverage by 0.03%.
The diff coverage is 80.64%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1114      +/-   ##
==========================================
- Coverage   46.16%   46.13%   -0.03%     
==========================================
  Files          82       82              
  Lines        7454     7456       +2     
==========================================
- Hits         3441     3440       -1     
- Misses       3648     3651       +3     
  Partials      365      365              
Files Changed Coverage Δ
memiavl/multitree.go 72.02% <79.31%> (-0.51%) ⬇️
memiavl/export.go 58.42% <100.00%> (ø)

... and 1 file with indirect coverage changes

Copy link

@yzang2019 yzang2019 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@yzang2019
Copy link

yzang2019 commented Jul 31, 2023

@yihuang After integrating this change with our chain, we are seeing some concurrent map writes error when exporting snapshot:

fatal error: concurrent map writes
goroutine 2889 [running]:
github.com/cosmos/iavl/cache.(*lruCache).Add(0xc0003f6240, {0x2a9fd40, 0xc004ae4630})
	/root/go/pkg/mod/github.com/sei-protocol/[email protected]/cache/cache.go:73 +0x2d0
github.com/sei-protocol/mmap-iavl/memiavl.(*Tree).Get(0xc00052c140, {0xc0039431c0, 0x19, 0x19})
	/root/go/pkg/mod/github.com/sei-protocol/[email protected]/memiavl/tree.go:215 +0x13b
github.com/sei-protocol/mmap-iavl/store/memiavlstore.(*Store).Get(0x41b223?, {0xc0039431c0?, 0xc0031c3580?, 0x20?})
	/root/go/pkg/mod/github.com/sei-protocol/[email protected]/store/memiavlstore/store.go:99 +0x25
github.com/cosmos/cosmos-sdk/store/cachekv.(*Store).Get(0xc00055ad80, {0xc0039431c0, 0x19, 0x19})
	/root/go/pkg/mod/github.com/sei-protocol/[email protected]/store/cachekv/store.go:116 +0x14b
github.com/cosmos/cosmos-sdk/store/cachekv.(*Store).Get(0xc003dbe720, {0xc0039431c0, 0x19, 0x19})
	/root/go/pkg/mod/github.com/sei-protocol/[email protected]/store/cachekv/store.go:116 +0x14b
github.com/cosmos/cosmos-sdk/store/gaskv.(*Store).Get(0xc005296120, {0xc0039431c0, 0x19, 0x19})
	/root/go/pkg/mod/github.com/sei-protocol/[email protected]/store/gaskv/store.go:43 +0x71
github.com/cosmos/cosmos-sdk/store/prefix.Store.Get({{0x2accf10, 0xc005296120}, {0xc0002a9340, 0x4, 0x20}}, {0x3b18b80, 0x15, 0x3?})
	/root/go/pkg/mod/github.com/sei-protocol/[email protected]/store/prefix/store.go:72 +0x10c
github.com/cosmos/cosmos-sdk/x/params/types.Subspace.Get({{0x2accdc0, 0xc0001b4c10}, 0xc0003fe3a8, {0x2aa5960, 0xc0006995a0}, {0x2aa59b0, 0xc000699670}, {0xc0002a9340, 0x3, 0x20}, ...}, ...)
	/root/go/pkg/mod/github.com/sei-protocol/[email protected]/x/params/types/subspace.go:106 +0x213
github.com/cosmos/cosmos-sdk/x/params/types.Subspace.GetParamSet({{0x2accdc0, 0xc0001b4c10}, 0xc0003fe3a8, {0x2aa5960, 0xc0006995a0}, {0x2aa59b0, 0xc000699670}, {0xc0002a9340, 0x3, 0x20}, ...}, ...)
	/root/go/pkg/mod/github.com/sei-protocol/[email protected]/x/params/types/subspace.go:222 +0x105
github.com/sei-protocol/sei-chain/x/dex/keeper.Keeper.GetParams(...)
	/sei-protocol/sei-chain/x/dex/keeper/params.go:11

Are you using a specific cosmos iavl version that has the concurrent write support?

@yihuang
Copy link
Collaborator Author

yihuang commented Aug 1, 2023

@yihuang After integrating this change with our chain, we are seeing some concurrent map writes error when exporting snapshot:


fatal error: concurrent map writes

goroutine 2889 [running]:

github.com/cosmos/iavl/cache.(*lruCache).Add(0xc0003f6240, {0x2a9fd40, 0xc004ae4630})

	/root/go/pkg/mod/github.com/sei-protocol/[email protected]/cache/cache.go:73 +0x2d0

github.com/sei-protocol/mmap-iavl/memiavl.(*Tree).Get(0xc00052c140, {0xc0039431c0, 0x19, 0x19})

	/root/go/pkg/mod/github.com/sei-protocol/[email protected]/memiavl/tree.go:215 +0x13b

github.com/sei-protocol/mmap-iavl/store/memiavlstore.(*Store).Get(0x41b223?, {0xc0039431c0?, 0xc0031c3580?, 0x20?})

	/root/go/pkg/mod/github.com/sei-protocol/[email protected]/store/memiavlstore/store.go:99 +0x25

github.com/cosmos/cosmos-sdk/store/cachekv.(*Store).Get(0xc00055ad80, {0xc0039431c0, 0x19, 0x19})

	/root/go/pkg/mod/github.com/sei-protocol/[email protected]/store/cachekv/store.go:116 +0x14b

github.com/cosmos/cosmos-sdk/store/cachekv.(*Store).Get(0xc003dbe720, {0xc0039431c0, 0x19, 0x19})

	/root/go/pkg/mod/github.com/sei-protocol/[email protected]/store/cachekv/store.go:116 +0x14b

github.com/cosmos/cosmos-sdk/store/gaskv.(*Store).Get(0xc005296120, {0xc0039431c0, 0x19, 0x19})

	/root/go/pkg/mod/github.com/sei-protocol/[email protected]/store/gaskv/store.go:43 +0x71

github.com/cosmos/cosmos-sdk/store/prefix.Store.Get({{0x2accf10, 0xc005296120}, {0xc0002a9340, 0x4, 0x20}}, {0x3b18b80, 0x15, 0x3?})

	/root/go/pkg/mod/github.com/sei-protocol/[email protected]/store/prefix/store.go:72 +0x10c

github.com/cosmos/cosmos-sdk/x/params/types.Subspace.Get({{0x2accdc0, 0xc0001b4c10}, 0xc0003fe3a8, {0x2aa5960, 0xc0006995a0}, {0x2aa59b0, 0xc000699670}, {0xc0002a9340, 0x3, 0x20}, ...}, ...)

	/root/go/pkg/mod/github.com/sei-protocol/[email protected]/x/params/types/subspace.go:106 +0x213

github.com/cosmos/cosmos-sdk/x/params/types.Subspace.GetParamSet({{0x2accdc0, 0xc0001b4c10}, 0xc0003fe3a8, {0x2aa5960, 0xc0006995a0}, {0x2aa59b0, 0xc000699670}, {0xc0002a9340, 0x3, 0x20}, ...}, ...)

	/root/go/pkg/mod/github.com/sei-protocol/[email protected]/x/params/types/subspace.go:222 +0x105

github.com/sei-protocol/sei-chain/x/dex/keeper.Keeper.GetParams(...)

	/sei-protocol/sei-chain/x/dex/keeper/params.go:11

Are you using a specific cosmos iavl version that has the concurrent write support?

There's a Copy method called before doing snapshotting, there should have no concurrency issue, don't you call snapshot from sdk? Or do you call directly?

@yihuang yihuang enabled auto-merge August 8, 2023 02:30
@yihuang yihuang added this pull request to the merge queue Aug 9, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Aug 9, 2023
@mmsqe mmsqe added this pull request to the merge queue Aug 9, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Aug 9, 2023
@yihuang yihuang added this pull request to the merge queue Aug 9, 2023
Merged via the queue into crypto-org-chain:main with commit af389f6 Aug 9, 2023
23 of 24 checks passed
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.

3 participants