Skip to content

Commit

Permalink
Merge branch 'main' into yzang/SEI-7926
Browse files Browse the repository at this point in the history
  • Loading branch information
yzang2019 authored Aug 28, 2024
2 parents 44fe08e + 3395ce7 commit aea9278
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 287 deletions.
36 changes: 5 additions & 31 deletions proto/cosmos/accesscontrol/constants.proto
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ enum ResourceType {
ANY = 0;
KV = 1; // child of ANY
Mem = 2; // child of ANY
DexMem = 3; // child of MEM
reserved 3; // dex deprecated
KV_BANK = 4; // child of KV
KV_STAKING = 5; // child of KV
KV_WASM = 6; // child of KV
KV_ORACLE = 7; // child of KV
KV_DEX = 8; // child of KV
reserved 8; // dex deprecated
KV_EPOCH = 9; // child of KV
KV_TOKENFACTORY = 10; // child of KV
KV_ORACLE_VOTE_TARGETS = 11; // child of KV_ORACLE
Expand Down Expand Up @@ -78,26 +78,7 @@ enum ResourceType {
KV_DISTRIBUTION_VAL_ACCUM_COMMISSION = 49; // child of KV_DISTRIBUTION
KV_DISTRIBUTION_SLASH_EVENT = 50; // child of KV_DISTRIBUTION

KV_DEX_CONTRACT_LONGBOOK = 51; // child of KV_DEX
KV_DEX_CONTRACT_SHORTBOOK = 52; // child of KV_DEX
KV_DEX_SETTLEMENT = 53; // child of KV_DEX
KV_DEX_PAIR_PREFIX = 54; // child of KV_DEX
KV_DEX_TWAP = 55; // child of KV_DEX
KV_DEX_PRICE = 56; // child of KV_DEX
KV_DEX_SETTLEMENT_ENTRY = 57; // child of KV_DEX
KV_DEX_REGISTERED_PAIR = 58; // child of KV_DEX
reserved 59; // KV_DEX_PRICE_TICK_SIZE deprecated // child of KV_DEX
KV_DEX_ORDER = 60; // child of KV_DEX
KV_DEX_CANCEL = 61; // child of KV_DEX
KV_DEX_ACCOUNT_ACTIVE_ORDERS = 62; // child of KV_DEX
reserved 63; // KV_DEX_REGISTERED_PAIR_COUNT deprecated // child of KV_DEX
KV_DEX_ASSET_LIST = 64; // child of KV_DEX
KV_DEX_NEXT_ORDER_ID = 65; // child of KV_DEX
KV_DEX_NEXT_SETTLEMENT_ID = 66; // child of KV_DEX
KV_DEX_MATCH_RESULT = 67; // child of KV_DEX
KV_DEX_SETTLEMENT_ORDER_ID = 68; // child of KV_DEX
KV_DEX_ORDER_BOOK = 69; // child of KV_DEX
reserved 70; // KV_DEX_QUANTITY_TICK_SIZE deprecated // child of KV_DEX
reserved 51 to 70; // dex deprecated

KV_ACCESSCONTROL = 71; // child of KV
KV_ACCESSCONTROL_WASM_DEPENDENCY_MAPPING = 72; // child of KV_ACCESSCONTROL
Expand All @@ -121,13 +102,7 @@ enum ResourceType {
KV_SLASHING_VAL_SIGNING_INFO = 85; // child of KV_SLASHING
KV_SLASHING_ADDR_PUBKEY_RELATION_KEY = 86; // child of KV_SLASHING

KV_DEX_MEM_ORDER = 87;
KV_DEX_MEM_CANCEL = 88;
KV_DEX_MEM_DEPOSIT = 89;

KV_DEX_CONTRACT = 90; // child of KV_DEX
KV_DEX_LONG_ORDER_COUNT = 91; // child of KV_DEX
KV_DEX_SHORT_ORDER_COUNT = 92; // child of KV_DEX
reserved 87 to 92; // dex deprecated

KV_BANK_DEFERRED = 93; // child of KV
reserved 94;
Expand All @@ -148,8 +123,7 @@ enum ResourceType {

KV_BANK_WEI_BALANCE = 108; // child of KV_BANK

KV_DEX_MEM_CONTRACTS_TO_PROCESS = 109; // child of KV_DEX_MEM
KV_DEX_MEM_DOWNSTREAM_CONTRACTS = 110; // child of KV_DEX_MEM
reserved 109, 110; // dex deprecated
}

enum WasmMessageSubtype {
Expand Down
13 changes: 13 additions & 0 deletions store/rootmulti/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,15 @@ func (rs *Store) loadVersion(ver int64, upgrades *types.StoreUpgrades) error {
storesKeys = append(storesKeys, key)
}
if upgrades != nil {
for _, upgrade := range upgrades.Deleted {
deletionStoreKey := types.NewKVStoreKey(upgrade)
storesKeys = append(storesKeys, deletionStoreKey)
rs.storesParams[deletionStoreKey] = storeParams{
key: deletionStoreKey,
typ: types.StoreTypeIAVL, // TODO: is this safe
}
rs.keysByName[upgrade] = deletionStoreKey
}
// deterministic iteration order for upgrades
// (as the underlying store may change and
// upgrades make store changes where the execution order may matter)
Expand Down Expand Up @@ -283,6 +292,10 @@ func (rs *Store) loadVersion(ver int64, upgrades *types.StoreUpgrades) error {
// If it was deleted, remove all data
if upgrades.IsDeleted(key.Name()) {
deleteKVStore(store.(types.KVStore))
// drop deleted KV store from stores
delete(newStores, key)
delete(rs.keysByName, key.Name())
delete(rs.storesParams, key)
} else if oldName := upgrades.RenamedFrom(key.Name()); oldName != "" {
// handle renames specially
// make an unregistered key to satify loadCommitStore params
Expand Down
13 changes: 7 additions & 6 deletions store/rootmulti/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,10 @@ func TestMultistoreLoadWithUpgrade(t *testing.T) {
require.NotNil(t, s1)
require.Equal(t, v1, s1.Get(k1))

// store3 is mounted, but data deleted are gone
s3, _ = restore.GetStoreByName("store3").(types.KVStore)
require.NotNil(t, s3)
require.Nil(t, s3.Get(k3)) // data was deleted
// store3 is no longer mounted, and data deleted are gone
s3, ok := restore.GetStoreByName("store3").(types.KVStore)
require.Nil(t, s3)
require.False(t, ok)

// store4 is mounted, with empty data
s4, _ = restore.GetStoreByName("store4").(types.KVStore)
Expand Down Expand Up @@ -298,8 +298,9 @@ func TestMultistoreLoadWithUpgrade(t *testing.T) {
ci, err = getCommitInfo(db, 2)
require.NoError(t, err)
require.Equal(t, int64(2), ci.Version)
require.Equal(t, 4, len(ci.StoreInfos), ci.StoreInfos)
checkContains(t, ci.StoreInfos, []string{"store1", "restore2", "store3", "store4"})
// 3 store infos because store3 was removed
require.Equal(t, 3, len(ci.StoreInfos), ci.StoreInfos)
checkContains(t, ci.StoreInfos, []string{"store1", "restore2", "store4"})
}

func TestParsePath(t *testing.T) {
Expand Down
17 changes: 17 additions & 0 deletions storev2/rootmulti/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,14 @@ func (rs *Store) LoadVersionAndUpgrade(version int64, upgrades *types.StoreUpgra
for key := range rs.storesParams {
storesKeys = append(storesKeys, key)
}

if upgrades != nil {
// load storeKeys for deletion
for _, upgrade := range upgrades.Deleted {
deletionStoreKey := types.NewKVStoreKey(upgrade)
storesKeys = append(storesKeys, deletionStoreKey)
}
}
// deterministic iteration order for upgrades
sort.Slice(storesKeys, func(i, j int) bool {
return storesKeys[i].Name() < storesKeys[j].Name()
Expand All @@ -397,11 +405,13 @@ func (rs *Store) LoadVersionAndUpgrade(version int64, upgrades *types.StoreUpgra
return nil
}

storesKeysForDeletion := make(map[types.StoreKey]struct{})
var treeUpgrades []*proto.TreeNameUpgrade
for _, key := range storesKeys {
switch {
case upgrades.IsDeleted(key.Name()):
treeUpgrades = append(treeUpgrades, &proto.TreeNameUpgrade{Name: key.Name(), Delete: true})
storesKeysForDeletion[key] = struct{}{}
case upgrades.IsAdded(key.Name()) || upgrades.RenamedFrom(key.Name()) != "":
treeUpgrades = append(treeUpgrades, &proto.TreeNameUpgrade{Name: key.Name(), RenameFrom: upgrades.RenamedFrom(key.Name())})
}
Expand All @@ -415,6 +425,9 @@ func (rs *Store) LoadVersionAndUpgrade(version int64, upgrades *types.StoreUpgra
var err error
newStores := make(map[types.StoreKey]types.CommitKVStore, len(storesKeys))
for _, key := range storesKeys {
if _, ok := storesKeysForDeletion[key]; ok {
continue
}
newStores[key], err = rs.loadCommitStoreFromParams(key, rs.storesParams[key])
if err != nil {
return err
Expand Down Expand Up @@ -765,6 +778,10 @@ loop:
if ssImporter != nil {
close(ssImporter)
}
// initialize the earliest version for SS store
if rs.ssStore != nil {
rs.ssStore.SetEarliestVersion(height)
}

return snapshotItem, restoreErr
}
Expand Down
Loading

0 comments on commit aea9278

Please sign in to comment.