Skip to content

Commit 5635183

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

File tree

13 files changed

+129
-83
lines changed

13 files changed

+129
-83
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
@@ -40,7 +40,8 @@
4040
- [Garbage collection of zero-value 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-zero-value-anchor-utxos`.
4445

4546
## RPC Updates
4647

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 & 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(
@@ -281,6 +276,7 @@ func testBurnAssets(t *harnessTest) {
281276
t.t, t.tapd,
282277
burnAmt+multiBurnAmt+burnAmt,
283278
WithScriptKeyType(asset.ScriptKeyBurn),
279+
WithIncludeLeased(),
284280
)
285281

286282
burns = AssertNumBurns(t.t, t.tapd, 4, nil)
@@ -335,6 +331,7 @@ func testBurnAssets(t *harnessTest) {
335331
t.t, t.tapd,
336332
burnAmt+multiBurnAmt+burnAmt+1,
337333
WithScriptKeyType(asset.ScriptKeyBurn),
334+
WithIncludeLeased(),
338335
)
339336

340337
// 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/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",

itest/zero_value_anchor_test.go

Lines changed: 1 addition & 1 deletion
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

rpcserver.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2671,11 +2671,19 @@ 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.SweepZeroValueAnchorUtxos {
2681+
zeroValueInputs, err = r.cfg.AssetStore.
2682+
FetchZeroValueAnchorUTXOs(ctx)
2683+
if err != nil {
2684+
return nil, fmt.Errorf("unable to fetch zero-value "+
2685+
"UTXOs: %w", err)
2686+
}
26792687
}
26802688

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

sample-tapd.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,10 @@
412412
; Value must be a valid float ranging from 0.00 to 1.00.
413413
; wallet.psbt-max-fee-ratio=0.75
414414

415+
; Sweep zero-value anchor UTXOs into send and burn anchor transactions.
416+
; Disabled by default.
417+
; wallet.sweep-zero-value-anchor-utxos=false
418+
415419
[address]
416420

417421
; If true, tapd will not try to sync issuance proofs for unknown assets when

0 commit comments

Comments
 (0)