multi: hook up new aux interfaces

This commit is contained in:
Olaoluwa Osuntokun 2024-06-08 20:10:27 -07:00
parent 47f728e548
commit 9a181105e2
No known key found for this signature in database
GPG Key ID: 3BBD59E99B280306
4 changed files with 39 additions and 2 deletions

View File

@ -225,6 +225,10 @@ type ChainArbitratorConfig struct {
// AuxSigner is an optional signer that can be used to sign auxiliary // AuxSigner is an optional signer that can be used to sign auxiliary
// leaves for certain custom channel types. // leaves for certain custom channel types.
AuxSigner fn.Option[lnwallet.AuxSigner] AuxSigner fn.Option[lnwallet.AuxSigner]
// AuxResolver is an optional interface that can be used to modify the
// way contracts are resolved.
AuxResolver fn.Option[lnwallet.AuxContractResolver]
} }
// ChainArbitrator is a sub-system that oversees the on-chain resolution of all // ChainArbitrator is a sub-system that oversees the on-chain resolution of all
@ -314,6 +318,9 @@ func (a *arbChannel) NewAnchorResolutions() (*lnwallet.AnchorResolutions,
a.c.cfg.AuxSigner.WhenSome(func(s lnwallet.AuxSigner) { a.c.cfg.AuxSigner.WhenSome(func(s lnwallet.AuxSigner) {
chanOpts = append(chanOpts, lnwallet.WithAuxSigner(s)) chanOpts = append(chanOpts, lnwallet.WithAuxSigner(s))
}) })
a.c.cfg.AuxResolver.WhenSome(func(s lnwallet.AuxContractResolver) {
chanOpts = append(chanOpts, lnwallet.WithAuxResolver(s))
})
chanMachine, err := lnwallet.NewLightningChannel( chanMachine, err := lnwallet.NewLightningChannel(
a.c.cfg.Signer, channel, nil, chanOpts..., a.c.cfg.Signer, channel, nil, chanOpts...,
@ -367,6 +374,9 @@ func (a *arbChannel) ForceCloseChan() (*lnwallet.LocalForceCloseSummary, error)
a.c.cfg.AuxSigner.WhenSome(func(s lnwallet.AuxSigner) { a.c.cfg.AuxSigner.WhenSome(func(s lnwallet.AuxSigner) {
chanOpts = append(chanOpts, lnwallet.WithAuxSigner(s)) chanOpts = append(chanOpts, lnwallet.WithAuxSigner(s))
}) })
a.c.cfg.AuxResolver.WhenSome(func(s lnwallet.AuxContractResolver) {
chanOpts = append(chanOpts, lnwallet.WithAuxResolver(s))
})
// Finally, we'll force close the channel completing // Finally, we'll force close the channel completing
// the force close workflow. // the force close workflow.
@ -581,6 +591,8 @@ func (c *ChainArbitrator) Start() error {
isOurAddr: c.cfg.IsOurAddress, isOurAddr: c.cfg.IsOurAddress,
contractBreach: breachClosure, contractBreach: breachClosure,
extractStateNumHint: lnwallet.GetStateNumHint, extractStateNumHint: lnwallet.GetStateNumHint,
auxLeafStore: c.cfg.AuxLeafStore,
auxResolver: c.cfg.AuxResolver,
}, },
) )
if err != nil { if err != nil {
@ -1210,6 +1222,8 @@ func (c *ChainArbitrator) WatchNewChannel(newChan *channeldb.OpenChannel) error
) )
}, },
extractStateNumHint: lnwallet.GetStateNumHint, extractStateNumHint: lnwallet.GetStateNumHint,
auxLeafStore: c.cfg.AuxLeafStore,
auxResolver: c.cfg.AuxResolver,
}, },
) )
if err != nil { if err != nil {

View File

@ -558,6 +558,10 @@ type Config struct {
// AuxSigner is an optional signer that can be used to sign auxiliary // AuxSigner is an optional signer that can be used to sign auxiliary
// leaves for certain custom channel types. // leaves for certain custom channel types.
AuxSigner fn.Option[lnwallet.AuxSigner] AuxSigner fn.Option[lnwallet.AuxSigner]
// AuxResolver is an optional interface that can be used to modify the
// way contracts are resolved.
AuxResolver fn.Option[lnwallet.AuxContractResolver]
} }
// Manager acts as an orchestrator/bridge between the wallet's // Manager acts as an orchestrator/bridge between the wallet's
@ -1090,6 +1094,9 @@ func (f *Manager) advanceFundingState(channel *channeldb.OpenChannel,
f.cfg.AuxSigner.WhenSome(func(s lnwallet.AuxSigner) { f.cfg.AuxSigner.WhenSome(func(s lnwallet.AuxSigner) {
chanOpts = append(chanOpts, lnwallet.WithAuxSigner(s)) chanOpts = append(chanOpts, lnwallet.WithAuxSigner(s))
}) })
f.cfg.AuxResolver.WhenSome(func(s lnwallet.AuxContractResolver) {
chanOpts = append(chanOpts, lnwallet.WithAuxResolver(s))
})
// We create the state-machine object which wraps the database state. // We create the state-machine object which wraps the database state.
lnChannel, err := lnwallet.NewLightningChannel( lnChannel, err := lnwallet.NewLightningChannel(

View File

@ -396,6 +396,10 @@ type Config struct {
// leaves for certain custom channel types. // leaves for certain custom channel types.
AuxSigner fn.Option[lnwallet.AuxSigner] AuxSigner fn.Option[lnwallet.AuxSigner]
// AuxResolver is an optional interface that can be used to modify the
// way contracts are resolved.
AuxResolver fn.Option[lnwallet.AuxContractResolver]
// PongBuf is a slice we'll reuse instead of allocating memory on the // PongBuf is a slice we'll reuse instead of allocating memory on the
// heap. Since only reads will occur and no writes, there is no need // heap. Since only reads will occur and no writes, there is no need
// for any synchronization primitives. As a result, it's safe to share // for any synchronization primitives. As a result, it's safe to share
@ -999,8 +1003,6 @@ func (p *Brontide) loadActiveChannels(chans []*channeldb.OpenChannel) (
} }
} }
// TODO(roasbeef): also make aux resolver here
var chanOpts []lnwallet.ChannelOpt var chanOpts []lnwallet.ChannelOpt
p.cfg.AuxLeafStore.WhenSome(func(s lnwallet.AuxLeafStore) { p.cfg.AuxLeafStore.WhenSome(func(s lnwallet.AuxLeafStore) {
chanOpts = append(chanOpts, lnwallet.WithLeafStore(s)) chanOpts = append(chanOpts, lnwallet.WithLeafStore(s))
@ -1008,6 +1010,14 @@ func (p *Brontide) loadActiveChannels(chans []*channeldb.OpenChannel) (
p.cfg.AuxSigner.WhenSome(func(s lnwallet.AuxSigner) { p.cfg.AuxSigner.WhenSome(func(s lnwallet.AuxSigner) {
chanOpts = append(chanOpts, lnwallet.WithAuxSigner(s)) chanOpts = append(chanOpts, lnwallet.WithAuxSigner(s))
}) })
p.cfg.AuxResolver.WhenSome(
func(s lnwallet.AuxContractResolver) {
chanOpts = append(
chanOpts, lnwallet.WithAuxResolver(s),
)
},
)
lnChan, err := lnwallet.NewLightningChannel( lnChan, err := lnwallet.NewLightningChannel(
p.cfg.Signer, dbChan, p.cfg.SigPool, chanOpts..., p.cfg.Signer, dbChan, p.cfg.SigPool, chanOpts...,
) )
@ -4254,6 +4264,9 @@ func (p *Brontide) addActiveChannel(c *lnpeer.NewChannel) error {
p.cfg.AuxSigner.WhenSome(func(s lnwallet.AuxSigner) { p.cfg.AuxSigner.WhenSome(func(s lnwallet.AuxSigner) {
chanOpts = append(chanOpts, lnwallet.WithAuxSigner(s)) chanOpts = append(chanOpts, lnwallet.WithAuxSigner(s))
}) })
p.cfg.AuxResolver.WhenSome(func(s lnwallet.AuxContractResolver) {
chanOpts = append(chanOpts, lnwallet.WithAuxResolver(s))
})
// If not already active, we'll add this channel to the set of active // If not already active, we'll add this channel to the set of active
// channels, so we can look it up later easily according to its channel // channels, so we can look it up later easily according to its channel

View File

@ -1319,6 +1319,7 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
}, },
AuxLeafStore: implCfg.AuxLeafStore, AuxLeafStore: implCfg.AuxLeafStore,
AuxSigner: implCfg.AuxSigner, AuxSigner: implCfg.AuxSigner,
AuxResolver: implCfg.AuxContractResolver,
}, dbs.ChanStateDB) }, dbs.ChanStateDB)
// Select the configuration and funding parameters for Bitcoin. // Select the configuration and funding parameters for Bitcoin.
@ -1568,6 +1569,7 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
IsSweeperOutpoint: s.sweeper.IsSweeperOutpoint, IsSweeperOutpoint: s.sweeper.IsSweeperOutpoint,
AuxFundingController: implCfg.AuxFundingController, AuxFundingController: implCfg.AuxFundingController,
AuxSigner: implCfg.AuxSigner, AuxSigner: implCfg.AuxSigner,
AuxResolver: implCfg.AuxContractResolver,
}) })
if err != nil { if err != nil {
return nil, err return nil, err
@ -4150,6 +4152,7 @@ func (s *server) peerConnected(conn net.Conn, connReq *connmgr.ConnReq,
AuxSigner: s.implCfg.AuxSigner, AuxSigner: s.implCfg.AuxSigner,
MsgRouter: s.implCfg.MsgRouter, MsgRouter: s.implCfg.MsgRouter,
AuxChanCloser: s.implCfg.AuxChanCloser, AuxChanCloser: s.implCfg.AuxChanCloser,
AuxResolver: s.implCfg.AuxContractResolver,
} }
copy(pCfg.PubKeyBytes[:], peerAddr.IdentityKey.SerializeCompressed()) copy(pCfg.PubKeyBytes[:], peerAddr.IdentityKey.SerializeCompressed())