peer+server: use feature manager to generate feature vectors
This commit is contained in:
parent
fe566e1755
commit
6c86075354
24
peer.go
24
peer.go
@ -190,9 +190,16 @@ type peer struct {
|
|||||||
|
|
||||||
server *server
|
server *server
|
||||||
|
|
||||||
// localFeatures is the set of local features that we advertised to the
|
// features is the set of features that we advertised to the remote
|
||||||
// remote node.
|
// node.
|
||||||
localFeatures *lnwire.RawFeatureVector
|
features *lnwire.FeatureVector
|
||||||
|
|
||||||
|
// legacyFeatures is the set of features that we advertised to the remote
|
||||||
|
// node for backwards compatibility. Nodes that have not implemented
|
||||||
|
// flat featurs will still be able to read our feature bits from the
|
||||||
|
// legacy global field, but we will also advertise everything in the
|
||||||
|
// default features field.
|
||||||
|
legacyFeatures *lnwire.FeatureVector
|
||||||
|
|
||||||
// outgoingCltvRejectDelta defines the number of blocks before expiry of
|
// outgoingCltvRejectDelta defines the number of blocks before expiry of
|
||||||
// an htlc where we don't offer an htlc anymore.
|
// an htlc where we don't offer an htlc anymore.
|
||||||
@ -234,7 +241,7 @@ var _ lnpeer.Peer = (*peer)(nil)
|
|||||||
// pointer to the main server.
|
// pointer to the main server.
|
||||||
func newPeer(conn net.Conn, connReq *connmgr.ConnReq, server *server,
|
func newPeer(conn net.Conn, connReq *connmgr.ConnReq, server *server,
|
||||||
addr *lnwire.NetAddress, inbound bool,
|
addr *lnwire.NetAddress, inbound bool,
|
||||||
localFeatures *lnwire.RawFeatureVector,
|
features, legacyFeatures *lnwire.FeatureVector,
|
||||||
chanActiveTimeout time.Duration,
|
chanActiveTimeout time.Duration,
|
||||||
outgoingCltvRejectDelta uint32) (
|
outgoingCltvRejectDelta uint32) (
|
||||||
*peer, error) {
|
*peer, error) {
|
||||||
@ -252,7 +259,8 @@ func newPeer(conn net.Conn, connReq *connmgr.ConnReq, server *server,
|
|||||||
|
|
||||||
server: server,
|
server: server,
|
||||||
|
|
||||||
localFeatures: localFeatures,
|
features: features,
|
||||||
|
legacyFeatures: legacyFeatures,
|
||||||
|
|
||||||
outgoingCltvRejectDelta: outgoingCltvRejectDelta,
|
outgoingCltvRejectDelta: outgoingCltvRejectDelta,
|
||||||
|
|
||||||
@ -2425,7 +2433,7 @@ func (p *peer) handleInitMsg(msg *lnwire.Init) error {
|
|||||||
//
|
//
|
||||||
// NOTE: Part of the lnpeer.Peer interface.
|
// NOTE: Part of the lnpeer.Peer interface.
|
||||||
func (p *peer) LocalGlobalFeatures() *lnwire.FeatureVector {
|
func (p *peer) LocalGlobalFeatures() *lnwire.FeatureVector {
|
||||||
return p.server.globalFeatures
|
return p.features
|
||||||
}
|
}
|
||||||
|
|
||||||
// RemoteGlobalFeatures returns the set of global features that has been
|
// RemoteGlobalFeatures returns the set of global features that has been
|
||||||
@ -2441,8 +2449,8 @@ func (p *peer) RemoteGlobalFeatures() *lnwire.FeatureVector {
|
|||||||
// supported local and global features.
|
// supported local and global features.
|
||||||
func (p *peer) sendInitMsg() error {
|
func (p *peer) sendInitMsg() error {
|
||||||
msg := lnwire.NewInitMessage(
|
msg := lnwire.NewInitMessage(
|
||||||
p.server.globalFeatures.RawFeatureVector,
|
p.legacyFeatures.RawFeatureVector,
|
||||||
p.localFeatures,
|
p.features.RawFeatureVector,
|
||||||
)
|
)
|
||||||
|
|
||||||
return p.writeMessage(msg)
|
return p.writeMessage(msg)
|
||||||
|
39
server.go
39
server.go
@ -35,6 +35,7 @@ import (
|
|||||||
"github.com/lightningnetwork/lnd/channelnotifier"
|
"github.com/lightningnetwork/lnd/channelnotifier"
|
||||||
"github.com/lightningnetwork/lnd/contractcourt"
|
"github.com/lightningnetwork/lnd/contractcourt"
|
||||||
"github.com/lightningnetwork/lnd/discovery"
|
"github.com/lightningnetwork/lnd/discovery"
|
||||||
|
"github.com/lightningnetwork/lnd/feature"
|
||||||
"github.com/lightningnetwork/lnd/htlcswitch"
|
"github.com/lightningnetwork/lnd/htlcswitch"
|
||||||
"github.com/lightningnetwork/lnd/htlcswitch/hop"
|
"github.com/lightningnetwork/lnd/htlcswitch/hop"
|
||||||
"github.com/lightningnetwork/lnd/input"
|
"github.com/lightningnetwork/lnd/input"
|
||||||
@ -232,9 +233,9 @@ type server struct {
|
|||||||
|
|
||||||
readPool *pool.Read
|
readPool *pool.Read
|
||||||
|
|
||||||
// globalFeatures feature vector which affects HTLCs and thus are also
|
// featureMgr dispatches feature vectors for various contexts within the
|
||||||
// advertised to other nodes.
|
// daemon.
|
||||||
globalFeatures *lnwire.FeatureVector
|
featureMgr *feature.Manager
|
||||||
|
|
||||||
// currentNodeAnn is the node announcement that has been broadcast to
|
// currentNodeAnn is the node announcement that has been broadcast to
|
||||||
// the network upon startup, if the attributes of the node (us) has
|
// 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,
|
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{
|
s := &server{
|
||||||
chanDB: chanDB,
|
chanDB: chanDB,
|
||||||
cc: cc,
|
cc: cc,
|
||||||
@ -405,10 +414,8 @@ func newServer(listenAddrs []net.Addr, chanDB *channeldb.DB,
|
|||||||
peerConnectedListeners: make(map[string][]chan<- lnpeer.Peer),
|
peerConnectedListeners: make(map[string][]chan<- lnpeer.Peer),
|
||||||
peerDisconnectedListeners: make(map[string][]chan<- struct{}),
|
peerDisconnectedListeners: make(map[string][]chan<- struct{}),
|
||||||
|
|
||||||
globalFeatures: lnwire.NewFeatureVector(
|
featureMgr: featureMgr,
|
||||||
globalFeatures, lnwire.GlobalFeatures,
|
quit: make(chan struct{}),
|
||||||
),
|
|
||||||
quit: make(chan struct{}),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
s.witnessBeacon = &preimageBeacon{
|
s.witnessBeacon = &preimageBeacon{
|
||||||
@ -594,7 +601,7 @@ func newServer(listenAddrs []net.Addr, chanDB *channeldb.DB,
|
|||||||
LastUpdate: time.Now(),
|
LastUpdate: time.Now(),
|
||||||
Addresses: selfAddrs,
|
Addresses: selfAddrs,
|
||||||
Alias: nodeAlias.String(),
|
Alias: nodeAlias.String(),
|
||||||
Features: s.globalFeatures,
|
Features: s.featureMgr.Get(feature.SetNodeAnn),
|
||||||
Color: color,
|
Color: color,
|
||||||
}
|
}
|
||||||
copy(selfNode.PubKeyBytes[:], privKey.PubKey().SerializeCompressed())
|
copy(selfNode.PubKeyBytes[:], privKey.PubKey().SerializeCompressed())
|
||||||
@ -2727,14 +2734,10 @@ func (s *server) peerConnected(conn net.Conn, connReq *connmgr.ConnReq,
|
|||||||
ChainNet: activeNetParams.Net,
|
ChainNet: activeNetParams.Net,
|
||||||
}
|
}
|
||||||
|
|
||||||
// With the brontide connection established, we'll now craft the local
|
// With the brontide connection established, we'll now craft the feature
|
||||||
// feature vector to advertise to the remote node.
|
// vectors to advertise to the remote node.
|
||||||
localFeatures := lnwire.NewRawFeatureVector()
|
initFeatures := s.featureMgr.Get(feature.SetInit)
|
||||||
|
legacyFeatures := s.featureMgr.Get(feature.SetLegacyGlobal)
|
||||||
// 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)
|
|
||||||
|
|
||||||
// Now that we've established a connection, create a peer, and it to the
|
// 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
|
// 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
|
// htlcs, an extra block is added to prevent the channel from being
|
||||||
// closed when the htlc is outstanding and a new block comes in.
|
// closed when the htlc is outstanding and a new block comes in.
|
||||||
p, err := newPeer(
|
p, err := newPeer(
|
||||||
conn, connReq, s, peerAddr, inbound, localFeatures,
|
conn, connReq, s, peerAddr, inbound, initFeatures,
|
||||||
cfg.ChanEnableTimeout,
|
legacyFeatures, cfg.ChanEnableTimeout,
|
||||||
defaultOutgoingCltvRejectDelta,
|
defaultOutgoingCltvRejectDelta,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user