config+rpcserver: allow configurable defualt-remote-max-htlcs
This commit is contained in:
parent
1760fe30db
commit
5c91be3f57
18
config.go
18
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,
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user