Skip to content

Commit d56be62

Browse files
committed
tapdb: only select confirmed assets when funding
To avoid attempting to spend freshly minted assets that haven't been confirmed yet, we set the minimum anchor height to 1 to avoid selecting them when funding any transaction.
1 parent 06d01fb commit d56be62

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

tapdb/assets_store.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1823,6 +1823,11 @@ func (a *AssetStore) ListEligibleCoins(ctx context.Context,
18231823
assetFilter.Spent = sqlBool(false)
18241824
assetFilter.Leased = sqlBool(false)
18251825

1826+
// We also only want to select confirmed commitments (freshly minted
1827+
// unconfirmed assets would otherwise be included). Unconfirmed assets
1828+
// have a block height of 0, so we set the minimum block height to 1.
1829+
assetFilter.MinAnchorHeight = sqlInt32(1)
1830+
18261831
return a.queryCommitments(ctx, assetFilter)
18271832
}
18281833

tapdb/assets_store_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ func TestImportAssetProof(t *testing.T) {
301301
t, testProof.AssetSnapshot.OutPoint, dbAsset.AnchorOutpoint,
302302
)
303303
require.Equal(t, testProof.AnchorTx.TxHash(), dbAsset.AnchorTx.TxHash())
304+
require.NotZero(t, dbAsset.AnchorBlockHeight)
304305

305306
// We should also be able to fetch the proof we just inserted using the
306307
// script key of the new asset.

tapdb/sqlutils_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func (d *DbHandler) AddRandomAssetProof(t *testing.T) (*asset.Asset,
105105
Asset: testAsset,
106106
OutPoint: anchorPoint,
107107
AnchorBlockHash: blockHash,
108-
AnchorBlockHeight: test.RandInt[uint32](),
108+
AnchorBlockHeight: uint32(test.RandIntn(1000) + 1),
109109
AnchorTxIndex: test.RandInt[uint32](),
110110
AnchorTx: anchorTx,
111111
OutputIndex: 0,

0 commit comments

Comments
 (0)