From 6bc363b5624bab5fd151ec4889b5f5116f2cf53c Mon Sep 17 00:00:00 2001 From: Mathieu Hofman <86499+mhofman@users.noreply.github.com> Date: Fri, 28 Jun 2024 01:12:09 -0700 Subject: [PATCH] fix(cosmos): only allow snapshot export at latest height (#9601) 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 --- golang/cosmos/daemon/cmd/root.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/golang/cosmos/daemon/cmd/root.go b/golang/cosmos/daemon/cmd/root.go index 11af8c8c22e..043b1b5edcf 100644 --- a/golang/cosmos/daemon/cmd/root.go +++ b/golang/cosmos/daemon/cmd/root.go @@ -2,6 +2,7 @@ package cmd import ( "errors" + "fmt" "io" "os" "path/filepath" @@ -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 } @@ -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 } @@ -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 {