@agoric/cosmos 0.34.2-dev-5dc325b.0 → 0.35.0-getting-started-dev-26244e8.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/CHANGELOG.md +73 -0
- package/app/app.go +4 -5
- package/cmd/agd/main.go +11 -133
- package/cmd/libdaemon/main.go +53 -67
- package/daemon/cmd/root.go +24 -55
- package/daemon/main.go +1 -3
- package/git-revision.txt +1 -1
- package/package.json +3 -6
- package/proto/agoric/vstorage/query.proto +1 -53
- package/vm/controller.go +18 -8
- package/x/lien/lien.go +4 -6
- package/x/lien/lien_test.go +15 -19
- package/x/swingset/abci.go +2 -3
- package/x/swingset/swingset.go +2 -4
- package/x/swingset/types/default-params.go +1 -1
- package/x/swingset/types/msgs.pb.go +16 -16
- package/x/vbank/vbank.go +10 -11
- package/x/vbank/vbank_test.go +5 -5
- package/x/vibc/ibc.go +9 -11
- package/x/vstorage/keeper/grpc_query.go +0 -221
- package/x/vstorage/types/query.pb.go +36 -646
- package/x/vstorage/types/query.pb.gw.go +0 -119
- package/x/vstorage/vstorage.go +15 -16
- package/x/vstorage/vstorage_test.go +4 -4
- package/cmd/agd/agvm.go +0 -42
- package/vm/client.go +0 -113
- package/vm/client_test.go +0 -184
- package/vm/jsonrpcconn/jsonrpcconn.go +0 -160
- package/vm/jsonrpcconn/jsonrpcconn_test.go +0 -126
- package/vm/server.go +0 -23
- package/x/vstorage/README.md +0 -140
- package/x/vstorage/capdata/capdata.go +0 -298
- package/x/vstorage/capdata/capdata_test.go +0 -352
- package/x/vstorage/keeper/keeper_grpc_test.go +0 -300
|
@@ -87,78 +87,6 @@ func local_request_Query_Data_0(ctx context.Context, marshaler runtime.Marshaler
|
|
|
87
87
|
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
-
var (
|
|
91
|
-
filter_Query_CapData_0 = &utilities.DoubleArray{Encoding: map[string]int{"path": 0}, Base: []int{1, 1, 0}, Check: []int{0, 1, 2}}
|
|
92
|
-
)
|
|
93
|
-
|
|
94
|
-
func request_Query_CapData_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
|
95
|
-
var protoReq QueryCapDataRequest
|
|
96
|
-
var metadata runtime.ServerMetadata
|
|
97
|
-
|
|
98
|
-
var (
|
|
99
|
-
val string
|
|
100
|
-
ok bool
|
|
101
|
-
err error
|
|
102
|
-
_ = err
|
|
103
|
-
)
|
|
104
|
-
|
|
105
|
-
val, ok = pathParams["path"]
|
|
106
|
-
if !ok {
|
|
107
|
-
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "path")
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
protoReq.Path, err = runtime.String(val)
|
|
111
|
-
|
|
112
|
-
if err != nil {
|
|
113
|
-
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "path", err)
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
if err := req.ParseForm(); err != nil {
|
|
117
|
-
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
|
118
|
-
}
|
|
119
|
-
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_CapData_0); err != nil {
|
|
120
|
-
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
msg, err := client.CapData(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
|
124
|
-
return msg, metadata, err
|
|
125
|
-
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
func local_request_Query_CapData_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
|
129
|
-
var protoReq QueryCapDataRequest
|
|
130
|
-
var metadata runtime.ServerMetadata
|
|
131
|
-
|
|
132
|
-
var (
|
|
133
|
-
val string
|
|
134
|
-
ok bool
|
|
135
|
-
err error
|
|
136
|
-
_ = err
|
|
137
|
-
)
|
|
138
|
-
|
|
139
|
-
val, ok = pathParams["path"]
|
|
140
|
-
if !ok {
|
|
141
|
-
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "path")
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
protoReq.Path, err = runtime.String(val)
|
|
145
|
-
|
|
146
|
-
if err != nil {
|
|
147
|
-
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "path", err)
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
if err := req.ParseForm(); err != nil {
|
|
151
|
-
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
|
152
|
-
}
|
|
153
|
-
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_CapData_0); err != nil {
|
|
154
|
-
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
msg, err := server.CapData(ctx, &protoReq)
|
|
158
|
-
return msg, metadata, err
|
|
159
|
-
|
|
160
|
-
}
|
|
161
|
-
|
|
162
90
|
var (
|
|
163
91
|
filter_Query_Children_0 = &utilities.DoubleArray{Encoding: map[string]int{"path": 0}, Base: []int{1, 1, 0}, Check: []int{0, 1, 2}}
|
|
164
92
|
)
|
|
@@ -260,29 +188,6 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv
|
|
|
260
188
|
|
|
261
189
|
})
|
|
262
190
|
|
|
263
|
-
mux.Handle("GET", pattern_Query_CapData_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
|
264
|
-
ctx, cancel := context.WithCancel(req.Context())
|
|
265
|
-
defer cancel()
|
|
266
|
-
var stream runtime.ServerTransportStream
|
|
267
|
-
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
|
|
268
|
-
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
|
269
|
-
rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req)
|
|
270
|
-
if err != nil {
|
|
271
|
-
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
|
272
|
-
return
|
|
273
|
-
}
|
|
274
|
-
resp, md, err := local_request_Query_CapData_0(rctx, inboundMarshaler, server, req, pathParams)
|
|
275
|
-
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
|
|
276
|
-
ctx = runtime.NewServerMetadataContext(ctx, md)
|
|
277
|
-
if err != nil {
|
|
278
|
-
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
|
279
|
-
return
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
forward_Query_CapData_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
|
283
|
-
|
|
284
|
-
})
|
|
285
|
-
|
|
286
191
|
mux.Handle("GET", pattern_Query_Children_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
|
287
192
|
ctx, cancel := context.WithCancel(req.Context())
|
|
288
193
|
defer cancel()
|
|
@@ -367,26 +272,6 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie
|
|
|
367
272
|
|
|
368
273
|
})
|
|
369
274
|
|
|
370
|
-
mux.Handle("GET", pattern_Query_CapData_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
|
371
|
-
ctx, cancel := context.WithCancel(req.Context())
|
|
372
|
-
defer cancel()
|
|
373
|
-
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
|
374
|
-
rctx, err := runtime.AnnotateContext(ctx, mux, req)
|
|
375
|
-
if err != nil {
|
|
376
|
-
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
|
377
|
-
return
|
|
378
|
-
}
|
|
379
|
-
resp, md, err := request_Query_CapData_0(rctx, inboundMarshaler, client, req, pathParams)
|
|
380
|
-
ctx = runtime.NewServerMetadataContext(ctx, md)
|
|
381
|
-
if err != nil {
|
|
382
|
-
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
|
383
|
-
return
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
forward_Query_CapData_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
|
387
|
-
|
|
388
|
-
})
|
|
389
|
-
|
|
390
275
|
mux.Handle("GET", pattern_Query_Children_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
|
391
276
|
ctx, cancel := context.WithCancel(req.Context())
|
|
392
277
|
defer cancel()
|
|
@@ -413,15 +298,11 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie
|
|
|
413
298
|
var (
|
|
414
299
|
pattern_Query_Data_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"agoric", "vstorage", "data", "path"}, "", runtime.AssumeColonVerbOpt(false)))
|
|
415
300
|
|
|
416
|
-
pattern_Query_CapData_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"agoric", "vstorage", "capdata", "path"}, "", runtime.AssumeColonVerbOpt(false)))
|
|
417
|
-
|
|
418
301
|
pattern_Query_Children_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"agoric", "vstorage", "children", "path"}, "", runtime.AssumeColonVerbOpt(false)))
|
|
419
302
|
)
|
|
420
303
|
|
|
421
304
|
var (
|
|
422
305
|
forward_Query_Data_0 = runtime.ForwardResponseMessage
|
|
423
306
|
|
|
424
|
-
forward_Query_CapData_0 = runtime.ForwardResponseMessage
|
|
425
|
-
|
|
426
307
|
forward_Query_Children_0 = runtime.ForwardResponseMessage
|
|
427
308
|
)
|
package/x/vstorage/vstorage.go
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
package vstorage
|
|
2
2
|
|
|
3
3
|
import (
|
|
4
|
-
"context"
|
|
5
4
|
"encoding/json"
|
|
6
5
|
"errors"
|
|
7
6
|
"fmt"
|
|
@@ -9,6 +8,7 @@ import (
|
|
|
9
8
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
10
9
|
|
|
11
10
|
agoric "github.com/Agoric/agoric-sdk/golang/cosmos/types"
|
|
11
|
+
"github.com/Agoric/agoric-sdk/golang/cosmos/vm"
|
|
12
12
|
)
|
|
13
13
|
|
|
14
14
|
type vstorageHandler struct {
|
|
@@ -41,8 +41,7 @@ func unmarshalSinglePathFromArgs(args []json.RawMessage, path *string) error {
|
|
|
41
41
|
return json.Unmarshal(args[0], path)
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
func (sh vstorageHandler) Receive(cctx
|
|
45
|
-
ctx := sdk.UnwrapSDKContext(cctx)
|
|
44
|
+
func (sh vstorageHandler) Receive(cctx *vm.ControllerContext, str string) (ret string, err error) {
|
|
46
45
|
keeper := sh.keeper
|
|
47
46
|
msg := new(vstorageMessage)
|
|
48
47
|
err = json.Unmarshal([]byte(str), &msg)
|
|
@@ -57,7 +56,7 @@ func (sh vstorageHandler) Receive(cctx context.Context, str string) (ret string,
|
|
|
57
56
|
case sdk.ErrorOutOfGas:
|
|
58
57
|
err = fmt.Errorf(
|
|
59
58
|
"out of gas in location: %v; gasUsed: %d",
|
|
60
|
-
rType.Descriptor,
|
|
59
|
+
rType.Descriptor, cctx.Context.GasMeter().GasConsumed(),
|
|
61
60
|
)
|
|
62
61
|
default:
|
|
63
62
|
// Not ErrorOutOfGas, so panic again.
|
|
@@ -75,7 +74,7 @@ func (sh vstorageHandler) Receive(cctx context.Context, str string) (ret string,
|
|
|
75
74
|
if err != nil {
|
|
76
75
|
return
|
|
77
76
|
}
|
|
78
|
-
keeper.SetStorageAndNotify(
|
|
77
|
+
keeper.SetStorageAndNotify(cctx.Context, entry)
|
|
79
78
|
}
|
|
80
79
|
return "true", nil
|
|
81
80
|
|
|
@@ -90,7 +89,7 @@ func (sh vstorageHandler) Receive(cctx context.Context, str string) (ret string,
|
|
|
90
89
|
return
|
|
91
90
|
}
|
|
92
91
|
//fmt.Printf("giving Keeper.SetStorage(%s) %s\n", entry.Path(), entry.Value())
|
|
93
|
-
keeper.LegacySetStorageAndNotify(
|
|
92
|
+
keeper.LegacySetStorageAndNotify(cctx.Context, entry)
|
|
94
93
|
}
|
|
95
94
|
return "true", nil
|
|
96
95
|
|
|
@@ -101,7 +100,7 @@ func (sh vstorageHandler) Receive(cctx context.Context, str string) (ret string,
|
|
|
101
100
|
if err != nil {
|
|
102
101
|
return
|
|
103
102
|
}
|
|
104
|
-
keeper.SetStorage(
|
|
103
|
+
keeper.SetStorage(cctx.Context, entry)
|
|
105
104
|
}
|
|
106
105
|
return "true", nil
|
|
107
106
|
|
|
@@ -116,7 +115,7 @@ func (sh vstorageHandler) Receive(cctx context.Context, str string) (ret string,
|
|
|
116
115
|
err = fmt.Errorf("no value for append entry with path: %q", entry.Key())
|
|
117
116
|
return
|
|
118
117
|
}
|
|
119
|
-
err = keeper.AppendStorageValueAndNotify(
|
|
118
|
+
err = keeper.AppendStorageValueAndNotify(cctx.Context, entry.Key(), entry.StringValue())
|
|
120
119
|
if err != nil {
|
|
121
120
|
return
|
|
122
121
|
}
|
|
@@ -131,7 +130,7 @@ func (sh vstorageHandler) Receive(cctx context.Context, str string) (ret string,
|
|
|
131
130
|
return
|
|
132
131
|
}
|
|
133
132
|
|
|
134
|
-
entry := keeper.GetEntry(
|
|
133
|
+
entry := keeper.GetEntry(cctx.Context, path)
|
|
135
134
|
bz, err := json.Marshal(entry.Value())
|
|
136
135
|
if err != nil {
|
|
137
136
|
return "", err
|
|
@@ -162,7 +161,7 @@ func (sh vstorageHandler) Receive(cctx context.Context, str string) (ret string,
|
|
|
162
161
|
if err != nil {
|
|
163
162
|
return
|
|
164
163
|
}
|
|
165
|
-
value := keeper.HasStorage(
|
|
164
|
+
value := keeper.HasStorage(cctx.Context, path)
|
|
166
165
|
if !value {
|
|
167
166
|
return "false", nil
|
|
168
167
|
}
|
|
@@ -175,7 +174,7 @@ func (sh vstorageHandler) Receive(cctx context.Context, str string) (ret string,
|
|
|
175
174
|
if err != nil {
|
|
176
175
|
return
|
|
177
176
|
}
|
|
178
|
-
children := keeper.GetChildren(
|
|
177
|
+
children := keeper.GetChildren(cctx.Context, path)
|
|
179
178
|
if children.Children == nil {
|
|
180
179
|
return "[]", nil
|
|
181
180
|
}
|
|
@@ -191,10 +190,10 @@ func (sh vstorageHandler) Receive(cctx context.Context, str string) (ret string,
|
|
|
191
190
|
if err != nil {
|
|
192
191
|
return
|
|
193
192
|
}
|
|
194
|
-
children := keeper.GetChildren(
|
|
193
|
+
children := keeper.GetChildren(cctx.Context, path)
|
|
195
194
|
entries := make([]agoric.KVEntry, len(children.Children))
|
|
196
195
|
for i, child := range children.Children {
|
|
197
|
-
entry := keeper.GetEntry(
|
|
196
|
+
entry := keeper.GetEntry(cctx.Context, fmt.Sprintf("%s.%s", path, child))
|
|
198
197
|
if !entry.HasValue() {
|
|
199
198
|
entries[i] = agoric.NewKVEntryWithNoValue(child)
|
|
200
199
|
} else {
|
|
@@ -213,10 +212,10 @@ func (sh vstorageHandler) Receive(cctx context.Context, str string) (ret string,
|
|
|
213
212
|
if err != nil {
|
|
214
213
|
return
|
|
215
214
|
}
|
|
216
|
-
children := keeper.GetChildren(
|
|
215
|
+
children := keeper.GetChildren(cctx.Context, path)
|
|
217
216
|
vals := make([]*string, len(children.Children))
|
|
218
217
|
for i, child := range children.Children {
|
|
219
|
-
vals[i] = keeper.GetEntry(
|
|
218
|
+
vals[i] = keeper.GetEntry(cctx.Context, fmt.Sprintf("%s.%s", path, child)).Value()
|
|
220
219
|
}
|
|
221
220
|
bytes, err := json.Marshal(vals)
|
|
222
221
|
if err != nil {
|
|
@@ -230,7 +229,7 @@ func (sh vstorageHandler) Receive(cctx context.Context, str string) (ret string,
|
|
|
230
229
|
if err != nil {
|
|
231
230
|
return
|
|
232
231
|
}
|
|
233
|
-
children := keeper.GetChildren(
|
|
232
|
+
children := keeper.GetChildren(cctx.Context, path)
|
|
234
233
|
if children.Children == nil {
|
|
235
234
|
return "0", nil
|
|
236
235
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
package vstorage
|
|
2
2
|
|
|
3
3
|
import (
|
|
4
|
-
"context"
|
|
5
4
|
"encoding/json"
|
|
6
5
|
"fmt"
|
|
7
6
|
"reflect"
|
|
@@ -15,6 +14,7 @@ import (
|
|
|
15
14
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
16
15
|
|
|
17
16
|
agorictypes "github.com/Agoric/agoric-sdk/golang/cosmos/types"
|
|
17
|
+
"github.com/Agoric/agoric-sdk/golang/cosmos/vm"
|
|
18
18
|
"github.com/tendermint/tendermint/libs/log"
|
|
19
19
|
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
|
20
20
|
dbm "github.com/tendermint/tm-db"
|
|
@@ -32,7 +32,7 @@ type testKit struct {
|
|
|
32
32
|
keeper Keeper
|
|
33
33
|
handler vstorageHandler
|
|
34
34
|
ctx sdk.Context
|
|
35
|
-
cctx
|
|
35
|
+
cctx *vm.ControllerContext
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
func makeTestKit() testKit {
|
|
@@ -45,14 +45,14 @@ func makeTestKit() testKit {
|
|
|
45
45
|
panic(err)
|
|
46
46
|
}
|
|
47
47
|
ctx := sdk.NewContext(ms, tmproto.Header{}, false, log.NewNopLogger())
|
|
48
|
-
cctx :=
|
|
48
|
+
cctx := &vm.ControllerContext{Context: ctx}
|
|
49
49
|
handler := vstorageHandler{keeper}
|
|
50
50
|
return testKit{keeper, handler, ctx, cctx}
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
func callReceive(
|
|
54
54
|
handler vstorageHandler,
|
|
55
|
-
cctx
|
|
55
|
+
cctx *vm.ControllerContext,
|
|
56
56
|
method string,
|
|
57
57
|
args []interface{},
|
|
58
58
|
) (string, error) {
|
package/cmd/agd/agvm.go
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
package main
|
|
2
|
-
|
|
3
|
-
import (
|
|
4
|
-
"fmt"
|
|
5
|
-
"os"
|
|
6
|
-
"os/exec"
|
|
7
|
-
|
|
8
|
-
"github.com/tendermint/tendermint/libs/log"
|
|
9
|
-
)
|
|
10
|
-
|
|
11
|
-
// NewVMCommand creates a new OS command to run the Agoric VM. It sets up the
|
|
12
|
-
// file descriptors for the VM to communicate with agd, and passes their numbers
|
|
13
|
-
// via AGVM_FROM_AGD and AGVM_TO_AGD environment variables.
|
|
14
|
-
func NewVMCommand(logger log.Logger, binary string, args []string, vmFromAgd, vmToAgd *os.File) *exec.Cmd {
|
|
15
|
-
logger.Info("agd connecting to VM", "binary", binary, "args", args)
|
|
16
|
-
cmd := exec.Command(binary, args[1:]...)
|
|
17
|
-
|
|
18
|
-
// Manage the file descriptors.
|
|
19
|
-
cmd.Stdout = os.Stdout
|
|
20
|
-
cmd.Stderr = os.Stderr
|
|
21
|
-
cmd.Stdin = os.Stdin
|
|
22
|
-
numStdFiles := 3 // stdin, stdout, stderr
|
|
23
|
-
|
|
24
|
-
// We start our file descriptor allocations after the standard ones, including
|
|
25
|
-
// Node.js IPC (fd=3).
|
|
26
|
-
fdFromAgd := 4
|
|
27
|
-
fdToAgd := fdFromAgd + 1
|
|
28
|
-
|
|
29
|
-
// ExtraFiles begins at fd numStdFiles, so we need to compute the array.
|
|
30
|
-
cmd.ExtraFiles = make([]*os.File, fdToAgd - numStdFiles + 1)
|
|
31
|
-
cmd.ExtraFiles[fdFromAgd - numStdFiles] = vmFromAgd
|
|
32
|
-
cmd.ExtraFiles[fdToAgd - numStdFiles] = vmToAgd
|
|
33
|
-
|
|
34
|
-
// Pass the file descriptor numbers in the environment.
|
|
35
|
-
cmd.Env = append(
|
|
36
|
-
os.Environ(),
|
|
37
|
-
fmt.Sprintf("AGVM_FROM_AGD=%d", fdFromAgd),
|
|
38
|
-
fmt.Sprintf("AGVM_TO_AGD=%d", fdToAgd),
|
|
39
|
-
)
|
|
40
|
-
|
|
41
|
-
return cmd
|
|
42
|
-
}
|
package/vm/client.go
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
package vm
|
|
2
|
-
|
|
3
|
-
import (
|
|
4
|
-
"context"
|
|
5
|
-
"fmt"
|
|
6
|
-
"net/rpc"
|
|
7
|
-
)
|
|
8
|
-
|
|
9
|
-
// ReceiveMessageMethod is the name of the method we call in order to have the
|
|
10
|
-
// VM receive a Message.
|
|
11
|
-
const ReceiveMessageMethod = "agvm.ReceiveMessage"
|
|
12
|
-
|
|
13
|
-
// Message is what we send to the VM.
|
|
14
|
-
type Message struct {
|
|
15
|
-
Port int
|
|
16
|
-
Data string
|
|
17
|
-
NeedsReply bool
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// ClientCodec implements rpc.ClientCodec.
|
|
21
|
-
var _ rpc.ClientCodec = (*ClientCodec)(nil)
|
|
22
|
-
|
|
23
|
-
// ClientCodec implements a net/rpc ClientCodec for the "bridge" between the Go
|
|
24
|
-
// runtime and the VM in the single-process dual-runtime configuration.
|
|
25
|
-
//
|
|
26
|
-
// We expect to call it via the legacy API with signature:
|
|
27
|
-
// sendToController func(needsReply bool, msg string) (string, error)
|
|
28
|
-
// where msg and the returned string are JSON-encoded values.
|
|
29
|
-
//
|
|
30
|
-
// Note that the net/rpc framework cannot express a call that does not expect a
|
|
31
|
-
// response, so we'll note such calls by sending with a reply port of 0 and
|
|
32
|
-
// having the WriteRequest() method fabricate a Receive() call to clear the rpc
|
|
33
|
-
// state.
|
|
34
|
-
type ClientCodec struct {
|
|
35
|
-
ctx context.Context
|
|
36
|
-
send func(port, rPort int, msg string)
|
|
37
|
-
outbound map[int]rpc.Request
|
|
38
|
-
inbound chan *rpc.Response
|
|
39
|
-
replies map[uint64]string
|
|
40
|
-
replyToRead uint64
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// NewClientCodec creates a new ClientCodec.
|
|
44
|
-
func NewClientCodec(ctx context.Context, send func(int, int, string)) *ClientCodec {
|
|
45
|
-
return &ClientCodec{
|
|
46
|
-
ctx: ctx,
|
|
47
|
-
send: send,
|
|
48
|
-
outbound: make(map[int]rpc.Request),
|
|
49
|
-
inbound: make(chan *rpc.Response),
|
|
50
|
-
replies: make(map[uint64]string),
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// WriteRequest sends a request to the VM.
|
|
55
|
-
func (cc *ClientCodec) WriteRequest(r *rpc.Request, body interface{}) error {
|
|
56
|
-
if r.ServiceMethod != ReceiveMessageMethod {
|
|
57
|
-
return fmt.Errorf("unknown method %s", r.ServiceMethod)
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
msg, ok := body.(Message)
|
|
61
|
-
if !ok {
|
|
62
|
-
return fmt.Errorf("body %T is not a Message", body)
|
|
63
|
-
}
|
|
64
|
-
rPort := int(r.Seq + 1) // rPort is 1-indexed to indicate it's required
|
|
65
|
-
cc.outbound[rPort] = *r
|
|
66
|
-
var senderReplyPort int
|
|
67
|
-
if msg.NeedsReply {
|
|
68
|
-
senderReplyPort = rPort
|
|
69
|
-
}
|
|
70
|
-
cc.send(msg.Port, senderReplyPort, msg.Data)
|
|
71
|
-
if !msg.NeedsReply {
|
|
72
|
-
return cc.Receive(rPort, false, "<no-reply-requested>")
|
|
73
|
-
}
|
|
74
|
-
return nil
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// ReadResponseHeader decodes a response header from the VM.
|
|
78
|
-
func (cc *ClientCodec) ReadResponseHeader(r *rpc.Response) error {
|
|
79
|
-
resp := <-cc.inbound
|
|
80
|
-
*r = *resp
|
|
81
|
-
cc.replyToRead = r.Seq
|
|
82
|
-
return nil
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
// ReadResponseBody decodes a response body (currently just string) from the VM.
|
|
86
|
-
func (cc *ClientCodec) ReadResponseBody(body interface{}) error {
|
|
87
|
-
if body != nil {
|
|
88
|
-
*body.(*string) = cc.replies[cc.replyToRead]
|
|
89
|
-
}
|
|
90
|
-
delete(cc.replies, cc.replyToRead)
|
|
91
|
-
return nil
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// Receive is called by the VM to send a response to the client.
|
|
95
|
-
func (cc *ClientCodec) Receive(rPort int, isError bool, data string) error {
|
|
96
|
-
outb := cc.outbound[rPort]
|
|
97
|
-
delete(cc.outbound, rPort)
|
|
98
|
-
resp := &rpc.Response{
|
|
99
|
-
ServiceMethod: outb.ServiceMethod,
|
|
100
|
-
Seq: outb.Seq,
|
|
101
|
-
}
|
|
102
|
-
if isError {
|
|
103
|
-
resp.Error = data
|
|
104
|
-
} else {
|
|
105
|
-
cc.replies[resp.Seq] = data
|
|
106
|
-
}
|
|
107
|
-
cc.inbound <- resp
|
|
108
|
-
return nil
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
func (cc *ClientCodec) Close() error {
|
|
112
|
-
return nil
|
|
113
|
-
}
|
package/vm/client_test.go
DELETED
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
package vm_test
|
|
2
|
-
|
|
3
|
-
import (
|
|
4
|
-
"context"
|
|
5
|
-
"encoding/json"
|
|
6
|
-
"fmt"
|
|
7
|
-
"net/rpc"
|
|
8
|
-
"testing"
|
|
9
|
-
"time"
|
|
10
|
-
|
|
11
|
-
"github.com/Agoric/agoric-sdk/golang/cosmos/vm"
|
|
12
|
-
)
|
|
13
|
-
|
|
14
|
-
type Sender func(ctx context.Context, needReply bool, str string) (string, error)
|
|
15
|
-
|
|
16
|
-
type errorWrapper struct {
|
|
17
|
-
Error string `json:"error"`
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// ConnectVMClientCodec creates an RPC client codec and a sender to the
|
|
21
|
-
// in-process implementation of the VM.
|
|
22
|
-
func ConnectVMClientCodec(ctx context.Context, nodePort int, sendFunc func(int, int, string)) (*vm.ClientCodec, Sender) {
|
|
23
|
-
vmClientCodec := vm.NewClientCodec(context.Background(), sendFunc)
|
|
24
|
-
vmClient := rpc.NewClientWithCodec(vmClientCodec)
|
|
25
|
-
|
|
26
|
-
sendToNode := func(ctx context.Context, needReply bool, str string) (string, error) {
|
|
27
|
-
if str == "shutdown" {
|
|
28
|
-
return "", vmClientCodec.Close()
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
msg := vm.Message{
|
|
32
|
-
Port: nodePort,
|
|
33
|
-
NeedsReply: needReply,
|
|
34
|
-
Data: str,
|
|
35
|
-
}
|
|
36
|
-
var reply string
|
|
37
|
-
err := vmClient.Call(vm.ReceiveMessageMethod, msg, &reply)
|
|
38
|
-
return reply, err
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return vmClientCodec, sendToNode
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
type Fixture struct {
|
|
45
|
-
SendToNode Sender
|
|
46
|
-
SendToGo func (port int, msgStr string) string
|
|
47
|
-
ReplyToGo func (replyPort int, isError bool, respStr string) int
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
func NewFixture(t *testing.T) (*Fixture) {
|
|
51
|
-
nodePort := 42
|
|
52
|
-
|
|
53
|
-
f := &Fixture{}
|
|
54
|
-
|
|
55
|
-
sendFunc := func(port int, reply int, str string) {
|
|
56
|
-
switch str {
|
|
57
|
-
case "ping":
|
|
58
|
-
time.AfterFunc(100*time.Millisecond, func() {
|
|
59
|
-
fmt.Printf("sendFunc: port=%d, reply=%d, str=%s\n", port, reply, str)
|
|
60
|
-
if reply != 0 {
|
|
61
|
-
f.ReplyToGo(reply, false, "pong")
|
|
62
|
-
}
|
|
63
|
-
})
|
|
64
|
-
case "wait":
|
|
65
|
-
time.AfterFunc(300*time.Millisecond, func() {
|
|
66
|
-
fmt.Printf("sendFunc: port=%d, reply=%d, str=%s\n", port, reply, str)
|
|
67
|
-
if reply != 0 {
|
|
68
|
-
f.ReplyToGo(reply, false, "done-waiting")
|
|
69
|
-
}
|
|
70
|
-
})
|
|
71
|
-
default:
|
|
72
|
-
t.Errorf("Unexpected message %s", str)
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
vmClientCodec, sendToNode := ConnectVMClientCodec(
|
|
77
|
-
context.Background(),
|
|
78
|
-
int(nodePort),
|
|
79
|
-
sendFunc,
|
|
80
|
-
)
|
|
81
|
-
agdServer := vm.NewAgdServer()
|
|
82
|
-
|
|
83
|
-
f.SendToNode = sendToNode
|
|
84
|
-
f.SendToGo = func (port int, msgStr string) string {
|
|
85
|
-
fmt.Println("Send to Go", msgStr)
|
|
86
|
-
var respStr string
|
|
87
|
-
message := &vm.Message{
|
|
88
|
-
Port: int(port),
|
|
89
|
-
NeedsReply: true,
|
|
90
|
-
Data: msgStr,
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
err := agdServer.ReceiveMessage(message, &respStr)
|
|
94
|
-
if err == nil {
|
|
95
|
-
return respStr
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// fmt.Fprintln(os.Stderr, "Cannot receive from controller", err)
|
|
99
|
-
errResp := errorWrapper{
|
|
100
|
-
Error: err.Error(),
|
|
101
|
-
}
|
|
102
|
-
respBytes, err := json.Marshal(&errResp)
|
|
103
|
-
if err != nil {
|
|
104
|
-
panic(err)
|
|
105
|
-
}
|
|
106
|
-
return string(respBytes)
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
f.ReplyToGo = func (replyPort int, isError bool, respStr string) int {
|
|
110
|
-
if err := vmClientCodec.Receive(replyPort, isError, respStr); err != nil {
|
|
111
|
-
return 1
|
|
112
|
-
}
|
|
113
|
-
return 0
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
return f
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
func TestClient_oneOutbound(t *testing.T) {
|
|
120
|
-
f := NewFixture(t)
|
|
121
|
-
|
|
122
|
-
// Try one blocking call.
|
|
123
|
-
ret, err := f.SendToNode(context.Background(), true, "ping")
|
|
124
|
-
if err != nil {
|
|
125
|
-
t.Error(err)
|
|
126
|
-
}
|
|
127
|
-
if ret != "pong" {
|
|
128
|
-
t.Errorf("ping want pong, got %s", ret)
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
func TestClient_ShortBg(t *testing.T) {
|
|
133
|
-
|
|
134
|
-
f := NewFixture(t)
|
|
135
|
-
|
|
136
|
-
// Try a short background call with a long overlapping call.
|
|
137
|
-
done := make(chan struct{})
|
|
138
|
-
go func() {
|
|
139
|
-
defer close(done)
|
|
140
|
-
ret, err := f.SendToNode(context.Background(), true, "ping")
|
|
141
|
-
if err != nil {
|
|
142
|
-
t.Error(err)
|
|
143
|
-
}
|
|
144
|
-
if ret != "pong" {
|
|
145
|
-
t.Errorf("ping want pong, got %s", ret)
|
|
146
|
-
}
|
|
147
|
-
}()
|
|
148
|
-
|
|
149
|
-
ret, err := f.SendToNode(context.Background(), true, "wait")
|
|
150
|
-
if err != nil {
|
|
151
|
-
t.Error(err)
|
|
152
|
-
}
|
|
153
|
-
if ret != "done-waiting" {
|
|
154
|
-
t.Errorf("wait want done-waiting, got %s", ret)
|
|
155
|
-
}
|
|
156
|
-
<-done
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
func TestClient_LongBg(t *testing.T) {
|
|
160
|
-
|
|
161
|
-
f := NewFixture(t)
|
|
162
|
-
|
|
163
|
-
// Try a long background call with a short overlapping call.
|
|
164
|
-
done := make(chan struct{})
|
|
165
|
-
go func() {
|
|
166
|
-
defer close(done)
|
|
167
|
-
ret, err := f.SendToNode(context.Background(), true, "wait")
|
|
168
|
-
if err != nil {
|
|
169
|
-
t.Error(err)
|
|
170
|
-
}
|
|
171
|
-
if ret != "done-waiting" {
|
|
172
|
-
t.Errorf("ping want done-waiting, got %s", ret)
|
|
173
|
-
}
|
|
174
|
-
}()
|
|
175
|
-
|
|
176
|
-
ret, err := f.SendToNode(context.Background(), true, "ping")
|
|
177
|
-
if err != nil {
|
|
178
|
-
t.Error(err)
|
|
179
|
-
}
|
|
180
|
-
if ret != "pong" {
|
|
181
|
-
t.Errorf("wait want pong, got %s", ret)
|
|
182
|
-
}
|
|
183
|
-
<-done
|
|
184
|
-
}
|