lnwallet: model the aux sig blob faithfully in tests
What changed, and why it matters
This commit fixes test code in LND's Lightning wallet so that mock auxiliary (taproot/asset channel) signatures behave more like the real production code. The changes make tests correctly preserve the aux signer across channel restarts and carry the aux signature blob through retransmitted commitment messages. There is no direct production code change; it is a test-harness hardening patch that prevents future bugs in the aux-signature protocol from being hidden by inaccurate test mocks.
No production deployment action required. Reviewers should verify that the updated default mock now exercises the per-HTLC slot pairing correctly and that any future production changes to aux signature handling are run against these hardened tests.
Security signals we found
Test-only fix that removes false negatives in aux-signature handling
Restart helper previously dropped aux signer, which could mask protocol failures in tests
Mock unpack previously returned a single slot regardless of HTLC count, hiding index-mismatch bugs
Retransmitted commitment messages now carry the aux blob in tests, matching link-layer production behavior
Evidence from the diff
The patch updates three test helpers in lnwallet: (1) MockAuxSigner.PackSigs/UnpackSigs now supports function-based returns and the default mock encodes the number of HTLC slots into the dummy TLV blob, returning exactly one slot per HTLC on unpack instead of always one slot; (2) restartChannel now re-attaches the channel’s AuxLeafStore and AuxSigner via ChannelOpt so restarts do not silently drop aux components; (3) two channel-sync tests now serialize the CustomRecords aux blob from the retransmitted CommitSig wire message and pass it into the rebuilt CommitSigs. These are test-only corrections that align the test environment with production behavior around custom records and aux signatures.
Changed components
lnwallet/channel_test.golnwallet/mock.golnwallet/test_utils.goInspect captured patch +102 / −9
### lnwallet/channel_test.go
@@ -3244,9 +3244,21 @@ func restartChannel(channelOld *LightningChannel) (*LightningChannel, error) {
return nil, err
}
+ // The aux components are re-applied every time a channel is loaded in
+ // production, so a restart must not silently drop them here either.
+ // Otherwise the restarted side stops producing aux signatures while
+ // its peer still expects them.
+ var chanOpts []ChannelOpt
+ channelOld.leafStore.WhenSome(func(s AuxLeafStore) {
+ chanOpts = append(chanOpts, WithLeafStore(s))
+ })
+ channelOld.auxSigner.WhenSome(func(s AuxSigner) {
+ chanOpts = append(chanOpts, WithAuxSigner(s))
+ })
+
channelNew, err := NewLightningChannel(
channelOld.Signer, nodeChannels[0],
- channelOld.sigPool,
+ channelOld.sigPool, chanOpts...,
)
if err != nil {
return nil, err
@@ -3490,10 +3502,16 @@ func testChanSyncOweCommitment(t *testing.T,
// At this point, we should be able to resume the prior state update
// without any issues, resulting in Alice settling the 3 htlc's, and
// adding one of her own.
+ // The link carries the aux signatures across from the wire message, so
+ // a faithful simulation of the restart has to do so as well.
+ aliceReAuxBlob, err := aliceReCommitSig.CustomRecords.Serialize()
+ require.NoError(t, err, "unable to serialize aux sig blob")
+
err = bobChannel.ReceiveNewCommitment(&CommitSigs{
CommitSig: aliceReCommitSig.CommitSig,
HtlcSigs: aliceReCommitSig.HtlcSigs,
PartialSig: aliceReCommitSig.PartialSig,
+ AuxSigBlob: aliceReAuxBlob,
})
require.NoError(t, err, "bob unable to process alice's commitment")
bobRevocation, _, _, err := bobChannel.RevokeCurrentCommitment()
@@ -4826,10 +4844,14 @@ func testChanSyncOweRevocationAndCommitForceTransition(t *testing.T,
// message to Bob.
_, _, err = aliceChannel.ReceiveRevocation(bobRevocation)
require.NoError(t, err, "alice unable to recv revocation")
+ bobAuxBlob, err := bobSigMsg.CustomRecords.Serialize()
+ require.NoError(t, err, "unable to serialize aux sig blob")
+
err = aliceChannel.ReceiveNewCommitment(&CommitSigs{
CommitSig: bobSigMsg.CommitSig,
HtlcSigs: bobSigMsg.HtlcSigs,
PartialSig: bobSigMsg.PartialSig,
+ AuxSigBlob: bobAuxBlob,
})
require.NoError(t, err, "alice unable to rev bob's commitment")
aliceRevocation, _, _, err = aliceChannel.RevokeCurrentCommitment()
### lnwallet/mock.go
@@ -511,13 +511,27 @@ func (a *MockAuxSigner) SubmitSecondLevelSigBatch(chanState AuxChanState,
return args.Error(0)
}
+// PackSigsFunc packs aux signatures into a blob. A test can register one of
+// these with the mock instead of a fixed value, so that the packed blob can
+// depend on the signatures handed in. That matters because a real aux signer
+// emits exactly one slot per HTLC.
+type PackSigsFunc func([]fn.Option[tlv.Blob]) fn.Result[fn.Option[tlv.Blob]]
+
+// UnpackSigsFunc is the counterpart of PackSigsFunc, recovering the per-HTLC
+// slots from a packed blob.
+type UnpackSigsFunc func(fn.Option[tlv.Blob]) fn.Result[[]fn.Option[tlv.Blob]]
+
// PackSigs takes a series of aux signatures and packs them into a
// single blob that can be sent alongside the CommitSig messages.
func (a *MockAuxSigner) PackSigs(
sigs []fn.Option[tlv.Blob]) fn.Result[fn.Option[tlv.Blob]] {
args := a.Called(sigs)
+ if f, ok := args.Get(0).(PackSigsFunc); ok {
+ return f(sigs)
+ }
+
return args.Get(0).(fn.Result[fn.Option[tlv.Blob]])
}
@@ -528,6 +542,10 @@ func (a *MockAuxSigner) UnpackSigs(
args := a.Called(sigs)
+ if f, ok := args.Get(0).(UnpackSigsFunc); ok {
+ return f(sigs)
+ }
+
return args.Get(0).(fn.Result[[]fn.Option[tlv.Blob]])
}
### lnwallet/test_utils.go
@@ -606,14 +606,67 @@ func NewDefaultAuxSignerMock(t *testing.T) *MockAuxSigner {
"SubmitSecondLevelSigBatch", mock.Anything, mock.Anything,
mock.Anything,
).Return(nil)
- auxSigner.On(
- "PackSigs", mock.Anything,
- ).Return(fn.Ok(fn.Some(sigBlobBuf.Bytes())))
- auxSigner.On(
- "UnpackSigs", mock.Anything,
- ).Return(fn.Ok([]fn.Option[tlv.Blob]{
- fn.Some(sigBlobBuf.Bytes()),
- }))
+ // A real aux signer emits exactly one slot per HTLC and recovers the
+ // same number of slots when unpacking. Code that pairs the unpacked
+ // slots with HTLCs by index relies on that, so the default mock has to
+ // honour it rather than always reporting a single slot regardless of
+ // how many HTLCs there are.
+ //
+ // The packed blob has to stay a canonical TLV stream, since it is
+ // parsed into custom records on the way out, so the slot count is
+ // carried in the dummy record's value rather than by repeating it.
+ packSlotCount := func(numSlots uint16) fn.Result[fn.Option[tlv.Blob]] {
+ rec := tlv.NewPrimitiveRecord[tlv.TlvType65634](numSlots)
+ stream, err := tlv.NewStream(rec.Record())
+ if err != nil {
+ return fn.Err[fn.Option[tlv.Blob]](err)
+ }
+
+ var buf bytes.Buffer
+ if err := stream.Encode(&buf); err != nil {
+ return fn.Err[fn.Option[tlv.Blob]](err)
+ }
+
+ return fn.Ok(fn.Some(buf.Bytes()))
+ }
+
+ auxSigner.On("PackSigs", mock.Anything).Return(
+ PackSigsFunc(func(
+ sigs []fn.Option[tlv.Blob],
+ ) fn.Result[fn.Option[tlv.Blob]] {
+
+ return packSlotCount(uint16(len(sigs)))
+ }),
+ )
+ auxSigner.On("UnpackSigs", mock.Anything).Return(
+ UnpackSigsFunc(func(
+ packed fn.Option[tlv.Blob],
+ ) fn.Result[[]fn.Option[tlv.Blob]] {
+
+ blob := packed.UnwrapOr(nil)
+ if len(blob) == 0 {
+ return fn.Ok[[]fn.Option[tlv.Blob]](nil)
+ }
+
+ rec := tlv.ZeroRecordT[tlv.TlvType65634, uint16]()
+ stream, err := tlv.NewStream(rec.Record())
+ if err != nil {
+ return fn.Err[[]fn.Option[tlv.Blob]](err)
+ }
+ if err := stream.Decode(
+ bytes.NewReader(blob),
+ ); err != nil {
+ return fn.Err[[]fn.Option[tlv.Blob]](err)
+ }
+
+ slots := make([]fn.Option[tlv.Blob], rec.Val)
+ for idx := range slots {
+ slots[idx] = fn.Some(sigBlobBuf.Bytes())
+ }
+
+ return fn.Ok(slots)
+ }),
+ )
auxSigner.On(
"VerifySecondLevelSigs", mock.Anything, mock.Anything,
mock.Anything,Why this scored 26/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.