fundingmanager+server: adding ChannelAcceptor to the fundingmanager
This commit is contained in:
parent
c2a6c86e6b
commit
4d02100e12
@ -15,6 +15,7 @@ import (
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
"github.com/go-errors/errors"
|
||||
"github.com/lightningnetwork/lnd/chainntnfs"
|
||||
"github.com/lightningnetwork/lnd/chanacceptor"
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
"github.com/lightningnetwork/lnd/discovery"
|
||||
"github.com/lightningnetwork/lnd/htlcswitch"
|
||||
@ -338,6 +339,11 @@ type fundingConfig struct {
|
||||
// NotifyOpenChannelEvent informs the ChannelNotifier when channels
|
||||
// transition from pending open to open.
|
||||
NotifyOpenChannelEvent func(wire.OutPoint)
|
||||
|
||||
// OpenChannelPredicate is a predicate on the lnwire.OpenChannel message
|
||||
// and on the requesting node's public key that returns a bool which tells
|
||||
// the funding manager whether or not to accept the channel.
|
||||
OpenChannelPredicate chanacceptor.ChannelAcceptor
|
||||
}
|
||||
|
||||
// fundingManager acts as an orchestrator/bridge between the wallet's
|
||||
@ -1057,7 +1063,23 @@ func (f *fundingManager) handleFundingOpen(fmsg *fundingOpenMsg) {
|
||||
if f.cfg.RejectPush && msg.PushAmount > 0 {
|
||||
f.failFundingFlow(
|
||||
fmsg.peer, fmsg.msg.PendingChannelID,
|
||||
lnwallet.ErrNonZeroPushAmount())
|
||||
lnwallet.ErrNonZeroPushAmount(),
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
// Send the OpenChannel request to the ChannelAcceptor to determine whether
|
||||
// this node will accept the channel.
|
||||
chanReq := &chanacceptor.ChannelAcceptRequest{
|
||||
Node: fmsg.peer.IdentityKey(),
|
||||
OpenChanMsg: fmsg.msg,
|
||||
}
|
||||
|
||||
if !f.cfg.OpenChannelPredicate.Accept(chanReq) {
|
||||
f.failFundingFlow(
|
||||
fmsg.peer, fmsg.msg.PendingChannelID,
|
||||
fmt.Errorf("open channel request rejected"),
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -23,6 +23,7 @@ import (
|
||||
"github.com/btcsuite/btcutil"
|
||||
|
||||
"github.com/lightningnetwork/lnd/chainntnfs"
|
||||
"github.com/lightningnetwork/lnd/chanacceptor"
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
"github.com/lightningnetwork/lnd/discovery"
|
||||
"github.com/lightningnetwork/lnd/htlcswitch"
|
||||
@ -281,6 +282,8 @@ func createTestFundingManager(t *testing.T, privKey *btcec.PrivateKey,
|
||||
|
||||
var chanIDSeed [32]byte
|
||||
|
||||
chainedAcceptor := chanacceptor.NewChainedAcceptor()
|
||||
|
||||
fundingCfg := fundingConfig{
|
||||
IDKey: privKey.PubKey(),
|
||||
Wallet: lnw,
|
||||
@ -364,6 +367,7 @@ func createTestFundingManager(t *testing.T, privKey *btcec.PrivateKey,
|
||||
ReservationTimeout: 1 * time.Nanosecond,
|
||||
MaxPendingChannels: DefaultMaxPendingChannels,
|
||||
NotifyOpenChannelEvent: func(wire.OutPoint) {},
|
||||
OpenChannelPredicate: chainedAcceptor,
|
||||
}
|
||||
|
||||
for _, op := range options {
|
||||
@ -414,6 +418,8 @@ func recreateAliceFundingManager(t *testing.T, alice *testNode) {
|
||||
|
||||
oldCfg := alice.fundingMgr.cfg
|
||||
|
||||
chainedAcceptor := chanacceptor.NewChainedAcceptor()
|
||||
|
||||
f, err := newFundingManager(fundingConfig{
|
||||
IDKey: oldCfg.IDKey,
|
||||
Wallet: oldCfg.Wallet,
|
||||
@ -458,6 +464,7 @@ func recreateAliceFundingManager(t *testing.T, alice *testNode) {
|
||||
},
|
||||
ZombieSweeperInterval: oldCfg.ZombieSweeperInterval,
|
||||
ReservationTimeout: oldCfg.ReservationTimeout,
|
||||
OpenChannelPredicate: chainedAcceptor,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("failed recreating aliceFundingManager: %v", err)
|
||||
|
2
lnd.go
2
lnd.go
@ -496,7 +496,7 @@ func Main(lisCfg ListenerCfg) error {
|
||||
// connections.
|
||||
server, err := newServer(
|
||||
cfg.Listeners, chanDB, towerClientDB, activeChainControl,
|
||||
idPrivKey, walletInitParams.ChansToRestore,
|
||||
idPrivKey, walletInitParams.ChansToRestore, chainedAcceptor,
|
||||
)
|
||||
if err != nil {
|
||||
err := fmt.Errorf("Unable to create server: %v", err)
|
||||
|
@ -28,6 +28,7 @@ import (
|
||||
sphinx "github.com/lightningnetwork/lightning-onion"
|
||||
"github.com/lightningnetwork/lnd/autopilot"
|
||||
"github.com/lightningnetwork/lnd/brontide"
|
||||
"github.com/lightningnetwork/lnd/chanacceptor"
|
||||
"github.com/lightningnetwork/lnd/chanbackup"
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
"github.com/lightningnetwork/lnd/channelnotifier"
|
||||
@ -297,7 +298,8 @@ func noiseDial(idPriv *btcec.PrivateKey) func(net.Addr) (net.Conn, error) {
|
||||
func newServer(listenAddrs []net.Addr, chanDB *channeldb.DB,
|
||||
towerClientDB *wtdb.ClientDB, cc *chainControl,
|
||||
privKey *btcec.PrivateKey,
|
||||
chansToRestore walletunlocker.ChannelsToRecover) (*server, error) {
|
||||
chansToRestore walletunlocker.ChannelsToRecover,
|
||||
chanPredicate chanacceptor.ChannelAcceptor) (*server, error) {
|
||||
|
||||
var err error
|
||||
|
||||
@ -908,6 +910,7 @@ func newServer(listenAddrs []net.Addr, chanDB *channeldb.DB,
|
||||
if _, err := rand.Read(chanIDSeed[:]); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
s.fundingMgr, err = newFundingManager(fundingConfig{
|
||||
IDKey: privKey.PubKey(),
|
||||
Wallet: cc.wallet,
|
||||
@ -1069,6 +1072,7 @@ func newServer(listenAddrs []net.Addr, chanDB *channeldb.DB,
|
||||
MaxPendingChannels: cfg.MaxPendingChannels,
|
||||
RejectPush: cfg.RejectPush,
|
||||
NotifyOpenChannelEvent: s.channelNotifier.NotifyOpenChannelEvent,
|
||||
OpenChannelPredicate: chanPredicate,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
Loading…
Reference in New Issue
Block a user