@agoric/cosmos 0.34.2-dev-3573f79.0 → 0.34.2-dev-fed2b5e.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
@@ -102,11 +102,13 @@ import (
102
102
  tmjson "github.com/tendermint/tendermint/libs/json"
103
103
  "github.com/tendermint/tendermint/libs/log"
104
104
  tmos "github.com/tendermint/tendermint/libs/os"
105
+ tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
105
106
  dbm "github.com/tendermint/tm-db"
106
107
 
107
108
  gaiaappparams "github.com/Agoric/agoric-sdk/golang/cosmos/app/params"
108
109
 
109
110
  appante "github.com/Agoric/agoric-sdk/golang/cosmos/ante"
111
+ agorictypes "github.com/Agoric/agoric-sdk/golang/cosmos/types"
110
112
  "github.com/Agoric/agoric-sdk/golang/cosmos/vm"
111
113
  "github.com/Agoric/agoric-sdk/golang/cosmos/x/lien"
112
114
  "github.com/Agoric/agoric-sdk/golang/cosmos/x/swingset"
@@ -200,6 +202,7 @@ type GaiaApp struct { // nolint: golint
200
202
  controllerInited bool
201
203
  bootstrapNeeded bool
202
204
  lienPort int
205
+ swingsetPort int
203
206
  vbankPort int
204
207
  vibcPort int
205
208
  vstoragePort int
@@ -457,6 +460,7 @@ func NewAgoricApp(
457
460
  app.VstorageKeeper, vbanktypes.ReservePoolName,
458
461
  callToController,
459
462
  )
463
+ app.swingsetPort = vm.RegisterPortHandler("swingset", swingset.NewPortHandler(app.SwingSetKeeper))
460
464
 
461
465
  app.SwingStoreExportsHandler = *swingsetkeeper.NewSwingStoreExportsHandler(
462
466
  app.Logger(),
@@ -472,10 +476,20 @@ func NewAgoricApp(
472
476
  return sendToController(true, string(bz))
473
477
  },
474
478
  )
479
+
480
+ getSwingStoreExportDataShadowCopyReader := func(height int64) agorictypes.KVEntryReader {
481
+ ctx := app.NewUncachedContext(false, tmproto.Header{Height: height})
482
+ exportDataIterator := app.SwingSetKeeper.GetSwingStore(ctx).Iterator(nil, nil)
483
+ if !exportDataIterator.Valid() {
484
+ exportDataIterator.Close()
485
+ return nil
486
+ }
487
+ return agorictypes.NewKVIteratorReader(exportDataIterator)
488
+ }
475
489
  app.SwingSetSnapshotter = *swingsetkeeper.NewExtensionSnapshotter(
476
490
  bApp,
477
491
  &app.SwingStoreExportsHandler,
478
- app.SwingSetKeeper.ExportSwingStore,
492
+ getSwingStoreExportDataShadowCopyReader,
479
493
  )
480
494
 
481
495
  app.VibcKeeper = vibc.NewKeeper(
@@ -803,6 +817,8 @@ func upgrade11Handler(app *GaiaApp, targetUpgrade string) func(sdk.Context, upgr
803
817
  // Record the plan to send to SwingSet
804
818
  app.upgradePlan = &plan
805
819
 
820
+ // TODO: Migrate x/vstorage swingStore to x/swingset SwingStore
821
+
806
822
  // Always run module migrations
807
823
  mvm, err := app.mm.RunMigrations(ctx, app.configurator, fromVm)
808
824
  if err != nil {
@@ -831,17 +847,18 @@ func normalizeModuleAccount(ctx sdk.Context, ak authkeeper.AccountKeeper, name s
831
847
  }
832
848
 
833
849
  type cosmosInitAction struct {
834
- Type string `json:"type"`
835
- ChainID string `json:"chainID"`
836
- BlockTime int64 `json:"blockTime,omitempty"`
837
- IsBootstrap bool `json:"isBootstrap"`
838
- Params swingset.Params `json:"params"`
839
- SupplyCoins sdk.Coins `json:"supplyCoins"`
840
- UpgradePlan *upgradetypes.Plan `json:"upgradePlan,omitempty"`
841
- LienPort int `json:"lienPort"`
842
- StoragePort int `json:"storagePort"`
843
- VbankPort int `json:"vbankPort"`
844
- VibcPort int `json:"vibcPort"`
850
+ Type string `json:"type"`
851
+ ChainID string `json:"chainID"`
852
+ BlockTime int64 `json:"blockTime,omitempty"`
853
+ IsBootstrap bool `json:"isBootstrap"`
854
+ Params swingset.Params `json:"params"`
855
+ SupplyCoins sdk.Coins `json:"supplyCoins"`
856
+ UpgradePlan *upgradetypes.Plan `json:"upgradePlan,omitempty"`
857
+ LienPort int `json:"lienPort"`
858
+ StoragePort int `json:"storagePort"`
859
+ SwingsetPort int `json:"swingsetPort"`
860
+ VbankPort int `json:"vbankPort"`
861
+ VibcPort int `json:"vibcPort"`
845
862
  }
846
863
 
847
864
  // Name returns the name of the App
@@ -871,17 +888,18 @@ func (app *GaiaApp) initController(ctx sdk.Context, bootstrap bool) {
871
888
 
872
889
  // Begin initializing the controller here.
873
890
  action := &cosmosInitAction{
874
- Type: "AG_COSMOS_INIT",
875
- ChainID: ctx.ChainID(),
876
- BlockTime: blockTime,
877
- IsBootstrap: bootstrap,
878
- Params: app.SwingSetKeeper.GetParams(ctx),
879
- SupplyCoins: sdk.NewCoins(app.BankKeeper.GetSupply(ctx, "uist")),
880
- UpgradePlan: app.upgradePlan,
881
- LienPort: app.lienPort,
882
- StoragePort: app.vstoragePort,
883
- VbankPort: app.vbankPort,
884
- VibcPort: app.vibcPort,
891
+ Type: "AG_COSMOS_INIT",
892
+ ChainID: ctx.ChainID(),
893
+ BlockTime: blockTime,
894
+ IsBootstrap: bootstrap,
895
+ Params: app.SwingSetKeeper.GetParams(ctx),
896
+ SupplyCoins: sdk.NewCoins(app.BankKeeper.GetSupply(ctx, "uist")),
897
+ UpgradePlan: app.upgradePlan,
898
+ LienPort: app.lienPort,
899
+ StoragePort: app.vstoragePort,
900
+ SwingsetPort: app.swingsetPort,
901
+ VbankPort: app.vbankPort,
902
+ VibcPort: app.vibcPort,
885
903
  }
886
904
  // This really abuses `BlockingSend` to get back at `sendToController`
887
905
  out, err := app.SwingSetKeeper.BlockingSend(ctx, action)
package/git-revision.txt CHANGED
@@ -1 +1 @@
1
- 3573f79
1
+ fed2b5e
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agoric/cosmos",
3
- "version": "0.34.2-dev-3573f79.0+3573f79",
3
+ "version": "0.34.2-dev-fed2b5e.0+fed2b5e",
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": "3573f7960954eb22458f812066adcb0888e74363"
38
+ "gitHead": "fed2b5e4658fc5b55c794622aa1684a8093f1604"
39
39
  }
@@ -13,4 +13,14 @@ message GenesisState {
13
13
  Params params = 2 [(gogoproto.nullable) = false];
14
14
 
15
15
  State state = 3 [(gogoproto.nullable) = false];
16
+
17
+ repeated SwingStoreExportDataEntry swing_store_export_data = 4 [
18
+ (gogoproto.jsontag) = "swingStoreExportData"
19
+ ];
20
+ }
21
+
22
+ // A SwingStore "export data" entry.
23
+ message SwingStoreExportDataEntry {
24
+ string key = 1;
25
+ string value = 2;
16
26
  }
@@ -0,0 +1,114 @@
1
+ package types
2
+
3
+ import (
4
+ "encoding/json"
5
+ "fmt"
6
+ )
7
+
8
+ var _ json.Marshaler = &KVEntry{}
9
+ var _ json.Unmarshaler = &KVEntry{}
10
+
11
+ // KVEntry represents a string key / string value pair, where the value may be
12
+ // missing, which is different from an empty value.
13
+ // The semantics of a missing value are purpose-dependent rather than specified
14
+ // here, but frequently correspond with deletion/incompleteness/etc.
15
+ // A KVEntry with an empty key is considered invalid.
16
+ type KVEntry struct {
17
+ key string
18
+ value *string
19
+ }
20
+
21
+ // NewKVEntry creates a KVEntry with the provided key and value
22
+ func NewKVEntry(key string, value string) KVEntry {
23
+ return KVEntry{key, &value}
24
+ }
25
+
26
+ // NewKVEntryWithNoValue creates a KVEntry with the provided key and no value
27
+ func NewKVEntryWithNoValue(key string) KVEntry {
28
+ return KVEntry{key, nil}
29
+ }
30
+
31
+ // UnmarshalJSON updates a KVEntry from JSON text corresponding with a
32
+ // [key: string, value?: string | null] shape, or returns an error indicating
33
+ // invalid input.
34
+ // The key must be a non-empty string, and the value (if present) must be a
35
+ // string or null.
36
+ //
37
+ // Implements json.Unmarshaler
38
+ // Note: unlike other methods, this accepts a pointer to satisfy
39
+ // the Unmarshaler semantics.
40
+ func (entry *KVEntry) UnmarshalJSON(input []byte) (err error) {
41
+ var generic []*string
42
+ err = json.Unmarshal(input, &generic)
43
+ if err != nil {
44
+ return err
45
+ }
46
+
47
+ length := len(generic)
48
+
49
+ if generic == nil {
50
+ return fmt.Errorf("KVEntry cannot be null")
51
+ }
52
+ if length != 1 && length != 2 {
53
+ return fmt.Errorf("KVEntry must be an array of length 1 or 2 (not %d)", length)
54
+ }
55
+
56
+ key := generic[0]
57
+ if key == nil || *key == "" {
58
+ return fmt.Errorf("KVEntry key must be a non-empty string: %v", key)
59
+ }
60
+
61
+ var value *string
62
+ if length == 2 {
63
+ value = generic[1]
64
+ }
65
+
66
+ entry.key = *key
67
+ entry.value = value
68
+
69
+ return nil
70
+ }
71
+
72
+ // MarshalJSON encodes the KVEntry into a JSON array of [key: string, value?: string],
73
+ // with the value missing (array length of 1) if the entry has no value.
74
+ //
75
+ // Implements json.Marshaler
76
+ func (entry KVEntry) MarshalJSON() ([]byte, error) {
77
+ if !entry.IsValidKey() {
78
+ return nil, fmt.Errorf("cannot marshal invalid KVEntry")
79
+ }
80
+ if entry.value != nil {
81
+ return json.Marshal([2]string{entry.key, *entry.value})
82
+ } else {
83
+ return json.Marshal([1]string{entry.key})
84
+ }
85
+ }
86
+
87
+ // IsValidKey returns whether the KVEntry has a non-empty key.
88
+ func (entry KVEntry) IsValidKey() bool {
89
+ return entry.key != ""
90
+ }
91
+
92
+ // Key returns the string key.
93
+ func (entry KVEntry) Key() string {
94
+ return entry.key
95
+ }
96
+
97
+ // HasValue returns whether the KVEntry has a value or not.
98
+ func (entry KVEntry) HasValue() bool {
99
+ return entry.value != nil
100
+ }
101
+
102
+ // Value returns a pointer to the string value or nil if the entry has no value.
103
+ func (entry KVEntry) Value() *string {
104
+ return entry.value
105
+ }
106
+
107
+ // StringValue returns the string value, or the empty string if the entry has no value.
108
+ // Note that the result therefore does not differentiate an empty string value from no value.
109
+ func (entry KVEntry) StringValue() string {
110
+ if entry.value != nil {
111
+ return *entry.value
112
+ }
113
+ return ""
114
+ }
@@ -0,0 +1,234 @@
1
+ package types
2
+
3
+ import (
4
+ "encoding/json"
5
+ "fmt"
6
+ "io"
7
+
8
+ swingsettypes "github.com/Agoric/agoric-sdk/golang/cosmos/x/swingset/types"
9
+ vstoragetypes "github.com/Agoric/agoric-sdk/golang/cosmos/x/vstorage/types"
10
+ sdk "github.com/cosmos/cosmos-sdk/types"
11
+ )
12
+
13
+ // These helpers facilitate handling KVEntry streams, in particular for the
14
+ // swing-store "export data" use case. The goal is to avoid passing around
15
+ // large slices of key/value pairs.
16
+ //
17
+ // Handling of these streams is primarily accomplished through a KVEntryReader
18
+ // interface, with multiple implementations for different backing sources, as
19
+ // well as a helper function to consume a reader and write the entries into a
20
+ // byte Writer as line terminated json encoded KVEntry.
21
+
22
+ // We attempt to pass sdk.Iterator around as much as possible to abstract a
23
+ // stream of Key/Value pairs without requiring the whole slice to be held in
24
+ // memory if possible. Cosmos SDK defines iterators as yielding Key/Value
25
+ // pairs, both as byte slices.
26
+ //
27
+ // More precisely, we define here the following:
28
+ // - A KVEntryReader interface allowing to Read the KVEntry one by one from an
29
+ // underlying source.
30
+ // - Multiple implementations of the KVEntryReader interface:
31
+ // - NewKVIteratorReader constructs a reader which consumes an sdk.Iterator.
32
+ // Keys and values are converted from byte slices to strings, and nil values
33
+ // are preserved as KVEntry instances with no value.
34
+ // - A generic reader which uses a slice of key/value data, and a conversion
35
+ // function from that data type to a KVEntry. The reader does bounds
36
+ // checking and keeps track of the current position. The following data
37
+ // types are available:
38
+ // - NewVstorageDataEntriesReader constructs a reader from a slice of
39
+ // vstorage DataEntry values.
40
+ // - NewSwingStoreExportDataEntriesReader constructs a reader from a slice
41
+ // of SwingStoreExportDataEntry values.
42
+ // - NewJsonRawMessageKVEntriesReader constructs a reader from a slice of
43
+ // [key: string, value?: string | null] JSON array values.
44
+ // - NewJsonlKVEntryDecoderReader constructs a reader from an io.ReadCloser
45
+ // (like a file) containing JSON Lines in which each item is a
46
+ // [key: string, value?: string | null] array.
47
+ // - EncodeKVEntryReaderToJsonl consumes a KVEntryReader and writes its entries
48
+ // into an io.Writer as a sequence of single-line JSON texts. The encoding of
49
+ // each line is [key, value] if the KVEntry has a value, and [key] otherwise.
50
+ // This format terminates each line, but is still compatible with JSON Lines
51
+ // (which is line feed *separated*) for Go and JS decoders.
52
+
53
+ // KVEntryReader is an abstraction for iteratively reading KVEntry data.
54
+ type KVEntryReader interface {
55
+ // Read returns the next KVEntry, or an error.
56
+ // An `io.EOF` error indicates that the previous Read() returned the final KVEntry.
57
+ Read() (KVEntry, error)
58
+ // Close frees the underlying resource (such as a slice or file descriptor).
59
+ Close() error
60
+ }
61
+
62
+ var _ KVEntryReader = &kvIteratorReader{}
63
+
64
+ // kvIteratorReader is a KVEntryReader backed by an sdk.Iterator
65
+ type kvIteratorReader struct {
66
+ iter sdk.Iterator
67
+ }
68
+
69
+ // NewKVIteratorReader returns a KVEntryReader backed by an sdk.Iterator.
70
+ func NewKVIteratorReader(iter sdk.Iterator) KVEntryReader {
71
+ return &kvIteratorReader{
72
+ iter: iter,
73
+ }
74
+ }
75
+
76
+ // Read yields the next KVEntry from the source iterator
77
+ // Implements KVEntryReader
78
+ func (ir kvIteratorReader) Read() (next KVEntry, err error) {
79
+ if !ir.iter.Valid() {
80
+ // There is unfortunately no way to differentiate completion from iteration
81
+ // errors with the implementation of Iterators by cosmos-sdk since the
82
+ // iter.Error() returns an error in both cases
83
+ return KVEntry{}, io.EOF
84
+ }
85
+
86
+ key := ir.iter.Key()
87
+ if len(key) == 0 {
88
+ return KVEntry{}, fmt.Errorf("nil or empty key yielded by iterator")
89
+ }
90
+
91
+ value := ir.iter.Value()
92
+ ir.iter.Next()
93
+ if value == nil {
94
+ return NewKVEntryWithNoValue(string(key)), nil
95
+ } else {
96
+ return NewKVEntry(string(key), string(value)), nil
97
+ }
98
+ }
99
+
100
+ func (ir kvIteratorReader) Close() error {
101
+ return ir.iter.Close()
102
+ }
103
+
104
+ var _ KVEntryReader = &kvEntriesReader[any]{}
105
+
106
+ // kvEntriesReader is the KVEntryReader using an underlying slice of generic
107
+ // kv entries. It reads from the slice sequentially using a type specific
108
+ // toKVEntry func, performing bounds checks, and tracking the position.
109
+ type kvEntriesReader[T any] struct {
110
+ entries []T
111
+ toKVEntry func(T) (KVEntry, error)
112
+ nextIndex int
113
+ }
114
+
115
+ // Read yields the next KVEntry from the source
116
+ // Implements KVEntryReader
117
+ func (reader *kvEntriesReader[T]) Read() (next KVEntry, err error) {
118
+ if reader.entries == nil {
119
+ return KVEntry{}, fmt.Errorf("reader closed")
120
+ }
121
+
122
+ length := len(reader.entries)
123
+
124
+ if reader.nextIndex < length {
125
+ entry, err := reader.toKVEntry(reader.entries[reader.nextIndex])
126
+ reader.nextIndex += 1
127
+ if err != nil {
128
+ return KVEntry{}, err
129
+ }
130
+ if !entry.IsValidKey() {
131
+ return KVEntry{}, fmt.Errorf("source yielded a KVEntry with an invalid key")
132
+ }
133
+ return entry, err
134
+ } else if reader.nextIndex == length {
135
+ reader.nextIndex += 1
136
+ return KVEntry{}, io.EOF
137
+ } else {
138
+ return KVEntry{}, fmt.Errorf("index %d is out of source bounds (length %d)", reader.nextIndex, length)
139
+ }
140
+ }
141
+
142
+ // Close releases the source slice
143
+ // Implements KVEntryReader
144
+ func (reader *kvEntriesReader[any]) Close() error {
145
+ reader.entries = nil
146
+ return nil
147
+ }
148
+
149
+ // NewVstorageDataEntriesReader creates a KVEntryReader backed by a
150
+ // vstorage DataEntry slice
151
+ func NewVstorageDataEntriesReader(vstorageDataEntries []*vstoragetypes.DataEntry) KVEntryReader {
152
+ return &kvEntriesReader[*vstoragetypes.DataEntry]{
153
+ entries: vstorageDataEntries,
154
+ toKVEntry: func(sourceEntry *vstoragetypes.DataEntry) (KVEntry, error) {
155
+ return NewKVEntry(sourceEntry.Path, sourceEntry.Value), nil
156
+ },
157
+ }
158
+ }
159
+
160
+ // NewSwingStoreExportDataEntriesReader creates a KVEntryReader backed by
161
+ // a SwingStoreExportDataEntry slice
162
+ func NewSwingStoreExportDataEntriesReader(exportDataEntries []*swingsettypes.SwingStoreExportDataEntry) KVEntryReader {
163
+ return &kvEntriesReader[*swingsettypes.SwingStoreExportDataEntry]{
164
+ entries: exportDataEntries,
165
+ toKVEntry: func(sourceEntry *swingsettypes.SwingStoreExportDataEntry) (KVEntry, error) {
166
+ return NewKVEntry(sourceEntry.Key, sourceEntry.Value), nil
167
+ },
168
+ }
169
+ }
170
+
171
+ // NewJsonRawMessageKVEntriesReader creates a KVEntryReader backed by
172
+ // a json.RawMessage slice
173
+ func NewJsonRawMessageKVEntriesReader(jsonEntries []json.RawMessage) KVEntryReader {
174
+ return &kvEntriesReader[json.RawMessage]{
175
+ entries: jsonEntries,
176
+ toKVEntry: func(sourceEntry json.RawMessage) (entry KVEntry, err error) {
177
+ err = json.Unmarshal(sourceEntry, &entry)
178
+ return entry, err
179
+ },
180
+ }
181
+ }
182
+
183
+ var _ KVEntryReader = &jsonlKVEntryDecoderReader{}
184
+
185
+ // jsonlKVEntryDecoderReader is the KVEntryReader decoding
186
+ // jsonl-like encoded key/value pairs.
187
+ type jsonlKVEntryDecoderReader struct {
188
+ closer io.Closer
189
+ decoder *json.Decoder
190
+ }
191
+
192
+ // Read yields the next decoded KVEntry
193
+ // Implements KVEntryReader
194
+ func (reader jsonlKVEntryDecoderReader) Read() (next KVEntry, err error) {
195
+ err = reader.decoder.Decode(&next)
196
+ return next, err
197
+ }
198
+
199
+ // Close release the underlying resource backing the decoder
200
+ // Implements KVEntryReader
201
+ func (reader jsonlKVEntryDecoderReader) Close() error {
202
+ return reader.closer.Close()
203
+ }
204
+
205
+ // NewJsonlKVEntryDecoderReader creates a KVEntryReader over a byte
206
+ // stream reader that decodes each line as a json encoded KVEntry. The entries
207
+ // are yielded in order they're present in the stream.
208
+ func NewJsonlKVEntryDecoderReader(byteReader io.ReadCloser) KVEntryReader {
209
+ return &jsonlKVEntryDecoderReader{
210
+ closer: byteReader,
211
+ decoder: json.NewDecoder(byteReader),
212
+ }
213
+ }
214
+
215
+ // EncodeKVEntryReaderToJsonl consumes a KVEntryReader and JSON encodes each
216
+ // KVEntry, terminating by new lines.
217
+ // It will not Close the Reader when done
218
+ func EncodeKVEntryReaderToJsonl(reader KVEntryReader, bytesWriter io.Writer) (err error) {
219
+ encoder := json.NewEncoder(bytesWriter)
220
+ encoder.SetEscapeHTML(false)
221
+ for {
222
+ entry, err := reader.Read()
223
+ if err == io.EOF {
224
+ return nil
225
+ } else if err != nil {
226
+ return err
227
+ }
228
+
229
+ err = encoder.Encode(entry)
230
+ if err != nil {
231
+ return err
232
+ }
233
+ }
234
+ }