Skip to content

Commit

Permalink
multi: unify gRPC max receive size
Browse files Browse the repository at this point in the history
Fixes lightninglabs#608.

This commit makes sure we use the same constant for the gRPC receive
message size limit everywhere.
If we ever need to bump this to a higher value, we can just edit it in a
single place.
  • Loading branch information
guggero committed Oct 23, 2023
1 parent be466b1 commit 7c18015
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 19 deletions.
7 changes: 1 addition & 6 deletions cmd/tapcli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
wrpc "github.com/lightninglabs/taproot-assets/taprpc/assetwalletrpc"
"github.com/lightninglabs/taproot-assets/taprpc/mintrpc"
"github.com/lightningnetwork/lnd/lncfg"
"github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/macaroons"
"github.com/lightningnetwork/lnd/tor"
"github.com/urfave/cli"
Expand Down Expand Up @@ -49,10 +48,6 @@ const (
var (
defaultTapdDir = btcutil.AppDataDir("tapd", false)
defaultTLSCertPath = filepath.Join(defaultTapdDir, defaultTLSCertFilename)

// maxMsgRecvSize is the largest message our client will receive. We
// set this to 200MiB atm.
maxMsgRecvSize = grpc.MaxCallRecvMsgSize(lnrpc.MaxGrpcMsgSize)
)

func fatal(err error) {
Expand Down Expand Up @@ -202,7 +197,7 @@ func getClientConn(ctx *cli.Context, skipMacaroons bool) *grpc.ClientConn {
opts = append(opts, grpc.WithContextDialer(genericDialer))
}

opts = append(opts, grpc.WithDefaultCallOptions(maxMsgRecvSize))
opts = append(opts, grpc.WithDefaultCallOptions(tap.MaxMsgReceiveSize))

conn, err := grpc.Dial(profile.RPCServer, opts...)
if err != nil {
Expand Down
8 changes: 2 additions & 6 deletions itest/loadtest/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import (
"time"

"github.com/btcsuite/btcd/rpcclient"
tap "github.com/lightninglabs/taproot-assets"
"github.com/lightninglabs/taproot-assets/itest"
"github.com/lightninglabs/taproot-assets/taprpc"
"github.com/lightninglabs/taproot-assets/taprpc/assetwalletrpc"
"github.com/lightninglabs/taproot-assets/taprpc/mintrpc"
"github.com/lightninglabs/taproot-assets/taprpc/universerpc"
"github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/macaroons"
"github.com/stretchr/testify/require"
"google.golang.org/grpc"
Expand All @@ -26,10 +26,6 @@ import (
)

var (
// maxMsgRecvSize is the largest message our client will receive. We
// set this to 200MiB atm.
maxMsgRecvSize = grpc.MaxCallRecvMsgSize(lnrpc.MaxGrpcMsgSize)

// defaultTimeout is a timeout that will be used for various wait
// scenarios where no custom timeout value is defined.
defaultTimeout = time.Second * 10
Expand Down Expand Up @@ -147,7 +143,7 @@ func getTapClient(t *testing.T, ctx context.Context,
// Create a dial options array.
opts := []grpc.DialOption{
grpc.WithTransportCredentials(creds),
grpc.WithDefaultCallOptions(maxMsgRecvSize),
grpc.WithDefaultCallOptions(tap.MaxMsgReceiveSize),
}

if cfg.MacPath != "" {
Expand Down
2 changes: 1 addition & 1 deletion itest/tapd_harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ func defaultDialOptions(serverCertPath, macaroonPath string) ([]grpc.DialOption,
Backoff: backoff.DefaultConfig,
MinConnectTimeout: 10 * time.Second,
}),
grpc.WithMaxMsgSize(lnrpc.MaxGrpcMsgSize),
grpc.WithDefaultCallOptions(tap.MaxMsgReceiveSize),
}

if serverCertPath != "" {
Expand Down
11 changes: 11 additions & 0 deletions rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,22 @@ import (
"github.com/lightninglabs/taproot-assets/universe"
"github.com/lightningnetwork/lnd/build"
"github.com/lightningnetwork/lnd/keychain"
"github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
"github.com/lightningnetwork/lnd/signal"
"google.golang.org/grpc"
)

var (
// MaxMsgReceiveSize is the largest message our client will receive. We
// set this to 200MiB atm.
MaxMsgReceiveSize = grpc.MaxCallRecvMsgSize(lnrpc.MaxGrpcMsgSize)

// ServerMaxMsgReceiveSize is the largest message our server will
// receive.
ServerMaxMsgReceiveSize = grpc.MaxRecvMsgSize(lnrpc.MaxGrpcMsgSize)
)

const (
// tapdMacaroonLocation is the value we use for the tapd macaroons'
// "Location" field when baking them.
Expand Down
4 changes: 1 addition & 3 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,7 @@ func (s *Server) RunUntilShutdown(mainErrChan <-chan error) error {
},
)
serverOpts = append(serverOpts, rpcServerOpts...)
serverOpts = append(
serverOpts, grpc.MaxRecvMsgSize(lnrpc.MaxGrpcMsgSize),
)
serverOpts = append(serverOpts, ServerMaxMsgReceiveSize)

grpcServer := grpc.NewServer(serverOpts...)
defer grpcServer.Stop()
Expand Down
4 changes: 1 addition & 3 deletions tapcfg/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -797,9 +797,7 @@ func getTLSConfig(cfg *Config,
// in cmd/tapcli/main.go.
restDialOpts := []grpc.DialOption{
grpc.WithTransportCredentials(restCreds),
grpc.WithDefaultCallOptions(
grpc.MaxCallRecvMsgSize(lnrpc.MaxGrpcMsgSize),
),
grpc.WithDefaultCallOptions(tap.MaxMsgReceiveSize),
}

// Return a function closure that can be used to listen on a given
Expand Down
1 change: 1 addition & 0 deletions universe_rpc_registrar.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ func ConnectUniverse(
// Create a dial options array.
opts := []grpc.DialOption{
grpc.WithTransportCredentials(creds),
grpc.WithDefaultCallOptions(MaxMsgReceiveSize),
}

uniAddr, err := serverAddr.Addr()
Expand Down

0 comments on commit 7c18015

Please sign in to comment.