@agoric/cosmos 0.34.2-dev-83191e7.0 → 0.34.2-dev-6112a8b.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 +25 -8
- package/daemon/cmd/root.go +48 -15
- package/git-revision.txt +1 -1
- package/package.json +2 -2
- package/x/swingset/genesis.go +99 -21
- package/x/swingset/module.go +17 -2
package/app/app.go
CHANGED
|
@@ -137,13 +137,22 @@ import (
|
|
|
137
137
|
|
|
138
138
|
const appName = "agoric"
|
|
139
139
|
|
|
140
|
-
|
|
141
|
-
//
|
|
142
|
-
//
|
|
143
|
-
// value is
|
|
144
|
-
//
|
|
145
|
-
//
|
|
146
|
-
|
|
140
|
+
const (
|
|
141
|
+
// FlagSwingStoreExportDir defines the config flag used to specify where a
|
|
142
|
+
// genesis swing-store export is expected. For start from genesis, the default
|
|
143
|
+
// value is config/swing-store in the home directory. For genesis export, the
|
|
144
|
+
// value is always a "swing-store" directory sibling to the exported
|
|
145
|
+
// genesis.json file.
|
|
146
|
+
// TODO: document this flag in config, likely alongside the genesis path
|
|
147
|
+
FlagSwingStoreExportDir = "swing-store-export-dir"
|
|
148
|
+
// FlagSwingStoreExportMode defines the export mode for the swing store
|
|
149
|
+
// Alongside the default mode `operational`, there are two other modes
|
|
150
|
+
//
|
|
151
|
+
// 1- `skip` mode will skip the swing store export altogether
|
|
152
|
+
//
|
|
153
|
+
// 2- `debug` mode will export all the available store
|
|
154
|
+
FlagSwingStoreExportMode = "swing-store-export-mode"
|
|
155
|
+
)
|
|
147
156
|
|
|
148
157
|
var (
|
|
149
158
|
// DefaultNodeHome default home directories for the application daemon
|
|
@@ -673,6 +682,7 @@ func NewAgoricApp(
|
|
|
673
682
|
app.EvidenceKeeper = *evidenceKeeper
|
|
674
683
|
|
|
675
684
|
swingStoreExportDir := cast.ToString(appOpts.Get(FlagSwingStoreExportDir))
|
|
685
|
+
swingStoreExportMode := cast.ToString(appOpts.Get(FlagSwingStoreExportMode))
|
|
676
686
|
|
|
677
687
|
// NOTE: Any module instantiated in the module manager that is later modified
|
|
678
688
|
// must be passed by reference here.
|
|
@@ -702,7 +712,14 @@ func NewAgoricApp(
|
|
|
702
712
|
icaModule,
|
|
703
713
|
packetforward.NewAppModule(app.PacketForwardKeeper),
|
|
704
714
|
vstorage.NewAppModule(app.VstorageKeeper),
|
|
705
|
-
swingset.NewAppModule(
|
|
715
|
+
swingset.NewAppModule(
|
|
716
|
+
app.SwingSetKeeper,
|
|
717
|
+
&app.SwingStoreExportsHandler,
|
|
718
|
+
setBootstrapNeeded,
|
|
719
|
+
app.ensureControllerInited,
|
|
720
|
+
swingStoreExportDir,
|
|
721
|
+
swingStoreExportMode,
|
|
722
|
+
),
|
|
706
723
|
vibcModule,
|
|
707
724
|
vbankModule,
|
|
708
725
|
vtransferModule,
|
package/daemon/cmd/root.go
CHANGED
|
@@ -386,6 +386,12 @@ const (
|
|
|
386
386
|
ExportedSwingStoreDirectoryName = "swing-store"
|
|
387
387
|
)
|
|
388
388
|
|
|
389
|
+
var allowedSwingSetExportModes = map[string]bool{
|
|
390
|
+
swingset.SwingStoreExportModeDebug: true,
|
|
391
|
+
swingset.SwingStoreExportModeOperational: true,
|
|
392
|
+
swingset.SwingStoreExportModeSkip: true,
|
|
393
|
+
}
|
|
394
|
+
|
|
389
395
|
// extendCosmosExportCommand monkey-patches the "export" command added by
|
|
390
396
|
// cosmos-sdk to add a required "export-dir" command-line flag, and create the
|
|
391
397
|
// genesis export in the specified directory if the VM is running.
|
|
@@ -396,31 +402,52 @@ func extendCosmosExportCommand(cmd *cobra.Command) {
|
|
|
396
402
|
panic(err)
|
|
397
403
|
}
|
|
398
404
|
|
|
405
|
+
var keys []string
|
|
406
|
+
for key := range allowedSwingSetExportModes {
|
|
407
|
+
keys = append(keys, key)
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
cmd.Flags().String(
|
|
411
|
+
gaia.FlagSwingStoreExportMode,
|
|
412
|
+
swingset.SwingStoreExportModeOperational,
|
|
413
|
+
fmt.Sprintf(
|
|
414
|
+
"The mode for swingstore export (%s)",
|
|
415
|
+
strings.Join(keys, " | "),
|
|
416
|
+
),
|
|
417
|
+
)
|
|
418
|
+
|
|
399
419
|
originalRunE := cmd.RunE
|
|
400
420
|
|
|
401
421
|
extendedRunE := func(cmd *cobra.Command, args []string) error {
|
|
402
422
|
serverCtx := server.GetServerContextFromCmd(cmd)
|
|
403
423
|
|
|
404
424
|
exportDir, _ := cmd.Flags().GetString(FlagExportDir)
|
|
425
|
+
swingStoreExportMode, _ := cmd.Flags().GetString(gaia.FlagSwingStoreExportMode)
|
|
426
|
+
|
|
405
427
|
err := os.MkdirAll(exportDir, os.ModePerm)
|
|
406
428
|
if err != nil {
|
|
407
429
|
return err
|
|
408
430
|
}
|
|
409
431
|
|
|
410
432
|
genesisPath := filepath.Join(exportDir, ExportedGenesisFileName)
|
|
411
|
-
swingStoreExportPath := filepath.Join(exportDir, ExportedSwingStoreDirectoryName)
|
|
412
433
|
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
434
|
+
// Since none mode doesn't perform any swing store export
|
|
435
|
+
// There is no point in creating the export directory
|
|
436
|
+
if swingStoreExportMode != swingset.SwingStoreExportModeSkip {
|
|
437
|
+
swingStoreExportPath := filepath.Join(exportDir, ExportedSwingStoreDirectoryName)
|
|
438
|
+
|
|
439
|
+
err = os.MkdirAll(swingStoreExportPath, os.ModePerm)
|
|
440
|
+
if err != nil {
|
|
441
|
+
return err
|
|
442
|
+
}
|
|
443
|
+
// We unconditionally set FlagSwingStoreExportDir as for export, it makes
|
|
444
|
+
// little sense for users to control this location separately, and we don't
|
|
445
|
+
// want to override any swing-store artifacts that may be associated to the
|
|
446
|
+
// current genesis.
|
|
447
|
+
serverCtx.Viper.Set(gaia.FlagSwingStoreExportDir, swingStoreExportPath)
|
|
416
448
|
}
|
|
417
|
-
// We unconditionally set FlagSwingStoreExportDir as for export, it makes
|
|
418
|
-
// little sense for users to control this location separately, and we don't
|
|
419
|
-
// want to override any swing-store artifacts that may be associated to the
|
|
420
|
-
// current genesis.
|
|
421
|
-
serverCtx.Viper.Set(gaia.FlagSwingStoreExportDir, swingStoreExportPath)
|
|
422
449
|
|
|
423
|
-
if hasVMController(serverCtx) {
|
|
450
|
+
if hasVMController(serverCtx) || swingStoreExportMode == swingset.SwingStoreExportModeSkip {
|
|
424
451
|
// Capture the export in the genesisPath.
|
|
425
452
|
// This will fail if a genesis.json already exists in the export-dir
|
|
426
453
|
genesisFile, err := os.OpenFile(
|
|
@@ -453,7 +480,16 @@ func (ac appCreator) appExport(
|
|
|
453
480
|
jailAllowedAddrs []string,
|
|
454
481
|
appOpts servertypes.AppOptions,
|
|
455
482
|
) (servertypes.ExportedApp, error) {
|
|
456
|
-
|
|
483
|
+
swingStoreExportMode, ok := appOpts.Get(gaia.FlagSwingStoreExportMode).(string)
|
|
484
|
+
if !(ok && allowedSwingSetExportModes[swingStoreExportMode]) {
|
|
485
|
+
return servertypes.ExportedApp{}, fmt.Errorf(
|
|
486
|
+
"export mode '%s' is not supported",
|
|
487
|
+
swingStoreExportMode,
|
|
488
|
+
)
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
// We don't have to launch VM in case the swing store export is not required
|
|
492
|
+
if swingStoreExportMode != swingset.SwingStoreExportModeSkip && OnExportHook != nil {
|
|
457
493
|
if err := OnExportHook(ac.agdServer, logger, appOpts); err != nil {
|
|
458
494
|
return servertypes.ExportedApp{}, err
|
|
459
495
|
}
|
|
@@ -464,10 +500,7 @@ func (ac appCreator) appExport(
|
|
|
464
500
|
return servertypes.ExportedApp{}, errors.New("application home is not set")
|
|
465
501
|
}
|
|
466
502
|
|
|
467
|
-
|
|
468
|
-
if height == -1 {
|
|
469
|
-
loadLatest = true
|
|
470
|
-
}
|
|
503
|
+
loadLatest := height == -1
|
|
471
504
|
|
|
472
505
|
gaiaApp := gaia.NewAgoricApp(
|
|
473
506
|
ac.sender, ac.agdServer,
|
package/git-revision.txt
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
6112a8b
|
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-6112a8b.0+6112a8b",
|
|
4
4
|
"description": "Connect JS to the Cosmos blockchain SDK",
|
|
5
5
|
"parsers": {
|
|
6
6
|
"js": "mjs"
|
|
@@ -39,5 +39,5 @@
|
|
|
39
39
|
"typeCoverage": {
|
|
40
40
|
"atLeast": 0
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "6112a8b0fc5482e7930f5aa092a340dcef1a2a66"
|
|
43
43
|
}
|
package/x/swingset/genesis.go
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
package swingset
|
|
2
2
|
|
|
3
3
|
import (
|
|
4
|
-
// "os"
|
|
5
4
|
"bytes"
|
|
6
5
|
"crypto/sha256"
|
|
7
6
|
"encoding/hex"
|
|
8
7
|
"encoding/json"
|
|
9
8
|
"fmt"
|
|
10
9
|
"hash"
|
|
10
|
+
"io"
|
|
11
11
|
"strings"
|
|
12
12
|
|
|
13
13
|
agoric "github.com/Agoric/agoric-sdk/golang/cosmos/types"
|
|
@@ -16,6 +16,20 @@ import (
|
|
|
16
16
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
17
17
|
)
|
|
18
18
|
|
|
19
|
+
const (
|
|
20
|
+
// SwingStoreExportModeSkip indicates swing store data should be
|
|
21
|
+
// excluded from the export.
|
|
22
|
+
SwingStoreExportModeSkip = "skip"
|
|
23
|
+
|
|
24
|
+
// SwingStoreExportModeOperational (default) indicates export should
|
|
25
|
+
// have the minimal set of artifacts needed to operate a node.
|
|
26
|
+
SwingStoreExportModeOperational = "operational"
|
|
27
|
+
|
|
28
|
+
// SwingStoreExportModeDebug indicates export should have the maximal
|
|
29
|
+
// set of artifacts available in the JS swing-store.
|
|
30
|
+
SwingStoreExportModeDebug = "debug"
|
|
31
|
+
)
|
|
32
|
+
|
|
19
33
|
func ValidateGenesis(data *types.GenesisState) error {
|
|
20
34
|
if data == nil {
|
|
21
35
|
return fmt.Errorf("swingset genesis data cannot be nil")
|
|
@@ -130,36 +144,59 @@ func InitGenesis(ctx sdk.Context, k Keeper, swingStoreExportsHandler *SwingStore
|
|
|
130
144
|
return false
|
|
131
145
|
}
|
|
132
146
|
|
|
133
|
-
func ExportGenesis(
|
|
147
|
+
func ExportGenesis(
|
|
148
|
+
ctx sdk.Context,
|
|
149
|
+
k Keeper,
|
|
150
|
+
swingStoreExportsHandler *SwingStoreExportsHandler,
|
|
151
|
+
swingStoreExportDir string,
|
|
152
|
+
swingStoreExportMode string,
|
|
153
|
+
) *types.GenesisState {
|
|
134
154
|
gs := &types.GenesisState{
|
|
135
155
|
Params: k.GetParams(ctx),
|
|
136
156
|
State: k.GetState(ctx),
|
|
137
157
|
SwingStoreExportData: nil,
|
|
138
158
|
}
|
|
139
159
|
|
|
160
|
+
// This will only be used in non skip mode
|
|
161
|
+
artifactMode := swingStoreExportMode
|
|
162
|
+
exportDataMode := keeper.SwingStoreExportDataModeSkip
|
|
163
|
+
hasher := sha256.New()
|
|
140
164
|
snapshotHeight := uint64(ctx.BlockHeight())
|
|
141
165
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
// The export will fail if the export of a historical height was requested
|
|
146
|
-
snapshotHeight,
|
|
147
|
-
eventHandler,
|
|
148
|
-
keeper.SwingStoreExportOptions{
|
|
149
|
-
ArtifactMode: keeper.SwingStoreArtifactModeOperational,
|
|
150
|
-
ExportDataMode: keeper.SwingStoreExportDataModeSkip,
|
|
151
|
-
},
|
|
152
|
-
)
|
|
153
|
-
if err != nil {
|
|
154
|
-
panic(err)
|
|
166
|
+
if swingStoreExportMode == SwingStoreExportModeDebug {
|
|
167
|
+
exportDataMode = keeper.SwingStoreExportDataModeAll
|
|
168
|
+
snapshotHeight = 0
|
|
155
169
|
}
|
|
156
170
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
171
|
+
if swingStoreExportMode != SwingStoreExportModeSkip {
|
|
172
|
+
eventHandler := swingStoreGenesisEventHandler{
|
|
173
|
+
exportDir: swingStoreExportDir,
|
|
174
|
+
snapshotHeight: snapshotHeight,
|
|
175
|
+
swingStore: k.GetSwingStore(ctx),
|
|
176
|
+
hasher: hasher,
|
|
177
|
+
exportMode: swingStoreExportMode,
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
err := swingStoreExportsHandler.InitiateExport(
|
|
181
|
+
// The export will fail if the export of a historical height was requested outside of debug mode
|
|
182
|
+
snapshotHeight,
|
|
183
|
+
eventHandler,
|
|
184
|
+
keeper.SwingStoreExportOptions{
|
|
185
|
+
ArtifactMode: artifactMode,
|
|
186
|
+
ExportDataMode: exportDataMode,
|
|
187
|
+
},
|
|
188
|
+
)
|
|
189
|
+
if err != nil {
|
|
190
|
+
panic(err)
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
err = keeper.WaitUntilSwingStoreExportDone()
|
|
194
|
+
if err != nil {
|
|
195
|
+
panic(err)
|
|
196
|
+
}
|
|
160
197
|
}
|
|
161
198
|
|
|
162
|
-
gs.SwingStoreExportDataHash = fmt.Sprintf("sha256:%x",
|
|
199
|
+
gs.SwingStoreExportDataHash = fmt.Sprintf("sha256:%x", hasher.Sum(nil))
|
|
163
200
|
|
|
164
201
|
return gs
|
|
165
202
|
}
|
|
@@ -169,6 +206,7 @@ type swingStoreGenesisEventHandler struct {
|
|
|
169
206
|
snapshotHeight uint64
|
|
170
207
|
swingStore sdk.KVStore
|
|
171
208
|
hasher hash.Hash
|
|
209
|
+
exportMode string
|
|
172
210
|
}
|
|
173
211
|
|
|
174
212
|
func (eventHandler swingStoreGenesisEventHandler) OnExportStarted(height uint64, retrieveSwingStoreExport func() error) error {
|
|
@@ -176,10 +214,12 @@ func (eventHandler swingStoreGenesisEventHandler) OnExportStarted(height uint64,
|
|
|
176
214
|
}
|
|
177
215
|
|
|
178
216
|
func (eventHandler swingStoreGenesisEventHandler) OnExportRetrieved(provider keeper.SwingStoreExportProvider) error {
|
|
179
|
-
if eventHandler.snapshotHeight != provider.BlockHeight {
|
|
217
|
+
if eventHandler.exportMode != SwingStoreExportModeDebug && eventHandler.snapshotHeight != provider.BlockHeight {
|
|
180
218
|
return fmt.Errorf("snapshot block height (%d) doesn't match requested height (%d)", provider.BlockHeight, eventHandler.snapshotHeight)
|
|
181
219
|
}
|
|
182
220
|
|
|
221
|
+
artifactsEnded := false
|
|
222
|
+
|
|
183
223
|
artifactsProvider := keeper.SwingStoreExportProvider{
|
|
184
224
|
GetExportDataReader: func() (agoric.KVEntryReader, error) {
|
|
185
225
|
exportDataIterator := eventHandler.swingStore.Iterator(nil, nil)
|
|
@@ -194,7 +234,45 @@ func (eventHandler swingStoreGenesisEventHandler) OnExportRetrieved(provider kee
|
|
|
194
234
|
return nil
|
|
195
235
|
}), nil
|
|
196
236
|
},
|
|
197
|
-
ReadNextArtifact:
|
|
237
|
+
ReadNextArtifact: func() (types.SwingStoreArtifact, error) {
|
|
238
|
+
var (
|
|
239
|
+
artifact types.SwingStoreArtifact
|
|
240
|
+
err error
|
|
241
|
+
encodedExportData bytes.Buffer
|
|
242
|
+
)
|
|
243
|
+
|
|
244
|
+
if !artifactsEnded {
|
|
245
|
+
artifact, err = provider.ReadNextArtifact()
|
|
246
|
+
} else {
|
|
247
|
+
return types.SwingStoreArtifact{}, io.EOF
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
if err == io.EOF {
|
|
251
|
+
artifactsEnded = true
|
|
252
|
+
if eventHandler.exportMode == SwingStoreExportModeDebug {
|
|
253
|
+
exportDataReader, _ := provider.GetExportDataReader()
|
|
254
|
+
|
|
255
|
+
defer exportDataReader.Close()
|
|
256
|
+
|
|
257
|
+
err = agoric.EncodeKVEntryReaderToJsonl(
|
|
258
|
+
exportDataReader,
|
|
259
|
+
&encodedExportData,
|
|
260
|
+
)
|
|
261
|
+
if err == nil {
|
|
262
|
+
artifact = types.SwingStoreArtifact{
|
|
263
|
+
Data: encodedExportData.Bytes(),
|
|
264
|
+
Name: keeper.UntrustedExportDataArtifactName,
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
return artifact, err
|
|
271
|
+
},
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
if eventHandler.exportMode == SwingStoreExportModeDebug {
|
|
275
|
+
artifactsProvider.BlockHeight = provider.BlockHeight
|
|
198
276
|
}
|
|
199
277
|
|
|
200
278
|
return keeper.WriteSwingStoreExportToDirectory(artifactsProvider, eventHandler.exportDir)
|
package/x/swingset/module.go
CHANGED
|
@@ -80,10 +80,18 @@ type AppModule struct {
|
|
|
80
80
|
setBootstrapNeeded func()
|
|
81
81
|
ensureControllerInited func(sdk.Context)
|
|
82
82
|
swingStoreExportDir string
|
|
83
|
+
swingStoreExportMode string
|
|
83
84
|
}
|
|
84
85
|
|
|
85
86
|
// NewAppModule creates a new AppModule Object
|
|
86
|
-
func NewAppModule(
|
|
87
|
+
func NewAppModule(
|
|
88
|
+
k Keeper,
|
|
89
|
+
swingStoreExportsHandler *SwingStoreExportsHandler,
|
|
90
|
+
setBootstrapNeeded func(),
|
|
91
|
+
ensureControllerInited func(sdk.Context),
|
|
92
|
+
swingStoreExportDir string,
|
|
93
|
+
swingStoreExportMode string,
|
|
94
|
+
) AppModule {
|
|
87
95
|
am := AppModule{
|
|
88
96
|
AppModuleBasic: AppModuleBasic{},
|
|
89
97
|
keeper: k,
|
|
@@ -91,6 +99,7 @@ func NewAppModule(k Keeper, swingStoreExportsHandler *SwingStoreExportsHandler,
|
|
|
91
99
|
setBootstrapNeeded: setBootstrapNeeded,
|
|
92
100
|
ensureControllerInited: ensureControllerInited,
|
|
93
101
|
swingStoreExportDir: swingStoreExportDir,
|
|
102
|
+
swingStoreExportMode: swingStoreExportMode,
|
|
94
103
|
}
|
|
95
104
|
return am
|
|
96
105
|
}
|
|
@@ -173,6 +182,12 @@ func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.
|
|
|
173
182
|
|
|
174
183
|
func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage {
|
|
175
184
|
am.checkSwingStoreExportSetup()
|
|
176
|
-
gs := ExportGenesis(
|
|
185
|
+
gs := ExportGenesis(
|
|
186
|
+
ctx,
|
|
187
|
+
am.keeper,
|
|
188
|
+
am.swingStoreExportsHandler,
|
|
189
|
+
am.swingStoreExportDir,
|
|
190
|
+
am.swingStoreExportMode,
|
|
191
|
+
)
|
|
177
192
|
return cdc.MustMarshalJSON(gs)
|
|
178
193
|
}
|