From 5c91be3f57531ef99389249f198246da975f10d7 Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Wed, 12 Aug 2020 15:45:57 -0700 Subject: [PATCH] config+rpcserver: allow configurable defualt-remote-max-htlcs --- config.go | 18 ++++++++++++++++++ lntest/itest/lnd_test.go | 20 +++++++++++++++----- server.go | 4 ++++ 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/config.go b/config.go index 8713aa8f..7df5adcd 100644 --- a/config.go +++ b/config.go @@ -27,6 +27,7 @@ import ( "github.com/lightningnetwork/lnd/discovery" "github.com/lightningnetwork/lnd/htlcswitch" "github.com/lightningnetwork/lnd/htlcswitch/hodl" + "github.com/lightningnetwork/lnd/input" "github.com/lightningnetwork/lnd/lncfg" "github.com/lightningnetwork/lnd/lnrpc/routerrpc" "github.com/lightningnetwork/lnd/lnrpc/signrpc" @@ -101,6 +102,11 @@ const ( defaultDiskTimeout = time.Second * 5 defaultDiskBackoff = time.Minute defaultDiskAttempts = 2 + + // defaultRemoteMaxHtlcs specifies the default limit for maximum + // concurrent HTLCs the remote party may add to commitment transactions. + // This value can be overridden with --default-remote-max-htlcs. + defaultRemoteMaxHtlcs = 483 ) var ( @@ -235,6 +241,8 @@ type Config struct { Color string `long:"color" description:"The color of the node in hex format (i.e. '#3399FF'). Used to customize node appearance in intelligence services"` MinChanSize int64 `long:"minchansize" description:"The smallest channel size (in satoshis) that we should accept. Incoming channels smaller than this will be rejected"` + DefaultRemoteMaxHtlcs uint16 `long:"default-remote-max-htlcs" description:"The default max_htlc applied when opening or accepting channels. This value limits the number of concurrent HTLCs that the remote party can add to the commitment. The maximum possible value is 483."` + NumGraphSyncPeers int `long:"numgraphsyncpeers" description:"The number of peers that we should receive new graph updates from. This option can be tuned to save bandwidth for light clients or routing nodes."` HistoricalSyncInterval time.Duration `long:"historicalsyncinterval" description:"The polling interval between historical graph sync attempts. Each historical graph sync attempt ensures we reconcile with the remote peer's graph from the genesis block."` @@ -379,6 +387,7 @@ func DefaultConfig() Config { Alias: defaultAlias, Color: defaultColor, MinChanSize: int64(minChanFundingSize), + DefaultRemoteMaxHtlcs: defaultRemoteMaxHtlcs, NumGraphSyncPeers: defaultMinPeers, HistoricalSyncInterval: discovery.DefaultHistoricalSyncInterval, Tor: &lncfg.Tor{ @@ -1152,6 +1161,15 @@ func ValidateConfig(cfg Config, usageMessage string) (*Config, error) { cfg.DB.Bolt.SyncFreelist = cfg.SyncFreelist } + // Ensure that the user hasn't chosen a remote-max-htlc value greater + // than the protocol maximum. + maxRemoteHtlcs := uint16(input.MaxHTLCNumber / 2) + if cfg.DefaultRemoteMaxHtlcs > maxRemoteHtlcs { + return nil, fmt.Errorf("default-remote-max-htlcs (%v) must be "+ + "less than %v", cfg.DefaultRemoteMaxHtlcs, + maxRemoteHtlcs) + } + // Validate the subconfigs for workers, caches, and the tower client. err = lncfg.Validate( cfg.Workers, diff --git a/lntest/itest/lnd_test.go b/lntest/itest/lnd_test.go index 6440ea61..864e3345 100644 --- a/lntest/itest/lnd_test.go +++ b/lntest/itest/lnd_test.go @@ -4844,14 +4844,21 @@ func assertChannelConstraintsEqual( func testListChannels(net *lntest.NetworkHarness, t *harnessTest) { ctxb := context.Background() + const aliceRemoteMaxHtlcs = 50 + const bobRemoteMaxHtlcs = 100 + // Create two fresh nodes and open a channel between them. - alice, err := net.NewNode("Alice", nil) + alice, err := net.NewNode("Alice", []string{ + fmt.Sprintf("--default-remote-max-htlcs=%v", aliceRemoteMaxHtlcs), + }) if err != nil { t.Fatalf("unable to create new node: %v", err) } defer shutdownAndAssert(net, t, alice) - bob, err := net.NewNode("Bob", nil) + bob, err := net.NewNode("Bob", []string{ + fmt.Sprintf("--default-remote-max-htlcs=%v", bobRemoteMaxHtlcs), + }) if err != nil { t.Fatalf("unable to create new node: %v", err) } @@ -4927,7 +4934,7 @@ func testListChannels(net *lntest.NetworkHarness, t *harnessTest) { DustLimitSat: uint64(lnwallet.DefaultDustLimit()), MaxPendingAmtMsat: 99000000, MinHtlcMsat: 1, - MaxAcceptedHtlcs: input.MaxHTLCNumber / 2, + MaxAcceptedHtlcs: bobRemoteMaxHtlcs, } assertChannelConstraintsEqual( t, defaultConstraints, aliceChannel.LocalConstraints, @@ -4943,7 +4950,7 @@ func testListChannels(net *lntest.NetworkHarness, t *harnessTest) { DustLimitSat: uint64(lnwallet.DefaultDustLimit()), MaxPendingAmtMsat: 99000000, MinHtlcMsat: customizedMinHtlc, - MaxAcceptedHtlcs: input.MaxHTLCNumber / 2, + MaxAcceptedHtlcs: aliceRemoteMaxHtlcs, } assertChannelConstraintsEqual( t, customizedConstraints, aliceChannel.RemoteConstraints, @@ -14452,7 +14459,10 @@ func TestLightningNetworkDaemon(t *testing.T) { // initialization of the network. args - list of lnd arguments, // example: "--debuglevel=debug" // TODO(roasbeef): create master balanced channel with all the monies? - if err = lndHarness.SetUp(nil); err != nil { + aliceBobArgs := []string{ + "--default-remote-max-htlcs=483", + } + if err = lndHarness.SetUp(aliceBobArgs); err != nil { ht.Fatalf("unable to set up test lightning network: %v", err) } diff --git a/server.go b/server.go index e1ef0c68..cba47e39 100644 --- a/server.go +++ b/server.go @@ -1156,6 +1156,10 @@ func newServer(cfg *Config, listenAddrs []net.Addr, return lnwire.NewMSatFromSatoshis(chanAmt) - reserve }, RequiredRemoteMaxHTLCs: func(chanAmt btcutil.Amount) uint16 { + if cfg.DefaultRemoteMaxHtlcs > 0 { + return cfg.DefaultRemoteMaxHtlcs + } + // By default, we'll permit them to utilize the full // channel bandwidth. return uint16(input.MaxHTLCNumber / 2)