Skip to content

Commit b6638fb

Browse files
committed
server+tapcfg: implement AuxChannelNegotiator
1 parent 999b88a commit b6638fb

File tree

3 files changed

+77
-3
lines changed

3 files changed

+77
-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"
@@ -229,6 +230,8 @@ type Config struct {
229230

230231
AuxTrafficShaper *tapchannel.AuxTrafficShaper
231232

233+
AuxChanNegotiator *tapfeatures.AuxChannelNegotiator
234+
232235
AuxInvoiceManager *tapchannel.AuxInvoiceManager
233236

234237
AuxChanCloser *tapchannel.AuxChanCloser

server.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,3 +1319,67 @@ func (s *Server) NotifyBroadcast(req *sweep.BumpRequest,
13191319

13201320
return s.cfg.AuxSweeper.NotifyBroadcast(req, tx, fee, outpointToTxIndex)
13211321
}
1322+
1323+
// GetInitRecords is called when sending an init message to a peer. It returns
1324+
// custom records to include in the init message TLVs. The implementation can
1325+
// decide which records to include based on the peer identity.
1326+
func (s *Server) GetInitRecords(
1327+
peer route.Vertex) (lnwire.CustomRecords, error) {
1328+
1329+
srvrLog.Tracef("GetInitRecords called, peer=%s", peer)
1330+
1331+
if err := s.waitForReady(); err != nil {
1332+
return nil, err
1333+
}
1334+
1335+
return s.cfg.AuxChanNegotiator.GetInitRecords(peer)
1336+
}
1337+
1338+
// ProcessInitRecords handles received init records from a peer. The
1339+
// implementation can store state internally to affect future channel operations
1340+
// with this peer.
1341+
func (s *Server) ProcessInitRecords(peer route.Vertex,
1342+
customRecords lnwire.CustomRecords) error {
1343+
1344+
srvrLog.Tracef("ProcessInitRecords called, peer=%s", peer)
1345+
1346+
if err := s.waitForReady(); err != nil {
1347+
return err
1348+
}
1349+
1350+
return s.cfg.AuxChanNegotiator.ProcessInitRecords(peer, customRecords)
1351+
}
1352+
1353+
// ProcessReestablishFeatures handles received channel_reestablish feature TLVs.
1354+
// This is a blocking call - the channel link will wait for this method to
1355+
// complete before continuing channel operations. The implementation can modify
1356+
// aux channel behavior based on the negotiated features.
1357+
func (s *Server) ProcessReestablish(cid lnwire.ChannelID, peer route.Vertex) {
1358+
srvrLog.Tracef("ProcessReestablishFeatures called, cid=%s",
1359+
cid.String())
1360+
1361+
if err := s.waitForReady(); err != nil {
1362+
srvrLog.Errorf("Failed to handle ProcessReestablish, server " +
1363+
"not ready")
1364+
}
1365+
1366+
s.cfg.AuxChanNegotiator.ProcessReestablish(
1367+
cid, peer,
1368+
)
1369+
}
1370+
1371+
// ProcessChannelReady handles the event of marking a channel identified by its
1372+
// channel ID as ready to use. We also provide the peer the channel was
1373+
// established with.
1374+
func (s *Server) ProcessChannelReady(cid lnwire.ChannelID, peer route.Vertex) {
1375+
srvrLog.Tracef("ProcessChannelReady called, cid=%s, peer=%s", cid, peer)
1376+
1377+
if err := s.waitForReady(); err != nil {
1378+
srvrLog.Errorf("ProcessChannelReady got error while waiting " +
1379+
"for server ready")
1380+
1381+
return
1382+
}
1383+
1384+
s.cfg.AuxChanNegotiator.ProcessChannelReady(cid, peer)
1385+
}

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"
@@ -474,6 +475,9 @@ func genServerConfig(cfg *Config, cfgLogger btclog.Logger,
474475
}
475476
}
476477

478+
// Construct the AuxChannelNegotiator.
479+
auxChanNegotiator := tapfeatures.NewAuxChannelNegotiator()
480+
477481
// Construct the RFQ manager.
478482
rfqManager, err := rfq.NewManager(rfq.ManagerCfg{
479483
PeerMessenger: msgTransportClient,
@@ -482,6 +486,7 @@ func genServerConfig(cfg *Config, cfgLogger btclog.Logger,
482486
PriceOracle: priceOracle,
483487
ChannelLister: lndServices.Client,
484488
GroupLookup: tapdbAddrBook,
489+
AuxChanNegotiator: auxChanNegotiator,
485490
AliasManager: lndRouterClient,
486491
AcceptPriceDeviationPpm: rfqCfg.AcceptPriceDeviationPpm,
487492
SkipAcceptQuotePriceCheck: rfqCfg.SkipAcceptQuotePriceCheck,
@@ -628,9 +633,10 @@ func genServerConfig(cfg *Config, cfgLogger btclog.Logger,
628633
)
629634
auxTrafficShaper := tapchannel.NewAuxTrafficShaper(
630635
&tapchannel.TrafficShaperConfig{
631-
ChainParams: &tapChainParams,
632-
RfqManager: rfqManager,
633-
NoopHTLCs: cfg.Channel.NoopHTLCs,
636+
ChainParams: &tapChainParams,
637+
RfqManager: rfqManager,
638+
NoopHTLCs: cfg.Channel.NoopHTLCs,
639+
AuxChanNegotiator: auxChanNegotiator,
634640
},
635641
)
636642
auxInvoiceManager := tapchannel.NewAuxInvoiceManager(
@@ -745,6 +751,7 @@ func genServerConfig(cfg *Config, cfgLogger btclog.Logger,
745751
AuxFundingController: auxFundingController,
746752
AuxChanCloser: auxChanCloser,
747753
AuxTrafficShaper: auxTrafficShaper,
754+
AuxChanNegotiator: auxChanNegotiator,
748755
AuxInvoiceManager: auxInvoiceManager,
749756
AuxSweeper: auxSweeper,
750757
LogWriter: cfg.LogWriter,

0 commit comments

Comments
 (0)