Skip to content
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

agd export option for diagnosis #10344

Merged
merged 21 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion golang/cosmos/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ const (
//
// 1- `skip` mode will skip the swing store export altogether
//
// 2- `debug` mode will export the complete store, starting from height zero
// 2- `debug` mode will export all the available store
FlagSwingStoreExportMode = "swing-store-export-mode"
mhofman marked this conversation as resolved.
Show resolved Hide resolved
)

Expand Down
14 changes: 7 additions & 7 deletions golang/cosmos/daemon/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,9 @@ const (
)

var allowedSwingSetExportModes = map[string]bool{
swingsetkeeper.SwingStoreArtifactModeDebug: true,
swingsetkeeper.SwingStoreArtifactModeNone: true,
swingsetkeeper.SwingStoreArtifactModeOperational: true,
swingsetkeeper.SwingStoreExportModeDebug: true,
swingsetkeeper.SwingStoreExportModeOperational: true,
swingsetkeeper.SwingStoreExportModeSkip: true,
}

// extendCosmosExportCommand monkey-patches the "export" command added by
Expand All @@ -409,7 +409,7 @@ func extendCosmosExportCommand(cmd *cobra.Command) {

cmd.Flags().String(
gaia.FlagSwingStoreExportMode,
swingsetkeeper.SwingStoreArtifactModeOperational,
swingsetkeeper.SwingStoreExportModeOperational,
fmt.Sprintf(
"The mode for swingstore export (%s)",
strings.Join(keys, " | "),
Expand All @@ -433,7 +433,7 @@ func extendCosmosExportCommand(cmd *cobra.Command) {

// Since none mode doesn't perform any swing store export
// There is no point in creating the export directory
if swingStoreExportMode != swingsetkeeper.SwingStoreArtifactModeNone {
if swingStoreExportMode != swingsetkeeper.SwingStoreExportModeSkip {
swingStoreExportPath := filepath.Join(exportDir, ExportedSwingStoreDirectoryName)

err = os.MkdirAll(swingStoreExportPath, os.ModePerm)
Expand All @@ -447,7 +447,7 @@ func extendCosmosExportCommand(cmd *cobra.Command) {
serverCtx.Viper.Set(gaia.FlagSwingStoreExportDir, swingStoreExportPath)
}

if hasVMController(serverCtx) || swingStoreExportMode == swingsetkeeper.SwingStoreArtifactModeNone {
if hasVMController(serverCtx) || swingStoreExportMode == swingsetkeeper.SwingStoreExportModeSkip {
// Capture the export in the genesisPath.
// This will fail if a genesis.json already exists in the export-dir
genesisFile, err := os.OpenFile(
Expand Down Expand Up @@ -489,7 +489,7 @@ func (ac appCreator) appExport(
}

// We don't have to launch VM in case the swing store export is not required
if swingStoreExportMode != swingsetkeeper.SwingStoreArtifactModeNone && OnExportHook != nil {
if swingStoreExportMode != swingsetkeeper.SwingStoreExportModeSkip && OnExportHook != nil {
if err := OnExportHook(ac.agdServer, logger, appOpts); err != nil {
return servertypes.ExportedApp{}, err
}
Expand Down
10 changes: 5 additions & 5 deletions golang/cosmos/x/swingset/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,12 @@ func ExportGenesis(
hasher := sha256.New()
snapshotHeight := uint64(ctx.BlockHeight())

if artifactMode == keeper.SwingStoreArtifactModeDebug {
if swingStoreExportMode == keeper.SwingStoreExportModeDebug {
exportDataMode = keeper.SwingStoreExportDataModeAll
snapshotHeight = 0
}

if artifactMode != keeper.SwingStoreArtifactModeNone {
if swingStoreExportMode != keeper.SwingStoreExportModeSkip {
eventHandler := swingStoreGenesisEventHandler{
exportDir: swingStoreExportDir,
snapshotHeight: snapshotHeight,
Expand Down Expand Up @@ -200,7 +200,7 @@ func (eventHandler swingStoreGenesisEventHandler) OnExportStarted(height uint64,
}

func (eventHandler swingStoreGenesisEventHandler) OnExportRetrieved(provider keeper.SwingStoreExportProvider) error {
if eventHandler.exportMode != keeper.SwingStoreArtifactModeDebug && eventHandler.snapshotHeight != provider.BlockHeight {
if eventHandler.exportMode != keeper.SwingStoreExportModeDebug && eventHandler.snapshotHeight != provider.BlockHeight {
return fmt.Errorf("snapshot block height (%d) doesn't match requested height (%d)", provider.BlockHeight, eventHandler.snapshotHeight)
}

Expand Down Expand Up @@ -235,7 +235,7 @@ func (eventHandler swingStoreGenesisEventHandler) OnExportRetrieved(provider kee

if err == io.EOF {
artifactsEnded = true
if eventHandler.exportMode == keeper.SwingStoreArtifactModeDebug {
if eventHandler.exportMode == keeper.SwingStoreExportModeDebug {
exportDataReader, _ := provider.GetExportDataReader()

defer exportDataReader.Close()
Expand All @@ -257,7 +257,7 @@ func (eventHandler swingStoreGenesisEventHandler) OnExportRetrieved(provider kee
},
}

if eventHandler.exportMode == keeper.SwingStoreArtifactModeDebug {
if eventHandler.exportMode == keeper.SwingStoreExportModeDebug {
artifactsProvider.BlockHeight = provider.BlockHeight
}

Expand Down
14 changes: 14 additions & 0 deletions golang/cosmos/x/swingset/keeper/swing_store_exports_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,20 @@ const (
SwingStoreExportDataModeAll = "all"
)

const (
// SwingStoreExportModeSkip indicates swing store data should be
// excluded from the export.
SwingStoreExportModeSkip = "skip"

// SwingStoreExportModeOperational (default) indicates export should
// have the minimal set of artifacts needed to operate a node.
SwingStoreExportModeOperational = "operational"

// SwingStoreExportModeDebug indicates export should have the maximal
// set of artifacts available in the JS swing-store.
SwingStoreExportModeDebug = "debug"
)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move these to genesis.go as it's only applicable to that logic.

// SwingStoreExportOptions are configurable options provided to the JS swing-store export
type SwingStoreExportOptions struct {
// ArtifactMode controls the set of artifacts that should be included in the
Expand Down
Loading