@agoric/cosmos 0.34.2-dev-4655b76.0 → 0.34.2-dev-1ea0d4b.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/git-revision.txt +1 -1
- package/package.json +2 -2
- package/x/vstorage/keeper/keeper.go +32 -4
package/git-revision.txt
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
1ea0d4b
|
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-1ea0d4b.0+1ea0d4b",
|
|
4
4
|
"description": "Connect JS to the Cosmos blockchain SDK",
|
|
5
5
|
"parsers": {
|
|
6
6
|
"js": "mjs"
|
|
@@ -38,5 +38,5 @@
|
|
|
38
38
|
"typeCoverage": {
|
|
39
39
|
"atLeast": 0
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "1ea0d4b70010df6a7f3064c0dbd2eabd1f4311b8"
|
|
42
42
|
}
|
|
@@ -11,7 +11,9 @@ import (
|
|
|
11
11
|
"strings"
|
|
12
12
|
|
|
13
13
|
sdkmath "cosmossdk.io/math"
|
|
14
|
+
metrics "github.com/armon/go-metrics"
|
|
14
15
|
storetypes "github.com/cosmos/cosmos-sdk/store/types"
|
|
16
|
+
"github.com/cosmos/cosmos-sdk/telemetry"
|
|
15
17
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
16
18
|
db "github.com/tendermint/tm-db"
|
|
17
19
|
|
|
@@ -117,6 +119,15 @@ func NewKeeper(storeKey storetypes.StoreKey) Keeper {
|
|
|
117
119
|
}
|
|
118
120
|
}
|
|
119
121
|
|
|
122
|
+
var MetricKeysSizeDelta = []string{"store", "size_delta"}
|
|
123
|
+
const MetricLabelStoreKey = "storeKey"
|
|
124
|
+
|
|
125
|
+
func NewMetricsLabels(k Keeper) []metrics.Label {
|
|
126
|
+
return []metrics.Label{
|
|
127
|
+
telemetry.NewLabel(MetricLabelStoreKey, k.storeKey.Name()),
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
120
131
|
// ExportStorage fetches all storage
|
|
121
132
|
func (k Keeper) ExportStorage(ctx sdk.Context) []*types.DataEntry {
|
|
122
133
|
return k.ExportStorageFromPrefix(ctx, "")
|
|
@@ -215,6 +226,9 @@ func (k Keeper) RemoveEntriesWithPrefix(ctx sdk.Context, pathPrefix string) {
|
|
|
215
226
|
keys := getEncodedKeysWithPrefixFromIterator(iterator, descendantPrefix)
|
|
216
227
|
|
|
217
228
|
for _, key := range keys {
|
|
229
|
+
rawValue := store.Get(key)
|
|
230
|
+
sizeDelta := float32(-len(key) - len(rawValue))
|
|
231
|
+
telemetry.IncrCounterWithLabels(MetricKeysSizeDelta, sizeDelta, NewMetricsLabels(k))
|
|
218
232
|
store.Delete(key)
|
|
219
233
|
}
|
|
220
234
|
|
|
@@ -366,18 +380,26 @@ func (k Keeper) SetStorage(ctx sdk.Context, entry agoric.KVEntry) {
|
|
|
366
380
|
store := ctx.KVStore(k.storeKey)
|
|
367
381
|
path := entry.Key()
|
|
368
382
|
encodedKey := types.PathToEncodedKey(path)
|
|
383
|
+
oldRawValue := store.Get(encodedKey)
|
|
369
384
|
|
|
370
385
|
if !entry.HasValue() {
|
|
371
386
|
if !k.HasChildren(ctx, path) {
|
|
372
387
|
// We have no children, can delete.
|
|
388
|
+
sizeDelta := float32(-len(encodedKey) - len(oldRawValue))
|
|
389
|
+
telemetry.IncrCounterWithLabels(MetricKeysSizeDelta, sizeDelta, NewMetricsLabels(k))
|
|
373
390
|
store.Delete(encodedKey)
|
|
374
391
|
} else {
|
|
392
|
+
// We have children, mark as an empty placeholder without deleting.
|
|
393
|
+
sizeDelta := float32(len(types.EncodedNoDataValue) - len(oldRawValue))
|
|
394
|
+
telemetry.IncrCounterWithLabels(MetricKeysSizeDelta, sizeDelta, NewMetricsLabels(k))
|
|
375
395
|
store.Set(encodedKey, types.EncodedNoDataValue)
|
|
376
396
|
}
|
|
377
397
|
} else {
|
|
378
398
|
// Update the value.
|
|
379
|
-
|
|
380
|
-
|
|
399
|
+
newRawValue := bytes.Join([][]byte{types.EncodedDataPrefix, []byte(entry.StringValue())}, []byte{})
|
|
400
|
+
sizeDelta := float32(len(newRawValue) - len(oldRawValue))
|
|
401
|
+
telemetry.IncrCounterWithLabels(MetricKeysSizeDelta, sizeDelta, NewMetricsLabels(k))
|
|
402
|
+
store.Set(encodedKey, newRawValue)
|
|
381
403
|
}
|
|
382
404
|
|
|
383
405
|
// Update our other parent children.
|
|
@@ -390,7 +412,10 @@ func (k Keeper) SetStorage(ctx sdk.Context, entry agoric.KVEntry) {
|
|
|
390
412
|
// this and further ancestors are needed, skip out
|
|
391
413
|
break
|
|
392
414
|
}
|
|
393
|
-
|
|
415
|
+
encodedAncestor := types.PathToEncodedKey(ancestor)
|
|
416
|
+
sizeDelta := float32(-len(encodedAncestor) - len(types.EncodedNoDataValue))
|
|
417
|
+
telemetry.IncrCounterWithLabels(MetricKeysSizeDelta, sizeDelta, NewMetricsLabels(k))
|
|
418
|
+
store.Delete(encodedAncestor)
|
|
394
419
|
}
|
|
395
420
|
} else {
|
|
396
421
|
// add placeholders as needed
|
|
@@ -400,7 +425,10 @@ func (k Keeper) SetStorage(ctx sdk.Context, entry agoric.KVEntry) {
|
|
|
400
425
|
// The ancestor exists, implying all further ancestors exist, so we can break.
|
|
401
426
|
break
|
|
402
427
|
}
|
|
403
|
-
|
|
428
|
+
encodedAncestor := types.PathToEncodedKey(ancestor)
|
|
429
|
+
sizeDelta := float32(len(encodedAncestor) + len(types.EncodedNoDataValue))
|
|
430
|
+
telemetry.IncrCounterWithLabels(MetricKeysSizeDelta, sizeDelta, NewMetricsLabels(k))
|
|
431
|
+
store.Set(encodedAncestor, types.EncodedNoDataValue)
|
|
404
432
|
}
|
|
405
433
|
}
|
|
406
434
|
}
|