peer+server: use feature manager to generate feature vectors
This commit is contained in:
2 files changed
+37
-26
No files matched your search
@@ -35,6 +35,7 @@ import (
|
||||
"github.com/lightningnetwork/lnd/channelnotifier"
|
||||
"github.com/lightningnetwork/lnd/contractcourt"
|
||||
"github.com/lightningnetwork/lnd/discovery"
|
||||
"github.com/lightningnetwork/lnd/feature"
|
||||
"github.com/lightningnetwork/lnd/htlcswitch"
|
||||
"github.com/lightningnetwork/lnd/htlcswitch/hop"
|
||||
"github.com/lightningnetwork/lnd/input"
|
||||
@@ -232,9 +233,9 @@ type server struct {
|
||||
|
||||
readPool *pool.Read
|
||||
|
||||
// globalFeatures feature vector which affects HTLCs and thus are also
|
||||
// advertised to other nodes.
|
||||
globalFeatures *lnwire.FeatureVector
|
||||
// featureMgr dispatches feature vectors for various contexts within the
|
||||
// daemon.
|
||||
featureMgr *feature.Manager
|
||||
|
||||
// currentNodeAnn is the node announcement that has been broadcast to
|
||||
// the network upon startup, if the attributes of the node (us) has
|
||||
@@ -369,6 +370,14 @@ func newServer(listenAddrs []net.Addr, chanDB *channeldb.DB,
|
||||
readBufferPool, cfg.Workers.Read, pool.DefaultWorkerTimeout,
|
||||
)
|
||||
|
||||
featureMgr, err := feature.NewManager(feature.Config{
|
||||
NoTLVOnion: cfg.LegacyProtocol.LegacyOnion(),
|
||||
NoStaticRemoteKey: cfg.LegacyProtocol.LegacyCommitment(),
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
s := &server{
|
||||
chanDB: chanDB,
|
||||
cc: cc,
|
||||
@@ -405,10 +414,8 @@ func newServer(listenAddrs []net.Addr, chanDB *channeldb.DB,
|
||||
peerConnectedListeners: make(map[string][]chan<- lnpeer.Peer),
|
||||
peerDisconnectedListeners: make(map[string][]chan<- struct{}),
|
||||
|
||||
globalFeatures: lnwire.NewFeatureVector(
|
||||
globalFeatures, lnwire.GlobalFeatures,
|
||||
),
|
||||
quit: make(chan struct{}),
|
||||
featureMgr: featureMgr,
|
||||
quit: make(chan struct{}),
|
||||
}
|
||||
|
||||
s.witnessBeacon = &preimageBeacon{
|
||||
@@ -594,7 +601,7 @@ func newServer(listenAddrs []net.Addr, chanDB *channeldb.DB,
|
||||
LastUpdate: time.Now(),
|
||||
Addresses: selfAddrs,
|
||||
Alias: nodeAlias.String(),
|
||||
Features: s.globalFeatures,
|
||||
Features: s.featureMgr.Get(feature.SetNodeAnn),
|
||||
Color: color,
|
||||
}
|
||||
copy(selfNode.PubKeyBytes[:], privKey.PubKey().SerializeCompressed())
|
||||
@@ -2727,14 +2734,10 @@ func (s *server) peerConnected(conn net.Conn, connReq *connmgr.ConnReq,
|
||||
ChainNet: activeNetParams.Net,
|
||||
}
|
||||
|
||||
// With the brontide connection established, we'll now craft the local
|
||||
// feature vector to advertise to the remote node.
|
||||
localFeatures := lnwire.NewRawFeatureVector()
|
||||
|
||||
// We'll signal that we understand the data loss protection feature,
|
||||
// and also that we support the new gossip query features.
|
||||
localFeatures.Set(lnwire.DataLossProtectRequired)
|
||||
localFeatures.Set(lnwire.GossipQueriesOptional)
|
||||
// With the brontide connection established, we'll now craft the feature
|
||||
// vectors to advertise to the remote node.
|
||||
initFeatures := s.featureMgr.Get(feature.SetInit)
|
||||
legacyFeatures := s.featureMgr.Get(feature.SetLegacyGlobal)
|
||||
|
||||
// Now that we've established a connection, create a peer, and it to the
|
||||
// set of currently active peers. Configure the peer with the incoming
|
||||
@@ -2743,8 +2746,8 @@ func (s *server) peerConnected(conn net.Conn, connReq *connmgr.ConnReq,
|
||||
// htlcs, an extra block is added to prevent the channel from being
|
||||
// closed when the htlc is outstanding and a new block comes in.
|
||||
p, err := newPeer(
|
||||
conn, connReq, s, peerAddr, inbound, localFeatures,
|
||||
cfg.ChanEnableTimeout,
|
||||
conn, connReq, s, peerAddr, inbound, initFeatures,
|
||||
legacyFeatures, cfg.ChanEnableTimeout,
|
||||
defaultOutgoingCltvRejectDelta,
|
||||
)
|
||||
if err != nil {
|
||||
|
||||
Reference in new issue
Block a user