Skip to content

Commit

Permalink
fix pruning bug
Browse files Browse the repository at this point in the history
  • Loading branch information
tac0turtle committed Nov 26, 2024
1 parent b49d76e commit adf8b37
Showing 1 changed file with 35 additions and 27 deletions.
62 changes: 35 additions & 27 deletions cmd/pruner.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@ import (
"context"
"fmt"
"path/filepath"
"sync"

"github.com/cosmos/cosmos-sdk/types"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types"
consensusparamtypes "github.com/cosmos/cosmos-sdk/x/consensus/types"
authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper"
feegrant "github.com/cosmos/cosmos-sdk/x/feegrant"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"
consensusparamtypes "github.com/cosmos/cosmos-sdk/x/consensus/types"
crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types"
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types"
feegrant "github.com/cosmos/cosmos-sdk/x/feegrant"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
Expand Down Expand Up @@ -204,8 +205,7 @@ func pruneAppState(home string) error {
keys[key] = value
}
} else if app == "regen" {
regenKeys := types.NewKVStoreKeys(
)
regenKeys := types.NewKVStoreKeys()
for key, value := range regenKeys {
keys[key] = value
}
Expand Down Expand Up @@ -259,8 +259,8 @@ func pruneAppState(home string) error {
}
} else if app == "juno" {
junoKeys := types.NewKVStoreKeys(
"icahost", // icahosttypes.StoreKey,
"wasm", // wasm.StoreKey,
"icahost", // icahosttypes.StoreKey,
"wasm", // wasm.StoreKey,
)

for key, value := range junoKeys {
Expand Down Expand Up @@ -295,8 +295,8 @@ func pruneAppState(home string) error {
// https://github.com/JackalLabs/canine-chain/blob/master/app/app.go#L347
jackalKeys := types.NewKVStoreKeys(
// common modules
"wasm", // wasm.StoreKey,
"icahost", // icahosttypes.StoreKey,
"wasm", // wasm.StoreKey,
"icahost", // icahosttypes.StoreKey,
// custom modules
"icacontroller", // icacontrollertypes.StoreKey, https://github.com/cosmos/ibc-go/blob/main/modules/apps/27-interchain-accounts/controller/types/keys.go#L5
// intertx is a demo and not an officially supported IBC team implementation
Expand All @@ -316,7 +316,7 @@ func pruneAppState(home string) error {
}
} else if app == "kichain" {
kichainKeys := types.NewKVStoreKeys(
"wasm", // wasm.StoreKey,
"wasm", // wasm.StoreKey,
)

for key, value := range kichainKeys {
Expand All @@ -338,41 +338,41 @@ func pruneAppState(home string) error {
}
} else if app == "cheqd" {
cheqdKeys := types.NewKVStoreKeys(
"cheqd", // cheqdtypes.StoreKey,
"cheqd", // cheqdtypes.StoreKey,
)

for key, value := range cheqdKeys {
keys[key] = value
}
} else if app == "stargaze" {
stargazeKeys := types.NewKVStoreKeys(
"claim", // claimmoduletypes.StoreKey,
"alloc", // allocmoduletypes.StoreKey,
"wasm", // wasm.StoreKey,
"claim", // claimmoduletypes.StoreKey,
"alloc", // allocmoduletypes.StoreKey,
"wasm", // wasm.StoreKey,
)

for key, value := range stargazeKeys {
keys[key] = value
}
} else if app == "bandchain" {
bandchainKeys := types.NewKVStoreKeys(
"oracle", // oracletypes.StoreKey,
"oracle", // oracletypes.StoreKey,
)

for key, value := range bandchainKeys {
keys[key] = value
}
} else if app == "chihuahua" {
chihuahuaKeys := types.NewKVStoreKeys(
"wasm", // wasm.StoreKey,
"wasm", // wasm.StoreKey,
)

for key, value := range chihuahuaKeys {
keys[key] = value
}
} else if app == "bitcanna" {
bitcannaKeys := types.NewKVStoreKeys(
"bcna", // bcnamoduletypes.StoreKey,
"bcna", // bcnamoduletypes.StoreKey,
)

for key, value := range bitcannaKeys {
Expand All @@ -399,7 +399,7 @@ func pruneAppState(home string) error {
}
} else if app == "vidulum" {
vidulumKeys := types.NewKVStoreKeys(
"vidulum", // vidulummoduletypes.StoreKey,
"vidulum", // vidulummoduletypes.StoreKey,
)

for key, value := range vidulumKeys {
Expand Down Expand Up @@ -428,7 +428,7 @@ func pruneAppState(home string) error {
}
} else if app == "dig" {
digKeys := types.NewKVStoreKeys(
"wasm", // wasm.StoreKey,
"wasm", // wasm.StoreKey,
)

for key, value := range digKeys {
Expand Down Expand Up @@ -463,15 +463,15 @@ func pruneAppState(home string) error {
}
} else if app == "fetchhub" {
fetchhubKeys := types.NewKVStoreKeys(
"wasm", // wasm.StoreKey,
"wasm", // wasm.StoreKey,
)

for key, value := range fetchhubKeys {
keys[key] = value
}
} else if app == "persistent" {
persistentKeys := types.NewKVStoreKeys(
"halving", // halving.StoreKey,
"halving", // halving.StoreKey,
)

for key, value := range persistentKeys {
Expand Down Expand Up @@ -527,22 +527,22 @@ func pruneAppState(home string) error {
}
} else if app == "umee" {
umeeKeys := types.NewKVStoreKeys(
"gravity", // gravitytypes.StoreKey,
"gravity", // gravitytypes.StoreKey,
)

for key, value := range umeeKeys {
keys[key] = value
}
} else if app == "desmos" {
// https://github.com/desmos-labs/desmos/blob/master/app/app.go#L255
// https://github.com/desmos-labs/desmos/blob/master/app/app.go#L255
desmosKeys := types.NewKVStoreKeys(
// common modules
"wasm", // wasm.StoreKey,
"wasm", // wasm.StoreKey,
// IBC modules
"icacontroller", // icacontrollertypes.StoreKey, https://github.com/cosmos/ibc-go/blob/main/modules/apps/27-interchain-accounts/controller/types/keys.go#L5
"icahost", // icahosttypes.StoreKey,
"icahost", // icahosttypes.StoreKey,
// mainnet since v4.7.0
"profiles", // profilestypes.StoreKey,
"profiles", // profilestypes.StoreKey,
"relationships", // relationshipstypes.StoreKey,
"subspaces", // subspacestypes.StoreKey,
"posts", // poststypes.StoreKey,
Expand Down Expand Up @@ -621,6 +621,8 @@ func pruneTMData(home string) error {

pruneHeight := blockStore.Height() - int64(blocks)

wg := sync.WaitGroup{}
wg.Add(1)
errs, _ := errgroup.WithContext(context.Background())
errs.Go(func() error {
fmt.Println("pruning block store")
Expand All @@ -635,6 +637,7 @@ func pruneTMData(home string) error {
return err
}

wg.Done()
return nil
})

Expand All @@ -650,6 +653,11 @@ func pruneTMData(home string) error {
return err
}

wg.Wait()

stateDB.Close()
blockStore.Close()

return nil
}

Expand Down

0 comments on commit adf8b37

Please sign in to comment.