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: prune cmd should disable async pruning #22656

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i

* (sims) [#21906](https://github.com/cosmos/cosmos-sdk/pull/21906) Skip sims test when running dry on validators
* (cli) [#21919](https://github.com/cosmos/cosmos-sdk/pull/21919) Query address-by-acc-num by account_id instead of id.
* (cli) [#22656](https://github.com/cosmos/cosmos-sdk/pull/22656) Prune cmd should disable async pruning.

### API Breaking Changes

Expand Down
5 changes: 5 additions & 0 deletions baseapp/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ func SetIAVLDisableFastNode(disable bool) func(*BaseApp) {
return func(bapp *BaseApp) { bapp.cms.SetIAVLDisableFastNode(disable) }
}

// SetIAVLSyncPruning set sync/async pruning in the IAVL store.
func SetIAVLSyncPruning(syncPruning bool) func(*BaseApp) {
return func(bapp *BaseApp) { bapp.cms.SetIAVLSyncPruning(syncPruning) }
}

// SetInterBlockCache provides a BaseApp option function that sets the
// inter-block cache.
func SetInterBlockCache(cache storetypes.MultiStorePersistentCache) func(*BaseApp) {
Expand Down
3 changes: 3 additions & 0 deletions client/pruning/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ Supported app-db-backend types include 'goleveldb', 'rocksdb', 'pebbledb'.`,
return err
}

// must disable async pruning
vp.Set(server.FlagIAVLSyncPruning, true)

// use the first argument if present to set the pruning method
if len(args) > 0 {
vp.Set(server.FlagPruning, args[0])
Expand Down
4 changes: 4 additions & 0 deletions server/mock/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ func (ms multiStore) SetIAVLDisableFastNode(disable bool) {
panic("not implemented")
}

func (ms multiStore) SetIAVLSyncPruning(syncPruning bool) {
panic("not implemented")
}
Comment on lines +145 to +147
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Missing implementation in CacheMultiStore

The SetIAVLSyncPruning method is defined in the MultiStore interface and needs to be implemented by all implementations. While rootmulti.Store has a proper implementation, cachemulti.Store is missing this method. The mock implementation in server/mock/store.go correctly panics for unimplemented functionality, but store/cachemulti/store.go needs to be updated to implement this interface method.

  • store/cachemulti/store.go: Add implementation of SetIAVLSyncPruning(bool) method
🔗 Analysis chain

Verify interface implementation across the codebase

Since this adds a new method to the MultiStore interface implementation, we should verify that all other implementations are updated accordingly.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for all MultiStore interface implementations
ast-grep --pattern 'type $_ struct {
  $$$
}

var _ storetypes.MultiStore = $_'

Length of output: 81


Script:

#!/bin/bash
# Let's try a different approach to find MultiStore implementations
# First, let's find the interface definition
rg "type\s+MultiStore\s+interface" -A 10

# Then search for struct types that might implement it
rg "type.*Store.*struct"

# And also search for explicit interface checks
rg "var\s+_\s+.*MultiStore\s+=\s+"

Length of output: 7067


Script:

#!/bin/bash
# Let's check the implementation of the SetIAVLSyncPruning method in both implementations we found
# Check store/cachemulti/store.go
rg "SetIAVLSyncPruning" store/cachemulti/store.go -A 3

# Check store/rootmulti/store.go
rg "SetIAVLSyncPruning" store/rootmulti/store.go -A 3

# Let's also check the interface definition to see if this is a new method
rg "SetIAVLSyncPruning" store/types/store.go -A 3

Length of output: 445


func (ms multiStore) SetInitialVersion(version int64) error {
panic("not implemented")
}
Expand Down
1 change: 1 addition & 0 deletions server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const (
FlagMinRetainBlocks = "min-retain-blocks"
FlagIAVLCacheSize = "iavl-cache-size"
FlagDisableIAVLFastNode = "iavl-disable-fastnode"
FlagIAVLSyncPruning = "iavl-sync-pruning"
FlagShutdownGrace = "shutdown-grace"

// state sync-related flags
Expand Down
1 change: 1 addition & 0 deletions server/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,7 @@ func DefaultBaseappOptions(appOpts types.AppOptions) []func(*baseapp.BaseApp) {
baseapp.SetSnapshot(snapshotStore, snapshotOptions),
baseapp.SetIAVLCacheSize(cast.ToInt(appOpts.Get(FlagIAVLCacheSize))),
baseapp.SetIAVLDisableFastNode(cast.ToBool(appOpts.Get(FlagDisableIAVLFastNode))),
baseapp.SetIAVLSyncPruning(cast.ToBool(appOpts.Get(FlagIAVLSyncPruning))),
defaultMempool,
baseapp.SetChainID(chainID),
baseapp.SetQueryGasLimit(cast.ToUint64(appOpts.Get(FlagQueryGasLimit))),
Expand Down
7 changes: 6 additions & 1 deletion store/iavl/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,16 @@ func LoadStore(db corestore.KVStoreWithBatch, logger types.Logger, key types.Sto
// provided DB. An error is returned if the version fails to load, or if called with a positive
// version on an empty tree.
func LoadStoreWithInitialVersion(db corestore.KVStoreWithBatch, logger types.Logger, key types.StoreKey, id types.CommitID, initialVersion uint64, cacheSize int, disableFastNode bool, metrics metrics.StoreMetrics) (types.CommitKVStore, error) {
return LoadStoreWithOpts(db, logger, key, id, initialVersion, cacheSize, disableFastNode, metrics, iavl.AsyncPruningOption(true))
}

func LoadStoreWithOpts(db corestore.KVStoreWithBatch, logger types.Logger, key types.StoreKey, id types.CommitID, initialVersion uint64, cacheSize int, disableFastNode bool, metrics metrics.StoreMetrics, opts ...iavl.Option) (types.CommitKVStore, error) {
// store/v1 and app/v1 flows never require an initial version of 0
if initialVersion == 0 {
initialVersion = 1
}
tree := iavl.NewMutableTree(db, cacheSize, disableFastNode, logger, iavl.InitialVersionOption(initialVersion), iavl.AsyncPruningOption(true))
opts = append(opts, iavl.InitialVersionOption(initialVersion))
tree := iavl.NewMutableTree(db, cacheSize, disableFastNode, logger, opts...)

isUpgradeable, err := tree.IsUpgradeable()
if err != nil {
Expand Down
15 changes: 6 additions & 9 deletions store/rootmulti/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ type Store struct {
pruningManager *pruning.Manager
iavlCacheSize int
iavlDisableFastNode bool
iavlSyncPruning bool
storesParams map[types.StoreKey]storeParams
stores map[types.StoreKey]types.CommitKVStore
keysByName map[string]types.StoreKey
Expand Down Expand Up @@ -133,6 +134,10 @@ func (rs *Store) SetIAVLDisableFastNode(disableFastNode bool) {
rs.iavlDisableFastNode = disableFastNode
}

func (rs *Store) SetIAVLSyncPruning(syncPruning bool) {
rs.iavlSyncPruning = syncPruning
}

// GetStoreType implements Store.
func (rs *Store) GetStoreType() types.StoreType {
return types.StoreTypeMulti
Expand Down Expand Up @@ -1033,15 +1038,7 @@ func (rs *Store) loadCommitStoreFromParams(key types.StoreKey, id types.CommitID
panic("recursive MultiStores not yet supported")

case types.StoreTypeIAVL:
var store types.CommitKVStore
var err error

if params.initialVersion == 0 {
store, err = iavl.LoadStore(db, rs.logger, key, id, rs.iavlCacheSize, rs.iavlDisableFastNode, rs.metrics)
} else {
store, err = iavl.LoadStoreWithInitialVersion(db, rs.logger, key, id, params.initialVersion, rs.iavlCacheSize, rs.iavlDisableFastNode, rs.metrics)
}

store, err := iavl.LoadStoreWithOpts(db, rs.logger, key, id, params.initialVersion, rs.iavlCacheSize, rs.iavlDisableFastNode, rs.metrics, iavltree.AsyncPruningOption(!rs.iavlSyncPruning))
if err != nil {
return nil, err
}
Expand Down
3 changes: 3 additions & 0 deletions store/types/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,9 @@ type CommitMultiStore interface {
// SetIAVLDisableFastNode enables/disables fastnode feature on iavl.
SetIAVLDisableFastNode(disable bool)

// SetIAVLSyncPruning set sync/async pruning on iavl.
SetIAVLSyncPruning(sync bool)

// RollbackToVersion rollback the db to specific version(height).
RollbackToVersion(version int64) error

Expand Down
Loading