Skip to content

Commit

Permalink
tapfreighter+tapdb: fix some loop memory aliasing
Browse files Browse the repository at this point in the history
  • Loading branch information
jharveyb committed Oct 3, 2023
1 parent 401f91d commit 6686744
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
3 changes: 2 additions & 1 deletion tapdb/addrs.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,11 @@ func (t *TapAddressBook) InsertAddrs(ctx context.Context,
// For each of the addresses listed, we'll insert the two new
// internal keys, then use those returned primary key IDs to
// returned to insert the address itself.
for _, addr := range addrs {
for idx := range addrs {
// The asset genesis should already be known at this
// point, so we'll just fetch it so we can obtain the
// genAssetID.
addr := addrs[idx]
assetGen, err := db.FetchGenesisByAssetID(
ctx, addr.AssetID[:],
)
Expand Down
6 changes: 4 additions & 2 deletions tapdb/assets_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -1295,7 +1295,8 @@ func (a *AssetStore) insertAssetWitnesses(ctx context.Context,
db ActiveAssetsStore, assetID int32, inputs []asset.Witness) error {

var buf [8]byte
for _, input := range inputs {
for idx := range inputs {
input := inputs[idx]
prevID := input.PrevID

prevOutpoint, err := encodeOutpoint(prevID.OutPoint)
Expand Down Expand Up @@ -2285,9 +2286,10 @@ func logPendingPassiveAssets(ctx context.Context,
q ActiveAssetsStore, transferID, newUtxoID int32,
passiveAssets []*tapfreighter.PassiveAssetReAnchor) error {

for _, passiveAsset := range passiveAssets {
for idx := range passiveAssets {
// Encode new witness data.
var (
passiveAsset = passiveAssets[idx]
newWitnessBuf bytes.Buffer
buf [8]byte
)
Expand Down
5 changes: 3 additions & 2 deletions tapfreighter/chain_porter.go
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,8 @@ func (p *ChainPorter) transferReceiverProof(pkg *sendPackage) error {

// Load passive asset proof files from archive.
passiveAssetProofFiles := map[[32]byte]proof.Blob{}
for _, passiveAsset := range pkg.OutboundPkg.PassiveAssets {
for idx := range pkg.OutboundPkg.PassiveAssets {
passiveAsset := pkg.OutboundPkg.PassiveAssets[idx]
proofLocator := proof.Locator{
AssetID: &passiveAsset.GenesisID,
ScriptKey: *passiveAsset.ScriptKey.PubKey,
Expand Down Expand Up @@ -776,7 +777,7 @@ func (p *ChainPorter) importLocalAddresses(ctx context.Context,
case strings.Contains(err.Error(), "already exists"):
break

case err != nil:
default:
return err
}
}
Expand Down
5 changes: 3 additions & 2 deletions tapfreighter/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ func (f *AssetWallet) fundPacketWithInputs(ctx context.Context,
// it in the database.
continue

case err != nil:
default:
return nil, fmt.Errorf("cannot fetch script key: %w",
err)
}
Expand Down Expand Up @@ -867,14 +867,15 @@ func (f *AssetWallet) setVPacketInputs(ctx context.Context,
vPkt.Inputs = make([]*tappsbt.VInput, len(eligibleCommitments))
inputCommitments := make(tappsbt.InputCommitments)

for idx, assetInput := range eligibleCommitments {
for idx := range eligibleCommitments {
// If the key found for the input UTXO cannot be identified as
// belonging to the lnd wallet, we won't be able to sign for it.
// This would happen if a user manually imported an asset that
// was issued/received for/on another node. We should probably
// not create asset entries for such imported assets in the
// first place, as we won't be able to spend it anyway. But for
// now we just put this check in place.
assetInput := eligibleCommitments[idx]
internalKey := assetInput.InternalKey
if !f.cfg.KeyRing.IsLocalKey(ctx, internalKey) {
return nil, fmt.Errorf("invalid internal key family "+
Expand Down

0 comments on commit 6686744

Please sign in to comment.