fix: incorrect tracking of num instantiations #19
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.
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).