config+rpcserver: allow configurable defualt-remote-max-htlcs

This commit is contained in:
Conner Fromknecht 2020-08-12 15:45:57 -07:00
parent 1760fe30db
commit 5c91be3f57
No known key found for this signature in database
GPG Key ID: E7D737B67FA592C7
3 changed files with 37 additions and 5 deletions

@ -27,6 +27,7 @@ import (
"github.com/lightningnetwork/lnd/discovery" "github.com/lightningnetwork/lnd/discovery"
"github.com/lightningnetwork/lnd/htlcswitch" "github.com/lightningnetwork/lnd/htlcswitch"
"github.com/lightningnetwork/lnd/htlcswitch/hodl" "github.com/lightningnetwork/lnd/htlcswitch/hodl"
"github.com/lightningnetwork/lnd/input"
"github.com/lightningnetwork/lnd/lncfg" "github.com/lightningnetwork/lnd/lncfg"
"github.com/lightningnetwork/lnd/lnrpc/routerrpc" "github.com/lightningnetwork/lnd/lnrpc/routerrpc"
"github.com/lightningnetwork/lnd/lnrpc/signrpc" "github.com/lightningnetwork/lnd/lnrpc/signrpc"
@ -101,6 +102,11 @@ const (
defaultDiskTimeout = time.Second * 5 defaultDiskTimeout = time.Second * 5
defaultDiskBackoff = time.Minute defaultDiskBackoff = time.Minute
defaultDiskAttempts = 2 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 ( 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"` 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"` 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."` 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."` 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, Alias: defaultAlias,
Color: defaultColor, Color: defaultColor,
MinChanSize: int64(minChanFundingSize), MinChanSize: int64(minChanFundingSize),
DefaultRemoteMaxHtlcs: defaultRemoteMaxHtlcs,
NumGraphSyncPeers: defaultMinPeers, NumGraphSyncPeers: defaultMinPeers,
HistoricalSyncInterval: discovery.DefaultHistoricalSyncInterval, HistoricalSyncInterval: discovery.DefaultHistoricalSyncInterval,
Tor: &lncfg.Tor{ Tor: &lncfg.Tor{
@ -1152,6 +1161,15 @@ func ValidateConfig(cfg Config, usageMessage string) (*Config, error) {
cfg.DB.Bolt.SyncFreelist = cfg.SyncFreelist 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. // Validate the subconfigs for workers, caches, and the tower client.
err = lncfg.Validate( err = lncfg.Validate(
cfg.Workers, cfg.Workers,

@ -4844,14 +4844,21 @@ func assertChannelConstraintsEqual(
func testListChannels(net *lntest.NetworkHarness, t *harnessTest) { func testListChannels(net *lntest.NetworkHarness, t *harnessTest) {
ctxb := context.Background() ctxb := context.Background()
const aliceRemoteMaxHtlcs = 50
const bobRemoteMaxHtlcs = 100
// Create two fresh nodes and open a channel between them. // 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 { if err != nil {
t.Fatalf("unable to create new node: %v", err) t.Fatalf("unable to create new node: %v", err)
} }
defer shutdownAndAssert(net, t, alice) 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 { if err != nil {
t.Fatalf("unable to create new node: %v", err) t.Fatalf("unable to create new node: %v", err)
} }
@ -4927,7 +4934,7 @@ func testListChannels(net *lntest.NetworkHarness, t *harnessTest) {
DustLimitSat: uint64(lnwallet.DefaultDustLimit()), DustLimitSat: uint64(lnwallet.DefaultDustLimit()),
MaxPendingAmtMsat: 99000000, MaxPendingAmtMsat: 99000000,
MinHtlcMsat: 1, MinHtlcMsat: 1,
MaxAcceptedHtlcs: input.MaxHTLCNumber / 2, MaxAcceptedHtlcs: bobRemoteMaxHtlcs,
} }
assertChannelConstraintsEqual( assertChannelConstraintsEqual(
t, defaultConstraints, aliceChannel.LocalConstraints, t, defaultConstraints, aliceChannel.LocalConstraints,
@ -4943,7 +4950,7 @@ func testListChannels(net *lntest.NetworkHarness, t *harnessTest) {
DustLimitSat: uint64(lnwallet.DefaultDustLimit()), DustLimitSat: uint64(lnwallet.DefaultDustLimit()),
MaxPendingAmtMsat: 99000000, MaxPendingAmtMsat: 99000000,
MinHtlcMsat: customizedMinHtlc, MinHtlcMsat: customizedMinHtlc,
MaxAcceptedHtlcs: input.MaxHTLCNumber / 2, MaxAcceptedHtlcs: aliceRemoteMaxHtlcs,
} }
assertChannelConstraintsEqual( assertChannelConstraintsEqual(
t, customizedConstraints, aliceChannel.RemoteConstraints, t, customizedConstraints, aliceChannel.RemoteConstraints,
@ -14452,7 +14459,10 @@ func TestLightningNetworkDaemon(t *testing.T) {
// initialization of the network. args - list of lnd arguments, // initialization of the network. args - list of lnd arguments,
// example: "--debuglevel=debug" // example: "--debuglevel=debug"
// TODO(roasbeef): create master balanced channel with all the monies? // 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) ht.Fatalf("unable to set up test lightning network: %v", err)
} }

@ -1156,6 +1156,10 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
return lnwire.NewMSatFromSatoshis(chanAmt) - reserve return lnwire.NewMSatFromSatoshis(chanAmt) - reserve
}, },
RequiredRemoteMaxHTLCs: func(chanAmt btcutil.Amount) uint16 { RequiredRemoteMaxHTLCs: func(chanAmt btcutil.Amount) uint16 {
if cfg.DefaultRemoteMaxHtlcs > 0 {
return cfg.DefaultRemoteMaxHtlcs
}
// By default, we'll permit them to utilize the full // By default, we'll permit them to utilize the full
// channel bandwidth. // channel bandwidth.
return uint16(input.MaxHTLCNumber / 2) return uint16(input.MaxHTLCNumber / 2)