Skip to content

Commit c72fde0

Browse files
committed
tapchannelmsg: include stxo flag in commitment blob
We extend the commitment blob to also store a flag, indicating whether STXO was active when that commitment was created. This can be useful for future sweeps that need to know whether that commitment used stxo alt leaves, which affects the reconstruction of the tap commitment.
1 parent a6ab848 commit c72fde0

File tree

7 files changed

+35
-10
lines changed

7 files changed

+35
-10
lines changed

rfq/manager_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ func createChannelWithCustomData(t *testing.T, id asset.ID, localBalance,
111111
),
112112
},
113113
nil, nil, lnwallet.CommitAuxLeaves{},
114+
false,
114115
),
115116
OpenChan: *tpchmsg.NewOpenChannel(
116117
[]*tpchmsg.AssetOutput{

tapchannel/auf_leaf_signer_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func setupAuxLeafSigner(t *testing.T, numJobs int32) (*AuxLeafSigner,
111111
}
112112

113113
com := cmsg.NewCommitment(
114-
nil, nil, outgoingHtlcs, nil, lnwallet.CommitAuxLeaves{},
114+
nil, nil, outgoingHtlcs, nil, lnwallet.CommitAuxLeaves{}, false,
115115
)
116116
cancelChan := make(chan struct{})
117117

tapchannel/aux_funding_controller.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,7 @@ func newCommitBlobAndLeaves(pendingFunding *pendingAssetFunding,
587587
// needs the sum of the remote+local assets, so we'll populate that.
588588
fakePrevState := cmsg.NewCommitment(
589589
localAssets, remoteAssets, nil, nil, lnwallet.CommitAuxLeaves{},
590+
stxo,
590591
)
591592

592593
// Just like above, we don't have a real HTLC view here, so we'll pass

tapchannel/commitment.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ func GenerateCommitmentAllocations(prevState *cmsg.Commitment,
651651
// Next, we can convert the allocations to auxiliary leaves and from
652652
// those construct our Commitment struct that will in the end also hold
653653
// our proof suffixes.
654-
newCommitment, err := ToCommitment(allocations, vPackets)
654+
newCommitment, err := ToCommitment(allocations, vPackets, stxo)
655655
if err != nil {
656656
return nil, nil, fmt.Errorf("unable to convert to commitment: "+
657657
"%w", err)
@@ -1155,7 +1155,7 @@ func LeavesFromTapscriptScriptTree(
11551155

11561156
// ToCommitment converts the allocations to a Commitment struct.
11571157
func ToCommitment(allocations []*tapsend.Allocation,
1158-
vPackets []*tappsbt.VPacket) (*cmsg.Commitment, error) {
1158+
vPackets []*tappsbt.VPacket, stxo bool) (*cmsg.Commitment, error) {
11591159

11601160
var (
11611161
localAssets []*cmsg.AssetOutput
@@ -1278,7 +1278,7 @@ func ToCommitment(allocations []*tapsend.Allocation,
12781278

12791279
return cmsg.NewCommitment(
12801280
localAssets, remoteAssets, outgoingHtlcs, incomingHtlcs,
1281-
auxLeaves,
1281+
auxLeaves, stxo,
12821282
), nil
12831283
}
12841284

tapchannelmsg/custom_channel_data_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ func TestReadChannelCustomData(t *testing.T) {
5050
}, map[input.HtlcIndex][]*AssetOutput{
5151
2: {output4},
5252
}, lnwallet.CommitAuxLeaves{},
53+
false,
5354
)
5455

5556
fundingBlob := fundingState.Bytes()
@@ -157,19 +158,19 @@ func TestReadBalanceCustomData(t *testing.T) {
157158

158159
openChannel1 := NewCommitment(
159160
[]*AssetOutput{output1}, []*AssetOutput{output2}, nil, nil,
160-
lnwallet.CommitAuxLeaves{},
161+
lnwallet.CommitAuxLeaves{}, false,
161162
)
162163
openChannel2 := NewCommitment(
163164
[]*AssetOutput{output2}, []*AssetOutput{output3}, nil, nil,
164-
lnwallet.CommitAuxLeaves{},
165+
lnwallet.CommitAuxLeaves{}, false,
165166
)
166167
pendingChannel1 := NewCommitment(
167168
[]*AssetOutput{output3}, nil, nil, nil,
168-
lnwallet.CommitAuxLeaves{},
169+
lnwallet.CommitAuxLeaves{}, false,
169170
)
170171
pendingChannel2 := NewCommitment(
171172
nil, []*AssetOutput{output1}, nil, nil,
172-
lnwallet.CommitAuxLeaves{},
173+
lnwallet.CommitAuxLeaves{}, false,
173174
)
174175

175176
var customChannelData bytes.Buffer

tapchannelmsg/records.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,13 +453,17 @@ type Commitment struct {
453453

454454
// AuxLeaves are the auxiliary leaves that correspond to the commitment.
455455
AuxLeaves tlv.RecordT[tlv.TlvType4, AuxLeaves]
456+
457+
// STXO is a flag indicating whether this commitment supports stxo
458+
// proofs.
459+
STXO tlv.RecordT[tlv.TlvType5, bool]
456460
}
457461

458462
// NewCommitment creates a new Commitment record with the given local and remote
459463
// assets, and incoming and outgoing HTLCs.
460464
func NewCommitment(localAssets, remoteAssets []*AssetOutput, outgoingHtlcs,
461465
incomingHtlcs map[input.HtlcIndex][]*AssetOutput,
462-
auxLeaves lnwallet.CommitAuxLeaves) *Commitment {
466+
auxLeaves lnwallet.CommitAuxLeaves, stxo bool) *Commitment {
463467

464468
return &Commitment{
465469
LocalAssets: tlv.NewRecordT[tlv.TlvType0](
@@ -485,6 +489,7 @@ func NewCommitment(localAssets, remoteAssets []*AssetOutput, outgoingHtlcs,
485489
auxLeaves.IncomingHtlcLeaves,
486490
),
487491
),
492+
STXO: tlv.NewPrimitiveRecord[tlv.TlvType5](stxo),
488493
}
489494
}
490495

@@ -496,6 +501,7 @@ func (c *Commitment) records() []tlv.Record {
496501
c.OutgoingHtlcAssets.Record(),
497502
c.IncomingHtlcAssets.Record(),
498503
c.AuxLeaves.Record(),
504+
c.STXO.Record(),
499505
}
500506
}
501507

tapchannelmsg/records_test.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ func TestCommitment(t *testing.T) {
215215
name: "commitment with empty HTLC maps",
216216
commitment: NewCommitment(
217217
nil, nil, nil, nil, lnwallet.CommitAuxLeaves{},
218+
false,
218219
),
219220
},
220221
{
@@ -228,7 +229,21 @@ func TestCommitment(t *testing.T) {
228229
NewAssetOutput(
229230
[32]byte{1}, 1000, *randProof,
230231
),
231-
}, nil, nil, lnwallet.CommitAuxLeaves{},
232+
}, nil, nil, lnwallet.CommitAuxLeaves{}, false,
233+
),
234+
},
235+
{
236+
name: "commitment with balances and stxo",
237+
commitment: NewCommitment(
238+
[]*AssetOutput{
239+
NewAssetOutput(
240+
[32]byte{1}, 1000, *randProof,
241+
),
242+
}, []*AssetOutput{
243+
NewAssetOutput(
244+
[32]byte{1}, 1000, *randProof,
245+
),
246+
}, nil, nil, lnwallet.CommitAuxLeaves{}, true,
232247
),
233248
},
234249
{
@@ -319,6 +334,7 @@ func TestCommitment(t *testing.T) {
319334
},
320335
},
321336
},
337+
false,
322338
),
323339
},
324340
}

0 commit comments

Comments
 (0)