Skip to content

Commit

Permalink
fix(cosmos): only allow snapshot export at latest height (#9601)
Browse files Browse the repository at this point in the history
closes: #9600

## Description
Check that an explicit height matches the latest height as exporting historical height is not supported by swing-store

### Security Considerations
None

### Scaling Considerations
None

### Documentation Considerations
Release notes should make clear limits of new support

### Testing Considerations
Manually tested explicit height

### Upgrade Considerations
Would be good to include in u16 if we cut a new rc1
  • Loading branch information
mhofman authored Jun 28, 2024
1 parent 14b9af4 commit 6bc363b
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions golang/cosmos/daemon/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"errors"
"fmt"
"io"
"os"
"path/filepath"
Expand Down Expand Up @@ -452,7 +453,7 @@ func replaceCosmosSnapshotExportCommand(cmd *cobra.Command, ac appCreator) {
replacedRunE := func(cmd *cobra.Command, args []string) error {
ctx := server.GetServerContextFromCmd(cmd)

height, err := cmd.Flags().GetInt64("height")
heightFlag, err := cmd.Flags().GetInt64("height")
if err != nil {
return err
}
Expand All @@ -467,13 +468,15 @@ func replaceCosmosSnapshotExportCommand(cmd *cobra.Command, ac appCreator) {
app := ac.newSnapshotsApp(ctx.Logger, db, nil, ctx.Viper)
gaiaApp := app.(*gaia.GaiaApp)

if height == 0 {
height = app.CommitMultiStore().LastCommitID().Version
latestHeight := app.CommitMultiStore().LastCommitID().Version

if heightFlag != 0 && latestHeight != heightFlag {
return fmt.Errorf("cannot export at height %d, only latest height %d is supported", heightFlag, latestHeight)
}

cmd.Printf("Exporting snapshot for height %d\n", height)
cmd.Printf("Exporting snapshot for height %d\n", latestHeight)

err = gaiaApp.SwingSetSnapshotter.InitiateSnapshot(height)
err = gaiaApp.SwingSetSnapshotter.InitiateSnapshot(latestHeight)
if err != nil {
return err
}
Expand All @@ -488,7 +491,7 @@ func replaceCosmosSnapshotExportCommand(cmd *cobra.Command, ac appCreator) {
return err
}

snapshotHeight := uint64(height)
snapshotHeight := uint64(latestHeight)

for _, snapshot := range snapshotList {
if snapshot.Height == snapshotHeight {
Expand Down

0 comments on commit 6bc363b

Please sign in to comment.