Skip to content

Commit ebf9856

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 9b869f9 commit ebf9856

File tree

11 files changed

+194
-44
lines changed

11 files changed

+194
-44
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
@@ -170,10 +170,14 @@ type AuxComponents struct {
170170
MsgRouter fn.Option[protofsm.MsgRouter]
171171

172172
// AuxFundingController is an optional controller that can be used to
173-
// modify the way we handle certain custom chanenl types. It's also
173+
// modify the way we handle certain custom channel types. It's also
174174
// able to automatically handle new custom protocol messages related to
175175
// the funding process.
176176
AuxFundingController fn.Option[funding.AuxFundingController]
177+
178+
// AuxSigner is an optional signer that can be used to sign auxiliary
179+
// leaves for certain custom channel types.
180+
AuxSigner fn.Option[lnwallet.AuxSigner]
177181
}
178182

179183
// DefaultWalletImpl is the default implementation of our normal, btcwallet
@@ -580,6 +584,7 @@ func (d *DefaultWalletImpl) BuildWalletConfig(ctx context.Context,
580584
ChanStateDB: dbs.ChanStateDB.ChannelStateDB(),
581585
NeutrinoCS: neutrinoCS,
582586
AuxLeafStore: aux.AuxLeafStore,
587+
AuxSigner: aux.AuxSigner,
583588
ActiveNetParams: d.cfg.ActiveNetParams,
584589
FeeURL: d.cfg.FeeURL,
585590
Dialer: func(addr string) (net.Conn, error) {
@@ -732,6 +737,7 @@ func (d *DefaultWalletImpl) BuildChainControl(
732737
NetParams: *walletConfig.NetParams,
733738
CoinSelectionStrategy: walletConfig.CoinSelectionStrategy,
734739
AuxLeafStore: partialChainControl.Cfg.AuxLeafStore,
740+
AuxSigner: partialChainControl.Cfg.AuxSigner,
735741
}
736742

737743
// The broadcast is already always active for neutrino nodes, so we
@@ -911,10 +917,6 @@ type DatabaseInstances struct {
911917
// for native SQL queries for tables that already support it. This may
912918
// be nil if the use-native-sql flag was not set.
913919
NativeSQLStore *sqldb.BaseDB
914-
915-
// AuxLeafStore is an optional data source that can be used by custom
916-
// channels to fetch+store various data.
917-
AuxLeafStore fn.Option[lnwallet.AuxLeafStore]
918920
}
919921

920922
// 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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2143,6 +2143,7 @@ func (l *channelLink) handleUpstreamMsg(msg lnwire.Message) {
21432143
CommitSig: msg.CommitSig,
21442144
HtlcSigs: msg.HtlcSigs,
21452145
PartialSig: msg.PartialSig,
2146+
AuxSigBlob: msg.ExtraData,
21462147
})
21472148
if err != nil {
21482149
// If we were unable to reconstruct their proposed
@@ -2556,6 +2557,7 @@ func (l *channelLink) updateCommitTx() error {
25562557
CommitSig: newCommit.CommitSig,
25572558
HtlcSigs: newCommit.HtlcSigs,
25582559
PartialSig: newCommit.PartialSig,
2560+
ExtraData: newCommit.AuxSigBlob,
25592561
}
25602562
l.cfg.Peer.SendMessage(false, commitSig)
25612563

0 commit comments

Comments
 (0)