From 8177fed3029199b6a821213d0a4ce3b2c8081141 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Wed, 1 Jul 2020 21:05:26 -0700 Subject: [PATCH] funding: allow incoming wumbo channel requests if wumbo is enabled --- fundingmanager.go | 9 +++-- fundingmanager_test.go | 81 ++++++++++++++++++++++++++++++++++++++++++ server.go | 1 + 3 files changed, 89 insertions(+), 2 deletions(-) diff --git a/fundingmanager.go b/fundingmanager.go index ebad44b6..aa3887ed 100644 --- a/fundingmanager.go +++ b/fundingmanager.go @@ -227,6 +227,10 @@ func newSerializedKey(pubKey *btcec.PublicKey) serializedPubKey { // within the configuration MUST be non-nil for the FundingManager to carry out // its duties. type fundingConfig struct { + // NoWumboChans indicates if we're to reject all incoming wumbo channel + // requests, and also reject all outgoing wumbo channel requests. + NoWumboChans bool + // IDKey is the PublicKey that is used to identify this node within the // Lightning Network. IDKey *btcec.PublicKey @@ -1236,8 +1240,9 @@ func (f *fundingManager) handleFundingOpen(fmsg *fundingOpenMsg) { } // We'll reject any request to create a channel that's above the - // current soft-limit for channel size. - if msg.FundingAmount > MaxFundingAmount { + // current soft-limit for channel size, but only if we're rejecting all + // wumbo channel initiations. + if f.cfg.NoWumboChans && msg.FundingAmount > MaxFundingAmount { f.failFundingFlow( fmsg.peer, fmsg.msg.PendingChannelID, lnwire.ErrChanTooLarge, diff --git a/fundingmanager_test.go b/fundingmanager_test.go index 4ea95fa5..9896563d 100644 --- a/fundingmanager_test.go +++ b/fundingmanager_test.go @@ -3176,3 +3176,84 @@ func TestGetUpfrontShutdownScript(t *testing.T) { }) } } + +func expectOpenChannelMsg(t *testing.T, msgChan chan lnwire.Message) *lnwire.OpenChannel { + var msg lnwire.Message + select { + case msg = <-msgChan: + case <-time.After(time.Second * 5): + t.Fatalf("node did not send OpenChannel message") + } + + openChannelReq, ok := msg.(*lnwire.OpenChannel) + if !ok { + errorMsg, gotError := msg.(*lnwire.Error) + if gotError { + t.Fatalf("expected OpenChannel to be sent "+ + "from bob, instead got error: %v", + errorMsg.Error()) + } + t.Fatalf("expected OpenChannel to be sent, instead got %T", + msg) + } + + return openChannelReq +} + +// TestWumboChannelConfig tests that the funding manager will respect the wumbo +// channel config param when creating or accepting new channels. +func TestWumboChannelConfig(t *testing.T) { + t.Parallel() + + // First we'll create a set of funding managers that will reject wumbo + // channels. + alice, bob := setupFundingManagers(t, func(cfg *fundingConfig) { + cfg.NoWumboChans = true + }) + + // If we attempt to initiate a new funding open request to Alice, + // that's below the wumbo channel mark, we should be able to start the + // funding process w/o issue. + updateChan := make(chan *lnrpc.OpenStatusUpdate) + errChan := make(chan error, 1) + initReq := &openChanReq{ + targetPubkey: bob.privKey.PubKey(), + chainHash: *activeNetParams.GenesisHash, + localFundingAmt: MaxFundingAmount, + pushAmt: lnwire.NewMSatFromSatoshis(0), + private: false, + updates: updateChan, + err: errChan, + } + + // We expect Bob to respond with an Accept channel message. + alice.fundingMgr.initFundingWorkflow(bob, initReq) + openChanMsg := expectOpenChannelMsg(t, alice.msgChan) + bob.fundingMgr.processFundingOpen(openChanMsg, alice) + assertFundingMsgSent(t, bob.msgChan, "AcceptChannel") + + // We'll now attempt to create a channel above the wumbo mark, which + // should be rejected. + initReq.localFundingAmt = btcutil.SatoshiPerBitcoin + + // After processing the funding open message, bob should respond with + // an error rejecting the channel. + alice.fundingMgr.initFundingWorkflow(bob, initReq) + openChanMsg = expectOpenChannelMsg(t, alice.msgChan) + bob.fundingMgr.processFundingOpen(openChanMsg, alice) + assertErrorSent(t, bob.msgChan) + + // Next, we'll re-create the funding managers, but this time allowing + // wumbo channels explicitly. + tearDownFundingManagers(t, alice, bob) + alice, bob = setupFundingManagers(t, func(cfg *fundingConfig) { + cfg.NoWumboChans = false + }) + + // We should now be able to initiate a wumbo channel funding w/o any + // issues. + alice.fundingMgr.initFundingWorkflow(bob, initReq) + openChanMsg = expectOpenChannelMsg(t, alice.msgChan) + bob.fundingMgr.processFundingOpen(openChanMsg, alice) + assertFundingMsgSent(t, bob.msgChan, "AcceptChannel") +} diff --git a/server.go b/server.go index c1dd7b05..612f2970 100644 --- a/server.go +++ b/server.go @@ -967,6 +967,7 @@ func newServer(cfg *Config, listenAddrs []net.Addr, chanDB *channeldb.DB, } s.fundingMgr, err = newFundingManager(fundingConfig{ + NoWumboChans: !cfg.ProtocolOptions.Wumbo(), IDKey: nodeKeyECDH.PubKey(), Wallet: cc.wallet, PublishTransaction: cc.wallet.PublishTransaction,