Skip to content

Commit 00741e7

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 9d7b2c5 commit 00741e7

File tree

3 files changed

+84
-2
lines changed

3 files changed

+84
-2
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"
@@ -395,6 +396,19 @@ func loadAndValidateConfig(interceptor signal.Interceptor) (*Config, error) {
395396
cfg.Lnd.RPCMiddleware.Enable = true
396397
}
397398

399+
// For the integration of tapd with lnd, we need to allow tapd to send
400+
// custom error messages to peers through the SendCustomMessage RPC in
401+
// lnd. Since the error messages aren't in the custom range, we
402+
// explicitly need to allow them. This isn't currently needed in remote
403+
// mode, because custom channels are only available if both lnd and tapd
404+
// are running in integrated mode.
405+
if !cfg.lndRemote {
406+
cfg.Lnd.ProtocolOptions.CustomMessage = append(
407+
cfg.Lnd.ProtocolOptions.CustomMessage,
408+
lnwire.MsgError,
409+
)
410+
}
411+
398412
// Validate the lightning-terminal config options.
399413
litDir := lnd.CleanAndExpandPath(preCfg.LitDir)
400414
cfg.LetsEncryptDir = lncfg.CleanAndExpandPath(cfg.LetsEncryptDir)

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ require (
2222
github.com/lightninglabs/taproot-assets v0.3.3-0.20240609154533-2b3c60ae77a9
2323
github.com/lightningnetwork/lnd v0.18.0-beta.rc3.0.20240607141010-393d6829ca7d
2424
github.com/lightningnetwork/lnd/cert v1.2.2
25+
github.com/lightningnetwork/lnd/fn v1.0.8
2526
github.com/lightningnetwork/lnd/kvdb v1.4.8
2627
github.com/lightningnetwork/lnd/tlv v1.2.6
2728
github.com/lightningnetwork/lnd/tor v1.1.2
@@ -129,7 +130,6 @@ require (
129130
github.com/lightninglabs/neutrino/cache v1.1.2 // indirect
130131
github.com/lightningnetwork/lightning-onion v1.2.1-0.20230823005744-06182b1d7d2f // indirect
131132
github.com/lightningnetwork/lnd/clock v1.1.1 // indirect
132-
github.com/lightningnetwork/lnd/fn v1.0.8 // indirect
133133
github.com/lightningnetwork/lnd/healthcheck v1.2.4 // indirect
134134
github.com/lightningnetwork/lnd/queue v1.1.1 // indirect
135135
github.com/lightningnetwork/lnd/sqldb v1.0.2 // indirect

terminal.go

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,12 @@ import (
3333
"github.com/lightninglabs/lightning-terminal/status"
3434
"github.com/lightninglabs/lightning-terminal/subservers"
3535
"github.com/lightninglabs/lndclient"
36+
taprootassets "github.com/lightninglabs/taproot-assets"
3637
"github.com/lightningnetwork/lnd"
3738
"github.com/lightningnetwork/lnd/build"
3839
"github.com/lightningnetwork/lnd/chainreg"
40+
"github.com/lightningnetwork/lnd/fn"
41+
"github.com/lightningnetwork/lnd/funding"
3942
"github.com/lightningnetwork/lnd/kvdb"
4043
"github.com/lightningnetwork/lnd/lncfg"
4144
"github.com/lightningnetwork/lnd/lnrpc"
@@ -48,8 +51,12 @@ import (
4851
"github.com/lightningnetwork/lnd/lnrpc/walletrpc"
4952
"github.com/lightningnetwork/lnd/lnrpc/watchtowerrpc"
5053
"github.com/lightningnetwork/lnd/lnrpc/wtclientrpc"
54+
"github.com/lightningnetwork/lnd/lnwallet"
5155
"github.com/lightningnetwork/lnd/lnwallet/btcwallet"
56+
"github.com/lightningnetwork/lnd/lnwallet/chancloser"
5257
"github.com/lightningnetwork/lnd/macaroons"
58+
"github.com/lightningnetwork/lnd/protofsm"
59+
"github.com/lightningnetwork/lnd/routing"
5360
"github.com/lightningnetwork/lnd/rpcperms"
5461
"github.com/lightningnetwork/lnd/signal"
5562
grpcProxy "github.com/mwitkow/grpc-proxy/proxy"
@@ -234,7 +241,8 @@ func (g *LightningTerminal) Run() error {
234241
// Construct a new Manager.
235242
g.permsMgr, err = perms.NewManager(false)
236243
if err != nil {
237-
return fmt.Errorf("could not create permissions manager")
244+
return fmt.Errorf("could not create permissions manager: %w",
245+
err)
238246
}
239247

240248
// The litcli status command will call the "/lnrpc.State/GetState" RPC.
@@ -466,13 +474,33 @@ func (g *LightningTerminal) start() error {
466474
}},
467475
}
468476

477+
var auxComponents lnd.AuxComponents
478+
switch g.cfg.TaprootAssetsMode {
479+
case ModeRemote, ModeDisable:
480+
log.Warnf("Taproot Assets daemon is either disabled " +
481+
"or running in remote mode. Taproot Asset " +
482+
"channel functionality will NOT be " +
483+
"available. To enable, set Taproot Assets " +
484+
"mode to 'integrated' in the config file.")
485+
486+
case ModeIntegrated:
487+
components, err := g.buildAuxComponents()
488+
if err != nil {
489+
return fmt.Errorf("could not build aux "+
490+
"components: %w", err)
491+
}
492+
493+
auxComponents = *components
494+
}
495+
469496
implCfg := &lnd.ImplementationCfg{
470497
GrpcRegistrar: g,
471498
RestRegistrar: g,
472499
ExternalValidator: g,
473500
DatabaseBuilder: g.defaultImplCfg.DatabaseBuilder,
474501
WalletConfigBuilder: g,
475502
ChainControlBuilder: g.defaultImplCfg.ChainControlBuilder,
503+
AuxComponents: auxComponents,
476504
}
477505

478506
g.wg.Add(1)
@@ -1233,6 +1261,46 @@ func (g *LightningTerminal) BuildWalletConfig(ctx context.Context,
12331261
)
12341262
}
12351263

1264+
// buildAuxComponent builds the auxiliary components required by lnd when
1265+
// running in integrated mode with tapd being the service that provides the
1266+
// aux component implementations.
1267+
func (g *LightningTerminal) buildAuxComponents() (*lnd.AuxComponents, error) {
1268+
errNotAvailable := fmt.Errorf("tapd is not available, both lnd and " +
1269+
"tapd must be started in integrated mode for Taproot " +
1270+
"Assets Channels to be available")
1271+
1272+
tapdWrapper, available := g.subServerMgr.GetServer(subservers.TAP)
1273+
if !available {
1274+
return nil, errNotAvailable
1275+
}
1276+
1277+
if tapdWrapper.Remote() {
1278+
return nil, errNotAvailable
1279+
}
1280+
1281+
tapd := tapdWrapper.Impl().(*taprootassets.Server)
1282+
1283+
router := protofsm.NewMultiMsgRouter()
1284+
router.Start()
1285+
err := router.RegisterEndpoint(tapd)
1286+
if err != nil {
1287+
return nil, fmt.Errorf("error registering tapd endpoint: %w",
1288+
err)
1289+
}
1290+
1291+
return &lnd.AuxComponents{
1292+
AuxLeafStore: fn.Some[lnwallet.AuxLeafStore](tapd),
1293+
MsgRouter: fn.Some[protofsm.MsgRouter](router),
1294+
AuxFundingController: fn.Some[funding.AuxFundingController](
1295+
tapd,
1296+
),
1297+
AuxSigner: fn.Some[lnwallet.AuxSigner](tapd),
1298+
TrafficShaper: fn.Some[routing.TlvTrafficShaper](tapd),
1299+
AuxDataParser: fn.Some[lnd.AuxDataParser](tapd),
1300+
AuxChanCloser: fn.Some[chancloser.AuxChanCloser](tapd),
1301+
}, nil
1302+
}
1303+
12361304
// shutdownSubServers stops all subservers that were started and attached to
12371305
// lnd.
12381306
func (g *LightningTerminal) shutdownSubServers() error {

0 commit comments

Comments
 (0)