Skip to content

Commit ae69e0a

Browse files
committed
tapfreighter: de-duplicate passive asset creation
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.
1 parent f20a875 commit ae69e0a

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

tapfreighter/wallet.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"github.com/lightninglabs/taproot-assets/tapsend"
2626
"github.com/lightningnetwork/lnd/keychain"
2727
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
28+
"golang.org/x/exp/maps"
2829
)
2930

3031
const (
@@ -1210,7 +1211,7 @@ func (f *AssetWallet) CreatePassiveAssets(ctx context.Context,
12101211
}
12111212

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

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

1252+
scriptKey := passiveAsset.ScriptKey.PubKey
1253+
passivePrevID := asset.PrevID{
1254+
OutPoint: prevID.OutPoint,
1255+
ID: passiveAsset.ID(),
1256+
ScriptKey: asset.ToSerialized(scriptKey),
1257+
}
1258+
log.Tracef("Adding passive packet for asset_id=%v, "+
1259+
"script_key=%x", passiveAsset.ID().String(),
1260+
scriptKey.SerializeCompressed())
1261+
12511262
passivePacket, err := createPassivePacket(
12521263
f.cfg.ChainParams, passiveAsset, activePackets,
12531264
anchorOutIdx, *anchorOutDesc, prevID.OutPoint,
@@ -1258,11 +1269,11 @@ func (f *AssetWallet) CreatePassiveAssets(ctx context.Context,
12581269
"passive packet: %w", err)
12591270
}
12601271

1261-
passivePackets = append(passivePackets, passivePacket)
1272+
passivePackets[passivePrevID] = passivePacket
12621273
}
12631274
}
12641275

1265-
return passivePackets, nil
1276+
return maps.Values(passivePackets), nil
12661277
}
12671278

12681279
// SignPassiveAssets signs the given passive asset packets.

0 commit comments

Comments
 (0)