Skip to content

Commit ce767b0

Browse files
committed
server+tapcfg: implement AuxChannelNegotiator
1 parent cbb7f15 commit ce767b0

File tree

3 files changed

+67
-3
lines changed

3 files changed

+67
-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: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,3 +1284,57 @@ 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+
// There's no need to wait for the server to be ready, this action acts
1293+
// only within the aux chan negotiator instance.
1294+
return s.cfg.AuxChanNegotiator.GetInitFeatures(peer)
1295+
}
1296+
1297+
// ProcessInitFeatures handles received init feature TLVs from a peer. The
1298+
// implementation can store state internally to affect future channel operations
1299+
// with this peer.
1300+
func (s *Server) ProcessInitFeatures(peer route.Vertex,
1301+
features tlv.Blob) error {
1302+
1303+
// There's no need to wait for the server to be ready, this action acts
1304+
// only within the aux chan negotiator instance.
1305+
return s.cfg.AuxChanNegotiator.ProcessInitFeatures(peer, features)
1306+
}
1307+
1308+
// GetReestablishFeatures is called when sending a channel_reestablish message.
1309+
// It returns feature bits based on the specific channel identified by its
1310+
// funding outpoint and aux channel blob.
1311+
func (s *Server) GetReestablishFeatures(cid lnwire.ChannelID,
1312+
auxChanBlob tlv.Blob) (tlv.Blob, error) {
1313+
1314+
// There's no need to wait for the server to be ready, this action acts
1315+
// only within the aux chan negotiator instance.
1316+
return s.cfg.AuxChanNegotiator.GetReestablishFeatures(
1317+
cid, auxChanBlob,
1318+
)
1319+
}
1320+
1321+
// ProcessReestablishFeatures handles received channel_reestablish feature TLVs.
1322+
// This is a blocking call - the channel link will wait for this method to
1323+
// complete before continuing channel operations. The implementation can modify
1324+
// aux channel behavior based on the negotiated features.
1325+
func (s *Server) ProcessReestablishFeatures(cid lnwire.ChannelID,
1326+
features tlv.Blob, auxChanBlob tlv.Blob) error {
1327+
1328+
// There's no need to wait for the server to be ready, this action acts
1329+
// only within the aux chan negotiator instance.
1330+
return s.cfg.AuxChanNegotiator.ProcessReestablishFeatures(
1331+
cid, features, auxChanBlob,
1332+
)
1333+
}
1334+
1335+
// ProcessChannelReady handles the event of marking a channel identified by its
1336+
// channel ID as ready to use. We also provide the peer the channel was
1337+
// established with.
1338+
func (s *Server) ProcessChannelReady(cid lnwire.ChannelID, peer route.Vertex) {
1339+
s.cfg.AuxChanNegotiator.ProcessChannelReady(cid, peer)
1340+
}

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)