4848 //
4949 // NOTE: for itest, this value is changed to 10ms.
5050 checkPeerChannelReadyInterval = 1 * time .Second
51+
52+ // errNoLocalNonce is returned when a local nonce is not found in the
53+ // expected TLV.
54+ errNoLocalNonce = fmt .Errorf ("local nonce not found" )
55+
56+ // errNoPartialSig is returned when a partial sig is not found in the
57+ // expected TLV.
58+ errNoPartialSig = fmt .Errorf ("partial sig not found" )
5159)
5260
5361// WriteOutpoint writes an outpoint to an io.Writer. This is not the same as
@@ -952,6 +960,28 @@ func (f *Manager) failFundingFlow(peer lnpeer.Peer, cid *chanIdentifier,
952960 }
953961}
954962
963+ // sendWarning sends a new warning message to the target peer, targeting the
964+ // specified cid with the passed funding error.
965+ func (f * Manager ) sendWarning (peer lnpeer.Peer , cid * chanIdentifier ,
966+ fundingErr error ) {
967+
968+ msg := fundingErr .Error ()
969+
970+ errMsg := & lnwire.Warning {
971+ ChanID : cid .tempChanID ,
972+ Data : lnwire .WarningData (msg ),
973+ }
974+
975+ log .Debugf ("Sending funding warning to peer (%x): %v" ,
976+ peer .IdentityKey ().SerializeCompressed (),
977+ spew .Sdump (errMsg ),
978+ )
979+
980+ if err := peer .SendMessage (false , errMsg ); err != nil {
981+ log .Errorf ("unable to send error message to peer %v" , err )
982+ }
983+ }
984+
955985// reservationCoordinator is the primary goroutine tasked with progressing the
956986// funding workflow between the wallet, and any outside peers or local callers.
957987//
@@ -1801,17 +1831,17 @@ func (f *Manager) fundeeProcessOpenChannel(peer lnpeer.Peer,
18011831 }
18021832
18031833 if resCtx .reservation .IsTaproot () {
1804- if msg . LocalNonce == nil {
1805- err := fmt . Errorf ( "local nonce not set for taproot " +
1806- "chan" )
1807- log . Error ( err )
1808- f .failFundingFlow (
1809- resCtx . peer , cid , err ,
1810- )
1834+ localNonce , err := msg . LocalNonce . UnwrapOrErrV ( errNoLocalNonce )
1835+ if err != nil {
1836+ log . Error ( errNoLocalNonce )
1837+
1838+ f .failFundingFlow (resCtx . peer , cid , errNoLocalNonce )
1839+
1840+ return
18111841 }
18121842
18131843 remoteContribution .LocalNonce = & musig2.Nonces {
1814- PubNonce : * msg . LocalNonce ,
1844+ PubNonce : localNonce ,
18151845 }
18161846 }
18171847
@@ -1827,13 +1857,6 @@ func (f *Manager) fundeeProcessOpenChannel(peer lnpeer.Peer,
18271857 log .Debugf ("Remote party accepted commitment constraints: %v" ,
18281858 spew .Sdump (remoteContribution .ChannelConfig .ChannelConstraints ))
18291859
1830- var localNonce * lnwire.Musig2Nonce
1831- if commitType .IsTaproot () {
1832- localNonce = (* lnwire .Musig2Nonce )(
1833- & ourContribution .LocalNonce .PubNonce ,
1834- )
1835- }
1836-
18371860 // With the initiator's contribution recorded, respond with our
18381861 // contribution in the next message of the workflow.
18391862 fundingAccept := lnwire.AcceptChannel {
@@ -1854,7 +1877,12 @@ func (f *Manager) fundeeProcessOpenChannel(peer lnpeer.Peer,
18541877 UpfrontShutdownScript : ourContribution .UpfrontShutdown ,
18551878 ChannelType : chanType ,
18561879 LeaseExpiry : msg .LeaseExpiry ,
1857- LocalNonce : localNonce ,
1880+ }
1881+
1882+ if commitType .IsTaproot () {
1883+ fundingAccept .LocalNonce = lnwire .SomeMusig2Nonce (
1884+ ourContribution .LocalNonce .PubNonce ,
1885+ )
18581886 }
18591887
18601888 if err := peer .SendMessage (true , & fundingAccept ); err != nil {
@@ -2044,15 +2072,17 @@ func (f *Manager) funderProcessAcceptChannel(peer lnpeer.Peer,
20442072 }
20452073
20462074 if resCtx .reservation .IsTaproot () {
2047- if msg .LocalNonce == nil {
2048- err := fmt .Errorf ("local nonce not set for taproot " +
2049- "chan" )
2050- log .Error (err )
2051- f .failFundingFlow (resCtx .peer , cid , err )
2075+ localNonce , err := msg .LocalNonce .UnwrapOrErrV (errNoLocalNonce )
2076+ if err != nil {
2077+ log .Error (errNoLocalNonce )
2078+
2079+ f .failFundingFlow (resCtx .peer , cid , errNoLocalNonce )
2080+
2081+ return
20522082 }
20532083
20542084 remoteContribution .LocalNonce = & musig2.Nonces {
2055- PubNonce : * msg . LocalNonce ,
2085+ PubNonce : localNonce ,
20562086 }
20572087 }
20582088
@@ -2263,7 +2293,9 @@ func (f *Manager) continueFundingAccept(resCtx *reservationWithCtx,
22632293 return
22642294 }
22652295
2266- fundingCreated .PartialSig = partialSig .ToWireSig ()
2296+ fundingCreated .PartialSig = lnwire .MaybePartialSigWithNonce (
2297+ partialSig .ToWireSig (),
2298+ )
22672299 } else {
22682300 fundingCreated .CommitSig , err = lnwire .NewSigFromSignature (sig )
22692301 if err != nil {
@@ -2317,14 +2349,15 @@ func (f *Manager) fundeeProcessFundingCreated(peer lnpeer.Peer,
23172349 // our internal input.Signature type.
23182350 var commitSig input.Signature
23192351 if resCtx .reservation .IsTaproot () {
2320- if msg . PartialSig == nil {
2321- log . Errorf ( "partial sig not included: %v" , err )
2352+ partialSig , err := msg . PartialSig . UnwrapOrErrV ( errNoPartialSig )
2353+ if err != nil {
23222354 f .failFundingFlow (peer , cid , err )
2355+
23232356 return
23242357 }
23252358
23262359 commitSig = new (lnwallet.MusigPartialSig ).FromWireSig (
2327- msg . PartialSig ,
2360+ & partialSig ,
23282361 )
23292362 } else {
23302363 commitSig , err = msg .CommitSig .ToSignature ()
@@ -2408,7 +2441,9 @@ func (f *Manager) fundeeProcessFundingCreated(peer lnpeer.Peer,
24082441 return
24092442 }
24102443
2411- fundingSigned .PartialSig = partialSig .ToWireSig ()
2444+ fundingSigned .PartialSig = lnwire .MaybePartialSigWithNonce (
2445+ partialSig .ToWireSig (),
2446+ )
24122447 } else {
24132448 fundingSigned .CommitSig , err = lnwire .NewSigFromSignature (sig )
24142449 if err != nil {
@@ -2565,14 +2600,15 @@ func (f *Manager) funderProcessFundingSigned(peer lnpeer.Peer,
25652600 // our internal input.Signature type.
25662601 var commitSig input.Signature
25672602 if resCtx .reservation .IsTaproot () {
2568- if msg . PartialSig == nil {
2569- log . Errorf ( "partial sig not included: %v" , err )
2603+ partialSig , err := msg . PartialSig . UnwrapOrErrV ( errNoPartialSig )
2604+ if err != nil {
25702605 f .failFundingFlow (peer , cid , err )
2606+
25712607 return
25722608 }
25732609
25742610 commitSig = new (lnwallet.MusigPartialSig ).FromWireSig (
2575- msg . PartialSig ,
2611+ & partialSig ,
25762612 )
25772613 } else {
25782614 commitSig , err = msg .CommitSig .ToSignature ()
@@ -3153,8 +3189,8 @@ func (f *Manager) sendChannelReady(completeChan *channeldb.OpenChannel,
31533189 }
31543190 f .nonceMtx .Unlock ()
31553191
3156- channelReadyMsg .NextLocalNonce = ( * lnwire .Musig2Nonce ) (
3157- & localNonce .PubNonce ,
3192+ channelReadyMsg .NextLocalNonce = lnwire .SomeMusig2Nonce (
3193+ localNonce .PubNonce ,
31583194 )
31593195 }
31603196
@@ -3824,11 +3860,9 @@ func (f *Manager) handleChannelReady(peer lnpeer.Peer, //nolint:funlen
38243860 channelReadyMsg .AliasScid = & alias
38253861
38263862 if firstVerNonce != nil {
3827- wireNonce := ( * lnwire .Musig2Nonce )(
3828- & firstVerNonce .PubNonce ,
3863+ channelReadyMsg . NextLocalNonce = lnwire .SomeMusig2Nonce ( //nolint:lll
3864+ firstVerNonce .PubNonce ,
38293865 )
3830-
3831- channelReadyMsg .NextLocalNonce = wireNonce
38323866 }
38333867
38343868 err = peer .SendMessage (true , channelReadyMsg )
@@ -3873,16 +3907,21 @@ func (f *Manager) handleChannelReady(peer lnpeer.Peer, //nolint:funlen
38733907 log .Infof ("ChanID(%v): applying local+remote musig2 nonces" ,
38743908 chanID )
38753909
3876- if msg .NextLocalNonce == nil {
3877- log .Errorf ("remote nonces are nil" )
3910+ remoteNonce , err := msg .NextLocalNonce .UnwrapOrErrV (
3911+ errNoLocalNonce ,
3912+ )
3913+ if err != nil {
3914+ cid := newChanIdentifier (msg .ChanID )
3915+ f .sendWarning (peer , cid , err )
3916+
38783917 return
38793918 }
38803919
38813920 chanOpts = append (
38823921 chanOpts ,
38833922 lnwallet .WithLocalMusigNonces (localNonce ),
38843923 lnwallet .WithRemoteMusigNonces (& musig2.Nonces {
3885- PubNonce : * msg . NextLocalNonce ,
3924+ PubNonce : remoteNonce ,
38863925 }),
38873926 )
38883927 }
@@ -4714,13 +4753,6 @@ func (f *Manager) handleInitFundingMsg(msg *InitFundingMsg) {
47144753 log .Infof ("Starting funding workflow with %v for pending_id(%x), " +
47154754 "committype=%v" , msg .Peer .Address (), chanID , commitType )
47164755
4717- var localNonce * lnwire.Musig2Nonce
4718- if commitType .IsTaproot () {
4719- localNonce = (* lnwire .Musig2Nonce )(
4720- & ourContribution .LocalNonce .PubNonce ,
4721- )
4722- }
4723-
47244756 fundingOpen := lnwire.OpenChannel {
47254757 ChainHash : * f .cfg .Wallet .Cfg .NetParams .GenesisHash ,
47264758 PendingChannelID : chanID ,
@@ -4743,8 +4775,14 @@ func (f *Manager) handleInitFundingMsg(msg *InitFundingMsg) {
47434775 UpfrontShutdownScript : shutdown ,
47444776 ChannelType : chanType ,
47454777 LeaseExpiry : leaseExpiry ,
4746- LocalNonce : localNonce ,
47474778 }
4779+
4780+ if commitType .IsTaproot () {
4781+ fundingOpen .LocalNonce = lnwire .SomeMusig2Nonce (
4782+ ourContribution .LocalNonce .PubNonce ,
4783+ )
4784+ }
4785+
47484786 if err := msg .Peer .SendMessage (true , & fundingOpen ); err != nil {
47494787 e := fmt .Errorf ("unable to send funding request message: %v" ,
47504788 err )
0 commit comments