Skip to content

Commit 2dacf15

Browse files
committed
server+tapcfg: implement AuxChannelNegotiator
1 parent 7d5f6c4 commit 2dacf15

File tree

3 files changed

+101
-3
lines changed

3 files changed

+101
-3
lines changed

config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/lightninglabs/taproot-assets/rfq"
1616
"github.com/lightninglabs/taproot-assets/tapchannel"
1717
"github.com/lightninglabs/taproot-assets/tapdb"
18+
"github.com/lightninglabs/taproot-assets/tapfeatures"
1819
"github.com/lightninglabs/taproot-assets/tapfreighter"
1920
"github.com/lightninglabs/taproot-assets/tapgarden"
2021
"github.com/lightninglabs/taproot-assets/universe"
@@ -223,6 +224,8 @@ type Config struct {
223224

224225
AuxTrafficShaper *tapchannel.AuxTrafficShaper
225226

227+
AuxChanNegotiator *tapfeatures.AuxChannelNegotiator
228+
226229
AuxInvoiceManager *tapchannel.AuxInvoiceManager
227230

228231
AuxChanCloser *tapchannel.AuxChanCloser

server.go

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,3 +1284,91 @@ func (s *Server) NotifyBroadcast(req *sweep.BumpRequest,
12841284

12851285
return s.cfg.AuxSweeper.NotifyBroadcast(req, tx, fee, outpointToTxIndex)
12861286
}
1287+
1288+
// GetInitFeatures is called when sending an init message to a peer. It returns
1289+
// custom feature bits to include in the init message TLVs. The implementation
1290+
// can decide which features to advertise based on the peer's identity.
1291+
func (s *Server) GetInitFeatures(peer route.Vertex) (tlv.Blob, error) {
1292+
srvrLog.Tracef("GetInitFeatures called, peer=%s", peer)
1293+
1294+
if err := s.waitForReady(); err != nil {
1295+
return nil, err
1296+
}
1297+
1298+
// There's no need to wait for the server to be ready, this action acts
1299+
// only within the aux chan negotiator instance.
1300+
return s.cfg.AuxChanNegotiator.GetInitFeatures(peer)
1301+
}
1302+
1303+
// ProcessInitFeatures handles received init feature TLVs from a peer. The
1304+
// implementation can store state internally to affect future channel operations
1305+
// with this peer.
1306+
func (s *Server) ProcessInitFeatures(peer route.Vertex,
1307+
features tlv.Blob) error {
1308+
1309+
srvrLog.Tracef("ProcessInitFeatures called, peer=%s", peer)
1310+
1311+
if err := s.waitForReady(); err != nil {
1312+
return err
1313+
}
1314+
1315+
// There's no need to wait for the server to be ready, this action acts
1316+
// only within the aux chan negotiator instance.
1317+
return s.cfg.AuxChanNegotiator.ProcessInitFeatures(peer, features)
1318+
}
1319+
1320+
// GetReestablishFeatures is called when sending a channel_reestablish message.
1321+
// It returns feature bits based on the specific channel identified by its
1322+
// funding outpoint and aux channel blob.
1323+
func (s *Server) GetReestablishFeatures(cid lnwire.ChannelID,
1324+
auxChanBlob tlv.Blob) (tlv.Blob, error) {
1325+
1326+
srvrLog.Tracef("GetReestablishFeatures called, cid=%s", cid.String())
1327+
1328+
if err := s.waitForReady(); err != nil {
1329+
return nil, err
1330+
}
1331+
1332+
// There's no need to wait for the server to be ready, this action acts
1333+
// only within the aux chan negotiator instance.
1334+
return s.cfg.AuxChanNegotiator.GetReestablishFeatures(
1335+
cid, auxChanBlob,
1336+
)
1337+
}
1338+
1339+
// ProcessReestablishFeatures handles received channel_reestablish feature TLVs.
1340+
// This is a blocking call - the channel link will wait for this method to
1341+
// complete before continuing channel operations. The implementation can modify
1342+
// aux channel behavior based on the negotiated features.
1343+
func (s *Server) ProcessReestablishFeatures(cid lnwire.ChannelID,
1344+
features tlv.Blob, auxChanBlob tlv.Blob) error {
1345+
1346+
srvrLog.Tracef("ProcessReestablishFeatures called, cid=%s",
1347+
cid.String())
1348+
1349+
if err := s.waitForReady(); err != nil {
1350+
return err
1351+
}
1352+
1353+
// There's no need to wait for the server to be ready, this action acts
1354+
// only within the aux chan negotiator instance.
1355+
return s.cfg.AuxChanNegotiator.ProcessReestablishFeatures(
1356+
cid, features, auxChanBlob,
1357+
)
1358+
}
1359+
1360+
// ProcessChannelReady handles the event of marking a channel identified by its
1361+
// channel ID as ready to use. We also provide the peer the channel was
1362+
// established with.
1363+
func (s *Server) ProcessChannelReady(cid lnwire.ChannelID, peer route.Vertex) {
1364+
srvrLog.Tracef("ProcessChannelReady called, cid=%s, peer=%s", cid, peer)
1365+
1366+
if err := s.waitForReady(); err != nil {
1367+
srvrLog.Errorf("ProcessChannelReady got error while waiting " +
1368+
"for server ready")
1369+
1370+
return
1371+
}
1372+
1373+
s.cfg.AuxChanNegotiator.ProcessChannelReady(cid, peer)
1374+
}

tapcfg/server.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"github.com/lightninglabs/taproot-assets/tapchannel"
2121
"github.com/lightninglabs/taproot-assets/tapdb"
2222
"github.com/lightninglabs/taproot-assets/tapdb/sqlc"
23+
"github.com/lightninglabs/taproot-assets/tapfeatures"
2324
"github.com/lightninglabs/taproot-assets/tapfreighter"
2425
"github.com/lightninglabs/taproot-assets/tapgarden"
2526
"github.com/lightninglabs/taproot-assets/tapscript"
@@ -470,6 +471,9 @@ func genServerConfig(cfg *Config, cfgLogger btclog.Logger,
470471
}
471472
}
472473

