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

feat(server/v2): Add snapshots commands #21065

Merged
merged 26 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from 21 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
50 changes: 50 additions & 0 deletions scripts/test_snapshots_export_restore.sh
Copy link
Member

Choose a reason for hiding this comment

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

Can this be a system test instead? cc @alpe

Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env bash

set -o errexit
set -o nounset
set -x

ROOT=$PWD

SIMD="$ROOT/build/simdv2"
CONFIG="${CONFIG:-$HOME/.simappv2/config}"

COSMOS_BUILD_OPTIONS=v2 make build

if [ -d "$($SIMD config home)" ]; then rm -rv $($SIMD config home); fi
Copy link
Contributor

Choose a reason for hiding this comment

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

Quote the command substitution to prevent word splitting.

The command substitution should be quoted to prevent word splitting and potential issues.

- if [ -d "$($SIMD config home)" ]; then rm -rv $($SIMD config home); fi
+ if [ -d "$("$SIMD" config home)" ]; then rm -rv "$("$SIMD" config home)"; fi
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if [ -d "$($SIMD config home)" ]; then rm -rv $($SIMD config home); fi
if [ -d "$("$SIMD" config home)" ]; then rm -rv "$("$SIMD" config home)"; fi
Tools
Shellcheck

[warning] 14-14: Quote this to prevent word splitting.

(SC2046)


$SIMD init simapp-v2-node --chain-id simapp-v2-chain

cd "$CONFIG"

# to change the voting_period
jq '.app_state.gov.voting_params.voting_period = "600s"' genesis.json > temp.json && mv temp.json genesis.json

# to change the inflation
jq '.app_state.mint.minter.inflation = "0.300000000000000000"' genesis.json > temp.json && mv temp.json genesis.json

$SIMD config set client chain-id simapp-v2-chain
$SIMD keys add test_validator --indiscreet
VALIDATOR_ADDRESS=$($SIMD keys show test_validator -a --keyring-backend test)

$SIMD genesis add-genesis-account "$VALIDATOR_ADDRESS" 1000000000stake
$SIMD genesis gentx test_validator 1000000000stake --keyring-backend test
$SIMD genesis collect-gentxs

$SIMD start &
SIMD_PID=$!

# wait 10s then export snapshot at height 10
sleep 10

kill -9 "$SIMD_PID"

$SIMD store export --height 5

# clear sc & ss data
rm -rf "$HOME/.simappv2/data/application.db"
rm -rf "$HOME/.simappv2/data/ss"

# restore

$SIMD restore 5 3
16 changes: 6 additions & 10 deletions server/v2/store/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,8 @@ Supported app-db-backend types include 'goleveldb', 'rocksdb', 'pebbledb'.`,
}

logger := log.NewLogger(cmd.OutOrStdout())
home, err := cmd.Flags().GetString(serverv2.FlagHome)
if err != nil {
return err
}

rootStore, keepRecent, err := createRootStore(cmd, home, vp, logger)
rootStore, keepRecent, err := createRootStore(cmd, vp, logger)
if err != nil {
return fmt.Errorf("can not create root store %w", err)
}
Expand Down Expand Up @@ -78,14 +74,14 @@ Supported app-db-backend types include 'goleveldb', 'rocksdb', 'pebbledb'.`,
}

cmd.Flags().String(FlagAppDBBackend, "", "The type of database for application and snapshots databases")
cmd.Flags().Uint64(FlagPruningKeepRecent, 0, "Number of recent heights to keep on disk (ignored if pruning is not 'custom')")
cmd.Flags().Uint64(FlagKeepRecent, 0, "Number of recent heights to keep on disk (ignored if pruning is not 'custom')")

return cmd
}

func createRootStore(cmd *cobra.Command, rootDir string, v *viper.Viper, logger log.Logger) (storev2.RootStore, uint64, error) {
func createRootStore(cmd *cobra.Command, v *viper.Viper, logger log.Logger) (storev2.RootStore, uint64, error) {
tempViper := v

rootDir := v.GetString(serverv2.FlagHome)
// handle FlagAppDBBackend
var dbType db.DBType
if cmd.Flags().Changed(FlagAppDBBackend) {
Expand All @@ -103,8 +99,8 @@ func createRootStore(cmd *cobra.Command, rootDir string, v *viper.Viper, logger
}

// handle KeepRecent & Interval flags
if cmd.Flags().Changed(FlagPruningKeepRecent) {
keepRecent, err := cmd.Flags().GetUint64(FlagPruningKeepRecent)
if cmd.Flags().Changed(FlagKeepRecent) {
keepRecent, err := cmd.Flags().GetUint64(FlagKeepRecent)
if err != nil {
return nil, 0, err
}
Expand Down
5 changes: 3 additions & 2 deletions server/v2/store/flags.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package store

const (
FlagAppDBBackend = "app-db-backend"
FlagPruningKeepRecent = "keep-recent"
FlagAppDBBackend = "app-db-backend"
FlagKeepRecent = "keep-recent"
FlagInterval = "interval"
)
19 changes: 5 additions & 14 deletions server/v2/store/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,24 +45,15 @@ func (s *StoreComponent[T]) Stop(ctx context.Context) error {
return nil
}

func (s *StoreComponent[T]) GetCommands() []*cobra.Command {
return []*cobra.Command{
s.PrunesCmd(),
}
}

func (s *StoreComponent[T]) GetTxs() []*cobra.Command {
return nil
}

func (s *StoreComponent[T]) GetQueries() []*cobra.Command {
return nil
}

func (s *StoreComponent[T]) CLICommands() serverv2.CLIConfig {
return serverv2.CLIConfig{
Commands: []*cobra.Command{
s.PrunesCmd(),
s.ExportSnapshotCmd(),
s.DeleteSnapshotCmd(),
s.ListSnapshotsCmd(),
s.DumpArchiveCmd(),
s.LoadArchiveCmd(),
},
}
}
Expand Down
Loading
Loading