Unify RPC method signatures and parameter decoding (#8397)

Pass all parameters from JSON-RPC requests to their corresponding handlers
using struct types instead of positional parameters. This allows us to control
encoding of arguments using only the standard library, and to eliminate the
remaining special-purpose JSON encoding hooks in the server.

To support existing use, the server still allows arguments to be encoded in
JSON as either an array or an object.

Related changes:

- Rework the RPCFunc constructor to reduce reflection during RPC call service.
- Add request parameter wrappers for each RPC service method.
- Update the RPC Environment methods to use these types.
- Update the interfaces and shims derived from Environment to the new
  signatures.
- Update and extend test cases.
This commit is contained in:
M. J. Fromberger
2022-04-27 07:53:51 -07:00
committed by GitHub
parent e741d01231
commit da1b871808
30 changed files with 983 additions and 779 deletions

View File

@@ -17,10 +17,14 @@ import (
)
func FuzzRPCJSONRPCServer(f *testing.F) {
type args struct {
S string `json:"s"`
I int `json:"i"`
}
var rpcFuncMap = map[string]*rpcserver.RPCFunc{
"c": rpcserver.NewRPCFunc(func(ctx context.Context, s string, i int) (string, error) {
"c": rpcserver.NewRPCFunc(func(context.Context, *args) (string, error) {
return "foo", nil
}, "s", "i"),
}),
}
mux := http.NewServeMux()