Skip to content

Commit a027e40

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 57c40e5 commit a027e40

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"
@@ -627,6 +628,19 @@ func loadConfigFile(preCfg *Config, interceptor signal.Interceptor) (*Config,
627628
// configuration is fully valid. This also sets up the main logger that
628629
// logs to a sub-directory in the .lnd folder.
629630
case ModeIntegrated:
631+
// For the integration of tapd with lnd, we need to allow tapd
632+
// to send custom error messages to peers through the
633+
// SendCustomMessage RPC in lnd. Since the error messages aren't
634+
// in the custom range, we explicitly need to allow them. This
635+
// isn't currently needed in remote mode, because custom
636+
// channels are only available if both lnd and tapd are running
637+
// in integrated mode. We need to set this value before we call
638+
// lnd.ValidateConfig() below, because that's what's going to
639+
// inject these values into the lnwire package.
640+
cfg.Lnd.ProtocolOptions.CustomMessage = append(
641+
cfg.Lnd.ProtocolOptions.CustomMessage, lnwire.MsgError,
642+
)
643+
630644
var err error
631645
cfg.Lnd, err = lnd.ValidateConfig(
632646
*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.5.0
2626
github.com/lightningnetwork/lnd v0.18.4-beta
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,13 @@ 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"
43+
"github.com/lightningnetwork/lnd/htlcswitch"
4044
"github.com/lightningnetwork/lnd/kvdb"
4145
"github.com/lightningnetwork/lnd/lncfg"
4246
"github.com/lightningnetwork/lnd/lnrpc"
@@ -49,10 +53,14 @@ import (
4953
"github.com/lightningnetwork/lnd/lnrpc/walletrpc"
5054
"github.com/lightningnetwork/lnd/lnrpc/watchtowerrpc"
5155
"github.com/lightningnetwork/lnd/lnrpc/wtclientrpc"
56+
"github.com/lightningnetwork/lnd/lnwallet"
5257
"github.com/lightningnetwork/lnd/lnwallet/btcwallet"
58+
"github.com/lightningnetwork/lnd/lnwallet/chancloser"
5359
"github.com/lightningnetwork/lnd/macaroons"
60+
"github.com/lightningnetwork/lnd/msgmux"
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"
@@ -509,13 +517,33 @@ func (g *LightningTerminal) start() error {
509517
}},
510518
}
511519

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

521549
g.wg.Add(1)
@@ -1296,6 +1324,59 @@ func (g *LightningTerminal) BuildWalletConfig(ctx context.Context,
12961324
)
12971325
}
12981326

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

0 commit comments

Comments
 (0)