Skip to content

Commit 716d4c0

Browse files
committed
funding: create new AuxFundingController interface
In this commit, we make a new `AuxFundingController` interface capable of processing messages off the wire. In addition, we can use it to abstract away details w.r.t how we obtain a `AuxFundingDesc` for a given channel. We'll now use this whenever we get a channel funding request, to make sure we pass along the custom state that a channel may require.
1 parent 9909c01 commit 716d4c0

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

funding/aux_funding.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package funding
2+
3+
import (
4+
"github.com/lightningnetwork/lnd/fn"
5+
"github.com/lightningnetwork/lnd/lnwallet"
6+
"github.com/lightningnetwork/lnd/protofsm"
7+
)
8+
9+
// AuxFundingController permits the implementation of the funding of custom
10+
// channels types. The controller serves as a MsgEndpoint which allows it to
11+
// intercept custom messages, or even the regular funding messages. The
12+
// controller might also pass along an aux funding desc based on an existing
13+
// pending channel ID.
14+
type AuxFundingController interface {
15+
// The controller is also a message endpoint. This'll allow it to
16+
// handle custom messages specific to the funding type.
17+
protofsm.MsgEndpoint
18+
19+
// DescPendingChanID takes a pending channel ID, that may already be
20+
// known due to prior custom channel messages, and maybe returns an aux
21+
// funding desc which can be used to modify how a channel is funded.
22+
//
23+
// TODO(roasbeef): erorr on validation if fail due to invalid root
24+
// match?
25+
DescFromPendingChanID(PendingChanID) fn.Option[lnwallet.AuxFundingDesc]
26+
}

funding/manager.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,12 @@ type Config struct {
539539
// AliasManager is an implementation of the aliasHandler interface that
540540
// abstracts away the handling of many alias functions.
541541
AliasManager aliasHandler
542+
543+
// AuxFundingController is an optional controller that can be used to
544+
// modify the way we handle certain custom chanenl types. It's also
545+
// able to automatically handle new custom protocol messages related to
546+
// the funding process.
547+
AuxFundingController fn.Option[AuxFundingController]
542548
}
543549

544550
// Manager acts as an orchestrator/bridge between the wallet's
@@ -1604,6 +1610,15 @@ func (f *Manager) fundeeProcessOpenChannel(peer lnpeer.Peer,
16041610
return
16051611
}
16061612

1613+
// At this point, if we have an AuxFundingController active, we'll
1614+
// check to see if we have any aux info that we should carry along for
1615+
// this pid.
1616+
auxFundingDesc := fn.MapOption(
1617+
func(a AuxFundingController) fn.Option[lnwallet.AuxFundingDesc] {
1618+
return a.DescFromPendingChanID(msg.PendingChannelID)
1619+
},
1620+
)(f.cfg.AuxFundingController)
1621+
16071622
req := &lnwallet.InitFundingReserveMsg{
16081623
ChainHash: &msg.ChainHash,
16091624
PendingChanID: msg.PendingChannelID,
@@ -1620,6 +1635,7 @@ func (f *Manager) fundeeProcessOpenChannel(peer lnpeer.Peer,
16201635
ZeroConf: zeroConf,
16211636
OptionScidAlias: scid,
16221637
ScidAliasFeature: scidFeatureVal,
1638+
AuxFundingDesc: fn.FlattenOption(auxFundingDesc),
16231639
}
16241640

16251641
reservation, err := f.cfg.Wallet.InitChannelReservation(req)
@@ -4594,6 +4610,15 @@ func (f *Manager) handleInitFundingMsg(msg *InitFundingMsg) {
45944610
scidFeatureVal = true
45954611
}
45964612

4613+
// At this point, if we have an AuxFundingController active, we'll
4614+
// check to see if we have any aux info that we should carry along for
4615+
// this pid.
4616+
auxFundingDesc := fn.MapOption(
4617+
func(a AuxFundingController) fn.Option[lnwallet.AuxFundingDesc] {
4618+
return a.DescFromPendingChanID(chanID)
4619+
},
4620+
)(f.cfg.AuxFundingController)
4621+
45974622
req := &lnwallet.InitFundingReserveMsg{
45984623
ChainHash: &msg.ChainHash,
45994624
PendingChanID: chanID,
@@ -4617,6 +4642,7 @@ func (f *Manager) handleInitFundingMsg(msg *InitFundingMsg) {
46174642
OptionScidAlias: scid,
46184643
ScidAliasFeature: scidFeatureVal,
46194644
Memo: msg.Memo,
4645+
AuxFundingDesc: fn.FlattenOption(auxFundingDesc),
46204646
}
46214647

46224648
reservation, err := f.cfg.Wallet.InitChannelReservation(req)

0 commit comments

Comments
 (0)