@agoric/cosmos 0.34.2-dev-c6d8a27.0 → 0.34.2-dev-479a1a0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/app/app.go
CHANGED
|
@@ -810,6 +810,42 @@ func NewAgoricApp(
|
|
|
810
810
|
return app
|
|
811
811
|
}
|
|
812
812
|
|
|
813
|
+
type swingStoreMigrationEventHandler struct {
|
|
814
|
+
swingStore sdk.KVStore
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
func (eventHandler swingStoreMigrationEventHandler) OnExportStarted(height uint64, retrieveSwingStoreExport func() error) error {
|
|
818
|
+
return retrieveSwingStoreExport()
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
func (eventHandler swingStoreMigrationEventHandler) OnExportRetrieved(provider swingsetkeeper.SwingStoreExportProvider) (err error) {
|
|
822
|
+
exportDataReader, err := provider.GetExportDataReader()
|
|
823
|
+
if err != nil {
|
|
824
|
+
return err
|
|
825
|
+
}
|
|
826
|
+
defer exportDataReader.Close()
|
|
827
|
+
|
|
828
|
+
var hasExportData bool
|
|
829
|
+
|
|
830
|
+
for {
|
|
831
|
+
entry, err := exportDataReader.Read()
|
|
832
|
+
if err == io.EOF {
|
|
833
|
+
break
|
|
834
|
+
} else if err != nil {
|
|
835
|
+
return err
|
|
836
|
+
}
|
|
837
|
+
hasExportData = true
|
|
838
|
+
if !entry.HasValue() {
|
|
839
|
+
return fmt.Errorf("no value for export data key %s", entry.Key())
|
|
840
|
+
}
|
|
841
|
+
eventHandler.swingStore.Set([]byte(entry.Key()), []byte(entry.StringValue()))
|
|
842
|
+
}
|
|
843
|
+
if !hasExportData {
|
|
844
|
+
return fmt.Errorf("export data had no entries")
|
|
845
|
+
}
|
|
846
|
+
return nil
|
|
847
|
+
}
|
|
848
|
+
|
|
813
849
|
// upgrade11Handler performs standard upgrade actions plus custom actions for upgrade-11.
|
|
814
850
|
func upgrade11Handler(app *GaiaApp, targetUpgrade string) func(sdk.Context, upgradetypes.Plan, module.VersionMap) (module.VersionMap, error) {
|
|
815
851
|
return func(ctx sdk.Context, plan upgradetypes.Plan, fromVm module.VersionMap) (module.VersionMap, error) {
|
|
@@ -817,7 +853,64 @@ func upgrade11Handler(app *GaiaApp, targetUpgrade string) func(sdk.Context, upgr
|
|
|
817
853
|
// Record the plan to send to SwingSet
|
|
818
854
|
app.upgradePlan = &plan
|
|
819
855
|
|
|
820
|
-
//
|
|
856
|
+
// Perform swing-store migrations. We do this in the app upgrade handler
|
|
857
|
+
// since it involves multiple modules (x/vstorage and x/swingset) which
|
|
858
|
+
// don't strictly have a version change on their own.
|
|
859
|
+
|
|
860
|
+
// We are at the begining of the upgrade block, so all stores are commited
|
|
861
|
+
// as of the end of the previous block
|
|
862
|
+
savedBlockHeight := uint64(ctx.BlockHeight() - 1)
|
|
863
|
+
|
|
864
|
+
// First, repair swing-store metadata in case this node was previously
|
|
865
|
+
// initialized from a state-sync snapshot. This is done with a check on the
|
|
866
|
+
// block height to catch early any hangover related mismatch.
|
|
867
|
+
// Only entries related to missing historical metadata are imported, but we
|
|
868
|
+
// don't know what these look like here, so we provide it all.
|
|
869
|
+
getSwingStoreExportDataFromVstorage := func() (reader agorictypes.KVEntryReader, err error) {
|
|
870
|
+
return agorictypes.NewVstorageDataEntriesReader(
|
|
871
|
+
app.VstorageKeeper.ExportStorageFromPrefix(ctx, swingsetkeeper.StoragePathSwingStore),
|
|
872
|
+
), nil
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
// We're not restoring any artifact to swing-store, nor have any to provide
|
|
876
|
+
readNoArtifact := func() (artifact swingsettypes.SwingStoreArtifact, err error) {
|
|
877
|
+
return artifact, io.EOF
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
err := app.SwingStoreExportsHandler.RestoreExport(
|
|
881
|
+
swingsetkeeper.SwingStoreExportProvider{
|
|
882
|
+
BlockHeight: savedBlockHeight,
|
|
883
|
+
GetExportDataReader: getSwingStoreExportDataFromVstorage,
|
|
884
|
+
ReadNextArtifact: readNoArtifact,
|
|
885
|
+
},
|
|
886
|
+
swingsetkeeper.SwingStoreRestoreOptions{
|
|
887
|
+
ArtifactMode: swingsetkeeper.SwingStoreArtifactModeNone,
|
|
888
|
+
ExportDataMode: swingsetkeeper.SwingStoreExportDataModeRepairMetadata,
|
|
889
|
+
},
|
|
890
|
+
)
|
|
891
|
+
if err != nil {
|
|
892
|
+
return nil, err
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
// Then migrate the swing-store shadow copy:
|
|
896
|
+
// 1. Remove the swing-store "export data" shadow-copy entries from vstorage.
|
|
897
|
+
// 2. Export swing-store "export-data" (as of the previous block) through a
|
|
898
|
+
// handler that writes every entry into the swingset module's new Store.
|
|
899
|
+
app.VstorageKeeper.RemoveEntriesWithPrefix(ctx, swingsetkeeper.StoragePathSwingStore)
|
|
900
|
+
err = app.SwingStoreExportsHandler.InitiateExport(
|
|
901
|
+
savedBlockHeight,
|
|
902
|
+
swingStoreMigrationEventHandler{swingStore: app.SwingSetKeeper.GetSwingStore(ctx)},
|
|
903
|
+
swingsetkeeper.SwingStoreExportOptions{
|
|
904
|
+
ArtifactMode: swingsetkeeper.SwingStoreArtifactModeNone,
|
|
905
|
+
ExportDataMode: swingsetkeeper.SwingStoreExportDataModeAll,
|
|
906
|
+
},
|
|
907
|
+
)
|
|
908
|
+
if err == nil {
|
|
909
|
+
err = swingsetkeeper.WaitUntilSwingStoreExportDone()
|
|
910
|
+
}
|
|
911
|
+
if err != nil {
|
|
912
|
+
return nil, err
|
|
913
|
+
}
|
|
821
914
|
|
|
822
915
|
// Always run module migrations
|
|
823
916
|
mvm, err := app.mm.RunMigrations(ctx, app.configurator, fromVm)
|
package/git-revision.txt
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
479a1a0
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agoric/cosmos",
|
|
3
|
-
"version": "0.34.2-dev-
|
|
3
|
+
"version": "0.34.2-dev-479a1a0.0+479a1a0",
|
|
4
4
|
"description": "Connect JS to the Cosmos blockchain SDK",
|
|
5
5
|
"parsers": {
|
|
6
6
|
"js": "mjs"
|
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
"publishConfig": {
|
|
36
36
|
"access": "public"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "479a1a02a362144acf30cb9ca956dc05f6cfb5ea"
|
|
39
39
|
}
|
|
@@ -125,8 +125,8 @@ func (snapshotter *ExtensionSnapshotter) InitiateSnapshot(height int64) error {
|
|
|
125
125
|
blockHeight := uint64(height)
|
|
126
126
|
|
|
127
127
|
return snapshotter.swingStoreExportsHandler.InitiateExport(blockHeight, snapshotter, SwingStoreExportOptions{
|
|
128
|
-
|
|
129
|
-
|
|
128
|
+
ArtifactMode: SwingStoreArtifactModeReplay,
|
|
129
|
+
ExportDataMode: SwingStoreExportDataModeSkip,
|
|
130
130
|
})
|
|
131
131
|
}
|
|
132
132
|
|
|
@@ -304,6 +304,6 @@ func (snapshotter *ExtensionSnapshotter) RestoreExtension(blockHeight uint64, fo
|
|
|
304
304
|
|
|
305
305
|
return snapshotter.swingStoreExportsHandler.RestoreExport(
|
|
306
306
|
SwingStoreExportProvider{BlockHeight: blockHeight, GetExportDataReader: getExportDataReader, ReadNextArtifact: readNextArtifact},
|
|
307
|
-
SwingStoreRestoreOptions{
|
|
307
|
+
SwingStoreRestoreOptions{ArtifactMode: SwingStoreArtifactModeReplay, ExportDataMode: SwingStoreExportDataModeAll},
|
|
308
308
|
)
|
|
309
309
|
}
|
|
@@ -72,7 +72,7 @@ import (
|
|
|
72
72
|
// - OnExportRetrieved reads the export using the provider.
|
|
73
73
|
//
|
|
74
74
|
// Restoring a swing-store export does not have similar non-blocking requirements.
|
|
75
|
-
// The component simply invokes
|
|
75
|
+
// The component simply invokes swingStoreExportsHandler.RestoreExport with a
|
|
76
76
|
// SwingStoreExportProvider representing the swing-store export to
|
|
77
77
|
// be restored, and RestoreExport will consume it and block until the JS side
|
|
78
78
|
// has completed the restore before returning.
|
|
@@ -157,44 +157,81 @@ type swingStoreRestoreExportAction struct {
|
|
|
157
157
|
Args [1]swingStoreImportOptions `json:"args"`
|
|
158
158
|
}
|
|
159
159
|
|
|
160
|
-
|
|
161
|
-
//
|
|
162
|
-
|
|
160
|
+
const (
|
|
161
|
+
// SwingStoreArtifactModeNone means that no artifacts are part of the
|
|
162
|
+
// export / import.
|
|
163
|
+
SwingStoreArtifactModeNone = "none"
|
|
163
164
|
|
|
164
|
-
//
|
|
165
|
-
//
|
|
166
|
-
|
|
165
|
+
// SwingStoreArtifactModeOperational represents the minimal set of artifacts
|
|
166
|
+
// needed to operate a node.
|
|
167
|
+
SwingStoreArtifactModeOperational = "operational"
|
|
167
168
|
|
|
168
|
-
//
|
|
169
|
-
//
|
|
170
|
-
|
|
171
|
-
|
|
169
|
+
// SwingStoreArtifactModeReplay represents the set of artifacts needed to
|
|
170
|
+
// replay the current incarnation of every vat.
|
|
171
|
+
SwingStoreArtifactModeReplay = "replay"
|
|
172
|
+
|
|
173
|
+
// SwingStoreArtifactModeArchival represents the set of all artifacts
|
|
174
|
+
// providing all available historical state.
|
|
175
|
+
SwingStoreArtifactModeArchival = "archival"
|
|
176
|
+
|
|
177
|
+
// SwingStoreArtifactModeDebug represents the maximal set of artifacts
|
|
178
|
+
// available in the JS swing-store, including any kept around for debugging
|
|
179
|
+
// purposes only (like previous XS heap snapshots)
|
|
180
|
+
SwingStoreArtifactModeDebug = "debug"
|
|
181
|
+
)
|
|
182
|
+
|
|
183
|
+
const (
|
|
184
|
+
// SwingStoreExportDataModeSkip indicates "export data" should be excluded from
|
|
185
|
+
// an export. ArtifactMode cannot be "none" in this case.
|
|
186
|
+
SwingStoreExportDataModeSkip = "skip"
|
|
187
|
+
|
|
188
|
+
// SwingStoreExportDataModeRepairMetadata indicates the "export data" should be
|
|
189
|
+
// used to repair the metadata of an existing swing-store for an import
|
|
190
|
+
// operation. ArtifactMode must be "none" in this case.
|
|
191
|
+
SwingStoreExportDataModeRepairMetadata = "repair-metadata"
|
|
192
|
+
|
|
193
|
+
// SwingStoreExportDataModeAll indicates "export data" should be part of the
|
|
194
|
+
// export or import. For import, ArtifactMode cannot be "none".
|
|
195
|
+
SwingStoreExportDataModeAll = "all"
|
|
196
|
+
)
|
|
172
197
|
|
|
173
198
|
// SwingStoreExportOptions are configurable options provided to the JS swing-store export
|
|
174
199
|
type SwingStoreExportOptions struct {
|
|
175
|
-
//
|
|
176
|
-
//
|
|
177
|
-
//
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
//
|
|
181
|
-
//
|
|
182
|
-
|
|
200
|
+
// ArtifactMode controls the set of artifacts that should be included in the
|
|
201
|
+
// swing-store export. Any SwingStoreArtifactMode* const value can be used
|
|
202
|
+
// (None, Operational, Replay, Archival, Debug).
|
|
203
|
+
// See packages/cosmic-swingset/src/export-kernel-db.js initiateSwingStoreExport
|
|
204
|
+
ArtifactMode string `json:"artifactMode,omitempty"`
|
|
205
|
+
// ExportDataMode selects whether to include "export data" in the swing-store
|
|
206
|
+
// export or not. Use the value SwingStoreExportDataModeSkip or
|
|
207
|
+
// SwingStoreExportDataModeAll. If "skip", the reader returned by
|
|
208
|
+
// SwingStoreExportProvider's GetExportDataReader will be nil.
|
|
209
|
+
ExportDataMode string `json:"exportDataMode,omitempty"`
|
|
183
210
|
}
|
|
184
211
|
|
|
185
212
|
// SwingStoreRestoreOptions are configurable options provided to the JS swing-store import
|
|
186
213
|
type SwingStoreRestoreOptions struct {
|
|
187
|
-
//
|
|
188
|
-
//
|
|
189
|
-
|
|
214
|
+
// ArtifactMode controls the set of artifacts that should be restored in
|
|
215
|
+
// swing-store. Any SwingStoreArtifactMode* const value can be used
|
|
216
|
+
// (None, Operational, Replay, Archival, Debug).
|
|
217
|
+
// See packages/cosmic-swingset/src/import-kernel-db.js performStateSyncImport
|
|
218
|
+
ArtifactMode string `json:"artifactMode,omitempty"`
|
|
219
|
+
// ExportDataMode selects the purpose of the restore, to recreate a
|
|
220
|
+
// swing-store (SwingStoreExportDataModeAll), or just to import missing
|
|
221
|
+
// metadata (SwingStoreExportDataModeRepairMetadata).
|
|
222
|
+
// If RepairMetadata, ArtifactMode should be SwingStoreArtifactModeNone.
|
|
223
|
+
// If All, ArtifactMode must be at least SwingStoreArtifactModeOperational.
|
|
224
|
+
ExportDataMode string `json:"exportDataMode,omitempty"`
|
|
190
225
|
}
|
|
191
226
|
|
|
192
227
|
type swingStoreImportOptions struct {
|
|
193
228
|
// ExportDir is the directory created by RestoreExport that JS swing-store
|
|
194
229
|
// should import from.
|
|
195
230
|
ExportDir string `json:"exportDir"`
|
|
196
|
-
//
|
|
197
|
-
|
|
231
|
+
// ArtifactMode is a copy of SwingStoreRestoreOptions.ArtifactMode
|
|
232
|
+
ArtifactMode string `json:"artifactMode,omitempty"`
|
|
233
|
+
// ExportDataMode is a copy of SwingStoreRestoreOptions.ExportDataMode
|
|
234
|
+
ExportDataMode string `json:"exportDataMode,omitempty"`
|
|
198
235
|
}
|
|
199
236
|
|
|
200
237
|
var disallowedArtifactNameChar = regexp.MustCompile(`[^-_.a-zA-Z0-9]`)
|
|
@@ -781,8 +818,9 @@ func (exportsHandler SwingStoreExportsHandler) RestoreExport(provider SwingStore
|
|
|
781
818
|
BlockHeight: blockHeight,
|
|
782
819
|
Request: restoreRequest,
|
|
783
820
|
Args: [1]swingStoreImportOptions{{
|
|
784
|
-
ExportDir:
|
|
785
|
-
|
|
821
|
+
ExportDir: exportDir,
|
|
822
|
+
ArtifactMode: restoreOptions.ArtifactMode,
|
|
823
|
+
ExportDataMode: restoreOptions.ExportDataMode,
|
|
786
824
|
}},
|
|
787
825
|
}
|
|
788
826
|
|
|
@@ -181,6 +181,54 @@ func (k Keeper) ImportStorage(ctx sdk.Context, entries []*types.DataEntry) {
|
|
|
181
181
|
}
|
|
182
182
|
}
|
|
183
183
|
|
|
184
|
+
func getEncodedKeysWithPrefixFromIterator(iterator sdk.Iterator, prefix string) [][]byte {
|
|
185
|
+
keys := make([][]byte, 0)
|
|
186
|
+
defer iterator.Close()
|
|
187
|
+
for ; iterator.Valid(); iterator.Next() {
|
|
188
|
+
key := iterator.Key()
|
|
189
|
+
path := types.EncodedKeyToPath(key)
|
|
190
|
+
if strings.HasPrefix(path, prefix) {
|
|
191
|
+
keys = append(keys, key)
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return keys
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// RemoveEntriesWithPrefix removes all storage entries starting with the
|
|
198
|
+
// supplied pathPrefix, which may not be empty.
|
|
199
|
+
// It has the same effect as listing children of the prefix and removing each
|
|
200
|
+
// descendant recursively.
|
|
201
|
+
func (k Keeper) RemoveEntriesWithPrefix(ctx sdk.Context, pathPrefix string) {
|
|
202
|
+
store := ctx.KVStore(k.storeKey)
|
|
203
|
+
|
|
204
|
+
if len(pathPrefix) == 0 {
|
|
205
|
+
panic("cannot remove all content")
|
|
206
|
+
}
|
|
207
|
+
if err := types.ValidatePath(pathPrefix); err != nil {
|
|
208
|
+
panic(err)
|
|
209
|
+
}
|
|
210
|
+
descendantPrefix := pathPrefix + types.PathSeparator
|
|
211
|
+
|
|
212
|
+
// since vstorage encodes keys with a prefix indicating the number of path
|
|
213
|
+
// elements, we cannot use a simple prefix iterator.
|
|
214
|
+
// Instead we iterate over the whole vstorage content and check
|
|
215
|
+
// whether each entry matches the descendantPrefix. This choice assumes most
|
|
216
|
+
// entries will be deleted. An alternative implementation would be to
|
|
217
|
+
// recursively list all children under the descendantPrefix, and delete them.
|
|
218
|
+
|
|
219
|
+
iterator := sdk.KVStorePrefixIterator(store, nil)
|
|
220
|
+
|
|
221
|
+
keys := getEncodedKeysWithPrefixFromIterator(iterator, descendantPrefix)
|
|
222
|
+
|
|
223
|
+
for _, key := range keys {
|
|
224
|
+
store.Delete(key)
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// Update the prefix entry itself with SetStorage, which will effectively
|
|
228
|
+
// delete it and all necessary ancestors.
|
|
229
|
+
k.SetStorage(ctx, agoric.NewKVEntryWithNoValue(pathPrefix))
|
|
230
|
+
}
|
|
231
|
+
|
|
184
232
|
func (k Keeper) EmitChange(ctx sdk.Context, change *ProposedChange) {
|
|
185
233
|
if change.NewValue == change.ValueFromLastBlock {
|
|
186
234
|
// No change.
|
|
@@ -185,7 +185,25 @@ func TestStorage(t *testing.T) {
|
|
|
185
185
|
t.Errorf("got export %q, want %q", got, expectedKey2Export)
|
|
186
186
|
}
|
|
187
187
|
|
|
188
|
+
keeper.RemoveEntriesWithPrefix(ctx, "key2.child2")
|
|
189
|
+
if keeper.HasEntry(ctx, "key2") {
|
|
190
|
+
t.Errorf("got leftover entries for key2 after removal")
|
|
191
|
+
}
|
|
192
|
+
expectedRemainingExport := []*types.DataEntry{
|
|
193
|
+
{Path: "alpha2", Value: "value2"},
|
|
194
|
+
{Path: "beta3", Value: "value3"},
|
|
195
|
+
{Path: "inited", Value: ""},
|
|
196
|
+
}
|
|
197
|
+
gotRemainingExport := keeper.ExportStorage(ctx)
|
|
198
|
+
if !reflect.DeepEqual(gotRemainingExport, expectedRemainingExport) {
|
|
199
|
+
t.Errorf("got remaining export %q, want %q", expectedRemainingExport, expectedRemainingExport)
|
|
200
|
+
}
|
|
201
|
+
|
|
188
202
|
keeper.ImportStorage(ctx, gotExport)
|
|
203
|
+
gotExport = keeper.ExportStorage(ctx)
|
|
204
|
+
if !reflect.DeepEqual(gotExport, expectedExport) {
|
|
205
|
+
t.Errorf("got export %q after import, want %q", gotExport, expectedExport)
|
|
206
|
+
}
|
|
189
207
|
}
|
|
190
208
|
|
|
191
209
|
func TestStorageNotify(t *testing.T) {
|