diff --git a/golang/cosmos/x/swingset/keeper/snapshotter.go b/golang/cosmos/x/swingset/keeper/snapshotter.go index a73d47501447..c86f42eb9698 100644 --- a/golang/cosmos/x/swingset/keeper/snapshotter.go +++ b/golang/cosmos/x/swingset/keeper/snapshotter.go @@ -26,6 +26,8 @@ const SnapshotFormat = 1 const ExportManifestFilename = "export-manifest.json" const ExportDataFilename = "export-data.jsonl" +const UntrustedExportDataArtifactName = "UNTRUSTED-EXPORT-DATA" +const UntrustedExportDataFilename = "untrusted-export-data.jsonl" const ExportedFilesMode = 0644 type activeSnapshot struct { @@ -245,9 +247,19 @@ func (snapshotter *SwingsetSnapshotter) SnapshotExtension(height uint64, payload return nil } + if manifest.Data != "" { + err = fileToPayload(UntrustedExportDataArtifactName, manifest.Data) + if err != nil { + return err + } + } + for _, artifactInfo := range manifest.Artifacts { name := artifactInfo[0] filename := artifactInfo[1] + if name == UntrustedExportDataArtifactName { + return fmt.Errorf("unexpected artifact name %s", name) + } err = fileToPayload(name, filename) if err != nil { return err @@ -320,10 +332,25 @@ 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) + 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 { return err