Skip to content

Commit d52a498

Browse files
committed
tapcfg+tapfreighter: configure sweeping with wallet flag
1 parent 5f8ba65 commit d52a498

File tree

14 files changed

+351
-86
lines changed

14 files changed

+351
-86
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+
// SweepZeroValueAnchorUtxos toggles sweeping zero-value UTXOs into
194+
// anchor transactions for sends and burns.
195+
SweepZeroValueAnchorUtxos 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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
- [Garbage collection of zero-value UTXOs](https://github.com/lightninglabs/taproot-assets/pull/1832)
3636
by sweeping tombstones and burn outputs when executing onchain transactions.
3737
Garbage collection will be executed on every burn, transfer or call to
38-
`AnchorVirtualPsbts`.
38+
`AnchorVirtualPsbts`. A new configuration is available to control the sweeping
39+
via the flag `wallet.sweep-zero-value-anchor-utxos`.
3940

4041
## RPC Updates
4142

itest/assertions.go

Lines changed: 4 additions & 13 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,17 +1321,12 @@ func AssertAssetOutboundTransferWithOutputs(t *testing.T,
13251321
return slices.Contains(actualInputAssetIDs, id)
13261322
})
13271323
}, defaultTimeout, wait.PollInterval)
1328-
require.NoError(t, err)
13291324

1330-
transferResp, err := sender.ListTransfers(
1325+
_, err := sender.ListTransfers(
13311326
ctxb, &taprpc.ListTransfersRequest{},
13321327
)
13331328
require.NoError(t, err)
13341329

1335-
transferRespJSON, err := formatProtoJSON(transferResp)
1336-
require.NoError(t, err)
1337-
t.Logf("Got response from list transfers: %v", transferRespJSON)
1338-
13391330
return newBlock
13401331
}
13411332

@@ -2410,7 +2401,7 @@ func AssertBalances(t *testing.T, client taprpc.TaprootAssetsClient,
24102401
actualBalance := balanceSum(resp, false)
24112402
if balance != actualBalance {
24122403
return fmt.Errorf("asset balance, wanted %d, "+
2413-
"got: %v", balance, toJSON(t, resp))
2404+
"got: %v", balance, actualBalance)
24142405
}
24152406

24162407
// If we query for grouped asset balances too, it means
@@ -2528,7 +2519,7 @@ func AssertBalances(t *testing.T, client taprpc.TaprootAssetsClient,
25282519
}
25292520
if balance != totalBalance {
25302521
return fmt.Errorf("ListAssets balance, wanted %d, "+
2531-
"got: %v", balance, toJSON(t, resp))
2522+
"got: %v", balance, totalBalance)
25322523
}
25332524

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

26062597
if balance != totalBalance {
26072598
return fmt.Errorf("ListUtxos balance, wanted %d, "+
2608-
"got: %v", balance, toJSON(t, resp))
2599+
"got: %v", balance, totalBalance)
26092600
}
26102601

26112602
if config.numAnchorUtxos > 0 {

itest/burn_test.go

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

249-
resp, err := t.tapd.ListAssets(ctxt, &taprpc.ListAssetRequest{
250-
IncludeSpent: true,
251-
})
252-
require.NoError(t.t, err)
253-
assets, err := formatProtoJSON(resp)
254-
require.NoError(t.t, err)
255-
t.Logf("All assets before last burn: %v", assets)
256-
257249
// Test case 4: Burn some units of a grouped asset. We start by making
258250
// sure we still have the full balance before burning.
259251
AssertBalanceByID(
@@ -282,6 +274,7 @@ func testBurnAssets(t *harnessTest) {
282274
burnAmt+simpleCollectible.Amount+multiBurnAmt+burnAmt,
283275
WithNumUtxos(4), WithNumAnchorUtxos(4),
284276
WithScriptKeyType(asset.ScriptKeyBurn),
277+
WithIncludeLeased(),
285278
)
286279

287280
burns = AssertNumBurns(t.t, t.tapd, 4, nil)
@@ -337,6 +330,7 @@ func testBurnAssets(t *harnessTest) {
337330
burnAmt+simpleCollectible.Amount+multiBurnAmt+burnAmt+1,
338331
WithNumUtxos(5), WithNumAnchorUtxos(5),
339332
WithScriptKeyType(asset.ScriptKeyBurn),
333+
WithIncludeLeased(),
340334
)
341335

342336
// We now perform some queries to test the filters of the ListBurns

itest/integration_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func TestTaprootAssetsDaemon(t *testing.T) {
119119
// assure no state is taken over between runs.
120120
tapdHarness, uniHarness, proofCourier := setupHarnesses(
121121
t1, ht, lndHarness, uniServerLndHarness,
122-
testCase.proofCourierType,
122+
testCase.proofCourierType, testCase.tapdOptions...,
123123
)
124124

125125
ht := ht.newHarnessTest(

itest/tapd_harness.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,10 @@ type harnessOpts struct {
139139
// the local oracle to the counterparty when requesting a quote.
140140
sendPriceHint bool
141141

142+
// sweepZeroValueAnchorUtxos indicates whether zero-value anchor UTXOs
143+
// should be swept into anchor transactions.
144+
sweepZeroValueAnchorUtxos bool
145+
142146
// disableSupplyVerifierChainWatch when true prevents the supply
143147
// verifier from starting state machines to watch on-chain outputs for
144148
// spends. This option is intended for universe servers, where supply
@@ -197,6 +201,8 @@ func newTapdHarness(t *testing.T, ht *harnessTest, cfg tapdConfig,
197201
tapCfg.ChainConf.Network = cfg.NetParams.Name
198202
tapCfg.TapdDir = cfg.BaseDir
199203
tapCfg.DebugLevel = *logLevel
204+
tapCfg.Wallet.SweepZeroValueAnchorUtxos =
205+
opts.sweepZeroValueAnchorUtxos
200206

201207
// Enable universe proof courier RPC endpoints. These endpoints are
202208
// also used within some tests for transferring proofs.

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+
// sweepZeroValueAnchorUtxos indicates whether zero-value anchor UTXOs
379+
// should be swept into anchor transactions.
380+
sweepZeroValueAnchorUtxos bool
375381
}
376382

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

409+
// WithSweepZeroValueAnchorUtxos enables sweeping zero-value anchor UTXOs for
410+
// the tapd harness created with this option.
411+
func WithSweepZeroValueAnchorUtxos() Option {
412+
return func(th *tapdHarnessParams) {
413+
th.sweepZeroValueAnchorUtxos = 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.sweepZeroValueAnchorUtxos = params.sweepZeroValueAnchorUtxos
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+
WithSweepZeroValueAnchorUtxos(),
109+
},
110+
},
111+
{
112+
name: "zero value anchor accumulation",
113+
test: testZeroValueAnchorAccumulation,
107114
},
108115
{
109116
name: "restart receiver check balance",

0 commit comments

Comments
 (0)