Skip to content

Commit

Permalink
chore: small snapshot commands & docs improvement (#16404)
Browse files Browse the repository at this point in the history
(cherry picked from commit b590b09)

# Conflicts:
#	client/snapshot/export.go
#	docs/run-node/run-node.md
#	go.mod
#	server/cmt_cmds.go
#	simapp/go.mod
  • Loading branch information
julienrbrt authored and mergify[bot] committed Jun 2, 2023
1 parent 26405d9 commit 153b3a6
Show file tree
Hide file tree
Showing 9 changed files with 631 additions and 19 deletions.
1 change: 0 additions & 1 deletion client/snapshot/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ func Cmd(appCreator servertypes.AppCreator) *cobra.Command {
cmd := &cobra.Command{
Use: "snapshots",
Short: "Manage local snapshots",
Long: "Manage local snapshots",
}
cmd.AddCommand(
ListSnapshotsCmd,
Expand Down
8 changes: 6 additions & 2 deletions client/snapshot/export.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package snapshot

import (
<<<<<<< HEAD
"fmt"

=======
"cosmossdk.io/log"
>>>>>>> b590b0910 (chore: small snapshot commands & docs improvement (#16404))
"github.com/cosmos/cosmos-sdk/server"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -34,15 +38,15 @@ func ExportSnapshotCmd(appCreator servertypes.AppCreator) *cobra.Command {
height = app.CommitMultiStore().LastCommitID().Version
}

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

sm := app.SnapshotManager()
snapshot, err := sm.Create(uint64(height))
if err != nil {
return err
}

fmt.Printf("Snapshot created at height %d, format %d, chunks %d\n", snapshot.Height, snapshot.Format, snapshot.Chunks)
cmd.Printf("Snapshot created at height %d, format %d, chunks %d\n", snapshot.Height, snapshot.Format, snapshot.Chunks)
return nil
},
}
Expand Down
2 changes: 1 addition & 1 deletion client/snapshot/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var ListSnapshotsCmd = &cobra.Command{
return fmt.Errorf("failed to list snapshots: %w", err)
}
for _, snapshot := range snapshots {
fmt.Println("height:", snapshot.Height, "format:", snapshot.Format, "chunks:", snapshot.Chunks)
cmd.Println("height:", snapshot.Height, "format:", snapshot.Format, "chunks:", snapshot.Chunks)
}

return nil
Expand Down
4 changes: 2 additions & 2 deletions client/snapshot/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const SnapshotFileName = "_snapshot"
func LoadArchiveCmd() *cobra.Command {
return &cobra.Command{
Use: "load <archive-file>",
Short: "Load a snapshot archive file into snapshot store",
Short: "Load a snapshot archive file (.tar.gz) into snapshot store",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
ctx := server.GetServerContextFromCmd(cmd)
Expand Down Expand Up @@ -70,7 +70,7 @@ func LoadArchiveCmd() *cobra.Command {

savedSnapshot, err := snapshotStore.Save(snapshot.Height, snapshot.Format, chunks)
if err != nil {
fmt.Println("failed to save snapshot", err)
cmd.Println("failed to save snapshot", err)
return
}
quitChan <- savedSnapshot
Expand Down
36 changes: 35 additions & 1 deletion docs/run-node/run-node.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,49 @@ The naive way would be to run the same commands again in separate terminal windo

## State Sync

State sync is the act in which a node syncs the latest or close to the latest state of a blockchain. This is useful for users who don't want to sync all the blocks in history. You can read more here: https://docs.cometbft.com/v0.37/core/state-sync
State sync is the act in which a node syncs the latest or close to the latest state of a blockchain. This is useful for users who don't want to sync all the blocks in history. Read more in [CometBFT documentation](https://docs.cometbft.com/v0.37/core/state-sync).

State sync works thanks to snapshots. Read how the SDK handles snapshots [here](https://github.com/cosmos/cosmos-sdk/blob/825245d/store/snapshots/README.md).

### Local State Sync

Local state sync work similar to normal state sync except that it works off a local snapshot of state instead of one provided via the p2p network. The steps to start local state sync are similar to normal state sync with a few different designs.

1. As mentioned in https://docs.cometbft.com/v0.37/core/state-sync, one must set a height and hash in the config.toml along with a few rpc servers (the afromentioned link has instructions on how to do this).
<<<<<<< HEAD:docs/run-node/run-node.md
2. Bootsrapping Comet state in order to start the node after the snapshot has been ingested. This can be done with the bootstrap command `<app> comet bootstrap-state`
<!-- 3. TODO after https://github.com/cosmos/cosmos-sdk/pull/16060 is merged -->
## Next {hide}

Read about the [Interacting with your Node](./interact-node.md) {hide}
=======
2. Run `<appd snapshot restore <height> <format>` to restore a local snapshot (note: first load it from a file with the *load* command).
3. Bootsrapping Comet state in order to start the node after the snapshot has been ingested. This can be done with the bootstrap command `<app> comet bootstrap-state`

### Snapshots Commands

The Cosmos SDK provides commands for managing snapshots.
These commands can be added in an app with the following snippet in `cmd/<app>/root.go`:

```go
import (
"github.com/cosmos/cosmos-sdk/client/snapshot"
)

func initRootCmd(/* ... */) {
// ...
rootCmd.AddCommand(
snapshot.Cmd(appCreator),
)
}
```

Then following commands are available at `<appd> snapshots [command]`:

* **list**: list local snapshots
* **load**: Load a snapshot archive file into snapshot store
* **restore**: Restore app state from local snapshot
* **export**: Export app state to snapshot store
* **dump**: Dump the snapshot as portable archive format
* **delete**: Delete a local snapshot
>>>>>>> b590b0910 (chore: small snapshot commands & docs improvement (#16404)):docs/docs/run-node/01-run-node.md
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,13 @@ replace (
// Fix upstream GHSA-h395-qcrw-5vmq and GHSA-3vp4-m3rf-835h vulnerabilities.
// TODO Remove it: https://github.com/cosmos/cosmos-sdk/issues/10409
github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.9.0
<<<<<<< HEAD
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
github.com/jhump/protoreflect => github.com/jhump/protoreflect v1.9.0
// replace broken goleveldb.
=======
// replace broken goleveldb
>>>>>>> b590b0910 (chore: small snapshot commands & docs improvement (#16404))
github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
// use cometbft
github.com/tendermint/tendermint => github.com/cometbft/cometbft v0.34.28
Expand Down
Loading

0 comments on commit 153b3a6

Please sign in to comment.