multi: move and export funding-related vars to funding package

Also moves the lnd global MaxFundingAmount to server.go
This commit is contained in:
eugene 2020-11-16 18:28:56 -05:00
parent f6524aabcb
commit caa0f5da6a
11 changed files with 112 additions and 101 deletions

@ -27,6 +27,7 @@ import (
"github.com/lightningnetwork/lnd/chanbackup" "github.com/lightningnetwork/lnd/chanbackup"
"github.com/lightningnetwork/lnd/channeldb" "github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/discovery" "github.com/lightningnetwork/lnd/discovery"
"github.com/lightningnetwork/lnd/funding"
"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/input"
@ -413,7 +414,7 @@ func DefaultConfig() Config {
Autopilot: &lncfg.AutoPilot{ Autopilot: &lncfg.AutoPilot{
MaxChannels: 5, MaxChannels: 5,
Allocation: 0.6, Allocation: 0.6,
MinChannelSize: int64(minChanFundingSize), MinChannelSize: int64(funding.MinChanFundingSize),
MaxChannelSize: int64(MaxFundingAmount), MaxChannelSize: int64(MaxFundingAmount),
MinConfs: 1, MinConfs: 1,
ConfTarget: autopilot.DefaultConfTarget, ConfTarget: autopilot.DefaultConfTarget,
@ -429,7 +430,7 @@ func DefaultConfig() Config {
HeightHintCacheQueryDisable: defaultHeightHintCacheQueryDisable, HeightHintCacheQueryDisable: defaultHeightHintCacheQueryDisable,
Alias: defaultAlias, Alias: defaultAlias,
Color: defaultColor, Color: defaultColor,
MinChanSize: int64(minChanFundingSize), MinChanSize: int64(funding.MinChanFundingSize),
MaxChanSize: int64(0), MaxChanSize: int64(0),
DefaultRemoteMaxHtlcs: defaultRemoteMaxHtlcs, DefaultRemoteMaxHtlcs: defaultRemoteMaxHtlcs,
NumGraphSyncPeers: defaultMinPeers, NumGraphSyncPeers: defaultMinPeers,
@ -689,8 +690,8 @@ func ValidateConfig(cfg Config, usageMessage string) (*Config, error) {
// Ensure that the specified values for the min and max channel size // Ensure that the specified values for the min and max channel size
// are within the bounds of the normal chan size constraints. // are within the bounds of the normal chan size constraints.
if cfg.Autopilot.MinChannelSize < int64(minChanFundingSize) { if cfg.Autopilot.MinChannelSize < int64(funding.MinChanFundingSize) {
cfg.Autopilot.MinChannelSize = int64(minChanFundingSize) cfg.Autopilot.MinChannelSize = int64(funding.MinChanFundingSize)
} }
if cfg.Autopilot.MaxChannelSize > int64(MaxFundingAmount) { if cfg.Autopilot.MaxChannelSize > int64(MaxFundingAmount) {
cfg.Autopilot.MaxChannelSize = int64(MaxFundingAmount) cfg.Autopilot.MaxChannelSize = int64(MaxFundingAmount)
@ -707,9 +708,9 @@ func ValidateConfig(cfg Config, usageMessage string) (*Config, error) {
// If unset (marked by 0 value), then enforce proper default. // If unset (marked by 0 value), then enforce proper default.
if cfg.MaxChanSize == 0 { if cfg.MaxChanSize == 0 {
if cfg.ProtocolOptions.Wumbo() { if cfg.ProtocolOptions.Wumbo() {
cfg.MaxChanSize = int64(MaxBtcFundingAmountWumbo) cfg.MaxChanSize = int64(funding.MaxBtcFundingAmountWumbo)
} else { } else {
cfg.MaxChanSize = int64(MaxBtcFundingAmount) cfg.MaxChanSize = int64(funding.MaxBtcFundingAmount)
} }
} }
@ -857,7 +858,7 @@ func ValidateConfig(cfg Config, usageMessage string) (*Config, error) {
"litecoin.active must be set to 1 (true)", funcName) "litecoin.active must be set to 1 (true)", funcName)
case cfg.Litecoin.Active: case cfg.Litecoin.Active:
err := cfg.Litecoin.Validate(minTimeLockDelta, minLtcRemoteDelay) err := cfg.Litecoin.Validate(minTimeLockDelta, funding.MinLtcRemoteDelay)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -941,7 +942,7 @@ func ValidateConfig(cfg Config, usageMessage string) (*Config, error) {
// Finally we'll register the litecoin chain as our current // Finally we'll register the litecoin chain as our current
// primary chain. // primary chain.
cfg.registeredChains.RegisterPrimaryChain(chainreg.LitecoinChain) cfg.registeredChains.RegisterPrimaryChain(chainreg.LitecoinChain)
MaxFundingAmount = maxLtcFundingAmount MaxFundingAmount = funding.MaxLtcFundingAmount
case cfg.Bitcoin.Active: case cfg.Bitcoin.Active:
// Multiple networks can't be selected simultaneously. Count // Multiple networks can't be selected simultaneously. Count
@ -982,7 +983,7 @@ func ValidateConfig(cfg Config, usageMessage string) (*Config, error) {
return nil, err return nil, err
} }
err := cfg.Bitcoin.Validate(minTimeLockDelta, minBtcRemoteDelay) err := cfg.Bitcoin.Validate(minTimeLockDelta, funding.MinBtcRemoteDelay)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -1060,8 +1061,8 @@ func ValidateConfig(cfg Config, usageMessage string) (*Config, error) {
// Ensure that the specified values for the min and max channel size // Ensure that the specified values for the min and max channel size
// don't are within the bounds of the normal chan size constraints. // don't are within the bounds of the normal chan size constraints.
if cfg.Autopilot.MinChannelSize < int64(minChanFundingSize) { if cfg.Autopilot.MinChannelSize < int64(funding.MinChanFundingSize) {
cfg.Autopilot.MinChannelSize = int64(minChanFundingSize) cfg.Autopilot.MinChannelSize = int64(funding.MinChanFundingSize)
} }
if cfg.Autopilot.MaxChannelSize > int64(MaxFundingAmount) { if cfg.Autopilot.MaxChannelSize > int64(MaxFundingAmount) {
cfg.Autopilot.MaxChannelSize = int64(MaxFundingAmount) cfg.Autopilot.MaxChannelSize = int64(MaxFundingAmount)

@ -5,6 +5,8 @@ import (
"io" "io"
"github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcutil"
"github.com/lightningnetwork/lnd/chainreg"
) )
var ( var (
@ -26,3 +28,42 @@ func WriteOutpoint(w io.Writer, o *wire.OutPoint) error {
_, err := w.Write(scratch) _, err := w.Write(scratch)
return err return err
} }
const (
// MinBtcRemoteDelay is the minimum CSV delay we will require the remote
// to use for its commitment transaction.
MinBtcRemoteDelay uint16 = 144
// MaxBtcRemoteDelay is the maximum CSV delay we will require the remote
// to use for its commitment transaction.
MaxBtcRemoteDelay uint16 = 2016
// MinLtcRemoteDelay is the minimum Litecoin CSV delay we will require the
// remote to use for its commitment transaction.
MinLtcRemoteDelay uint16 = 576
// MaxLtcRemoteDelay is the maximum Litecoin CSV delay we will require the
// remote to use for its commitment transaction.
MaxLtcRemoteDelay uint16 = 8064
// 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
// MaxBtcFundingAmountWumbo is a soft-limit on the maximum size of wumbo
// channels. This limit is 10 BTC and is the only thing standing between
// you and limitless channel size (apart from 21 million cap)
MaxBtcFundingAmountWumbo = btcutil.Amount(1000000000)
// MaxLtcFundingAmount is a soft-limit of the maximum channel size
// currently accepted on the Litecoin chain within the Lightning
// Protocol.
MaxLtcFundingAmount = MaxBtcFundingAmount * chainreg.BtcToLtcConversionRate
)

@ -39,59 +39,13 @@ const (
// TODO(roasbeef): tune // TODO(roasbeef): tune
msgBufferSize = 50 msgBufferSize = 50
// 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
// somewhere between these values, depending on channel size.
minBtcRemoteDelay uint16 = 144
maxBtcRemoteDelay uint16 = 2016
// minLtcRemoteDelay and maxLtcRemoteDelay is the extremes of the
// Litecoin CSV delay we will require the remote to use for its
// commitment transaction. The actual delay we will require will be
// somewhere between these values, depending on channel size.
minLtcRemoteDelay uint16 = 576
maxLtcRemoteDelay uint16 = 8064
// maxWaitNumBlocksFundingConf is the maximum number of blocks to wait // maxWaitNumBlocksFundingConf is the maximum number of blocks to wait
// for the funding transaction to be confirmed before forgetting // for the funding transaction to be confirmed before forgetting
// channels that aren't initiated by us. 2016 blocks is ~2 weeks. // channels that aren't initiated by us. 2016 blocks is ~2 weeks.
maxWaitNumBlocksFundingConf = 2016 maxWaitNumBlocksFundingConf = 2016
// 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
// MaxBtcFundingAmountWumbo is a soft-limit on the maximum size of wumbo
// channels. This limit is 10 BTC and is the only thing standing between
// you and limitless channel size (apart from 21 million cap)
MaxBtcFundingAmountWumbo = btcutil.Amount(1000000000)
// maxLtcFundingAmount is a soft-limit of the maximum channel size
// currently accepted on the Litecoin chain within the Lightning
// Protocol.
maxLtcFundingAmount = MaxBtcFundingAmount * chainreg.BtcToLtcConversionRate
) )
var ( 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
// ErrFundingManagerShuttingDown is an error returned when attempting to // ErrFundingManagerShuttingDown is an error returned when attempting to
// process a funding request/message but the funding manager has already // process a funding request/message but the funding manager has already
// been signaled to shut down. // been signaled to shut down.

@ -27,6 +27,7 @@ import (
"github.com/lightningnetwork/lnd/channeldb" "github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/channelnotifier" "github.com/lightningnetwork/lnd/channelnotifier"
"github.com/lightningnetwork/lnd/discovery" "github.com/lightningnetwork/lnd/discovery"
"github.com/lightningnetwork/lnd/funding"
"github.com/lightningnetwork/lnd/htlcswitch" "github.com/lightningnetwork/lnd/htlcswitch"
"github.com/lightningnetwork/lnd/input" "github.com/lightningnetwork/lnd/input"
"github.com/lightningnetwork/lnd/keychain" "github.com/lightningnetwork/lnd/keychain"
@ -433,7 +434,7 @@ func createTestFundingManager(t *testing.T, privKey *btcec.PrivateKey,
}, },
ZombieSweeperInterval: 1 * time.Hour, ZombieSweeperInterval: 1 * time.Hour,
ReservationTimeout: 1 * time.Nanosecond, ReservationTimeout: 1 * time.Nanosecond,
MaxChanSize: MaxFundingAmount, MaxChanSize: funding.MaxBtcFundingAmount,
MaxLocalCSVDelay: defaultMaxLocalCSVDelay, MaxLocalCSVDelay: defaultMaxLocalCSVDelay,
MaxPendingChannels: lncfg.DefaultMaxPendingChannels, MaxPendingChannels: lncfg.DefaultMaxPendingChannels,
NotifyOpenChannelEvent: evt.NotifyOpenChannelEvent, NotifyOpenChannelEvent: evt.NotifyOpenChannelEvent,
@ -3374,10 +3375,10 @@ func TestMaxChannelSizeConfig(t *testing.T) {
// Create a set of funding managers that will reject wumbo // Create a set of funding managers that will reject wumbo
// channels but set --maxchansize explicitly lower than soft-limit. // channels but set --maxchansize explicitly lower than soft-limit.
// Verify that wumbo rejecting funding managers will respect --maxchansize // Verify that wumbo rejecting funding managers will respect --maxchansize
// below 16777215 satoshi (MaxFundingAmount) limit. // below 16777215 satoshi (funding.MaxBtcFundingAmount) limit.
alice, bob := setupFundingManagers(t, func(cfg *fundingConfig) { alice, bob := setupFundingManagers(t, func(cfg *fundingConfig) {
cfg.NoWumboChans = true cfg.NoWumboChans = true
cfg.MaxChanSize = MaxFundingAmount - 1 cfg.MaxChanSize = funding.MaxBtcFundingAmount - 1
}) })
// Attempt to create a channel above the limit // Attempt to create a channel above the limit
@ -3387,7 +3388,7 @@ func TestMaxChannelSizeConfig(t *testing.T) {
initReq := &openChanReq{ initReq := &openChanReq{
targetPubkey: bob.privKey.PubKey(), targetPubkey: bob.privKey.PubKey(),
chainHash: *fundingNetParams.GenesisHash, chainHash: *fundingNetParams.GenesisHash,
localFundingAmt: MaxFundingAmount, localFundingAmt: funding.MaxBtcFundingAmount,
pushAmt: lnwire.NewMSatFromSatoshis(0), pushAmt: lnwire.NewMSatFromSatoshis(0),
private: false, private: false,
updates: updateChan, updates: updateChan,
@ -3407,7 +3408,7 @@ func TestMaxChannelSizeConfig(t *testing.T) {
tearDownFundingManagers(t, alice, bob) tearDownFundingManagers(t, alice, bob)
alice, bob = setupFundingManagers(t, func(cfg *fundingConfig) { alice, bob = setupFundingManagers(t, func(cfg *fundingConfig) {
cfg.NoWumboChans = true cfg.NoWumboChans = true
cfg.MaxChanSize = MaxFundingAmount + 1 cfg.MaxChanSize = funding.MaxBtcFundingAmount + 1
}) })
// We expect Bob to respond with an Accept channel message. // We expect Bob to respond with an Accept channel message.
@ -3456,7 +3457,7 @@ func TestWumboChannelConfig(t *testing.T) {
initReq := &openChanReq{ initReq := &openChanReq{
targetPubkey: bob.privKey.PubKey(), targetPubkey: bob.privKey.PubKey(),
chainHash: *fundingNetParams.GenesisHash, chainHash: *fundingNetParams.GenesisHash,
localFundingAmt: MaxFundingAmount, localFundingAmt: funding.MaxBtcFundingAmount,
pushAmt: lnwire.NewMSatFromSatoshis(0), pushAmt: lnwire.NewMSatFromSatoshis(0),
private: false, private: false,
updates: updateChan, updates: updateChan,
@ -3485,7 +3486,7 @@ func TestWumboChannelConfig(t *testing.T) {
tearDownFundingManagers(t, alice, bob) tearDownFundingManagers(t, alice, bob)
alice, bob = setupFundingManagers(t, func(cfg *fundingConfig) { alice, bob = setupFundingManagers(t, func(cfg *fundingConfig) {
cfg.NoWumboChans = false cfg.NoWumboChans = false
cfg.MaxChanSize = MaxBtcFundingAmountWumbo cfg.MaxChanSize = funding.MaxBtcFundingAmountWumbo
}) })
// We should now be able to initiate a wumbo channel funding w/o any // We should now be able to initiate a wumbo channel funding w/o any

@ -8,7 +8,7 @@ import (
"strings" "strings"
"github.com/btcsuite/btcutil" "github.com/btcsuite/btcutil"
"github.com/lightningnetwork/lnd" "github.com/lightningnetwork/lnd/funding"
"github.com/lightningnetwork/lnd/lntest" "github.com/lightningnetwork/lnd/lntest"
) )
@ -49,7 +49,7 @@ func testMaxChannelSize(net *lntest.NetworkHarness, t *harnessTest) {
t.Fatalf("unable to connect peers: %v", err) t.Fatalf("unable to connect peers: %v", err)
} }
chanAmt := lnd.MaxBtcFundingAmountWumbo + 1 chanAmt := funding.MaxBtcFundingAmountWumbo + 1
_, err = net.OpenChannel( _, err = net.OpenChannel(
ctxb, wumboNode, wumboNode2, lntest.OpenChannelParams{ ctxb, wumboNode, wumboNode2, lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
@ -97,7 +97,7 @@ func testMaxChannelSize(net *lntest.NetworkHarness, t *harnessTest) {
// to accept our wumbo channel funding. // to accept our wumbo channel funding.
wumboNode3, err := net.NewNode( wumboNode3, err := net.NewNode(
"wumbo3", []string{"--protocol.wumbo-channels", "wumbo3", []string{"--protocol.wumbo-channels",
fmt.Sprintf("--maxchansize=%v", int64(lnd.MaxBtcFundingAmountWumbo+1))}, fmt.Sprintf("--maxchansize=%v", int64(funding.MaxBtcFundingAmountWumbo+1))},
) )
if err != nil { if err != nil {
t.Fatalf("unable to create new node: %v", err) t.Fatalf("unable to create new node: %v", err)

@ -6,7 +6,7 @@ import (
"strings" "strings"
"time" "time"
"github.com/lightningnetwork/lnd" "github.com/lightningnetwork/lnd/funding"
"github.com/lightningnetwork/lnd/lnrpc" "github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/lnrpc/routerrpc" "github.com/lightningnetwork/lnd/lnrpc/routerrpc"
"github.com/lightningnetwork/lnd/lntest" "github.com/lightningnetwork/lnd/lntest"
@ -19,7 +19,7 @@ func testHtlcErrorPropagation(net *lntest.NetworkHarness, t *harnessTest) {
// In this test we wish to exercise the daemon's correct parsing, // In this test we wish to exercise the daemon's correct parsing,
// handling, and propagation of errors that occur while processing a // handling, and propagation of errors that occur while processing a
// multi-hop payment. // multi-hop payment.
const chanAmt = lnd.MaxBtcFundingAmount const chanAmt = funding.MaxBtcFundingAmount
// First establish a channel with a capacity of 0.5 BTC between Alice // First establish a channel with a capacity of 0.5 BTC between Alice
// and Bob. // and Bob.
@ -102,7 +102,7 @@ func testHtlcErrorPropagation(net *lntest.NetworkHarness, t *harnessTest) {
t.Fatalf("unable to connect bob to carol: %v", err) t.Fatalf("unable to connect bob to carol: %v", err)
} }
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout) ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
const bobChanAmt = lnd.MaxBtcFundingAmount const bobChanAmt = funding.MaxBtcFundingAmount
chanPointBob := openChannelAndAssert( chanPointBob := openChannelAndAssert(
ctxt, t, net, net.Bob, carol, ctxt, t, net, net.Bob, carol,
lntest.OpenChannelParams{ lntest.OpenChannelParams{

@ -8,7 +8,7 @@ import (
"github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcutil" "github.com/btcsuite/btcutil"
"github.com/lightningnetwork/lnd" "github.com/lightningnetwork/lnd/funding"
"github.com/lightningnetwork/lnd/lnrpc" "github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/lnrpc/walletrpc" "github.com/lightningnetwork/lnd/lnrpc/walletrpc"
"github.com/lightningnetwork/lnd/lntest" "github.com/lightningnetwork/lnd/lntest"
@ -20,7 +20,7 @@ import (
// multisig funding output. // multisig funding output.
func testPsbtChanFunding(net *lntest.NetworkHarness, t *harnessTest) { func testPsbtChanFunding(net *lntest.NetworkHarness, t *harnessTest) {
ctxb := context.Background() ctxb := context.Background()
const chanSize = lnd.MaxBtcFundingAmount const chanSize = funding.MaxBtcFundingAmount
// First, we'll create two new nodes that we'll use to open channels // First, we'll create two new nodes that we'll use to open channels
// between for this test. Dave gets some coins that will be used to // between for this test. Dave gets some coins that will be used to

@ -32,6 +32,7 @@ import (
"github.com/lightningnetwork/lnd" "github.com/lightningnetwork/lnd"
"github.com/lightningnetwork/lnd/chainreg" "github.com/lightningnetwork/lnd/chainreg"
"github.com/lightningnetwork/lnd/channeldb" "github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/funding"
"github.com/lightningnetwork/lnd/input" "github.com/lightningnetwork/lnd/input"
"github.com/lightningnetwork/lnd/labels" "github.com/lightningnetwork/lnd/labels"
"github.com/lightningnetwork/lnd/lncfg" "github.com/lightningnetwork/lnd/lncfg"
@ -1250,7 +1251,7 @@ func basicChannelFundingTest(t *harnessTest, net *lntest.NetworkHarness,
alice *lntest.HarnessNode, bob *lntest.HarnessNode, alice *lntest.HarnessNode, bob *lntest.HarnessNode,
fundingShim *lnrpc.FundingShim) (*lnrpc.Channel, *lnrpc.Channel, func(), error) { fundingShim *lnrpc.FundingShim) (*lnrpc.Channel, *lnrpc.Channel, func(), error) {
chanAmt := lnd.MaxBtcFundingAmount chanAmt := funding.MaxBtcFundingAmount
pushAmt := btcutil.Amount(100000) pushAmt := btcutil.Amount(100000)
// Record nodes' channel balance before testing. // Record nodes' channel balance before testing.
@ -1493,7 +1494,7 @@ func testUnconfirmedChannelFunding(net *lntest.NetworkHarness, t *harnessTest) {
ctxb := context.Background() ctxb := context.Background()
const ( const (
chanAmt = lnd.MaxBtcFundingAmount chanAmt = funding.MaxBtcFundingAmount
pushAmt = btcutil.Amount(100000) pushAmt = btcutil.Amount(100000)
) )
@ -1945,7 +1946,7 @@ func testUpdateChannelPolicy(net *lntest.NetworkHarness, t *harnessTest) {
defaultTimeLockDelta = chainreg.DefaultBitcoinTimeLockDelta defaultTimeLockDelta = chainreg.DefaultBitcoinTimeLockDelta
defaultMinHtlc = 1000 defaultMinHtlc = 1000
) )
defaultMaxHtlc := calculateMaxHtlc(lnd.MaxBtcFundingAmount) defaultMaxHtlc := calculateMaxHtlc(funding.MaxBtcFundingAmount)
// Launch notification clients for all nodes, such that we can // Launch notification clients for all nodes, such that we can
// get notified when they discover new channels and updates in the // get notified when they discover new channels and updates in the
@ -1955,7 +1956,7 @@ func testUpdateChannelPolicy(net *lntest.NetworkHarness, t *harnessTest) {
bobSub := subscribeGraphNotifications(t, ctxb, net.Bob) bobSub := subscribeGraphNotifications(t, ctxb, net.Bob)
defer close(bobSub.quit) defer close(bobSub.quit)
chanAmt := lnd.MaxBtcFundingAmount chanAmt := funding.MaxBtcFundingAmount
pushAmt := chanAmt / 2 pushAmt := chanAmt / 2
// Create a channel Alice->Bob. // Create a channel Alice->Bob.
@ -2518,7 +2519,7 @@ func testOpenChannelAfterReorg(net *lntest.NetworkHarness, t *harnessTest) {
// Create a new channel that requires 1 confs before it's considered // Create a new channel that requires 1 confs before it's considered
// open, then broadcast the funding transaction // open, then broadcast the funding transaction
chanAmt := lnd.MaxBtcFundingAmount chanAmt := funding.MaxBtcFundingAmount
pushAmt := btcutil.Amount(0) pushAmt := btcutil.Amount(0)
ctxt, _ := context.WithTimeout(ctxb, channelOpenTimeout) ctxt, _ := context.WithTimeout(ctxb, channelOpenTimeout)
pendingUpdate, err := net.OpenPendingChannel(ctxt, net.Alice, net.Bob, pendingUpdate, err := net.OpenPendingChannel(ctxt, net.Alice, net.Bob,
@ -2738,7 +2739,7 @@ func testDisconnectingTargetPeer(net *lntest.NetworkHarness, t *harnessTest) {
t.Fatalf("unable to send coins to alice: %v", err) t.Fatalf("unable to send coins to alice: %v", err)
} }
chanAmt := lnd.MaxBtcFundingAmount chanAmt := funding.MaxBtcFundingAmount
pushAmt := btcutil.Amount(0) pushAmt := btcutil.Amount(0)
// Create a new channel that requires 1 confs before it's considered // Create a new channel that requires 1 confs before it's considered
@ -2873,7 +2874,7 @@ func testDisconnectingTargetPeer(net *lntest.NetworkHarness, t *harnessTest) {
func testChannelFundingPersistence(net *lntest.NetworkHarness, t *harnessTest) { func testChannelFundingPersistence(net *lntest.NetworkHarness, t *harnessTest) {
ctxb := context.Background() ctxb := context.Background()
chanAmt := lnd.MaxBtcFundingAmount chanAmt := funding.MaxBtcFundingAmount
pushAmt := btcutil.Amount(0) pushAmt := btcutil.Amount(0)
// As we need to create a channel that requires more than 1 // As we need to create a channel that requires more than 1
@ -3061,7 +3062,7 @@ func testChannelBalance(net *lntest.NetworkHarness, t *harnessTest) {
// Open a channel with 0.16 BTC between Alice and Bob, ensuring the // Open a channel with 0.16 BTC between Alice and Bob, ensuring the
// channel has been opened properly. // channel has been opened properly.
amount := lnd.MaxBtcFundingAmount amount := funding.MaxBtcFundingAmount
// Creates a helper closure to be used below which asserts the proper // Creates a helper closure to be used below which asserts the proper
// response to a channel balance RPC. // response to a channel balance RPC.
@ -6169,7 +6170,7 @@ func testSendToRouteErrorPropagation(net *lntest.NetworkHarness, t *harnessTest)
func testUnannouncedChannels(net *lntest.NetworkHarness, t *harnessTest) { func testUnannouncedChannels(net *lntest.NetworkHarness, t *harnessTest) {
ctxb := context.Background() ctxb := context.Background()
amount := lnd.MaxBtcFundingAmount amount := funding.MaxBtcFundingAmount
// Open a channel between Alice and Bob, ensuring the // Open a channel between Alice and Bob, ensuring the
// channel has been opened properly. // channel has been opened properly.
@ -7408,7 +7409,7 @@ func testBasicChannelCreationAndUpdates(net *lntest.NetworkHarness, t *harnessTe
ctxb := context.Background() ctxb := context.Background()
const ( const (
numChannels = 2 numChannels = 2
amount = lnd.MaxBtcFundingAmount amount = funding.MaxBtcFundingAmount
) )
// Subscribe Bob and Alice to channel event notifications. // Subscribe Bob and Alice to channel event notifications.
@ -7572,7 +7573,7 @@ func testMaxPendingChannels(net *lntest.NetworkHarness, t *harnessTest) {
ctxb := context.Background() ctxb := context.Background()
maxPendingChannels := lncfg.DefaultMaxPendingChannels + 1 maxPendingChannels := lncfg.DefaultMaxPendingChannels + 1
amount := lnd.MaxBtcFundingAmount amount := funding.MaxBtcFundingAmount
// Create a new node (Carol) with greater number of max pending // Create a new node (Carol) with greater number of max pending
// channels. // channels.
@ -8183,7 +8184,7 @@ func testRevokedCloseRetribution(net *lntest.NetworkHarness, t *harnessTest) {
ctxb := context.Background() ctxb := context.Background()
const ( const (
chanAmt = lnd.MaxBtcFundingAmount chanAmt = funding.MaxBtcFundingAmount
paymentAmt = 10000 paymentAmt = 10000
numInvoices = 6 numInvoices = 6
) )
@ -8452,7 +8453,7 @@ func testRevokedCloseRetributionZeroValueRemoteOutput(net *lntest.NetworkHarness
ctxb := context.Background() ctxb := context.Background()
const ( const (
chanAmt = lnd.MaxBtcFundingAmount chanAmt = funding.MaxBtcFundingAmount
paymentAmt = 10000 paymentAmt = 10000
numInvoices = 6 numInvoices = 6
) )
@ -8701,7 +8702,7 @@ func testRevokedCloseRetributionRemoteHodl(net *lntest.NetworkHarness,
ctxb := context.Background() ctxb := context.Background()
const ( const (
chanAmt = lnd.MaxBtcFundingAmount chanAmt = funding.MaxBtcFundingAmount
pushAmt = 200000 pushAmt = 200000
paymentAmt = 10000 paymentAmt = 10000
numInvoices = 6 numInvoices = 6
@ -8747,7 +8748,7 @@ func testRevokedCloseRetributionRemoteHodl(net *lntest.NetworkHarness,
// In order to test Dave's response to an uncooperative channel closure // 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 // by Carol, we'll first open up a channel between them with a
// lnd.MaxBtcFundingAmount (2^24) satoshis value. // funding.MaxBtcFundingAmount (2^24) satoshis value.
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout) ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
chanPoint := openChannelAndAssert( chanPoint := openChannelAndAssert(
ctxt, t, net, dave, carol, ctxt, t, net, dave, carol,
@ -9165,7 +9166,7 @@ func testRevokedCloseRetributionAltruistWatchtowerCase(
ctxb := context.Background() ctxb := context.Background()
const ( const (
chanAmt = lnd.MaxBtcFundingAmount chanAmt = funding.MaxBtcFundingAmount
paymentAmt = 10000 paymentAmt = 10000
numInvoices = 6 numInvoices = 6
externalIP = "1.2.3.4" externalIP = "1.2.3.4"
@ -9739,7 +9740,7 @@ func assertDLPExecuted(net *lntest.NetworkHarness, t *harnessTest,
func testDataLossProtection(net *lntest.NetworkHarness, t *harnessTest) { func testDataLossProtection(net *lntest.NetworkHarness, t *harnessTest) {
ctxb := context.Background() ctxb := context.Background()
const ( const (
chanAmt = lnd.MaxBtcFundingAmount chanAmt = funding.MaxBtcFundingAmount
paymentAmt = 10000 paymentAmt = 10000
numInvoices = 6 numInvoices = 6
) )
@ -10329,7 +10330,7 @@ func subscribeGraphNotifications(t *harnessTest, ctxb context.Context,
func testGraphTopologyNotifications(net *lntest.NetworkHarness, t *harnessTest) { func testGraphTopologyNotifications(net *lntest.NetworkHarness, t *harnessTest) {
ctxb := context.Background() ctxb := context.Background()
const chanAmt = lnd.MaxBtcFundingAmount const chanAmt = funding.MaxBtcFundingAmount
// Let Alice subscribe to graph notifications. // Let Alice subscribe to graph notifications.
graphSub := subscribeGraphNotifications( graphSub := subscribeGraphNotifications(
@ -10656,7 +10657,7 @@ func testNodeAnnouncement(net *lntest.NetworkHarness, t *harnessTest) {
func testNodeSignVerify(net *lntest.NetworkHarness, t *harnessTest) { func testNodeSignVerify(net *lntest.NetworkHarness, t *harnessTest) {
ctxb := context.Background() ctxb := context.Background()
chanAmt := lnd.MaxBtcFundingAmount chanAmt := funding.MaxBtcFundingAmount
pushAmt := btcutil.Amount(100000) pushAmt := btcutil.Amount(100000)
// Create a channel between alice and bob. // Create a channel between alice and bob.
@ -13198,7 +13199,7 @@ func testAbandonChannel(net *lntest.NetworkHarness, t *harnessTest) {
// First establish a channel between Alice and Bob. // First establish a channel between Alice and Bob.
channelParam := lntest.OpenChannelParams{ channelParam := lntest.OpenChannelParams{
Amt: lnd.MaxBtcFundingAmount, Amt: funding.MaxBtcFundingAmount,
PushAmt: btcutil.Amount(100000), PushAmt: btcutil.Amount(100000),
} }
@ -13991,7 +13992,7 @@ func testExternalFundingChanPoint(net *lntest.NetworkHarness, t *harnessTest) {
// flow. To start with, we'll create a pending channel with a shim for // flow. To start with, we'll create a pending channel with a shim for
// a transaction that will never be published. // a transaction that will never be published.
const thawHeight uint32 = 10 const thawHeight uint32 = 10
const chanSize = lnd.MaxBtcFundingAmount const chanSize = funding.MaxBtcFundingAmount
fundingShim1, chanPoint1, _ := deriveFundingShim( fundingShim1, chanPoint1, _ := deriveFundingShim(
net, t, carol, dave, chanSize, thawHeight, 1, false, net, t, carol, dave, chanSize, thawHeight, 1, false,
) )

@ -5,7 +5,7 @@ import (
"strings" "strings"
"github.com/btcsuite/btcutil" "github.com/btcsuite/btcutil"
"github.com/lightningnetwork/lnd" "github.com/lightningnetwork/lnd/funding"
"github.com/lightningnetwork/lnd/lntest" "github.com/lightningnetwork/lnd/lntest"
) )
@ -48,7 +48,7 @@ func testWumboChannels(net *lntest.NetworkHarness, t *harnessTest) {
t.Fatalf("unable to connect peers: %v", err) t.Fatalf("unable to connect peers: %v", err)
} }
chanAmt := lnd.MaxBtcFundingAmount + 1 chanAmt := funding.MaxBtcFundingAmount + 1
_, err = net.OpenChannel( _, err = net.OpenChannel(
ctxb, wumboNode, miniNode, lntest.OpenChannelParams{ ctxb, wumboNode, miniNode, lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,

@ -42,6 +42,7 @@ import (
"github.com/lightningnetwork/lnd/contractcourt" "github.com/lightningnetwork/lnd/contractcourt"
"github.com/lightningnetwork/lnd/discovery" "github.com/lightningnetwork/lnd/discovery"
"github.com/lightningnetwork/lnd/feature" "github.com/lightningnetwork/lnd/feature"
"github.com/lightningnetwork/lnd/funding"
"github.com/lightningnetwork/lnd/htlcswitch" "github.com/lightningnetwork/lnd/htlcswitch"
"github.com/lightningnetwork/lnd/htlcswitch/hop" "github.com/lightningnetwork/lnd/htlcswitch/hop"
"github.com/lightningnetwork/lnd/input" "github.com/lightningnetwork/lnd/input"
@ -1803,9 +1804,9 @@ func (r *rpcServer) parseOpenChannelReq(in *lnrpc.OpenChannelRequest,
// Restrict the size of the channel we'll actually open. At a later // Restrict the size of the channel we'll actually open. At a later
// level, we'll ensure that the output we create after accounting for // level, we'll ensure that the output we create after accounting for
// fees that a dust output isn't created. // fees that a dust output isn't created.
if localFundingAmt < minChanFundingSize { if localFundingAmt < funding.MinChanFundingSize {
return nil, fmt.Errorf("channel is too small, the minimum "+ return nil, fmt.Errorf("channel is too small, the minimum "+
"channel size is: %v SAT", int64(minChanFundingSize)) "channel size is: %v SAT", int64(funding.MinChanFundingSize))
} }
// Prevent users from submitting a max-htlc value that would exceed the // Prevent users from submitting a max-htlc value that would exceed the

@ -39,6 +39,7 @@ import (
"github.com/lightningnetwork/lnd/contractcourt" "github.com/lightningnetwork/lnd/contractcourt"
"github.com/lightningnetwork/lnd/discovery" "github.com/lightningnetwork/lnd/discovery"
"github.com/lightningnetwork/lnd/feature" "github.com/lightningnetwork/lnd/feature"
"github.com/lightningnetwork/lnd/funding"
"github.com/lightningnetwork/lnd/healthcheck" "github.com/lightningnetwork/lnd/healthcheck"
"github.com/lightningnetwork/lnd/htlcswitch" "github.com/lightningnetwork/lnd/htlcswitch"
"github.com/lightningnetwork/lnd/htlcswitch/hop" "github.com/lightningnetwork/lnd/htlcswitch/hop"
@ -114,6 +115,17 @@ var (
// validColorRegexp is a regexp that lets you check if a particular // validColorRegexp is a regexp that lets you check if a particular
// color string matches the standard hex color format #RRGGBB. // color string matches the standard hex color format #RRGGBB.
validColorRegexp = regexp.MustCompile("^#[A-Fa-f0-9]{6}$") validColorRegexp = regexp.MustCompile("^#[A-Fa-f0-9]{6}$")
// MaxFundingAmount is a soft-limit of the maximum channel size
// currently accepted within the Lightning Protocol. This 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 = funding.MaxBtcFundingAmount
) )
// errPeerAlreadyConnected is an error returned by the server when we're // errPeerAlreadyConnected is an error returned by the server when we're
@ -977,12 +989,12 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
// Litecoin, depending on the primary registered chain. // Litecoin, depending on the primary registered chain.
primaryChain := cfg.registeredChains.PrimaryChain() primaryChain := cfg.registeredChains.PrimaryChain()
chainCfg := cfg.Bitcoin chainCfg := cfg.Bitcoin
minRemoteDelay := minBtcRemoteDelay minRemoteDelay := funding.MinBtcRemoteDelay
maxRemoteDelay := maxBtcRemoteDelay maxRemoteDelay := funding.MaxBtcRemoteDelay
if primaryChain == chainreg.LitecoinChain { if primaryChain == chainreg.LitecoinChain {
chainCfg = cfg.Litecoin chainCfg = cfg.Litecoin
minRemoteDelay = minLtcRemoteDelay minRemoteDelay = funding.MinLtcRemoteDelay
maxRemoteDelay = maxLtcRemoteDelay maxRemoteDelay = funding.MaxLtcRemoteDelay
} }
var chanIDSeed [32]byte var chanIDSeed [32]byte