@agoric/cosmos 0.35.0-u13.0 → 0.35.0-upgrade-14-dev-0a0580c.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/app/app.go +54 -39
- package/git-revision.txt +1 -1
- package/package.json +2 -2
- package/vm/action.go +130 -0
- package/vm/action_test.go +129 -0
- package/vm/controller.go +0 -6
- package/vm/core_proposals.go +31 -0
- package/x/lien/keeper/keeper_test.go +1 -1
- package/x/swingset/abci.go +25 -33
- package/x/swingset/keeper/keeper.go +22 -4
- package/x/swingset/keeper/msg_server.go +19 -47
- package/x/swingset/keeper/proposal.go +4 -8
- package/x/vbank/vbank.go +8 -7
- package/x/vbank/vbank_test.go +10 -10
- package/x/vibc/handler.go +3 -8
- package/x/vibc/ibc.go +39 -87
package/app/app.go
CHANGED
|
@@ -213,7 +213,7 @@ type GaiaApp struct { // nolint: golint
|
|
|
213
213
|
vibcPort int
|
|
214
214
|
vstoragePort int
|
|
215
215
|
|
|
216
|
-
|
|
216
|
+
upgradeDetails *upgradeDetails
|
|
217
217
|
|
|
218
218
|
invCheckPeriod uint
|
|
219
219
|
|
|
@@ -776,17 +776,17 @@ func NewAgoricApp(
|
|
|
776
776
|
app.SetEndBlocker(app.EndBlocker)
|
|
777
777
|
|
|
778
778
|
const (
|
|
779
|
-
upgradeName = "agoric-upgrade-
|
|
780
|
-
upgradeNameTest = "agorictest-upgrade-
|
|
779
|
+
upgradeName = "agoric-upgrade-14"
|
|
780
|
+
upgradeNameTest = "agorictest-upgrade-14"
|
|
781
781
|
)
|
|
782
782
|
|
|
783
783
|
app.UpgradeKeeper.SetUpgradeHandler(
|
|
784
784
|
upgradeName,
|
|
785
|
-
|
|
785
|
+
upgrade14Handler(app, upgradeName),
|
|
786
786
|
)
|
|
787
787
|
app.UpgradeKeeper.SetUpgradeHandler(
|
|
788
788
|
upgradeNameTest,
|
|
789
|
-
|
|
789
|
+
upgrade14Handler(app, upgradeNameTest),
|
|
790
790
|
)
|
|
791
791
|
|
|
792
792
|
upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk()
|
|
@@ -824,12 +824,26 @@ func NewAgoricApp(
|
|
|
824
824
|
return app
|
|
825
825
|
}
|
|
826
826
|
|
|
827
|
-
//
|
|
828
|
-
func
|
|
827
|
+
// upgrade14Handler performs standard upgrade actions plus custom actions for upgrade-14.
|
|
828
|
+
func upgrade14Handler(app *GaiaApp, targetUpgrade string) func(sdk.Context, upgradetypes.Plan, module.VersionMap) (module.VersionMap, error) {
|
|
829
829
|
return func(ctx sdk.Context, plan upgradetypes.Plan, fromVm module.VersionMap) (module.VersionMap, error) {
|
|
830
830
|
app.CheckControllerInited(false)
|
|
831
|
-
|
|
832
|
-
|
|
831
|
+
|
|
832
|
+
// Each CoreProposalStep runs sequentially, and can be constructed from
|
|
833
|
+
// one or more modules executing in parallel within the step.
|
|
834
|
+
CoreProposalSteps := []vm.CoreProposalStep{
|
|
835
|
+
// First, upgrade wallet factory
|
|
836
|
+
vm.CoreProposalStepForModules("@agoric/vats/scripts/build-wallet-factory2-upgrade.js"),
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
app.upgradeDetails = &upgradeDetails{
|
|
840
|
+
// Record the plan to send to SwingSet
|
|
841
|
+
Plan: plan,
|
|
842
|
+
// Core proposals that should run during the upgrade block
|
|
843
|
+
// These will be merged with any coreProposals specified in the
|
|
844
|
+
// upgradeInfo field of the upgrade plan ran as subsequent steps
|
|
845
|
+
CoreProposals: vm.CoreProposalsFromSteps(CoreProposalSteps...),
|
|
846
|
+
}
|
|
833
847
|
|
|
834
848
|
// Always run module migrations
|
|
835
849
|
mvm, err := app.mm.RunMigrations(ctx, app.configurator, fromVm)
|
|
@@ -864,19 +878,23 @@ func normalizeModuleAccount(ctx sdk.Context, ak authkeeper.AccountKeeper, name s
|
|
|
864
878
|
ak.SetModuleAccount(ctx, newAcct)
|
|
865
879
|
}
|
|
866
880
|
|
|
881
|
+
type upgradeDetails struct {
|
|
882
|
+
Plan upgradetypes.Plan `json:"plan"`
|
|
883
|
+
CoreProposals *vm.CoreProposals `json:"coreProposals,omitempty"`
|
|
884
|
+
}
|
|
885
|
+
|
|
867
886
|
type cosmosInitAction struct {
|
|
868
|
-
|
|
869
|
-
ChainID
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
Params
|
|
873
|
-
SupplyCoins
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
VibcPort int `json:"vibcPort"`
|
|
887
|
+
vm.ActionHeader `actionType:"AG_COSMOS_INIT"`
|
|
888
|
+
ChainID string `json:"chainID"`
|
|
889
|
+
IsBootstrap bool `json:"isBootstrap"`
|
|
890
|
+
UpgradeDetails *upgradeDetails `json:"upgradeDetails,omitempty"`
|
|
891
|
+
Params swingset.Params `json:"params"`
|
|
892
|
+
SupplyCoins sdk.Coins `json:"supplyCoins"`
|
|
893
|
+
LienPort int `json:"lienPort"`
|
|
894
|
+
StoragePort int `json:"storagePort"`
|
|
895
|
+
SwingsetPort int `json:"swingsetPort"`
|
|
896
|
+
VbankPort int `json:"vbankPort"`
|
|
897
|
+
VibcPort int `json:"vibcPort"`
|
|
880
898
|
}
|
|
881
899
|
|
|
882
900
|
// Name returns the name of the App
|
|
@@ -899,27 +917,24 @@ func (app *GaiaApp) initController(ctx sdk.Context, bootstrap bool) {
|
|
|
899
917
|
app.CheckControllerInited(false)
|
|
900
918
|
app.controllerInited = true
|
|
901
919
|
|
|
902
|
-
var blockTime int64 = 0
|
|
903
|
-
if bootstrap || app.upgradePlan != nil {
|
|
904
|
-
blockTime = ctx.BlockTime().Unix()
|
|
905
|
-
}
|
|
906
|
-
|
|
907
920
|
// Begin initializing the controller here.
|
|
908
921
|
action := &cosmosInitAction{
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
VbankPort: app.vbankPort,
|
|
920
|
-
VibcPort: app.vibcPort,
|
|
922
|
+
ChainID: ctx.ChainID(),
|
|
923
|
+
IsBootstrap: bootstrap,
|
|
924
|
+
Params: app.SwingSetKeeper.GetParams(ctx),
|
|
925
|
+
SupplyCoins: sdk.NewCoins(app.BankKeeper.GetSupply(ctx, "uist")),
|
|
926
|
+
UpgradeDetails: app.upgradeDetails,
|
|
927
|
+
LienPort: app.lienPort,
|
|
928
|
+
StoragePort: app.vstoragePort,
|
|
929
|
+
SwingsetPort: app.swingsetPort,
|
|
930
|
+
VbankPort: app.vbankPort,
|
|
931
|
+
VibcPort: app.vibcPort,
|
|
921
932
|
}
|
|
922
|
-
// This
|
|
933
|
+
// This uses `BlockingSend` as a friendly wrapper for `sendToController`
|
|
934
|
+
//
|
|
935
|
+
// CAVEAT: we are restarting after an in-consensus halt or just because this
|
|
936
|
+
// node felt like it. The controller must be able to handle either case
|
|
937
|
+
// (inConsensus := action.IsBootstrap || action.UpgradeDetails != nil).
|
|
923
938
|
out, err := app.SwingSetKeeper.BlockingSend(ctx, action)
|
|
924
939
|
|
|
925
940
|
// fmt.Fprintf(os.Stderr, "AG_COSMOS_INIT Returned from SwingSet: %s, %v\n", out, err)
|
package/git-revision.txt
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
0a0580c
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agoric/cosmos",
|
|
3
|
-
"version": "0.35.0-
|
|
3
|
+
"version": "0.35.0-upgrade-14-dev-0a0580c.0+0a0580c",
|
|
4
4
|
"description": "Connect JS to the Cosmos blockchain SDK",
|
|
5
5
|
"parsers": {
|
|
6
6
|
"js": "mjs"
|
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
"publishConfig": {
|
|
36
36
|
"access": "public"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "0a0580cba9f4b41a1dc748cdd267dbcf0feed362"
|
|
39
39
|
}
|
package/vm/action.go
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
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 interprets `default:"..."` tags and specially handles an
|
|
62
|
+
// embedded ActionHeader struct.
|
|
63
|
+
func PopulateAction(ctx sdk.Context, action Action) Action {
|
|
64
|
+
oldRv := reflect.Indirect(reflect.ValueOf(action))
|
|
65
|
+
if oldRv.Kind() != reflect.Struct {
|
|
66
|
+
return action
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Shallow copy to a new value.
|
|
70
|
+
rp := reflect.New(oldRv.Type())
|
|
71
|
+
rv := reflect.Indirect(rp)
|
|
72
|
+
for i := 0; i < rv.NumField(); i++ {
|
|
73
|
+
oldField := oldRv.Field(i)
|
|
74
|
+
field := rv.Field(i)
|
|
75
|
+
fieldType := rv.Type().Field(i)
|
|
76
|
+
if !field.CanSet() {
|
|
77
|
+
continue
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Copy from original.
|
|
81
|
+
field.Set(oldField)
|
|
82
|
+
|
|
83
|
+
// Populate any ActionHeader struct.
|
|
84
|
+
var ahp *ActionHeader
|
|
85
|
+
if fieldType.Type == actionHeaderType {
|
|
86
|
+
ahp = field.Addr().Interface().(*ActionHeader)
|
|
87
|
+
} else if fieldType.Type == reflect.PtrTo(actionHeaderType) {
|
|
88
|
+
if field.IsNil() {
|
|
89
|
+
ahp = &ActionHeader{}
|
|
90
|
+
} else {
|
|
91
|
+
ahp = field.Interface().(*ActionHeader)
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if ahp != nil {
|
|
95
|
+
actionTypeTag, _ := fieldType.Tag.Lookup("actionType")
|
|
96
|
+
ah := *ahp
|
|
97
|
+
SetActionHeaderFromContext(ctx, actionTypeTag, &ah)
|
|
98
|
+
if field.Kind() == reflect.Ptr {
|
|
99
|
+
field.Set(reflect.ValueOf(&ah))
|
|
100
|
+
} else {
|
|
101
|
+
field.Set(reflect.ValueOf(ah))
|
|
102
|
+
}
|
|
103
|
+
continue
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Still zero value, try default struct field tag.
|
|
107
|
+
defaultTag, _ := fieldType.Tag.Lookup("default")
|
|
108
|
+
if !field.IsZero() || len(defaultTag) == 0 {
|
|
109
|
+
continue
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
switch field.Kind() {
|
|
113
|
+
case reflect.String:
|
|
114
|
+
field.SetString(defaultTag)
|
|
115
|
+
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
|
116
|
+
if val, err := strconv.ParseInt(defaultTag, 0, 64); err == nil {
|
|
117
|
+
field.SetInt(val)
|
|
118
|
+
}
|
|
119
|
+
case reflect.Bool:
|
|
120
|
+
if val, err := strconv.ParseBool(defaultTag); err == nil {
|
|
121
|
+
field.SetBool(val)
|
|
122
|
+
}
|
|
123
|
+
case reflect.Float32, reflect.Float64:
|
|
124
|
+
if val, err := strconv.ParseFloat(defaultTag, 64); err == nil {
|
|
125
|
+
field.SetFloat(val)
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return rv.Interface().(Action)
|
|
130
|
+
}
|
|
@@ -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
|
+
jstr := 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 := jstr(tc.in)
|
|
117
|
+
out := vm.PopulateAction(tc.ctx, tc.in)
|
|
118
|
+
jsonIn2 := jstr(tc.in)
|
|
119
|
+
if jsonIn != jsonIn2 {
|
|
120
|
+
t.Errorf("unexpected mutated input: %s to %s", jsonIn, jsonIn2)
|
|
121
|
+
}
|
|
122
|
+
jsonOut := jstr(out)
|
|
123
|
+
jsonExpectedOut := jstr(tc.expectedOut)
|
|
124
|
+
if jsonOut != jsonExpectedOut {
|
|
125
|
+
t.Errorf("expected %s, got %s", jsonExpectedOut, jsonOut)
|
|
126
|
+
}
|
|
127
|
+
})
|
|
128
|
+
}
|
|
129
|
+
}
|
package/vm/controller.go
CHANGED
|
@@ -25,12 +25,6 @@ type ControllerAdmissionMsg interface {
|
|
|
25
25
|
IsHighPriority(sdk.Context, interface{}) (bool, error)
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
// Jsonable is a value, j, that can be passed through json.Marshal(j).
|
|
29
|
-
type Jsonable interface{}
|
|
30
|
-
|
|
31
|
-
// ActionPusher enqueues data for later consumption by the controller.
|
|
32
|
-
type ActionPusher func(ctx sdk.Context, action Jsonable) error
|
|
33
|
-
|
|
34
28
|
var controllerContext ControllerContext
|
|
35
29
|
|
|
36
30
|
type PortHandler interface {
|
|
@@ -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
|
+
}
|
|
@@ -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)
|
package/x/swingset/abci.go
CHANGED
|
@@ -2,6 +2,7 @@ package swingset
|
|
|
2
2
|
|
|
3
3
|
import (
|
|
4
4
|
// "os"
|
|
5
|
+
"context"
|
|
5
6
|
"fmt"
|
|
6
7
|
"time"
|
|
7
8
|
|
|
@@ -9,38 +10,34 @@ import (
|
|
|
9
10
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
10
11
|
abci "github.com/tendermint/tendermint/abci/types"
|
|
11
12
|
|
|
13
|
+
"github.com/Agoric/agoric-sdk/golang/cosmos/vm"
|
|
12
14
|
"github.com/Agoric/agoric-sdk/golang/cosmos/x/swingset/types"
|
|
13
15
|
)
|
|
14
16
|
|
|
15
17
|
type beginBlockAction struct {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
ChainID string `json:"chainID"`
|
|
20
|
-
Params types.Params `json:"params"`
|
|
18
|
+
vm.ActionHeader `actionType:"BEGIN_BLOCK"`
|
|
19
|
+
ChainID string `json:"chainID"`
|
|
20
|
+
Params types.Params `json:"params"`
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
type endBlockAction struct {
|
|
24
|
-
|
|
25
|
-
BlockHeight int64 `json:"blockHeight"`
|
|
26
|
-
BlockTime int64 `json:"blockTime"`
|
|
24
|
+
vm.ActionHeader `actionType:"END_BLOCK"`
|
|
27
25
|
}
|
|
28
26
|
|
|
29
27
|
type commitBlockAction struct {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
vm.ActionHeader `actionType:"COMMIT_BLOCK"`
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
type afterCommitBlockAction struct {
|
|
32
|
+
vm.ActionHeader `actionType:"AFTER_COMMIT_BLOCK"`
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
func BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock, keeper Keeper) error {
|
|
36
36
|
defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyBeginBlocker)
|
|
37
37
|
|
|
38
38
|
action := &beginBlockAction{
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
BlockTime: ctx.BlockTime().Unix(),
|
|
42
|
-
ChainID: ctx.ChainID(),
|
|
43
|
-
Params: keeper.GetParams(ctx),
|
|
39
|
+
ChainID: ctx.ChainID(),
|
|
40
|
+
Params: keeper.GetParams(ctx),
|
|
44
41
|
}
|
|
45
42
|
_, err := keeper.BlockingSend(ctx, action)
|
|
46
43
|
// fmt.Fprintf(os.Stderr, "BEGIN_BLOCK Returned from SwingSet: %s, %v\n", out, err)
|
|
@@ -59,11 +56,7 @@ var endBlockTime int64
|
|
|
59
56
|
func EndBlock(ctx sdk.Context, req abci.RequestEndBlock, keeper Keeper) ([]abci.ValidatorUpdate, error) {
|
|
60
57
|
defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyEndBlocker)
|
|
61
58
|
|
|
62
|
-
action := &endBlockAction{
|
|
63
|
-
Type: "END_BLOCK",
|
|
64
|
-
BlockHeight: ctx.BlockHeight(),
|
|
65
|
-
BlockTime: ctx.BlockTime().Unix(),
|
|
66
|
-
}
|
|
59
|
+
action := &endBlockAction{}
|
|
67
60
|
_, err := keeper.BlockingSend(ctx, action)
|
|
68
61
|
|
|
69
62
|
// fmt.Fprintf(os.Stderr, "END_BLOCK Returned from SwingSet: %s, %v\n", out, err)
|
|
@@ -80,15 +73,18 @@ func EndBlock(ctx sdk.Context, req abci.RequestEndBlock, keeper Keeper) ([]abci.
|
|
|
80
73
|
return []abci.ValidatorUpdate{}, nil
|
|
81
74
|
}
|
|
82
75
|
|
|
76
|
+
func getEndBlockContext() sdk.Context {
|
|
77
|
+
return sdk.Context{}.
|
|
78
|
+
WithContext(context.Background()).
|
|
79
|
+
WithBlockHeight(endBlockHeight).
|
|
80
|
+
WithBlockTime(time.Unix(endBlockTime, 0))
|
|
81
|
+
}
|
|
82
|
+
|
|
83
83
|
func CommitBlock(keeper Keeper) error {
|
|
84
84
|
defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), "commit_blocker")
|
|
85
85
|
|
|
86
|
-
action := &commitBlockAction{
|
|
87
|
-
|
|
88
|
-
BlockHeight: endBlockHeight,
|
|
89
|
-
BlockTime: endBlockTime,
|
|
90
|
-
}
|
|
91
|
-
_, err := keeper.BlockingSend(sdk.Context{}, action)
|
|
86
|
+
action := &commitBlockAction{}
|
|
87
|
+
_, err := keeper.BlockingSend(getEndBlockContext(), action)
|
|
92
88
|
|
|
93
89
|
// fmt.Fprintf(os.Stderr, "COMMIT_BLOCK Returned from SwingSet: %s, %v\n", out, err)
|
|
94
90
|
if err != nil {
|
|
@@ -102,12 +98,8 @@ func CommitBlock(keeper Keeper) error {
|
|
|
102
98
|
func AfterCommitBlock(keeper Keeper) error {
|
|
103
99
|
// defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), "commit_blocker")
|
|
104
100
|
|
|
105
|
-
action := &
|
|
106
|
-
|
|
107
|
-
BlockHeight: endBlockHeight,
|
|
108
|
-
BlockTime: endBlockTime,
|
|
109
|
-
}
|
|
110
|
-
_, err := keeper.BlockingSend(sdk.Context{}, action)
|
|
101
|
+
action := &afterCommitBlockAction{}
|
|
102
|
+
_, err := keeper.BlockingSend(getEndBlockContext(), action)
|
|
111
103
|
|
|
112
104
|
// fmt.Fprintf(os.Stderr, "AFTER_COMMIT_BLOCK Returned from SwingSet: %s, %v\n", out, err)
|
|
113
105
|
if err != nil {
|
|
@@ -110,6 +110,16 @@ func NewKeeper(
|
|
|
110
110
|
}
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
+
func populateAction(ctx sdk.Context, action vm.Action) (vm.Action, error) {
|
|
114
|
+
action = vm.PopulateAction(ctx, action)
|
|
115
|
+
ah := action.GetActionHeader()
|
|
116
|
+
if len(ah.Type) == 0 {
|
|
117
|
+
return nil, fmt.Errorf("action %q cannot have an empty ActionHeader.Type", action)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return action, nil
|
|
121
|
+
}
|
|
122
|
+
|
|
113
123
|
// pushAction appends an action to the controller's specified inbound queue.
|
|
114
124
|
// The queue is kept in the kvstore so that changes are properly reverted if the
|
|
115
125
|
// kvstore is rolled back. By the time the block manager runs, it can commit
|
|
@@ -118,7 +128,11 @@ func NewKeeper(
|
|
|
118
128
|
//
|
|
119
129
|
// The inbound queue's format is documented by `makeChainQueue` in
|
|
120
130
|
// `packages/cosmic-swingset/src/helpers/make-queue.js`.
|
|
121
|
-
func (k Keeper) pushAction(ctx sdk.Context, inboundQueuePath string, action vm.
|
|
131
|
+
func (k Keeper) pushAction(ctx sdk.Context, inboundQueuePath string, action vm.Action) error {
|
|
132
|
+
action, err := populateAction(ctx, action)
|
|
133
|
+
if err != nil {
|
|
134
|
+
return err
|
|
135
|
+
}
|
|
122
136
|
txHash, txHashOk := ctx.Context().Value(baseapp.TxHashContextKey).(string)
|
|
123
137
|
if !txHashOk {
|
|
124
138
|
txHash = "unknown"
|
|
@@ -143,12 +157,12 @@ func (k Keeper) pushAction(ctx sdk.Context, inboundQueuePath string, action vm.J
|
|
|
143
157
|
}
|
|
144
158
|
|
|
145
159
|
// PushAction appends an action to the controller's actionQueue.
|
|
146
|
-
func (k Keeper) PushAction(ctx sdk.Context, action vm.
|
|
160
|
+
func (k Keeper) PushAction(ctx sdk.Context, action vm.Action) error {
|
|
147
161
|
return k.pushAction(ctx, StoragePathActionQueue, action)
|
|
148
162
|
}
|
|
149
163
|
|
|
150
164
|
// PushAction appends an action to the controller's highPriorityQueue.
|
|
151
|
-
func (k Keeper) PushHighPriorityAction(ctx sdk.Context, action vm.
|
|
165
|
+
func (k Keeper) PushHighPriorityAction(ctx sdk.Context, action vm.Action) error {
|
|
152
166
|
return k.pushAction(ctx, StoragePathHighPriorityQueue, action)
|
|
153
167
|
}
|
|
154
168
|
|
|
@@ -234,7 +248,11 @@ func (k Keeper) UpdateQueueAllowed(ctx sdk.Context) error {
|
|
|
234
248
|
// until the response. It is orthogonal to PushAction, and should only be used
|
|
235
249
|
// by SwingSet to perform block lifecycle events (BEGIN_BLOCK, END_BLOCK,
|
|
236
250
|
// COMMIT_BLOCK).
|
|
237
|
-
func (k Keeper) BlockingSend(ctx sdk.Context, action vm.
|
|
251
|
+
func (k Keeper) BlockingSend(ctx sdk.Context, action vm.Action) (string, error) {
|
|
252
|
+
action, err := populateAction(ctx, action)
|
|
253
|
+
if err != nil {
|
|
254
|
+
return "", err
|
|
255
|
+
}
|
|
238
256
|
bz, err := json.Marshal(action)
|
|
239
257
|
if err != nil {
|
|
240
258
|
return "", err
|
|
@@ -21,15 +21,13 @@ func NewMsgServerImpl(keeper Keeper) types.MsgServer {
|
|
|
21
21
|
var _ types.MsgServer = msgServer{}
|
|
22
22
|
|
|
23
23
|
type deliverInboundAction struct {
|
|
24
|
-
|
|
25
|
-
Peer
|
|
26
|
-
Messages
|
|
27
|
-
Ack
|
|
28
|
-
BlockHeight int64 `json:"blockHeight"`
|
|
29
|
-
BlockTime int64 `json:"blockTime"`
|
|
24
|
+
vm.ActionHeader `actionType:"DELIVER_INBOUND"`
|
|
25
|
+
Peer string `json:"peer"`
|
|
26
|
+
Messages [][]interface{} `json:"messages"`
|
|
27
|
+
Ack uint64 `json:"ack"`
|
|
30
28
|
}
|
|
31
29
|
|
|
32
|
-
func (keeper msgServer) routeAction(ctx sdk.Context, msg vm.ControllerAdmissionMsg, action vm.
|
|
30
|
+
func (keeper msgServer) routeAction(ctx sdk.Context, msg vm.ControllerAdmissionMsg, action vm.Action) error {
|
|
33
31
|
isHighPriority, err := msg.IsHighPriority(ctx, keeper)
|
|
34
32
|
if err != nil {
|
|
35
33
|
return err
|
|
@@ -53,12 +51,9 @@ func (keeper msgServer) DeliverInbound(goCtx context.Context, msg *types.MsgDeli
|
|
|
53
51
|
}
|
|
54
52
|
|
|
55
53
|
action := &deliverInboundAction{
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
Ack: msg.Ack,
|
|
60
|
-
BlockHeight: ctx.BlockHeight(),
|
|
61
|
-
BlockTime: ctx.BlockTime().Unix(),
|
|
54
|
+
Peer: msg.Submitter.String(),
|
|
55
|
+
Messages: messages,
|
|
56
|
+
Ack: msg.Ack,
|
|
62
57
|
}
|
|
63
58
|
|
|
64
59
|
err := keeper.routeAction(ctx, msg, action)
|
|
@@ -70,11 +65,9 @@ func (keeper msgServer) DeliverInbound(goCtx context.Context, msg *types.MsgDeli
|
|
|
70
65
|
}
|
|
71
66
|
|
|
72
67
|
type walletAction struct {
|
|
73
|
-
|
|
74
|
-
Owner
|
|
75
|
-
Action
|
|
76
|
-
BlockHeight int64 `json:"blockHeight"`
|
|
77
|
-
BlockTime int64 `json:"blockTime"`
|
|
68
|
+
vm.ActionHeader `actionType:"WALLET_ACTION"`
|
|
69
|
+
Owner string `json:"owner"`
|
|
70
|
+
Action string `json:"action"`
|
|
78
71
|
}
|
|
79
72
|
|
|
80
73
|
func (keeper msgServer) WalletAction(goCtx context.Context, msg *types.MsgWalletAction) (*types.MsgWalletActionResponse, error) {
|
|
@@ -86,11 +79,8 @@ func (keeper msgServer) WalletAction(goCtx context.Context, msg *types.MsgWallet
|
|
|
86
79
|
}
|
|
87
80
|
|
|
88
81
|
action := &walletAction{
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
Action: msg.Action,
|
|
92
|
-
BlockHeight: ctx.BlockHeight(),
|
|
93
|
-
BlockTime: ctx.BlockTime().Unix(),
|
|
82
|
+
Owner: msg.Owner.String(),
|
|
83
|
+
Action: msg.Action,
|
|
94
84
|
}
|
|
95
85
|
// fmt.Fprintf(os.Stderr, "Context is %+v\n", ctx)
|
|
96
86
|
|
|
@@ -103,11 +93,9 @@ func (keeper msgServer) WalletAction(goCtx context.Context, msg *types.MsgWallet
|
|
|
103
93
|
}
|
|
104
94
|
|
|
105
95
|
type walletSpendAction struct {
|
|
106
|
-
|
|
107
|
-
Owner
|
|
108
|
-
SpendAction
|
|
109
|
-
BlockHeight int64 `json:"blockHeight"`
|
|
110
|
-
BlockTime int64 `json:"blockTime"`
|
|
96
|
+
vm.ActionHeader `actionType:"WALLET_SPEND_ACTION"`
|
|
97
|
+
Owner string `json:"owner"`
|
|
98
|
+
SpendAction string `json:"spendAction"`
|
|
111
99
|
}
|
|
112
100
|
|
|
113
101
|
func (keeper msgServer) WalletSpendAction(goCtx context.Context, msg *types.MsgWalletSpendAction) (*types.MsgWalletSpendActionResponse, error) {
|
|
@@ -119,11 +107,8 @@ func (keeper msgServer) WalletSpendAction(goCtx context.Context, msg *types.MsgW
|
|
|
119
107
|
}
|
|
120
108
|
|
|
121
109
|
action := &walletSpendAction{
|
|
122
|
-
Type: "WALLET_SPEND_ACTION",
|
|
123
110
|
Owner: msg.Owner.String(),
|
|
124
111
|
SpendAction: msg.SpendAction,
|
|
125
|
-
BlockHeight: ctx.BlockHeight(),
|
|
126
|
-
BlockTime: ctx.BlockTime().Unix(),
|
|
127
112
|
}
|
|
128
113
|
// fmt.Fprintf(os.Stderr, "Context is %+v\n", ctx)
|
|
129
114
|
err = keeper.routeAction(ctx, msg, action)
|
|
@@ -134,11 +119,9 @@ func (keeper msgServer) WalletSpendAction(goCtx context.Context, msg *types.MsgW
|
|
|
134
119
|
}
|
|
135
120
|
|
|
136
121
|
type provisionAction struct {
|
|
122
|
+
vm.ActionHeader `actionType:"PLEASE_PROVISION"`
|
|
137
123
|
*types.MsgProvision
|
|
138
|
-
|
|
139
|
-
BlockHeight int64 `json:"blockHeight"`
|
|
140
|
-
BlockTime int64 `json:"blockTime"`
|
|
141
|
-
AutoProvision bool `json:"autoProvision"`
|
|
124
|
+
AutoProvision bool `json:"autoProvision"`
|
|
142
125
|
}
|
|
143
126
|
|
|
144
127
|
// provisionIfNeeded generates a provision action if no smart wallet is already
|
|
@@ -162,9 +145,6 @@ func (keeper msgServer) provisionIfNeeded(ctx sdk.Context, owner sdk.AccAddress)
|
|
|
162
145
|
|
|
163
146
|
action := &provisionAction{
|
|
164
147
|
MsgProvision: msg,
|
|
165
|
-
Type: "PLEASE_PROVISION",
|
|
166
|
-
BlockHeight: ctx.BlockHeight(),
|
|
167
|
-
BlockTime: ctx.BlockTime().Unix(),
|
|
168
148
|
AutoProvision: true,
|
|
169
149
|
}
|
|
170
150
|
|
|
@@ -187,9 +167,6 @@ func (keeper msgServer) Provision(goCtx context.Context, msg *types.MsgProvision
|
|
|
187
167
|
|
|
188
168
|
action := &provisionAction{
|
|
189
169
|
MsgProvision: msg,
|
|
190
|
-
Type: "PLEASE_PROVISION",
|
|
191
|
-
BlockHeight: ctx.BlockHeight(),
|
|
192
|
-
BlockTime: ctx.BlockTime().Unix(),
|
|
193
170
|
}
|
|
194
171
|
|
|
195
172
|
// Create the account, if it doesn't already exist.
|
|
@@ -209,10 +186,8 @@ func (keeper msgServer) Provision(goCtx context.Context, msg *types.MsgProvision
|
|
|
209
186
|
}
|
|
210
187
|
|
|
211
188
|
type installBundleAction struct {
|
|
189
|
+
vm.ActionHeader `actionType:"INSTALL_BUNDLE"`
|
|
212
190
|
*types.MsgInstallBundle
|
|
213
|
-
Type string `json:"type"` // INSTALL_BUNDLE
|
|
214
|
-
BlockHeight int64 `json:"blockHeight"`
|
|
215
|
-
BlockTime int64 `json:"blockTime"`
|
|
216
191
|
}
|
|
217
192
|
|
|
218
193
|
func (keeper msgServer) InstallBundle(goCtx context.Context, msg *types.MsgInstallBundle) (*types.MsgInstallBundleResponse, error) {
|
|
@@ -224,9 +199,6 @@ func (keeper msgServer) InstallBundle(goCtx context.Context, msg *types.MsgInsta
|
|
|
224
199
|
}
|
|
225
200
|
action := &installBundleAction{
|
|
226
201
|
MsgInstallBundle: msg,
|
|
227
|
-
Type: "INSTALL_BUNDLE",
|
|
228
|
-
BlockHeight: ctx.BlockHeight(),
|
|
229
|
-
BlockTime: ctx.BlockTime().Unix(),
|
|
230
202
|
}
|
|
231
203
|
|
|
232
204
|
err = keeper.routeAction(ctx, msg, action)
|
|
@@ -3,23 +3,19 @@ package keeper
|
|
|
3
3
|
import (
|
|
4
4
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
5
5
|
|
|
6
|
+
"github.com/Agoric/agoric-sdk/golang/cosmos/vm"
|
|
6
7
|
"github.com/Agoric/agoric-sdk/golang/cosmos/x/swingset/types"
|
|
7
8
|
)
|
|
8
9
|
|
|
9
10
|
type coreEvalAction struct {
|
|
10
|
-
|
|
11
|
-
Evals
|
|
12
|
-
BlockHeight int64 `json:"blockHeight"`
|
|
13
|
-
BlockTime int64 `json:"blockTime"`
|
|
11
|
+
vm.ActionHeader `actionType:"CORE_EVAL"`
|
|
12
|
+
Evals []types.CoreEval `json:"evals"`
|
|
14
13
|
}
|
|
15
14
|
|
|
16
15
|
// CoreEvalProposal tells SwingSet to evaluate the given JS code.
|
|
17
16
|
func (k Keeper) CoreEvalProposal(ctx sdk.Context, p *types.CoreEvalProposal) error {
|
|
18
17
|
action := &coreEvalAction{
|
|
19
|
-
|
|
20
|
-
Evals: p.Evals,
|
|
21
|
-
BlockHeight: ctx.BlockHeight(),
|
|
22
|
-
BlockTime: ctx.BlockTime().Unix(),
|
|
18
|
+
Evals: p.Evals,
|
|
23
19
|
}
|
|
24
20
|
|
|
25
21
|
return k.PushHighPriorityAction(ctx, action)
|
package/x/vbank/vbank.go
CHANGED
|
@@ -68,15 +68,15 @@ func (vbu vbankManyBalanceUpdates) Swap(i int, j int) {
|
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
type vbankBalanceUpdate struct {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
Updated
|
|
71
|
+
vm.ActionHeader `actionType:"VBANK_BALANCE_UPDATE"`
|
|
72
|
+
Nonce uint64 `json:"nonce"`
|
|
73
|
+
Updated vbankManyBalanceUpdates `json:"updated"`
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
// getBalanceUpdate returns a bridge message containing the current bank balance
|
|
77
77
|
// for the given addresses each for the specified denominations. Coins are used
|
|
78
78
|
// only to track the set of denoms, not for the particular nonzero amounts.
|
|
79
|
-
func getBalanceUpdate(ctx sdk.Context, keeper Keeper, addressToUpdate map[string]sdk.Coins) vm.
|
|
79
|
+
func getBalanceUpdate(ctx sdk.Context, keeper Keeper, addressToUpdate map[string]sdk.Coins) vm.Action {
|
|
80
80
|
nentries := len(addressToUpdate)
|
|
81
81
|
if nentries == 0 {
|
|
82
82
|
return nil
|
|
@@ -84,7 +84,6 @@ func getBalanceUpdate(ctx sdk.Context, keeper Keeper, addressToUpdate map[string
|
|
|
84
84
|
|
|
85
85
|
nonce := keeper.GetNextSequence(ctx)
|
|
86
86
|
event := vbankBalanceUpdate{
|
|
87
|
-
Type: "VBANK_BALANCE_UPDATE",
|
|
88
87
|
Nonce: nonce,
|
|
89
88
|
Updated: make([]vbankSingleBalanceUpdate, 0, nentries),
|
|
90
89
|
}
|
|
@@ -111,7 +110,9 @@ func getBalanceUpdate(ctx sdk.Context, keeper Keeper, addressToUpdate map[string
|
|
|
111
110
|
|
|
112
111
|
// Ensure we have a deterministic order of updates.
|
|
113
112
|
sort.Sort(event.Updated)
|
|
114
|
-
|
|
113
|
+
|
|
114
|
+
// Populate the event default fields (even though event does not embed vm.ActionHeader)
|
|
115
|
+
return vm.PopulateAction(ctx, event)
|
|
115
116
|
}
|
|
116
117
|
|
|
117
118
|
func marshal(event vm.Jsonable) ([]byte, error) {
|
|
@@ -242,7 +243,7 @@ func (ch portHandler) Receive(ctx *vm.ControllerContext, str string) (ret string
|
|
|
242
243
|
return
|
|
243
244
|
}
|
|
244
245
|
|
|
245
|
-
func (am AppModule) PushAction(ctx sdk.Context, action vm.
|
|
246
|
+
func (am AppModule) PushAction(ctx sdk.Context, action vm.Action) error {
|
|
246
247
|
// vbank actions are not triggered by a swingset message in a transaction, so we need to
|
|
247
248
|
// synthesize unique context information.
|
|
248
249
|
// We use a fixed placeholder value for the txHash context, and can simply use `0` for the
|
package/x/vbank/vbank_test.go
CHANGED
|
@@ -250,7 +250,7 @@ func (b *mockBank) SendCoinsFromModuleToModule(ctx sdk.Context, senderModule, re
|
|
|
250
250
|
func makeTestKit(account types.AccountKeeper, bank types.BankKeeper) (Keeper, sdk.Context) {
|
|
251
251
|
encodingConfig := params.MakeEncodingConfig()
|
|
252
252
|
cdc := encodingConfig.Marshaler
|
|
253
|
-
pushAction := func(ctx sdk.Context, action vm.
|
|
253
|
+
pushAction := func(ctx sdk.Context, action vm.Action) error {
|
|
254
254
|
return nil
|
|
255
255
|
}
|
|
256
256
|
|
|
@@ -517,16 +517,16 @@ func Test_EndBlock_Events(t *testing.T) {
|
|
|
517
517
|
}}
|
|
518
518
|
acct := &mockAuthKeeper{
|
|
519
519
|
accounts: map[string]authtypes.AccountI{
|
|
520
|
-
addr1: &authtypes.ModuleAccount{BaseAccount: &authtypes.BaseAccount{
|
|
521
|
-
addr2: &authtypes.ModuleAccount{BaseAccount: &authtypes.BaseAccount{
|
|
522
|
-
addr3: &authtypes.BaseAccount{
|
|
520
|
+
addr1: &authtypes.ModuleAccount{BaseAccount: &authtypes.BaseAccount{Address: addr1}},
|
|
521
|
+
addr2: &authtypes.ModuleAccount{BaseAccount: &authtypes.BaseAccount{Address: addr2}},
|
|
522
|
+
addr3: &authtypes.BaseAccount{Address: addr3},
|
|
523
523
|
},
|
|
524
524
|
}
|
|
525
525
|
keeper, ctx := makeTestKit(acct, bank)
|
|
526
526
|
// Turn off rewards.
|
|
527
527
|
keeper.SetParams(ctx, types.Params{PerEpochRewardFraction: sdk.ZeroDec()})
|
|
528
528
|
msgsSent := []string{}
|
|
529
|
-
keeper.PushAction = func(ctx sdk.Context, action vm.
|
|
529
|
+
keeper.PushAction = func(ctx sdk.Context, action vm.Action) error {
|
|
530
530
|
bz, err := json.Marshal(action)
|
|
531
531
|
if err != nil {
|
|
532
532
|
return err
|
|
@@ -630,7 +630,7 @@ func Test_EndBlock_Rewards(t *testing.T) {
|
|
|
630
630
|
}
|
|
631
631
|
keeper, ctx := makeTestKit(nil, bank)
|
|
632
632
|
msgsSent := []string{}
|
|
633
|
-
keeper.PushAction = func(ctx sdk.Context, action vm.
|
|
633
|
+
keeper.PushAction = func(ctx sdk.Context, action vm.Action) error {
|
|
634
634
|
bz, err := json.Marshal(action)
|
|
635
635
|
if err != nil {
|
|
636
636
|
return err
|
|
@@ -746,7 +746,7 @@ func Test_EndBlock_Rewards(t *testing.T) {
|
|
|
746
746
|
}
|
|
747
747
|
}
|
|
748
748
|
|
|
749
|
-
type mockAuthKeeper struct{
|
|
749
|
+
type mockAuthKeeper struct {
|
|
750
750
|
accounts map[string]authtypes.AccountI
|
|
751
751
|
modAddrs map[string]string
|
|
752
752
|
}
|
|
@@ -754,11 +754,11 @@ type mockAuthKeeper struct{
|
|
|
754
754
|
func (ma mockAuthKeeper) GetModuleAccount(ctx sdk.Context, name string) authtypes.ModuleAccountI {
|
|
755
755
|
addr, ok := ma.modAddrs[name]
|
|
756
756
|
if !ok {
|
|
757
|
-
|
|
757
|
+
return nil
|
|
758
758
|
}
|
|
759
759
|
acct, ok := ma.accounts[addr]
|
|
760
760
|
if !ok {
|
|
761
|
-
|
|
761
|
+
panic("missing module account")
|
|
762
762
|
}
|
|
763
763
|
return acct.(authtypes.ModuleAccountI)
|
|
764
764
|
}
|
|
@@ -778,7 +778,7 @@ func Test_Module_Account(t *testing.T) {
|
|
|
778
778
|
acct := &mockAuthKeeper{
|
|
779
779
|
accounts: map[string]authtypes.AccountI{
|
|
780
780
|
moduleBech32: authtypes.NewEmptyModuleAccount("vbank/reserve"),
|
|
781
|
-
addr1:
|
|
781
|
+
addr1: authtypes.NewBaseAccountWithAddress(sdk.MustAccAddressFromBech32(addr1)),
|
|
782
782
|
},
|
|
783
783
|
modAddrs: map[string]string{
|
|
784
784
|
"vbank/reserve": moduleBech32,
|
package/x/vibc/handler.go
CHANGED
|
@@ -3,6 +3,7 @@ package vibc
|
|
|
3
3
|
import (
|
|
4
4
|
"fmt"
|
|
5
5
|
|
|
6
|
+
"github.com/Agoric/agoric-sdk/golang/cosmos/vm"
|
|
6
7
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
7
8
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
|
8
9
|
)
|
|
@@ -23,10 +24,8 @@ func NewHandler(keeper Keeper) sdk.Handler {
|
|
|
23
24
|
|
|
24
25
|
type sendPacketAction struct {
|
|
25
26
|
*MsgSendPacket
|
|
26
|
-
|
|
27
|
-
Event
|
|
28
|
-
BlockHeight int64 `json:"blockHeight"`
|
|
29
|
-
BlockTime int64 `json:"blockTime"`
|
|
27
|
+
vm.ActionHeader `actionType:"IBC_EVENT"`
|
|
28
|
+
Event string `json:"event" default:"sendPacket"`
|
|
30
29
|
}
|
|
31
30
|
|
|
32
31
|
func handleMsgSendPacket(ctx sdk.Context, keeper Keeper, msg *MsgSendPacket) (*sdk.Result, error) {
|
|
@@ -41,10 +40,6 @@ func handleMsgSendPacket(ctx sdk.Context, keeper Keeper, msg *MsgSendPacket) (*s
|
|
|
41
40
|
|
|
42
41
|
action := &sendPacketAction{
|
|
43
42
|
MsgSendPacket: msg,
|
|
44
|
-
Type: "IBC_EVENT",
|
|
45
|
-
Event: "sendPacket",
|
|
46
|
-
BlockHeight: ctx.BlockHeight(),
|
|
47
|
-
BlockTime: ctx.BlockTime().Unix(),
|
|
48
43
|
}
|
|
49
44
|
// fmt.Fprintf(os.Stderr, "Context is %+v\n", ctx)
|
|
50
45
|
|
package/x/vibc/ibc.go
CHANGED
|
@@ -151,7 +151,7 @@ func (ch IBCModule) Receive(ctx *vm.ControllerContext, str string) (ret string,
|
|
|
151
151
|
return
|
|
152
152
|
}
|
|
153
153
|
|
|
154
|
-
func (im IBCModule) PushAction(ctx sdk.Context, action vm.
|
|
154
|
+
func (im IBCModule) PushAction(ctx sdk.Context, action vm.Action) error {
|
|
155
155
|
// fmt.Println("ibc.go upcall", send)
|
|
156
156
|
return im.keeper.PushAction(ctx, action)
|
|
157
157
|
// fmt.Println("ibc.go upcall reply", reply, err)
|
|
@@ -175,16 +175,14 @@ func (im IBCModule) OnChanOpenInit(
|
|
|
175
175
|
}
|
|
176
176
|
|
|
177
177
|
type channelOpenTryEvent struct {
|
|
178
|
-
|
|
179
|
-
Event
|
|
180
|
-
Order
|
|
181
|
-
ConnectionHops
|
|
182
|
-
PortID
|
|
183
|
-
ChannelID
|
|
184
|
-
Counterparty
|
|
185
|
-
Version
|
|
186
|
-
BlockHeight int64 `json:"blockHeight"`
|
|
187
|
-
BlockTime int64 `json:"blockTime"`
|
|
178
|
+
vm.ActionHeader `actionType:"IBC_EVENT"`
|
|
179
|
+
Event string `json:"event" default:"channelOpenTry"`
|
|
180
|
+
Order string `json:"order"`
|
|
181
|
+
ConnectionHops []string `json:"connectionHops"`
|
|
182
|
+
PortID string `json:"portID"`
|
|
183
|
+
ChannelID string `json:"channelID"`
|
|
184
|
+
Counterparty channeltypes.Counterparty `json:"counterparty"`
|
|
185
|
+
Version string `json:"version"`
|
|
188
186
|
}
|
|
189
187
|
|
|
190
188
|
func (im IBCModule) OnChanOpenTry(
|
|
@@ -198,16 +196,12 @@ func (im IBCModule) OnChanOpenTry(
|
|
|
198
196
|
counterpartyVersion string,
|
|
199
197
|
) (string, error) {
|
|
200
198
|
event := channelOpenTryEvent{
|
|
201
|
-
Type: "IBC_EVENT",
|
|
202
|
-
Event: "channelOpenTry",
|
|
203
199
|
Order: orderToString(order),
|
|
204
200
|
ConnectionHops: connectionHops,
|
|
205
201
|
PortID: portID,
|
|
206
202
|
ChannelID: channelID,
|
|
207
203
|
Counterparty: counterparty,
|
|
208
204
|
Version: counterpartyVersion, // TODO: don't just use the counterparty version
|
|
209
|
-
BlockHeight: ctx.BlockHeight(),
|
|
210
|
-
BlockTime: ctx.BlockTime().Unix(),
|
|
211
205
|
}
|
|
212
206
|
|
|
213
207
|
err := im.PushAction(ctx, event)
|
|
@@ -224,15 +218,13 @@ func (im IBCModule) OnChanOpenTry(
|
|
|
224
218
|
}
|
|
225
219
|
|
|
226
220
|
type channelOpenAckEvent struct {
|
|
227
|
-
|
|
228
|
-
Event string `json:"event"
|
|
221
|
+
vm.ActionHeader `actionType:"IBC_EVENT"`
|
|
222
|
+
Event string `json:"event" default:"channelOpenAck"`
|
|
229
223
|
PortID string `json:"portID"`
|
|
230
224
|
ChannelID string `json:"channelID"`
|
|
231
225
|
CounterpartyVersion string `json:"counterpartyVersion"`
|
|
232
226
|
Counterparty channeltypes.Counterparty `json:"counterparty"`
|
|
233
227
|
ConnectionHops []string `json:"connectionHops"`
|
|
234
|
-
BlockHeight int64 `json:"blockHeight"`
|
|
235
|
-
BlockTime int64 `json:"blockTime"`
|
|
236
228
|
}
|
|
237
229
|
|
|
238
230
|
func (im IBCModule) OnChanOpenAck(
|
|
@@ -248,27 +240,21 @@ func (im IBCModule) OnChanOpenAck(
|
|
|
248
240
|
|
|
249
241
|
channel.Counterparty.ChannelId = counterpartyChannelID
|
|
250
242
|
event := channelOpenAckEvent{
|
|
251
|
-
Type: "IBC_EVENT",
|
|
252
|
-
Event: "channelOpenAck",
|
|
253
243
|
PortID: portID,
|
|
254
244
|
ChannelID: channelID,
|
|
255
245
|
CounterpartyVersion: counterpartyVersion,
|
|
256
246
|
Counterparty: channel.Counterparty,
|
|
257
247
|
ConnectionHops: channel.ConnectionHops,
|
|
258
|
-
BlockHeight: ctx.BlockHeight(),
|
|
259
|
-
BlockTime: ctx.BlockTime().Unix(),
|
|
260
248
|
}
|
|
261
249
|
|
|
262
250
|
return im.PushAction(ctx, event)
|
|
263
251
|
}
|
|
264
252
|
|
|
265
253
|
type channelOpenConfirmEvent struct {
|
|
266
|
-
|
|
267
|
-
Event
|
|
268
|
-
PortID
|
|
269
|
-
ChannelID
|
|
270
|
-
BlockHeight int64 `json:"blockHeight"`
|
|
271
|
-
BlockTime int64 `json:"blockTime"`
|
|
254
|
+
vm.ActionHeader `actionType:"IBC_EVENT"`
|
|
255
|
+
Event string `json:"event" default:"channelOpenConfirm"`
|
|
256
|
+
PortID string `json:"portID"`
|
|
257
|
+
ChannelID string `json:"channelID"`
|
|
272
258
|
}
|
|
273
259
|
|
|
274
260
|
func (im IBCModule) OnChanOpenConfirm(
|
|
@@ -277,24 +263,18 @@ func (im IBCModule) OnChanOpenConfirm(
|
|
|
277
263
|
channelID string,
|
|
278
264
|
) error {
|
|
279
265
|
event := channelOpenConfirmEvent{
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
PortID: portID,
|
|
283
|
-
ChannelID: channelID,
|
|
284
|
-
BlockHeight: ctx.BlockHeight(),
|
|
285
|
-
BlockTime: ctx.BlockTime().Unix(),
|
|
266
|
+
PortID: portID,
|
|
267
|
+
ChannelID: channelID,
|
|
286
268
|
}
|
|
287
269
|
|
|
288
270
|
return im.PushAction(ctx, event)
|
|
289
271
|
}
|
|
290
272
|
|
|
291
273
|
type channelCloseInitEvent struct {
|
|
292
|
-
|
|
293
|
-
Event
|
|
294
|
-
PortID
|
|
295
|
-
ChannelID
|
|
296
|
-
BlockHeight int64 `json:"blockHeight"`
|
|
297
|
-
BlockTime int64 `json:"blockTime"`
|
|
274
|
+
vm.ActionHeader `actionType:"IBC_EVENT"`
|
|
275
|
+
Event string `json:"event" default:"channelCloseInit"`
|
|
276
|
+
PortID string `json:"portID"`
|
|
277
|
+
ChannelID string `json:"channelID"`
|
|
298
278
|
}
|
|
299
279
|
|
|
300
280
|
func (im IBCModule) OnChanCloseInit(
|
|
@@ -303,12 +283,8 @@ func (im IBCModule) OnChanCloseInit(
|
|
|
303
283
|
channelID string,
|
|
304
284
|
) error {
|
|
305
285
|
event := channelCloseInitEvent{
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
PortID: portID,
|
|
309
|
-
ChannelID: channelID,
|
|
310
|
-
BlockHeight: ctx.BlockHeight(),
|
|
311
|
-
BlockTime: ctx.BlockTime().Unix(),
|
|
286
|
+
PortID: portID,
|
|
287
|
+
ChannelID: channelID,
|
|
312
288
|
}
|
|
313
289
|
|
|
314
290
|
err := im.PushAction(ctx, event)
|
|
@@ -316,12 +292,10 @@ func (im IBCModule) OnChanCloseInit(
|
|
|
316
292
|
}
|
|
317
293
|
|
|
318
294
|
type channelCloseConfirmEvent struct {
|
|
319
|
-
|
|
320
|
-
Event
|
|
321
|
-
PortID
|
|
322
|
-
ChannelID
|
|
323
|
-
BlockHeight int64 `json:"blockHeight"`
|
|
324
|
-
BlockTime int64 `json:"blockTime"`
|
|
295
|
+
vm.ActionHeader `actionType:"IBC_EVENT"`
|
|
296
|
+
Event string `json:"event" default:"channelCloseConfirm"`
|
|
297
|
+
PortID string `json:"portID"`
|
|
298
|
+
ChannelID string `json:"channelID"`
|
|
325
299
|
}
|
|
326
300
|
|
|
327
301
|
func (im IBCModule) OnChanCloseConfirm(
|
|
@@ -330,12 +304,8 @@ func (im IBCModule) OnChanCloseConfirm(
|
|
|
330
304
|
channelID string,
|
|
331
305
|
) error {
|
|
332
306
|
event := channelCloseConfirmEvent{
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
PortID: portID,
|
|
336
|
-
ChannelID: channelID,
|
|
337
|
-
BlockHeight: ctx.BlockHeight(),
|
|
338
|
-
BlockTime: ctx.BlockTime().Unix(),
|
|
307
|
+
PortID: portID,
|
|
308
|
+
ChannelID: channelID,
|
|
339
309
|
}
|
|
340
310
|
|
|
341
311
|
err := im.PushAction(ctx, event)
|
|
@@ -343,11 +313,9 @@ func (im IBCModule) OnChanCloseConfirm(
|
|
|
343
313
|
}
|
|
344
314
|
|
|
345
315
|
type receivePacketEvent struct {
|
|
346
|
-
|
|
347
|
-
Event
|
|
348
|
-
Packet
|
|
349
|
-
BlockHeight int64 `json:"blockHeight"`
|
|
350
|
-
BlockTime int64 `json:"blockTime"`
|
|
316
|
+
vm.ActionHeader `actionType:"IBC_EVENT"`
|
|
317
|
+
Event string `json:"event" default:"receivePacket"`
|
|
318
|
+
Packet channeltypes.Packet `json:"packet"`
|
|
351
319
|
}
|
|
352
320
|
|
|
353
321
|
func (im IBCModule) OnRecvPacket(
|
|
@@ -364,11 +332,7 @@ func (im IBCModule) OnRecvPacket(
|
|
|
364
332
|
// the same packets.
|
|
365
333
|
|
|
366
334
|
event := receivePacketEvent{
|
|
367
|
-
|
|
368
|
-
Event: "receivePacket",
|
|
369
|
-
Packet: packet,
|
|
370
|
-
BlockHeight: ctx.BlockHeight(),
|
|
371
|
-
BlockTime: ctx.BlockTime().Unix(),
|
|
335
|
+
Packet: packet,
|
|
372
336
|
}
|
|
373
337
|
|
|
374
338
|
err := im.PushAction(ctx, event)
|
|
@@ -380,12 +344,10 @@ func (im IBCModule) OnRecvPacket(
|
|
|
380
344
|
}
|
|
381
345
|
|
|
382
346
|
type acknowledgementPacketEvent struct {
|
|
383
|
-
|
|
384
|
-
Event string `json:"event"
|
|
347
|
+
vm.ActionHeader `actionType:"IBC_EVENT"`
|
|
348
|
+
Event string `json:"event" default:"acknowledgementPacket"`
|
|
385
349
|
Packet channeltypes.Packet `json:"packet"`
|
|
386
350
|
Acknowledgement []byte `json:"acknowledgement"`
|
|
387
|
-
BlockHeight int64 `json:"blockHeight"`
|
|
388
|
-
BlockTime int64 `json:"blockTime"`
|
|
389
351
|
}
|
|
390
352
|
|
|
391
353
|
func (im IBCModule) OnAcknowledgementPacket(
|
|
@@ -395,12 +357,8 @@ func (im IBCModule) OnAcknowledgementPacket(
|
|
|
395
357
|
relayer sdk.AccAddress,
|
|
396
358
|
) error {
|
|
397
359
|
event := acknowledgementPacketEvent{
|
|
398
|
-
Type: "IBC_EVENT",
|
|
399
|
-
Event: "acknowledgementPacket",
|
|
400
360
|
Packet: packet,
|
|
401
361
|
Acknowledgement: acknowledgement,
|
|
402
|
-
BlockHeight: ctx.BlockHeight(),
|
|
403
|
-
BlockTime: ctx.BlockTime().Unix(),
|
|
404
362
|
}
|
|
405
363
|
|
|
406
364
|
err := im.PushAction(ctx, event)
|
|
@@ -412,11 +370,9 @@ func (im IBCModule) OnAcknowledgementPacket(
|
|
|
412
370
|
}
|
|
413
371
|
|
|
414
372
|
type timeoutPacketEvent struct {
|
|
415
|
-
|
|
416
|
-
Event
|
|
417
|
-
Packet
|
|
418
|
-
BlockHeight int64 `json:"blockHeight"`
|
|
419
|
-
BlockTime int64 `json:"blockTime"`
|
|
373
|
+
vm.ActionHeader `actionType:"IBC_EVENT"`
|
|
374
|
+
Event string `json:"event" default:"timeoutPacket"`
|
|
375
|
+
Packet channeltypes.Packet `json:"packet"`
|
|
420
376
|
}
|
|
421
377
|
|
|
422
378
|
func (im IBCModule) OnTimeoutPacket(
|
|
@@ -425,11 +381,7 @@ func (im IBCModule) OnTimeoutPacket(
|
|
|
425
381
|
relayer sdk.AccAddress,
|
|
426
382
|
) error {
|
|
427
383
|
event := timeoutPacketEvent{
|
|
428
|
-
|
|
429
|
-
Event: "timeoutPacket",
|
|
430
|
-
Packet: packet,
|
|
431
|
-
BlockHeight: ctx.BlockHeight(),
|
|
432
|
-
BlockTime: ctx.BlockTime().Unix(),
|
|
384
|
+
Packet: packet,
|
|
433
385
|
}
|
|
434
386
|
|
|
435
387
|
err := im.PushAction(ctx, event)
|