Skip to content

Commit

Permalink
lnwallet: obtain+verify aux sigs for all second level HTLCs
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
Roasbeef authored and guggero committed May 17, 2024
1 parent bb4fad7 commit 36416dc
Show file tree
Hide file tree
Showing 11 changed files with 187 additions and 40 deletions.
4 changes: 4 additions & 0 deletions chainreg/chainregistry.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ type Config struct {
// leaves for certain custom channel types.
AuxLeafStore fn.Option[lnwallet.AuxLeafStore]

// AuxSigner is an optional signer that can be used to sign auxiliary
// leaves for certain custom channel types.
AuxSigner fn.Option[lnwallet.AuxSigner]

// BlockCache is the main cache for storing block information.
BlockCache *blockcache.BlockCache

Expand Down
12 changes: 7 additions & 5 deletions config_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,14 @@ type AuxComponents struct {
MsgRouter fn.Option[protofsm.MsgRouter]

// AuxFundingController is an optional controller that can be used to
// modify the way we handle certain custom chanenl types. It's also
// modify the way we handle certain custom channel types. It's also
// able to automatically handle new custom protocol messages related to
// the funding process.
AuxFundingController fn.Option[funding.AuxFundingController]

// AuxSigner is an optional signer that can be used to sign auxiliary
// leaves for certain custom channel types.
AuxSigner fn.Option[lnwallet.AuxSigner]
}

// DefaultWalletImpl is the default implementation of our normal, btcwallet
Expand Down Expand Up @@ -575,6 +579,7 @@ func (d *DefaultWalletImpl) BuildWalletConfig(ctx context.Context,
ChanStateDB: dbs.ChanStateDB.ChannelStateDB(),
NeutrinoCS: neutrinoCS,
AuxLeafStore: aux.AuxLeafStore,
AuxSigner: aux.AuxSigner,
ActiveNetParams: d.cfg.ActiveNetParams,
FeeURL: d.cfg.FeeURL,
Dialer: func(addr string) (net.Conn, error) {
Expand Down Expand Up @@ -727,6 +732,7 @@ func (d *DefaultWalletImpl) BuildChainControl(
NetParams: *walletConfig.NetParams,
CoinSelectionStrategy: walletConfig.CoinSelectionStrategy,
AuxLeafStore: partialChainControl.Cfg.AuxLeafStore,
AuxSigner: partialChainControl.Cfg.AuxSigner,
}

// The broadcast is already always active for neutrino nodes, so we
Expand Down Expand Up @@ -906,10 +912,6 @@ type DatabaseInstances struct {
// for native SQL queries for tables that already support it. This may
// be nil if the use-native-sql flag was not set.
NativeSQLStore *sqldb.BaseDB

// AuxLeafStore is an optional data source that can be used by custom
// channels to fetch+store various data.
AuxLeafStore fn.Option[lnwallet.AuxLeafStore]
}

// DefaultDatabaseBuilder is a type that builds the default database backends
Expand Down
10 changes: 10 additions & 0 deletions contractcourt/chain_arbitrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@ type ChainArbitratorConfig struct {
// AuxLeafStore is an optional store that can be used to store auxiliary
// leaves for certain custom channel types.
AuxLeafStore fn.Option[lnwallet.AuxLeafStore]

// AuxSigner is an optional signer that can be used to sign auxiliary
// leaves for certain custom channel types.
AuxSigner fn.Option[lnwallet.AuxSigner]
}

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

chanMachine, err := lnwallet.NewLightningChannel(
a.c.cfg.Signer, channel, nil, chanOpts...,
Expand Down Expand Up @@ -357,6 +364,9 @@ func (a *arbChannel) ForceCloseChan() (*lnwallet.LocalForceCloseSummary, error)
a.c.cfg.AuxLeafStore.WhenSome(func(s lnwallet.AuxLeafStore) {
chanOpts = append(chanOpts, lnwallet.WithLeafStore(s))
})
a.c.cfg.AuxSigner.WhenSome(func(s lnwallet.AuxSigner) {
chanOpts = append(chanOpts, lnwallet.WithAuxSigner(s))
})

// Finally, we'll force close the channel completing
// the force close workflow.
Expand Down
7 changes: 7 additions & 0 deletions funding/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,10 @@ type Config struct {
// able to automatically handle new custom protocol messages related to
// the funding process.
AuxFundingController fn.Option[AuxFundingController]

// AuxSigner is an optional signer that can be used to sign auxiliary
// leaves for certain custom channel types.
AuxSigner fn.Option[lnwallet.AuxSigner]
}

// Manager acts as an orchestrator/bridge between the wallet's
Expand Down Expand Up @@ -1077,6 +1081,9 @@ func (f *Manager) advanceFundingState(channel *channeldb.OpenChannel,
f.cfg.AuxLeafStore.WhenSome(func(s lnwallet.AuxLeafStore) {
chanOpts = append(chanOpts, lnwallet.WithLeafStore(s))
})
f.cfg.AuxSigner.WhenSome(func(s lnwallet.AuxSigner) {
chanOpts = append(chanOpts, lnwallet.WithAuxSigner(s))
})

// We create the state-machine object which wraps the database state.
lnChannel, err := lnwallet.NewLightningChannel(
Expand Down
1 change: 1 addition & 0 deletions htlcswitch/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -2554,6 +2554,7 @@ func (l *channelLink) updateCommitTx() error {
CommitSig: newCommit.CommitSig,
HtlcSigs: newCommit.HtlcSigs,
PartialSig: newCommit.PartialSig,
ExtraData: newCommit.AuxSigBlob,
}
l.cfg.Peer.SendMessage(false, commitSig)

Expand Down

0 comments on commit 36416dc

Please sign in to comment.