mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-06-22 14:51:45 +02:00
lnd+funding: move Manager to funding, change references
This commit is contained in:
parent
e7e872f19a
commit
dcdf36f410
3528
funding/manager.go
3528
funding/manager.go
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,6 @@
|
|||||||
// +build !rpctest
|
// +build !rpctest
|
||||||
|
|
||||||
package lnd
|
package funding
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
@ -27,7 +27,6 @@ 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"
|
||||||
@ -60,6 +59,10 @@ const (
|
|||||||
|
|
||||||
// A dummy value to use for the funding broadcast height.
|
// A dummy value to use for the funding broadcast height.
|
||||||
fundingBroadcastHeight = 123
|
fundingBroadcastHeight = 123
|
||||||
|
|
||||||
|
// defaultMaxLocalCSVDelay is the maximum delay we accept on our
|
||||||
|
// commitment output.
|
||||||
|
defaultMaxLocalCSVDelay = 10000
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -347,7 +350,7 @@ func createTestFundingManager(t *testing.T, privKey *btcec.PrivateKey,
|
|||||||
|
|
||||||
chainedAcceptor := chanacceptor.NewChainedAcceptor()
|
chainedAcceptor := chanacceptor.NewChainedAcceptor()
|
||||||
|
|
||||||
fundingCfg := fundingConfig{
|
fundingCfg := Config{
|
||||||
IDKey: privKey.PubKey(),
|
IDKey: privKey.PubKey(),
|
||||||
Wallet: lnw,
|
Wallet: lnw,
|
||||||
Notifier: chainNotifier,
|
Notifier: chainNotifier,
|
||||||
@ -434,7 +437,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: funding.MaxBtcFundingAmount,
|
MaxChanSize: MaxBtcFundingAmount,
|
||||||
MaxLocalCSVDelay: defaultMaxLocalCSVDelay,
|
MaxLocalCSVDelay: defaultMaxLocalCSVDelay,
|
||||||
MaxPendingChannels: lncfg.DefaultMaxPendingChannels,
|
MaxPendingChannels: lncfg.DefaultMaxPendingChannels,
|
||||||
NotifyOpenChannelEvent: evt.NotifyOpenChannelEvent,
|
NotifyOpenChannelEvent: evt.NotifyOpenChannelEvent,
|
||||||
@ -492,7 +495,7 @@ func recreateAliceFundingManager(t *testing.T, alice *testNode) {
|
|||||||
|
|
||||||
chainedAcceptor := chanacceptor.NewChainedAcceptor()
|
chainedAcceptor := chanacceptor.NewChainedAcceptor()
|
||||||
|
|
||||||
f, err := NewFundingManager(fundingConfig{
|
f, err := NewFundingManager(Config{
|
||||||
IDKey: oldCfg.IDKey,
|
IDKey: oldCfg.IDKey,
|
||||||
Wallet: oldCfg.Wallet,
|
Wallet: oldCfg.Wallet,
|
||||||
Notifier: oldCfg.Notifier,
|
Notifier: oldCfg.Notifier,
|
||||||
@ -557,7 +560,7 @@ func recreateAliceFundingManager(t *testing.T, alice *testNode) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type cfgOption func(*fundingConfig)
|
type cfgOption func(*Config)
|
||||||
|
|
||||||
func setupFundingManagers(t *testing.T,
|
func setupFundingManagers(t *testing.T,
|
||||||
options ...cfgOption) (*testNode, *testNode) {
|
options ...cfgOption) (*testNode, *testNode) {
|
||||||
@ -2864,7 +2867,7 @@ func TestFundingManagerMaxPendingChannels(t *testing.T) {
|
|||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
alice, bob := setupFundingManagers(
|
alice, bob := setupFundingManagers(
|
||||||
t, func(cfg *fundingConfig) {
|
t, func(cfg *Config) {
|
||||||
cfg.MaxPendingChannels = maxPending
|
cfg.MaxPendingChannels = maxPending
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@ -3037,7 +3040,7 @@ func TestFundingManagerRejectPush(t *testing.T) {
|
|||||||
|
|
||||||
// Enable 'rejectpush' option and initialize funding managers.
|
// Enable 'rejectpush' option and initialize funding managers.
|
||||||
alice, bob := setupFundingManagers(
|
alice, bob := setupFundingManagers(
|
||||||
t, func(cfg *fundingConfig) {
|
t, func(cfg *Config) {
|
||||||
cfg.RejectPush = true
|
cfg.RejectPush = true
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@ -3377,10 +3380,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 (funding.MaxBtcFundingAmount) limit.
|
// below 16777215 satoshi (MaxBtcFundingAmount) limit.
|
||||||
alice, bob := setupFundingManagers(t, func(cfg *fundingConfig) {
|
alice, bob := setupFundingManagers(t, func(cfg *Config) {
|
||||||
cfg.NoWumboChans = true
|
cfg.NoWumboChans = true
|
||||||
cfg.MaxChanSize = funding.MaxBtcFundingAmount - 1
|
cfg.MaxChanSize = MaxBtcFundingAmount - 1
|
||||||
})
|
})
|
||||||
|
|
||||||
// Attempt to create a channel above the limit
|
// Attempt to create a channel above the limit
|
||||||
@ -3391,7 +3394,7 @@ func TestMaxChannelSizeConfig(t *testing.T) {
|
|||||||
Peer: bob,
|
Peer: bob,
|
||||||
TargetPubkey: bob.privKey.PubKey(),
|
TargetPubkey: bob.privKey.PubKey(),
|
||||||
ChainHash: *fundingNetParams.GenesisHash,
|
ChainHash: *fundingNetParams.GenesisHash,
|
||||||
LocalFundingAmt: funding.MaxBtcFundingAmount,
|
LocalFundingAmt: MaxBtcFundingAmount,
|
||||||
PushAmt: lnwire.NewMSatFromSatoshis(0),
|
PushAmt: lnwire.NewMSatFromSatoshis(0),
|
||||||
Private: false,
|
Private: false,
|
||||||
Updates: updateChan,
|
Updates: updateChan,
|
||||||
@ -3409,9 +3412,9 @@ func TestMaxChannelSizeConfig(t *testing.T) {
|
|||||||
// channels but set --maxchansize explicitly higher than soft-limit
|
// channels but set --maxchansize explicitly higher than soft-limit
|
||||||
// A --maxchansize greater than this limit should have no effect.
|
// A --maxchansize greater than this limit should have no effect.
|
||||||
tearDownFundingManagers(t, alice, bob)
|
tearDownFundingManagers(t, alice, bob)
|
||||||
alice, bob = setupFundingManagers(t, func(cfg *fundingConfig) {
|
alice, bob = setupFundingManagers(t, func(cfg *Config) {
|
||||||
cfg.NoWumboChans = true
|
cfg.NoWumboChans = true
|
||||||
cfg.MaxChanSize = funding.MaxBtcFundingAmount + 1
|
cfg.MaxChanSize = MaxBtcFundingAmount + 1
|
||||||
})
|
})
|
||||||
|
|
||||||
// Reset the Peer to the newly created one.
|
// Reset the Peer to the newly created one.
|
||||||
@ -3427,7 +3430,7 @@ func TestMaxChannelSizeConfig(t *testing.T) {
|
|||||||
// Create the funding managers, this time allowing
|
// Create the funding managers, this time allowing
|
||||||
// wumbo channels but setting --maxchansize explicitly.
|
// wumbo channels but setting --maxchansize explicitly.
|
||||||
tearDownFundingManagers(t, alice, bob)
|
tearDownFundingManagers(t, alice, bob)
|
||||||
alice, bob = setupFundingManagers(t, func(cfg *fundingConfig) {
|
alice, bob = setupFundingManagers(t, func(cfg *Config) {
|
||||||
cfg.NoWumboChans = false
|
cfg.NoWumboChans = false
|
||||||
cfg.MaxChanSize = btcutil.Amount(100000000)
|
cfg.MaxChanSize = btcutil.Amount(100000000)
|
||||||
})
|
})
|
||||||
@ -3454,7 +3457,7 @@ func TestWumboChannelConfig(t *testing.T) {
|
|||||||
|
|
||||||
// First we'll create a set of funding managers that will reject wumbo
|
// First we'll create a set of funding managers that will reject wumbo
|
||||||
// channels.
|
// channels.
|
||||||
alice, bob := setupFundingManagers(t, func(cfg *fundingConfig) {
|
alice, bob := setupFundingManagers(t, func(cfg *Config) {
|
||||||
cfg.NoWumboChans = true
|
cfg.NoWumboChans = true
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -3467,7 +3470,7 @@ func TestWumboChannelConfig(t *testing.T) {
|
|||||||
Peer: bob,
|
Peer: bob,
|
||||||
TargetPubkey: bob.privKey.PubKey(),
|
TargetPubkey: bob.privKey.PubKey(),
|
||||||
ChainHash: *fundingNetParams.GenesisHash,
|
ChainHash: *fundingNetParams.GenesisHash,
|
||||||
LocalFundingAmt: funding.MaxBtcFundingAmount,
|
LocalFundingAmt: MaxBtcFundingAmount,
|
||||||
PushAmt: lnwire.NewMSatFromSatoshis(0),
|
PushAmt: lnwire.NewMSatFromSatoshis(0),
|
||||||
Private: false,
|
Private: false,
|
||||||
Updates: updateChan,
|
Updates: updateChan,
|
||||||
@ -3494,9 +3497,9 @@ func TestWumboChannelConfig(t *testing.T) {
|
|||||||
// Next, we'll re-create the funding managers, but this time allowing
|
// Next, we'll re-create the funding managers, but this time allowing
|
||||||
// wumbo channels explicitly.
|
// wumbo channels explicitly.
|
||||||
tearDownFundingManagers(t, alice, bob)
|
tearDownFundingManagers(t, alice, bob)
|
||||||
alice, bob = setupFundingManagers(t, func(cfg *fundingConfig) {
|
alice, bob = setupFundingManagers(t, func(cfg *Config) {
|
||||||
cfg.NoWumboChans = false
|
cfg.NoWumboChans = false
|
||||||
cfg.MaxChanSize = funding.MaxBtcFundingAmountWumbo
|
cfg.MaxChanSize = MaxBtcFundingAmountWumbo
|
||||||
})
|
})
|
||||||
|
|
||||||
// Reset the Peer to the newly created one.
|
// Reset the Peer to the newly created one.
|
3540
fundingmanager.go
3540
fundingmanager.go
File diff suppressed because it is too large
Load Diff
1
log.go
1
log.go
@ -82,7 +82,6 @@ var (
|
|||||||
ltndLog = addLndPkgLogger("LTND")
|
ltndLog = addLndPkgLogger("LTND")
|
||||||
rpcsLog = addLndPkgLogger("RPCS")
|
rpcsLog = addLndPkgLogger("RPCS")
|
||||||
srvrLog = addLndPkgLogger("SRVR")
|
srvrLog = addLndPkgLogger("SRVR")
|
||||||
fndgLog = addLndPkgLogger("FNDG")
|
|
||||||
utxnLog = addLndPkgLogger("UTXN")
|
utxnLog = addLndPkgLogger("UTXN")
|
||||||
brarLog = addLndPkgLogger("BRAR")
|
brarLog = addLndPkgLogger("BRAR")
|
||||||
atplLog = addLndPkgLogger("ATPL")
|
atplLog = addLndPkgLogger("ATPL")
|
||||||
|
3
pilot.go
3
pilot.go
@ -10,6 +10,7 @@ import (
|
|||||||
"github.com/btcsuite/btcutil"
|
"github.com/btcsuite/btcutil"
|
||||||
"github.com/lightningnetwork/lnd/autopilot"
|
"github.com/lightningnetwork/lnd/autopilot"
|
||||||
"github.com/lightningnetwork/lnd/chainreg"
|
"github.com/lightningnetwork/lnd/chainreg"
|
||||||
|
"github.com/lightningnetwork/lnd/funding"
|
||||||
"github.com/lightningnetwork/lnd/lncfg"
|
"github.com/lightningnetwork/lnd/lncfg"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
"github.com/lightningnetwork/lnd/tor"
|
"github.com/lightningnetwork/lnd/tor"
|
||||||
@ -97,7 +98,7 @@ func (c *chanController) OpenChannel(target *btcec.PublicKey,
|
|||||||
|
|
||||||
// Construct the open channel request and send it to the server to begin
|
// Construct the open channel request and send it to the server to begin
|
||||||
// the funding workflow.
|
// the funding workflow.
|
||||||
req := &InitFundingMsg{
|
req := &funding.InitFundingMsg{
|
||||||
TargetPubkey: target,
|
TargetPubkey: target,
|
||||||
ChainHash: *c.netParams.GenesisHash,
|
ChainHash: *c.netParams.GenesisHash,
|
||||||
SubtractFees: true,
|
SubtractFees: true,
|
||||||
|
@ -1765,7 +1765,7 @@ func (r *rpcServer) canOpenChannel() error {
|
|||||||
// struct. The logic is abstracted so that it can be shared between OpenChannel
|
// struct. The logic is abstracted so that it can be shared between OpenChannel
|
||||||
// and OpenChannelSync.
|
// and OpenChannelSync.
|
||||||
func (r *rpcServer) parseOpenChannelReq(in *lnrpc.OpenChannelRequest,
|
func (r *rpcServer) parseOpenChannelReq(in *lnrpc.OpenChannelRequest,
|
||||||
isSync bool) (*InitFundingMsg, error) {
|
isSync bool) (*funding.InitFundingMsg, error) {
|
||||||
|
|
||||||
rpcsLog.Debugf("[openchannel] request to NodeKey(%x) "+
|
rpcsLog.Debugf("[openchannel] request to NodeKey(%x) "+
|
||||||
"allocation(us=%v, them=%v)", in.NodePubkey,
|
"allocation(us=%v, them=%v)", in.NodePubkey,
|
||||||
@ -1892,7 +1892,7 @@ func (r *rpcServer) parseOpenChannelReq(in *lnrpc.OpenChannelRequest,
|
|||||||
// Instruct the server to trigger the necessary events to attempt to
|
// Instruct the server to trigger the necessary events to attempt to
|
||||||
// open a new channel. A stream is returned in place, this stream will
|
// open a new channel. A stream is returned in place, this stream will
|
||||||
// be used to consume updates of the state of the pending channel.
|
// be used to consume updates of the state of the pending channel.
|
||||||
return &InitFundingMsg{
|
return &funding.InitFundingMsg{
|
||||||
TargetPubkey: nodePubKey,
|
TargetPubkey: nodePubKey,
|
||||||
ChainHash: *r.cfg.ActiveNetParams.GenesisHash,
|
ChainHash: *r.cfg.ActiveNetParams.GenesisHash,
|
||||||
LocalFundingAmt: localFundingAmt,
|
LocalFundingAmt: localFundingAmt,
|
||||||
|
@ -218,7 +218,7 @@ type server struct {
|
|||||||
|
|
||||||
cc *chainreg.ChainControl
|
cc *chainreg.ChainControl
|
||||||
|
|
||||||
fundingMgr *Manager
|
fundingMgr *funding.Manager
|
||||||
|
|
||||||
localChanDB *channeldb.DB
|
localChanDB *channeldb.DB
|
||||||
|
|
||||||
@ -1001,7 +1001,7 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
s.fundingMgr, err = NewFundingManager(fundingConfig{
|
s.fundingMgr, err = funding.NewFundingManager(funding.Config{
|
||||||
NoWumboChans: !cfg.ProtocolOptions.Wumbo(),
|
NoWumboChans: !cfg.ProtocolOptions.Wumbo(),
|
||||||
IDKey: nodeKeyECDH.PubKey(),
|
IDKey: nodeKeyECDH.PubKey(),
|
||||||
Wallet: cc.Wallet,
|
Wallet: cc.Wallet,
|
||||||
@ -3627,7 +3627,7 @@ func (s *server) DisconnectPeer(pubKey *btcec.PublicKey) error {
|
|||||||
//
|
//
|
||||||
// NOTE: This function is safe for concurrent access.
|
// NOTE: This function is safe for concurrent access.
|
||||||
func (s *server) OpenChannel(
|
func (s *server) OpenChannel(
|
||||||
req *InitFundingMsg) (chan *lnrpc.OpenStatusUpdate, chan error) {
|
req *funding.InitFundingMsg) (chan *lnrpc.OpenStatusUpdate, chan error) {
|
||||||
|
|
||||||
// The updateChan will have a buffer of 2, since we expect a ChanPending
|
// The updateChan will have a buffer of 2, since we expect a ChanPending
|
||||||
// + a ChanOpen update, and we want to make sure the funding process is
|
// + a ChanOpen update, and we want to make sure the funding process is
|
||||||
|
Loading…
x
Reference in New Issue
Block a user