Skip to content

Commit eb267a6

Browse files
committed
server+tapcfg: implement AuxChannelNegotiator
1 parent 6dde6c2 commit eb267a6

File tree

3 files changed

+67
-10
lines changed

3 files changed

+67
-10
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"
@@ -219,6 +220,8 @@ type Config struct {
219220

220221
AuxTrafficShaper *tapchannel.AuxTrafficShaper
221222

223+
AuxChanNegotiator *tapfeatures.AuxChannelNegotiator
224+
222225
AuxInvoiceManager *tapchannel.AuxInvoiceManager
223226

224227
AuxChanCloser *tapchannel.AuxChanCloser

server.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,3 +1279,50 @@ 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(fundingPoint wire.OutPoint,
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+
fundingPoint, 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(fundingPoint wire.OutPoint,
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+
fundingPoint, features, auxChanBlob,
1327+
)
1328+
}

tapcfg/server.go

Lines changed: 17 additions & 10 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,16 +456,20 @@ 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(
460464
rfq.ManagerCfg{
461-
PeerMessenger: msgTransportClient,
462-
HtlcInterceptor: lndRouterClient,
463-
HtlcSubscriber: lndRouterClient,
464-
PriceOracle: priceOracle,
465-
ChannelLister: lndServices.Client,
466-
GroupLookup: tapdbAddrBook,
467-
AliasManager: lndRouterClient,
465+
PeerMessenger: msgTransportClient,
466+
HtlcInterceptor: lndRouterClient,
467+
HtlcSubscriber: lndRouterClient,
468+
PriceOracle: priceOracle,
469+
ChannelLister: lndServices.Client,
470+
GroupLookup: tapdbAddrBook,
471+
AliasManager: lndRouterClient,
472+
AuxChanNegotiator: auxChanNegotiator,
468473
// nolint: lll
469474
AcceptPriceDeviationPpm: rfqCfg.AcceptPriceDeviationPpm,
470475
// nolint: lll
@@ -538,9 +543,10 @@ func genServerConfig(cfg *Config, cfgLogger btclog.Logger,
538543
)
539544
auxTrafficShaper := tapchannel.NewAuxTrafficShaper(
540545
&tapchannel.TrafficShaperConfig{
541-
ChainParams: &tapChainParams,
542-
RfqManager: rfqManager,
543-
NoopHTLCs: cfg.Channel.NoopHTLCs,
546+
ChainParams: &tapChainParams,
547+
RfqManager: rfqManager,
548+
NoopHTLCs: cfg.Channel.NoopHTLCs,
549+
AuxChanNegotiator: auxChanNegotiator,
544550
},
545551
)
546552
auxInvoiceManager := tapchannel.NewAuxInvoiceManager(
@@ -694,6 +700,7 @@ func genServerConfig(cfg *Config, cfgLogger btclog.Logger,
694700
AuxFundingController: auxFundingController,
695701
AuxChanCloser: auxChanCloser,
696702
AuxTrafficShaper: auxTrafficShaper,
703+
AuxChanNegotiator: auxChanNegotiator,
697704
AuxInvoiceManager: auxInvoiceManager,
698705
AuxSweeper: auxSweeper,
699706
LogWriter: cfg.LogWriter,

0 commit comments

Comments
 (0)