Skip to content

Commit d139088

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

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
@@ -419,6 +419,28 @@ func CreateTestChannels(t *testing.T, chanType channeldb.ChannelType,
419419
return channelAlice, channelBob, nil
420420
}
421421

422+
// initMusigNonce is used to manually setup musig2 nonces for a new channel,
423+
// outside the normal chan-reest flow.
424+
func initMusigNonce(chanA, chanB *LightningChannel) error {
425+
chanANonces, err := chanA.GenMusigNonces()
426+
if err != nil {
427+
return err
428+
}
429+
chanBNonces, err := chanB.GenMusigNonces()
430+
if err != nil {
431+
return err
432+
}
433+
434+
if err := chanA.InitRemoteMusigNonces(chanBNonces); err != nil {
435+
return err
436+
}
437+
if err := chanB.InitRemoteMusigNonces(chanANonces); err != nil {
438+
return err
439+
}
440+
441+
return nil
442+
}
443+
422444
// initRevocationWindows simulates a new channel being opened within the p2p
423445
// network by populating the initial revocation windows of the passed
424446
// commitment state machines.
@@ -427,19 +449,7 @@ func initRevocationWindows(chanA, chanB *LightningChannel) error {
427449
// either FundingLocked or ChannelReestablish by calling
428450
// InitRemoteMusigNonces for both sides.
429451
if chanA.channelState.ChanType.IsTaproot() {
430-
chanANonces, err := chanA.GenMusigNonces()
431-
if err != nil {
432-
return err
433-
}
434-
chanBNonces, err := chanB.GenMusigNonces()
435-
if err != nil {
436-
return err
437-
}
438-
439-
if err := chanA.InitRemoteMusigNonces(chanBNonces); err != nil {
440-
return err
441-
}
442-
if err := chanB.InitRemoteMusigNonces(chanANonces); err != nil {
452+
if err := initMusigNonce(chanA, chanB); err != nil {
443453
return err
444454
}
445455
}

0 commit comments

Comments
 (0)