Skip to content

Commit 3174374

Browse files
committed
tapfreighter: fix bug with burns not being recognized
This fixes the main part of the flake that caused burns to sometimes not be recognized correctly. Because we now also use the allocation code to create virtual packets, we need to apply the same ordering of inputs to the selected commitments before choosing the first input that the burn key is derived from. Otherwise it can happen that the actual first input in the allocated virtual transaction is another one and the resulting burn key isn't recognized correctly.
1 parent 0c224cc commit 3174374

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

tapfreighter/wallet.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"context"
66
"errors"
77
"fmt"
8+
"slices"
89
"time"
910

1011
"github.com/btcsuite/btcd/blockchain"
@@ -525,7 +526,13 @@ func (f *AssetWallet) FundBurn(ctx context.Context,
525526
}
526527

527528
// Now that we know what inputs we're going to spend, we know that by
528-
// definition, we use the first input's info as the burn's PrevID.
529+
// definition, we use the first input's info as the burn's PrevID. But
530+
// to know which input will actually be assigned as the first input in
531+
// the allocated virtual packet, we first apply the same sorting that
532+
// the allocation code will also apply.
533+
slices.SortFunc(activeAssets, func(a, b *AnchoredCommitment) int {
534+
return tapsend.AssetSortForInputs(*a.Asset, *b.Asset)
535+
})
529536
firstInput := activeAssets[0]
530537
firstPrevID := asset.PrevID{
531538
OutPoint: firstInput.AnchorPoint,

0 commit comments

Comments
 (0)