Skip to content

Commit 74d98bf

Browse files
committed
server+tapcfg: implement AuxChannelNegotiator
1 parent 5911187 commit 74d98bf

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"
@@ -221,6 +222,8 @@ type Config struct {
221222

222223
AuxTrafficShaper *tapchannel.AuxTrafficShaper
223224

225+
AuxChanNegotiator *tapfeatures.AuxChannelNegotiator
226+
224227
AuxInvoiceManager *tapchannel.AuxInvoiceManager
225228

226229
AuxChanCloser *tapchannel.AuxChanCloser

server.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,3 +1279,57 @@ func (s *Server) NotifyBroadcast(req *sweep.BumpRequest,
12791279

12801280
return s.cfg.AuxSweeper.NotifyBroadcast(req, tx, fee, outpointToTxIndex)
12811281
}
1282+
1283+
// GetInitFeatures is called when sending an init message to a peer. It returns
1284+
// custom feature bits to include in the init message TLVs. The implementation
1285+
// can decide which features to advertise based on the peer's identity.
1286+
func (s *Server) GetInitFeatures(peer route.Vertex) (tlv.Blob, error) {
1287+
// There's no need to wait for the server to be ready, this action acts
1288+
// only within the aux chan negotiator instance.
1289+
return s.cfg.AuxChanNegotiator.GetInitFeatures(peer)
1290+
}
1291+
1292+
// ProcessInitFeatures handles received init feature TLVs from a peer. The
1293+
// implementation can store state internally to affect future channel operations
1294+
// with this peer.
1295+
func (s *Server) ProcessInitFeatures(peer route.Vertex,
1296+
features tlv.Blob) error {
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.ProcessInitFeatures(peer, features)
1301+
}
1302+
1303+
// GetReestablishFeatures is called when sending a channel_reestablish message.
1304+
// It returns feature bits based on the specific channel identified by its
1305+
// funding outpoint and aux channel blob.
1306+
func (s *Server) GetReestablishFeatures(cid lnwire.ChannelID,
1307+
auxChanBlob tlv.Blob) (tlv.Blob, error) {
1308+
1309+
// There's no need to wait for the server to be ready, this action acts
1310+
// only within the aux chan negotiator instance.
1311+
return s.cfg.AuxChanNegotiator.GetReestablishFeatures(
1312+
cid, auxChanBlob,
1313+
)
1314+
}
1315+
1316+
// ProcessReestablishFeatures handles received channel_reestablish feature TLVs.
1317+
// This is a blocking call - the channel link will wait for this method to
1318+
// complete before continuing channel operations. The implementation can modify
1319+
// aux channel behavior based on the negotiated features.
1320+
func (s *Server) ProcessReestablishFeatures(cid lnwire.ChannelID,
1321+
features tlv.Blob, auxChanBlob tlv.Blob) error {
1322+
1323+
// There's no need to wait for the server to be ready, this action acts
1324+
// only within the aux chan negotiator instance.
1325+
return s.cfg.AuxChanNegotiator.ProcessReestablishFeatures(
1326+
cid, features, auxChanBlob,
1327+
)
1328+
}
1329+
1330+
// ProcessChannelReady handles the event of marking a channel identified by its
1331+
// channel ID as ready to use. We also provide the peer the channel was
1332+
// established with.
1333+
func (s *Server) ProcessChannelReady(cid lnwire.ChannelID, peer route.Vertex) {
1334+
s.cfg.AuxChanNegotiator.ProcessChannelReady(cid, peer)
1335+
}

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"
@@ -455,6 +456,9 @@ func genServerConfig(cfg *Config, cfgLogger btclog.Logger,
455456
}
456457
}
457458

459+
// Construct the AuxChannelNegotiator.
460+
auxChanNegotiator := tapfeatures.NewAuxChannelNegotiator()
461+
458462
// Construct the RFQ manager.
459463
rfqManager, err := rfq.NewManager(rfq.ManagerCfg{
460464
PeerMessenger: msgTransportClient,
@@ -463,6 +467,7 @@ func genServerConfig(cfg *Config, cfgLogger btclog.Logger,
463467
PriceOracle: priceOracle,
464468
ChannelLister: lndServices.Client,
465469
GroupLookup: tapdbAddrBook,
470+
AuxChanNegotiator: auxChanNegotiator,
466471
AliasManager: lndRouterClient,
467472
AcceptPriceDeviationPpm: rfqCfg.AcceptPriceDeviationPpm,
468473
SkipAcceptQuotePriceCheck: rfqCfg.SkipAcceptQuotePriceCheck,
@@ -536,9 +541,10 @@ func genServerConfig(cfg *Config, cfgLogger btclog.Logger,
536541
)
537542
auxTrafficShaper := tapchannel.NewAuxTrafficShaper(
538543
&tapchannel.TrafficShaperConfig{
539-
ChainParams: &tapChainParams,
540-
RfqManager: rfqManager,
541-
NoopHTLCs: cfg.Channel.NoopHTLCs,
544+
ChainParams: &tapChainParams,
545+
RfqManager: rfqManager,
546+
NoopHTLCs: cfg.Channel.NoopHTLCs,
547+
AuxChanNegotiator: auxChanNegotiator,
542548
},
543549
)
544550
auxInvoiceManager := tapchannel.NewAuxInvoiceManager(
@@ -693,6 +699,7 @@ func genServerConfig(cfg *Config, cfgLogger btclog.Logger,
693699
AuxFundingController: auxFundingController,
694700
AuxChanCloser: auxChanCloser,
695701
AuxTrafficShaper: auxTrafficShaper,
702+
AuxChanNegotiator: auxChanNegotiator,
696703
AuxInvoiceManager: auxInvoiceManager,
697704
AuxSweeper: auxSweeper,
698705
LogWriter: cfg.LogWriter,

0 commit comments

Comments
 (0)