feat: add local snapshots management commands (#16067)

Co-authored-by: Marko <marbar3778@yahoo.com>
This commit is contained in:
yihuang
2023-05-11 10:11:31 +00:00
committed by GitHub
co-authored by Marko
parent b28c50fdd2
commit c1ceb3bdda
16 changed files with 483 additions and 16 deletions
+4
View File
@@ -5,6 +5,7 @@ import (
"io"
"cosmossdk.io/log"
"cosmossdk.io/store/snapshots"
storetypes "cosmossdk.io/store/types"
abci "github.com/cometbft/cometbft/abci/types"
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
@@ -54,6 +55,9 @@ type (
// CommitMultiStore return the multistore instance
CommitMultiStore() storetypes.CommitMultiStore
// Return the snapshot manager
SnapshotManager() *snapshots.Manager
}
// AppCreator is a function that allows us to lazily initialize an
+20 -10
View File
@@ -469,16 +469,7 @@ func DefaultBaseappOptions(appOpts types.AppOptions) []func(*baseapp.BaseApp) {
chainID = appGenesis.ChainID
}
snapshotDir := filepath.Join(homeDir, "data", "snapshots")
if err = os.MkdirAll(snapshotDir, os.ModePerm); err != nil {
panic(fmt.Errorf("failed to create snapshots directory: %w", err))
}
snapshotDB, err := dbm.NewDB("metadata", GetAppDBBackend(appOpts), snapshotDir)
if err != nil {
panic(err)
}
snapshotStore, err := snapshots.NewStore(snapshotDB, snapshotDir)
snapshotStore, err := GetSnapshotStore(appOpts)
if err != nil {
panic(err)
}
@@ -514,3 +505,22 @@ func DefaultBaseappOptions(appOpts types.AppOptions) []func(*baseapp.BaseApp) {
baseapp.SetChainID(chainID),
}
}
func GetSnapshotStore(appOpts types.AppOptions) (*snapshots.Store, error) {
homeDir := cast.ToString(appOpts.Get(flags.FlagHome))
snapshotDir := filepath.Join(homeDir, "data", "snapshots")
if err := os.MkdirAll(snapshotDir, os.ModePerm); err != nil {
return nil, fmt.Errorf("failed to create snapshots directory: %w", err)
}
snapshotDB, err := dbm.NewDB("metadata", GetAppDBBackend(appOpts), snapshotDir)
if err != nil {
return nil, err
}
snapshotStore, err := snapshots.NewStore(snapshotDB, snapshotDir)
if err != nil {
return nil, err
}
return snapshotStore, nil
}