Skip to content

Commit

Permalink
tapfreighter: trim altLeaves from passive vPkts
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jharveyb committed Dec 3, 2024
1 parent c891d1d commit 8823ab7
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions tapfreighter/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,8 @@ func (f *AssetWallet) FundAddressSend(ctx context.Context,
func createPassivePacket(params *address.ChainParams, passiveAsset *asset.Asset,
activePackets []*tappsbt.VPacket, anchorOutputIndex uint32,
anchorOutputInternalKey keychain.KeyDescriptor, prevOut wire.OutPoint,
inputProof *proof.Proof) (*tappsbt.VPacket, error) {
inputProof *proof.Proof,
inputAltLeaves []*asset.Asset) (*tappsbt.VPacket, error) {

// Specify virtual input.
inputAsset := passiveAsset.Copy()
Expand All @@ -281,6 +282,7 @@ func createPassivePacket(params *address.ChainParams, passiveAsset *asset.Asset,
SighashType: txscript.SigHashDefault,
},
}
vInput.SetAltLeaves(inputAltLeaves)

err := tapsend.ValidateVPacketVersions(activePackets)
if err != nil {
Expand Down Expand Up @@ -580,7 +582,14 @@ func (f *AssetWallet) hasOtherAssets(inputCommitments tappsbt.InputCommitments,
return false, err
}

if len(passiveCommitments.CommittedAssets()) > 0 {
trimmedPassiveCommitments, _, err := commitment.TrimAltLeaves(
passiveCommitments,
)
if err != nil {
return false, err
}

if len(trimmedPassiveCommitments.CommittedAssets()) > 0 {
return true, nil
}
}
Expand Down Expand Up @@ -1243,7 +1252,14 @@ func (f *AssetWallet) CreatePassiveAssets(ctx context.Context,
return nil, err
}

passiveAssets := passiveCommitments.CommittedAssets()
trimmedPassives, altLeaves, err := commitment.TrimAltLeaves(
passiveCommitments,
)
if err != nil {
return nil, err
}

passiveAssets := trimmedPassives.CommittedAssets()
if len(passiveAssets) == 0 {
continue
}
Expand Down Expand Up @@ -1272,7 +1288,7 @@ func (f *AssetWallet) CreatePassiveAssets(ctx context.Context,
passivePacket, err := createPassivePacket(
f.cfg.ChainParams, passiveAsset, activePackets,
anchorOutIdx, *anchorOutDesc, prevID.OutPoint,
inputProof,
inputProof, altLeaves,
)
if err != nil {
return nil, fmt.Errorf("unable to create "+
Expand Down

0 comments on commit 8823ab7

Please sign in to comment.