Skip to content

Commit 773c448

Browse files
committed
tapcfg+tapfreighter: configure sweeping with wallet flag
1 parent 2c3b3ab commit 773c448

18 files changed

+101
-55
lines changed

config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,10 @@ type Config struct {
190190

191191
ChainPorter tapfreighter.Porter
192192

193+
// SweepOrphanUtxos toggles sweeping orphaned UTXOs into anchor
194+
// transactions for sends and burns.
195+
SweepOrphanUtxos bool
196+
193197
// FsmDaemonAdapters is a set of adapters that allow a state machine to
194198
// interact with external daemons.
195199
FsmDaemonAdapters *lndservices.LndFsmDaemonAdapters

docs/release-notes/release-notes-0.8.0.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,11 @@
3737

3838
## Functional Updates
3939

40-
- [Garbage collection of zero-value UTXOs](https://github.com/lightninglabs/taproot-assets/pull/1832)
40+
- [Garbage collection of orphaned UTXOs](https://github.com/lightninglabs/taproot-assets/pull/1832)
4141
by sweeping tombstones and burn outputs when executing onchain transactions.
4242
Garbage collection will be executed on every burn, transfer or call to
43-
`AnchorVirtualPsbts`.
43+
`AnchorVirtualPsbts`. A new configuration is available to control the sweeping
44+
via the flag `wallet.sweep-orphan-utxos`.
4445

4546
## RPC Updates
4647

itest/assertions.go

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,10 +1276,6 @@ func AssertAssetOutboundTransferWithOutputs(t *testing.T,
12761276
scripts[string(o.ScriptKey)] = struct{}{}
12771277
}
12781278

1279-
sendRespJSON, err := formatProtoJSON(transfer)
1280-
require.NoError(t, err)
1281-
t.Logf("Got response from sending assets: %v", sendRespJSON)
1282-
12831279
// Mine a block to force the send event to complete (confirm on-chain).
12841280
var newBlock *wire.MsgBlock
12851281
if confirm {
@@ -1325,16 +1321,6 @@ func AssertAssetOutboundTransferWithOutputs(t *testing.T,
13251321
return slices.Contains(actualInputAssetIDs, id)
13261322
})
13271323
}, defaultTimeout, wait.PollInterval)
1328-
require.NoError(t, err)
1329-
1330-
transferResp, err := sender.ListTransfers(
1331-
ctxb, &taprpc.ListTransfersRequest{},
1332-
)
1333-
require.NoError(t, err)
1334-
1335-
transferRespJSON, err := formatProtoJSON(transferResp)
1336-
require.NoError(t, err)
1337-
t.Logf("Got response from list transfers: %v", transferRespJSON)
13381324

13391325
return newBlock
13401326
}
@@ -2410,7 +2396,7 @@ func AssertBalances(t *testing.T, client taprpc.TaprootAssetsClient,
24102396
actualBalance := balanceSum(resp, false)
24112397
if balance != actualBalance {
24122398
return fmt.Errorf("asset balance, wanted %d, "+
2413-
"got: %v", balance, toJSON(t, resp))
2399+
"got: %v", balance, actualBalance)
24142400
}
24152401

24162402
// If we query for grouped asset balances too, it means
@@ -2528,7 +2514,7 @@ func AssertBalances(t *testing.T, client taprpc.TaprootAssetsClient,
25282514
}
25292515
if balance != totalBalance {
25302516
return fmt.Errorf("ListAssets balance, wanted %d, "+
2531-
"got: %v", balance, toJSON(t, resp))
2517+
"got: %v", balance, totalBalance)
25322518
}
25332519

25342520
// The number of UTXOs means asset outputs in this case. We
@@ -2605,7 +2591,7 @@ func AssertBalances(t *testing.T, client taprpc.TaprootAssetsClient,
26052591

26062592
if balance != totalBalance {
26072593
return fmt.Errorf("ListUtxos balance, wanted %d, "+
2608-
"got: %v", balance, toJSON(t, resp))
2594+
"got: %v", balance, totalBalance)
26092595
}
26102596

