@@ -99,7 +99,6 @@ const (
9999 // you and limitless channel size (apart from 21 million cap).
100100 MaxBtcFundingAmountWumbo = btcutil .Amount (1000000000 )
101101
102- // TODO(roasbeef): tune.
103102 msgBufferSize = 50
104103
105104 // MaxWaitNumBlocksFundingConf is the maximum number of blocks to wait
@@ -1622,11 +1621,14 @@ func (f *Manager) fundeeProcessOpenChannel(peer lnpeer.Peer,
16221621 // At this point, if we have an AuxFundingController active, we'll
16231622 // check to see if we have a special tapscript root to use in our
16241623 // musig2 funding output.
1625- tapscriptRoot := fn .MapOption (
1626- func (a AuxFundingController ) fn.Option [chainhash.Hash ] {
1627- return a .DeriveTapscriptRoot (msg .PendingChannelID )
1628- },
1629- )(f .cfg .AuxFundingController )
1624+ tapscriptRoot , err := deriveTapscriptRoot (
1625+ f .cfg .AuxFundingController , msg .PendingChannelID ,
1626+ )
1627+ if err != nil {
1628+ err = fmt .Errorf ("error deriving tapscript root: %w" , err )
1629+ log .Error (err )
1630+ f .failFundingFlow (peer , cid , err )
1631+ }
16301632
16311633 req := & lnwallet.InitFundingReserveMsg {
16321634 ChainHash : & msg .ChainHash ,
@@ -1644,7 +1646,7 @@ func (f *Manager) fundeeProcessOpenChannel(peer lnpeer.Peer,
16441646 ZeroConf : zeroConf ,
16451647 OptionScidAlias : scid ,
16461648 ScidAliasFeature : scidFeatureVal ,
1647- TapscriptRoot : fn . FlattenOption ( tapscriptRoot ) ,
1649+ TapscriptRoot : tapscriptRoot ,
16481650 }
16491651
16501652 reservation , err := f .cfg .Wallet .InitChannelReservation (req )
@@ -2241,10 +2243,27 @@ func (f *Manager) waitForPsbt(intent *chanfunding.PsbtIntent,
22412243 return
22422244 }
22432245
2246+ // At this point, we'll see if there's an AuxFundingDesc we
2247+ // need to deliver so the funding process can continue
2248+ // properly.
2249+ chanState := resCtx .reservation .ChanState ()
2250+ localKeys , remoteKeys := resCtx .reservation .CommitmentKeyRings ()
2251+ auxFundingDesc , err := descFromPendingChanID (
2252+ f .cfg .AuxFundingController , cid .tempChanID , chanState ,
2253+ * localKeys , * remoteKeys , true ,
2254+ )
2255+ if err != nil {
2256+ failFlow ("error continuing PSBT flow" , err )
2257+ return
2258+ }
2259+
22442260 // A non-nil error means we can continue the funding flow.
22452261 // Notify the wallet so it can prepare everything we need to
22462262 // continue.
2247- err = resCtx .reservation .ProcessPsbt ()
2263+ //
2264+ // We'll also pass along the aux funding controller as well,
2265+ // which may be used to help process the finalized PSBT.
2266+ err = resCtx .reservation .ProcessPsbt (auxFundingDesc )
22482267 if err != nil {
22492268 failFlow ("error continuing PSBT flow" , err )
22502269 return
@@ -2253,8 +2272,8 @@ func (f *Manager) waitForPsbt(intent *chanfunding.PsbtIntent,
22532272 // We are now ready to continue the funding flow.
22542273 f .continueFundingAccept (resCtx , cid )
22552274
2256- // Handle a server shutdown as well because the reservation won't
2257- // survive a restart as it's in memory only.
2275+ // Handle a server shutdown as well because the reservation won't
2276+ // survive a restart as it's in memory only.
22582277 case <- f .quit :
22592278 log .Errorf ("Unable to handle funding accept message " +
22602279 "for peer_key=%x, pending_chan_id=%x: funding manager " +
@@ -2308,6 +2327,10 @@ func (f *Manager) continueFundingAccept(resCtx *reservationWithCtx,
23082327 // funding flow fails.
23092328 cid .setChanID (channelID )
23102329
2330+ // Now that we're ready to resume the funding flow, we'll call into the
2331+ // aux controller with the final funding details so we can obtain the
2332+ // funding descs we need.
2333+
23112334 // Send the FundingCreated msg.
23122335 fundingCreated := & lnwire.FundingCreated {
23132336 PendingChannelID : cid .tempChanID ,
@@ -2370,7 +2393,6 @@ func (f *Manager) fundeeProcessFundingCreated(peer lnpeer.Peer,
23702393 // final funding transaction, as well as a signature for our version of
23712394 // the commitment transaction. So at this point, we can validate the
23722395 // initiator's commitment transaction, then send our own if it's valid.
2373- // TODO(roasbeef): make case (p vs P) consistent throughout
23742396 fundingOut := msg .FundingPoint
23752397 log .Infof ("completing pending_id(%x) with ChannelPoint(%v)" ,
23762398 pendingChanID [:], fundingOut )
@@ -2402,16 +2424,33 @@ func (f *Manager) fundeeProcessFundingCreated(peer lnpeer.Peer,
24022424 }
24032425 }
24042426
2427+ // At this point, we'll see if there's an AuxFundingDesc we need to
2428+ // deliver so the funding process can continue properly.
2429+ chanState := resCtx .reservation .ChanState ()
2430+ localKeys , remoteKeys := resCtx .reservation .CommitmentKeyRings ()
2431+ auxFundingDesc , err := descFromPendingChanID (
2432+ f .cfg .AuxFundingController , cid .tempChanID , chanState ,
2433+ * localKeys , * remoteKeys , true ,
2434+ )
2435+ if err != nil {
2436+ log .Errorf ("error continuing PSBT flow: %v" , err )
2437+ f .failFundingFlow (peer , cid , err )
2438+ return
2439+ }
2440+
24052441 // With all the necessary data available, attempt to advance the
24062442 // funding workflow to the next stage. If this succeeds then the
24072443 // funding transaction will broadcast after our next message.
24082444 // CompleteReservationSingle will also mark the channel as 'IsPending'
24092445 // in the database.
2446+ //
2447+ // We'll also directly pass in the AuxFundiner controller as well,
2448+ // which may be used by the reservation system to finalize funding our
2449+ // side.
24102450 completeChan , err := resCtx .reservation .CompleteReservationSingle (
2411- & fundingOut , commitSig ,
2451+ & fundingOut , commitSig , auxFundingDesc ,
24122452 )
24132453 if err != nil {
2414- // TODO(roasbeef): better error logging: peerID, channelID, etc.
24152454 log .Errorf ("unable to complete single reservation: %v" , err )
24162455 f .failFundingFlow (peer , cid , err )
24172456 return
@@ -2722,9 +2761,6 @@ func (f *Manager) funderProcessFundingSigned(peer lnpeer.Peer,
27222761
27232762 // Send an update to the upstream client that the negotiation process
27242763 // is over.
2725- //
2726- // TODO(roasbeef): add abstraction over updates to accommodate
2727- // long-polling, or SSE, etc.
27282764 upd := & lnrpc.OpenStatusUpdate {
27292765 Update : & lnrpc.OpenStatusUpdate_ChanPending {
27302766 ChanPending : & lnrpc.PendingUpdate {
@@ -4429,7 +4465,6 @@ func (f *Manager) announceChannel(localIDKey, remoteIDKey *btcec.PublicKey,
44294465
44304466// InitFundingWorkflow sends a message to the funding manager instructing it
44314467// to initiate a single funder workflow with the source peer.
4432- // TODO(roasbeef): re-visit blocking nature..
44334468func (f * Manager ) InitFundingWorkflow (msg * InitFundingMsg ) {
44344469 f .fundingRequests <- msg
44354470}
@@ -4622,11 +4657,14 @@ func (f *Manager) handleInitFundingMsg(msg *InitFundingMsg) {
46224657 // At this point, if we have an AuxFundingController active, we'll
46234658 // check to see if we have a special tapscript root to use in our
46244659 // musig2 funding output.
4625- tapscriptRoot := fn .MapOption (
4626- func (a AuxFundingController ) fn.Option [chainhash.Hash ] {
4627- return a .DeriveTapscriptRoot (chanID )
4628- },
4629- )(f .cfg .AuxFundingController )
4660+ tapscriptRoot , err := deriveTapscriptRoot (
4661+ f .cfg .AuxFundingController , chanID ,
4662+ )
4663+ if err != nil {
4664+ err = fmt .Errorf ("error deriving tapscript root: %w" , err )
4665+ msg .Err <- err
4666+ return
4667+ }
46304668
46314669 req := & lnwallet.InitFundingReserveMsg {
46324670 ChainHash : & msg .ChainHash ,
@@ -4651,7 +4689,7 @@ func (f *Manager) handleInitFundingMsg(msg *InitFundingMsg) {
46514689 OptionScidAlias : scid ,
46524690 ScidAliasFeature : scidFeatureVal ,
46534691 Memo : msg .Memo ,
4654- TapscriptRoot : fn . FlattenOption ( tapscriptRoot ) ,
4692+ TapscriptRoot : tapscriptRoot ,
46554693 }
46564694
46574695 reservation , err := f .cfg .Wallet .InitChannelReservation (req )
0 commit comments