litd: register tapd as aux component of lnd

This commit represents the main integration between lnd running in
integrated mode and tapd providing auxiliary components for custom
channels.
This commit is contained in:
Oliver Gugger 2024-05-23 13:54:35 +02:00
parent 57c40e5ad8
commit a027e4051d
No known key found for this signature in database
GPG key ID: 8E4256593F177720
3 changed files with 96 additions and 1 deletions

View file

@ -31,6 +31,7 @@ import (
"github.com/lightningnetwork/lnd/cert"
"github.com/lightningnetwork/lnd/lncfg"
"github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/signal"
"github.com/mwitkow/go-conntrack/connhelpers"
"golang.org/x/crypto/acme/autocert"
@ -627,6 +628,19 @@ func loadConfigFile(preCfg *Config, interceptor signal.Interceptor) (*Config,
// configuration is fully valid. This also sets up the main logger that
// logs to a sub-directory in the .lnd folder.
case ModeIntegrated:
// For the integration of tapd with lnd, we need to allow tapd
// to send custom error messages to peers through the
// SendCustomMessage RPC in lnd. Since the error messages aren't
// in the custom range, we explicitly need to allow them. This
// isn't currently needed in remote mode, because custom
// channels are only available if both lnd and tapd are running
// in integrated mode. We need to set this value before we call
// lnd.ValidateConfig() below, because that's what's going to
// inject these values into the lnwire package.
cfg.Lnd.ProtocolOptions.CustomMessage = append(
cfg.Lnd.ProtocolOptions.CustomMessage, lnwire.MsgError,
)
var err error
cfg.Lnd, err = lnd.ValidateConfig(
*cfg.Lnd, interceptor, fileParser, flagParser,

2
go.mod
View file

@ -25,6 +25,7 @@ require (
github.com/lightninglabs/taproot-assets v0.5.0
github.com/lightningnetwork/lnd v0.18.4-beta
github.com/lightningnetwork/lnd/cert v1.2.2
github.com/lightningnetwork/lnd/fn v1.2.3
github.com/lightningnetwork/lnd/kvdb v1.4.10
github.com/lightningnetwork/lnd/tlv v1.2.6
github.com/lightningnetwork/lnd/tor v1.1.2
@ -136,7 +137,6 @@ require (
github.com/lightninglabs/neutrino/cache v1.1.2 // indirect
github.com/lightningnetwork/lightning-onion v1.2.1-0.20240712235311-98bd56499dfb // indirect
github.com/lightningnetwork/lnd/clock v1.1.1 // indirect
github.com/lightningnetwork/lnd/fn v1.2.3 // indirect
github.com/lightningnetwork/lnd/healthcheck v1.2.5 // indirect
github.com/lightningnetwork/lnd/queue v1.1.1 // indirect
github.com/lightningnetwork/lnd/sqldb v1.0.4 // indirect

View file

@ -34,9 +34,13 @@ import (
"github.com/lightninglabs/lightning-terminal/status"
"github.com/lightninglabs/lightning-terminal/subservers"
"github.com/lightninglabs/lndclient"
taprootassets "github.com/lightninglabs/taproot-assets"
"github.com/lightningnetwork/lnd"
"github.com/lightningnetwork/lnd/build"
"github.com/lightningnetwork/lnd/chainreg"
"github.com/lightningnetwork/lnd/fn"
"github.com/lightningnetwork/lnd/funding"
"github.com/lightningnetwork/lnd/htlcswitch"
"github.com/lightningnetwork/lnd/kvdb"
"github.com/lightningnetwork/lnd/lncfg"
"github.com/lightningnetwork/lnd/lnrpc"
@ -49,10 +53,14 @@ import (
"github.com/lightningnetwork/lnd/lnrpc/walletrpc"
"github.com/lightningnetwork/lnd/lnrpc/watchtowerrpc"
"github.com/lightningnetwork/lnd/lnrpc/wtclientrpc"
"github.com/lightningnetwork/lnd/lnwallet"
"github.com/lightningnetwork/lnd/lnwallet/btcwallet"
"github.com/lightningnetwork/lnd/lnwallet/chancloser"
"github.com/lightningnetwork/lnd/macaroons"
"github.com/lightningnetwork/lnd/msgmux"
"github.com/lightningnetwork/lnd/rpcperms"
"github.com/lightningnetwork/lnd/signal"
"github.com/lightningnetwork/lnd/sweep"
grpcProxy "github.com/mwitkow/grpc-proxy/proxy"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
@ -509,6 +517,25 @@ func (g *LightningTerminal) start() error {
}},
}
var auxComponents lnd.AuxComponents
switch g.cfg.TaprootAssetsMode {
case ModeRemote, ModeDisable:
log.Warnf("Taproot Assets daemon is either disabled " +
"or running in remote mode. Taproot Asset " +
"channel functionality will NOT be " +
"available. To enable, set Taproot Assets " +
"mode to 'integrated' in the config file.")
case ModeIntegrated:
components, err := g.buildAuxComponents()
if err != nil {
return fmt.Errorf("could not build aux "+
"components: %w", err)
}
auxComponents = *components
}
implCfg := &lnd.ImplementationCfg{
GrpcRegistrar: g,
RestRegistrar: g,
@ -516,6 +543,7 @@ func (g *LightningTerminal) start() error {
DatabaseBuilder: g.defaultImplCfg.DatabaseBuilder,
WalletConfigBuilder: g,
ChainControlBuilder: g.defaultImplCfg.ChainControlBuilder,
AuxComponents: auxComponents,
}
g.wg.Add(1)
@ -1296,6 +1324,59 @@ func (g *LightningTerminal) BuildWalletConfig(ctx context.Context,
)
}
// buildAuxComponent builds the auxiliary components required by lnd when
// running in integrated mode with tapd being the service that provides the
// aux component implementations.
func (g *LightningTerminal) buildAuxComponents() (*lnd.AuxComponents, error) {
errNotAvailable := fmt.Errorf("tapd is not available, both lnd and " +
"tapd must be started in integrated mode for Taproot " +
"Assets Channels to be available")
tapdWrapper, available := g.subServerMgr.GetServer(subservers.TAP)
if !available {
return nil, errNotAvailable
}
if tapdWrapper.Remote() {
return nil, errNotAvailable
}
tapdOpt := tapdWrapper.Impl()
tapdAny, err := tapdOpt.UnwrapOrErr(errors.New("tapd not available"))
if err != nil {
return nil, err
}
tapd, ok := tapdAny.(*taprootassets.Server)
if !ok {
return nil, fmt.Errorf("tapd is not of the expected type")
}
router := msgmux.NewMultiMsgRouter()
router.Start()
err = router.RegisterEndpoint(tapd)
if err != nil {
return nil, fmt.Errorf("error registering tapd endpoint: %w",
err)
}
return &lnd.AuxComponents{
AuxLeafStore: fn.Some[lnwallet.AuxLeafStore](tapd),
MsgRouter: fn.Some[msgmux.Router](router),
AuxFundingController: fn.Some[funding.AuxFundingController](
tapd,
),
AuxSigner: fn.Some[lnwallet.AuxSigner](tapd),
TrafficShaper: fn.Some[htlcswitch.AuxTrafficShaper](tapd),
AuxDataParser: fn.Some[lnd.AuxDataParser](tapd),
AuxChanCloser: fn.Some[chancloser.AuxChanCloser](tapd),
AuxSweeper: fn.Some[sweep.AuxSweeper](tapd),
AuxContractResolver: fn.Some[lnwallet.AuxContractResolver](
tapd,
),
}, nil
}
// shutdownSubServers stops all subservers that were started and attached to
// lnd.
func (g *LightningTerminal) shutdownSubServers() error {