Skip to content

Commit

Permalink
Merge pull request OffchainLabs#2321 from emilianobonassi/das_http_li…
Browse files Browse the repository at this point in the history
…mits

feat(das): add support to configure http body limit
  • Loading branch information
Tristan-Wilson authored May 25, 2024
2 parents 7cda2b3 + 5931051 commit 3deb9ca
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 12 deletions.
13 changes: 8 additions & 5 deletions cmd/daserver/daserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ import (
)

type DAServerConfig struct {
EnableRPC bool `koanf:"enable-rpc"`
RPCAddr string `koanf:"rpc-addr"`
RPCPort uint64 `koanf:"rpc-port"`
RPCServerTimeouts genericconf.HTTPServerTimeoutConfig `koanf:"rpc-server-timeouts"`
EnableRPC bool `koanf:"enable-rpc"`
RPCAddr string `koanf:"rpc-addr"`
RPCPort uint64 `koanf:"rpc-port"`
RPCServerTimeouts genericconf.HTTPServerTimeoutConfig `koanf:"rpc-server-timeouts"`
RPCServerBodyLimit int `koanf:"rpc-server-body-limit"`

EnableREST bool `koanf:"enable-rest"`
RESTAddr string `koanf:"rest-addr"`
Expand All @@ -58,6 +59,7 @@ var DefaultDAServerConfig = DAServerConfig{
RPCAddr: "localhost",
RPCPort: 9876,
RPCServerTimeouts: genericconf.HTTPServerTimeoutConfigDefault,
RPCServerBodyLimit: genericconf.HTTPServerBodyLimitDefault,
EnableREST: false,
RESTAddr: "localhost",
RESTPort: 9877,
Expand Down Expand Up @@ -88,6 +90,7 @@ func parseDAServer(args []string) (*DAServerConfig, error) {
f.Bool("enable-rpc", DefaultDAServerConfig.EnableRPC, "enable the HTTP-RPC server listening on rpc-addr and rpc-port")
f.String("rpc-addr", DefaultDAServerConfig.RPCAddr, "HTTP-RPC server listening interface")
f.Uint64("rpc-port", DefaultDAServerConfig.RPCPort, "HTTP-RPC server listening port")
f.Int("rpc-server-body-limit", DefaultDAServerConfig.RPCServerBodyLimit, "HTTP-RPC server maximum request body size in bytes; the default (0) uses geth's 5MB limit")
genericconf.HTTPServerTimeoutConfigAddOptions("rpc-server-timeouts", f)

f.Bool("enable-rest", DefaultDAServerConfig.EnableREST, "enable the REST server listening on rest-addr and rest-port")
Expand Down Expand Up @@ -250,7 +253,7 @@ func startup() error {
if serverConfig.EnableRPC {
log.Info("Starting HTTP-RPC server", "addr", serverConfig.RPCAddr, "port", serverConfig.RPCPort, "revision", vcsRevision, "vcs.time", vcsTime)

rpcServer, err = das.StartDASRPCServer(ctx, serverConfig.RPCAddr, serverConfig.RPCPort, serverConfig.RPCServerTimeouts, daReader, daWriter, daHealthChecker)
rpcServer, err = das.StartDASRPCServer(ctx, serverConfig.RPCAddr, serverConfig.RPCPort, serverConfig.RPCServerTimeouts, serverConfig.RPCServerBodyLimit, daReader, daWriter, daHealthChecker)
if err != nil {
return err
}
Expand Down
2 changes: 2 additions & 0 deletions cmd/genericconf/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ var HTTPServerTimeoutConfigDefault = HTTPServerTimeoutConfig{
IdleTimeout: 120 * time.Second,
}

const HTTPServerBodyLimitDefault = 0 // Use default from go-ethereum

func (c HTTPConfig) Apply(stackConf *node.Config) {
stackConf.HTTPHost = c.Addr
stackConf.HTTPPort = c.Port
Expand Down
9 changes: 6 additions & 3 deletions das/dasRpcServer.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,22 @@ type DASRPCServer struct {
daHealthChecker DataAvailabilityServiceHealthChecker
}

func StartDASRPCServer(ctx context.Context, addr string, portNum uint64, rpcServerTimeouts genericconf.HTTPServerTimeoutConfig, daReader DataAvailabilityServiceReader, daWriter DataAvailabilityServiceWriter, daHealthChecker DataAvailabilityServiceHealthChecker) (*http.Server, error) {
func StartDASRPCServer(ctx context.Context, addr string, portNum uint64, rpcServerTimeouts genericconf.HTTPServerTimeoutConfig, rpcServerBodyLimit int, daReader DataAvailabilityServiceReader, daWriter DataAvailabilityServiceWriter, daHealthChecker DataAvailabilityServiceHealthChecker) (*http.Server, error) {
listener, err := net.Listen("tcp", fmt.Sprintf("%s:%d", addr, portNum))
if err != nil {
return nil, err
}
return StartDASRPCServerOnListener(ctx, listener, rpcServerTimeouts, daReader, daWriter, daHealthChecker)
return StartDASRPCServerOnListener(ctx, listener, rpcServerTimeouts, rpcServerBodyLimit, daReader, daWriter, daHealthChecker)
}

func StartDASRPCServerOnListener(ctx context.Context, listener net.Listener, rpcServerTimeouts genericconf.HTTPServerTimeoutConfig, daReader DataAvailabilityServiceReader, daWriter DataAvailabilityServiceWriter, daHealthChecker DataAvailabilityServiceHealthChecker) (*http.Server, error) {
func StartDASRPCServerOnListener(ctx context.Context, listener net.Listener, rpcServerTimeouts genericconf.HTTPServerTimeoutConfig, rpcServerBodyLimit int, daReader DataAvailabilityServiceReader, daWriter DataAvailabilityServiceWriter, daHealthChecker DataAvailabilityServiceHealthChecker) (*http.Server, error) {
if daWriter == nil {
return nil, errors.New("No writer backend was configured for DAS RPC server. Has the BLS signing key been set up (--data-availability.key.key-dir or --data-availability.key.priv-key options)?")
}
rpcServer := rpc.NewServer()
if rpcServerBodyLimit > 0 {
rpcServer.SetHTTPBodyLimit(rpcServerBodyLimit)
}
err := rpcServer.RegisterName("das", &DASRPCServer{
daReader: daReader,
daWriter: daWriter,
Expand Down
2 changes: 1 addition & 1 deletion das/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func TestRPC(t *testing.T) {
testhelpers.RequireImpl(t, err)
localDas, err := NewSignAfterStoreDASWriterWithSeqInboxCaller(privKey, nil, storageService, "")
testhelpers.RequireImpl(t, err)
dasServer, err := StartDASRPCServerOnListener(ctx, lis, genericconf.HTTPServerTimeoutConfigDefault, storageService, localDas, storageService)
dasServer, err := StartDASRPCServerOnListener(ctx, lis, genericconf.HTTPServerTimeoutConfigDefault, genericconf.HTTPServerBodyLimitDefault, storageService, localDas, storageService)
defer func() {
if err := dasServer.Shutdown(ctx); err != nil {
panic(err)
Expand Down
2 changes: 1 addition & 1 deletion system_tests/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1128,7 +1128,7 @@ func setupConfigWithDAS(
Require(t, err)
restLis, err := net.Listen("tcp", "localhost:0")
Require(t, err)
_, err = das.StartDASRPCServerOnListener(ctx, rpcLis, genericconf.HTTPServerTimeoutConfigDefault, daReader, daWriter, daHealthChecker)
_, err = das.StartDASRPCServerOnListener(ctx, rpcLis, genericconf.HTTPServerTimeoutConfigDefault, genericconf.HTTPServerBodyLimitDefault, daReader, daWriter, daHealthChecker)
Require(t, err)
_, err = das.NewRestfulDasServerOnListener(restLis, genericconf.HTTPServerTimeoutConfigDefault, daReader, daHealthChecker)
Require(t, err)
Expand Down
4 changes: 2 additions & 2 deletions system_tests/das_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func startLocalDASServer(
Require(t, err)
rpcLis, err := net.Listen("tcp", "localhost:0")
Require(t, err)
rpcServer, err := das.StartDASRPCServerOnListener(ctx, rpcLis, genericconf.HTTPServerTimeoutConfigDefault, storageService, daWriter, storageService)
rpcServer, err := das.StartDASRPCServerOnListener(ctx, rpcLis, genericconf.HTTPServerTimeoutConfigDefault, genericconf.HTTPServerBodyLimitDefault, storageService, daWriter, storageService)
Require(t, err)
restLis, err := net.Listen("tcp", "localhost:0")
Require(t, err)
Expand Down Expand Up @@ -284,7 +284,7 @@ func TestDASComplexConfigAndRestMirror(t *testing.T) {
defer lifecycleManager.StopAndWaitUntil(time.Second)
rpcLis, err := net.Listen("tcp", "localhost:0")
Require(t, err)
_, err = das.StartDASRPCServerOnListener(ctx, rpcLis, genericconf.HTTPServerTimeoutConfigDefault, daReader, daWriter, daHealthChecker)
_, err = das.StartDASRPCServerOnListener(ctx, rpcLis, genericconf.HTTPServerTimeoutConfigDefault, genericconf.HTTPServerBodyLimitDefault, daReader, daWriter, daHealthChecker)
Require(t, err)
restLis, err := net.Listen("tcp", "localhost:0")
Require(t, err)
Expand Down

0 comments on commit 3deb9ca

Please sign in to comment.