@agoric/cosmos 0.35.0-u21.0 → 0.35.0-u22.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/CHANGELOG.md +11 -187
- package/Makefile +2 -2
- package/ante/ante.go +2 -2
- package/ante/inbound.go +1 -2
- package/ante/inbound_test.go +3 -1
- package/ante/vm_admission.go +1 -2
- package/app/app.go +255 -174
- package/app/encoding.go +6 -3
- package/app/export.go +50 -21
- package/app/genesis.go +7 -5
- package/app/params/encoding.go +1 -1
- package/app/params/proto.go +6 -4
- package/app/sim_test.go +11 -13
- package/app/txconfig/tx_config.go +169 -0
- package/app/upgrade.go +52 -97
- package/app/upgrade_test.go +1 -1
- package/cmd/agd/agvm.go +1 -1
- package/cmd/agd/main.go +1 -1
- package/cmd/libdaemon/main.go +2 -2
- package/daemon/cmd/root.go +99 -30
- package/daemon/cmd/root_test.go +12 -27
- package/daemon/main.go +2 -9
- package/git-revision.txt +1 -1
- package/go.mod +129 -109
- package/go.sum +228 -469
- package/package.json +2 -2
- package/proto/agoric/swingset/msgs.proto +46 -9
- package/proto/agoric/swingset/swingset.proto +7 -2
- package/proto/agoric/vbank/vbank.proto +1 -1
- package/proto/agoric/vibc/msgs.proto +4 -0
- package/tests/e2e/vbank/vbank_test.go +172 -0
- package/tests/integrations/types/aminojson_test.go +214 -0
- package/tests/integrations/vbank/vbank_test.go +348 -0
- package/third_party/proto/amino/amino.proto +6 -1
- package/third_party/proto/cosmos/base/v1beta1/coin.proto +18 -5
- package/third_party/proto/cosmos/upgrade/v1beta1/upgrade.proto +4 -8
- package/third_party/proto/ibc/core/channel/v1/channel.proto +42 -17
- package/third_party/proto/ibc/core/client/v1/client.proto +48 -40
- package/types/address_hooks.go +2 -2
- package/types/address_hooks_test.go +3 -3
- package/types/ibc_packet.go +3 -3
- package/types/ibc_packet_test.go +3 -3
- package/types/kv_entry_helpers.go +3 -3
- package/types/kv_entry_helpers_test.go +2 -2
- package/types/legacy_address_encoder.go +58 -0
- package/vm/proto_json_test.go +1 -1
- package/vm/server.go +2 -1
- package/x/swingset/abci.go +2 -2
- package/x/swingset/client/cli/tx.go +16 -14
- package/x/swingset/config.go +1 -1
- package/x/swingset/genesis.go +2 -1
- package/x/swingset/handler.go +2 -1
- package/x/swingset/keeper/extension_snapshotter.go +14 -5
- package/x/swingset/keeper/extension_snapshotter_test.go +1 -1
- package/x/swingset/keeper/keeper.go +21 -17
- package/x/swingset/keeper/keeper_test.go +10 -7
- package/x/swingset/keeper/msg_server.go +26 -5
- package/x/swingset/keeper/swing_store_exports_handler.go +1 -1
- package/x/swingset/keeper/swing_store_exports_handler_test.go +1 -1
- package/x/swingset/module.go +20 -22
- package/x/swingset/types/codec.go +10 -5
- package/x/swingset/types/default-params.go +13 -12
- package/x/swingset/types/expected_keepers.go +5 -4
- package/x/swingset/types/msgs.go +50 -36
- package/x/swingset/types/msgs.pb.go +60 -51
- package/x/swingset/types/params_test.go +21 -20
- package/x/swingset/types/swingset.pb.go +67 -61
- package/x/vbank/genesis.go +12 -8
- package/x/vbank/handler.go +2 -1
- package/x/vbank/keeper/grpc_query.go +4 -1
- package/x/vbank/keeper/keeper.go +108 -23
- package/x/vbank/keeper/querier.go +4 -1
- package/x/vbank/keeper/rewards.go +6 -2
- package/x/vbank/module.go +47 -75
- package/x/vbank/types/expected_keepers.go +15 -10
- package/x/vbank/types/key.go +3 -0
- package/x/vbank/types/params.go +4 -3
- package/x/vbank/types/vbank.pb.go +41 -40
- package/x/vbank/vbank.go +25 -10
- package/x/vbank/vbank_test.go +213 -154
- package/x/vibc/handler.go +2 -1
- package/x/vibc/keeper/keeper.go +10 -10
- package/x/vibc/keeper/migrations.go +1 -1
- package/x/vibc/keeper/triggers.go +1 -1
- package/x/vibc/module.go +5 -22
- package/x/vibc/types/codec.go +2 -1
- package/x/vibc/types/expected_keepers.go +7 -5
- package/x/vibc/types/ibc_module.go +5 -5
- package/x/vibc/types/msgs.go +30 -7
- package/x/vibc/types/msgs.pb.go +29 -25
- package/x/vibc/types/receiver.go +2 -2
- package/x/vlocalchain/handler.go +2 -1
- package/x/vlocalchain/keeper/keeper.go +17 -5
- package/x/vlocalchain/keeper/keeper_test.go +3 -2
- package/x/vlocalchain/types/expected_keepers.go +7 -4
- package/x/vlocalchain/vlocalchain_test.go +38 -26
- package/x/vstorage/genesis.go +10 -10
- package/x/vstorage/handler.go +2 -1
- package/x/vstorage/keeper/keeper.go +68 -46
- package/x/vstorage/keeper/keeper_test.go +35 -19
- package/x/vstorage/module.go +27 -13
- package/x/vstorage/testing/queue.go +5 -3
- package/x/vstorage/vstorage.go +2 -1
- package/x/vstorage/vstorage_test.go +21 -17
- package/x/vtransfer/genesis.go +1 -3
- package/x/vtransfer/handler.go +3 -2
- package/x/vtransfer/ibc_middleware.go +5 -5
- package/x/vtransfer/ibc_middleware_test.go +43 -29
- package/x/vtransfer/keeper/keeper.go +35 -33
- package/x/vtransfer/module.go +8 -11
- package/x/vtransfer/types/expected_keepers.go +3 -3
- package/x/vtransfer/utils_test.go +26 -11
- package/daemon/cmd/testnet.go +0 -539
|
@@ -10,12 +10,14 @@ import (
|
|
|
10
10
|
"strconv"
|
|
11
11
|
"strings"
|
|
12
12
|
|
|
13
|
+
corestore "cosmossdk.io/core/store"
|
|
13
14
|
sdkmath "cosmossdk.io/math"
|
|
14
|
-
|
|
15
|
-
db "github.com/
|
|
16
|
-
|
|
15
|
+
storetypes "cosmossdk.io/store/types"
|
|
16
|
+
db "github.com/cosmos/cosmos-db"
|
|
17
|
+
"github.com/cosmos/cosmos-sdk/runtime"
|
|
17
18
|
"github.com/cosmos/cosmos-sdk/telemetry"
|
|
18
19
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
20
|
+
metrics "github.com/hashicorp/go-metrics"
|
|
19
21
|
|
|
20
22
|
agoric "github.com/Agoric/agoric-sdk/golang/cosmos/types"
|
|
21
23
|
"github.com/Agoric/agoric-sdk/golang/cosmos/x/vstorage/types"
|
|
@@ -39,9 +41,9 @@ type ProposedChange struct {
|
|
|
39
41
|
}
|
|
40
42
|
|
|
41
43
|
type ChangeManager interface {
|
|
42
|
-
Track(ctx sdk.Context, k Keeper, entry agoric.KVEntry, isLegacy bool)
|
|
43
|
-
EmitEvents(ctx sdk.Context, k Keeper)
|
|
44
|
-
Rollback(ctx sdk.Context)
|
|
44
|
+
Track(ctx sdk.Context, k Keeper, entry agoric.KVEntry, isLegacy bool) error
|
|
45
|
+
EmitEvents(ctx sdk.Context, k Keeper) error
|
|
46
|
+
Rollback(ctx sdk.Context) error
|
|
45
47
|
}
|
|
46
48
|
|
|
47
49
|
type BatchingChangeManager struct {
|
|
@@ -52,16 +54,17 @@ type BatchingChangeManager struct {
|
|
|
52
54
|
var _ ChangeManager = (*BatchingChangeManager)(nil)
|
|
53
55
|
|
|
54
56
|
// 2 ** 256 - 1
|
|
55
|
-
var MaxSDKInt =
|
|
57
|
+
var MaxSDKInt = sdkmath.NewIntFromBigInt(new(big.Int).Sub(new(big.Int).Exp(big.NewInt(2), big.NewInt(256), nil), big.NewInt(1)))
|
|
56
58
|
|
|
57
59
|
// Keeper maintains the link to data storage and exposes getter/setter methods
|
|
58
60
|
// for the various parts of the state machine
|
|
59
61
|
type Keeper struct {
|
|
62
|
+
storeName string // The name of the store, used for telemetry.
|
|
63
|
+
storeService corestore.KVStoreService
|
|
60
64
|
changeManager ChangeManager
|
|
61
|
-
storeKey storetypes.StoreKey
|
|
62
65
|
}
|
|
63
66
|
|
|
64
|
-
func (bcm *BatchingChangeManager) Track(ctx sdk.Context, k Keeper, entry agoric.KVEntry, isLegacy bool) {
|
|
67
|
+
func (bcm *BatchingChangeManager) Track(ctx sdk.Context, k Keeper, entry agoric.KVEntry, isLegacy bool) error {
|
|
65
68
|
path := entry.Key()
|
|
66
69
|
// TODO: differentiate between deletion and setting empty string?
|
|
67
70
|
// Using empty string for deletion for backwards compatibility
|
|
@@ -71,7 +74,7 @@ func (bcm *BatchingChangeManager) Track(ctx sdk.Context, k Keeper, entry agoric.
|
|
|
71
74
|
if isLegacy {
|
|
72
75
|
change.LegacyEvents = true
|
|
73
76
|
}
|
|
74
|
-
return
|
|
77
|
+
return nil
|
|
75
78
|
}
|
|
76
79
|
bcm.changes[path] = &ProposedChange{
|
|
77
80
|
Path: path,
|
|
@@ -79,18 +82,20 @@ func (bcm *BatchingChangeManager) Track(ctx sdk.Context, k Keeper, entry agoric.
|
|
|
79
82
|
ValueFromLastBlock: k.GetEntry(ctx, path).StringValue(),
|
|
80
83
|
LegacyEvents: isLegacy,
|
|
81
84
|
}
|
|
85
|
+
return nil
|
|
82
86
|
}
|
|
83
87
|
|
|
84
|
-
func (bcm *BatchingChangeManager) Rollback(ctx sdk.Context) {
|
|
88
|
+
func (bcm *BatchingChangeManager) Rollback(ctx sdk.Context) error {
|
|
85
89
|
bcm.changes = make(map[string]*ProposedChange)
|
|
90
|
+
return nil
|
|
86
91
|
}
|
|
87
92
|
|
|
88
93
|
// EmitEvents emits events for all actual changes.
|
|
89
94
|
// This does not clear the cache, so the caller must call Rollback() to do so.
|
|
90
|
-
func (bcm *BatchingChangeManager) EmitEvents(ctx sdk.Context, k Keeper) {
|
|
95
|
+
func (bcm *BatchingChangeManager) EmitEvents(ctx sdk.Context, k Keeper) error {
|
|
91
96
|
changes := bcm.changes
|
|
92
97
|
if len(changes) == 0 {
|
|
93
|
-
return
|
|
98
|
+
return nil
|
|
94
99
|
}
|
|
95
100
|
|
|
96
101
|
// Deterministic order.
|
|
@@ -104,6 +109,8 @@ func (bcm *BatchingChangeManager) EmitEvents(ctx sdk.Context, k Keeper) {
|
|
|
104
109
|
change := bcm.changes[path]
|
|
105
110
|
k.EmitChange(ctx, change)
|
|
106
111
|
}
|
|
112
|
+
|
|
113
|
+
return nil
|
|
107
114
|
}
|
|
108
115
|
|
|
109
116
|
// The BatchingChangeManager needs to be a pointer because its state is mutated.
|
|
@@ -112,14 +119,15 @@ func NewBatchingChangeManager() *BatchingChangeManager {
|
|
|
112
119
|
return &bcm
|
|
113
120
|
}
|
|
114
121
|
|
|
115
|
-
func NewKeeper(
|
|
122
|
+
func NewKeeper(storeName string, storeService corestore.KVStoreService) Keeper {
|
|
116
123
|
return Keeper{
|
|
117
|
-
|
|
124
|
+
storeName: storeName,
|
|
125
|
+
storeService: storeService,
|
|
118
126
|
changeManager: NewBatchingChangeManager(),
|
|
119
127
|
}
|
|
120
128
|
}
|
|
121
129
|
|
|
122
|
-
// size_increase and
|
|
130
|
+
// size_increase and size_decπrease metrics represent total writes and deletes *issued*
|
|
123
131
|
// respectively, which may differ from the total number of bytes committed/freed
|
|
124
132
|
// to/from the store due to the store's internal implementation.
|
|
125
133
|
var MetricKeyStoreSizeIncrease = []string{"store", "size_increase"}
|
|
@@ -131,7 +139,7 @@ const MetricLabelStoreKey = "storeKey"
|
|
|
131
139
|
// when Cosmos telemetry is enabled.
|
|
132
140
|
func (k Keeper) reportStoreSizeMetrics(increase int, decrease int) {
|
|
133
141
|
metricsLabel := []metrics.Label{
|
|
134
|
-
telemetry.NewLabel(MetricLabelStoreKey, k.
|
|
142
|
+
telemetry.NewLabel(MetricLabelStoreKey, k.GetStoreName()),
|
|
135
143
|
}
|
|
136
144
|
if increase > 0 {
|
|
137
145
|
telemetry.IncrCounterWithLabels(MetricKeyStoreSizeIncrease, float32(increase), metricsLabel)
|
|
@@ -142,17 +150,17 @@ func (k Keeper) reportStoreSizeMetrics(increase int, decrease int) {
|
|
|
142
150
|
}
|
|
143
151
|
|
|
144
152
|
// ExportStorage fetches all storage
|
|
145
|
-
func (k Keeper) ExportStorage(ctx sdk.Context) []*types.DataEntry {
|
|
153
|
+
func (k Keeper) ExportStorage(ctx sdk.Context) ([]*types.DataEntry, error) {
|
|
146
154
|
return k.ExportStorageFromPrefix(ctx, "")
|
|
147
155
|
}
|
|
148
156
|
|
|
149
157
|
// ExportStorageFromPrefix fetches storage only under the supplied pathPrefix.
|
|
150
|
-
func (k Keeper) ExportStorageFromPrefix(ctx sdk.Context, pathPrefix string) []*types.DataEntry {
|
|
151
|
-
store :=
|
|
158
|
+
func (k Keeper) ExportStorageFromPrefix(ctx sdk.Context, pathPrefix string) ([]*types.DataEntry, error) {
|
|
159
|
+
store := k.storeService.OpenKVStore(ctx)
|
|
152
160
|
|
|
153
161
|
if len(pathPrefix) > 0 {
|
|
154
162
|
if err := types.ValidatePath(pathPrefix); err != nil {
|
|
155
|
-
|
|
163
|
+
return nil, err
|
|
156
164
|
}
|
|
157
165
|
pathPrefix = pathPrefix + types.PathSeparator
|
|
158
166
|
}
|
|
@@ -164,10 +172,11 @@ func (k Keeper) ExportStorageFromPrefix(ctx sdk.Context, pathPrefix string) []*t
|
|
|
164
172
|
// entries will be exported. An alternative implementation would be to
|
|
165
173
|
// recursively list all children under the pathPrefix, and export them.
|
|
166
174
|
|
|
167
|
-
|
|
175
|
+
kvstore := runtime.KVStoreAdapter(store)
|
|
176
|
+
iterator := storetypes.KVStorePrefixIterator(kvstore, nil)
|
|
177
|
+
defer iterator.Close()
|
|
168
178
|
|
|
169
179
|
exported := []*types.DataEntry{}
|
|
170
|
-
defer iterator.Close()
|
|
171
180
|
for ; iterator.Valid(); iterator.Next() {
|
|
172
181
|
rawValue := iterator.Value()
|
|
173
182
|
if len(rawValue) == 0 {
|
|
@@ -182,26 +191,28 @@ func (k Keeper) ExportStorageFromPrefix(ctx sdk.Context, pathPrefix string) []*t
|
|
|
182
191
|
}
|
|
183
192
|
value, hasPrefix := bytes.CutPrefix(rawValue, types.EncodedDataPrefix)
|
|
184
193
|
if !hasPrefix {
|
|
185
|
-
|
|
194
|
+
return nil, fmt.Errorf("value at path %q starts with unexpected prefix", path)
|
|
186
195
|
}
|
|
187
196
|
path = path[len(pathPrefix):]
|
|
188
197
|
entry := types.DataEntry{Path: path, Value: string(value)}
|
|
189
198
|
exported = append(exported, &entry)
|
|
190
199
|
}
|
|
191
|
-
return exported
|
|
200
|
+
return exported, nil
|
|
192
201
|
}
|
|
193
202
|
|
|
194
|
-
func (k Keeper) ImportStorage(ctx sdk.Context, entries []*types.DataEntry) {
|
|
203
|
+
func (k Keeper) ImportStorage(ctx sdk.Context, entries []*types.DataEntry) error {
|
|
195
204
|
for _, entry := range entries {
|
|
196
205
|
// This set does the bookkeeping for us in case the entries aren't a
|
|
197
206
|
// complete tree.
|
|
198
207
|
k.SetStorage(ctx, agoric.NewKVEntry(entry.Path, entry.Value))
|
|
199
208
|
}
|
|
209
|
+
return nil
|
|
200
210
|
}
|
|
201
211
|
|
|
202
|
-
func getEncodedKeysWithPrefixFromIterator(iterator
|
|
203
|
-
keys := make([][]byte, 0)
|
|
212
|
+
func getEncodedKeysWithPrefixFromIterator(iterator storetypes.Iterator, prefix string) [][]byte {
|
|
204
213
|
defer iterator.Close()
|
|
214
|
+
|
|
215
|
+
keys := make([][]byte, 0)
|
|
205
216
|
for ; iterator.Valid(); iterator.Next() {
|
|
206
217
|
key := iterator.Key()
|
|
207
218
|
path := types.EncodedKeyToPath(key)
|
|
@@ -217,7 +228,8 @@ func getEncodedKeysWithPrefixFromIterator(iterator sdk.Iterator, prefix string)
|
|
|
217
228
|
// It has the same effect as listing children of the prefix and removing each
|
|
218
229
|
// descendant recursively.
|
|
219
230
|
func (k Keeper) RemoveEntriesWithPrefix(ctx sdk.Context, pathPrefix string) {
|
|
220
|
-
|
|
231
|
+
kvstore := k.storeService.OpenKVStore(ctx)
|
|
232
|
+
store := runtime.KVStoreAdapter(kvstore)
|
|
221
233
|
|
|
222
234
|
if len(pathPrefix) == 0 {
|
|
223
235
|
panic("cannot remove all content")
|
|
@@ -234,7 +246,7 @@ func (k Keeper) RemoveEntriesWithPrefix(ctx sdk.Context, pathPrefix string) {
|
|
|
234
246
|
// entries will be deleted. An alternative implementation would be to
|
|
235
247
|
// recursively list all children under the descendantPrefix, and delete them.
|
|
236
248
|
|
|
237
|
-
iterator :=
|
|
249
|
+
iterator := storetypes.KVStorePrefixIterator(store, nil)
|
|
238
250
|
|
|
239
251
|
keys := getEncodedKeysWithPrefixFromIterator(iterator, descendantPrefix)
|
|
240
252
|
|
|
@@ -275,7 +287,9 @@ func (k Keeper) EmitChange(ctx sdk.Context, change *ProposedChange) {
|
|
|
275
287
|
// GetEntry gets generic storage. The default value is an empty string.
|
|
276
288
|
func (k Keeper) GetEntry(ctx sdk.Context, path string) agoric.KVEntry {
|
|
277
289
|
//fmt.Printf("GetEntry(%s)\n", path);
|
|
278
|
-
|
|
290
|
+
kvstore := k.storeService.OpenKVStore(ctx)
|
|
291
|
+
store := runtime.KVStoreAdapter(kvstore)
|
|
292
|
+
|
|
279
293
|
encodedKey := types.PathToEncodedKey(path)
|
|
280
294
|
rawValue := store.Get(encodedKey)
|
|
281
295
|
if len(rawValue) == 0 {
|
|
@@ -292,19 +306,20 @@ func (k Keeper) GetEntry(ctx sdk.Context, path string) agoric.KVEntry {
|
|
|
292
306
|
}
|
|
293
307
|
|
|
294
308
|
func (k Keeper) getKeyIterator(ctx sdk.Context, path string) db.Iterator {
|
|
295
|
-
|
|
309
|
+
kvstore := k.storeService.OpenKVStore(ctx)
|
|
310
|
+
store := runtime.KVStoreAdapter(kvstore)
|
|
296
311
|
keyPrefix := types.PathToChildrenPrefix(path)
|
|
297
312
|
|
|
298
|
-
return
|
|
313
|
+
return storetypes.KVStorePrefixIterator(store, keyPrefix)
|
|
299
314
|
}
|
|
300
315
|
|
|
301
316
|
// GetChildren gets all vstorage child children at a given path
|
|
302
317
|
func (k Keeper) GetChildren(ctx sdk.Context, path string) *types.Children {
|
|
303
318
|
iterator := k.getKeyIterator(ctx, path)
|
|
319
|
+
defer iterator.Close()
|
|
304
320
|
|
|
305
321
|
var children types.Children
|
|
306
322
|
children.Children = []string{}
|
|
307
|
-
defer iterator.Close()
|
|
308
323
|
for ; iterator.Valid(); iterator.Next() {
|
|
309
324
|
parts := strings.Split(types.EncodedKeyToPath(iterator.Key()), types.PathSeparator)
|
|
310
325
|
childrentr := parts[len(parts)-1]
|
|
@@ -322,14 +337,16 @@ func (k Keeper) HasStorage(ctx sdk.Context, path string) bool {
|
|
|
322
337
|
|
|
323
338
|
// HasEntry tells if a given path has either subnodes or data.
|
|
324
339
|
func (k Keeper) HasEntry(ctx sdk.Context, path string) bool {
|
|
325
|
-
|
|
340
|
+
kvstore := k.storeService.OpenKVStore(ctx)
|
|
341
|
+
store := runtime.KVStoreAdapter(kvstore)
|
|
342
|
+
|
|
326
343
|
encodedKey := types.PathToEncodedKey(path)
|
|
327
344
|
|
|
328
345
|
// Check if we have a path entry.
|
|
329
346
|
return store.Has(encodedKey)
|
|
330
347
|
}
|
|
331
348
|
|
|
332
|
-
// HasChildren tells if a given path has child
|
|
349
|
+
// HasChildren tells if a given path has child nodes.
|
|
333
350
|
func (k Keeper) HasChildren(ctx sdk.Context, path string) bool {
|
|
334
351
|
// Check if we have children.
|
|
335
352
|
iterator := k.getKeyIterator(ctx, path)
|
|
@@ -337,13 +354,16 @@ func (k Keeper) HasChildren(ctx sdk.Context, path string) bool {
|
|
|
337
354
|
return iterator.Valid()
|
|
338
355
|
}
|
|
339
356
|
|
|
340
|
-
func (k Keeper) NewChangeBatch(ctx sdk.Context) {
|
|
341
|
-
k.changeManager.Rollback(ctx)
|
|
357
|
+
func (k Keeper) NewChangeBatch(ctx sdk.Context) error {
|
|
358
|
+
return k.changeManager.Rollback(ctx)
|
|
342
359
|
}
|
|
343
360
|
|
|
344
|
-
func (k Keeper) FlushChangeEvents(ctx sdk.Context) {
|
|
345
|
-
k.changeManager.EmitEvents(ctx, k)
|
|
346
|
-
|
|
361
|
+
func (k Keeper) FlushChangeEvents(ctx sdk.Context) error {
|
|
362
|
+
if err := k.changeManager.EmitEvents(ctx, k); err != nil {
|
|
363
|
+
return err
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
return k.changeManager.Rollback(ctx)
|
|
347
367
|
}
|
|
348
368
|
|
|
349
369
|
func (k Keeper) SetStorageAndNotify(ctx sdk.Context, entry agoric.KVEntry) {
|
|
@@ -389,7 +409,9 @@ func componentsToPath(components []string) string {
|
|
|
389
409
|
// Maintains the invariant: path entries exist if and only if self or some
|
|
390
410
|
// descendant has non-empty storage
|
|
391
411
|
func (k Keeper) SetStorage(ctx sdk.Context, entry agoric.KVEntry) {
|
|
392
|
-
|
|
412
|
+
kvstore := k.storeService.OpenKVStore(ctx)
|
|
413
|
+
store := runtime.KVStoreAdapter(kvstore)
|
|
414
|
+
|
|
393
415
|
path := entry.Key()
|
|
394
416
|
encodedKey := types.PathToEncodedKey(path)
|
|
395
417
|
oldRawValue := store.Get(encodedKey)
|
|
@@ -445,7 +467,7 @@ func (k Keeper) PathToEncodedKey(path string) []byte {
|
|
|
445
467
|
}
|
|
446
468
|
|
|
447
469
|
func (k Keeper) GetStoreName() string {
|
|
448
|
-
return k.
|
|
470
|
+
return k.storeName
|
|
449
471
|
}
|
|
450
472
|
|
|
451
473
|
func (k Keeper) GetDataPrefix() []byte {
|
|
@@ -459,10 +481,10 @@ func (k Keeper) GetNoDataValue() []byte {
|
|
|
459
481
|
func (k Keeper) GetIntValue(ctx sdk.Context, path string) (sdkmath.Int, error) {
|
|
460
482
|
indexEntry := k.GetEntry(ctx, path)
|
|
461
483
|
if !indexEntry.HasValue() {
|
|
462
|
-
return
|
|
484
|
+
return sdkmath.NewInt(0), nil
|
|
463
485
|
}
|
|
464
486
|
|
|
465
|
-
index, ok :=
|
|
487
|
+
index, ok := sdkmath.NewIntFromString(indexEntry.StringValue())
|
|
466
488
|
if !ok {
|
|
467
489
|
return index, fmt.Errorf("couldn't parse %s as Int: %s", path, indexEntry.StringValue())
|
|
468
490
|
}
|
|
@@ -493,7 +515,7 @@ func (k Keeper) PushQueueItem(ctx sdk.Context, queuePath string, value string) e
|
|
|
493
515
|
if tail.GTE(MaxSDKInt) {
|
|
494
516
|
return errors.New(queuePath + " overflow")
|
|
495
517
|
}
|
|
496
|
-
nextTail := tail.Add(
|
|
518
|
+
nextTail := tail.Add(sdkmath.NewInt(1))
|
|
497
519
|
|
|
498
520
|
// Set the vstorage corresponding to the queue entry for the current tail.
|
|
499
521
|
path := queuePath + "." + tail.String()
|
|
@@ -4,16 +4,17 @@ import (
|
|
|
4
4
|
"reflect"
|
|
5
5
|
"testing"
|
|
6
6
|
|
|
7
|
+
"cosmossdk.io/store"
|
|
8
|
+
storemetrics "cosmossdk.io/store/metrics"
|
|
9
|
+
storetypes "cosmossdk.io/store/types"
|
|
7
10
|
agoric "github.com/Agoric/agoric-sdk/golang/cosmos/types"
|
|
8
11
|
"github.com/Agoric/agoric-sdk/golang/cosmos/x/vstorage/types"
|
|
9
|
-
|
|
10
|
-
"github.com/cosmos/cosmos-
|
|
11
|
-
|
|
12
|
+
abcitypes "github.com/cometbft/cometbft/abci/types"
|
|
13
|
+
dbm "github.com/cosmos/cosmos-db"
|
|
14
|
+
"github.com/cosmos/cosmos-sdk/runtime"
|
|
12
15
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
13
16
|
|
|
14
|
-
|
|
15
|
-
abci "github.com/cometbft/cometbft/abci/types"
|
|
16
|
-
"github.com/cometbft/cometbft/libs/log"
|
|
17
|
+
"cosmossdk.io/log"
|
|
17
18
|
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
|
|
18
19
|
)
|
|
19
20
|
|
|
@@ -27,10 +28,9 @@ type testKit struct {
|
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
func makeTestKit() testKit {
|
|
30
|
-
keeper := NewKeeper(vstorageStoreKey)
|
|
31
|
-
|
|
32
31
|
db := dbm.NewMemDB()
|
|
33
|
-
|
|
32
|
+
logger := log.NewNopLogger()
|
|
33
|
+
ms := store.NewCommitMultiStore(db, logger, storemetrics.NewNoOpMetrics())
|
|
34
34
|
ms.MountStoreWithDB(vstorageStoreKey, storetypes.StoreTypeIAVL, db)
|
|
35
35
|
err := ms.LoadLatestVersion()
|
|
36
36
|
if err != nil {
|
|
@@ -38,6 +38,9 @@ func makeTestKit() testKit {
|
|
|
38
38
|
}
|
|
39
39
|
ctx := sdk.NewContext(ms, tmproto.Header{}, false, log.NewNopLogger())
|
|
40
40
|
|
|
41
|
+
storeService := runtime.NewKVStoreService(vstorageStoreKey)
|
|
42
|
+
keeper := NewKeeper(types.StoreKey, storeService)
|
|
43
|
+
|
|
41
44
|
return testKit{ctx, keeper}
|
|
42
45
|
}
|
|
43
46
|
|
|
@@ -171,7 +174,10 @@ func TestStorage(t *testing.T) {
|
|
|
171
174
|
{Path: "key2.child2.grandchild2", Value: "value2grandchild"},
|
|
172
175
|
{Path: "key2.child2.grandchild2a", Value: "value2grandchilda"},
|
|
173
176
|
}
|
|
174
|
-
gotExport := keeper.ExportStorage(ctx)
|
|
177
|
+
gotExport, err := keeper.ExportStorage(ctx)
|
|
178
|
+
if err != nil {
|
|
179
|
+
t.Errorf("ExportStorage failed: %v", err)
|
|
180
|
+
}
|
|
175
181
|
if !reflect.DeepEqual(gotExport, expectedExport) {
|
|
176
182
|
t.Errorf("got export %q, want %q", gotExport, expectedExport)
|
|
177
183
|
}
|
|
@@ -181,7 +187,11 @@ func TestStorage(t *testing.T) {
|
|
|
181
187
|
{Path: "child2.grandchild2", Value: "value2grandchild"},
|
|
182
188
|
{Path: "child2.grandchild2a", Value: "value2grandchilda"},
|
|
183
189
|
}
|
|
184
|
-
|
|
190
|
+
got, err := keeper.ExportStorageFromPrefix(ctx, "key2")
|
|
191
|
+
if err != nil {
|
|
192
|
+
t.Errorf("ExportStorageFromPrefix failed: %v", err)
|
|
193
|
+
}
|
|
194
|
+
if !reflect.DeepEqual(got, expectedKey2Export) {
|
|
185
195
|
t.Errorf("got export %q, want %q", got, expectedKey2Export)
|
|
186
196
|
}
|
|
187
197
|
|
|
@@ -194,13 +204,19 @@ func TestStorage(t *testing.T) {
|
|
|
194
204
|
{Path: "beta3", Value: "value3"},
|
|
195
205
|
{Path: "inited", Value: ""},
|
|
196
206
|
}
|
|
197
|
-
gotRemainingExport := keeper.ExportStorage(ctx)
|
|
207
|
+
gotRemainingExport, err := keeper.ExportStorage(ctx)
|
|
208
|
+
if err != nil {
|
|
209
|
+
t.Errorf("ExportStorage failed: %v", err)
|
|
210
|
+
}
|
|
198
211
|
if !reflect.DeepEqual(gotRemainingExport, expectedRemainingExport) {
|
|
199
212
|
t.Errorf("got remaining export %q, want %q", expectedRemainingExport, expectedRemainingExport)
|
|
200
213
|
}
|
|
201
214
|
|
|
202
215
|
keeper.ImportStorage(ctx, gotExport)
|
|
203
|
-
gotExport = keeper.ExportStorage(ctx)
|
|
216
|
+
gotExport, err = keeper.ExportStorage(ctx)
|
|
217
|
+
if err != nil {
|
|
218
|
+
t.Errorf("ExportStorage failed: %v", err)
|
|
219
|
+
}
|
|
204
220
|
if !reflect.DeepEqual(gotExport, expectedExport) {
|
|
205
221
|
t.Errorf("got export %q after import, want %q", gotExport, expectedExport)
|
|
206
222
|
}
|
|
@@ -226,14 +242,14 @@ func TestStorageNotify(t *testing.T) {
|
|
|
226
242
|
expectedAfterFlushEvents := sdk.Events{
|
|
227
243
|
{
|
|
228
244
|
Type: "storage",
|
|
229
|
-
Attributes: []
|
|
245
|
+
Attributes: []abcitypes.EventAttribute{
|
|
230
246
|
{Key: "path", Value: "notify.legacy"},
|
|
231
247
|
{Key: "value", Value: "legacyValue"},
|
|
232
248
|
},
|
|
233
249
|
},
|
|
234
250
|
{
|
|
235
251
|
Type: "state_change",
|
|
236
|
-
Attributes: []
|
|
252
|
+
Attributes: []abcitypes.EventAttribute{
|
|
237
253
|
{Key: "store", Value: "vstorage"},
|
|
238
254
|
{Key: "key", Value: "2\x00notify\x00legacy"},
|
|
239
255
|
{Key: "anckey", Value: "\x012\x00notify\x00legacy\x01"},
|
|
@@ -242,14 +258,14 @@ func TestStorageNotify(t *testing.T) {
|
|
|
242
258
|
},
|
|
243
259
|
{
|
|
244
260
|
Type: "storage",
|
|
245
|
-
Attributes: []
|
|
261
|
+
Attributes: []abcitypes.EventAttribute{
|
|
246
262
|
{Key: "path", Value: "notify.legacy2"},
|
|
247
263
|
{Key: "value", Value: "legacyValue2b"},
|
|
248
264
|
},
|
|
249
265
|
},
|
|
250
266
|
{
|
|
251
267
|
Type: "state_change",
|
|
252
|
-
Attributes: []
|
|
268
|
+
Attributes: []abcitypes.EventAttribute{
|
|
253
269
|
{Key: "store", Value: "vstorage"},
|
|
254
270
|
{Key: "key", Value: "2\x00notify\x00legacy2"},
|
|
255
271
|
{Key: "anckey", Value: "\x012\x00notify\x00legacy2\x01"},
|
|
@@ -258,7 +274,7 @@ func TestStorageNotify(t *testing.T) {
|
|
|
258
274
|
},
|
|
259
275
|
{
|
|
260
276
|
Type: "state_change",
|
|
261
|
-
Attributes: []
|
|
277
|
+
Attributes: []abcitypes.EventAttribute{
|
|
262
278
|
{Key: "store", Value: "vstorage"},
|
|
263
279
|
{Key: "key", Value: "2\x00notify\x00noLegacy"},
|
|
264
280
|
{Key: "anckey", Value: "\x012\x00notify\x00noLegacy\x01"},
|
|
@@ -267,7 +283,7 @@ func TestStorageNotify(t *testing.T) {
|
|
|
267
283
|
},
|
|
268
284
|
{
|
|
269
285
|
Type: "state_change",
|
|
270
|
-
Attributes: []
|
|
286
|
+
Attributes: []abcitypes.EventAttribute{
|
|
271
287
|
{Key: "store", Value: "vstorage"},
|
|
272
288
|
{Key: "key", Value: "2\x00notify\x00noLegacy2"},
|
|
273
289
|
{Key: "anckey", Value: "\x012\x00notify\x00noLegacy2\x01"},
|
package/x/vstorage/module.go
CHANGED
|
@@ -4,6 +4,7 @@ import (
|
|
|
4
4
|
"context"
|
|
5
5
|
"encoding/json"
|
|
6
6
|
|
|
7
|
+
"cosmossdk.io/core/appmodule"
|
|
7
8
|
"github.com/grpc-ecosystem/grpc-gateway/runtime"
|
|
8
9
|
"github.com/spf13/cobra"
|
|
9
10
|
|
|
@@ -15,14 +16,16 @@ import (
|
|
|
15
16
|
cdctypes "github.com/cosmos/cosmos-sdk/codec/types"
|
|
16
17
|
"github.com/cosmos/cosmos-sdk/types/module"
|
|
17
18
|
|
|
18
|
-
abci "github.com/cometbft/cometbft/abci/types"
|
|
19
19
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
20
20
|
)
|
|
21
21
|
|
|
22
22
|
// type check to ensure the interface is properly implemented
|
|
23
23
|
var (
|
|
24
|
-
_ module.AppModule
|
|
25
|
-
_ module.
|
|
24
|
+
_ module.AppModule = AppModule{}
|
|
25
|
+
_ module.HasGenesis = AppModule{}
|
|
26
|
+
_ module.AppModuleBasic = AppModuleBasic{}
|
|
27
|
+
_ appmodule.HasBeginBlocker = AppModule{}
|
|
28
|
+
_ appmodule.HasEndBlocker = AppModule{}
|
|
26
29
|
)
|
|
27
30
|
|
|
28
31
|
// app module Basics object
|
|
@@ -75,6 +78,12 @@ type AppModule struct {
|
|
|
75
78
|
keeper Keeper
|
|
76
79
|
}
|
|
77
80
|
|
|
81
|
+
// IsAppModule implements the appmodule.AppModule interface.
|
|
82
|
+
func (am AppModule) IsAppModule() {}
|
|
83
|
+
|
|
84
|
+
// IsOnePerModuleType is a marker function just indicates that this is a one-per-module type.
|
|
85
|
+
func (am AppModule) IsOnePerModuleType() {}
|
|
86
|
+
|
|
78
87
|
// NewAppModule creates a new AppModule Object
|
|
79
88
|
func NewAppModule(k Keeper) AppModule {
|
|
80
89
|
am := AppModule{
|
|
@@ -97,23 +106,28 @@ func (am AppModule) RegisterServices(cfg module.Configurator) {
|
|
|
97
106
|
|
|
98
107
|
func (AppModule) ConsensusVersion() uint64 { return 1 }
|
|
99
108
|
|
|
100
|
-
func (am AppModule) BeginBlock(ctx
|
|
101
|
-
am.keeper.NewChangeBatch(ctx)
|
|
109
|
+
func (am AppModule) BeginBlock(ctx context.Context) error {
|
|
110
|
+
return am.keeper.NewChangeBatch(sdk.UnwrapSDKContext(ctx))
|
|
102
111
|
}
|
|
103
112
|
|
|
104
|
-
func (am AppModule) EndBlock(ctx
|
|
105
|
-
am.keeper.FlushChangeEvents(ctx)
|
|
106
|
-
// Prevent Cosmos SDK internal errors.
|
|
107
|
-
return []abci.ValidatorUpdate{}
|
|
113
|
+
func (am AppModule) EndBlock(ctx context.Context) error {
|
|
114
|
+
return am.keeper.FlushChangeEvents(sdk.UnwrapSDKContext(ctx))
|
|
108
115
|
}
|
|
109
116
|
|
|
110
|
-
func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage)
|
|
117
|
+
func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) {
|
|
111
118
|
var genesisState types.GenesisState
|
|
112
|
-
cdc.
|
|
113
|
-
|
|
119
|
+
if err := cdc.UnmarshalJSON(data, &genesisState); err != nil {
|
|
120
|
+
panic(err)
|
|
121
|
+
}
|
|
122
|
+
if err := InitGenesis(ctx, am.keeper, &genesisState); err != nil {
|
|
123
|
+
panic(err)
|
|
124
|
+
}
|
|
114
125
|
}
|
|
115
126
|
|
|
116
127
|
func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage {
|
|
117
|
-
gs := ExportGenesis(ctx, am.keeper)
|
|
128
|
+
gs, err := ExportGenesis(ctx, am.keeper)
|
|
129
|
+
if err != nil {
|
|
130
|
+
panic(err)
|
|
131
|
+
}
|
|
118
132
|
return cdc.MustMarshalJSON(gs)
|
|
119
133
|
}
|
|
@@ -3,12 +3,14 @@ package testing
|
|
|
3
3
|
import (
|
|
4
4
|
"fmt"
|
|
5
5
|
|
|
6
|
+
sdkmath "cosmossdk.io/math"
|
|
7
|
+
storetypes "cosmossdk.io/store/types"
|
|
6
8
|
keeper "github.com/Agoric/agoric-sdk/golang/cosmos/x/vstorage/keeper"
|
|
7
9
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
8
10
|
)
|
|
9
11
|
|
|
10
12
|
func GetQueueItems(ctx sdk.Context, vstorageKeeper keeper.Keeper, queuePath string) ([]string, error) {
|
|
11
|
-
unlimitedCtx := ctx.WithGasMeter(
|
|
13
|
+
unlimitedCtx := ctx.WithGasMeter(storetypes.NewInfiniteGasMeter())
|
|
12
14
|
head, err := vstorageKeeper.GetIntValue(unlimitedCtx, queuePath+".head")
|
|
13
15
|
if err != nil {
|
|
14
16
|
return nil, err
|
|
@@ -21,14 +23,14 @@ func GetQueueItems(ctx sdk.Context, vstorageKeeper keeper.Keeper, queuePath stri
|
|
|
21
23
|
values := make([]string, length)
|
|
22
24
|
var i int64
|
|
23
25
|
for i = 0; i < length; i++ {
|
|
24
|
-
path := fmt.Sprintf("%s.%s", queuePath, head.Add(
|
|
26
|
+
path := fmt.Sprintf("%s.%s", queuePath, head.Add(sdkmath.NewInt(i)).String())
|
|
25
27
|
values[i] = vstorageKeeper.GetEntry(unlimitedCtx, path).StringValue()
|
|
26
28
|
}
|
|
27
29
|
return values, nil
|
|
28
30
|
}
|
|
29
31
|
|
|
30
32
|
func ResetQueue(ctx sdk.Context, vstorageKeeper keeper.Keeper, queuePath string) error {
|
|
31
|
-
unlimitedCtx := ctx.WithGasMeter(
|
|
33
|
+
unlimitedCtx := ctx.WithGasMeter(storetypes.NewInfiniteGasMeter())
|
|
32
34
|
vstorageKeeper.RemoveEntriesWithPrefix(unlimitedCtx, queuePath)
|
|
33
35
|
return nil
|
|
34
36
|
}
|
package/x/vstorage/vstorage.go
CHANGED
|
@@ -6,6 +6,7 @@ import (
|
|
|
6
6
|
"errors"
|
|
7
7
|
"fmt"
|
|
8
8
|
|
|
9
|
+
storetypes "cosmossdk.io/store/types"
|
|
9
10
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
10
11
|
|
|
11
12
|
agoric "github.com/Agoric/agoric-sdk/golang/cosmos/types"
|
|
@@ -54,7 +55,7 @@ func (sh vstorageHandler) Receive(cctx context.Context, str string) (ret string,
|
|
|
54
55
|
defer func() {
|
|
55
56
|
if r := recover(); r != nil {
|
|
56
57
|
switch rType := r.(type) {
|
|
57
|
-
case
|
|
58
|
+
case storetypes.ErrorOutOfGas:
|
|
58
59
|
err = fmt.Errorf(
|
|
59
60
|
"out of gas in location: %v; gasUsed: %d",
|
|
60
61
|
rType.Descriptor, ctx.GasMeter().GasConsumed(),
|