Skip to content

Commit

Permalink
fixup! WIP feat(cosmos): Export KVData as artifact
Browse files Browse the repository at this point in the history
Refactor payloadReader loop
  • Loading branch information
mhofman committed Mar 28, 2023
1 parent 95b8dab commit b86ae62
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions golang/cosmos/x/swingset/keeper/snapshotter.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,22 +332,24 @@ func (snapshotter *SwingsetSnapshotter) RestoreExtension(height uint64, format u
return err
}

filename := artifactNameSanitizer.ReplaceAllString(filepath.Base(payload.Name), "-")
filename = fmt.Sprintf("%d-%s", len(manifest.Artifacts), filename)
manifest.Artifacts = append(manifest.Artifacts, [2]string{payload.Name, filename})
err = writeExportFile(filename, payload.Data)

if payload.Name == UntrustedExportDataArtifactName {
if len(swingStoreEntries) == 0 {
snapshotter.logger().Info("using unverified export data for swingstore restore")
_, err := exportDataFile.Write(payload.Data)
if err != nil {
return err
}
continue
} else {
filename = UntrustedExportDataFilename
}
switch {
case payload.Name != UntrustedExportDataArtifactName:
// Artifact verifiable on import from the export data
filename := artifactNameSanitizer.ReplaceAllString(filepath.Base(payload.Name), "-")
filename = fmt.Sprintf("%d-%s", len(manifest.Artifacts), filename)
manifest.Artifacts = append(manifest.Artifacts, [2]string{payload.Name, filename})
err = writeExportFile(filename, payload.Data)

case len(swingStoreEntries) > 0:
// Pseudo artifact containing untrusted export data which may have been
// saved separately for debugging purposes (not referenced from the manifest)
err = writeExportFile(UntrustedExportDataFilename, payload.Data)

default:
// There is no trusted export data, so use any untrusted export data artifact
// FIXME: Remove. Only useful if streamed export data is disabled
snapshotter.logger().Info("using unverified export data for swingstore restore")
_, err = exportDataFile.Write(payload.Data)
}

if err != nil {
Expand Down

0 comments on commit b86ae62

Please sign in to comment.