Skip to content

Commit fd36830

Browse files
Roasbeefguggero
authored andcommitted
multi: hook up new aux interfaces
1 parent c2648d1 commit fd36830

File tree

9 files changed

+59
-21
lines changed

9 files changed

+59
-21
lines changed

config_builder.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import (
5050
"github.com/lightningnetwork/lnd/rpcperms"
5151
"github.com/lightningnetwork/lnd/signal"
5252
"github.com/lightningnetwork/lnd/sqldb"
53+
"github.com/lightningnetwork/lnd/sweep"
5354
"github.com/lightningnetwork/lnd/walletunlocker"
5455
"github.com/lightningnetwork/lnd/watchtower"
5556
"github.com/lightningnetwork/lnd/watchtower/wtclient"
@@ -188,13 +189,13 @@ type AuxComponents struct {
188189
// modify the way a coop-close transaction is constructed.
189190
AuxChanCloser fn.Option[chancloser.AuxChanCloser]
190191

192+
// AuxSweeper is an optional interface that can be used to modify the
193+
// way sweep transaction are generated.
194+
AuxSweeper fn.Option[sweep.AuxSweeper]
195+
191196
// AuxContractResolver is an optional interface that can be used to
192197
// modify the way contracts are resolved.
193198
AuxContractResolver fn.Option[lnwallet.AuxContractResolver]
194-
195-
// AuxSweeper is an optional interface that can be used to modify the
196-
// way sweep transaction are generated.
197-
AuxSweeper fn.Option[lnwallet.AuxContractResolver]
198199
}
199200

200201
// DefaultWalletImpl is the default implementation of our normal, btcwallet

contractcourt/chain_arbitrator.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,10 @@ type ChainArbitratorConfig struct {
225225
// AuxSigner is an optional signer that can be used to sign auxiliary
226226
// leaves for certain custom channel types.
227227
AuxSigner fn.Option[lnwallet.AuxSigner]
228+
229+
// AuxResolver is an optional interface that can be used to modify the
230+
// way contracts are resolved.
231+
AuxResolver fn.Option[lnwallet.AuxContractResolver]
228232
}
229233

230234
// ChainArbitrator is a sub-system that oversees the on-chain resolution of all
@@ -314,6 +318,9 @@ func (a *arbChannel) NewAnchorResolutions() (*lnwallet.AnchorResolutions,
314318
a.c.cfg.AuxSigner.WhenSome(func(s lnwallet.AuxSigner) {
315319
chanOpts = append(chanOpts, lnwallet.WithAuxSigner(s))
316320
})
321+
a.c.cfg.AuxResolver.WhenSome(func(s lnwallet.AuxContractResolver) {
322+
chanOpts = append(chanOpts, lnwallet.WithAuxResolver(s))
323+
})
317324

318325
chanMachine, err := lnwallet.NewLightningChannel(
319326
a.c.cfg.Signer, channel, nil, chanOpts...,
@@ -367,6 +374,9 @@ func (a *arbChannel) ForceCloseChan() (*lnwallet.LocalForceCloseSummary, error)
367374
a.c.cfg.AuxSigner.WhenSome(func(s lnwallet.AuxSigner) {
368375
chanOpts = append(chanOpts, lnwallet.WithAuxSigner(s))
369376
})
377+
a.c.cfg.AuxResolver.WhenSome(func(s lnwallet.AuxContractResolver) {
378+
chanOpts = append(chanOpts, lnwallet.WithAuxResolver(s))
379+
})
370380

371381
// Finally, we'll force close the channel completing
372382
// the force close workflow.
@@ -1198,10 +1208,11 @@ func (c *ChainArbitrator) WatchNewChannel(newChan *channeldb.OpenChannel) error
11981208
// that we detect any relevant on chain events.
11991209
chainWatcher, err := newChainWatcher(
12001210
chainWatcherConfig{
1201-
chanState: newChan,
1202-
notifier: c.cfg.Notifier,
1203-
signer: c.cfg.Signer,
1204-
isOurAddr: c.cfg.IsOurAddress,
1211+
chanState: newChan,
1212+
notifier: c.cfg.Notifier,
1213+
signer: c.cfg.Signer,
1214+
isOurAddr: c.cfg.IsOurAddress,
1215+
auxResolver: c.cfg.AuxResolver,
12051216
contractBreach: func(
12061217
retInfo *lnwallet.BreachRetribution) error {
12071218

contractcourt/chain_watcher.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,8 @@ type chainWatcherConfig struct {
196196
// auxLeafStore can be used to fetch information for custom channels.
197197
auxLeafStore fn.Option[lnwallet.AuxLeafStore]
198198

199-
// auxResolver...
199+
// auxResolver is used to supplement contract resolution.
200200
auxResolver fn.Option[lnwallet.AuxContractResolver]
201-
202-
// TODO(roasbeef): always set in config ^
203201
}
204202

205203
// chainWatcher is a system that's assigned to every active channel. The duty

funding/manager.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,10 @@ type Config struct {
558558
// AuxSigner is an optional signer that can be used to sign auxiliary
559559
// leaves for certain custom channel types.
560560
AuxSigner fn.Option[lnwallet.AuxSigner]
561+
562+
// AuxResolver is an optional interface that can be used to modify the
563+
// way contracts are resolved.
564+
AuxResolver fn.Option[lnwallet.AuxContractResolver]
561565
}
562566

563567
// Manager acts as an orchestrator/bridge between the wallet's
@@ -1090,6 +1094,9 @@ func (f *Manager) advanceFundingState(channel *channeldb.OpenChannel,
10901094
f.cfg.AuxSigner.WhenSome(func(s lnwallet.AuxSigner) {
10911095
chanOpts = append(chanOpts, lnwallet.WithAuxSigner(s))
10921096
})
1097+
f.cfg.AuxResolver.WhenSome(func(s lnwallet.AuxContractResolver) {
1098+
chanOpts = append(chanOpts, lnwallet.WithAuxResolver(s))
1099+
})
10931100

10941101
// We create the state-machine object which wraps the database state.
10951102
lnChannel, err := lnwallet.NewLightningChannel(

lnwallet/channel.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -978,7 +978,8 @@ func WithAuxSigner(signer AuxSigner) ChannelOpt {
978978
}
979979
}
980980

981-
// WithAuxResolver...
981+
// WithAuxResolver is used to specify a custom aux contract resolver for the
982+
// channel.
982983
func WithAuxResolver(resolver AuxContractResolver) ChannelOpt {
983984
return func(o *channelOpts) {
984985
o.auxResolver = fn.Some[AuxContractResolver](resolver)

peer/brontide.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,10 @@ type Config struct {
395395
// leaves for certain custom channel types.
396396
AuxSigner fn.Option[lnwallet.AuxSigner]
397397

398+
// AuxResolver is an optional interface that can be used to modify the
399+
// way contracts are resolved.
400+
AuxResolver fn.Option[lnwallet.AuxContractResolver]
401+
398402
// PongBuf is a slice we'll reuse instead of allocating memory on the
399403
// heap. Since only reads will occur and no writes, there is no need
400404
// for any synchronization primitives. As a result, it's safe to share
@@ -997,15 +1001,17 @@ func (p *Brontide) loadActiveChannels(chans []*channeldb.OpenChannel) (
9971001
}
9981002
}
9991003

1000-
// TODO(roasbeef): also make aux resolver here
1001-
10021004
var chanOpts []lnwallet.ChannelOpt
10031005
p.cfg.AuxLeafStore.WhenSome(func(s lnwallet.AuxLeafStore) {
10041006
chanOpts = append(chanOpts, lnwallet.WithLeafStore(s))
10051007
})
10061008
p.cfg.AuxSigner.WhenSome(func(s lnwallet.AuxSigner) {
10071009
chanOpts = append(chanOpts, lnwallet.WithAuxSigner(s))
10081010
})
1011+
p.cfg.AuxResolver.WhenSome(func(s lnwallet.AuxContractResolver) { //nolint:lll
1012+
chanOpts = append(chanOpts, lnwallet.WithAuxResolver(s))
1013+
})
1014+
10091015
lnChan, err := lnwallet.NewLightningChannel(
10101016
p.cfg.Signer, dbChan, p.cfg.SigPool, chanOpts...,
10111017
)
@@ -4181,6 +4187,9 @@ func (p *Brontide) addActiveChannel(c *lnpeer.NewChannel) error {
41814187
p.cfg.AuxSigner.WhenSome(func(s lnwallet.AuxSigner) {
41824188
chanOpts = append(chanOpts, lnwallet.WithAuxSigner(s))
41834189
})
4190+
p.cfg.AuxResolver.WhenSome(func(s lnwallet.AuxContractResolver) {
4191+
chanOpts = append(chanOpts, lnwallet.WithAuxResolver(s))
4192+
})
41844193

41854194
// If not already active, we'll add this channel to the set of active
41864195
// channels, so we can look it up later easily according to its channel

server.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,10 +1111,11 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
11111111
)
11121112

11131113
s.txPublisher = sweep.NewTxPublisher(sweep.TxPublisherConfig{
1114-
Signer: cc.Wallet.Cfg.Signer,
1115-
Wallet: cc.Wallet,
1116-
Estimator: cc.FeeEstimator,
1117-
Notifier: cc.ChainNotifier,
1114+
Signer: cc.Wallet.Cfg.Signer,
1115+
Wallet: cc.Wallet,
1116+
Estimator: cc.FeeEstimator,
1117+
Notifier: cc.ChainNotifier,
1118+
AuxSweeper: s.implCfg.AuxSweeper,
11181119
})
11191120

11201121
s.sweeper = sweep.New(&sweep.UtxoSweeperConfig{
@@ -1132,6 +1133,7 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
11321133
Aggregator: aggregator,
11331134
Publisher: s.txPublisher,
11341135
NoDeadlineConfTarget: cfg.Sweeper.NoDeadlineConfTarget,
1136+
AuxSweeper: s.implCfg.AuxSweeper,
11351137
})
11361138

11371139
s.utxoNursery = contractcourt.NewUtxoNursery(&contractcourt.NurseryConfig{
@@ -1309,6 +1311,7 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
13091311
},
13101312
AuxLeafStore: implCfg.AuxLeafStore,
13111313
AuxSigner: implCfg.AuxSigner,
1314+
AuxResolver: implCfg.AuxContractResolver,
13121315
}, dbs.ChanStateDB)
13131316

13141317
// Select the configuration and funding parameters for Bitcoin.
@@ -1557,6 +1560,8 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
15571560
AliasManager: s.aliasMgr,
15581561
IsSweeperOutpoint: s.sweeper.IsSweeperOutpoint,
15591562
AuxFundingController: implCfg.AuxFundingController,
1563+
AuxSigner: implCfg.AuxSigner,
1564+
AuxResolver: implCfg.AuxContractResolver,
15601565
})
15611566
if err != nil {
15621567
return nil, err
@@ -1644,7 +1649,8 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
16441649

16451650
br, err := lnwallet.NewBreachRetribution(
16461651
channel, commitHeight, 0, nil,
1647-
implCfg.AuxLeafStore, implCfg.AuxSweeper,
1652+
implCfg.AuxLeafStore,
1653+
implCfg.AuxContractResolver,
16481654
)
16491655
if err != nil {
16501656
return nil, 0, err
@@ -4002,6 +4008,7 @@ func (s *server) peerConnected(conn net.Conn, connReq *connmgr.ConnReq,
40024008
AuxSigner: s.implCfg.AuxSigner,
40034009
MsgRouter: s.implCfg.MsgRouter,
40044010
AuxChanCloser: s.implCfg.AuxChanCloser,
4011+
AuxResolver: s.implCfg.AuxContractResolver,
40054012
}
40064013

40074014
copy(pCfg.PubKeyBytes[:], peerAddr.IdentityKey.SerializeCompressed())

sweep/fee_bumper.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,8 @@ type TxPublisherConfig struct {
258258
// Notifier is used to monitor the confirmation status of the tx.
259259
Notifier chainntnfs.ChainNotifier
260260

261-
// AuxSweeper is an optional interface that can be used to shape the
262-
// way the final sweep transaction is generated.
261+
// AuxSweeper is an optional interface that can be used to modify the
262+
// way sweep transaction are generated.
263263
AuxSweeper fn.Option[AuxSweeper]
264264
}
265265

sweep/sweeper.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,10 @@ type UtxoSweeperConfig struct {
362362
// NoDeadlineConfTarget is the conf target to use when sweeping
363363
// non-time-sensitive outputs.
364364
NoDeadlineConfTarget uint32
365+
366+
// AuxSweeper is an optional interface that can be used to modify the
367+
// way sweep transaction are generated.
368+
AuxSweeper fn.Option[AuxSweeper]
365369
}
366370

367371
// Result is the struct that is pushed through the result channel. Callers can

0 commit comments

Comments
 (0)