Skip to content

Commit c0c511c

Browse files
Roasbeefguggero
authored andcommitted
lnwallet: obtain+verify aux sigs for all second level HTLCs
In this commit, we start to use the new AuxSigner to obtain+verify aux sigs for all second level HTLCs. This is similar to the existing SigPool, but we'll only attempt to do this if the AuxSigner is present (won't be for most channels).
1 parent e9e10cc commit c0c511c

File tree

12 files changed

+181
-36
lines changed

12 files changed

+181
-36
lines changed

chainreg/chainregistry.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ type Config struct {
6868
// leaves for certain custom channel types.
6969
AuxLeafStore fn.Option[lnwallet.AuxLeafStore]
7070

71+
// AuxSigner is an optional signer that can be used to sign auxiliary
72+
// leaves for certain custom channel types.
73+
AuxSigner fn.Option[lnwallet.AuxSigner]
74+
7175
// BlockCache is the main cache for storing block information.
7276
BlockCache *blockcache.BlockCache
7377

config_builder.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,14 @@ type AuxComponents struct {
165165
MsgRouter fn.Option[protofsm.MsgRouter]
166166

167167
// AuxFundingController is an optional controller that can be used to
168-
// modify the way we handle certain custom chanenl types. It's also
168+
// modify the way we handle certain custom channel types. It's also
169169
// able to automatically handle new custom protocol messages related to
170170
// the funding process.
171171
AuxFundingController fn.Option[funding.AuxFundingController]
172+
173+
// AuxSigner is an optional signer that can be used to sign auxiliary
174+
// leaves for certain custom channel types.
175+
AuxSigner fn.Option[lnwallet.AuxSigner]
172176
}
173177

174178
// DefaultWalletImpl is the default implementation of our normal, btcwallet
@@ -575,6 +579,7 @@ func (d *DefaultWalletImpl) BuildWalletConfig(ctx context.Context,
575579
ChanStateDB: dbs.ChanStateDB.ChannelStateDB(),
576580
NeutrinoCS: neutrinoCS,
577581
AuxLeafStore: aux.AuxLeafStore,
582+
AuxSigner: aux.AuxSigner,
578583
ActiveNetParams: d.cfg.ActiveNetParams,
579584
FeeURL: d.cfg.FeeURL,
580585
Dialer: func(addr string) (net.Conn, error) {
@@ -727,6 +732,7 @@ func (d *DefaultWalletImpl) BuildChainControl(
727732
NetParams: *walletConfig.NetParams,
728733
CoinSelectionStrategy: walletConfig.CoinSelectionStrategy,
729734
AuxLeafStore: partialChainControl.Cfg.AuxLeafStore,
735+
AuxSigner: partialChainControl.Cfg.AuxSigner,
730736
}
731737

732738
// The broadcast is already always active for neutrino nodes, so we
@@ -906,10 +912,6 @@ type DatabaseInstances struct {
906912
// for native SQL queries for tables that already support it. This may
907913
// be nil if the use-native-sql flag was not set.
908914
NativeSQLStore *sqldb.BaseDB
909-
910-
// AuxLeafStore is an optional data source that can be used by custom
911-
// channels to fetch+store various data.
912-
AuxLeafStore fn.Option[lnwallet.AuxLeafStore]
913915
}
914916

915917
// DefaultDatabaseBuilder is a type that builds the default database backends

contractcourt/chain_arbitrator.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,10 @@ type ChainArbitratorConfig struct {
221221
// AuxLeafStore is an optional store that can be used to store auxiliary
222222
// leaves for certain custom channel types.
223223
AuxLeafStore fn.Option[lnwallet.AuxLeafStore]
224+
225+
// AuxSigner is an optional signer that can be used to sign auxiliary
226+
// leaves for certain custom channel types.
227+
AuxSigner fn.Option[lnwallet.AuxSigner]
224228
}
225229

226230
// ChainArbitrator is a sub-system that oversees the on-chain resolution of all
@@ -307,6 +311,9 @@ func (a *arbChannel) NewAnchorResolutions() (*lnwallet.AnchorResolutions,
307311
a.c.cfg.AuxLeafStore.WhenSome(func(s lnwallet.AuxLeafStore) {
308312
chanOpts = append(chanOpts, lnwallet.WithLeafStore(s))
309313
})
314+
a.c.cfg.AuxSigner.WhenSome(func(s lnwallet.AuxSigner) {
315+
chanOpts = append(chanOpts, lnwallet.WithAuxSigner(s))
316+
})
310317

311318
chanMachine, err := lnwallet.NewLightningChannel(
312319
a.c.cfg.Signer, channel, nil, chanOpts...,
@@ -357,6 +364,9 @@ func (a *arbChannel) ForceCloseChan() (*lnwallet.LocalForceCloseSummary, error)
357364
a.c.cfg.AuxLeafStore.WhenSome(func(s lnwallet.AuxLeafStore) {
358365
chanOpts = append(chanOpts, lnwallet.WithLeafStore(s))
359366
})
367+
a.c.cfg.AuxSigner.WhenSome(func(s lnwallet.AuxSigner) {
368+
chanOpts = append(chanOpts, lnwallet.WithAuxSigner(s))
369+
})
360370

361371
// Finally, we'll force close the channel completing
362372
// the force close workflow.

funding/manager.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,10 @@ type Config struct {
548548
// able to automatically handle new custom protocol messages related to
549549
// the funding process.
550550
AuxFundingController fn.Option[AuxFundingController]
551+
552+
// AuxSigner is an optional signer that can be used to sign auxiliary
553+
// leaves for certain custom channel types.
554+
AuxSigner fn.Option[lnwallet.AuxSigner]
551555
}
552556

553557
// Manager acts as an orchestrator/bridge between the wallet's
@@ -1077,6 +1081,9 @@ func (f *Manager) advanceFundingState(channel *channeldb.OpenChannel,
10771081
f.cfg.AuxLeafStore.WhenSome(func(s lnwallet.AuxLeafStore) {
10781082
chanOpts = append(chanOpts, lnwallet.WithLeafStore(s))
10791083
})
1084+
f.cfg.AuxSigner.WhenSome(func(s lnwallet.AuxSigner) {
1085+
chanOpts = append(chanOpts, lnwallet.WithAuxSigner(s))
1086+
})
10801087

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

htlcswitch/link.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2554,6 +2554,7 @@ func (l *channelLink) updateCommitTx() error {
25542554
CommitSig: newCommit.CommitSig,
25552555
HtlcSigs: newCommit.HtlcSigs,
25562556
PartialSig: newCommit.PartialSig,
2557+
ExtraData: newCommit.AuxSigBlob,
25572558
}
25582559
l.cfg.Peer.SendMessage(false, commitSig)
25592560

lnwallet/aux_signer.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ type AuxSigJobResp struct {
7777
// blob
7878
SigBlob fn.Option[tlv.Blob]
7979

80+
// HtlcIndex is the index of the HTLC that was signed.
81+
HtlcIndex uint64
82+
8083
// Err is the error that occurred when executing the specified
8184
// signature job. In the case that no error occurred, this value will
8285
// be nil.

0 commit comments

Comments
 (0)