Skip to content

Commit

Permalink
WIP feat(cosmos): Export KVData as artifact
Browse files Browse the repository at this point in the history
  • Loading branch information
mhofman committed Mar 31, 2023
1 parent 978e36e commit a2587ba
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions golang/cosmos/x/swingset/keeper/snapshotter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a2587ba

Please sign in to comment.