From 8b8449faee25e14f6e6f9a70c780d2d3f2c980ae Mon Sep 17 00:00:00 2001 From: Lucas Molas Date: Tue, 17 Nov 2020 10:39:53 -0300 Subject: [PATCH] update jsonrpc with max req size --- cmd/lotus-gateway/main.go | 10 +++++++++- cmd/lotus/daemon.go | 10 +++++++++- cmd/lotus/rpc.go | 8 ++++++-- go.mod | 6 +++--- go.sum | 10 ++++++++-- 5 files changed, 35 insertions(+), 9 deletions(-) diff --git a/cmd/lotus-gateway/main.go b/cmd/lotus-gateway/main.go index 3fed88468..bc8785923 100644 --- a/cmd/lotus-gateway/main.go +++ b/cmd/lotus-gateway/main.go @@ -61,6 +61,10 @@ var runCmd = &cli.Command{ Usage: "host address and port the api server will listen on", Value: "0.0.0.0:2346", }, + &cli.IntFlag{ + Name: "api-max-req-size", + Usage: "maximum API request size accepted by the JSON RPC server", + }, }, Action: func(cctx *cli.Context) error { log.Info("Starting lotus gateway") @@ -87,7 +91,11 @@ var runCmd = &cli.Command{ log.Info("Setting up API endpoint at " + address) - rpcServer := jsonrpc.NewServer() + serverOptions := make([]jsonrpc.ServerOption, 0) + if maxRequestSize := cctx.Int("api-max-req-size"); maxRequestSize != 0 { + serverOptions = append(serverOptions, jsonrpc.WithMaxRequestSize(int64(maxRequestSize))) + } + rpcServer := jsonrpc.NewServer(serverOptions...) rpcServer.Register("Filecoin", metrics.MetricedGatewayAPI(NewGatewayAPI(api))) mux.Handle("/rpc/v0", rpcServer) diff --git a/cmd/lotus/daemon.go b/cmd/lotus/daemon.go index 1d13b4082..d15707fc7 100644 --- a/cmd/lotus/daemon.go +++ b/cmd/lotus/daemon.go @@ -136,6 +136,14 @@ var DaemonCmd = &cli.Command{ Name: "config", Usage: "specify path of config file to use", }, + // FIXME: This is not the correct place to put this configuration + // option. Ideally it would be part of `config.toml` but at the + // moment that only applies to the node configuration and not outside + // components like the RPC server. + &cli.IntFlag{ + Name: "api-max-req-size", + Usage: "maximum API request size accepted by the JSON RPC server", + }, }, Action: func(cctx *cli.Context) error { isLite := cctx.Bool("lite") @@ -321,7 +329,7 @@ var DaemonCmd = &cli.Command{ } // TODO: properly parse api endpoint (or make it a URL) - return serveRPC(api, stop, endpoint, shutdownChan) + return serveRPC(api, stop, endpoint, shutdownChan, int64(cctx.Int("api-max-req-size"))) }, Subcommands: []*cli.Command{ daemonStopCmd, diff --git a/cmd/lotus/rpc.go b/cmd/lotus/rpc.go index 955a92fc0..82a1fb480 100644 --- a/cmd/lotus/rpc.go +++ b/cmd/lotus/rpc.go @@ -33,8 +33,12 @@ import ( var log = logging.Logger("main") -func serveRPC(a api.FullNode, stop node.StopFunc, addr multiaddr.Multiaddr, shutdownCh <-chan struct{}) error { - rpcServer := jsonrpc.NewServer() +func serveRPC(a api.FullNode, stop node.StopFunc, addr multiaddr.Multiaddr, shutdownCh <-chan struct{}, maxRequestSize int64) error { + serverOptions := make([]jsonrpc.ServerOption, 0) + if maxRequestSize != 0 { // config set + serverOptions = append(serverOptions, jsonrpc.WithMaxRequestSize(maxRequestSize)) + } + rpcServer := jsonrpc.NewServer(serverOptions...) rpcServer.Register("Filecoin", apistruct.PermissionedFullAPI(metrics.MetricedFullAPI(a))) ah := &auth.Handler{ diff --git a/go.mod b/go.mod index e907d8651..107b935d6 100644 --- a/go.mod +++ b/go.mod @@ -32,7 +32,7 @@ require ( github.com/filecoin-project/go-data-transfer v1.2.0 github.com/filecoin-project/go-fil-commcid v0.0.0-20201016201715-d41df56b4f6a github.com/filecoin-project/go-fil-markets v1.0.6 - github.com/filecoin-project/go-jsonrpc v0.1.2-0.20201008195726-68c6a2704e49 + github.com/filecoin-project/go-jsonrpc v0.1.2-0.20201116213214-f4b2d34247f0 github.com/filecoin-project/go-multistore v0.0.3 github.com/filecoin-project/go-padreader v0.0.0-20200903213702-ed5fae088b20 github.com/filecoin-project/go-paramfetch v0.0.2-0.20200701152213-3e0f0afdc261 @@ -132,10 +132,10 @@ require ( github.com/whyrusleeping/multiaddr-filter v0.0.0-20160516205228-e903e4adabd7 github.com/whyrusleeping/pubsub v0.0.0-20131020042734-02de8aa2db3d github.com/xorcare/golden v0.6.1-0.20191112154924-b87f686d7542 - go.opencensus.io v0.22.4 + go.opencensus.io v0.22.5 go.uber.org/dig v1.10.0 // indirect go.uber.org/fx v1.9.0 - go.uber.org/multierr v1.5.0 + go.uber.org/multierr v1.6.0 go.uber.org/zap v1.16.0 golang.org/x/net v0.0.0-20201021035429-f5854403a974 golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9 diff --git a/go.sum b/go.sum index f2c7ddd4a..a2331bcfb 100644 --- a/go.sum +++ b/go.sum @@ -269,8 +269,8 @@ github.com/filecoin-project/go-hamt-ipld v0.1.5/go.mod h1:6Is+ONR5Cd5R6XZoCse1CW github.com/filecoin-project/go-hamt-ipld v0.1.5/go.mod h1:6Is+ONR5Cd5R6XZoCse1CWaXZc0Hdb/JeX+EQCQzX24= github.com/filecoin-project/go-hamt-ipld/v2 v2.0.0 h1:b3UDemBYN2HNfk3KOXNuxgTTxlWi3xVvbQP0IT38fvM= github.com/filecoin-project/go-hamt-ipld/v2 v2.0.0/go.mod h1:7aWZdaQ1b16BVoQUYR+eEvrDCGJoPLxFpDynFjYfBjI= -github.com/filecoin-project/go-jsonrpc v0.1.2-0.20201008195726-68c6a2704e49 h1:FSY245KeXFCUgyfFEu+bhrZNk8BGGJyfpSmQl2aiPU8= -github.com/filecoin-project/go-jsonrpc v0.1.2-0.20201008195726-68c6a2704e49/go.mod h1:XBBpuKIMaXIIzeqzO1iucq4GvbF8CxmXRFoezRh+Cx4= +github.com/filecoin-project/go-jsonrpc v0.1.2-0.20201116213214-f4b2d34247f0 h1:kCIWv46+RUz45DfQdBTaYOmduwN/iH4dghYDTcyCgg4= +github.com/filecoin-project/go-jsonrpc v0.1.2-0.20201116213214-f4b2d34247f0/go.mod h1:XBBpuKIMaXIIzeqzO1iucq4GvbF8CxmXRFoezRh+Cx4= github.com/filecoin-project/go-multistore v0.0.3 h1:vaRBY4YiA2UZFPK57RNuewypB8u0DzzQwqsL0XarpnI= github.com/filecoin-project/go-multistore v0.0.3/go.mod h1:kaNqCC4IhU4B1uyr7YWFHd23TL4KM32aChS0jNkyUvQ= github.com/filecoin-project/go-padreader v0.0.0-20200903213702-ed5fae088b20 h1:+/4aUeUoKr6AKfPE3mBhXA5spIV6UcKdTYDPNU2Tdmg= @@ -1542,12 +1542,16 @@ go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.4 h1:LYy1Hy3MJdrCdMwwzxA/dRok4ejH+RwNGbuoD9fCjto= go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= +go.opencensus.io v0.22.5 h1:dntmOdLpSpHlVqbW5Eay97DelsZHe+55D+xC6i0dDS0= +go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk= go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= go.uber.org/atomic v1.5.1/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= go.uber.org/atomic v1.6.0 h1:Ezj3JGmsOnG1MoRWQkPBsKLe9DwWD9QeXzTRzzldNVk= go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= +go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw= +go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/dig v1.10.0 h1:yLmDDj9/zuDjv3gz8GQGviXMs9TfysIUMUilCpgzUJY= go.uber.org/dig v1.10.0/go.mod h1:X34SnWGr8Fyla9zQNO2GSO2D+TIuqB14OS8JhYocIyw= go.uber.org/fx v1.9.0 h1:7OAz8ucp35AU8eydejpYG7QrbE8rLKzGhHbZlJi5LYY= @@ -1559,6 +1563,8 @@ go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+ go.uber.org/multierr v1.4.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4= go.uber.org/multierr v1.5.0 h1:KCa4XfM8CWFCpxXRGok+Q0SS/0XBhMDbHHGABQLvD2A= go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU= +go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4= +go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee h1:0mgffUl7nfd+FpvXMVz4IDEaUSmT1ysygQC7qYo7sG4= go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA= go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=