Skip to content

Commit d090080

Browse files
committed
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.
1 parent cb20360 commit d090080

File tree

3 files changed

+96
-1
lines changed

3 files changed

+96
-1
lines changed

config.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
"github.com/lightningnetwork/lnd/cert"
3232
"github.com/lightningnetwork/lnd/lncfg"
3333
"github.com/lightningnetwork/lnd/lnrpc"
34+
"github.com/lightningnetwork/lnd/lnwire"
3435
"github.com/lightningnetwork/lnd/signal"
3536
"github.com/mwitkow/go-conntrack/connhelpers"
3637
"golang.org/x/crypto/acme/autocert"
@@ -614,6 +615,19 @@ func loadConfigFile(preCfg *Config, interceptor signal.Interceptor) (*Config,
614615
// configuration is fully valid. This also sets up the main logger that
615616
// logs to a sub-directory in the .lnd folder.
616617
case ModeIntegrated:
618+
// For the integration of tapd with lnd, we need to allow tapd
619+
// to send custom error messages to peers through the
620+
// SendCustomMessage RPC in lnd. Since the error messages aren't
621+
// in the custom range, we explicitly need to allow them. This
622+
// isn't currently needed in remote mode, because custom
623+
// channels are only available if both lnd and tapd are running
624+
// in integrated mode. We need to set this value before we call
625+
// lnd.ValidateConfig() below, because that's what's going to
626+
// inject these values into the lnwire package.
627+
cfg.Lnd.ProtocolOptions.CustomMessage = append(
628+
cfg.Lnd.ProtocolOptions.CustomMessage, lnwire.MsgError,
629+
)
630+
617631
var err error
618632
cfg.Lnd, err = lnd.ValidateConfig(
619633
*cfg.Lnd, interceptor, fileParser, flagParser,

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ require (
2525
github.com/lightninglabs/taproot-assets v0.4.2-0.20241031160301-588e58bfae6c
2626
github.com/lightningnetwork/lnd v0.18.3-beta.rc3.0.20241025090009-615f3d633e61
2727
github.com/lightningnetwork/lnd/cert v1.2.2
28+
github.com/lightningnetwork/lnd/fn v1.2.3
2829
github.com/lightningnetwork/lnd/kvdb v1.4.10
2930
github.com/lightningnetwork/lnd/tlv v1.2.6
3031
github.com/lightningnetwork/lnd/tor v1.1.2
@@ -136,7 +137,6 @@ require (
136137
github.com/lightninglabs/neutrino/cache v1.1.2 // indirect
137138
github.com/lightningnetwork/lightning-onion v1.2.1-0.20240712235311-98bd56499dfb // indirect
138139
github.com/lightningnetwork/lnd/clock v1.1.1 // indirect
139-
github.com/lightningnetwork/lnd/fn v1.2.3 // indirect
140140
github.com/lightningnetwork/lnd/healthcheck v1.2.5 // indirect
141141
github.com/lightningnetwork/lnd/queue v1.1.1 // indirect
142142
github.com/lightningnetwork/lnd/sqldb v1.0.4 // indirect

terminal.go

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,12 @@ import (
3434
"github.com/lightninglabs/lightning-terminal/status"
3535
"github.com/lightninglabs/lightning-terminal/subservers"
3636
"github.com/lightninglabs/lndclient"
37+
taprootassets "github.com/lightninglabs/taproot-assets"
3738
"github.com/lightningnetwork/lnd"
3839
"github.com/lightningnetwork/lnd/build"
3940
"github.com/lightningnetwork/lnd/chainreg"
41+
"github.com/lightningnetwork/lnd/fn"
42+
"github.com/lightningnetwork/lnd/funding"
4043
"github.com/lightningnetwork/lnd/kvdb"
4144
"github.com/lightningnetwork/lnd/lncfg"
4245
"github.com/lightningnetwork/lnd/lnrpc"
@@ -49,10 +52,15 @@ import (
4952
"github.com/lightningnetwork/lnd/lnrpc/walletrpc"
5053
"github.com/lightningnetwork/lnd/lnrpc/watchtowerrpc"
5154
"github.com/lightningnetwork/lnd/lnrpc/wtclientrpc"
55+
"github.com/lightningnetwork/lnd/lnwallet"
5256
"github.com/lightningnetwork/lnd/lnwallet/btcwallet"
57+
"github.com/lightningnetwork/lnd/lnwallet/chancloser"
5358
"github.com/lightningnetwork/lnd/macaroons"
59+
"github.com/lightningnetwork/lnd/msgmux"
60+
"github.com/lightningnetwork/lnd/routing"
5461
"github.com/lightningnetwork/lnd/rpcperms"
5562
"github.com/lightningnetwork/lnd/signal"
63+
"github.com/lightningnetwork/lnd/sweep"
5664
grpcProxy "github.com/mwitkow/grpc-proxy/proxy"
5765
"google.golang.org/grpc"
5866
"google.golang.org/grpc/credentials"
@@ -507,13 +515,33 @@ func (g *LightningTerminal) start() error {
507515
}},
508516
}
509517

518+
var auxComponents lnd.AuxComponents
519+
switch g.cfg.TaprootAssetsMode {
520+
case ModeRemote, ModeDisable:
521+
log.Warnf("Taproot Assets daemon is either disabled " +
522+
"or running in remote mode. Taproot Asset " +
523+
"channel functionality will NOT be " +
524+
"available. To enable, set Taproot Assets " +
525+
"mode to 'integrated' in the config file.")
526+
527+
case ModeIntegrated:
528+
components, err := g.buildAuxComponents()
529+
if err != nil {
530+
return fmt.Errorf("could not build aux "+
531+
"components: %w", err)
532+
}
533+
534+
auxComponents = *components
535+
}
536+
510537
implCfg := &lnd.ImplementationCfg{
511538
GrpcRegistrar: g,
512539
RestRegistrar: g,
513540
ExternalValidator: g,
514541
DatabaseBuilder: g.defaultImplCfg.DatabaseBuilder,
515542
WalletConfigBuilder: g,
516543
ChainControlBuilder: g.defaultImplCfg.ChainControlBuilder,
544+
AuxComponents: auxComponents,
517545
}
518546

519547
g.wg.Add(1)
@@ -1293,6 +1321,59 @@ func (g *LightningTerminal) BuildWalletConfig(ctx context.Context,
12931321
)
12941322
}
12951323

1324+
// buildAuxComponent builds the auxiliary components required by lnd when
1325+
// running in integrated mode with tapd being the service that provides the
1326+
// aux component implementations.
1327+
func (g *LightningTerminal) buildAuxComponents() (*lnd.AuxComponents, error) {
1328+
errNotAvailable := fmt.Errorf("tapd is not available, both lnd and " +
1329+
"tapd must be started in integrated mode for Taproot " +
1330+
"Assets Channels to be available")
1331+
1332+
tapdWrapper, available := g.subServerMgr.GetServer(subservers.TAP)
1333+
if !available {
1334+
return nil, errNotAvailable
1335+
}
1336+
1337+
if tapdWrapper.Remote() {
1338+
return nil, errNotAvailable
1339+
}
1340+
1341+
tapdOpt := tapdWrapper.Impl()
1342+
tapdAny, err := tapdOpt.UnwrapOrErr(errors.New("tapd not available"))
1343+
if err != nil {
1344+
return nil, err
1345+
}
1346+
1347+
tapd, ok := tapdAny.(*taprootassets.Server)
1348+
if !ok {
1349+
return nil, fmt.Errorf("tapd is not of the expected type")
1350+
}
1351+
1352+
router := msgmux.NewMultiMsgRouter()
1353+
router.Start()
1354+
err = router.RegisterEndpoint(tapd)
1355+
if err != nil {
1356+
return nil, fmt.Errorf("error registering tapd endpoint: %w",
1357+
err)
1358+
}
1359+
1360+
return &lnd.AuxComponents{
1361+
AuxLeafStore: fn.Some[lnwallet.AuxLeafStore](tapd),
1362+
MsgRouter: fn.Some[msgmux.Router](router),
1363+
AuxFundingController: fn.Some[funding.AuxFundingController](
1364+
tapd,
1365+
),
1366+
AuxSigner: fn.Some[lnwallet.AuxSigner](tapd),
1367+
TrafficShaper: fn.Some[routing.TlvTrafficShaper](tapd),
1368+
AuxDataParser: fn.Some[lnd.AuxDataParser](tapd),
1369+
AuxChanCloser: fn.Some[chancloser.AuxChanCloser](tapd),
1370+
AuxSweeper: fn.Some[sweep.AuxSweeper](tapd),
1371+
AuxContractResolver: fn.Some[lnwallet.AuxContractResolver](
1372+
tapd,
1373+
),
1374+
}, nil
1375+
}
1376+
12961377
// shutdownSubServers stops all subservers that were started and attached to
12971378
// lnd.
12981379
func (g *LightningTerminal) shutdownSubServers() error {

0 commit comments

Comments
 (0)