-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6e9aa8a
commit fae652f
Showing
5 changed files
with
120 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package commands | ||
|
||
import ( | ||
"fmt" | ||
cfg "github.com/KYVENetwork/ksync/config" | ||
"github.com/KYVENetwork/ksync/executor/db/store" | ||
"github.com/spf13/cobra" | ||
"os" | ||
) | ||
|
||
var ( | ||
untilHeight int64 | ||
) | ||
|
||
func init() { | ||
pruneCmd.Flags().StringVar(&home, "home", "", "home directory") | ||
if err := pruneCmd.MarkFlagRequired("home"); err != nil { | ||
panic(fmt.Errorf("flag 'home' should be required: %w", err)) | ||
} | ||
|
||
pruneCmd.Flags().Int64Var(&untilHeight, "until-height", 0, "prune blocks until this height (excluding)") | ||
if err := pruneCmd.MarkFlagRequired("until-height"); err != nil { | ||
panic(fmt.Errorf("flag 'until-height' should be required: %w", err)) | ||
} | ||
|
||
rootCmd.AddCommand(pruneCmd) | ||
} | ||
|
||
var pruneCmd = &cobra.Command{ | ||
Use: "prune-blocks", | ||
Short: "Prune blocks until a specific height", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
config, err := cfg.LoadConfig(home) | ||
if err != nil { | ||
panic(fmt.Errorf("failed to load config: %w", err)) | ||
} | ||
|
||
blockStoreDB, blockStore, err := store.GetBlockstoreDBs(config) | ||
defer blockStoreDB.Close() | ||
|
||
if err != nil { | ||
panic(fmt.Errorf("failed to load blockstore db: %w", err)) | ||
} | ||
|
||
base := blockStore.Base() | ||
|
||
if untilHeight < base { | ||
fmt.Printf("Error: base height %d is higher than prune height %d\n", base, untilHeight) | ||
os.Exit(0) | ||
} | ||
|
||
blocks, err := blockStore.PruneBlocks(untilHeight) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
fmt.Printf("Pruned %d blocks, new base height is %d\n", blocks, blockStore.Base()) | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters