@agoric/cosmos 0.34.2-dev-3c8aafe.0 → 0.34.2-dev-74fbe43.0.74fbe43
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/Makefile +6 -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 +256 -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 +40 -90
- 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 +130 -109
- package/go.sum +228 -469
- package/package.json +2 -2
- package/proto/agoric/swingset/msgs.proto +72 -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/scripts/mockgen.sh +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 +349 -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 -27
- 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 +28 -23
- package/x/swingset/keeper/keeper_test.go +10 -7
- package/x/swingset/keeper/msg_server.go +52 -5
- package/x/swingset/keeper/msg_server_test.go +121 -0
- package/x/swingset/keeper/proposal.go +4 -0
- package/x/swingset/keeper/querier.go +1 -1
- 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/keeper/test_utils.go +2 -2
- package/x/swingset/module.go +20 -22
- package/x/swingset/testing/queue.go +5 -2
- package/x/swingset/testutil/mocks.go +379 -0
- package/x/swingset/types/codec.go +10 -5
- package/x/swingset/types/default-params.go +13 -12
- package/x/swingset/types/expected_keepers.go +29 -4
- package/x/swingset/types/msgs.go +51 -36
- package/x/swingset/types/msgs.pb.go +561 -51
- package/x/swingset/types/params_test.go +21 -20
- package/x/swingset/types/swingset.pb.go +67 -61
- package/x/vbank/genesis.go +13 -9
- 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 +10 -5
- 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 +29 -11
- 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/grpc_query.go +1 -1
- package/x/vstorage/keeper/keeper.go +72 -50
- package/x/vstorage/keeper/keeper_test.go +74 -54
- package/x/vstorage/keeper/querier.go +1 -1
- package/x/vstorage/module.go +27 -13
- package/x/vstorage/testing/queue.go +5 -3
- package/x/vstorage/vstorage.go +10 -9
- package/x/vstorage/vstorage_test.go +24 -18
- 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,25 +306,26 @@ 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
|
-
func (k Keeper) GetChildren(ctx sdk.Context, path string)
|
|
317
|
+
func (k Keeper) GetChildren(ctx sdk.Context, path string) []string {
|
|
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]
|
|
311
326
|
children.Children = append(children.Children, childrentr)
|
|
312
327
|
}
|
|
313
|
-
return
|
|
328
|
+
return children.Children
|
|
314
329
|
}
|
|
315
330
|
|
|
316
331
|
// HasStorage tells if a given path has data. Some storage nodes have no data
|
|
@@ -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,22 +354,25 @@ 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) {
|
|
350
|
-
k.changeManager.Track(ctx, k, entry, false)
|
|
370
|
+
_ = k.changeManager.Track(ctx, k, entry, false)
|
|
351
371
|
k.SetStorage(ctx, entry)
|
|
352
372
|
}
|
|
353
373
|
|
|
354
374
|
func (k Keeper) LegacySetStorageAndNotify(ctx sdk.Context, entry agoric.KVEntry) {
|
|
355
|
-
k.changeManager.Track(ctx, k, entry, true)
|
|
375
|
+
_ = k.changeManager.Track(ctx, k, entry, true)
|
|
356
376
|
k.SetStorage(ctx, entry)
|
|
357
377
|
}
|
|
358
378
|
|
|
@@ -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
|
|
|
@@ -75,28 +78,28 @@ func TestStorage(t *testing.T) {
|
|
|
75
78
|
}
|
|
76
79
|
|
|
77
80
|
// Check that our children are updated as expected.
|
|
78
|
-
if got := keeper.GetChildren(ctx, ""); !childrenEqual(got
|
|
79
|
-
t.Errorf("got %q children, want [inited]", got
|
|
81
|
+
if got := keeper.GetChildren(ctx, ""); !childrenEqual(got, []string{"inited"}) {
|
|
82
|
+
t.Errorf("got %q children, want [inited]", got)
|
|
80
83
|
}
|
|
81
84
|
|
|
82
85
|
keeper.SetStorage(ctx, agoric.NewKVEntry("key1", "value1"))
|
|
83
|
-
if got := keeper.GetChildren(ctx, ""); !childrenEqual(got
|
|
84
|
-
t.Errorf("got %q children, want [inited,key1]", got
|
|
86
|
+
if got := keeper.GetChildren(ctx, ""); !childrenEqual(got, []string{"inited", "key1"}) {
|
|
87
|
+
t.Errorf("got %q children, want [inited,key1]", got)
|
|
85
88
|
}
|
|
86
89
|
|
|
87
90
|
// Check alphabetical.
|
|
88
91
|
keeper.SetStorage(ctx, agoric.NewKVEntry("alpha2", "value2"))
|
|
89
|
-
if got := keeper.GetChildren(ctx, ""); !childrenEqual(got
|
|
90
|
-
t.Errorf("got %q children, want [alpha2,inited,key1]", got
|
|
92
|
+
if got := keeper.GetChildren(ctx, ""); !childrenEqual(got, []string{"alpha2", "inited", "key1"}) {
|
|
93
|
+
t.Errorf("got %q children, want [alpha2,inited,key1]", got)
|
|
91
94
|
}
|
|
92
95
|
|
|
93
96
|
keeper.SetStorage(ctx, agoric.NewKVEntry("beta3", "value3"))
|
|
94
|
-
if got := keeper.GetChildren(ctx, ""); !childrenEqual(got
|
|
95
|
-
t.Errorf("got %q children, want [alpha2,beta3,inited,key1]", got
|
|
97
|
+
if got := keeper.GetChildren(ctx, ""); !childrenEqual(got, []string{"alpha2", "beta3", "inited", "key1"}) {
|
|
98
|
+
t.Errorf("got %q children, want [alpha2,beta3,inited,key1]", got)
|
|
96
99
|
}
|
|
97
100
|
|
|
98
|
-
if got := keeper.GetChildren(ctx, "nonexistent"); !childrenEqual(got
|
|
99
|
-
t.Errorf("got %q children, want []", got
|
|
101
|
+
if got := keeper.GetChildren(ctx, "nonexistent"); !childrenEqual(got, []string{}) {
|
|
102
|
+
t.Errorf("got %q children, want []", got)
|
|
100
103
|
}
|
|
101
104
|
|
|
102
105
|
// Check adding children.
|
|
@@ -105,8 +108,8 @@ func TestStorage(t *testing.T) {
|
|
|
105
108
|
t.Errorf("got %q, want %q", got, "value1child")
|
|
106
109
|
}
|
|
107
110
|
|
|
108
|
-
if got := keeper.GetChildren(ctx, "key1"); !childrenEqual(got
|
|
109
|
-
t.Errorf("got %q children, want [child1]", got
|
|
111
|
+
if got := keeper.GetChildren(ctx, "key1"); !childrenEqual(got, []string{"child1"}) {
|
|
112
|
+
t.Errorf("got %q children, want [child1]", got)
|
|
110
113
|
}
|
|
111
114
|
|
|
112
115
|
// Add a grandchild.
|
|
@@ -115,52 +118,52 @@ func TestStorage(t *testing.T) {
|
|
|
115
118
|
t.Errorf("got %q, want %q", got, "value1grandchild")
|
|
116
119
|
}
|
|
117
120
|
|
|
118
|
-
if got := keeper.GetChildren(ctx, "key1.child1"); !childrenEqual(got
|
|
119
|
-
t.Errorf("got %q children, want [grandchild1]", got
|
|
121
|
+
if got := keeper.GetChildren(ctx, "key1.child1"); !childrenEqual(got, []string{"grandchild1"}) {
|
|
122
|
+
t.Errorf("got %q children, want [grandchild1]", got)
|
|
120
123
|
}
|
|
121
124
|
|
|
122
125
|
// Delete the child's contents.
|
|
123
126
|
keeper.SetStorage(ctx, agoric.NewKVEntryWithNoValue("key1.child1"))
|
|
124
|
-
if got := keeper.GetChildren(ctx, "key1"); !childrenEqual(got
|
|
125
|
-
t.Errorf("got %q children, want [child1]", got
|
|
127
|
+
if got := keeper.GetChildren(ctx, "key1"); !childrenEqual(got, []string{"child1"}) {
|
|
128
|
+
t.Errorf("got %q children, want [child1]", got)
|
|
126
129
|
}
|
|
127
130
|
|
|
128
|
-
if got := keeper.GetChildren(ctx, "key1.child1"); !childrenEqual(got
|
|
129
|
-
t.Errorf("got %q children, want [grandchild1]", got
|
|
131
|
+
if got := keeper.GetChildren(ctx, "key1.child1"); !childrenEqual(got, []string{"grandchild1"}) {
|
|
132
|
+
t.Errorf("got %q children, want [grandchild1]", got)
|
|
130
133
|
}
|
|
131
134
|
|
|
132
135
|
// Delete the grandchild's contents.
|
|
133
136
|
keeper.SetStorage(ctx, agoric.NewKVEntryWithNoValue("key1.child1.grandchild1"))
|
|
134
|
-
if got := keeper.GetChildren(ctx, "key1.child1"); !childrenEqual(got
|
|
135
|
-
t.Errorf("got %q children, want []", got
|
|
137
|
+
if got := keeper.GetChildren(ctx, "key1.child1"); !childrenEqual(got, []string{}) {
|
|
138
|
+
t.Errorf("got %q children, want []", got)
|
|
136
139
|
}
|
|
137
140
|
// Removing that node rolls up into the parent.
|
|
138
|
-
if got := keeper.GetChildren(ctx, "key1"); !childrenEqual(got
|
|
139
|
-
t.Errorf("got %q children, want []", got
|
|
141
|
+
if got := keeper.GetChildren(ctx, "key1"); !childrenEqual(got, []string{}) {
|
|
142
|
+
t.Errorf("got %q children, want []", got)
|
|
140
143
|
}
|
|
141
144
|
|
|
142
145
|
// See about deleting the parent.
|
|
143
146
|
keeper.SetStorage(ctx, agoric.NewKVEntryWithNoValue("key1"))
|
|
144
|
-
if got := keeper.GetChildren(ctx, ""); !childrenEqual(got
|
|
145
|
-
t.Errorf("got %q children, want [alpha2,beta3,inited]", got
|
|
147
|
+
if got := keeper.GetChildren(ctx, ""); !childrenEqual(got, []string{"alpha2", "beta3", "inited"}) {
|
|
148
|
+
t.Errorf("got %q children, want [alpha2,beta3,inited]", got)
|
|
146
149
|
}
|
|
147
150
|
|
|
148
151
|
// Do a deep set.
|
|
149
152
|
keeper.SetStorage(ctx, agoric.NewKVEntry("key2.child2.grandchild2", "value2grandchild"))
|
|
150
|
-
if got := keeper.GetChildren(ctx, ""); !childrenEqual(got
|
|
151
|
-
t.Errorf("got %q children, want [alpha2,beta3,inited,key2]", got
|
|
153
|
+
if got := keeper.GetChildren(ctx, ""); !childrenEqual(got, []string{"alpha2", "beta3", "inited", "key2"}) {
|
|
154
|
+
t.Errorf("got %q children, want [alpha2,beta3,inited,key2]", got)
|
|
152
155
|
}
|
|
153
|
-
if got := keeper.GetChildren(ctx, "key2.child2"); !childrenEqual(got
|
|
154
|
-
t.Errorf("got %q children, want [grandchild2]", got
|
|
156
|
+
if got := keeper.GetChildren(ctx, "key2.child2"); !childrenEqual(got, []string{"grandchild2"}) {
|
|
157
|
+
t.Errorf("got %q children, want [grandchild2]", got)
|
|
155
158
|
}
|
|
156
|
-
if got := keeper.GetChildren(ctx, "key2"); !childrenEqual(got
|
|
157
|
-
t.Errorf("got %q children, want [child2]", got
|
|
159
|
+
if got := keeper.GetChildren(ctx, "key2"); !childrenEqual(got, []string{"child2"}) {
|
|
160
|
+
t.Errorf("got %q children, want [child2]", got)
|
|
158
161
|
}
|
|
159
162
|
|
|
160
163
|
// Do another deep set.
|
|
161
164
|
keeper.SetStorage(ctx, agoric.NewKVEntry("key2.child2.grandchild2a", "value2grandchilda"))
|
|
162
|
-
if got := keeper.GetChildren(ctx, "key2.child2"); !childrenEqual(got
|
|
163
|
-
t.Errorf("got %q children, want [grandchild2,grandchild2a]", got
|
|
165
|
+
if got := keeper.GetChildren(ctx, "key2.child2"); !childrenEqual(got, []string{"grandchild2", "grandchild2a"}) {
|
|
166
|
+
t.Errorf("got %q children, want [grandchild2,grandchild2a]", got)
|
|
164
167
|
}
|
|
165
168
|
|
|
166
169
|
// Check the export.
|
|
@@ -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
|
-
keeper.ImportStorage(ctx, gotExport)
|
|
203
|
-
gotExport = keeper.ExportStorage(ctx)
|
|
215
|
+
_ = keeper.ImportStorage(ctx, gotExport)
|
|
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"},
|
|
@@ -276,7 +292,9 @@ func TestStorageNotify(t *testing.T) {
|
|
|
276
292
|
},
|
|
277
293
|
}
|
|
278
294
|
|
|
279
|
-
keeper.FlushChangeEvents(ctx)
|
|
295
|
+
if err := keeper.FlushChangeEvents(ctx); err != nil {
|
|
296
|
+
t.Errorf("got unexpected flush error %v", err)
|
|
297
|
+
}
|
|
280
298
|
if got := ctx.EventManager().Events(); !reflect.DeepEqual(got, expectedAfterFlushEvents) {
|
|
281
299
|
for _, e := range got {
|
|
282
300
|
t.Logf("got event: %s", e.Type)
|
|
@@ -287,7 +305,9 @@ func TestStorageNotify(t *testing.T) {
|
|
|
287
305
|
t.Errorf("got after flush events %#v, want %#v", got, expectedAfterFlushEvents)
|
|
288
306
|
}
|
|
289
307
|
|
|
290
|
-
keeper.FlushChangeEvents(ctx)
|
|
308
|
+
if err := keeper.FlushChangeEvents(ctx); err != nil {
|
|
309
|
+
t.Errorf("got unexpected second flush error %v", err)
|
|
310
|
+
}
|
|
291
311
|
if got := ctx.EventManager().Events(); !reflect.DeepEqual(got, expectedAfterFlushEvents) {
|
|
292
312
|
t.Errorf("got after second flush events %#v, want %#v", got, expectedAfterFlushEvents)
|
|
293
313
|
}
|
|
@@ -44,7 +44,7 @@ func queryData(ctx sdk.Context, path string, req abci.RequestQuery, keeper Keepe
|
|
|
44
44
|
// nolint: unparam
|
|
45
45
|
func queryChildren(ctx sdk.Context, path string, req abci.RequestQuery, keeper Keeper, legacyQuerierCdc *codec.LegacyAmino) (res []byte, err error) {
|
|
46
46
|
children := keeper.GetChildren(ctx, path)
|
|
47
|
-
klist := children
|
|
47
|
+
klist := children
|
|
48
48
|
|
|
49
49
|
if klist == nil {
|
|
50
50
|
klist = []string{}
|