474+
// Construct the AuxChannelNegotiator.
475+
auxChanNegotiator := tapfeatures.NewAuxChannelNegotiator()
476+
473477
// Construct the RFQ manager.
474478
rfqManager, err := rfq.NewManager(rfq.ManagerCfg{
475479
PeerMessenger: msgTransportClient,
@@ -478,6 +482,7 @@ func genServerConfig(cfg *Config, cfgLogger btclog.Logger,
478482
PriceOracle: priceOracle,
479483
ChannelLister: lndServices.Client,
480484
GroupLookup: tapdbAddrBook,
485+
AuxChanNegotiator: auxChanNegotiator,
481486
AliasManager: lndRouterClient,
482487
AcceptPriceDeviationPpm: rfqCfg.AcceptPriceDeviationPpm,
483488
SkipAcceptQuotePriceCheck: rfqCfg.SkipAcceptQuotePriceCheck,
@@ -588,9 +593,10 @@ func genServerConfig(cfg *Config, cfgLogger btclog.Logger,
588593
)
589594
auxTrafficShaper := tapchannel.NewAuxTrafficShaper(
590595
&tapchannel.TrafficShaperConfig{
591-
ChainParams: &tapChainParams,
592-
RfqManager: rfqManager,
593-
NoopHTLCs: cfg.Channel.NoopHTLCs,
596+
ChainParams: &tapChainParams,
597+
RfqManager: rfqManager,
598+
NoopHTLCs: cfg.Channel.NoopHTLCs,
599+
AuxChanNegotiator: auxChanNegotiator,
594600
},
595601
)
596602
auxInvoiceManager := tapchannel.NewAuxInvoiceManager(
@@ -704,6 +710,7 @@ func genServerConfig(cfg *Config, cfgLogger btclog.Logger,
704710
AuxFundingController: auxFundingController,
705711
AuxChanCloser: auxChanCloser,
706712
AuxTrafficShaper: auxTrafficShaper,
713+
AuxChanNegotiator: auxChanNegotiator,
707714
AuxInvoiceManager: auxInvoiceManager,
708715
AuxSweeper: auxSweeper,
709716
LogWriter: cfg.LogWriter,

0 commit comments

Comments
 (0)