@agoric/cosmos 0.34.2-upgrade-18-dev-6ddbef0.0 → 0.34.2-upgrade-19-dev-2a71f04.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/ante/inbound_test.go +2 -2
- package/app/app.go +26 -9
- package/app/upgrade.go +84 -66
- package/daemon/cmd/root.go +48 -15
- package/e2e_test/go.mod +25 -3
- package/e2e_test/go.sum +13 -13
- package/git-revision.txt +1 -1
- package/go.mod +85 -74
- package/go.sum +207 -174
- package/package.json +2 -3
- package/proto/agoric/swingset/swingset.proto +25 -0
- package/proto/agoric/vbank/vbank.proto +7 -0
- package/types/address_hooks.go +242 -0
- package/types/address_hooks_test.go +221 -0
- package/x/swingset/genesis.go +99 -21
- package/x/swingset/keeper/keeper.go +19 -14
- package/x/swingset/keeper/keeper_test.go +16 -10
- package/x/swingset/keeper/msg_server.go +1 -1
- package/x/swingset/module.go +17 -2
- package/x/swingset/testing/queue.go +8 -0
- package/x/swingset/types/default-params.go +31 -5
- package/x/swingset/types/expected_keepers.go +2 -2
- package/x/swingset/types/msgs.go +34 -12
- package/x/swingset/types/params.go +53 -43
- package/x/swingset/types/params_test.go +75 -9
- package/x/swingset/types/swingset.pb.go +386 -56
- package/x/vbank/README.md +6 -1
- package/x/vbank/keeper/keeper.go +4 -9
- package/x/vbank/keeper/migrations.go +30 -0
- package/x/vbank/module.go +8 -2
- package/x/vbank/types/params.go +43 -2
- package/x/vbank/types/vbank.pb.go +105 -36
- package/x/vbank/vbank_test.go +12 -7
- package/x/vibc/keeper/keeper.go +2 -5
- package/x/vibc/keeper/triggers.go +3 -6
- package/x/vibc/types/receiver.go +11 -5
- package/x/vstorage/testing/queue.go +10 -3
- package/x/vtransfer/ibc_middleware.go +5 -1
- package/x/vtransfer/ibc_middleware_test.go +511 -145
- package/x/vtransfer/keeper/keeper.go +215 -50
- package/x/vtransfer/types/genesis.pb.go +1 -0
- package/x/vtransfer/utils_test.go +111 -0
package/x/swingset/genesis.go
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
package swingset
|
|
2
2
|
|
|
3
3
|
import (
|
|
4
|
-
// "os"
|
|
5
4
|
"bytes"
|
|
6
5
|
"crypto/sha256"
|
|
7
6
|
"encoding/hex"
|
|
8
7
|
"encoding/json"
|
|
9
8
|
"fmt"
|
|
10
9
|
"hash"
|
|
10
|
+
"io"
|
|
11
11
|
"strings"
|
|
12
12
|
|
|
13
13
|
agoric "github.com/Agoric/agoric-sdk/golang/cosmos/types"
|
|
@@ -16,6 +16,20 @@ import (
|
|
|
16
16
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
17
17
|
)
|
|
18
18
|
|
|
19
|
+
const (
|
|
20
|
+
// SwingStoreExportModeSkip indicates swing store data should be
|
|
21
|
+
// excluded from the export.
|
|
22
|
+
SwingStoreExportModeSkip = "skip"
|
|
23
|
+
|
|
24
|
+
// SwingStoreExportModeOperational (default) indicates export should
|
|
25
|
+
// have the minimal set of artifacts needed to operate a node.
|
|
26
|
+
SwingStoreExportModeOperational = "operational"
|
|
27
|
+
|
|
28
|
+
// SwingStoreExportModeDebug indicates export should have the maximal
|
|
29
|
+
// set of artifacts available in the JS swing-store.
|
|
30
|
+
SwingStoreExportModeDebug = "debug"
|
|
31
|
+
)
|
|
32
|
+
|
|
19
33
|
func ValidateGenesis(data *types.GenesisState) error {
|
|
20
34
|
if data == nil {
|
|
21
35
|
return fmt.Errorf("swingset genesis data cannot be nil")
|
|
@@ -130,36 +144,59 @@ func InitGenesis(ctx sdk.Context, k Keeper, swingStoreExportsHandler *SwingStore
|
|
|
130
144
|
return false
|
|
131
145
|
}
|
|
132
146
|
|
|
133
|
-
func ExportGenesis(
|
|
147
|
+
func ExportGenesis(
|
|
148
|
+
ctx sdk.Context,
|
|
149
|
+
k Keeper,
|
|
150
|
+
swingStoreExportsHandler *SwingStoreExportsHandler,
|
|
151
|
+
swingStoreExportDir string,
|
|
152
|
+
swingStoreExportMode string,
|
|
153
|
+
) *types.GenesisState {
|
|
134
154
|
gs := &types.GenesisState{
|
|
135
155
|
Params: k.GetParams(ctx),
|
|
136
156
|
State: k.GetState(ctx),
|
|
137
157
|
SwingStoreExportData: nil,
|
|
138
158
|
}
|
|
139
159
|
|
|
160
|
+
// This will only be used in non skip mode
|
|
161
|
+
artifactMode := swingStoreExportMode
|
|
162
|
+
exportDataMode := keeper.SwingStoreExportDataModeSkip
|
|
163
|
+
hasher := sha256.New()
|
|
140
164
|
snapshotHeight := uint64(ctx.BlockHeight())
|
|
141
165
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
// The export will fail if the export of a historical height was requested
|
|
146
|
-
snapshotHeight,
|
|
147
|
-
eventHandler,
|
|
148
|
-
keeper.SwingStoreExportOptions{
|
|
149
|
-
ArtifactMode: keeper.SwingStoreArtifactModeOperational,
|
|
150
|
-
ExportDataMode: keeper.SwingStoreExportDataModeSkip,
|
|
151
|
-
},
|
|
152
|
-
)
|
|
153
|
-
if err != nil {
|
|
154
|
-
panic(err)
|
|
166
|
+
if swingStoreExportMode == SwingStoreExportModeDebug {
|
|
167
|
+
exportDataMode = keeper.SwingStoreExportDataModeAll
|
|
168
|
+
snapshotHeight = 0
|
|
155
169
|
}
|
|
156
170
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
171
|
+
if swingStoreExportMode != SwingStoreExportModeSkip {
|
|
172
|
+
eventHandler := swingStoreGenesisEventHandler{
|
|
173
|
+
exportDir: swingStoreExportDir,
|
|
174
|
+
snapshotHeight: snapshotHeight,
|
|
175
|
+
swingStore: k.GetSwingStore(ctx),
|
|
176
|
+
hasher: hasher,
|
|
177
|
+
exportMode: swingStoreExportMode,
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
err := swingStoreExportsHandler.InitiateExport(
|
|
181
|
+
// The export will fail if the export of a historical height was requested outside of debug mode
|
|
182
|
+
snapshotHeight,
|
|
183
|
+
eventHandler,
|
|
184
|
+
keeper.SwingStoreExportOptions{
|
|
185
|
+
ArtifactMode: artifactMode,
|
|
186
|
+
ExportDataMode: exportDataMode,
|
|
187
|
+
},
|
|
188
|
+
)
|
|
189
|
+
if err != nil {
|
|
190
|
+
panic(err)
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
err = keeper.WaitUntilSwingStoreExportDone()
|
|
194
|
+
if err != nil {
|
|
195
|
+
panic(err)
|
|
196
|
+
}
|
|
160
197
|
}
|
|
161
198
|
|
|
162
|
-
gs.SwingStoreExportDataHash = fmt.Sprintf("sha256:%x",
|
|
199
|
+
gs.SwingStoreExportDataHash = fmt.Sprintf("sha256:%x", hasher.Sum(nil))
|
|
163
200
|
|
|
164
201
|
return gs
|
|
165
202
|
}
|
|
@@ -169,6 +206,7 @@ type swingStoreGenesisEventHandler struct {
|
|
|
169
206
|
snapshotHeight uint64
|
|
170
207
|
swingStore sdk.KVStore
|
|
171
208
|
hasher hash.Hash
|
|
209
|
+
exportMode string
|
|
172
210
|
}
|
|
173
211
|
|
|
174
212
|
func (eventHandler swingStoreGenesisEventHandler) OnExportStarted(height uint64, retrieveSwingStoreExport func() error) error {
|
|
@@ -176,10 +214,12 @@ func (eventHandler swingStoreGenesisEventHandler) OnExportStarted(height uint64,
|
|
|
176
214
|
}
|
|
177
215
|
|
|
178
216
|
func (eventHandler swingStoreGenesisEventHandler) OnExportRetrieved(provider keeper.SwingStoreExportProvider) error {
|
|
179
|
-
if eventHandler.snapshotHeight != provider.BlockHeight {
|
|
217
|
+
if eventHandler.exportMode != SwingStoreExportModeDebug && eventHandler.snapshotHeight != provider.BlockHeight {
|
|
180
218
|
return fmt.Errorf("snapshot block height (%d) doesn't match requested height (%d)", provider.BlockHeight, eventHandler.snapshotHeight)
|
|
181
219
|
}
|
|
182
220
|
|
|
221
|
+
artifactsEnded := false
|
|
222
|
+
|
|
183
223
|
artifactsProvider := keeper.SwingStoreExportProvider{
|
|
184
224
|
GetExportDataReader: func() (agoric.KVEntryReader, error) {
|
|
185
225
|
exportDataIterator := eventHandler.swingStore.Iterator(nil, nil)
|
|
@@ -194,7 +234,45 @@ func (eventHandler swingStoreGenesisEventHandler) OnExportRetrieved(provider kee
|
|
|
194
234
|
return nil
|
|
195
235
|
}), nil
|
|
196
236
|
},
|
|
197
|
-
ReadNextArtifact:
|
|
237
|
+
ReadNextArtifact: func() (types.SwingStoreArtifact, error) {
|
|
238
|
+
var (
|
|
239
|
+
artifact types.SwingStoreArtifact
|
|
240
|
+
err error
|
|
241
|
+
encodedExportData bytes.Buffer
|
|
242
|
+
)
|
|
243
|
+
|
|
244
|
+
if !artifactsEnded {
|
|
245
|
+
artifact, err = provider.ReadNextArtifact()
|
|
246
|
+
} else {
|
|
247
|
+
return types.SwingStoreArtifact{}, io.EOF
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
if err == io.EOF {
|
|
251
|
+
artifactsEnded = true
|
|
252
|
+
if eventHandler.exportMode == SwingStoreExportModeDebug {
|
|
253
|
+
exportDataReader, _ := provider.GetExportDataReader()
|
|
254
|
+
|
|
255
|
+
defer exportDataReader.Close()
|
|
256
|
+
|
|
257
|
+
err = agoric.EncodeKVEntryReaderToJsonl(
|
|
258
|
+
exportDataReader,
|
|
259
|
+
&encodedExportData,
|
|
260
|
+
)
|
|
261
|
+
if err == nil {
|
|
262
|
+
artifact = types.SwingStoreArtifact{
|
|
263
|
+
Data: encodedExportData.Bytes(),
|
|
264
|
+
Name: keeper.UntrustedExportDataArtifactName,
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
return artifact, err
|
|
271
|
+
},
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
if eventHandler.exportMode == SwingStoreExportModeDebug {
|
|
275
|
+
artifactsProvider.BlockHeight = provider.BlockHeight
|
|
198
276
|
}
|
|
199
277
|
|
|
200
278
|
return keeper.WriteSwingStoreExportToDirectory(artifactsProvider, eventHandler.exportDir)
|
|
@@ -246,7 +246,10 @@ func (k Keeper) BlockingSend(ctx sdk.Context, action vm.Action) (string, error)
|
|
|
246
246
|
}
|
|
247
247
|
|
|
248
248
|
func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) {
|
|
249
|
-
|
|
249
|
+
// Note the use of "IfExists"...
|
|
250
|
+
// migration fills in missing data with defaults,
|
|
251
|
+
// so it is the only consumer that should ever see a nil pair.
|
|
252
|
+
k.paramSpace.GetParamSetIfExists(ctx, ¶ms)
|
|
250
253
|
return params
|
|
251
254
|
}
|
|
252
255
|
|
|
@@ -304,9 +307,12 @@ func (k Keeper) SetBeansOwing(ctx sdk.Context, addr sdk.AccAddress, beans sdkmat
|
|
|
304
307
|
// ChargeBeans charges the given address the given number of beans. It divides
|
|
305
308
|
// the beans into the number to debit immediately vs. the number to store in the
|
|
306
309
|
// beansOwing.
|
|
307
|
-
func (k Keeper) ChargeBeans(
|
|
308
|
-
|
|
309
|
-
|
|
310
|
+
func (k Keeper) ChargeBeans(
|
|
311
|
+
ctx sdk.Context,
|
|
312
|
+
beansPerUnit map[string]sdkmath.Uint,
|
|
313
|
+
addr sdk.AccAddress,
|
|
314
|
+
beans sdkmath.Uint,
|
|
315
|
+
) error {
|
|
310
316
|
wasOwing := k.GetBeansOwing(ctx, addr)
|
|
311
317
|
nowOwing := wasOwing.Add(beans)
|
|
312
318
|
|
|
@@ -339,10 +345,13 @@ func (k Keeper) ChargeBeans(ctx sdk.Context, addr sdk.AccAddress, beans sdkmath.
|
|
|
339
345
|
}
|
|
340
346
|
|
|
341
347
|
// ChargeForSmartWallet charges the fee for provisioning a smart wallet.
|
|
342
|
-
func (k Keeper) ChargeForSmartWallet(
|
|
343
|
-
|
|
348
|
+
func (k Keeper) ChargeForSmartWallet(
|
|
349
|
+
ctx sdk.Context,
|
|
350
|
+
beansPerUnit map[string]sdkmath.Uint,
|
|
351
|
+
addr sdk.AccAddress,
|
|
352
|
+
) error {
|
|
344
353
|
beans := beansPerUnit[types.BeansPerSmartWalletProvision]
|
|
345
|
-
err := k.ChargeBeans(ctx, addr, beans)
|
|
354
|
+
err := k.ChargeBeans(ctx, beansPerUnit, addr, beans)
|
|
346
355
|
if err != nil {
|
|
347
356
|
return err
|
|
348
357
|
}
|
|
@@ -371,7 +380,7 @@ func makeFeeMenu(powerFlagFees []types.PowerFlagFee) map[string]sdk.Coins {
|
|
|
371
380
|
|
|
372
381
|
var privilegedProvisioningCoins sdk.Coins = sdk.NewCoins(sdk.NewInt64Coin("provisionpass", 1))
|
|
373
382
|
|
|
374
|
-
func calculateFees(balances sdk.Coins,
|
|
383
|
+
func calculateFees(balances sdk.Coins, powerFlags []string, powerFlagFees []types.PowerFlagFee) (sdk.Coins, error) {
|
|
375
384
|
fees := sdk.NewCoins()
|
|
376
385
|
|
|
377
386
|
// See if we have the balance needed for privileged provisioning.
|
|
@@ -380,10 +389,6 @@ func calculateFees(balances sdk.Coins, submitter, addr sdk.AccAddress, powerFlag
|
|
|
380
389
|
return fees, nil
|
|
381
390
|
}
|
|
382
391
|
|
|
383
|
-
if !submitter.Equals(addr) {
|
|
384
|
-
return nil, fmt.Errorf("submitter is not the same as target address for fee-based provisioning")
|
|
385
|
-
}
|
|
386
|
-
|
|
387
392
|
if len(powerFlags) == 0 {
|
|
388
393
|
return nil, fmt.Errorf("must specify powerFlags for fee-based provisioning")
|
|
389
394
|
}
|
|
@@ -403,9 +408,9 @@ func calculateFees(balances sdk.Coins, submitter, addr sdk.AccAddress, powerFlag
|
|
|
403
408
|
return fees, nil
|
|
404
409
|
}
|
|
405
410
|
|
|
406
|
-
func (k Keeper) ChargeForProvisioning(ctx sdk.Context, submitter
|
|
411
|
+
func (k Keeper) ChargeForProvisioning(ctx sdk.Context, submitter sdk.AccAddress, powerFlags []string) error {
|
|
407
412
|
balances := k.bankKeeper.GetAllBalances(ctx, submitter)
|
|
408
|
-
fees, err := calculateFees(balances,
|
|
413
|
+
fees, err := calculateFees(balances, powerFlags, k.GetParams(ctx).PowerFlagFees)
|
|
409
414
|
if err != nil {
|
|
410
415
|
return err
|
|
411
416
|
}
|
|
@@ -61,15 +61,6 @@ func Test_calculateFees(t *testing.T) {
|
|
|
61
61
|
},
|
|
62
62
|
want: cns(),
|
|
63
63
|
},
|
|
64
|
-
{
|
|
65
|
-
name: "cannot pay fee to provision third party",
|
|
66
|
-
args: args{
|
|
67
|
-
submitter: submitAddr,
|
|
68
|
-
addr: utilAddr,
|
|
69
|
-
powerFlags: []string{"powerflag1"},
|
|
70
|
-
},
|
|
71
|
-
errMsg: "submitter is not the same as target address for fee-based provisioning",
|
|
72
|
-
},
|
|
73
64
|
{
|
|
74
65
|
name: "need powerflags for fee provisioning",
|
|
75
66
|
args: args{
|
|
@@ -106,6 +97,21 @@ func Test_calculateFees(t *testing.T) {
|
|
|
106
97
|
},
|
|
107
98
|
want: cns(a(1300)),
|
|
108
99
|
},
|
|
100
|
+
{
|
|
101
|
+
name: "can pay fee to provision third party",
|
|
102
|
+
args: args{
|
|
103
|
+
submitter: submitAddr,
|
|
104
|
+
addr: utilAddr,
|
|
105
|
+
powerFlags: []string{"power1"},
|
|
106
|
+
powerFlagFees: []types.PowerFlagFee{
|
|
107
|
+
{
|
|
108
|
+
PowerFlag: "power1",
|
|
109
|
+
Fee: cns(a(1000)),
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
want: cns(a(1000)),
|
|
114
|
+
},
|
|
109
115
|
{
|
|
110
116
|
name: "later menu entries do not override",
|
|
111
117
|
args: args{
|
|
@@ -173,7 +179,7 @@ func Test_calculateFees(t *testing.T) {
|
|
|
173
179
|
}
|
|
174
180
|
for _, tt := range tests {
|
|
175
181
|
t.Run(tt.name, func(t *testing.T) {
|
|
176
|
-
got, err := calculateFees(tt.args.balances, tt.args.
|
|
182
|
+
got, err := calculateFees(tt.args.balances, tt.args.powerFlags, tt.args.powerFlagFees)
|
|
177
183
|
var errMsg string
|
|
178
184
|
if err != nil {
|
|
179
185
|
errMsg = err.Error()
|
|
@@ -158,7 +158,7 @@ func (keeper msgServer) provisionIfNeeded(ctx sdk.Context, owner sdk.AccAddress)
|
|
|
158
158
|
func (keeper msgServer) Provision(goCtx context.Context, msg *types.MsgProvision) (*types.MsgProvisionResponse, error) {
|
|
159
159
|
ctx := sdk.UnwrapSDKContext(goCtx)
|
|
160
160
|
|
|
161
|
-
err := keeper.ChargeForProvisioning(ctx, msg.Submitter, msg.
|
|
161
|
+
err := keeper.ChargeForProvisioning(ctx, msg.Submitter, msg.PowerFlags)
|
|
162
162
|
if err != nil {
|
|
163
163
|
return nil, err
|
|
164
164
|
}
|
package/x/swingset/module.go
CHANGED
|
@@ -80,10 +80,18 @@ type AppModule struct {
|
|
|
80
80
|
setBootstrapNeeded func()
|
|
81
81
|
ensureControllerInited func(sdk.Context)
|
|
82
82
|
swingStoreExportDir string
|
|
83
|
+
swingStoreExportMode string
|
|
83
84
|
}
|
|
84
85
|
|
|
85
86
|
// NewAppModule creates a new AppModule Object
|
|
86
|
-
func NewAppModule(
|
|
87
|
+
func NewAppModule(
|
|
88
|
+
k Keeper,
|
|
89
|
+
swingStoreExportsHandler *SwingStoreExportsHandler,
|
|
90
|
+
setBootstrapNeeded func(),
|
|
91
|
+
ensureControllerInited func(sdk.Context),
|
|
92
|
+
swingStoreExportDir string,
|
|
93
|
+
swingStoreExportMode string,
|
|
94
|
+
) AppModule {
|
|
87
95
|
am := AppModule{
|
|
88
96
|
AppModuleBasic: AppModuleBasic{},
|
|
89
97
|
keeper: k,
|
|
@@ -91,6 +99,7 @@ func NewAppModule(k Keeper, swingStoreExportsHandler *SwingStoreExportsHandler,
|
|
|
91
99
|
setBootstrapNeeded: setBootstrapNeeded,
|
|
92
100
|
ensureControllerInited: ensureControllerInited,
|
|
93
101
|
swingStoreExportDir: swingStoreExportDir,
|
|
102
|
+
swingStoreExportMode: swingStoreExportMode,
|
|
94
103
|
}
|
|
95
104
|
return am
|
|
96
105
|
}
|
|
@@ -173,6 +182,12 @@ func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.
|
|
|
173
182
|
|
|
174
183
|
func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage {
|
|
175
184
|
am.checkSwingStoreExportSetup()
|
|
176
|
-
gs := ExportGenesis(
|
|
185
|
+
gs := ExportGenesis(
|
|
186
|
+
ctx,
|
|
187
|
+
am.keeper,
|
|
188
|
+
am.swingStoreExportsHandler,
|
|
189
|
+
am.swingStoreExportDir,
|
|
190
|
+
am.swingStoreExportMode,
|
|
191
|
+
)
|
|
177
192
|
return cdc.MustMarshalJSON(gs)
|
|
178
193
|
}
|
|
@@ -15,3 +15,11 @@ func GetActionQueueRecords(t *testing.T, ctx sdk.Context, swingsetKeeper keeper.
|
|
|
15
15
|
actionQueueName := keeper.StoragePathActionQueue
|
|
16
16
|
return vstoragetesting.GetQueueItems(ctx, vstorageKeeper, actionQueueName)
|
|
17
17
|
}
|
|
18
|
+
|
|
19
|
+
// ResetActionQueue resets the action queue.
|
|
20
|
+
// This is a testing utility function.
|
|
21
|
+
func ResetActionQueue(t *testing.T, ctx sdk.Context, swingsetKeeper keeper.Keeper) error {
|
|
22
|
+
vstorageKeeper := keeper.GetVstorageKeeper(t, swingsetKeeper)
|
|
23
|
+
actionQueueName := keeper.StoragePathActionQueue
|
|
24
|
+
return vstoragetesting.ResetQueue(ctx, vstorageKeeper, actionQueueName)
|
|
25
|
+
}
|
|
@@ -22,13 +22,23 @@ const (
|
|
|
22
22
|
BeansPerXsnapComputron = "xsnapComputron"
|
|
23
23
|
BeansPerSmartWalletProvision = "smartWalletProvision"
|
|
24
24
|
|
|
25
|
+
// PowerFlags.
|
|
26
|
+
PowerFlagSmartWallet = "SMART_WALLET"
|
|
27
|
+
|
|
25
28
|
// QueueSize keys.
|
|
26
|
-
// Keep up-to-date with updateQueueAllowed() in
|
|
29
|
+
// Keep up-to-date with updateQueueAllowed() in packages/cosmic-swingset/src/launch-chain.js
|
|
27
30
|
QueueInbound = "inbound"
|
|
28
31
|
QueueInboundMempool = "inbound_mempool"
|
|
29
32
|
|
|
30
|
-
//
|
|
31
|
-
|
|
33
|
+
// Vat cleanup budget keys.
|
|
34
|
+
// Keep up-to-date with CleanupBudget in packages/cosmic-swingset/src/launch-chain.js
|
|
35
|
+
VatCleanupDefault = "default"
|
|
36
|
+
VatCleanupExports = "exports"
|
|
37
|
+
VatCleanupImports = "imports"
|
|
38
|
+
VatCleanupPromises = "promises"
|
|
39
|
+
VatCleanupKv = "kv"
|
|
40
|
+
VatCleanupSnapshots = "snapshots"
|
|
41
|
+
VatCleanupTranscripts = "transcripts"
|
|
32
42
|
)
|
|
33
43
|
|
|
34
44
|
var (
|
|
@@ -62,10 +72,26 @@ var (
|
|
|
62
72
|
}
|
|
63
73
|
|
|
64
74
|
DefaultInboundQueueMax = int32(1_000)
|
|
65
|
-
|
|
66
|
-
DefaultQueueMax = []QueueSize{
|
|
75
|
+
DefaultQueueMax = []QueueSize{
|
|
67
76
|
NewQueueSize(QueueInbound, DefaultInboundQueueMax),
|
|
68
77
|
}
|
|
78
|
+
|
|
79
|
+
DefaultVatCleanupDefault = sdk.NewUint(5)
|
|
80
|
+
// DefaultVatCleanupExports = DefaultVatCleanupDefault
|
|
81
|
+
// DefaultVatCleanupImports = DefaultVatCleanupDefault
|
|
82
|
+
// DefaultVatCleanupPromises = DefaultVatCleanupDefault
|
|
83
|
+
DefaultVatCleanupKv = sdk.NewUint(50)
|
|
84
|
+
// DefaultVatCleanupSnapshots = DefaultVatCleanupDefault
|
|
85
|
+
// DefaultVatCleanupTranscripts = DefaultVatCleanupDefault
|
|
86
|
+
DefaultVatCleanupBudget = []UintMapEntry{
|
|
87
|
+
UintMapEntry{VatCleanupDefault, DefaultVatCleanupDefault},
|
|
88
|
+
// UintMapEntry{VatCleanupExports, DefaultVatCleanupExports},
|
|
89
|
+
// UintMapEntry{VatCleanupImports, DefaultVatCleanupImports},
|
|
90
|
+
// UintMapEntry{VatCleanupPromises, DefaultVatCleanupPromises},
|
|
91
|
+
UintMapEntry{VatCleanupKv, DefaultVatCleanupKv},
|
|
92
|
+
// UintMapEntry{VatCleanupSnapshots, DefaultVatCleanupSnapshots},
|
|
93
|
+
// UintMapEntry{VatCleanupTranscripts, DefaultVatCleanupTranscripts},
|
|
94
|
+
}
|
|
69
95
|
)
|
|
70
96
|
|
|
71
97
|
// move DefaultBeansPerUnit to a function to allow for boot overriding of the Default params
|
|
@@ -23,8 +23,8 @@ type AccountKeeper interface {
|
|
|
23
23
|
|
|
24
24
|
type SwingSetKeeper interface {
|
|
25
25
|
GetBeansPerUnit(ctx sdk.Context) map[string]sdkmath.Uint
|
|
26
|
-
ChargeBeans(ctx sdk.Context, addr sdk.AccAddress, beans sdkmath.Uint) error
|
|
26
|
+
ChargeBeans(ctx sdk.Context, beansPerUnit map[string]sdkmath.Uint, addr sdk.AccAddress, beans sdkmath.Uint) error
|
|
27
27
|
IsHighPriorityAddress(ctx sdk.Context, addr sdk.AccAddress) (bool, error)
|
|
28
28
|
GetSmartWalletState(ctx sdk.Context, addr sdk.AccAddress) SmartWalletState
|
|
29
|
-
ChargeForSmartWallet(ctx sdk.Context, addr sdk.AccAddress) error
|
|
29
|
+
ChargeForSmartWallet(ctx sdk.Context, beansPerUnit map[string]sdkmath.Uint, addr sdk.AccAddress) error
|
|
30
30
|
}
|
package/x/swingset/types/msgs.go
CHANGED
|
@@ -8,9 +8,12 @@ import (
|
|
|
8
8
|
"strings"
|
|
9
9
|
|
|
10
10
|
sdkioerrors "cosmossdk.io/errors"
|
|
11
|
-
"
|
|
11
|
+
sdkmath "cosmossdk.io/math"
|
|
12
|
+
|
|
12
13
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
13
14
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
|
15
|
+
|
|
16
|
+
"github.com/Agoric/agoric-sdk/golang/cosmos/vm"
|
|
14
17
|
)
|
|
15
18
|
|
|
16
19
|
const RouterKey = ModuleName // this was defined in your key.go file
|
|
@@ -56,16 +59,26 @@ const (
|
|
|
56
59
|
|
|
57
60
|
// Charge an account address for the beans associated with given messages and storage.
|
|
58
61
|
// See list of bean charges in default-params.go
|
|
59
|
-
func chargeAdmission(
|
|
60
|
-
|
|
62
|
+
func chargeAdmission(
|
|
63
|
+
ctx sdk.Context,
|
|
64
|
+
keeper SwingSetKeeper,
|
|
65
|
+
beansPerUnit map[string]sdkmath.Uint,
|
|
66
|
+
addr sdk.AccAddress,
|
|
67
|
+
msgs []string,
|
|
68
|
+
storageLen uint64,
|
|
69
|
+
) error {
|
|
70
|
+
// A flat charge for each transaction.
|
|
61
71
|
beans := beansPerUnit[BeansPerInboundTx]
|
|
72
|
+
// A charge for each message in the transaction.
|
|
62
73
|
beans = beans.Add(beansPerUnit[BeansPerMessage].MulUint64((uint64(len(msgs)))))
|
|
74
|
+
// A charge for the total byte length of all messages.
|
|
63
75
|
for _, msg := range msgs {
|
|
64
76
|
beans = beans.Add(beansPerUnit[BeansPerMessageByte].MulUint64(uint64(len(msg))))
|
|
65
77
|
}
|
|
78
|
+
// A charge for persistent storage.
|
|
66
79
|
beans = beans.Add(beansPerUnit[BeansPerStorageByte].MulUint64(storageLen))
|
|
67
80
|
|
|
68
|
-
return keeper.ChargeBeans(ctx, addr, beans)
|
|
81
|
+
return keeper.ChargeBeans(ctx, beansPerUnit, addr, beans)
|
|
69
82
|
}
|
|
70
83
|
|
|
71
84
|
// checkSmartWalletProvisioned verifies if a smart wallet message (MsgWalletAction
|
|
@@ -74,7 +87,12 @@ func chargeAdmission(ctx sdk.Context, keeper SwingSetKeeper, addr sdk.AccAddress
|
|
|
74
87
|
// provisioning fee is charged successfully.
|
|
75
88
|
// All messages for non-provisioned smart wallets allowed here will result in
|
|
76
89
|
// an auto-provision action generated by the msg server.
|
|
77
|
-
func checkSmartWalletProvisioned(
|
|
90
|
+
func checkSmartWalletProvisioned(
|
|
91
|
+
ctx sdk.Context,
|
|
92
|
+
keeper SwingSetKeeper,
|
|
93
|
+
beansPerUnit map[string]sdkmath.Uint,
|
|
94
|
+
addr sdk.AccAddress,
|
|
95
|
+
) error {
|
|
78
96
|
walletState := keeper.GetSmartWalletState(ctx, addr)
|
|
79
97
|
|
|
80
98
|
switch walletState {
|
|
@@ -91,7 +109,7 @@ func checkSmartWalletProvisioned(ctx sdk.Context, keeper SwingSetKeeper, addr sd
|
|
|
91
109
|
// This is a separate charge from the smart wallet action which triggered the check
|
|
92
110
|
// TODO: Currently this call does not mark the smart wallet provisioning as
|
|
93
111
|
// pending, resulting in multiple provisioning charges for the owner.
|
|
94
|
-
return keeper.ChargeForSmartWallet(ctx, addr)
|
|
112
|
+
return keeper.ChargeForSmartWallet(ctx, beansPerUnit, addr)
|
|
95
113
|
}
|
|
96
114
|
}
|
|
97
115
|
|
|
@@ -118,7 +136,8 @@ func (msg MsgDeliverInbound) CheckAdmissibility(ctx sdk.Context, data interface{
|
|
|
118
136
|
}
|
|
119
137
|
*/
|
|
120
138
|
|
|
121
|
-
|
|
139
|
+
beansPerUnit := keeper.GetBeansPerUnit(ctx)
|
|
140
|
+
return chargeAdmission(ctx, keeper, beansPerUnit, msg.Submitter, msg.Messages, 0)
|
|
122
141
|
}
|
|
123
142
|
|
|
124
143
|
// GetInboundMsgCount implements InboundMsgCarrier.
|
|
@@ -184,12 +203,13 @@ func (msg MsgWalletAction) CheckAdmissibility(ctx sdk.Context, data interface{})
|
|
|
184
203
|
return sdkioerrors.Wrapf(sdkerrors.ErrInvalidRequest, "data must be a SwingSetKeeper, not a %T", data)
|
|
185
204
|
}
|
|
186
205
|
|
|
187
|
-
|
|
206
|
+
beansPerUnit := keeper.GetBeansPerUnit(ctx)
|
|
207
|
+
err := checkSmartWalletProvisioned(ctx, keeper, beansPerUnit, msg.Owner)
|
|
188
208
|
if err != nil {
|
|
189
209
|
return err
|
|
190
210
|
}
|
|
191
211
|
|
|
192
|
-
return chargeAdmission(ctx, keeper, msg.Owner, []string{msg.Action}, 0)
|
|
212
|
+
return chargeAdmission(ctx, keeper, beansPerUnit, msg.Owner, []string{msg.Action}, 0)
|
|
193
213
|
}
|
|
194
214
|
|
|
195
215
|
// GetInboundMsgCount implements InboundMsgCarrier.
|
|
@@ -256,12 +276,13 @@ func (msg MsgWalletSpendAction) CheckAdmissibility(ctx sdk.Context, data interfa
|
|
|
256
276
|
return sdkioerrors.Wrapf(sdkerrors.ErrInvalidRequest, "data must be a SwingSetKeeper, not a %T", data)
|
|
257
277
|
}
|
|
258
278
|
|
|
259
|
-
|
|
279
|
+
beansPerUnit := keeper.GetBeansPerUnit(ctx)
|
|
280
|
+
err := checkSmartWalletProvisioned(ctx, keeper, beansPerUnit, msg.Owner)
|
|
260
281
|
if err != nil {
|
|
261
282
|
return err
|
|
262
283
|
}
|
|
263
284
|
|
|
264
|
-
return chargeAdmission(ctx, keeper, msg.Owner, []string{msg.SpendAction}, 0)
|
|
285
|
+
return chargeAdmission(ctx, keeper, beansPerUnit, msg.Owner, []string{msg.SpendAction}, 0)
|
|
265
286
|
}
|
|
266
287
|
|
|
267
288
|
// GetInboundMsgCount implements InboundMsgCarrier.
|
|
@@ -373,7 +394,8 @@ func (msg MsgInstallBundle) CheckAdmissibility(ctx sdk.Context, data interface{}
|
|
|
373
394
|
if !ok {
|
|
374
395
|
return sdkioerrors.Wrapf(sdkerrors.ErrInvalidRequest, "data must be a SwingSetKeeper, not a %T", data)
|
|
375
396
|
}
|
|
376
|
-
|
|
397
|
+
beansPerUnit := keeper.GetBeansPerUnit(ctx)
|
|
398
|
+
return chargeAdmission(ctx, keeper, beansPerUnit, msg.Submitter, []string{msg.Bundle}, msg.ExpectedUncompressedSize())
|
|
377
399
|
}
|
|
378
400
|
|
|
379
401
|
// GetInboundMsgCount implements InboundMsgCarrier.
|