@agoric/cosmos 0.32.3-dev-7f04fe6.0 → 0.32.3-dev-9715146.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agoric/cosmos",
|
|
3
|
-
"version": "0.32.3-dev-
|
|
3
|
+
"version": "0.32.3-dev-9715146.0+9715146",
|
|
4
4
|
"description": "Connect JS to the Cosmos blockchain SDK",
|
|
5
5
|
"parsers": {
|
|
6
6
|
"js": "mjs"
|
|
@@ -47,5 +47,5 @@
|
|
|
47
47
|
"publishConfig": {
|
|
48
48
|
"access": "public"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "9715146ccac69dceadb01061b5dad8c27c11b856"
|
|
51
51
|
}
|
|
@@ -6,7 +6,6 @@ import (
|
|
|
6
6
|
"fmt"
|
|
7
7
|
stdlog "log"
|
|
8
8
|
"math"
|
|
9
|
-
"math/big"
|
|
10
9
|
|
|
11
10
|
"github.com/tendermint/tendermint/libs/log"
|
|
12
11
|
|
|
@@ -16,6 +15,7 @@ import (
|
|
|
16
15
|
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
|
|
17
16
|
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
|
|
18
17
|
|
|
18
|
+
"github.com/Agoric/agoric-sdk/golang/cosmos/ante"
|
|
19
19
|
"github.com/Agoric/agoric-sdk/golang/cosmos/vm"
|
|
20
20
|
"github.com/Agoric/agoric-sdk/golang/cosmos/x/swingset/types"
|
|
21
21
|
vstoragekeeper "github.com/Agoric/agoric-sdk/golang/cosmos/x/vstorage/keeper"
|
|
@@ -25,22 +25,21 @@ import (
|
|
|
25
25
|
// Top-level paths for chain storage should remain synchronized with
|
|
26
26
|
// packages/internal/src/chain-storage-paths.js
|
|
27
27
|
const (
|
|
28
|
-
StoragePathActionQueue
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
28
|
+
StoragePathActionQueue = "actionQueue"
|
|
29
|
+
StoragePathHighPriorityQueue = "highPriorityQueue"
|
|
30
|
+
StoragePathHighPrioritySenders = "highPrioritySenders"
|
|
31
|
+
StoragePathBeansOwing = "beansOwing"
|
|
32
|
+
StoragePathEgress = "egress"
|
|
33
|
+
StoragePathMailbox = "mailbox"
|
|
34
|
+
StoragePathCustom = "published"
|
|
35
|
+
StoragePathBundles = "bundles"
|
|
36
|
+
StoragePathSwingStore = "swingStore"
|
|
35
37
|
)
|
|
36
38
|
|
|
37
|
-
// 2 ** 256 - 1
|
|
38
|
-
var MaxSDKInt = sdk.NewIntFromBigInt(new(big.Int).Sub(new(big.Int).Exp(big.NewInt(2), big.NewInt(256), nil), big.NewInt(1)))
|
|
39
|
-
|
|
40
39
|
const stateKey string = "state"
|
|
41
40
|
|
|
42
|
-
// Contextual information about the message source of an action on
|
|
43
|
-
// This context should be unique per
|
|
41
|
+
// Contextual information about the message source of an action on an inbound queue.
|
|
42
|
+
// This context should be unique per inboundQueueRecord.
|
|
44
43
|
type actionContext struct {
|
|
45
44
|
// The block height in which the corresponding action was enqueued
|
|
46
45
|
BlockHeight int64 `json:"blockHeight"`
|
|
@@ -53,7 +52,7 @@ type actionContext struct {
|
|
|
53
52
|
// actionContext unique. (for example a counter per block and source module).
|
|
54
53
|
MsgIdx int `json:"msgIdx"`
|
|
55
54
|
}
|
|
56
|
-
type
|
|
55
|
+
type inboundQueueRecord struct {
|
|
57
56
|
Action vm.Jsonable `json:"action"`
|
|
58
57
|
Context actionContext `json:"context"`
|
|
59
58
|
}
|
|
@@ -74,6 +73,7 @@ type Keeper struct {
|
|
|
74
73
|
}
|
|
75
74
|
|
|
76
75
|
var _ types.SwingSetKeeper = &Keeper{}
|
|
76
|
+
var _ ante.SwingsetKeeper = &Keeper{}
|
|
77
77
|
|
|
78
78
|
// NewKeeper creates a new IBC transfer Keeper instance
|
|
79
79
|
func NewKeeper(
|
|
@@ -100,15 +100,15 @@ func NewKeeper(
|
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
-
//
|
|
104
|
-
// kept in the kvstore so that changes
|
|
103
|
+
// pushAction appends an action to the controller's specified inbound queue.
|
|
104
|
+
// The queue is kept in the kvstore so that changes are properly reverted if the
|
|
105
105
|
// kvstore is rolled back. By the time the block manager runs, it can commit
|
|
106
106
|
// its SwingSet transactions without fear of side-effecting the world with
|
|
107
107
|
// intermediate transaction state.
|
|
108
108
|
//
|
|
109
|
-
// The
|
|
109
|
+
// The inbound queue's format is documented by `makeChainQueue` in
|
|
110
110
|
// `packages/cosmic-swingset/src/helpers/make-queue.js`.
|
|
111
|
-
func (k Keeper)
|
|
111
|
+
func (k Keeper) pushAction(ctx sdk.Context, inboundQueuePath string, action vm.Jsonable) error {
|
|
112
112
|
txHash, txHashOk := ctx.Context().Value(baseapp.TxHashContextKey).(string)
|
|
113
113
|
if !txHashOk {
|
|
114
114
|
txHash = "unknown"
|
|
@@ -117,62 +117,47 @@ func (k Keeper) PushAction(ctx sdk.Context, action vm.Jsonable) error {
|
|
|
117
117
|
if !txHashOk || !msgIdxOk {
|
|
118
118
|
stdlog.Printf("error while extracting context for action %q\n", action)
|
|
119
119
|
}
|
|
120
|
-
record :=
|
|
120
|
+
record := inboundQueueRecord{Action: action, Context: actionContext{BlockHeight: ctx.BlockHeight(), TxHash: txHash, MsgIdx: msgIdx}}
|
|
121
121
|
bz, err := json.Marshal(record)
|
|
122
122
|
if err != nil {
|
|
123
123
|
return err
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
tail, err := k.actionQueueIndex(ctx, "tail")
|
|
129
|
-
if err != nil {
|
|
130
|
-
return err
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
if tail.Equal(MaxSDKInt) {
|
|
134
|
-
return errors.New(StoragePathActionQueue + " overflow")
|
|
135
|
-
}
|
|
136
|
-
nextTail := tail.Add(sdk.NewInt(1))
|
|
137
|
-
|
|
138
|
-
// Set the vstorage corresponding to the queue entry for the current tail.
|
|
139
|
-
path := StoragePathActionQueue + "." + tail.String()
|
|
140
|
-
k.vstorageKeeper.SetStorage(ctx, vstoragetypes.NewStorageEntry(path, string(bz)))
|
|
126
|
+
return k.vstorageKeeper.PushQueueItem(ctx, inboundQueuePath, string(bz))
|
|
127
|
+
}
|
|
141
128
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
k.
|
|
145
|
-
return nil
|
|
129
|
+
// PushAction appends an action to the controller's actionQueue.
|
|
130
|
+
func (k Keeper) PushAction(ctx sdk.Context, action vm.Jsonable) error {
|
|
131
|
+
return k.pushAction(ctx, StoragePathActionQueue, action)
|
|
146
132
|
}
|
|
147
133
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
if !indexEntry.HasData() {
|
|
153
|
-
return sdk.NewInt(0), nil
|
|
154
|
-
}
|
|
134
|
+
// PushAction appends an action to the controller's highPriorityQueue.
|
|
135
|
+
func (k Keeper) PushHighPriorityAction(ctx sdk.Context, action vm.Jsonable) error {
|
|
136
|
+
return k.pushAction(ctx, StoragePathHighPriorityQueue, action)
|
|
137
|
+
}
|
|
155
138
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
}
|
|
160
|
-
return index, nil
|
|
139
|
+
func (k Keeper) IsHighPriorityAddress(ctx sdk.Context, addr sdk.AccAddress) (bool, error) {
|
|
140
|
+
path := StoragePathHighPrioritySenders + "." + addr.String()
|
|
141
|
+
return k.vstorageKeeper.HasEntry(ctx, path), nil
|
|
161
142
|
}
|
|
162
143
|
|
|
163
|
-
func (k Keeper)
|
|
164
|
-
|
|
144
|
+
func (k Keeper) InboundQueueLength(ctx sdk.Context) (int32, error) {
|
|
145
|
+
size := sdk.NewInt(0)
|
|
146
|
+
|
|
147
|
+
highPriorityQueueLength, err := k.vstorageKeeper.GetQueueLength(ctx, StoragePathHighPriorityQueue)
|
|
165
148
|
if err != nil {
|
|
166
149
|
return 0, err
|
|
167
150
|
}
|
|
168
|
-
|
|
151
|
+
size = size.Add(highPriorityQueueLength)
|
|
152
|
+
|
|
153
|
+
actionQueueLength, err := k.vstorageKeeper.GetQueueLength(ctx, StoragePathActionQueue)
|
|
169
154
|
if err != nil {
|
|
170
155
|
return 0, err
|
|
171
156
|
}
|
|
172
|
-
|
|
173
|
-
|
|
157
|
+
size = size.Add(actionQueueLength)
|
|
158
|
+
|
|
174
159
|
if !size.IsInt64() {
|
|
175
|
-
return 0, fmt.Errorf("
|
|
160
|
+
return 0, fmt.Errorf("inbound queue size too big: %s", size)
|
|
176
161
|
}
|
|
177
162
|
|
|
178
163
|
int64Size := size.Int64()
|
|
@@ -190,7 +175,7 @@ func (k Keeper) UpdateQueueAllowed(ctx sdk.Context) error {
|
|
|
190
175
|
}
|
|
191
176
|
inboundMempoolQueueMax := inboundQueueMax / 2
|
|
192
177
|
|
|
193
|
-
inboundQueueSize, err := k.
|
|
178
|
+
inboundQueueSize, err := k.InboundQueueLength(ctx)
|
|
194
179
|
if err != nil {
|
|
195
180
|
return err
|
|
196
181
|
}
|
|
@@ -30,6 +30,19 @@ type deliverInboundAction struct {
|
|
|
30
30
|
BlockTime int64 `json:"blockTime"`
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
func (keeper msgServer) routeAction(ctx sdk.Context, msg vm.ControllerAdmissionMsg, action vm.Jsonable) error {
|
|
34
|
+
isHighPriority, err := msg.IsHighPriority(ctx, keeper)
|
|
35
|
+
if err != nil {
|
|
36
|
+
return err
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if isHighPriority {
|
|
40
|
+
return keeper.PushHighPriorityAction(ctx, action)
|
|
41
|
+
} else {
|
|
42
|
+
return keeper.PushAction(ctx, action)
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
33
46
|
func (keeper msgServer) DeliverInbound(goCtx context.Context, msg *types.MsgDeliverInbound) (*types.MsgDeliverInboundResponse, error) {
|
|
34
47
|
ctx := sdk.UnwrapSDKContext(goCtx)
|
|
35
48
|
|
|
@@ -50,7 +63,7 @@ func (keeper msgServer) DeliverInbound(goCtx context.Context, msg *types.MsgDeli
|
|
|
50
63
|
BlockTime: ctx.BlockTime().Unix(),
|
|
51
64
|
}
|
|
52
65
|
|
|
53
|
-
err := keeper.
|
|
66
|
+
err := keeper.routeAction(ctx, msg, action)
|
|
54
67
|
// fmt.Fprintln(os.Stderr, "Returned from SwingSet", out, err)
|
|
55
68
|
if err != nil {
|
|
56
69
|
return nil, err
|
|
@@ -78,7 +91,7 @@ func (keeper msgServer) WalletAction(goCtx context.Context, msg *types.MsgWallet
|
|
|
78
91
|
}
|
|
79
92
|
// fmt.Fprintf(os.Stderr, "Context is %+v\n", ctx)
|
|
80
93
|
|
|
81
|
-
err := keeper.
|
|
94
|
+
err := keeper.routeAction(ctx, msg, action)
|
|
82
95
|
// fmt.Fprintln(os.Stderr, "Returned from SwingSet", out, err)
|
|
83
96
|
if err != nil {
|
|
84
97
|
return nil, err
|
|
@@ -105,7 +118,7 @@ func (keeper msgServer) WalletSpendAction(goCtx context.Context, msg *types.MsgW
|
|
|
105
118
|
BlockTime: ctx.BlockTime().Unix(),
|
|
106
119
|
}
|
|
107
120
|
// fmt.Fprintf(os.Stderr, "Context is %+v\n", ctx)
|
|
108
|
-
err := keeper.
|
|
121
|
+
err := keeper.routeAction(ctx, msg, action)
|
|
109
122
|
if err != nil {
|
|
110
123
|
return nil, err
|
|
111
124
|
}
|
|
@@ -141,7 +154,7 @@ func (keeper msgServer) Provision(goCtx context.Context, msg *types.MsgProvision
|
|
|
141
154
|
return nil, err
|
|
142
155
|
}
|
|
143
156
|
|
|
144
|
-
err = keeper.
|
|
157
|
+
err = keeper.routeAction(ctx, msg, action)
|
|
145
158
|
// fmt.Fprintln(os.Stderr, "Returned from SwingSet", out, err)
|
|
146
159
|
if err != nil {
|
|
147
160
|
return nil, err
|
|
@@ -167,7 +180,7 @@ func (keeper msgServer) InstallBundle(goCtx context.Context, msg *types.MsgInsta
|
|
|
167
180
|
BlockTime: ctx.BlockTime().Unix(),
|
|
168
181
|
}
|
|
169
182
|
|
|
170
|
-
err := keeper.
|
|
183
|
+
err := keeper.routeAction(ctx, msg, action)
|
|
171
184
|
// fmt.Fprintln(os.Stderr, "Returned from SwingSet", out, err)
|
|
172
185
|
if err != nil {
|
|
173
186
|
return nil, err
|
|
@@ -14,4 +14,5 @@ type AccountKeeper interface {
|
|
|
14
14
|
type SwingSetKeeper interface {
|
|
15
15
|
GetBeansPerUnit(ctx sdk.Context) map[string]sdk.Uint
|
|
16
16
|
ChargeBeans(ctx sdk.Context, addr sdk.AccAddress, beans sdk.Uint) error
|
|
17
|
+
IsHighPriorityAddress(ctx sdk.Context, addr sdk.AccAddress) (bool, error)
|
|
17
18
|
}
|
package/x/swingset/types/msgs.go
CHANGED
|
@@ -72,6 +72,11 @@ func (msg MsgDeliverInbound) GetInboundMsgCount() int32 {
|
|
|
72
72
|
return 1
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
+
// IsHighPriority implements the vm.ControllerAdmissionMsg interface.
|
|
76
|
+
func (msg MsgDeliverInbound) IsHighPriority(ctx sdk.Context, data interface{}) (bool, error) {
|
|
77
|
+
return false, nil
|
|
78
|
+
}
|
|
79
|
+
|
|
75
80
|
// Route should return the name of the module
|
|
76
81
|
func (msg MsgDeliverInbound) Route() string { return RouterKey }
|
|
77
82
|
|
|
@@ -133,6 +138,11 @@ func (msg MsgWalletAction) GetInboundMsgCount() int32 {
|
|
|
133
138
|
return 1
|
|
134
139
|
}
|
|
135
140
|
|
|
141
|
+
// IsHighPriority implements the vm.ControllerAdmissionMsg interface.
|
|
142
|
+
func (msg MsgWalletAction) IsHighPriority(ctx sdk.Context, data interface{}) (bool, error) {
|
|
143
|
+
return false, nil
|
|
144
|
+
}
|
|
145
|
+
|
|
136
146
|
func (msg MsgWalletAction) GetSigners() []sdk.AccAddress {
|
|
137
147
|
return []sdk.AccAddress{msg.Owner}
|
|
138
148
|
}
|
|
@@ -194,6 +204,17 @@ func (msg MsgWalletSpendAction) CheckAdmissibility(ctx sdk.Context, data interfa
|
|
|
194
204
|
func (msg MsgWalletSpendAction) GetInboundMsgCount() int32 {
|
|
195
205
|
return 1
|
|
196
206
|
}
|
|
207
|
+
|
|
208
|
+
// IsHighPriority implements the vm.ControllerAdmissionMsg interface.
|
|
209
|
+
func (msg MsgWalletSpendAction) IsHighPriority(ctx sdk.Context, data interface{}) (bool, error) {
|
|
210
|
+
keeper, ok := data.(SwingSetKeeper)
|
|
211
|
+
if !ok {
|
|
212
|
+
return false, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "data must be a SwingSetKeeper, not a %T", data)
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
return keeper.IsHighPriorityAddress(ctx, msg.Owner)
|
|
216
|
+
}
|
|
217
|
+
|
|
197
218
|
func (msg MsgWalletSpendAction) GetSigners() []sdk.AccAddress {
|
|
198
219
|
return []sdk.AccAddress{msg.Owner}
|
|
199
220
|
}
|
|
@@ -253,6 +274,11 @@ func (msg MsgProvision) GetInboundMsgCount() int32 {
|
|
|
253
274
|
return 1
|
|
254
275
|
}
|
|
255
276
|
|
|
277
|
+
// IsHighPriority implements the vm.ControllerAdmissionMsg interface.
|
|
278
|
+
func (msg MsgProvision) IsHighPriority(ctx sdk.Context, data interface{}) (bool, error) {
|
|
279
|
+
return false, nil
|
|
280
|
+
}
|
|
281
|
+
|
|
256
282
|
// GetSignBytes encodes the message for signing
|
|
257
283
|
func (msg MsgProvision) GetSignBytes() []byte {
|
|
258
284
|
if msg.PowerFlags == nil {
|
|
@@ -288,6 +314,11 @@ func (msg MsgInstallBundle) GetInboundMsgCount() int32 {
|
|
|
288
314
|
return 1
|
|
289
315
|
}
|
|
290
316
|
|
|
317
|
+
// IsHighPriority implements the vm.ControllerAdmissionMsg interface.
|
|
318
|
+
func (msg MsgInstallBundle) IsHighPriority(ctx sdk.Context, data interface{}) (bool, error) {
|
|
319
|
+
return false, nil
|
|
320
|
+
}
|
|
321
|
+
|
|
291
322
|
// Route should return the name of the module
|
|
292
323
|
func (msg MsgInstallBundle) Route() string { return RouterKey }
|
|
293
324
|
|
|
@@ -3,7 +3,9 @@ package keeper
|
|
|
3
3
|
import (
|
|
4
4
|
"bytes"
|
|
5
5
|
"encoding/json"
|
|
6
|
+
"errors"
|
|
6
7
|
"fmt"
|
|
8
|
+
"math/big"
|
|
7
9
|
"sort"
|
|
8
10
|
"strconv"
|
|
9
11
|
"strings"
|
|
@@ -45,6 +47,9 @@ type BatchingChangeManager struct {
|
|
|
45
47
|
|
|
46
48
|
var _ ChangeManager = (*BatchingChangeManager)(nil)
|
|
47
49
|
|
|
50
|
+
// 2 ** 256 - 1
|
|
51
|
+
var MaxSDKInt = sdk.NewIntFromBigInt(new(big.Int).Sub(new(big.Int).Exp(big.NewInt(2), big.NewInt(256), nil), big.NewInt(1)))
|
|
52
|
+
|
|
48
53
|
// TODO: Use bytes.CutPrefix once we can rely upon go >= 1.20.
|
|
49
54
|
func cutPrefix(s, prefix []byte) (after []byte, found bool) {
|
|
50
55
|
if !bytes.HasPrefix(s, prefix) {
|
|
@@ -397,3 +402,52 @@ func (k Keeper) GetDataPrefix() []byte {
|
|
|
397
402
|
func (k Keeper) GetNoDataValue() []byte {
|
|
398
403
|
return types.EncodedNoDataValue
|
|
399
404
|
}
|
|
405
|
+
|
|
406
|
+
func (k Keeper) getIntValue(ctx sdk.Context, path string) (sdk.Int, error) {
|
|
407
|
+
indexEntry := k.GetEntry(ctx, path)
|
|
408
|
+
if !indexEntry.HasData() {
|
|
409
|
+
return sdk.NewInt(0), nil
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
index, ok := sdk.NewIntFromString(indexEntry.StringValue())
|
|
413
|
+
if !ok {
|
|
414
|
+
return index, fmt.Errorf("couldn't parse %s as Int: %s", path, indexEntry.StringValue())
|
|
415
|
+
}
|
|
416
|
+
return index, nil
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
func (k Keeper) GetQueueLength(ctx sdk.Context, queuePath string) (sdk.Int, error) {
|
|
420
|
+
head, err := k.getIntValue(ctx, queuePath+".head")
|
|
421
|
+
if err != nil {
|
|
422
|
+
return sdk.NewInt(0), err
|
|
423
|
+
}
|
|
424
|
+
tail, err := k.getIntValue(ctx, queuePath+".tail")
|
|
425
|
+
if err != nil {
|
|
426
|
+
return sdk.NewInt(0), err
|
|
427
|
+
}
|
|
428
|
+
// The tail index is exclusive
|
|
429
|
+
return tail.Sub(head), nil
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
func (k Keeper) PushQueueItem(ctx sdk.Context, queuePath string, value string) error {
|
|
433
|
+
// Get the current queue tail, defaulting to zero if its vstorage doesn't exist.
|
|
434
|
+
// The `tail` is the value of the next index to be inserted
|
|
435
|
+
tail, err := k.getIntValue(ctx, queuePath+".tail")
|
|
436
|
+
if err != nil {
|
|
437
|
+
return err
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
if tail.Equal(MaxSDKInt) {
|
|
441
|
+
return errors.New(queuePath + " overflow")
|
|
442
|
+
}
|
|
443
|
+
nextTail := tail.Add(sdk.NewInt(1))
|
|
444
|
+
|
|
445
|
+
// Set the vstorage corresponding to the queue entry for the current tail.
|
|
446
|
+
path := queuePath + "." + tail.String()
|
|
447
|
+
k.SetStorage(ctx, types.NewStorageEntry(path, value))
|
|
448
|
+
|
|
449
|
+
// Update the tail to point to the next available entry.
|
|
450
|
+
path = queuePath + ".tail"
|
|
451
|
+
k.SetStorage(ctx, types.NewStorageEntry(path, nextTail.String()))
|
|
452
|
+
return nil
|
|
453
|
+
}
|