Skip to content

Commit

Permalink
tapfreighter: de-duplicate passive asset creation
Browse files Browse the repository at this point in the history
Because we now check all active and passive packets for uniqueness in
their commitment keys, this issue has surfaced. If we're spending
multiple different assets from the same on-chain input commitment, we
used to create duplicate passive assets.
That wasn't a problem until now because within the trees everything
would just be overwritten and collapsed back to a single asset. But
because have the uniqueness check on the virtual packet slice level,
this duplication became apparent.
  • Loading branch information
guggero committed Nov 14, 2024
1 parent f20a875 commit ae69e0a
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions tapfreighter/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/lightninglabs/taproot-assets/tapsend"
"github.com/lightningnetwork/lnd/keychain"
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
"golang.org/x/exp/maps"
)

const (
Expand Down Expand Up @@ -1210,7 +1211,7 @@ func (f *AssetWallet) CreatePassiveAssets(ctx context.Context,
}

// Gather passive assets found in each input Taproot Asset commitment.
var passivePackets []*tappsbt.VPacket
passivePackets := make(map[asset.PrevID]*tappsbt.VPacket)
for prevID := range inputCommitments {
tapCommitment := inputCommitments[prevID]

Expand Down Expand Up @@ -1248,6 +1249,16 @@ func (f *AssetWallet) CreatePassiveAssets(ctx context.Context,
"proof: %w", err)
}

scriptKey := passiveAsset.ScriptKey.PubKey
passivePrevID := asset.PrevID{
OutPoint: prevID.OutPoint,
ID: passiveAsset.ID(),
ScriptKey: asset.ToSerialized(scriptKey),
}
log.Tracef("Adding passive packet for asset_id=%v, "+
"script_key=%x", passiveAsset.ID().String(),
scriptKey.SerializeCompressed())

passivePacket, err := createPassivePacket(
f.cfg.ChainParams, passiveAsset, activePackets,
anchorOutIdx, *anchorOutDesc, prevID.OutPoint,
Expand All @@ -1258,11 +1269,11 @@ func (f *AssetWallet) CreatePassiveAssets(ctx context.Context,
"passive packet: %w", err)
}

passivePackets = append(passivePackets, passivePacket)
passivePackets[passivePrevID] = passivePacket
}
}

return passivePackets, nil
return maps.Values(passivePackets), nil
}

// SignPassiveAssets signs the given passive asset packets.
Expand Down

0 comments on commit ae69e0a

Please sign in to comment.