diff --git a/chainregistry.go b/chainregistry.go index 005aa106..c2deb6f3 100644 --- a/chainregistry.go +++ b/chainregistry.go @@ -44,6 +44,10 @@ const ( defaultLitecoinTimeLockDelta = 576 defaultLitecoinStaticFeeRate = lnwallet.SatPerVByte(200) defaultLitecoinDustLimit = btcutil.Amount(54600) + + // btcToLtcConversionRate is a fixed ratio used in order to scale up + // payments when running on the Litecoin chain. + btcToLtcConversionRate = 60 ) // defaultBtcChannelConstraints is the default set of channel constraints that are diff --git a/config.go b/config.go index 0ac2f39f..4ed9fed9 100644 --- a/config.go +++ b/config.go @@ -353,42 +353,6 @@ func loadConfig() (*config, error) { cfg.BitcoindMode.Dir = cleanAndExpandPath(cfg.BitcoindMode.Dir) cfg.LitecoindMode.Dir = cleanAndExpandPath(cfg.LitecoindMode.Dir) - // Ensure that the user didn't attempt to specify negative values for - // any of the autopilot params. - if cfg.Autopilot.MaxChannels < 0 { - str := "%s: autopilot.maxchannels must be non-negative" - err := fmt.Errorf(str, funcName) - fmt.Fprintln(os.Stderr, err) - return nil, err - } - if cfg.Autopilot.Allocation < 0 { - str := "%s: autopilot.allocation must be non-negative" - err := fmt.Errorf(str, funcName) - fmt.Fprintln(os.Stderr, err) - return nil, err - } - if cfg.Autopilot.MinChannelSize < 0 { - str := "%s: autopilot.minchansize must be non-negative" - err := fmt.Errorf(str, funcName) - fmt.Fprintln(os.Stderr, err) - return nil, err - } - if cfg.Autopilot.MaxChannelSize < 0 { - str := "%s: autopilot.maxchansize must be non-negative" - err := fmt.Errorf(str, funcName) - fmt.Fprintln(os.Stderr, err) - return nil, err - } - - // Ensure that the specified values for the min and max channel size - // don't are within the bounds of the normal chan size constraints. - if cfg.Autopilot.MinChannelSize < int64(minChanFundingSize) { - cfg.Autopilot.MinChannelSize = int64(minChanFundingSize) - } - if cfg.Autopilot.MaxChannelSize > int64(maxFundingAmount) { - cfg.Autopilot.MaxChannelSize = int64(maxFundingAmount) - } - // Setup dial and DNS resolution functions depending on the specified // options. The default is to use the standard golang "net" package // functions. When Tor's proxy is specified, the dial function is set to @@ -533,6 +497,8 @@ func loadConfig() (*config, error) { // Finally we'll register the litecoin chain as our current // primary chain. registeredChains.RegisterPrimaryChain(litecoinChain) + maxFundingAmount = maxLtcFundingAmount + maxPaymentMSat = maxLtcPaymentMSat case cfg.Bitcoin.Active: // Multiple networks can't be selected simultaneously. Count @@ -626,6 +592,42 @@ func loadConfig() (*config, error) { registeredChains.RegisterPrimaryChain(bitcoinChain) } + // Ensure that the user didn't attempt to specify negative values for + // any of the autopilot params. + if cfg.Autopilot.MaxChannels < 0 { + str := "%s: autopilot.maxchannels must be non-negative" + err := fmt.Errorf(str, funcName) + fmt.Fprintln(os.Stderr, err) + return nil, err + } + if cfg.Autopilot.Allocation < 0 { + str := "%s: autopilot.allocation must be non-negative" + err := fmt.Errorf(str, funcName) + fmt.Fprintln(os.Stderr, err) + return nil, err + } + if cfg.Autopilot.MinChannelSize < 0 { + str := "%s: autopilot.minchansize must be non-negative" + err := fmt.Errorf(str, funcName) + fmt.Fprintln(os.Stderr, err) + return nil, err + } + if cfg.Autopilot.MaxChannelSize < 0 { + str := "%s: autopilot.maxchansize must be non-negative" + err := fmt.Errorf(str, funcName) + fmt.Fprintln(os.Stderr, err) + return nil, err + } + + // Ensure that the specified values for the min and max channel size + // don't are within the bounds of the normal chan size constraints. + if cfg.Autopilot.MinChannelSize < int64(minChanFundingSize) { + cfg.Autopilot.MinChannelSize = int64(minChanFundingSize) + } + if cfg.Autopilot.MaxChannelSize > int64(maxFundingAmount) { + cfg.Autopilot.MaxChannelSize = int64(maxFundingAmount) + } + // Validate profile port number. if cfg.Profile != "" { profilePort, err := strconv.Atoi(cfg.Profile) diff --git a/fundingmanager.go b/fundingmanager.go index 29f12c00..24f2cdba 100644 --- a/fundingmanager.go +++ b/fundingmanager.go @@ -33,15 +33,6 @@ const ( // TODO(roasbeef): tune msgBufferSize = 50 - // maxFundingAmount is a soft-limit of the maximum channel size - // accepted within the Lightning Protocol Currently. This limit is - // currently defined in BOLT-0002, and serves as an initial - // precautionary limit while implementations are battle tested in the - // real world. - // - // TODO(roasbeef): add command line param to modify - maxFundingAmount = btcutil.Amount(1 << 24) - // minBtcRemoteDelay and maxBtcRemoteDelay is the extremes of the // Bitcoin CSV delay we will require the remote to use for its // commitment transaction. The actual delay we will require will be @@ -64,6 +55,31 @@ const ( // minChanFundingSize is the smallest channel that we'll allow to be // created over the RPC interface. minChanFundingSize = btcutil.Amount(20000) + + // maxBtcFundingAmount is a soft-limit of the maximum channel size + // currently accepted on the Bitcoin chain within the Lightning + // Protocol. This limit is defined in BOLT-0002, and serves as an + // initial precautionary limit while implementations are battle tested + // in the real world. + maxBtcFundingAmount = btcutil.Amount(1<<24) - 1 + + // maxLtcFundingAmount is a soft-limit of the maximum channel size + // currently accepted on the Litecoin chain within the Lightning + // Protocol. + maxLtcFundingAmount = maxBtcFundingAmount * btcToLtcConversionRate +) + +var ( + // maxFundingAmount is a soft-limit of the maximum channel size + // currently accepted within the Lightning Protocol. This limit is + // defined in BOLT-0002, and serves as an initial precautionary limit + // while implementations are battle tested in the real world. + // + // At the moment, this value depends on which chain is active. It is set + // to the value under the Bitcoin chain as default. + // + // TODO(roasbeef): add command line param to modify + maxFundingAmount = maxBtcFundingAmount ) // reservationWithCtx encapsulates a pending channel reservation. This wrapper diff --git a/lnd_test.go b/lnd_test.go index 6caab8d8..68ba2201 100644 --- a/lnd_test.go +++ b/lnd_test.go @@ -623,7 +623,7 @@ func testBasicChannelFunding(net *lntest.NetworkHarness, t *harnessTest) { timeout := time.Duration(time.Second * 5) ctxb := context.Background() - chanAmt := maxFundingAmount + chanAmt := maxBtcFundingAmount pushAmt := btcutil.Amount(100000) // First establish a channel with a capacity of 0.5 BTC between Alice @@ -688,7 +688,7 @@ func testUpdateChannelPolicy(net *lntest.NetworkHarness, t *harnessTest) { bobUpdates, bQuit := subscribeGraphNotifications(t, ctxb, net.Bob) defer close(bQuit) - chanAmt := maxFundingAmount + chanAmt := maxBtcFundingAmount pushAmt := btcutil.Amount(100000) // Create a channel Alice->Bob. @@ -1057,7 +1057,7 @@ func testOpenChannelAfterReorg(net *lntest.NetworkHarness, t *harnessTest) { // Create a new channel that requires 1 confs before it's considered // open, then broadcast the funding transaction - chanAmt := maxFundingAmount + chanAmt := maxBtcFundingAmount pushAmt := btcutil.Amount(0) ctxt, _ := context.WithTimeout(ctxb, timeout) pendingUpdate, err := net.OpenPendingChannel(ctxt, net.Alice, net.Bob, @@ -1193,7 +1193,7 @@ func testDisconnectingTargetPeer(net *lntest.NetworkHarness, t *harnessTest) { // Check existing connection. assertNumConnections(ctxb, t, net.Alice, net.Bob, 1) - chanAmt := maxFundingAmount + chanAmt := maxBtcFundingAmount pushAmt := btcutil.Amount(0) timeout := time.Duration(time.Second * 10) @@ -1329,7 +1329,7 @@ func testDisconnectingTargetPeer(net *lntest.NetworkHarness, t *harnessTest) { func testChannelFundingPersistence(net *lntest.NetworkHarness, t *harnessTest) { ctxb := context.Background() - chanAmt := maxFundingAmount + chanAmt := maxBtcFundingAmount pushAmt := btcutil.Amount(0) timeout := time.Duration(time.Second * 10) @@ -1463,7 +1463,7 @@ func testChannelBalance(net *lntest.NetworkHarness, t *harnessTest) { // Open a channel with 0.16 BTC between Alice and Bob, ensuring the // channel has been opened properly. - amount := maxFundingAmount + amount := maxBtcFundingAmount ctx, _ := context.WithTimeout(context.Background(), timeout) // Creates a helper closure to be used below which asserts the proper @@ -3848,7 +3848,7 @@ func testBasicChannelCreation(net *lntest.NetworkHarness, t *harnessTest) { const ( numChannels = 2 timeout = time.Duration(time.Second * 5) - amount = maxFundingAmount + amount = maxBtcFundingAmount ) // Open the channel between Alice and Bob, asserting that the @@ -3874,7 +3874,7 @@ func testBasicChannelCreation(net *lntest.NetworkHarness, t *harnessTest) { // exists and works properly. func testMaxPendingChannels(net *lntest.NetworkHarness, t *harnessTest) { maxPendingChannels := defaultMaxPendingChannels + 1 - amount := maxFundingAmount + amount := maxBtcFundingAmount timeout := time.Duration(time.Second * 10) ctx, _ := context.WithTimeout(context.Background(), timeout) @@ -4253,7 +4253,7 @@ func testRevokedCloseRetribution(net *lntest.NetworkHarness, t *harnessTest) { ctxb := context.Background() const ( timeout = time.Duration(time.Second * 10) - chanAmt = maxFundingAmount + chanAmt = maxBtcFundingAmount paymentAmt = 10000 numInvoices = 6 ) @@ -4499,7 +4499,7 @@ func testRevokedCloseRetributionZeroValueRemoteOutput(net *lntest.NetworkHarness ctxb := context.Background() const ( timeout = time.Duration(time.Second * 10) - chanAmt = maxFundingAmount + chanAmt = maxBtcFundingAmount paymentAmt = 10000 numInvoices = 6 ) @@ -4731,7 +4731,7 @@ func testRevokedCloseRetributionRemoteHodl(net *lntest.NetworkHarness, ctxb := context.Background() const ( timeout = time.Duration(time.Second * 10) - chanAmt = maxFundingAmount + chanAmt = maxBtcFundingAmount pushAmt = 200000 paymentAmt = 10000 numInvoices = 6 @@ -4768,7 +4768,7 @@ func testRevokedCloseRetributionRemoteHodl(net *lntest.NetworkHarness, // In order to test Dave's response to an uncooperative channel closure // by Carol, we'll first open up a channel between them with a - // maxFundingAmount (2^24) satoshis value. + // maxBtcFundingAmount (2^24) satoshis value. ctxt, _ := context.WithTimeout(ctxb, timeout) chanPoint := openChannelAndAssert( ctxt, t, net, dave, carol, chanAmt, pushAmt, false, @@ -5163,7 +5163,7 @@ func testHtlcErrorPropagation(net *lntest.NetworkHarness, t *harnessTest) { timeout := time.Duration(time.Second * 15) ctxb := context.Background() - const chanAmt = maxFundingAmount + const chanAmt = maxBtcFundingAmount // First establish a channel with a capacity of 0.5 BTC between Alice // and Bob. @@ -5212,7 +5212,7 @@ func testHtlcErrorPropagation(net *lntest.NetworkHarness, t *harnessTest) { t.Fatalf("unable to connect bob to carol: %v", err) } ctxt, _ = context.WithTimeout(ctxb, timeout) - const bobChanAmt = maxFundingAmount + const bobChanAmt = maxBtcFundingAmount chanPointBob := openChannelAndAssert( ctxt, t, net, net.Bob, carol, chanAmt, 0, false, ) @@ -5493,7 +5493,7 @@ func subscribeGraphNotifications(t *harnessTest, ctxb context.Context, } func testGraphTopologyNotifications(net *lntest.NetworkHarness, t *harnessTest) { - const chanAmt = maxFundingAmount + const chanAmt = maxBtcFundingAmount timeout := time.Duration(time.Second * 5) ctxb := context.Background() @@ -5777,7 +5777,7 @@ func testNodeSignVerify(net *lntest.NetworkHarness, t *harnessTest) { timeout := time.Duration(time.Second * 15) ctxb := context.Background() - chanAmt := maxFundingAmount + chanAmt := maxBtcFundingAmount pushAmt := btcutil.Amount(100000) // Create a channel between alice and bob. diff --git a/rpcserver.go b/rpcserver.go index 59ce3af4..7aa1a2f9 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -39,7 +39,23 @@ import ( "golang.org/x/net/context" ) +const ( + // maxBtcPaymentMSat is the maximum allowed Bitcoin payment currently + // permitted as defined in BOLT-0002. + maxBtcPaymentMSat = lnwire.MilliSatoshi(math.MaxUint32) + + // maxLtcPaymentMSat is the maximum allowed Litecoin payment currently + // permitted. + maxLtcPaymentMSat = lnwire.MilliSatoshi(math.MaxUint32) * + btcToLtcConversionRate +) + var ( + // maxPaymentMSat is the maximum allowed payment currently permitted as + // defined in BOLT-002. This value depends on which chain is active. + // It is set to the value under the Bitcoin chain as default. + maxPaymentMSat = maxBtcPaymentMSat + defaultAccount uint32 = waddrmgr.DefaultAccountNum // readPermissions is a slice of all entities that allow read @@ -300,12 +316,6 @@ var ( } ) -const ( - // maxPaymentMSat is the maximum allowed payment permitted currently as - // defined in BOLT-0002. - maxPaymentMSat = lnwire.MilliSatoshi(math.MaxUint32) -) - // rpcServer is a gRPC, RPC front end to the lnd daemon. // TODO(roasbeef): pagination support for the list-style calls type rpcServer struct {