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

fix: incorrect tracking of num instantiations #19

Closed
wants to merge 4 commits into from

Conversation

czarcas7ic
Copy link
Member

@czarcas7ic czarcas7ic commented Sep 16, 2023

Every time we instantiate a contract the classic way, we increment types.KeySequenceInstanceID: https://github.com/CosmWasm/wasmd/blob/e0bfaa52317a3d1f73bf26c5b9d61a777f63bd88/x/wasm/keeper/addresses.go#L17-L22
Every time we instantiate a contract with a predictable address (instantiate2), we do not increment this ID: https://github.com/CosmWasm/wasmd/blob/e0bfaa52317a3d1f73bf26c5b9d61a777f63bd88/x/wasm/keeper/addresses.go#L24-L32
In ImportGenesis, maxContractID takes into consideration ALL contracts: https://github.com/CosmWasm/wasmd/blob/e0bfaa52317a3d1f73bf26c5b9d61a777f63bd88/x/wasm/keeper/genesis.go#L45-L55
ImportGenesis expects the types.KeySequenceInstanceID to be greater than the number of contracts, but its not since we don’t always increment this value: https://github.com/CosmWasm/wasmd/blob/e0bfaa52317a3d1f73bf26c5b9d61a777f63bd88/x/wasm/keeper/genesis.go#L69-L72

This means that the discrepancy between the expected value and the actual value should be all contracts that were instantiated with predictable addresses.

This fix manually increments the KeyLastInstanceID to what we expect it to be. This way the check in InitGenesis passes. This also increments the KeyLastInstanceID on all instantiate2 calls. If chains manually set this key to the correct value in their upgrade handler, they can remove the manual setting of the KeyLastInstanceID in export genesis (but it's probably not a big deal if this isn't touched).

@alpe
Copy link

alpe commented Sep 18, 2023

Thanks for the PR. It would be great if you can share bug reports on wasmd repo so that we can address them upstream.

@alpe
Copy link

alpe commented Sep 18, 2023

Please see CosmWasm#1630

@czarcas7ic
Copy link
Member Author

@alpe I was actually intending to upstream this myself, we were just internally testing (and still are testing) this with state exported testnets prior to opening a PR!

@czarcas7ic czarcas7ic closed this Jul 27, 2024
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.

2 participants