From 8ef2d2695b25bee933ae3470c60267bdcb43640c Mon Sep 17 00:00:00 2001 From: Alex Peters Date: Fri, 23 Apr 2021 13:28:52 +0200 Subject: [PATCH 1/3] Persist last code update with contract lookup index --- x/wasm/keeper/genesis_test.go | 33 ++++++++++++++++----------------- x/wasm/keeper/keeper.go | 33 ++++++++++++++++++++++++++++----- x/wasm/keeper/keeper_test.go | 17 +++++++++++++---- x/wasm/types/keys.go | 6 +++--- x/wasm/types/keys_test.go | 6 +++--- 5 files changed, 63 insertions(+), 32 deletions(-) diff --git a/x/wasm/keeper/genesis_test.go b/x/wasm/keeper/genesis_test.go index dca6e4735d..3fae7e4efc 100644 --- a/x/wasm/keeper/genesis_test.go +++ b/x/wasm/keeper/genesis_test.go @@ -6,6 +6,7 @@ import ( "encoding/base64" "errors" "fmt" + prefix2 "github.com/cosmos/cosmos-sdk/store/prefix" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" "io/ioutil" "math/rand" @@ -103,19 +104,27 @@ func TestGenesisExportImport(t *testing.T) { exportedGenesis, err := wasmKeeper.cdc.MarshalJSON(exportedState) require.NoError(t, err) - // reset ContractInfo in source DB for comparison with dest DB + // setup new instances + dstKeeper, dstCtx, dstStoreKeys := setupKeeper(t) + + // reset contract code index in source DB for comparison with dest DB wasmKeeper.IterateContractInfo(srcCtx, func(address sdk.AccAddress, info wasmTypes.ContractInfo) bool { - wasmKeeper.deleteContractSecondIndex(srcCtx, address, &info) - info.ResetFromGenesis(srcCtx) - wasmKeeper.storeContractInfo(srcCtx, address, &info) + wasmKeeper.removeFromContractCodeSecondaryIndex(srcCtx, address, wasmKeeper.getLastContractHistoryEntry(srcCtx, address)) + prefix := prefix2.NewStore(srcCtx.KVStore(wasmKeeper.storeKey), types.GetContractCodeHistoryElementPrefix(address)) + for iter := prefix.Iterator(nil, nil); iter.Valid(); iter.Next() { + prefix.Delete(iter.Key()) + } + x := &info + newHistory := x.ResetFromGenesis(dstCtx) + wasmKeeper.storeContractInfo(srcCtx, address, x) + wasmKeeper.addToContractCodeSecondaryIndex(srcCtx, address, newHistory) + wasmKeeper.appendToContractHistory(srcCtx, address, newHistory) return false }) // re-import - dstKeeper, dstCtx, dstStoreKeys := setupKeeper(t) - var importState wasmTypes.GenesisState - err = wasmKeeper.cdc.UnmarshalJSON(exportedGenesis, &importState) + err = dstKeeper.cdc.UnmarshalJSON(exportedGenesis, &importState) require.NoError(t, err) InitGenesis(dstCtx, dstKeeper, importState, &StakingKeeperMock{}, TestHandler(contractKeeper)) @@ -125,16 +134,6 @@ func TestGenesisExportImport(t *testing.T) { dstIT := dstCtx.KVStore(dstStoreKeys[j]).Iterator(nil, nil) for i := 0; srcIT.Valid(); i++ { - isContractHistory := srcStoreKeys[j].Name() == types.StoreKey && bytes.HasPrefix(srcIT.Key(), types.ContractCodeHistoryElementPrefix) - if isContractHistory { - // only skip history entries because we know they are different - // from genesis they are merged into 1 single entry - srcIT.Next() - if bytes.HasPrefix(dstIT.Key(), types.ContractCodeHistoryElementPrefix) { - dstIT.Next() - } - continue - } require.True(t, dstIT.Valid(), "[%s] destination DB has less elements than source. Missing: %x", srcStoreKeys[j].Name(), srcIT.Key()) require.Equal(t, srcIT.Key(), dstIT.Key(), i) require.Equal(t, srcIT.Value(), dstIT.Value(), "[%s] element (%d): %X", srcStoreKeys[j].Name(), i, srcIT.Key()) diff --git a/x/wasm/keeper/keeper.go b/x/wasm/keeper/keeper.go index 6c1117309d..3d7766c00f 100644 --- a/x/wasm/keeper/keeper.go +++ b/x/wasm/keeper/keeper.go @@ -296,8 +296,10 @@ func (k Keeper) instantiate(ctx sdk.Context, codeID uint64, creator, admin sdk.A } // store contract before dispatch so that contract could be called back + historyEntry := contractInfo.InitialHistory(initMsg) + k.addToContractCodeSecondaryIndex(ctx, contractAddress, historyEntry) + k.appendToContractHistory(ctx, contractAddress, historyEntry) k.storeContractInfo(ctx, contractAddress, &contractInfo) - k.appendToContractHistory(ctx, contractAddress, contractInfo.InitialHistory(initMsg)) // dispatch submessages then messages err = k.dispatchAll(ctx, contractAddress, contractInfo.IBCPortID, res.Submessages, res.Messages) @@ -408,10 +410,11 @@ func (k Keeper) migrate(ctx sdk.Context, contractAddress sdk.AccAddress, caller ctx.EventManager().EmitEvents(events) // delete old secondary index entry - k.deleteContractSecondIndex(ctx, contractAddress, contractInfo) + k.removeFromContractCodeSecondaryIndex(ctx, contractAddress, k.getLastContractHistoryEntry(ctx, contractAddress)) // persist migration updates historyEntry := contractInfo.AddMigration(ctx, newCodeID, msg) k.appendToContractHistory(ctx, contractAddress, historyEntry) + k.addToContractCodeSecondaryIndex(ctx, contractAddress, historyEntry) k.storeContractInfo(ctx, contractAddress, contractInfo) // dispatch submessages then messages @@ -507,8 +510,15 @@ func (k Keeper) reply(ctx sdk.Context, contractAddress sdk.AccAddress, reply was }, nil } -func (k Keeper) deleteContractSecondIndex(ctx sdk.Context, contractAddress sdk.AccAddress, contractInfo *types.ContractInfo) { - ctx.KVStore(k.storeKey).Delete(types.GetContractByCreatedSecondaryIndexKey(contractAddress, contractInfo)) +// addToContractCodeSecondaryIndex adds element to the index for contracts-by-codeid queries +func (k Keeper) addToContractCodeSecondaryIndex(ctx sdk.Context, contractAddress sdk.AccAddress, entry types.ContractCodeHistoryEntry) { + store := ctx.KVStore(k.storeKey) + store.Set(types.GetContractByCreatedSecondaryIndexKey(contractAddress, entry), []byte{}) +} + +// removeFromContractCodeSecondaryIndex removes element to the index for contracts-by-codeid queries +func (k Keeper) removeFromContractCodeSecondaryIndex(ctx sdk.Context, contractAddress sdk.AccAddress, entry types.ContractCodeHistoryEntry) { + ctx.KVStore(k.storeKey).Delete(types.GetContractByCreatedSecondaryIndexKey(contractAddress, entry)) } func (k Keeper) setContractAdmin(ctx sdk.Context, contractAddress, caller, newAdmin sdk.AccAddress, authZ AuthorizationPolicy) error { @@ -552,6 +562,18 @@ func (k Keeper) GetContractHistory(ctx sdk.Context, contractAddr sdk.AccAddress) return r } +func (k Keeper) getLastContractHistoryEntry(ctx sdk.Context, contractAddr sdk.AccAddress) types.ContractCodeHistoryEntry { + prefixStore := prefix.NewStore(ctx.KVStore(k.storeKey), types.GetContractCodeHistoryElementPrefix(contractAddr)) + iter := prefixStore.ReverseIterator(nil, nil) + var r types.ContractCodeHistoryEntry + if !iter.Valid() { + // all contracts have a history + panic(fmt.Sprintf("no history for %s", contractAddr.String())) + } + k.cdc.MustUnmarshalBinaryBare(iter.Value(), &r) + return r +} + // QuerySmart queries the smart contract itself. func (k Keeper) QuerySmart(ctx sdk.Context, contractAddr sdk.AccAddress, req []byte) ([]byte, error) { defer telemetry.MeasureSince(time.Now(), "wasm", "contract", "query-smart") @@ -623,10 +645,10 @@ func (k Keeper) HasContractInfo(ctx sdk.Context, contractAddress sdk.AccAddress) return store.Has(types.GetContractAddressKey(contractAddress)) } +// storeContractInfo persists the ContractInfo. No secondary index updated here. func (k Keeper) storeContractInfo(ctx sdk.Context, contractAddress sdk.AccAddress, contract *types.ContractInfo) { store := ctx.KVStore(k.storeKey) store.Set(types.GetContractAddressKey(contractAddress), k.cdc.MustMarshalBinaryBare(contract)) - store.Set(types.GetContractByCreatedSecondaryIndexKey(contractAddress, contract), []byte{}) } func (k Keeper) IterateContractInfo(ctx sdk.Context, cb func(sdk.AccAddress, types.ContractInfo) bool) { @@ -1003,6 +1025,7 @@ func (k Keeper) importContract(ctx sdk.Context, contractAddr sdk.AccAddress, c * historyEntry := c.ResetFromGenesis(ctx) k.appendToContractHistory(ctx, contractAddr, historyEntry) k.storeContractInfo(ctx, contractAddr, c) + k.addToContractCodeSecondaryIndex(ctx, contractAddr, historyEntry) return k.importContractState(ctx, contractAddr, state) } diff --git a/x/wasm/keeper/keeper_test.go b/x/wasm/keeper/keeper_test.go index 65844fec6e..0ea3dd0438 100644 --- a/x/wasm/keeper/keeper_test.go +++ b/x/wasm/keeper/keeper_test.go @@ -950,20 +950,29 @@ func TestMigrateReplacesTheSecondIndex(t *testing.T) { store := ctx.KVStore(keepers.WasmKeeper.storeKey) oldContractInfo := keepers.WasmKeeper.GetContractInfo(ctx, example.Contract) require.NotNil(t, oldContractInfo) - exists := store.Has(types.GetContractByCreatedSecondaryIndexKey(example.Contract, oldContractInfo)) + createHistoryEntry := types.ContractCodeHistoryEntry{ + CodeID: example.CodeID, + Updated: types.NewAbsoluteTxPosition(ctx), + } + exists := store.Has(types.GetContractByCreatedSecondaryIndexKey(example.Contract, createHistoryEntry)) require.True(t, exists) + ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1) // increment for different block // when do migrate newCodeExample := StoreBurnerExampleContract(t, ctx, keepers) migMsgBz := BurnerExampleInitMsg{Payout: example.CreatorAddr}.GetBytes(t) _, err := keepers.ContractKeeper.Migrate(ctx, example.Contract, example.CreatorAddr, newCodeExample.CodeID, migMsgBz) require.NoError(t, err) + // then the new index exists - newContractInfo := keepers.WasmKeeper.GetContractInfo(ctx, example.Contract) - exists = store.Has(types.GetContractByCreatedSecondaryIndexKey(example.Contract, newContractInfo)) + migrateHistoryEntry := types.ContractCodeHistoryEntry{ + CodeID: newCodeExample.CodeID, + Updated: types.NewAbsoluteTxPosition(ctx), + } + exists = store.Has(types.GetContractByCreatedSecondaryIndexKey(example.Contract, migrateHistoryEntry)) require.True(t, exists) // and the old index was removed - exists = store.Has(types.GetContractByCreatedSecondaryIndexKey(example.Contract, oldContractInfo)) + exists = store.Has(types.GetContractByCreatedSecondaryIndexKey(example.Contract, createHistoryEntry)) require.False(t, exists) } diff --git a/x/wasm/types/keys.go b/x/wasm/types/keys.go index ff9bcb68a8..310034ca77 100644 --- a/x/wasm/types/keys.go +++ b/x/wasm/types/keys.go @@ -52,13 +52,13 @@ func GetContractStorePrefix(addr sdk.AccAddress) []byte { } // GetContractByCreatedSecondaryIndexKey returns the key for the secondary index: -// `` -func GetContractByCreatedSecondaryIndexKey(contractAddr sdk.AccAddress, c *ContractInfo) []byte { +// `` +func GetContractByCreatedSecondaryIndexKey(contractAddr sdk.AccAddress, c ContractCodeHistoryEntry) []byte { prefix := GetContractByCodeIDSecondaryIndexPrefix(c.CodeID) prefixLen := len(prefix) r := make([]byte, prefixLen+AbsoluteTxPositionLen+sdk.AddrLen) copy(r[0:], prefix) - copy(r[prefixLen:], c.Created.Bytes()) + copy(r[prefixLen:], c.Updated.Bytes()) copy(r[prefixLen+AbsoluteTxPositionLen:], contractAddr) return r } diff --git a/x/wasm/types/keys_test.go b/x/wasm/types/keys_test.go index 2d12aef6f8..95ef74ff16 100644 --- a/x/wasm/types/keys_test.go +++ b/x/wasm/types/keys_test.go @@ -29,12 +29,12 @@ func TestGetContractByCodeIDSecondaryIndexPrefix(t *testing.T) { } func TestGetContractByCreatedSecondaryIndexKey(t *testing.T) { - c := &ContractInfo{ + e := ContractCodeHistoryEntry{ CodeID: 1, - Created: &AbsoluteTxPosition{2 + 1<<(8*7), 3 + 1<<(8*7)}, + Updated: &AbsoluteTxPosition{2 + 1<<(8*7), 3 + 1<<(8*7)}, } addr := bytes.Repeat([]byte{4}, sdk.AddrLen) - got := GetContractByCreatedSecondaryIndexKey(addr, c) + got := GetContractByCreatedSecondaryIndexKey(addr, e) exp := []byte{6, // prefix 0, 0, 0, 0, 0, 0, 0, 1, // codeID 1, 0, 0, 0, 0, 0, 0, 2, // height From c377d7110e3d97ce2a660068420154c83efe954f Mon Sep 17 00:00:00 2001 From: Alex Peters Date: Fri, 23 Apr 2021 15:07:33 +0200 Subject: [PATCH 2/3] List contract address without other data --- contrib/local/02-contracts.sh | 2 +- contrib/local/03-grpc-queries.sh | 16 +- docs/proto/proto-docs.md | 20 +- proto/cosmwasm/wasm/v1beta1/query.proto | 17 +- x/wasm/alias.go | 1 - x/wasm/keeper/genesis_test.go | 21 +- x/wasm/keeper/keeper.go | 12 + x/wasm/keeper/keeper_test.go | 41 +++ x/wasm/keeper/legacy_querier.go | 40 +-- x/wasm/keeper/legacy_querier_test.go | 9 +- x/wasm/keeper/querier.go | 28 +- x/wasm/keeper/querier_test.go | 13 +- x/wasm/keeper/wasmtesting/mock_engine.go | 10 +- x/wasm/module_test.go | 10 +- x/wasm/types/exported_keepers.go | 1 + x/wasm/types/query.pb.go | 438 +++++------------------ 16 files changed, 212 insertions(+), 467 deletions(-) diff --git a/contrib/local/02-contracts.sh b/contrib/local/02-contracts.sh index f95c41bf3b..ccb5eb40f1 100755 --- a/contrib/local/02-contracts.sh +++ b/contrib/local/02-contracts.sh @@ -25,7 +25,7 @@ wasmd tx wasm instantiate "$CODE_ID" "$INIT" --admin=$(wasmd keys show validator --from validator --amount="100ustake" --label "local0.1.0" \ --gas 1000000 -y --chain-id=testing -b block | jq -CONTRACT=$(wasmd query wasm list-contract-by-code "$CODE_ID" -o json | jq -r '.contract_infos[-1].address') +CONTRACT=$(wasmd query wasm list-contract-by-code "$CODE_ID" -o json | jq -r '.contracts[-1]') echo "* Contract address: $CONTRACT" echo "### Query all" RESP=$(wasmd query wasm contract-state all "$CONTRACT" -o json) diff --git a/contrib/local/03-grpc-queries.sh b/contrib/local/03-grpc-queries.sh index 94ea59983f..bca10cb05d 100755 --- a/contrib/local/03-grpc-queries.sh +++ b/contrib/local/03-grpc-queries.sh @@ -4,26 +4,28 @@ set -o errexit -o nounset -o pipefail DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)" echo "-----------------------" -COSMOS_SDK_DIR=${COSMOS_SDK_DIR:-$(go list -f "{{ .Dir }}" -m github.com/cosmos/cosmos-sdk)} +PROTO_THRD="$DIR/../../third_party/proto" +PROTO_WASMD="$DIR/../../proto" +PROTO_WASMD_QUERY="$PROTO_WASMD/cosmwasm/wasm/v1beta1/query.proto" echo "### List all codes" -RESP=$(grpcurl -plaintext -import-path $COSMOS_SDK_DIR/third_party/proto -import-path $COSMOS_SDK_DIR/proto -import-path . -proto ./x/wasm/types/query.proto \ +RESP=$(grpcurl -plaintext -import-path $PROTO_THRD -import-path $PROTO_WASMD -proto $PROTO_WASMD_QUERY \ localhost:9090 cosmwasm.wasm.v1beta1.Query/Codes) echo "$RESP" | jq CODE_ID=$(echo "$RESP" | jq -r '.codeInfos[-1].codeId') -echo "### List contract by code" -RESP=$(grpcurl -plaintext -import-path $COSMOS_SDK_DIR/third_party/proto -import-path $COSMOS_SDK_DIR/proto -import-path . -proto ./x/wasm/types/query.proto \ +echo "### List contracts by code" +RESP=$(grpcurl -plaintext -import-path $PROTO_THRD -import-path $PROTO_WASMD -proto $PROTO_WASMD_QUERY \ -d "{\"codeId\": $CODE_ID}" localhost:9090 cosmwasm.wasm.v1beta1.Query/ContractsByCode ) echo $RESP | jq echo "### Show history for contract" -CONTRACT=$(echo $RESP | jq -r ".contractInfos[-1].address") -grpcurl -plaintext -import-path $COSMOS_SDK_DIR/third_party/proto -import-path $COSMOS_SDK_DIR/proto -import-path . -proto ./x/wasm/types/query.proto \ +CONTRACT=$(echo $RESP | jq -r ".contracts[-1]") +grpcurl -plaintext -import-path $PROTO_THRD -import-path $PROTO_WASMD -proto $PROTO_WASMD_QUERY \ -d "{\"address\": \"$CONTRACT\"}" localhost:9090 cosmwasm.wasm.v1beta1.Query/ContractHistory | jq echo "### Show contract state" -grpcurl -plaintext -import-path $COSMOS_SDK_DIR/third_party/proto -import-path $COSMOS_SDK_DIR/proto -import-path . -proto ./x/wasm/types/query.proto \ +grpcurl -plaintext -import-path $PROTO_THRD -import-path $PROTO_WASMD -proto $PROTO_WASMD_QUERY \ -d "{\"address\": \"$CONTRACT\"}" localhost:9090 cosmwasm.wasm.v1beta1.Query/AllContractState | jq echo "Empty state due to 'burner' contract cleanup" diff --git a/docs/proto/proto-docs.md b/docs/proto/proto-docs.md index 16c4196174..7235179730 100644 --- a/docs/proto/proto-docs.md +++ b/docs/proto/proto-docs.md @@ -55,7 +55,6 @@ - [cosmwasm/wasm/v1beta1/query.proto](#cosmwasm/wasm/v1beta1/query.proto) - [CodeInfoResponse](#cosmwasm.wasm.v1beta1.CodeInfoResponse) - - [ContractInfoWithAddress](#cosmwasm.wasm.v1beta1.ContractInfoWithAddress) - [QueryAllContractStateRequest](#cosmwasm.wasm.v1beta1.QueryAllContractStateRequest) - [QueryAllContractStateResponse](#cosmwasm.wasm.v1beta1.QueryAllContractStateResponse) - [QueryCodeRequest](#cosmwasm.wasm.v1beta1.QueryCodeRequest) @@ -814,23 +813,6 @@ CodeInfoResponse contains code meta data from CodeInfo - - -### ContractInfoWithAddress -ContractInfoWithAddress adds the address (key) to the ContractInfo -representation - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `address` | [string](#string) | | | -| `contract_info` | [ContractInfo](#cosmwasm.wasm.v1beta1.ContractInfo) | | | - - - - - - ### QueryAllContractStateRequest @@ -1020,7 +1002,7 @@ Query/ContractsByCode RPC method | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `contract_infos` | [ContractInfoWithAddress](#cosmwasm.wasm.v1beta1.ContractInfoWithAddress) | repeated | | +| `contracts` | [string](#string) | repeated | contracts are a set of contract addresses | | `pagination` | [cosmos.base.query.v1beta1.PageResponse](#cosmos.base.query.v1beta1.PageResponse) | | pagination defines the pagination in the response. | diff --git a/proto/cosmwasm/wasm/v1beta1/query.proto b/proto/cosmwasm/wasm/v1beta1/query.proto index cd91c7ffb3..3f96cc68f1 100644 --- a/proto/cosmwasm/wasm/v1beta1/query.proto +++ b/proto/cosmwasm/wasm/v1beta1/query.proto @@ -100,23 +100,12 @@ message QueryContractsByCodeRequest { cosmos.base.query.v1beta1.PageRequest pagination = 2; } -// ContractInfoWithAddress adds the address (key) to the ContractInfo -// representation -message ContractInfoWithAddress { - option (gogoproto.equal) = true; - - string address = 1; - ContractInfo contract_info = 2 [ - (gogoproto.embed) = true, - (gogoproto.nullable) = false, - (gogoproto.jsontag) = "" - ]; -} // QueryContractsByCodeResponse is the response type for the // Query/ContractsByCode RPC method message QueryContractsByCodeResponse { - repeated ContractInfoWithAddress contract_infos = 1 - [ (gogoproto.nullable) = false ]; + // contracts are a set of contract addresses + repeated string contracts = 1; + // pagination defines the pagination in the response. cosmos.base.query.v1beta1.PageResponse pagination = 2; } diff --git a/x/wasm/alias.go b/x/wasm/alias.go index 59ff271023..82573fa2fa 100644 --- a/x/wasm/alias.go +++ b/x/wasm/alias.go @@ -125,7 +125,6 @@ type ( ContractInfo = types.ContractInfo CreatedAt = types.AbsoluteTxPosition Config = types.WasmConfig - ContractInfoWithAddress = types.ContractInfoWithAddress CodeInfoResponse = types.CodeInfoResponse MessageHandler = keeper.SDKMessageHandler BankEncoder = keeper.BankEncoder diff --git a/x/wasm/keeper/genesis_test.go b/x/wasm/keeper/genesis_test.go index 3fae7e4efc..23a48d4953 100644 --- a/x/wasm/keeper/genesis_test.go +++ b/x/wasm/keeper/genesis_test.go @@ -6,20 +6,14 @@ import ( "encoding/base64" "errors" "fmt" - prefix2 "github.com/cosmos/cosmos-sdk/store/prefix" - govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" - "io/ioutil" - "math/rand" - "os" - "testing" - "time" - "github.com/CosmWasm/wasmd/x/wasm/types" wasmTypes "github.com/CosmWasm/wasmd/x/wasm/types" "github.com/cosmos/cosmos-sdk/store" + "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" distributionkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" @@ -31,6 +25,11 @@ import ( "github.com/tendermint/tendermint/proto/tendermint/crypto" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" dbm "github.com/tendermint/tm-db" + "io/ioutil" + "math/rand" + "os" + "testing" + "time" ) const firstCodeID = 1 @@ -110,9 +109,9 @@ func TestGenesisExportImport(t *testing.T) { // reset contract code index in source DB for comparison with dest DB wasmKeeper.IterateContractInfo(srcCtx, func(address sdk.AccAddress, info wasmTypes.ContractInfo) bool { wasmKeeper.removeFromContractCodeSecondaryIndex(srcCtx, address, wasmKeeper.getLastContractHistoryEntry(srcCtx, address)) - prefix := prefix2.NewStore(srcCtx.KVStore(wasmKeeper.storeKey), types.GetContractCodeHistoryElementPrefix(address)) - for iter := prefix.Iterator(nil, nil); iter.Valid(); iter.Next() { - prefix.Delete(iter.Key()) + prefixStore := prefix.NewStore(srcCtx.KVStore(wasmKeeper.storeKey), types.GetContractCodeHistoryElementPrefix(address)) + for iter := prefixStore.Iterator(nil, nil); iter.Valid(); iter.Next() { + prefixStore.Delete(iter.Key()) } x := &info newHistory := x.ResetFromGenesis(dstCtx) diff --git a/x/wasm/keeper/keeper.go b/x/wasm/keeper/keeper.go index 3d7766c00f..9dcc4c4bc9 100644 --- a/x/wasm/keeper/keeper.go +++ b/x/wasm/keeper/keeper.go @@ -521,6 +521,17 @@ func (k Keeper) removeFromContractCodeSecondaryIndex(ctx sdk.Context, contractAd ctx.KVStore(k.storeKey).Delete(types.GetContractByCreatedSecondaryIndexKey(contractAddress, entry)) } +// IterateContractsByCode iterates over all contracts with given codeID ASC on code update time. +func (k Keeper) IterateContractsByCode(ctx sdk.Context, codeID uint64, cb func(address sdk.AccAddress) bool) { + prefixStore := prefix.NewStore(ctx.KVStore(k.storeKey), types.GetContractByCodeIDSecondaryIndexPrefix(codeID)) + for iter := prefixStore.Iterator(nil, nil); iter.Valid(); iter.Next() { + key := iter.Key() + if cb(key[types.AbsoluteTxPositionLen:]) { + return + } + } +} + func (k Keeper) setContractAdmin(ctx sdk.Context, contractAddress, caller, newAdmin sdk.AccAddress, authZ AuthorizationPolicy) error { contractInfo := k.GetContractInfo(ctx, contractAddress) if contractInfo == nil { @@ -562,6 +573,7 @@ func (k Keeper) GetContractHistory(ctx sdk.Context, contractAddr sdk.AccAddress) return r } +// getLastContractHistoryEntry returns the last element from history. To be used internally only as it panics when none exists func (k Keeper) getLastContractHistoryEntry(ctx sdk.Context, contractAddr sdk.AccAddress) types.ContractCodeHistoryEntry { prefixStore := prefix.NewStore(ctx.KVStore(k.storeKey), types.GetContractCodeHistoryElementPrefix(contractAddr)) iter := prefixStore.ReverseIterator(nil, nil) diff --git a/x/wasm/keeper/keeper_test.go b/x/wasm/keeper/keeper_test.go index 0ea3dd0438..4b5607f7bd 100644 --- a/x/wasm/keeper/keeper_test.go +++ b/x/wasm/keeper/keeper_test.go @@ -1055,6 +1055,47 @@ func TestMigrateWithDispatchedMessage(t *testing.T) { assert.Equal(t, deposit, balance) } +func TestIterateContractsByCode(t *testing.T) { + ctx, keepers := CreateTestInput(t, false, SupportedFeatures) + k, c := keepers.WasmKeeper, keepers.ContractKeeper + example1 := InstantiateHackatomExampleContract(t, ctx, keepers) + ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1) + example2 := InstantiateIBCReflectContract(t, ctx, keepers) + ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1) + initMsg := HackatomExampleInitMsg{ + Verifier: RandomAccountAddress(t), + Beneficiary: RandomAccountAddress(t), + }.GetBytes(t) + contractAddr3, _, err := c.Instantiate(ctx, example1.CodeID, example1.CreatorAddr, nil, initMsg, "foo", nil) + require.NoError(t, err) + specs := map[string]struct { + codeID uint64 + exp []sdk.AccAddress + }{ + "multiple results": { + codeID: example1.CodeID, + exp: []sdk.AccAddress{example1.Contract, contractAddr3}, + }, + "single results": { + codeID: example2.CodeID, + exp: []sdk.AccAddress{example2.Contract}, + }, + "empty results": { + codeID: 99999, + }, + } + for name, spec := range specs { + t.Run(name, func(t *testing.T) { + var gotAddr []sdk.AccAddress + k.IterateContractsByCode(ctx, spec.codeID, func(address sdk.AccAddress) bool { + gotAddr = append(gotAddr, address) + return false + }) + assert.Equal(t, spec.exp, gotAddr) + }) + } +} + type sudoMsg struct { // This is a tongue-in-check demo command. This is not the intended purpose of Sudo. // Here we show that some priviledged Go module can make a call that should never be exposed diff --git a/x/wasm/keeper/legacy_querier.go b/x/wasm/keeper/legacy_querier.go index 5afde39479..f5d24a1993 100644 --- a/x/wasm/keeper/legacy_querier.go +++ b/x/wasm/keeper/legacy_querier.go @@ -2,15 +2,12 @@ package keeper import ( "encoding/json" - "reflect" - "sort" - "strconv" - "strings" - "github.com/CosmWasm/wasmd/x/wasm/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" abci "github.com/tendermint/tendermint/abci/types" + "reflect" + "strconv" ) const ( @@ -47,7 +44,7 @@ func NewLegacyQuerier(keeper types.ViewKeeper, gasLimit sdk.Gas) sdk.Querier { if err != nil { return nil, sdkerrors.Wrapf(types.ErrInvalid, "code id: %s", err.Error()) } - rsp, err = queryContractListByCode(ctx, codeID, keeper) + rsp = queryContractListByCode(ctx, codeID, keeper) case QueryGetContractState: if len(path) < 3 { return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, "unknown data query endpoint") @@ -145,32 +142,11 @@ func queryContractHistory(ctx sdk.Context, contractAddr sdk.AccAddress, keeper t return history, nil } -func queryContractListByCode(ctx sdk.Context, codeID uint64, keeper types.ViewKeeper) ([]types.ContractInfoWithAddress, error) { - var contracts []types.ContractInfoWithAddress - keeper.IterateContractInfo(ctx, func(addr sdk.AccAddress, info types.ContractInfo) bool { - if info.CodeID == codeID { - // and add the address - infoWithAddress := types.ContractInfoWithAddress{ - Address: addr.String(), - ContractInfo: info, - } - contracts = append(contracts, infoWithAddress) - } +func queryContractListByCode(ctx sdk.Context, codeID uint64, keeper types.ViewKeeper) []string { + var contracts []string + keeper.IterateContractsByCode(ctx, codeID, func(addr sdk.AccAddress) bool { + contracts = append(contracts, addr.String()) return false }) - - // now we sort them by AbsoluteTxPosition - sort.Slice(contracts, func(i, j int) bool { - this := contracts[i].ContractInfo.Created - other := contracts[j].ContractInfo.Created - if this.Equal(other) { - return strings.Compare(contracts[i].Address, contracts[j].Address) < 0 - } - return this.LessThan(other) - }) - - for i := range contracts { - contracts[i].Created = nil - } - return contracts, nil + return contracts } diff --git a/x/wasm/keeper/legacy_querier_test.go b/x/wasm/keeper/legacy_querier_test.go index 7c366c2672..0699eebc3a 100644 --- a/x/wasm/keeper/legacy_querier_test.go +++ b/x/wasm/keeper/legacy_querier_test.go @@ -205,17 +205,14 @@ func TestLegacyQueryContractListByCodeOrdering(t *testing.T) { res, err := q(ctx, query, data) require.NoError(t, err) - var contracts []map[string]interface{} + var contracts []string err = json.Unmarshal(res, &contracts) require.NoError(t, err) require.Equal(t, 10, len(contracts)) - for i, contract := range contracts { - assert.Equal(t, fmt.Sprintf("contract %d", i), contract["label"]) - assert.NotEmpty(t, contract["address"]) - // ensure these are not shown - assert.Nil(t, contract["created"]) + for _, contract := range contracts { + assert.NotEmpty(t, contract) } } diff --git a/x/wasm/keeper/querier.go b/x/wasm/keeper/querier.go index cbca1be29c..0901c4448f 100644 --- a/x/wasm/keeper/querier.go +++ b/x/wasm/keeper/querier.go @@ -43,10 +43,7 @@ func (q grpcQuerier) ContractInfo(c context.Context, req *types.QueryContractInf case rsp == nil: return nil, types.ErrNotFound } - return &types.QueryContractInfoResponse{ - Address: rsp.Address, - ContractInfo: rsp.ContractInfo, - }, nil + return rsp, nil } func (q grpcQuerier) ContractHistory(c context.Context, req *types.QueryContractHistoryRequest) (*types.QueryContractHistoryResponse, error) { @@ -82,6 +79,7 @@ func (q grpcQuerier) ContractHistory(c context.Context, req *types.QueryContract }, nil } +// ContractsByCode lists all smart contracts for a code id func (q grpcQuerier) ContractsByCode(c context.Context, req *types.QueryContractsByCodeRequest) (*types.QueryContractsByCodeResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "empty request") @@ -90,21 +88,13 @@ func (q grpcQuerier) ContractsByCode(c context.Context, req *types.QueryContract return nil, sdkerrors.Wrap(types.ErrInvalid, "code id") } ctx := sdk.UnwrapSDKContext(c) - r := make([]types.ContractInfoWithAddress, 0) + r := make([]string, 0) prefixStore := prefix.NewStore(ctx.KVStore(q.storeKey), types.GetContractByCodeIDSecondaryIndexPrefix(req.CodeId)) pageRes, err := query.FilteredPaginate(prefixStore, req.Pagination, func(key []byte, value []byte, accumulate bool) (bool, error) { - var contractAddr sdk.AccAddress = key[types.AbsoluteTxPositionLen:] - c := q.keeper.GetContractInfo(ctx, contractAddr) - if c == nil { - return false, types.ErrNotFound - } - c.Created = nil // redact if accumulate { - r = append(r, types.ContractInfoWithAddress{ - Address: contractAddr.String(), - ContractInfo: *c, - }) + var contractAddr sdk.AccAddress = key[types.AbsoluteTxPositionLen:] + r = append(r, contractAddr.String()) } return true, nil }) @@ -112,8 +102,8 @@ func (q grpcQuerier) ContractsByCode(c context.Context, req *types.QueryContract return nil, err } return &types.QueryContractsByCodeResponse{ - ContractInfos: r, - Pagination: pageRes, + Contracts: r, + Pagination: pageRes, }, nil } @@ -258,14 +248,14 @@ func (q grpcQuerier) Codes(c context.Context, req *types.QueryCodesRequest) (*ty return &types.QueryCodesResponse{CodeInfos: r, Pagination: pageRes}, nil } -func queryContractInfo(ctx sdk.Context, addr sdk.AccAddress, keeper types.ViewKeeper) (*types.ContractInfoWithAddress, error) { +func queryContractInfo(ctx sdk.Context, addr sdk.AccAddress, keeper types.ViewKeeper) (*types.QueryContractInfoResponse, error) { info := keeper.GetContractInfo(ctx, addr) if info == nil { return nil, types.ErrNotFound } // redact the Created field (just used for sorting, not part of public API) info.Created = nil - return &types.ContractInfoWithAddress{ + return &types.QueryContractInfoResponse{ Address: addr.String(), ContractInfo: *info, }, nil diff --git a/x/wasm/keeper/querier_test.go b/x/wasm/keeper/querier_test.go index 05f554939a..cdb7098539 100644 --- a/x/wasm/keeper/querier_test.go +++ b/x/wasm/keeper/querier_test.go @@ -283,13 +283,13 @@ func TestQueryContractListByCodeOrdering(t *testing.T) { } // create 10 contracts with real block/gas setup - for i := range [10]int{} { + for i := 0; i < 10; i++ { // 3 tx per block, so we ensure both comparisons work if i%3 == 0 { ctx = setBlock(ctx, h) h++ } - _, _, err = keepers.ContractKeeper.Instantiate(ctx, codeID, creator, nil, initMsgBz, fmt.Sprintf("contract %d", i), topUp) + _, _, err = keepers.ContractKeeper.Instantiate(ctx, codeID, creator, nil, initMsgBz, fmt.Sprintf("contractAddr %d", i), topUp) require.NoError(t, err) } @@ -298,13 +298,10 @@ func TestQueryContractListByCodeOrdering(t *testing.T) { res, err := q.ContractsByCode(sdk.WrapSDKContext(ctx), &types.QueryContractsByCodeRequest{CodeId: codeID}) require.NoError(t, err) - require.Equal(t, 10, len(res.ContractInfos)) + require.Equal(t, 10, len(res.Contracts)) - for i, contract := range res.ContractInfos { - assert.Equal(t, fmt.Sprintf("contract %d", i), contract.Label) - assert.NotEmpty(t, contract.Address) - // ensure these are not shown - assert.Nil(t, contract.Created) + for _, contractAddr := range res.Contracts { + assert.NotEmpty(t, contractAddr) } } diff --git a/x/wasm/keeper/wasmtesting/mock_engine.go b/x/wasm/keeper/wasmtesting/mock_engine.go index d0dc0d695e..0e8fbb0c4c 100644 --- a/x/wasm/keeper/wasmtesting/mock_engine.go +++ b/x/wasm/keeper/wasmtesting/mock_engine.go @@ -271,10 +271,16 @@ type contractExecutable interface { ) (*wasmvmtypes.Response, uint64, error) } -//MakeIBCInstantiable adds some noop functions to not fail when contract is used for instantiation -func MakeIBCInstantiable(m *MockWasmer) { +//MakeInstantiable adds some noop functions to not fail when contract is used for instantiation +func MakeInstantiable(m *MockWasmer) { m.CreateFn = HashOnlyCreateFn m.InstantiateFn = NoOpInstantiateFn + m.AnalyzeCodeFn = WithoutIBCAnalyzeFn +} + +//MakeIBCInstantiable adds some noop functions to not fail when contract is used for instantiation +func MakeIBCInstantiable(m *MockWasmer) { + MakeInstantiable(m) m.AnalyzeCodeFn = HasIBCAnalyzeFn } diff --git a/x/wasm/module_test.go b/x/wasm/module_test.go index 514cc5a66c..6d0f2aa271 100644 --- a/x/wasm/module_test.go +++ b/x/wasm/module_test.go @@ -509,25 +509,25 @@ func assertCodeBytes(t *testing.T, q sdk.Querier, ctx sdk.Context, codeID uint64 assert.EqualValues(t, codeID, res["id"]) } -func assertContractList(t *testing.T, q sdk.Querier, ctx sdk.Context, codeID uint64, addrs []string) { +func assertContractList(t *testing.T, q sdk.Querier, ctx sdk.Context, codeID uint64, expContractAddrs []string) { bz, sdkerr := q(ctx, []string{QueryListContractByCode, fmt.Sprintf("%d", codeID)}, abci.RequestQuery{}) require.NoError(t, sdkerr) if len(bz) == 0 { - require.Equal(t, len(addrs), 0) + require.Equal(t, len(expContractAddrs), 0) return } - var res []ContractInfoWithAddress + var res []string err := json.Unmarshal(bz, &res) require.NoError(t, err) var hasAddrs = make([]string, len(res)) for i, r := range res { - hasAddrs[i] = r.Address + hasAddrs[i] = r } - assert.Equal(t, hasAddrs, addrs) + assert.Equal(t, expContractAddrs, hasAddrs) } func assertContractState(t *testing.T, q sdk.Querier, ctx sdk.Context, contractBech32Addr string, expected state) { diff --git a/x/wasm/types/exported_keepers.go b/x/wasm/types/exported_keepers.go index 53533563c8..201653130e 100644 --- a/x/wasm/types/exported_keepers.go +++ b/x/wasm/types/exported_keepers.go @@ -15,6 +15,7 @@ type ViewKeeper interface { HasContractInfo(ctx sdk.Context, contractAddress sdk.AccAddress) bool GetContractInfo(ctx types.Context, contractAddress types.AccAddress) *ContractInfo IterateContractInfo(ctx types.Context, cb func(types.AccAddress, ContractInfo) bool) + IterateContractsByCode(ctx sdk.Context, codeID uint64, cb func(address sdk.AccAddress) bool) GetContractState(ctx types.Context, contractAddress types.AccAddress) types.Iterator GetCodeInfo(ctx types.Context, codeID uint64) *CodeInfo IterateCodeInfos(ctx types.Context, cb func(uint64, CodeInfo) bool) diff --git a/x/wasm/types/query.pb.go b/x/wasm/types/query.pb.go index ac8995c07a..8b2c6cdb96 100644 --- a/x/wasm/types/query.pb.go +++ b/x/wasm/types/query.pb.go @@ -238,50 +238,11 @@ func (m *QueryContractsByCodeRequest) XXX_DiscardUnknown() { var xxx_messageInfo_QueryContractsByCodeRequest proto.InternalMessageInfo -// ContractInfoWithAddress adds the address (key) to the ContractInfo -// representation -type ContractInfoWithAddress struct { - Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` - ContractInfo `protobuf:"bytes,2,opt,name=contract_info,json=contractInfo,proto3,embedded=contract_info" json:""` -} - -func (m *ContractInfoWithAddress) Reset() { *m = ContractInfoWithAddress{} } -func (m *ContractInfoWithAddress) String() string { return proto.CompactTextString(m) } -func (*ContractInfoWithAddress) ProtoMessage() {} -func (*ContractInfoWithAddress) Descriptor() ([]byte, []int) { - return fileDescriptor_e8595715dfdf95d1, []int{5} -} -func (m *ContractInfoWithAddress) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *ContractInfoWithAddress) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_ContractInfoWithAddress.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *ContractInfoWithAddress) XXX_Merge(src proto.Message) { - xxx_messageInfo_ContractInfoWithAddress.Merge(m, src) -} -func (m *ContractInfoWithAddress) XXX_Size() int { - return m.Size() -} -func (m *ContractInfoWithAddress) XXX_DiscardUnknown() { - xxx_messageInfo_ContractInfoWithAddress.DiscardUnknown(m) -} - -var xxx_messageInfo_ContractInfoWithAddress proto.InternalMessageInfo - // QueryContractsByCodeResponse is the response type for the // Query/ContractsByCode RPC method type QueryContractsByCodeResponse struct { - ContractInfos []ContractInfoWithAddress `protobuf:"bytes,1,rep,name=contract_infos,json=contractInfos,proto3" json:"contract_infos"` + // contracts are a set of contract addresses + Contracts []string `protobuf:"bytes,1,rep,name=contracts,proto3" json:"contracts,omitempty"` // pagination defines the pagination in the response. Pagination *query.PageResponse `protobuf:"bytes,2,opt,name=pagination,proto3" json:"pagination,omitempty"` } @@ -290,7 +251,7 @@ func (m *QueryContractsByCodeResponse) Reset() { *m = QueryContractsByCo func (m *QueryContractsByCodeResponse) String() string { return proto.CompactTextString(m) } func (*QueryContractsByCodeResponse) ProtoMessage() {} func (*QueryContractsByCodeResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_e8595715dfdf95d1, []int{6} + return fileDescriptor_e8595715dfdf95d1, []int{5} } func (m *QueryContractsByCodeResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -332,7 +293,7 @@ func (m *QueryAllContractStateRequest) Reset() { *m = QueryAllContractSt func (m *QueryAllContractStateRequest) String() string { return proto.CompactTextString(m) } func (*QueryAllContractStateRequest) ProtoMessage() {} func (*QueryAllContractStateRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_e8595715dfdf95d1, []int{7} + return fileDescriptor_e8595715dfdf95d1, []int{6} } func (m *QueryAllContractStateRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -373,7 +334,7 @@ func (m *QueryAllContractStateResponse) Reset() { *m = QueryAllContractS func (m *QueryAllContractStateResponse) String() string { return proto.CompactTextString(m) } func (*QueryAllContractStateResponse) ProtoMessage() {} func (*QueryAllContractStateResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_e8595715dfdf95d1, []int{8} + return fileDescriptor_e8595715dfdf95d1, []int{7} } func (m *QueryAllContractStateResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -414,7 +375,7 @@ func (m *QueryRawContractStateRequest) Reset() { *m = QueryRawContractSt func (m *QueryRawContractStateRequest) String() string { return proto.CompactTextString(m) } func (*QueryRawContractStateRequest) ProtoMessage() {} func (*QueryRawContractStateRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_e8595715dfdf95d1, []int{9} + return fileDescriptor_e8595715dfdf95d1, []int{8} } func (m *QueryRawContractStateRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -454,7 +415,7 @@ func (m *QueryRawContractStateResponse) Reset() { *m = QueryRawContractS func (m *QueryRawContractStateResponse) String() string { return proto.CompactTextString(m) } func (*QueryRawContractStateResponse) ProtoMessage() {} func (*QueryRawContractStateResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_e8595715dfdf95d1, []int{10} + return fileDescriptor_e8595715dfdf95d1, []int{9} } func (m *QueryRawContractStateResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -496,7 +457,7 @@ func (m *QuerySmartContractStateRequest) Reset() { *m = QuerySmartContra func (m *QuerySmartContractStateRequest) String() string { return proto.CompactTextString(m) } func (*QuerySmartContractStateRequest) ProtoMessage() {} func (*QuerySmartContractStateRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_e8595715dfdf95d1, []int{11} + return fileDescriptor_e8595715dfdf95d1, []int{10} } func (m *QuerySmartContractStateRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -536,7 +497,7 @@ func (m *QuerySmartContractStateResponse) Reset() { *m = QuerySmartContr func (m *QuerySmartContractStateResponse) String() string { return proto.CompactTextString(m) } func (*QuerySmartContractStateResponse) ProtoMessage() {} func (*QuerySmartContractStateResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_e8595715dfdf95d1, []int{12} + return fileDescriptor_e8595715dfdf95d1, []int{11} } func (m *QuerySmartContractStateResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -574,7 +535,7 @@ func (m *QueryCodeRequest) Reset() { *m = QueryCodeRequest{} } func (m *QueryCodeRequest) String() string { return proto.CompactTextString(m) } func (*QueryCodeRequest) ProtoMessage() {} func (*QueryCodeRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_e8595715dfdf95d1, []int{13} + return fileDescriptor_e8595715dfdf95d1, []int{12} } func (m *QueryCodeRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -616,7 +577,7 @@ func (m *CodeInfoResponse) Reset() { *m = CodeInfoResponse{} } func (m *CodeInfoResponse) String() string { return proto.CompactTextString(m) } func (*CodeInfoResponse) ProtoMessage() {} func (*CodeInfoResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_e8595715dfdf95d1, []int{14} + return fileDescriptor_e8595715dfdf95d1, []int{13} } func (m *CodeInfoResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -655,7 +616,7 @@ func (m *QueryCodeResponse) Reset() { *m = QueryCodeResponse{} } func (m *QueryCodeResponse) String() string { return proto.CompactTextString(m) } func (*QueryCodeResponse) ProtoMessage() {} func (*QueryCodeResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_e8595715dfdf95d1, []int{15} + return fileDescriptor_e8595715dfdf95d1, []int{14} } func (m *QueryCodeResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -694,7 +655,7 @@ func (m *QueryCodesRequest) Reset() { *m = QueryCodesRequest{} } func (m *QueryCodesRequest) String() string { return proto.CompactTextString(m) } func (*QueryCodesRequest) ProtoMessage() {} func (*QueryCodesRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_e8595715dfdf95d1, []int{16} + return fileDescriptor_e8595715dfdf95d1, []int{15} } func (m *QueryCodesRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -734,7 +695,7 @@ func (m *QueryCodesResponse) Reset() { *m = QueryCodesResponse{} } func (m *QueryCodesResponse) String() string { return proto.CompactTextString(m) } func (*QueryCodesResponse) ProtoMessage() {} func (*QueryCodesResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_e8595715dfdf95d1, []int{17} + return fileDescriptor_e8595715dfdf95d1, []int{16} } func (m *QueryCodesResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -769,7 +730,6 @@ func init() { proto.RegisterType((*QueryContractHistoryRequest)(nil), "cosmwasm.wasm.v1beta1.QueryContractHistoryRequest") proto.RegisterType((*QueryContractHistoryResponse)(nil), "cosmwasm.wasm.v1beta1.QueryContractHistoryResponse") proto.RegisterType((*QueryContractsByCodeRequest)(nil), "cosmwasm.wasm.v1beta1.QueryContractsByCodeRequest") - proto.RegisterType((*ContractInfoWithAddress)(nil), "cosmwasm.wasm.v1beta1.ContractInfoWithAddress") proto.RegisterType((*QueryContractsByCodeResponse)(nil), "cosmwasm.wasm.v1beta1.QueryContractsByCodeResponse") proto.RegisterType((*QueryAllContractStateRequest)(nil), "cosmwasm.wasm.v1beta1.QueryAllContractStateRequest") proto.RegisterType((*QueryAllContractStateResponse)(nil), "cosmwasm.wasm.v1beta1.QueryAllContractStateResponse") @@ -787,77 +747,75 @@ func init() { func init() { proto.RegisterFile("cosmwasm/wasm/v1beta1/query.proto", fileDescriptor_e8595715dfdf95d1) } var fileDescriptor_e8595715dfdf95d1 = []byte{ - // 1111 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xc4, 0x97, 0xcd, 0x6f, 0x1b, 0xc5, - 0x1b, 0xc7, 0x3d, 0xa9, 0xf3, 0xe2, 0x69, 0xfa, 0xfb, 0x85, 0x51, 0xa1, 0xc6, 0xb8, 0xbb, 0x61, - 0x41, 0xa9, 0x5b, 0xa4, 0xdd, 0x24, 0x4e, 0x11, 0x94, 0x53, 0x9d, 0x02, 0xa9, 0x44, 0x79, 0xd9, - 0x08, 0x22, 0xe8, 0x21, 0x1a, 0xef, 0x4e, 0xed, 0x45, 0xf6, 0x8e, 0xbb, 0x33, 0x26, 0xb1, 0xa2, - 0x50, 0xc4, 0x85, 0x2b, 0xa8, 0x47, 0x2e, 0x1c, 0x38, 0xa0, 0x02, 0xf7, 0x1e, 0x39, 0x70, 0xc8, - 0x31, 0x12, 0x17, 0x4e, 0x16, 0x38, 0x08, 0xa1, 0xfc, 0x09, 0x3d, 0xa1, 0x9d, 0x9d, 0x75, 0x76, - 0x1d, 0xaf, 0xd7, 0x41, 0x16, 0x5c, 0xa2, 0x9d, 0xf8, 0x79, 0x9e, 0xf9, 0x3c, 0xdf, 0x67, 0xe6, - 0x79, 0x76, 0xe1, 0xf3, 0x16, 0x65, 0xcd, 0x1d, 0xcc, 0x9a, 0x86, 0xf8, 0xf3, 0xc9, 0x4a, 0x95, - 0x70, 0xbc, 0x62, 0xdc, 0x6f, 0x13, 0xaf, 0xa3, 0xb7, 0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4, - 0x07, 0x2a, 0xea, 0xbe, 0x8a, 0x7a, 0x50, 0xcc, 0x90, 0xeb, 0x5d, 0x5c, 0x23, 0x32, 0xaa, 0x19, - 0xf1, 0xd4, 0x1e, 0x03, 0x58, 0x1c, 0x4e, 0x20, 0x95, 0x79, 0x07, 0xce, 0x12, 0x97, 0x7b, 0x0e, - 0xf1, 0x11, 0xce, 0x95, 0xce, 0xaf, 0x1a, 0x29, 0x99, 0xaf, 0x53, 0x9b, 0xc8, 0x20, 0xaf, 0xbb, - 0xdc, 0xeb, 0x54, 0xb2, 0xbe, 0x0a, 0x66, 0x18, 0x05, 0xbd, 0x39, 0x84, 0xfc, 0x4a, 0x2a, 0x79, - 0x40, 0x13, 0x43, 0xff, 0x74, 0x40, 0x3b, 0x56, 0xe9, 0xf8, 0x7b, 0x87, 0xda, 0x5d, 0x82, 0xb3, - 0x16, 0xb5, 0xc9, 0xb6, 0x63, 0x0b, 0xed, 0xb2, 0xe6, 0x8c, 0xbf, 0xbc, 0x6d, 0x4f, 0x4c, 0xba, - 0xaf, 0x00, 0xbc, 0x14, 0x2d, 0xf7, 0x96, 0xc3, 0xeb, 0x37, 0x65, 0x79, 0xfe, 0xab, 0xf3, 0xf4, - 0xf3, 0x60, 0x39, 0xfb, 0xa2, 0xc8, 0x72, 0xde, 0x85, 0xff, 0x8b, 0x6d, 0x1f, 0x56, 0x55, 0x1f, - 0x63, 0xff, 0x48, 0x82, 0xb2, 0xa8, 0x17, 0xa2, 0x08, 0x13, 0x2c, 0xed, 0x67, 0x61, 0x1a, 0x37, - 0x1b, 0x8d, 0x90, 0x60, 0x93, 0x63, 0x4e, 0xfe, 0xbd, 0x8b, 0xf1, 0x2d, 0x80, 0x97, 0x13, 0x10, - 0xa4, 0x94, 0x37, 0xe0, 0x4c, 0x93, 0xda, 0xa4, 0x11, 0x4a, 0x58, 0x4c, 0x90, 0xf0, 0x8e, 0x6f, - 0x24, 0x05, 0x93, 0x1e, 0x93, 0x53, 0x6a, 0x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, 0x53, 0x32, 0x07, 0x3d, 0x05, 0x1c, - 0xf6, 0x14, 0xf0, 0x5b, 0x4f, 0x01, 0x5f, 0x1e, 0x29, 0x99, 0xc3, 0x23, 0x25, 0xf3, 0xeb, 0x91, - 0x92, 0xf9, 0x68, 0x29, 0x32, 0x5b, 0xd7, 0x29, 0x6b, 0x6e, 0x85, 0x1f, 0xaf, 0xb6, 0xb1, 0x1b, - 0x04, 0x14, 0x1f, 0xaf, 0xd5, 0x19, 0xf1, 0xcd, 0x59, 0xfe, 0x3b, 0x00, 0x00, 0xff, 0xff, 0x99, - 0xbc, 0xec, 0x7a, 0x32, 0x0f, 0x00, 0x00, + // 1084 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x97, 0xcf, 0x6f, 0xe3, 0x44, + 0x14, 0xc7, 0x33, 0xdd, 0xf4, 0x47, 0x66, 0x8b, 0x28, 0xa3, 0x05, 0x42, 0xc8, 0xda, 0xc5, 0xa0, + 0x6e, 0x76, 0x91, 0xec, 0xfe, 0x5a, 0x04, 0xcb, 0x89, 0x74, 0x81, 0xae, 0xc4, 0xf2, 0xc3, 0x15, + 0xac, 0x80, 0x43, 0x35, 0xb1, 0x67, 0x13, 0xa3, 0xc4, 0x93, 0xf5, 0x4c, 0x68, 0xa3, 0xaa, 0x2c, + 0x42, 0x42, 0x5c, 0x91, 0xf6, 0xc8, 0x85, 0x03, 0x07, 0xb4, 0xc0, 0x7d, 0x8f, 0x1c, 0x7b, 0xac, + 0xc4, 0x85, 0x53, 0x04, 0x29, 0x42, 0xa8, 0x7f, 0xc2, 0x9e, 0xd0, 0x8c, 0xc7, 0x89, 0x93, 0xc6, + 0x71, 0x8a, 0x22, 0x2e, 0x91, 0x27, 0x7e, 0xef, 0xf9, 0xf3, 0xbe, 0xf3, 0xde, 0x3c, 0x1b, 0xbe, + 0xe0, 0x50, 0xd6, 0xd8, 0xc3, 0xac,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e0, 0xb8, 0xab, 0x81, 0x3f, 0xba, 0x1a, 0xf8, 0xf6, 0x44, 0xcb, 0x1c, 0x9f, + 0x68, 0x99, 0xdf, 0x4f, 0xb4, 0xcc, 0x27, 0x2b, 0xb1, 0xd9, 0xba, 0x45, 0x59, 0xe3, 0x4e, 0xf4, + 0xa5, 0xe7, 0x5a, 0xfb, 0x61, 0x40, 0xf9, 0xa5, 0x57, 0x99, 0x93, 0x1f, 0x68, 0x1b, 0xff, 0x06, + 0x00, 0x00, 0xff, 0xff, 0xcc, 0x4d, 0x4e, 0xc2, 0x5f, 0x0e, 0x00, 0x00, } func (this *QueryContractInfoResponse) Equal(that interface{}) bool { @@ -887,33 +845,6 @@ func (this *QueryContractInfoResponse) Equal(that interface{}) bool { } return true } -func (this *ContractInfoWithAddress) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*ContractInfoWithAddress) - if !ok { - that2, ok := that.(ContractInfoWithAddress) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if this.Address != that1.Address { - return false - } - if !this.ContractInfo.Equal(&that1.ContractInfo) { - return false - } - return true -} func (this *CodeInfoResponse) Equal(that interface{}) bool { if that == nil { return this == nil @@ -1527,46 +1458,6 @@ func (m *QueryContractsByCodeRequest) MarshalToSizedBuffer(dAtA []byte) (int, er return len(dAtA) - i, nil } -func (m *ContractInfoWithAddress) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *ContractInfoWithAddress) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *ContractInfoWithAddress) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - { - size, err := m.ContractInfo.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintQuery(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x12 - if len(m.Address) > 0 { - i -= len(m.Address) - copy(dAtA[i:], m.Address) - i = encodeVarintQuery(dAtA, i, uint64(len(m.Address))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - func (m *QueryContractsByCodeResponse) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -1599,16 +1490,11 @@ func (m *QueryContractsByCodeResponse) MarshalToSizedBuffer(dAtA []byte) (int, e i-- dAtA[i] = 0x12 } - if len(m.ContractInfos) > 0 { - for iNdEx := len(m.ContractInfos) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.ContractInfos[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintQuery(dAtA, i, uint64(size)) - } + if len(m.Contracts) > 0 { + for iNdEx := len(m.Contracts) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.Contracts[iNdEx]) + copy(dAtA[i:], m.Contracts[iNdEx]) + i = encodeVarintQuery(dAtA, i, uint64(len(m.Contracts[iNdEx]))) i-- dAtA[i] = 0xa } @@ -2142,30 +2028,15 @@ func (m *QueryContractsByCodeRequest) Size() (n int) { return n } -func (m *ContractInfoWithAddress) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.Address) - if l > 0 { - n += 1 + l + sovQuery(uint64(l)) - } - l = m.ContractInfo.Size() - n += 1 + l + sovQuery(uint64(l)) - return n -} - func (m *QueryContractsByCodeResponse) Size() (n int) { if m == nil { return 0 } var l int _ = l - if len(m.ContractInfos) > 0 { - for _, e := range m.ContractInfos { - l = e.Size() + if len(m.Contracts) > 0 { + for _, s := range m.Contracts { + l = len(s) n += 1 + l + sovQuery(uint64(l)) } } @@ -2907,7 +2778,7 @@ func (m *QueryContractsByCodeRequest) Unmarshal(dAtA []byte) error { } return nil } -func (m *ContractInfoWithAddress) Unmarshal(dAtA []byte) error { +func (m *QueryContractsByCodeResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -2930,15 +2801,15 @@ func (m *ContractInfoWithAddress) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: ContractInfoWithAddress: wiretype end group for non-group") + return fmt.Errorf("proto: QueryContractsByCodeResponse: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: ContractInfoWithAddress: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: QueryContractsByCodeResponse: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Address", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Contracts", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -2966,124 +2837,7 @@ func (m *ContractInfoWithAddress) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Address = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ContractInfo", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthQuery - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.ContractInfo.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipQuery(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *QueryContractsByCodeResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: QueryContractsByCodeResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: QueryContractsByCodeResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ContractInfos", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthQuery - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.ContractInfos = append(m.ContractInfos, ContractInfoWithAddress{}) - if err := m.ContractInfos[len(m.ContractInfos)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } + m.Contracts = append(m.Contracts, string(dAtA[iNdEx:postIndex])) iNdEx = postIndex case 2: if wireType != 2 { From 8c7967e5b48a48a459fe783356b175afedb307d7 Mon Sep 17 00:00:00 2001 From: Alex Peters Date: Tue, 27 Apr 2021 09:04:58 +0200 Subject: [PATCH 3/3] Review feedback --- x/wasm/keeper/keeper_test.go | 27 +++++++++++++++++++++++++++ x/wasm/keeper/querier_test.go | 2 +- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/x/wasm/keeper/keeper_test.go b/x/wasm/keeper/keeper_test.go index 4b5607f7bd..fc88de3b3e 100644 --- a/x/wasm/keeper/keeper_test.go +++ b/x/wasm/keeper/keeper_test.go @@ -1096,6 +1096,33 @@ func TestIterateContractsByCode(t *testing.T) { } } +func TestIterateContractsByCodeWithMigration(t *testing.T) { + // mock migration so that it does not fail when migrate example1 to example2.codeID + mockWasmVM := wasmtesting.MockWasmer{MigrateFn: func(codeID wasmvm.Checksum, env wasmvmtypes.Env, migrateMsg []byte, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64) (*wasmvmtypes.Response, uint64, error) { + return &wasmvmtypes.Response{}, 1, nil + }} + wasmtesting.MakeInstantiable(&mockWasmVM) + ctx, keepers := CreateTestInput(t, false, SupportedFeatures, WithWasmEngine(&mockWasmVM)) + k, c := keepers.WasmKeeper, keepers.ContractKeeper + example1 := InstantiateHackatomExampleContract(t, ctx, keepers) + ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1) + example2 := InstantiateIBCReflectContract(t, ctx, keepers) + ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1) + _, err := c.Migrate(ctx, example1.Contract, example1.CreatorAddr, example2.CodeID, []byte("{}")) + require.NoError(t, err) + + // when + var gotAddr []sdk.AccAddress + k.IterateContractsByCode(ctx, example2.CodeID, func(address sdk.AccAddress) bool { + gotAddr = append(gotAddr, address) + return false + }) + + // then + exp := []sdk.AccAddress{example2.Contract, example1.Contract} + assert.Equal(t, exp, gotAddr) +} + type sudoMsg struct { // This is a tongue-in-check demo command. This is not the intended purpose of Sudo. // Here we show that some priviledged Go module can make a call that should never be exposed diff --git a/x/wasm/keeper/querier_test.go b/x/wasm/keeper/querier_test.go index cdb7098539..ee989014a1 100644 --- a/x/wasm/keeper/querier_test.go +++ b/x/wasm/keeper/querier_test.go @@ -289,7 +289,7 @@ func TestQueryContractListByCodeOrdering(t *testing.T) { ctx = setBlock(ctx, h) h++ } - _, _, err = keepers.ContractKeeper.Instantiate(ctx, codeID, creator, nil, initMsgBz, fmt.Sprintf("contractAddr %d", i), topUp) + _, _, err = keepers.ContractKeeper.Instantiate(ctx, codeID, creator, nil, initMsgBz, fmt.Sprintf("contract %d", i), topUp) require.NoError(t, err) }