26112597
if config.numAnchorUtxos > 0 {

itest/burn_test.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -246,11 +246,6 @@ func testBurnAssets(t *harnessTest) {
246246
WithScriptKeyType(asset.ScriptKeyBurn),
247247
)
248248

249-
_, err = t.tapd.ListAssets(ctxt, &taprpc.ListAssetRequest{
250-
IncludeSpent: true,
251-
})
252-
require.NoError(t.t, err)
253-
254249
// Test case 4: Burn some units of a grouped asset. We start by making
255250
// sure we still have the full balance before burning.
256251
AssertBalanceByID(

itest/integration_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ func TestTaprootAssetsDaemon(t *testing.T) {
120120
tapdHarness, uniHarness, proofCourier := setupHarnesses(
121121
t1, ht, lndHarness, uniServerLndHarness,
122122
testCase.proofCourierType,
123+
testCase.tapdOptions...,
123124
)
124125

125126
ht := ht.newHarnessTest(

itest/tapd_harness.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ type harnessOpts struct {
145145
// verification should only occur for commitments submitted by peers,
146146
// not via on-chain spend detection.
147147
disableSupplyVerifierChainWatch bool
148+
149+
// sweepOrphanUtxos indicates whether orphaned anchor UTXOs should be
150+
// swept into anchor transactions.
151+
sweepOrphanUtxos bool
148152
}
149153

150154
type harnessOption func(*harnessOpts)
@@ -256,6 +260,10 @@ func newTapdHarness(t *testing.T, ht *harnessTest, cfg tapdConfig,
256260
// nolint: lll
257261
tapCfg.Universe.DisableSupplyVerifierChainWatch = opts.disableSupplyVerifierChainWatch
258262

263+
// Pass through the sweep orphan UTXOs flag. If the option was not set,
264+
// this will be false, which is the default.
265+
tapCfg.Wallet.SweepOrphanUtxos = opts.sweepOrphanUtxos
266+
259267
switch {
260268
case len(opts.oracleServerAddress) > 0:
261269
tapCfg.Experimental.Rfq.PriceOracleAddress =

itest/test_harness.go

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ type testCase struct {
7070
name string
7171
test func(t *harnessTest)
7272
proofCourierType proof.CourierType
73+
tapdOptions []Option
7374
}
7475

7576
// harnessTest wraps a regular testing.T providing enhanced error detection
@@ -270,7 +271,7 @@ func (h *harnessTest) addFederationServer(host string, target *tapdHarness) {
270271
// to each other through an in-memory gRPC connection.
271272
func setupHarnesses(t *testing.T, ht *harnessTest,
272273
lndHarness *lntest.HarnessTest, uniServerLndHarness *node.HarnessNode,
273-
proofCourierType proof.CourierType) (*tapdHarness,
274+
proofCourierType proof.CourierType, tapdOpts ...Option) (*tapdHarness,
274275
*universeServerHarness, proof.CourierHarness) {
275276

276277
// Create a new universe server harness and start it.
@@ -306,10 +307,11 @@ func setupHarnesses(t *testing.T, ht *harnessTest,
306307
alice := lndHarness.NewNodeWithCoins("Alice", nil)
307308

308309
// Create a tapd that uses Alice and connect it to the universe server.
310+
tapdOptions := append(tapdOpts, func(params *tapdHarnessParams) {
311+
params.proofCourier = proofCourier
312+
})
309313
tapdHarness := setupTapdHarness(
310-
t, ht, alice, universeServer, func(params *tapdHarnessParams) {
311-
params.proofCourier = proofCourier
312-
},
314+
t, ht, alice, universeServer, tapdOptions...,
313315
)
314316
return tapdHarness, universeServer, proofCourier
315317
}
@@ -372,6 +374,10 @@ type tapdHarnessParams struct {
372374
// sendPriceHint indicates whether the tapd should send price hints from
373375
// the local oracle to the counterparty when requesting a quote.
374376
sendPriceHint bool
377+
378+
// sweepOrphanUtxos indicates whether orphaned UTXOs should be swept
379+
// into anchor transactions.
380+
sweepOrphanUtxos bool
375381
}
376382

377383
// Option is a tapd harness option.
@@ -400,6 +406,14 @@ func WithSendPriceHint() Option {
400406
}
401407
}
402408

409+
// WithSweepOrphanUtxos enables sweeping zero-value anchor UTXOs for
410+
// the tapd harness created with this option.
411+
func WithSweepOrphanUtxos() Option {
412+
return func(th *tapdHarnessParams) {
413+
th.sweepOrphanUtxos = true
414+
}
415+
}
416+
403417
// setupTapdHarness creates a new tapd that connects to the given lnd node
404418
// and to the given universe server.
405419
func setupTapdHarness(t *testing.T, ht *harnessTest,
@@ -434,6 +448,7 @@ func setupTapdHarness(t *testing.T, ht *harnessTest,
434448
ho.disableSyncCache = params.disableSyncCache
435449
ho.oracleServerAddress = params.oracleServerAddress
436450
ho.sendPriceHint = params.sendPriceHint
451+
ho.sweepOrphanUtxos = params.sweepOrphanUtxos
437452
}
438453

439454
tapdCfg := tapdConfig{

itest/test_list_on_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,13 @@ var allTestCases = []*testCase{
104104
{
105105
name: "zero value anchor sweep",
106106
test: testZeroValueAnchorSweep,
107+
tapdOptions: []Option{
108+
WithSweepOrphanUtxos(),
109+
},
110+
},
111+
{
112+
name: "zero value anchor accumulation",
113+
test: testZeroValueAnchorAccumulation,
107114
},
108115
{
109116
name: "restart receiver check balance",

itest/zero_value_anchor_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func testZeroValueAnchorSweep(t *harnessTest) {
113113
AssetId: genInfo3.AssetId,
114114
},
115115
AmountToBurn: assetAmount,
116-
ConfirmationText: "assets will be destroyed",
116+
ConfirmationText: taprootassets.AssetBurnConfirmationText,
117117
})
118118
require.NoError(t.t, err)
119119

@@ -290,7 +290,7 @@ func testZeroValueAnchorAccumulation(t *harnessTest) {
290290
require.NoError(t.t, t.tapd.stop(false))
291291

292292
// Enable sweeping in the config.
293-
t.tapd.clientCfg.Wallet.SweepZeroValueAnchorUtxos = true
293+
t.tapd.clientCfg.Wallet.SweepOrphanUtxos = true
294294

295295
// Restart with the modified config.
296296
require.NoError(t.t, t.tapd.start(false))

rpcserver.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2671,11 +2671,18 @@ func (r *rpcServer) AnchorVirtualPsbts(ctx context.Context,
26712671
prevID.OutPoint.String())
26722672
}
26732673

2674-
// Fetch zero-value UTXOs that should be swept as additional inputs.
2675-
zeroValueInputs, err := r.cfg.AssetStore.FetchZeroValueAnchorUTXOs(ctx)
2676-
if err != nil {
2677-
return nil, fmt.Errorf("unable to fetch zero-value "+
2678-
"UTXOs: %w", err)
2674+
// Fetch zero-value UTXOs that should be swept as additional inputs if
2675+
// the feature is enabled.
2676+
var (
2677+
zeroValueInputs []*tapfreighter.ZeroValueInput
2678+
err error
2679+
)
2680+
if r.cfg.SweepOrphanUtxos {
2681+
zeroValueInputs, err = r.cfg.AssetStore.FetchOrphanUTXOs(ctx)
2682+
if err != nil {
2683+
return nil, fmt.Errorf("unable to fetch zero-value "+
2684+
"UTXOs: %w", err)
2685+
}
26792686
}
26802687

26812688
resp, err := r.cfg.ChainPorter.RequestShipment(

0 commit comments

Comments
 (0)