-
Notifications
You must be signed in to change notification settings - Fork 206
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
Support for snapshots export
command
#9563
Changes from all commits
2a3976e
84208e9
8c1a62d
4386f8e
2dabb52
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
diff --git a/dist/upgrade-test-scripts/env_setup.sh b/dist/upgrade-test-scripts/env_setup.sh | ||
index 617a0fbe7efdfa457e28fc52806dba1b323930d8..25f52a6cf133dca830bd0dcd47c91700e6a8effe 100755 | ||
--- a/dist/upgrade-test-scripts/env_setup.sh | ||
+++ b/dist/upgrade-test-scripts/env_setup.sh | ||
@@ -100,7 +100,7 @@ killAgd() { | ||
AGD_PID=$(cat $HOME/.agoric/agd.pid) | ||
kill $AGD_PID | ||
rm $HOME/.agoric/agd.pid | ||
- wait $AGD_PID || true | ||
+ tail --pid=$AGD_PID -f /dev/null || true | ||
} | ||
|
||
provisionSmartWallet() { |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/bin/bash | ||
|
||
source /usr/src/upgrade-test-scripts/env_setup.sh | ||
|
||
set -e | ||
|
||
killAgd | ||
agd snapshots export | ||
SNAPSHOT_DETAILS=$(agd snapshots list | head -n1 | sed -E 's/height: ([0-9]+) format: ([0-9]+) chunks: [0-9]+/\1 \2/') | ||
echo found snapshot $SNAPSHOT_DETAILS | ||
rm -rf /root/.agoric/data/application.db /root/.agoric/data/agoric | ||
agd snapshots restore $SNAPSHOT_DETAILS | ||
|
||
startAgd |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,5 @@ GLOBIGNORE=initial.test.js | |
yarn ava ./*.test.js | ||
|
||
./create-kread-item-test.sh | ||
|
||
./state-sync-snapshots-test.sh |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,6 @@ import ( | |
|
||
serverconfig "github.com/cosmos/cosmos-sdk/server/config" | ||
|
||
"github.com/cosmos/cosmos-sdk/baseapp" | ||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/client/config" | ||
"github.com/cosmos/cosmos-sdk/client/debug" | ||
|
@@ -19,9 +18,6 @@ import ( | |
"github.com/cosmos/cosmos-sdk/client/snapshot" | ||
"github.com/cosmos/cosmos-sdk/server" | ||
servertypes "github.com/cosmos/cosmos-sdk/server/types" | ||
"github.com/cosmos/cosmos-sdk/snapshots" | ||
snapshottypes "github.com/cosmos/cosmos-sdk/snapshots/types" | ||
"github.com/cosmos/cosmos-sdk/store" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli" | ||
"github.com/cosmos/cosmos-sdk/x/auth/types" | ||
|
@@ -39,6 +35,7 @@ import ( | |
gaia "github.com/Agoric/agoric-sdk/golang/cosmos/app" | ||
"github.com/Agoric/agoric-sdk/golang/cosmos/app/params" | ||
"github.com/Agoric/agoric-sdk/golang/cosmos/vm" | ||
swingsetkeeper "github.com/Agoric/agoric-sdk/golang/cosmos/x/swingset/keeper" | ||
) | ||
|
||
var AppName = "agd" | ||
|
@@ -142,16 +139,27 @@ func initRootCmd(sender vm.Sender, rootCmd *cobra.Command, encodingConfig params | |
testnetCmd(gaia.ModuleBasics, banktypes.GenesisBalancesIterator{}), | ||
debug.Cmd(), | ||
config.Cmd(), | ||
pruning.Cmd(ac.newApp, gaia.DefaultNodeHome), | ||
snapshot.Cmd(ac.newApp), | ||
pruning.Cmd(ac.newSnapshotsApp, gaia.DefaultNodeHome), | ||
snapshot.Cmd(ac.newSnapshotsApp), | ||
) | ||
|
||
server.AddCommands(rootCmd, gaia.DefaultNodeHome, ac.newApp, ac.appExport, addModuleInitFlags) | ||
|
||
for _, command := range rootCmd.Commands() { | ||
if command.Name() == "export" { | ||
switch command.Name() { | ||
case "export": | ||
addAgoricVMFlags(command) | ||
extendCosmosExportCommand(command) | ||
break | ||
case "snapshots": | ||
for _, subCommand := range command.Commands() { | ||
switch subCommand.Name() { | ||
case "restore": | ||
addAgoricVMFlags(subCommand) | ||
case "export": | ||
addAgoricVMFlags(subCommand) | ||
replaceCosmosSnapshotExportCommand(subCommand, ac) | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
@@ -264,22 +272,13 @@ func (ac appCreator) newApp( | |
} | ||
} | ||
|
||
var cache sdk.MultiStorePersistentCache | ||
|
||
if cast.ToBool(appOpts.Get(server.FlagInterBlockCache)) { | ||
cache = store.NewCommitKVStoreCacheManager() | ||
} | ||
baseappOptions := server.DefaultBaseappOptions(appOpts) | ||
|
||
skipUpgradeHeights := make(map[int64]bool) | ||
for _, h := range cast.ToIntSlice(appOpts.Get(server.FlagUnsafeSkipUpgrades)) { | ||
skipUpgradeHeights[int64(h)] = true | ||
} | ||
|
||
pruningOpts, err := server.GetPruningOptionsFromFlags(appOpts) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
homePath := cast.ToString(appOpts.Get(flags.FlagHome)) | ||
|
||
// Set a default value for FlagSwingStoreExportDir based on the homePath | ||
|
@@ -289,39 +288,41 @@ func (ac appCreator) newApp( | |
viper.Set(gaia.FlagSwingStoreExportDir, filepath.Join(homePath, "config", ExportedSwingStoreDirectoryName)) | ||
} | ||
|
||
snapshotDir := filepath.Join(homePath, "data", "snapshots") | ||
snapshotDB, err := dbm.NewDB("metadata", dbm.GoLevelDBBackend, snapshotDir) | ||
if err != nil { | ||
panic(err) | ||
} | ||
snapshotStore, err := snapshots.NewStore(snapshotDB, snapshotDir) | ||
if err != nil { | ||
panic(err) | ||
} | ||
snapshotOptions := snapshottypes.NewSnapshotOptions( | ||
cast.ToUint64(appOpts.Get(server.FlagStateSyncSnapshotInterval)), | ||
cast.ToUint32(appOpts.Get(server.FlagStateSyncSnapshotKeepRecent)), | ||
return gaia.NewAgoricApp( | ||
ac.sender, ac.agdServer, | ||
logger, db, traceStore, true, skipUpgradeHeights, | ||
homePath, | ||
cast.ToUint(appOpts.Get(server.FlagInvCheckPeriod)), | ||
ac.encCfg, | ||
appOpts, | ||
baseappOptions..., | ||
) | ||
} | ||
|
||
func (ac appCreator) newSnapshotsApp( | ||
logger log.Logger, | ||
db dbm.DB, | ||
traceStore io.Writer, | ||
appOpts servertypes.AppOptions, | ||
) servertypes.Application { | ||
if OnExportHook != nil { | ||
if err := OnExportHook(ac.agdServer, logger, appOpts); err != nil { | ||
panic(err) | ||
} | ||
} | ||
|
||
baseappOptions := server.DefaultBaseappOptions(appOpts) | ||
|
||
homePath := cast.ToString(appOpts.Get(flags.FlagHome)) | ||
|
||
return gaia.NewAgoricApp( | ||
ac.sender, ac.agdServer, | ||
logger, db, traceStore, true, skipUpgradeHeights, | ||
logger, db, traceStore, true, map[int64]bool{}, | ||
homePath, | ||
cast.ToUint(appOpts.Get(server.FlagInvCheckPeriod)), | ||
ac.encCfg, | ||
appOpts, | ||
baseapp.SetPruning(pruningOpts), | ||
baseapp.SetMinGasPrices(cast.ToString(appOpts.Get(server.FlagMinGasPrices))), | ||
baseapp.SetHaltHeight(cast.ToUint64(appOpts.Get(server.FlagHaltHeight))), | ||
baseapp.SetHaltTime(cast.ToUint64(appOpts.Get(server.FlagHaltTime))), | ||
baseapp.SetMinRetainBlocks(cast.ToUint64(appOpts.Get(server.FlagMinRetainBlocks))), | ||
baseapp.SetInterBlockCache(cache), | ||
baseapp.SetTrace(cast.ToBool(appOpts.Get(server.FlagTrace))), | ||
baseapp.SetIndexEvents(cast.ToStringSlice(appOpts.Get(server.FlagIndexEvents))), | ||
baseapp.SetSnapshot(snapshotStore, snapshotOptions), | ||
baseapp.SetIAVLCacheSize(cast.ToInt(appOpts.Get(server.FlagIAVLCacheSize))), | ||
baseapp.SetIAVLDisableFastNode(cast.ToBool(appOpts.Get(server.FlagDisableIAVLFastNode))), | ||
baseapp.SetIAVLLazyLoading(cast.ToBool(appOpts.Get(server.FlagIAVLLazyLoading))), | ||
baseappOptions..., | ||
Comment on lines
-313
to
+325
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ahhhhh... that's satisfying. |
||
) | ||
} | ||
|
||
|
@@ -342,7 +343,6 @@ const ( | |
// cosmos-sdk to add a required "export-dir" command-line flag, and create the | ||
// genesis export in the specified directory if the VM is running. | ||
func extendCosmosExportCommand(cmd *cobra.Command) { | ||
addAgoricVMFlags(cmd) | ||
cmd.Flags().String(FlagExportDir, "", "The directory where to create the genesis export") | ||
err := cmd.MarkFlagRequired(FlagExportDir) | ||
if err != nil { | ||
|
@@ -443,3 +443,62 @@ func (ac appCreator) appExport( | |
|
||
return gaiaApp.ExportAppStateAndValidators(forZeroHeight, jailAllowedAddrs) | ||
} | ||
|
||
// replaceCosmosSnapshotExportCommand monkey-patches the "snapshots export" command | ||
// added by cosmos-sdk and replaces its implementation with one suitable for | ||
// our modifications to the cosmos snapshots process | ||
func replaceCosmosSnapshotExportCommand(cmd *cobra.Command, ac appCreator) { | ||
// Copy of RunE is cosmos-sdk/client/snapshot/export.go | ||
replacedRunE := func(cmd *cobra.Command, args []string) error { | ||
ctx := server.GetServerContextFromCmd(cmd) | ||
|
||
height, err := cmd.Flags().GetInt64("height") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
home := ctx.Config.RootDir | ||
dataDir := filepath.Join(home, "data") | ||
db, err := dbm.NewDB("application", server.GetAppDBBackend(ctx.Viper), dataDir) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
app := ac.newSnapshotsApp(ctx.Logger, db, nil, ctx.Viper) | ||
gaiaApp := app.(*gaia.GaiaApp) | ||
|
||
if height == 0 { | ||
height = app.CommitMultiStore().LastCommitID().Version | ||
} | ||
|
||
cmd.Printf("Exporting snapshot for height %d\n", height) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this output go to stderr? Ideally, please use the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I copied this part from the original which used |
||
|
||
err = gaiaApp.SwingSetSnapshotter.InitiateSnapshot(height) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = swingsetkeeper.WaitUntilSwingStoreExportDone() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
snapshotList, err := app.SnapshotManager().List() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
snapshotHeight := uint64(height) | ||
|
||
for _, snapshot := range snapshotList { | ||
if snapshot.Height == snapshotHeight { | ||
cmd.Printf("Snapshot created at height %d, format %d, chunks %d\n", snapshot.Height, snapshot.Format, snapshot.Chunks) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And this should be |
||
break | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
cmd.RunE = replacedRunE | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a sneaky way to do waits from an unrelated process! Maybe a comment would be in order, such as citing a reference?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do in the PR I'll open against synthetic-chain