@agoric/cosmos 0.35.0-u13.0 → 0.35.0-u14.1
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 +57 -0
- package/Makefile +25 -12
- package/ante/ante.go +5 -6
- package/app/app.go +142 -96
- package/app/export.go +13 -6
- package/cmd/agd/main.go +5 -3
- package/cmd/libdaemon/main.go +5 -2
- package/daemon/cmd/genaccounts.go +13 -9
- package/daemon/cmd/root.go +38 -15
- package/daemon/cmd/root_test.go +1 -1
- package/daemon/cmd/testnet.go +17 -6
- package/daemon/main.go +3 -2
- package/git-revision.txt +1 -1
- package/go.mod +95 -64
- package/go.sum +592 -243
- package/package.json +3 -3
- package/proto/agoric/vstorage/query.proto +53 -1
- package/scripts/protocgen.sh +12 -1
- package/third_party/proto/buf.yaml +1 -0
- package/third_party/proto/cosmos/base/query/v1beta1/pagination.proto +4 -1
- package/third_party/proto/cosmos/base/v1beta1/coin.proto +7 -4
- package/third_party/proto/cosmos/upgrade/v1beta1/upgrade.proto +16 -6
- package/third_party/proto/cosmos_proto/cosmos.proto +97 -0
- package/third_party/proto/google/api/annotations.proto +1 -1
- package/third_party/proto/google/api/http.proto +181 -120
- package/third_party/proto/google/api/httpbody.proto +9 -6
- package/third_party/proto/google/protobuf/any.proto +1 -7
- package/third_party/proto/ibc/core/channel/v1/channel.proto +15 -1
- package/third_party/proto/ibc/core/client/v1/client.proto +9 -6
- package/upgradegaia.sh +13 -4
- package/vm/action.go +133 -0
- package/vm/action_test.go +129 -0
- package/vm/controller.go +9 -16
- package/vm/core_proposals.go +31 -0
- package/x/lien/keeper/account.go +3 -3
- package/x/lien/keeper/keeper.go +5 -4
- package/x/lien/keeper/keeper_test.go +9 -9
- package/x/lien/lien.go +6 -4
- package/x/lien/lien_test.go +20 -16
- package/x/swingset/abci.go +25 -33
- package/x/swingset/client/cli/query.go +2 -2
- package/x/swingset/client/cli/tx.go +48 -33
- package/x/swingset/client/proposal_handler.go +2 -17
- package/x/swingset/keeper/keeper.go +30 -15
- package/x/swingset/keeper/keeper_test.go +1 -1
- package/x/swingset/keeper/msg_server.go +21 -51
- package/x/swingset/keeper/proposal.go +14 -8
- package/x/swingset/keeper/querier.go +14 -6
- package/x/swingset/keeper/swing_store_exports_handler.go +5 -1
- package/x/swingset/proposal_handler.go +3 -3
- package/x/swingset/swingset.go +4 -2
- package/x/swingset/types/codec.go +2 -2
- package/x/swingset/types/msgs.pb.go +16 -16
- package/x/swingset/types/proposal.go +5 -5
- package/x/swingset/types/types.go +30 -28
- package/x/vbank/keeper/keeper.go +3 -2
- package/x/vbank/keeper/querier.go +6 -2
- package/x/vbank/keeper/rewards.go +1 -1
- package/x/vbank/vbank.go +19 -17
- package/x/vbank/vbank_test.go +18 -18
- package/x/vibc/handler.go +3 -8
- package/x/vibc/ibc.go +66 -113
- package/x/vibc/keeper/keeper.go +19 -18
- package/x/vibc/types/expected_keepers.go +13 -5
- package/x/vibc/types/msgs.go +1 -1
- package/x/vibc/types/msgs.pb.go +1 -1
- package/x/vstorage/README.md +138 -0
- package/x/vstorage/capdata/capdata.go +298 -0
- package/x/vstorage/capdata/capdata_test.go +352 -0
- package/x/vstorage/client/cli/query.go +51 -4
- package/x/vstorage/keeper/grpc_query.go +221 -0
- package/x/vstorage/keeper/keeper.go +3 -2
- package/x/vstorage/keeper/keeper_grpc_test.go +300 -0
- package/x/vstorage/keeper/keeper_test.go +1 -1
- package/x/vstorage/keeper/querier.go +6 -2
- package/x/vstorage/types/query.pb.go +646 -36
- package/x/vstorage/types/query.pb.gw.go +119 -0
- package/x/vstorage/vstorage.go +16 -15
- package/x/vstorage/vstorage_test.go +5 -5
- package/ante/fee.go +0 -96
- /package/{src/index.cjs → index.cjs} +0 -0
package/vm/action.go
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
package vm
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"reflect"
|
|
5
|
+
"strconv"
|
|
6
|
+
"time"
|
|
7
|
+
|
|
8
|
+
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
var (
|
|
12
|
+
zeroTime = time.Time{}
|
|
13
|
+
actionHeaderType = reflect.TypeOf(ActionHeader{})
|
|
14
|
+
_ Action = &ActionHeader{}
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
// Jsonable is a value, j, that can be passed through json.Marshal(j).
|
|
18
|
+
type Jsonable interface{}
|
|
19
|
+
|
|
20
|
+
type Action interface {
|
|
21
|
+
GetActionHeader() ActionHeader
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// ActionPusher enqueues data for later consumption by the controller.
|
|
25
|
+
type ActionPusher func(ctx sdk.Context, action Action) error
|
|
26
|
+
|
|
27
|
+
// ActionHeader should be embedded in all actions. It is populated by PopulateAction.
|
|
28
|
+
type ActionHeader struct {
|
|
29
|
+
// Type defaults to the `actionType:"..."` tag of the embedder's ActionHeader field.
|
|
30
|
+
Type string `json:"type"`
|
|
31
|
+
// BlockHeight defaults to sdk.Context.BlockHeight().
|
|
32
|
+
BlockHeight int64 `json:"blockHeight,omitempty"`
|
|
33
|
+
// BlockTime defaults to sdk.Context.BlockTime().Unix().
|
|
34
|
+
BlockTime int64 `json:"blockTime,omitempty"`
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
func (ah ActionHeader) GetActionHeader() ActionHeader {
|
|
38
|
+
return ah
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// SetActionHeaderFromContext provides defaults to an ActionHeader.
|
|
42
|
+
func SetActionHeaderFromContext(ctx sdk.Context, actionType string, ah *ActionHeader) {
|
|
43
|
+
// Default the action type.
|
|
44
|
+
if len(ah.Type) == 0 {
|
|
45
|
+
ah.Type = actionType
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Default the block height.
|
|
49
|
+
if ah.BlockHeight == 0 {
|
|
50
|
+
ah.BlockHeight = ctx.BlockHeight()
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if ah.BlockTime == 0 {
|
|
54
|
+
// Only default to a non-zero block time.
|
|
55
|
+
if blockTime := ctx.BlockTime(); blockTime != zeroTime {
|
|
56
|
+
ah.BlockTime = blockTime.Unix()
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// PopulateAction returns a clone of action in which empty/zero-valued fields
|
|
62
|
+
// in its embedded ActionHeader have been populated using the corresponding
|
|
63
|
+
// `actionType:"..."` tag and the provided ctx, and its own empty/zero-valued
|
|
64
|
+
// fields have been populated as specified by their `default:"..."` tags.
|
|
65
|
+
func PopulateAction(ctx sdk.Context, action Action) Action {
|
|
66
|
+
oldActionDesc := reflect.Indirect(reflect.ValueOf(action))
|
|
67
|
+
if oldActionDesc.Kind() != reflect.Struct {
|
|
68
|
+
return action
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Shallow copy to a new value.
|
|
72
|
+
newActionDescPtr := reflect.New(oldActionDesc.Type())
|
|
73
|
+
newActionDesc := reflect.Indirect(newActionDescPtr)
|
|
74
|
+
for i := 0; i < newActionDesc.NumField(); i++ {
|
|
75
|
+
oldField := oldActionDesc.Field(i)
|
|
76
|
+
field := newActionDesc.Field(i)
|
|
77
|
+
fieldType := newActionDesc.Type().Field(i)
|
|
78
|
+
if !field.CanSet() {
|
|
79
|
+
continue
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Copy from original.
|
|
83
|
+
field.Set(oldField)
|
|
84
|
+
|
|
85
|
+
// Populate any ActionHeader struct.
|
|
86
|
+
var headerPtr *ActionHeader
|
|
87
|
+
if fieldType.Type == actionHeaderType {
|
|
88
|
+
headerPtr = field.Addr().Interface().(*ActionHeader)
|
|
89
|
+
} else if fieldType.Type == reflect.PtrTo(actionHeaderType) {
|
|
90
|
+
if field.IsNil() {
|
|
91
|
+
headerPtr = &ActionHeader{}
|
|
92
|
+
} else {
|
|
93
|
+
headerPtr = field.Interface().(*ActionHeader)
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
if headerPtr != nil {
|
|
97
|
+
actionTypeTag, _ := fieldType.Tag.Lookup("actionType")
|
|
98
|
+
newHeader := *headerPtr
|
|
99
|
+
SetActionHeaderFromContext(ctx, actionTypeTag, &newHeader)
|
|
100
|
+
if field.Kind() == reflect.Ptr {
|
|
101
|
+
field.Set(reflect.ValueOf(&newHeader))
|
|
102
|
+
} else {
|
|
103
|
+
field.Set(reflect.ValueOf(newHeader))
|
|
104
|
+
}
|
|
105
|
+
continue
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Skip any field that is already populated or lacks a "default" tag.
|
|
109
|
+
defaultTag, _ := fieldType.Tag.Lookup("default")
|
|
110
|
+
if !field.IsZero() || len(defaultTag) == 0 {
|
|
111
|
+
continue
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Populate the field from its "default" tag.
|
|
115
|
+
switch field.Kind() {
|
|
116
|
+
case reflect.String:
|
|
117
|
+
field.SetString(defaultTag)
|
|
118
|
+
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
|
119
|
+
if val, err := strconv.ParseInt(defaultTag, 0, 64); err == nil {
|
|
120
|
+
field.SetInt(val)
|
|
121
|
+
}
|
|
122
|
+
case reflect.Bool:
|
|
123
|
+
if val, err := strconv.ParseBool(defaultTag); err == nil {
|
|
124
|
+
field.SetBool(val)
|
|
125
|
+
}
|
|
126
|
+
case reflect.Float32, reflect.Float64:
|
|
127
|
+
if val, err := strconv.ParseFloat(defaultTag, 64); err == nil {
|
|
128
|
+
field.SetFloat(val)
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return newActionDesc.Interface().(Action)
|
|
133
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
package vm_test
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"encoding/json"
|
|
5
|
+
"testing"
|
|
6
|
+
"time"
|
|
7
|
+
|
|
8
|
+
"github.com/Agoric/agoric-sdk/golang/cosmos/vm"
|
|
9
|
+
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
var (
|
|
13
|
+
_ vm.Action = &Trivial{}
|
|
14
|
+
_ vm.Action = &Defaults{}
|
|
15
|
+
_ vm.Action = &dataAction{}
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
type Trivial struct {
|
|
19
|
+
vm.ActionHeader
|
|
20
|
+
Abc int
|
|
21
|
+
def string
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
type Defaults struct {
|
|
25
|
+
String string `default:"abc"`
|
|
26
|
+
Int int `default:"123"`
|
|
27
|
+
Float float64 `default:"4.56"`
|
|
28
|
+
Bool bool `default:"true"`
|
|
29
|
+
Any interface{}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
func (d Defaults) GetActionHeader() vm.ActionHeader {
|
|
33
|
+
return vm.ActionHeader{}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
type dataAction struct {
|
|
37
|
+
*vm.ActionHeader `actionType:"DATA_ACTION"`
|
|
38
|
+
Data []byte
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
func TestActionContext(t *testing.T) {
|
|
42
|
+
emptyCtx := sdk.Context{}
|
|
43
|
+
|
|
44
|
+
testCases := []struct {
|
|
45
|
+
name string
|
|
46
|
+
ctx sdk.Context
|
|
47
|
+
in vm.Action
|
|
48
|
+
expectedOut interface{}
|
|
49
|
+
}{
|
|
50
|
+
{"nil", emptyCtx, nil, nil},
|
|
51
|
+
{"no context", emptyCtx,
|
|
52
|
+
&Trivial{Abc: 123, def: "zot"},
|
|
53
|
+
&Trivial{Abc: 123, def: "zot"},
|
|
54
|
+
},
|
|
55
|
+
{"block height",
|
|
56
|
+
emptyCtx.WithBlockHeight(998),
|
|
57
|
+
&Trivial{Abc: 123, def: "zot"},
|
|
58
|
+
&Trivial{ActionHeader: vm.ActionHeader{BlockHeight: 998}, Abc: 123, def: "zot"},
|
|
59
|
+
},
|
|
60
|
+
{"block time",
|
|
61
|
+
emptyCtx.WithBlockTime(time.UnixMicro(1_000_000)),
|
|
62
|
+
&Trivial{Abc: 123, def: "zot"},
|
|
63
|
+
&Trivial{Abc: 123, def: "zot", ActionHeader: vm.ActionHeader{BlockTime: 1}},
|
|
64
|
+
},
|
|
65
|
+
{"default tags",
|
|
66
|
+
emptyCtx,
|
|
67
|
+
&Defaults{},
|
|
68
|
+
&Defaults{"abc", 123, 4.56, true, nil},
|
|
69
|
+
},
|
|
70
|
+
{"data action defaults",
|
|
71
|
+
emptyCtx.WithBlockHeight(998).WithBlockTime(time.UnixMicro(1_000_000)),
|
|
72
|
+
&dataAction{Data: []byte("hello")},
|
|
73
|
+
&dataAction{Data: []byte("hello"),
|
|
74
|
+
ActionHeader: &vm.ActionHeader{Type: "DATA_ACTION", BlockHeight: 998, BlockTime: 1}},
|
|
75
|
+
},
|
|
76
|
+
{"data action override Type",
|
|
77
|
+
emptyCtx.WithBlockHeight(998).WithBlockTime(time.UnixMicro(1_000_000)),
|
|
78
|
+
&dataAction{Data: []byte("hello2"),
|
|
79
|
+
ActionHeader: &vm.ActionHeader{Type: "DATA_ACTION2"}},
|
|
80
|
+
&dataAction{Data: []byte("hello2"),
|
|
81
|
+
ActionHeader: &vm.ActionHeader{Type: "DATA_ACTION2", BlockHeight: 998, BlockTime: 1}},
|
|
82
|
+
},
|
|
83
|
+
{"data action override BlockHeight",
|
|
84
|
+
emptyCtx.WithBlockHeight(998).WithBlockTime(time.UnixMicro(1_000_000)),
|
|
85
|
+
&dataAction{Data: []byte("hello2"),
|
|
86
|
+
ActionHeader: &vm.ActionHeader{BlockHeight: 999}},
|
|
87
|
+
&dataAction{Data: []byte("hello2"),
|
|
88
|
+
ActionHeader: &vm.ActionHeader{Type: "DATA_ACTION", BlockHeight: 999, BlockTime: 1}},
|
|
89
|
+
},
|
|
90
|
+
{"data action override BlockTime",
|
|
91
|
+
emptyCtx.WithBlockHeight(998).WithBlockTime(time.UnixMicro(1_000_000)),
|
|
92
|
+
&dataAction{Data: []byte("hello2"),
|
|
93
|
+
ActionHeader: &vm.ActionHeader{BlockTime: 2}},
|
|
94
|
+
&dataAction{Data: []byte("hello2"),
|
|
95
|
+
ActionHeader: &vm.ActionHeader{Type: "DATA_ACTION", BlockHeight: 998, BlockTime: 2}},
|
|
96
|
+
},
|
|
97
|
+
{"data action override all defaults",
|
|
98
|
+
emptyCtx.WithBlockHeight(998).WithBlockTime(time.UnixMicro(1_000_000)),
|
|
99
|
+
&dataAction{Data: []byte("hello2"),
|
|
100
|
+
ActionHeader: &vm.ActionHeader{Type: "DATA_ACTION2", BlockHeight: 999, BlockTime: 2}},
|
|
101
|
+
&dataAction{Data: []byte("hello2"),
|
|
102
|
+
ActionHeader: &vm.ActionHeader{Type: "DATA_ACTION2", BlockHeight: 999, BlockTime: 2}},
|
|
103
|
+
},
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
for _, tc := range testCases {
|
|
107
|
+
tc := tc
|
|
108
|
+
t.Run(tc.name, func(t *testing.T) {
|
|
109
|
+
toJson := func(in interface{}) string {
|
|
110
|
+
bz, err := json.Marshal(in)
|
|
111
|
+
if err != nil {
|
|
112
|
+
t.Fatal(err)
|
|
113
|
+
}
|
|
114
|
+
return string(bz)
|
|
115
|
+
}
|
|
116
|
+
jsonIn := toJson(tc.in)
|
|
117
|
+
out := vm.PopulateAction(tc.ctx, tc.in)
|
|
118
|
+
jsonIn2 := toJson(tc.in)
|
|
119
|
+
if jsonIn != jsonIn2 {
|
|
120
|
+
t.Errorf("unexpected mutated input: %s to %s", jsonIn, jsonIn2)
|
|
121
|
+
}
|
|
122
|
+
jsonOut := toJson(out)
|
|
123
|
+
jsonExpectedOut := toJson(tc.expectedOut)
|
|
124
|
+
if jsonOut != jsonExpectedOut {
|
|
125
|
+
t.Errorf("expected %s, got %s", jsonExpectedOut, jsonOut)
|
|
126
|
+
}
|
|
127
|
+
})
|
|
128
|
+
}
|
|
129
|
+
}
|
package/vm/controller.go
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
package vm
|
|
2
2
|
|
|
3
3
|
import (
|
|
4
|
+
"context"
|
|
4
5
|
"fmt"
|
|
5
6
|
|
|
6
7
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
7
8
|
)
|
|
8
9
|
|
|
9
|
-
type ControllerContext struct {
|
|
10
|
-
Context sdk.Context
|
|
11
|
-
IBCChannelHandlerPort int
|
|
12
|
-
}
|
|
13
|
-
|
|
14
10
|
type ControllerAdmissionMsg interface {
|
|
15
11
|
sdk.Msg
|
|
16
12
|
CheckAdmissibility(sdk.Context, interface{}) error
|
|
@@ -25,16 +21,13 @@ type ControllerAdmissionMsg interface {
|
|
|
25
21
|
IsHighPriority(sdk.Context, interface{}) (bool, error)
|
|
26
22
|
}
|
|
27
23
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
type ActionPusher func(ctx sdk.Context, action Jsonable) error
|
|
33
|
-
|
|
34
|
-
var controllerContext ControllerContext
|
|
24
|
+
var wrappedEmptySDKContext = sdk.WrapSDKContext(
|
|
25
|
+
sdk.Context{}.WithContext(context.Background()),
|
|
26
|
+
)
|
|
27
|
+
var controllerContext context.Context = wrappedEmptySDKContext
|
|
35
28
|
|
|
36
29
|
type PortHandler interface {
|
|
37
|
-
Receive(
|
|
30
|
+
Receive(context.Context, string) (string, error)
|
|
38
31
|
}
|
|
39
32
|
|
|
40
33
|
var portToHandler = make(map[int]PortHandler)
|
|
@@ -45,9 +38,9 @@ var lastPort = 0
|
|
|
45
38
|
func SetControllerContext(ctx sdk.Context) func() {
|
|
46
39
|
// We are only called by the controller, so we assume that it is billing its
|
|
47
40
|
// own meter usage.
|
|
48
|
-
controllerContext
|
|
41
|
+
controllerContext = sdk.WrapSDKContext(ctx.WithGasMeter(sdk.NewInfiniteGasMeter()))
|
|
49
42
|
return func() {
|
|
50
|
-
controllerContext
|
|
43
|
+
controllerContext = wrappedEmptySDKContext
|
|
51
44
|
}
|
|
52
45
|
}
|
|
53
46
|
|
|
@@ -75,5 +68,5 @@ func ReceiveFromController(portNum int, msg string) (string, error) {
|
|
|
75
68
|
if handler == nil {
|
|
76
69
|
return "", fmt.Errorf("unregistered port %d", portNum)
|
|
77
70
|
}
|
|
78
|
-
return handler.Receive(
|
|
71
|
+
return handler.Receive(controllerContext, msg)
|
|
79
72
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
package vm
|
|
2
|
+
|
|
3
|
+
// CoreProposalStep is a set of core proposal configs which are executed
|
|
4
|
+
// concurrently
|
|
5
|
+
type CoreProposalStep []Jsonable
|
|
6
|
+
|
|
7
|
+
// CoreProposals is one possible shape for core proposals expressed as a series
|
|
8
|
+
// of sequential steps
|
|
9
|
+
// see SequentialCoreProposals in packages/deploy-script-support/src/extract-proposal.js
|
|
10
|
+
type CoreProposals struct {
|
|
11
|
+
Steps []CoreProposalStep `json:"steps"`
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// CoreProposalStepForModules generates a single core proposal step from
|
|
15
|
+
// the given modules, which will be executed concurrently during that step
|
|
16
|
+
func CoreProposalStepForModules(modules ...string) CoreProposalStep {
|
|
17
|
+
step := make([]Jsonable, len(modules))
|
|
18
|
+
for i := range modules {
|
|
19
|
+
step[i] = modules[i]
|
|
20
|
+
}
|
|
21
|
+
return step
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// CoreProposalsFromSteps returns a CoreProposals from the given steps
|
|
25
|
+
func CoreProposalsFromSteps(steps ...CoreProposalStep) *CoreProposals {
|
|
26
|
+
if steps == nil {
|
|
27
|
+
// Deal with https://github.com/golang/go/issues/37711
|
|
28
|
+
return &CoreProposals{Steps: []CoreProposalStep{}}
|
|
29
|
+
}
|
|
30
|
+
return &CoreProposals{Steps: steps}
|
|
31
|
+
}
|
package/x/lien/keeper/account.go
CHANGED
|
@@ -88,7 +88,7 @@ func (uva unlockedVestingAccount) TrackDelegation(blockTime time.Time, balance,
|
|
|
88
88
|
// TrackUndelegation implements the vestexported.VestingAccount interface.
|
|
89
89
|
func (uva unlockedVestingAccount) TrackUndelegation(amount sdk.Coins) {
|
|
90
90
|
// max(delegated - amount, 0) == delegated - min(delegated, amount)
|
|
91
|
-
uva.lien.Delegated = uva.lien.Delegated.Sub(uva.lien.Delegated.Min(amount))
|
|
91
|
+
uva.lien.Delegated = uva.lien.Delegated.Sub(uva.lien.Delegated.Min(amount)...)
|
|
92
92
|
}
|
|
93
93
|
|
|
94
94
|
// GetVestedCoins implements the vestexported.VestingAccount interface.
|
|
@@ -211,12 +211,12 @@ func (la *LienAccount) LienedLockedCoins(ctx sdk.Context) sdk.Coins {
|
|
|
211
211
|
liened := la.lien.Coins
|
|
212
212
|
acc := la.omniClawbackAccount.(authtypes.AccountI)
|
|
213
213
|
if clawback, ok := acc.(vestexported.ClawbackVestingAccountI); ok {
|
|
214
|
-
liened = liened.Add(clawback.GetOriginalVesting().Sub(clawback.GetVestedOnly(ctx.BlockTime()))...)
|
|
214
|
+
liened = liened.Add(clawback.GetOriginalVesting().Sub(clawback.GetVestedOnly(ctx.BlockTime())...)...)
|
|
215
215
|
}
|
|
216
216
|
// Since coins can't go negative, even transiently, use the
|
|
217
217
|
// identity A + B = max(A, B) + min(A, B)
|
|
218
218
|
// max(0, A - B) = max(B, A) - B = A - min(A, B)
|
|
219
|
-
return liened.Sub(liened.Min(delegated))
|
|
219
|
+
return liened.Sub(liened.Min(delegated)...)
|
|
220
220
|
}
|
|
221
221
|
|
|
222
222
|
// XXX_MessageName provides the message name for JSON serialization.
|
package/x/lien/keeper/keeper.go
CHANGED
|
@@ -7,6 +7,7 @@ import (
|
|
|
7
7
|
"github.com/Agoric/agoric-sdk/golang/cosmos/x/lien/types"
|
|
8
8
|
|
|
9
9
|
"github.com/cosmos/cosmos-sdk/codec"
|
|
10
|
+
storetypes "github.com/cosmos/cosmos-sdk/store/types"
|
|
10
11
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
11
12
|
vestexported "github.com/cosmos/cosmos-sdk/x/auth/vesting/exported"
|
|
12
13
|
stakingTypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
|
@@ -31,7 +32,7 @@ type Keeper interface {
|
|
|
31
32
|
// The accountKeeper field must be the same one that the bankKeeper and
|
|
32
33
|
// stakingKeeper use.
|
|
33
34
|
type keeperImpl struct {
|
|
34
|
-
key
|
|
35
|
+
key storetypes.StoreKey
|
|
35
36
|
cdc codec.Codec
|
|
36
37
|
|
|
37
38
|
accountKeeper *types.WrappedAccountKeeper
|
|
@@ -43,7 +44,7 @@ type keeperImpl struct {
|
|
|
43
44
|
|
|
44
45
|
// NewKeeper returns a new Keeper.
|
|
45
46
|
// The ak must be the same accout keeper that the bk and sk use.
|
|
46
|
-
func NewKeeper(cdc codec.Codec, key
|
|
47
|
+
func NewKeeper(cdc codec.Codec, key storetypes.StoreKey, ak *types.WrappedAccountKeeper, bk types.BankKeeper, sk types.StakingKeeper,
|
|
47
48
|
pushAction vm.ActionPusher) Keeper {
|
|
48
49
|
return keeperImpl{
|
|
49
50
|
key: key,
|
|
@@ -124,7 +125,7 @@ func (lk keeperImpl) ChangeLien(ctx sdk.Context, addr sdk.AccAddress, denom stri
|
|
|
124
125
|
return oldAmt, fmt.Errorf("lien delta of %s is larger than existing balance %s", delta, oldAmt)
|
|
125
126
|
}
|
|
126
127
|
newCoin := sdk.NewCoin(denom, newAmt)
|
|
127
|
-
newCoins := oldCoins.Sub(sdk.NewCoins(sdk.NewCoin(denom, oldAmt))).Add(newCoin)
|
|
128
|
+
newCoins := oldCoins.Sub(sdk.NewCoins(sdk.NewCoin(denom, oldAmt))...).Add(newCoin)
|
|
128
129
|
newLien := types.Lien{
|
|
129
130
|
Coins: newCoins,
|
|
130
131
|
Delegated: oldLien.Delegated,
|
|
@@ -223,7 +224,7 @@ func (lk keeperImpl) getLockedUnvested(ctx sdk.Context, addr sdk.AccAddress) (sd
|
|
|
223
224
|
original := clawbackAccount.GetOriginalVesting()
|
|
224
225
|
unlocked := clawbackAccount.GetUnlockedOnly(ctx.BlockTime())
|
|
225
226
|
vested := clawbackAccount.GetVestedOnly(ctx.BlockTime())
|
|
226
|
-
return original.Sub(unlocked), original.Sub(vested)
|
|
227
|
+
return original.Sub(unlocked...), original.Sub(vested...)
|
|
227
228
|
}
|
|
228
229
|
if vestingAccount, ok := account.(vestexported.VestingAccount); ok {
|
|
229
230
|
return vestingAccount.GetVestingCoins(ctx.BlockTime()), sdk.NewCoins()
|
|
@@ -99,7 +99,7 @@ func makeTestKit() testKit {
|
|
|
99
99
|
stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking},
|
|
100
100
|
authtypes.Minter: {authtypes.Minter},
|
|
101
101
|
}
|
|
102
|
-
innerAk := authkeeper.NewAccountKeeper(cdc, authStoreKey, authSpace, authtypes.ProtoBaseAccount, maccPerms)
|
|
102
|
+
innerAk := authkeeper.NewAccountKeeper(cdc, authStoreKey, authSpace, authtypes.ProtoBaseAccount, maccPerms, "agoric")
|
|
103
103
|
wak := types.NewWrappedAccountKeeper(innerAk)
|
|
104
104
|
|
|
105
105
|
// bank keeper
|
|
@@ -112,7 +112,7 @@ func makeTestKit() testKit {
|
|
|
112
112
|
sk := stakingkeeper.NewKeeper(cdc, stakingStoreKey, wak, bk, stakingSpace)
|
|
113
113
|
|
|
114
114
|
// lien keeper
|
|
115
|
-
pushAction := func(sdk.Context, vm.
|
|
115
|
+
pushAction := func(sdk.Context, vm.Action) error {
|
|
116
116
|
return nil
|
|
117
117
|
}
|
|
118
118
|
keeper := NewKeeper(cdc, lienStoreKey, wak, bk, sk, pushAction)
|
|
@@ -120,12 +120,12 @@ func makeTestKit() testKit {
|
|
|
120
120
|
|
|
121
121
|
db := dbm.NewMemDB()
|
|
122
122
|
ms := store.NewCommitMultiStore(db)
|
|
123
|
-
ms.MountStoreWithDB(paramsTKey,
|
|
124
|
-
ms.MountStoreWithDB(paramsStoreKey,
|
|
125
|
-
ms.MountStoreWithDB(authStoreKey,
|
|
126
|
-
ms.MountStoreWithDB(bankStoreKey,
|
|
127
|
-
ms.MountStoreWithDB(stakingStoreKey,
|
|
128
|
-
ms.MountStoreWithDB(lienStoreKey,
|
|
123
|
+
ms.MountStoreWithDB(paramsTKey, storetypes.StoreTypeTransient, nil)
|
|
124
|
+
ms.MountStoreWithDB(paramsStoreKey, storetypes.StoreTypeIAVL, db)
|
|
125
|
+
ms.MountStoreWithDB(authStoreKey, storetypes.StoreTypeIAVL, db)
|
|
126
|
+
ms.MountStoreWithDB(bankStoreKey, storetypes.StoreTypeIAVL, db)
|
|
127
|
+
ms.MountStoreWithDB(stakingStoreKey, storetypes.StoreTypeIAVL, db)
|
|
128
|
+
ms.MountStoreWithDB(lienStoreKey, storetypes.StoreTypeIAVL, db)
|
|
129
129
|
err := ms.LoadLatestVersion()
|
|
130
130
|
if err != nil {
|
|
131
131
|
panic(err)
|
|
@@ -165,7 +165,7 @@ func (tk testKit) initAccount(t *testing.T, funder, addr sdk.AccAddress, state t
|
|
|
165
165
|
}
|
|
166
166
|
|
|
167
167
|
// Total
|
|
168
|
-
toMint := state.Total.Sub(state.Locked)
|
|
168
|
+
toMint := state.Total.Sub(state.Locked...)
|
|
169
169
|
if !toMint.IsZero() {
|
|
170
170
|
err := tk.bankKeeper.MintCoins(tk.ctx, authtypes.Minter, toMint)
|
|
171
171
|
if err != nil {
|
package/x/lien/lien.go
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
package lien
|
|
6
6
|
|
|
7
7
|
import (
|
|
8
|
+
"context"
|
|
8
9
|
"encoding/json"
|
|
9
10
|
"fmt"
|
|
10
11
|
"math"
|
|
@@ -70,7 +71,8 @@ const (
|
|
|
70
71
|
// Receives and processes a bridge message, returning the
|
|
71
72
|
// JSON-encoded response or error.
|
|
72
73
|
// See spec/02_messages.md for the messages and responses.
|
|
73
|
-
func (ch portHandler) Receive(
|
|
74
|
+
func (ch portHandler) Receive(cctx context.Context, str string) (string, error) {
|
|
75
|
+
ctx := sdk.UnwrapSDKContext(cctx)
|
|
74
76
|
var msg portMessage
|
|
75
77
|
err := json.Unmarshal([]byte(str), &msg)
|
|
76
78
|
if err != nil {
|
|
@@ -78,13 +80,13 @@ func (ch portHandler) Receive(ctx *vm.ControllerContext, str string) (string, er
|
|
|
78
80
|
}
|
|
79
81
|
switch msg.Type {
|
|
80
82
|
case LIEN_GET_ACCOUNT_STATE:
|
|
81
|
-
return ch.handleGetAccountState(ctx
|
|
83
|
+
return ch.handleGetAccountState(ctx, msg)
|
|
82
84
|
|
|
83
85
|
case LIEN_GET_STAKING:
|
|
84
|
-
return ch.handleGetStaking(ctx
|
|
86
|
+
return ch.handleGetStaking(ctx, msg)
|
|
85
87
|
|
|
86
88
|
case LIEN_CHANGE_LIENED:
|
|
87
|
-
return ch.handleChangeLiened(ctx
|
|
89
|
+
return ch.handleChangeLiened(ctx, msg)
|
|
88
90
|
}
|
|
89
91
|
return "", fmt.Errorf("unrecognized type %s", msg.Type)
|
|
90
92
|
}
|
package/x/lien/lien_test.go
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
package lien
|
|
2
2
|
|
|
3
3
|
import (
|
|
4
|
+
"context"
|
|
4
5
|
"encoding/json"
|
|
5
6
|
"reflect"
|
|
6
7
|
"testing"
|
|
7
8
|
|
|
8
|
-
"github.com/Agoric/agoric-sdk/golang/cosmos/vm"
|
|
9
9
|
"github.com/Agoric/agoric-sdk/golang/cosmos/x/lien/types"
|
|
10
10
|
|
|
11
11
|
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
|
|
@@ -97,7 +97,7 @@ func (m *mockLienKeeper) BondDenom(ctx sdk.Context) string {
|
|
|
97
97
|
func (m *mockLienKeeper) GetAllBalances(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins {
|
|
98
98
|
state := m.GetAccountState(ctx, addr)
|
|
99
99
|
delegated := state.Bonded.Add(state.Unbonding...)
|
|
100
|
-
bank := state.Total.Sub(state.Total.Min(delegated))
|
|
100
|
+
bank := state.Total.Sub(state.Total.Min(delegated)...)
|
|
101
101
|
return bank
|
|
102
102
|
}
|
|
103
103
|
|
|
@@ -114,8 +114,8 @@ func (m *mockLienKeeper) GetDelegatorDelegations(ctx sdk.Context, delegator sdk.
|
|
|
114
114
|
}
|
|
115
115
|
|
|
116
116
|
func TestBadType(t *testing.T) {
|
|
117
|
-
ctx := sdk.Context{}
|
|
118
|
-
ctlCtx :=
|
|
117
|
+
ctx := sdk.Context{}.WithContext(context.Background())
|
|
118
|
+
ctlCtx := sdk.WrapSDKContext(ctx)
|
|
119
119
|
keeper := mockLienKeeper{
|
|
120
120
|
states: map[string]types.AccountState{},
|
|
121
121
|
}
|
|
@@ -135,8 +135,8 @@ func TestBadType(t *testing.T) {
|
|
|
135
135
|
}
|
|
136
136
|
|
|
137
137
|
func TestGetAccountState(t *testing.T) {
|
|
138
|
-
ctx := sdk.Context{}
|
|
139
|
-
ctlCtx :=
|
|
138
|
+
ctx := sdk.Context{}.WithContext(context.Background())
|
|
139
|
+
ctlCtx := sdk.WrapSDKContext(ctx)
|
|
140
140
|
|
|
141
141
|
keeper := mockLienKeeper{
|
|
142
142
|
states: map[string]types.AccountState{
|
|
@@ -177,8 +177,9 @@ func TestGetAccountState(t *testing.T) {
|
|
|
177
177
|
}
|
|
178
178
|
|
|
179
179
|
func TestGetAccountState_badRequest(t *testing.T) {
|
|
180
|
-
ctx := sdk.Context{}
|
|
181
|
-
ctlCtx :=
|
|
180
|
+
ctx := sdk.Context{}.WithContext(context.Background())
|
|
181
|
+
ctlCtx := sdk.WrapSDKContext(ctx)
|
|
182
|
+
|
|
182
183
|
keeper := mockLienKeeper{
|
|
183
184
|
states: map[string]types.AccountState{},
|
|
184
185
|
}
|
|
@@ -214,8 +215,9 @@ func TestGetAccountState_badRequest(t *testing.T) {
|
|
|
214
215
|
}
|
|
215
216
|
|
|
216
217
|
func TestSetLiened_badAddr(t *testing.T) {
|
|
217
|
-
ctx := sdk.Context{}
|
|
218
|
-
ctlCtx :=
|
|
218
|
+
ctx := sdk.Context{}.WithContext(context.Background())
|
|
219
|
+
ctlCtx := sdk.WrapSDKContext(ctx)
|
|
220
|
+
|
|
219
221
|
keeper := mockLienKeeper{}
|
|
220
222
|
ph := NewPortHandler(&keeper)
|
|
221
223
|
msg := portMessage{
|
|
@@ -235,8 +237,9 @@ func TestSetLiened_badAddr(t *testing.T) {
|
|
|
235
237
|
}
|
|
236
238
|
|
|
237
239
|
func TestSetLiened_badDenom(t *testing.T) {
|
|
238
|
-
ctx := sdk.Context{}
|
|
239
|
-
ctlCtx :=
|
|
240
|
+
ctx := sdk.Context{}.WithContext(context.Background())
|
|
241
|
+
ctlCtx := sdk.WrapSDKContext(ctx)
|
|
242
|
+
|
|
240
243
|
keeper := mockLienKeeper{}
|
|
241
244
|
ph := NewPortHandler(&keeper)
|
|
242
245
|
msg := portMessage{
|
|
@@ -256,8 +259,9 @@ func TestSetLiened_badDenom(t *testing.T) {
|
|
|
256
259
|
}
|
|
257
260
|
|
|
258
261
|
func TestSetLiened(t *testing.T) {
|
|
259
|
-
ctx := sdk.Context{}
|
|
260
|
-
ctlCtx :=
|
|
262
|
+
ctx := sdk.Context{}.WithContext(context.Background())
|
|
263
|
+
ctlCtx := sdk.WrapSDKContext(ctx)
|
|
264
|
+
|
|
261
265
|
keeper := mockLienKeeper{}
|
|
262
266
|
ph := NewPortHandler(&keeper)
|
|
263
267
|
msg := portMessage{
|
|
@@ -336,8 +340,8 @@ func TestGetStaking(t *testing.T) {
|
|
|
336
340
|
keeper.delegations[addr4.String()] = []stakingTypes.Delegation{}
|
|
337
341
|
|
|
338
342
|
ph := NewPortHandler(&keeper)
|
|
339
|
-
ctx := sdk.Context{}
|
|
340
|
-
ctlCtx :=
|
|
343
|
+
ctx := sdk.Context{}.WithContext(context.Background())
|
|
344
|
+
ctlCtx := sdk.WrapSDKContext(ctx)
|
|
341
345
|
|
|
342
346
|
pi := func(x int64) *sdk.Int {
|
|
343
347
|
n := i(x)
|