Skip to content

Commit 16a908b

Browse files
jharveybguggero
authored andcommitted
tapfreighter: trim altLeaves from passive vPkts
In this commit, we update the passive asset handling to not consider altLeaves as assets. Specifically, any altLeaf in an input Tap commitment should be set in the vInput for a passive asset vPkt, but should not have its own vPkt where it is an input. Overall, input altLeaves do not need to be re-anchored.
1 parent 5cf42a2 commit 16a908b

File tree

1 file changed

+32
-5
lines changed

1 file changed

+32
-5
lines changed

tapfreighter/wallet.go

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,8 @@ func (f *AssetWallet) FundAddressSend(ctx context.Context,
271271
func createPassivePacket(params *address.ChainParams, passiveAsset *asset.Asset,
272272
activePackets []*tappsbt.VPacket, anchorOutputIndex uint32,
273273
anchorOutputInternalKey keychain.KeyDescriptor, prevOut wire.OutPoint,
274-
inputProof *proof.Proof) (*tappsbt.VPacket, error) {
274+
inputProof *proof.Proof,
275+
inputAltLeaves []*asset.Asset) (*tappsbt.VPacket, error) {
275276

276277
// Specify virtual input.
277278
inputAsset := passiveAsset.Copy()
@@ -281,8 +282,12 @@ func createPassivePacket(params *address.ChainParams, passiveAsset *asset.Asset,
281282
SighashType: txscript.SigHashDefault,
282283
},
283284
}
285+
err := vInput.SetAltLeaves(inputAltLeaves)
286+
if err != nil {
287+
return nil, err
288+
}
284289

285-
err := tapsend.ValidateVPacketVersions(activePackets)
290+
err = tapsend.ValidateVPacketVersions(activePackets)
286291
if err != nil {
287292
return nil, err
288293
}
@@ -597,7 +602,18 @@ func (f *AssetWallet) hasOtherAssets(inputCommitments tappsbt.InputCommitments,
597602
return false, err
598603
}
599604

600-
if len(passiveCommitments.CommittedAssets()) > 0 {
605+
// We're trying to find out if there are any other assets in the
606+
// commitment. We don't want to count alt leaves as "assets" per
607+
// se in this context, so we trim them out, just for the next
608+
// check.
609+
trimmedPassiveCommitments, _, err := commitment.TrimAltLeaves(
610+
passiveCommitments,
611+
)
612+
if err != nil {
613+
return false, err
614+
}
615+
616+
if len(trimmedPassiveCommitments.CommittedAssets()) > 0 {
601617
return true, nil
602618
}
603619
}
@@ -1260,7 +1276,18 @@ func (f *AssetWallet) CreatePassiveAssets(ctx context.Context,
12601276
return nil, err
12611277
}
12621278

1263-
passiveAssets := passiveCommitments.CommittedAssets()
1279+
// We're trying to determine what assets are left over after
1280+
// removing the active assets. But we don't want to count the
1281+
// alt leaves as "assets" in this context, so we'll trim them
1282+
// out.
1283+
trimmedPassives, altLeaves, err := commitment.TrimAltLeaves(
1284+
passiveCommitments,
1285+
)
1286+
if err != nil {
1287+
return nil, err
1288+
}
1289+
1290+
passiveAssets := trimmedPassives.CommittedAssets()
12641291
if len(passiveAssets) == 0 {
12651292
continue
12661293
}
@@ -1289,7 +1316,7 @@ func (f *AssetWallet) CreatePassiveAssets(ctx context.Context,
12891316
passivePacket, err := createPassivePacket(
12901317
f.cfg.ChainParams, passiveAsset, activePackets,
12911318
anchorOutIdx, *anchorOutDesc, prevID.OutPoint,
1292-
inputProof,
1319+
inputProof, altLeaves,
12931320
)
12941321
if err != nil {
12951322
return nil, fmt.Errorf("unable to create "+

0 commit comments

Comments
 (0)