@@ -3,13 +3,11 @@ package tapchannel
33import (
44 "bytes"
55 "fmt"
6- "sync"
76 "time"
87
98 "github.com/btcsuite/btcd/txscript"
109 "github.com/btcsuite/btcd/wire"
1110 "github.com/lightninglabs/taproot-assets/address"
12- "github.com/lightninglabs/taproot-assets/fn"
1311 cmsg "github.com/lightninglabs/taproot-assets/tapchannelmsg"
1412 "github.com/lightningnetwork/lnd/channeldb"
1513 lfn "github.com/lightningnetwork/lnd/fn"
@@ -25,67 +23,12 @@ const (
2523 DefaultTimeout = 30 * time .Second
2624)
2725
28- // LeafCreatorConfig defines the configuration for the auxiliary leaf creator.
29- type LeafCreatorConfig struct {
30- ChainParams * address.ChainParams
31- }
32-
33- // AuxLeafCreator is a Taproot Asset auxiliary leaf creator that can be used to
34- // create auxiliary leaves for Taproot Asset channels.
35- type AuxLeafCreator struct {
36- startOnce sync.Once
37- stopOnce sync.Once
38-
39- cfg * LeafCreatorConfig
40-
41- // ContextGuard provides a wait group and main quit channel that can be
42- // used to create guarded contexts.
43- * fn.ContextGuard
44- }
45-
46- // NewAuxLeafCreator creates a new Taproot Asset auxiliary leaf creator based on
47- // the passed config.
48- func NewAuxLeafCreator (cfg * LeafCreatorConfig ) * AuxLeafCreator {
49- return & AuxLeafCreator {
50- cfg : cfg ,
51- ContextGuard : & fn.ContextGuard {
52- DefaultTimeout : DefaultTimeout ,
53- Quit : make (chan struct {}),
54- },
55- }
56- }
57-
58- // Start attempts to start a new aux leaf creator.
59- func (c * AuxLeafCreator ) Start () error {
60- var startErr error
61- c .startOnce .Do (func () {
62- log .Info ("Starting aux leaf creator" )
63- })
64- return startErr
65- }
66-
67- // Stop signals for a custodian to gracefully exit.
68- func (c * AuxLeafCreator ) Stop () error {
69- var stopErr error
70- c .stopOnce .Do (func () {
71- log .Info ("Stopping aux leaf creator" )
72-
73- close (c .Quit )
74- c .Wg .Wait ()
75- })
76-
77- return stopErr
78- }
79-
80- // A compile-time check to ensure that AuxLeafCreator fully implements the
81- // lnwallet.AuxLeafStore interface.
82- var _ lnwallet.AuxLeafStore = (* AuxLeafCreator )(nil )
83-
8426// FetchLeavesFromView attempts to fetch the auxiliary leaves that correspond to
8527// the passed aux blob, and pending fully evaluated HTLC view.
86- func (c * AuxLeafCreator ) FetchLeavesFromView (chanState * channeldb.OpenChannel ,
87- prevBlob tlv.Blob , originalView * lnwallet.HtlcView , isOurCommit bool ,
88- ourBalance , theirBalance lnwire.MilliSatoshi ,
28+ func FetchLeavesFromView (chainParams * address.ChainParams ,
29+ chanState * channeldb.OpenChannel , prevBlob tlv.Blob ,
30+ originalView * lnwallet.HtlcView , isOurCommit bool , ourBalance ,
31+ theirBalance lnwire.MilliSatoshi ,
8932 keys lnwallet.CommitmentKeyRing ) (lfn.Option [lnwallet.CommitAuxLeaves ],
9033 lnwallet.CommitSortFunc , error ) {
9134
@@ -112,7 +55,7 @@ func (c *AuxLeafCreator) FetchLeavesFromView(chanState *channeldb.OpenChannel,
11255
11356 allocations , newCommitment , err := GenerateCommitmentAllocations (
11457 prevState , chanState , chanAssetState , isOurCommit , ourBalance ,
115- theirBalance , originalView , c . cfg . ChainParams , keys ,
58+ theirBalance , originalView , chainParams , keys ,
11659 )
11760 if err != nil {
11861 return none , nil , fmt .Errorf ("unable to generate allocations: " +
@@ -132,8 +75,8 @@ func (c *AuxLeafCreator) FetchLeavesFromView(chanState *channeldb.OpenChannel,
13275
13376// FetchLeavesFromCommit attempts to fetch the auxiliary leaves that correspond
13477// to the passed aux blob, and an existing channel commitment.
135- func ( c * AuxLeafCreator ) FetchLeavesFromCommit (chanState * channeldb. OpenChannel ,
136- com channeldb.ChannelCommitment ,
78+ func FetchLeavesFromCommit (chainParams * address. ChainParams ,
79+ chanState * channeldb. OpenChannel , com channeldb.ChannelCommitment ,
13780 keys lnwallet.CommitmentKeyRing ) (lfn.Option [lnwallet.CommitAuxLeaves ],
13881 error ) {
13982
@@ -173,7 +116,7 @@ func (c *AuxLeafCreator) FetchLeavesFromCommit(chanState *channeldb.OpenChannel,
173116
174117 leaf , err := CreateSecondLevelHtlcTx (
175118 chanState , com .CommitTx , htlc .Amt .ToSatoshis (),
176- keys , c . cfg . ChainParams , htlcOutputs ,
119+ keys , chainParams , htlcOutputs ,
177120 )
178121 if err != nil {
179122 return none , fmt .Errorf ("unable to create " +
@@ -204,7 +147,7 @@ func (c *AuxLeafCreator) FetchLeavesFromCommit(chanState *channeldb.OpenChannel,
204147
205148 leaf , err := CreateSecondLevelHtlcTx (
206149 chanState , com .CommitTx , htlc .Amt .ToSatoshis (),
207- keys , c . cfg . ChainParams , htlcOutputs ,
150+ keys , chainParams , htlcOutputs ,
208151 )
209152 if err != nil {
210153 return none , fmt .Errorf ("unable to create " +
@@ -231,7 +174,7 @@ func (c *AuxLeafCreator) FetchLeavesFromCommit(chanState *channeldb.OpenChannel,
231174
232175// FetchLeavesFromRevocation attempts to fetch the auxiliary leaves
233176// from a channel revocation that stores balance + blob information.
234- func ( c * AuxLeafCreator ) FetchLeavesFromRevocation (
177+ func FetchLeavesFromRevocation (
235178 rev * channeldb.RevocationLog ) (lfn.Option [lnwallet.CommitAuxLeaves ],
236179 error ) {
237180
@@ -255,8 +198,9 @@ func (c *AuxLeafCreator) FetchLeavesFromRevocation(
255198// ApplyHtlcView serves as the state transition function for the custom
256199// channel's blob. Given the old blob, and an HTLC view, then a new
257200// blob should be returned that reflects the pending updates.
258- func (c * AuxLeafCreator ) ApplyHtlcView (chanState * channeldb.OpenChannel ,
259- prevBlob tlv.Blob , originalView * lnwallet.HtlcView , isOurCommit bool ,
201+ func ApplyHtlcView (chainParams * address.ChainParams ,
202+ chanState * channeldb.OpenChannel , prevBlob tlv.Blob ,
203+ originalView * lnwallet.HtlcView , isOurCommit bool ,
260204 ourBalance , theirBalance lnwire.MilliSatoshi ,
261205 keys lnwallet.CommitmentKeyRing ) (lfn.Option [tlv.Blob ], error ) {
262206
@@ -283,7 +227,7 @@ func (c *AuxLeafCreator) ApplyHtlcView(chanState *channeldb.OpenChannel,
283227
284228 _ , newCommitment , err := GenerateCommitmentAllocations (
285229 prevState , chanState , chanAssetState , isOurCommit , ourBalance ,
286- theirBalance , originalView , c . cfg . ChainParams , keys ,
230+ theirBalance , originalView , chainParams , keys ,
287231 )
288232 if err != nil {
289233 return none , fmt .Errorf ("unable to generate allocations: %w" ,
0 commit comments