Skip to content

Commit 5281998

Browse files
committed
lnwallet: extract initMusigNonce from initRevocationWindows
This'll be useful later to make some enhancements to the existing unit tests.
1 parent 69a1cf4 commit 5281998

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

lnwallet/test_utils.go

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,28 @@ func CreateTestChannels(t *testing.T, chanType channeldb.ChannelType,
435435
return channelAlice, channelBob, nil
436436
}
437437

438+
// initMusigNonce is used to manually setup musig2 nonces for a new channel,
439+
// outside the normal chan-reest flow.
440+
func initMusigNonce(chanA, chanB *LightningChannel) error {
441+
chanANonces, err := chanA.GenMusigNonces()
442+
if err != nil {
443+
return err
444+
}
445+
chanBNonces, err := chanB.GenMusigNonces()
446+
if err != nil {
447+
return err
448+
}
449+
450+
if err := chanA.InitRemoteMusigNonces(chanBNonces); err != nil {
451+
return err
452+
}
453+
if err := chanB.InitRemoteMusigNonces(chanANonces); err != nil {
454+
return err
455+
}
456+
457+
return nil
458+
}
459+
438460
// initRevocationWindows simulates a new channel being opened within the p2p
439461
// network by populating the initial revocation windows of the passed
440462
// commitment state machines.
@@ -443,19 +465,7 @@ func initRevocationWindows(chanA, chanB *LightningChannel) error {
443465
// either FundingLocked or ChannelReestablish by calling
444466
// InitRemoteMusigNonces for both sides.
445467
if chanA.channelState.ChanType.IsTaproot() {
446-
chanANonces, err := chanA.GenMusigNonces()
447-
if err != nil {
448-
return err
449-
}
450-
chanBNonces, err := chanB.GenMusigNonces()
451-
if err != nil {
452-
return err
453-
}
454-
455-
if err := chanA.InitRemoteMusigNonces(chanBNonces); err != nil {
456-
return err
457-
}
458-
if err := chanB.InitRemoteMusigNonces(chanANonces); err != nil {
468+
if err := initMusigNonce(chanA, chanB); err != nil {
459469
return err
460470
}
461471
}

0 commit comments

Comments
 (0)