multi: Update lnd to use new feature vector API.
This commit is contained in:
parent
af49752d4d
commit
9fd77a6e40
@ -145,8 +145,9 @@ func (d *databaseChannelGraph) addRandChannel(node1, node2 *btcec.PublicKey,
|
||||
IP: bytes.Repeat([]byte("a"), 16),
|
||||
},
|
||||
},
|
||||
Features: lnwire.NewFeatureVector(nil),
|
||||
AuthSig: testSig,
|
||||
Features: lnwire.NewFeatureVector(nil,
|
||||
lnwire.GlobalFeatures),
|
||||
AuthSig: testSig,
|
||||
}
|
||||
if err := d.db.AddLightningNode(graphNode); err != nil {
|
||||
return nil, err
|
||||
@ -170,7 +171,7 @@ func (d *databaseChannelGraph) addRandChannel(node1, node2 *btcec.PublicKey,
|
||||
IP: bytes.Repeat([]byte("a"), 16),
|
||||
},
|
||||
},
|
||||
Features: lnwire.NewFeatureVector(nil),
|
||||
Features: lnwire.NewFeatureVector(nil, lnwire.GlobalFeatures),
|
||||
AuthSig: testSig,
|
||||
}
|
||||
if err := d.db.AddLightningNode(dbNode); err != nil {
|
||||
|
@ -1592,10 +1592,12 @@ func deserializeLightningNode(r io.Reader) (*LightningNode, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
node.Features, err = lnwire.NewFeatureVectorFromReader(r)
|
||||
fv := lnwire.NewFeatureVector(nil, lnwire.GlobalFeatures)
|
||||
err = fv.Decode(r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
node.Features = fv
|
||||
|
||||
if _, err := r.Read(scratch[:2]); err != nil {
|
||||
return nil, err
|
||||
|
@ -37,7 +37,7 @@ var (
|
||||
_, _ = testSig.R.SetString("63724406601629180062774974542967536251589935445068131219452686511677818569431", 10)
|
||||
_, _ = testSig.S.SetString("18801056069249825825291287104931333862866033135609736119018462340006816851118", 10)
|
||||
|
||||
testFeatures = lnwire.NewFeatureVector([]lnwire.Feature{})
|
||||
testFeatures = lnwire.NewFeatureVector(nil, lnwire.GlobalFeatures)
|
||||
)
|
||||
|
||||
func createTestVertex(db *DB) (*LightningNode, error) {
|
||||
|
@ -647,6 +647,7 @@ func (d *AuthenticatedGossiper) processNetworkAnnouncement(nMsg *networkMsg) []l
|
||||
}
|
||||
}
|
||||
|
||||
features := lnwire.NewFeatureVector(msg.Features, lnwire.GlobalFeatures)
|
||||
node := &channeldb.LightningNode{
|
||||
HaveNodeAnnouncement: true,
|
||||
LastUpdate: time.Unix(int64(msg.Timestamp), 0),
|
||||
@ -654,7 +655,7 @@ func (d *AuthenticatedGossiper) processNetworkAnnouncement(nMsg *networkMsg) []l
|
||||
PubKey: msg.NodeID,
|
||||
Alias: msg.Alias.String(),
|
||||
AuthSig: msg.Signature,
|
||||
Features: msg.Features,
|
||||
Features: features,
|
||||
}
|
||||
|
||||
if err := d.cfg.Router.AddNode(node); err != nil {
|
||||
@ -1178,7 +1179,7 @@ func (d *AuthenticatedGossiper) synchronizeWithNode(syncReq *syncRequest) error
|
||||
Addresses: node.Addresses,
|
||||
NodeID: node.PubKey,
|
||||
Alias: alias,
|
||||
Features: node.Features,
|
||||
Features: node.Features.RawFeatureVector,
|
||||
}
|
||||
announceMessages = append(announceMessages, ann)
|
||||
|
||||
@ -1258,7 +1259,7 @@ func (d *AuthenticatedGossiper) updateChannel(info *channeldb.ChannelEdgeInfo,
|
||||
NodeID2: info.NodeKey2,
|
||||
ChainHash: info.ChainHash,
|
||||
BitcoinKey1: info.BitcoinKey1,
|
||||
Features: lnwire.NewFeatureVector([]lnwire.Feature{}),
|
||||
Features: lnwire.NewRawFeatureVector(),
|
||||
BitcoinKey2: info.BitcoinKey2,
|
||||
}
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ var (
|
||||
testAddr = &net.TCPAddr{IP: (net.IP)([]byte{0xA, 0x0, 0x0, 0x1}),
|
||||
Port: 9000}
|
||||
testAddrs = []net.Addr{testAddr}
|
||||
testFeatures = lnwire.NewFeatureVector([]lnwire.Feature{})
|
||||
testFeatures = lnwire.NewRawFeatureVector()
|
||||
testSig = &btcec.Signature{
|
||||
R: new(big.Int),
|
||||
S: new(big.Int),
|
||||
|
@ -32,7 +32,7 @@ func createChanAnnouncement(chanProof *channeldb.ChannelAuthProof,
|
||||
NodeID2: chanInfo.NodeKey2,
|
||||
ChainHash: chanInfo.ChainHash,
|
||||
BitcoinKey1: chanInfo.BitcoinKey1,
|
||||
Features: lnwire.NewFeatureVector([]lnwire.Feature{}),
|
||||
Features: lnwire.NewRawFeatureVector(),
|
||||
BitcoinKey2: chanInfo.BitcoinKey2,
|
||||
}
|
||||
|
||||
|
22
features.go
22
features.go
@ -1,22 +0,0 @@
|
||||
package main
|
||||
|
||||
import "github.com/lightningnetwork/lnd/lnwire"
|
||||
|
||||
// globalFeatures feature vector which affects HTLCs and thus are also
|
||||
// advertised to other nodes.
|
||||
var globalFeatures = lnwire.NewFeatureVector([]lnwire.Feature{})
|
||||
|
||||
// localFeatures is an feature vector which represent the features which
|
||||
// only affect the protocol between these two nodes.
|
||||
//
|
||||
// TODO(roasbeef): update to only have one, add a dummy vector?
|
||||
var localFeatures = lnwire.NewFeatureVector([]lnwire.Feature{
|
||||
{
|
||||
Name: "filler",
|
||||
Flag: lnwire.OptionalFlag,
|
||||
},
|
||||
{
|
||||
Name: "announce-graph",
|
||||
Flag: lnwire.OptionalFlag,
|
||||
},
|
||||
})
|
@ -1738,7 +1738,7 @@ func (f *fundingManager) newChanAnnouncement(localPubKey, remotePubKey *btcec.Pu
|
||||
// within the blockchain.
|
||||
chanAnn := &lnwire.ChannelAnnouncement{
|
||||
ShortChannelID: shortChanID,
|
||||
Features: lnwire.NewFeatureVector([]lnwire.Feature{}),
|
||||
Features: lnwire.NewRawFeatureVector(),
|
||||
ChainHash: chainHash,
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,7 @@ type ChannelAnnouncement struct {
|
||||
// by the target node. This field can be used to signal the type of the
|
||||
// channel, or modifications to the fields that would normally follow
|
||||
// this vector.
|
||||
Features *FeatureVector
|
||||
Features *RawFeatureVector
|
||||
|
||||
// ChainHash denotes the target chain that this channel was opened
|
||||
// within. This value should be the genesis hash of the target chain.
|
||||
|
@ -170,10 +170,14 @@ type FeatureVector struct {
|
||||
}
|
||||
|
||||
// NewFeatureVector constructs a new FeatureVector from a raw feature vector and
|
||||
// mapping of feature definitions.
|
||||
// mapping of feature definitions. If the feature vector argument is nil, a new
|
||||
// one will be constructed with no enabled features.
|
||||
func NewFeatureVector(featureVector *RawFeatureVector,
|
||||
featureNames map[FeatureBit]string) *FeatureVector {
|
||||
|
||||
if featureVector == nil {
|
||||
featureVector = NewRawFeatureVector()
|
||||
}
|
||||
return &FeatureVector{
|
||||
RawFeatureVector: featureVector,
|
||||
featureNames: featureNames,
|
||||
|
@ -9,15 +9,15 @@ import "io"
|
||||
type Init struct {
|
||||
// GlobalFeatures is feature vector which affects HTLCs and thus are
|
||||
// also advertised to other nodes.
|
||||
GlobalFeatures *FeatureVector
|
||||
GlobalFeatures *RawFeatureVector
|
||||
|
||||
// LocalFeatures is feature vector which only affect the protocol
|
||||
// between two nodes.
|
||||
LocalFeatures *FeatureVector
|
||||
LocalFeatures *RawFeatureVector
|
||||
}
|
||||
|
||||
// NewInitMessage creates new instance of init message object.
|
||||
func NewInitMessage(gf, lf *FeatureVector) *Init {
|
||||
func NewInitMessage(gf *RawFeatureVector, lf *RawFeatureVector) *Init {
|
||||
return &Init{
|
||||
GlobalFeatures: gf,
|
||||
LocalFeatures: lf,
|
||||
|
@ -215,7 +215,7 @@ func writeElement(w io.Writer, element interface{}) error {
|
||||
if err := wire.WriteVarBytes(w, 0, e); err != nil {
|
||||
return err
|
||||
}
|
||||
case *FeatureVector:
|
||||
case *RawFeatureVector:
|
||||
if e == nil {
|
||||
return fmt.Errorf("cannot write nil feature vector")
|
||||
}
|
||||
@ -435,8 +435,9 @@ func readElement(r io.Reader, element interface{}) error {
|
||||
return err
|
||||
}
|
||||
*e = pubKey
|
||||
case **FeatureVector:
|
||||
f, err := NewFeatureVectorFromReader(r)
|
||||
case **RawFeatureVector:
|
||||
f := NewRawFeatureVector()
|
||||
err = f.Decode(r)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -51,16 +51,14 @@ func randPubKey() (*btcec.PublicKey, error) {
|
||||
return priv.PubKey(), nil
|
||||
}
|
||||
|
||||
func randFeatureVector(r *rand.Rand) *FeatureVector {
|
||||
numFeatures := r.Int31n(10000)
|
||||
features := make([]Feature, numFeatures)
|
||||
for i := int32(0); i < numFeatures; i++ {
|
||||
features[i] = Feature{
|
||||
Flag: featureFlag(rand.Int31n(2) + 1),
|
||||
func randRawFeatureVector(r *rand.Rand) *RawFeatureVector {
|
||||
featureVec := NewRawFeatureVector()
|
||||
for i := 0; i < 10000; i++ {
|
||||
if r.Int31n(2) == 0 {
|
||||
featureVec.Set(FeatureBit(i))
|
||||
}
|
||||
}
|
||||
|
||||
return NewFeatureVector(features)
|
||||
return featureVec
|
||||
}
|
||||
|
||||
func TestMaxOutPointIndex(t *testing.T) {
|
||||
@ -139,11 +137,9 @@ func TestLightningWireProtocol(t *testing.T) {
|
||||
customTypeGen := map[MessageType]func([]reflect.Value, *rand.Rand){
|
||||
MsgInit: func(v []reflect.Value, r *rand.Rand) {
|
||||
req := NewInitMessage(
|
||||
randFeatureVector(r),
|
||||
randFeatureVector(r),
|
||||
randRawFeatureVector(r),
|
||||
randRawFeatureVector(r),
|
||||
)
|
||||
req.GlobalFeatures.featuresMap = nil
|
||||
req.LocalFeatures.featuresMap = nil
|
||||
|
||||
v[0] = reflect.ValueOf(*req)
|
||||
},
|
||||
@ -351,9 +347,8 @@ func TestLightningWireProtocol(t *testing.T) {
|
||||
MsgChannelAnnouncement: func(v []reflect.Value, r *rand.Rand) {
|
||||
req := ChannelAnnouncement{
|
||||
ShortChannelID: NewShortChanIDFromInt(uint64(r.Int63())),
|
||||
Features: randFeatureVector(r),
|
||||
Features: randRawFeatureVector(r),
|
||||
}
|
||||
req.Features.featuresMap = nil
|
||||
req.NodeSig1 = testSig
|
||||
req.NodeSig2 = testSig
|
||||
req.BitcoinSig1 = testSig
|
||||
@ -396,7 +391,7 @@ func TestLightningWireProtocol(t *testing.T) {
|
||||
|
||||
req := NodeAnnouncement{
|
||||
Signature: testSig,
|
||||
Features: randFeatureVector(r),
|
||||
Features: randRawFeatureVector(r),
|
||||
Timestamp: uint32(r.Int31()),
|
||||
Alias: a,
|
||||
RGBColor: RGB{
|
||||
@ -407,7 +402,6 @@ func TestLightningWireProtocol(t *testing.T) {
|
||||
// TODO(roasbeef): proper gen rand addrs
|
||||
Addresses: testAddrs,
|
||||
}
|
||||
req.Features.featuresMap = nil
|
||||
|
||||
var err error
|
||||
req.NodeID, err = randPubKey()
|
||||
|
@ -59,7 +59,7 @@ type NodeAnnouncement struct {
|
||||
Signature *btcec.Signature
|
||||
|
||||
// Features is the list of protocol features this node supports.
|
||||
Features *FeatureVector
|
||||
Features *RawFeatureVector
|
||||
|
||||
// Timestamp allows ordering in the case of multiple announcements.
|
||||
Timestamp uint32
|
||||
|
@ -26,7 +26,7 @@ var (
|
||||
Port: 9000}
|
||||
testAddrs = []net.Addr{testAddr}
|
||||
|
||||
testFeatures = lnwire.NewFeatureVector([]lnwire.Feature{})
|
||||
testFeatures = lnwire.NewFeatureVector(nil, lnwire.GlobalFeatures)
|
||||
|
||||
testHash = [32]byte{
|
||||
0xb7, 0x94, 0x38, 0x5f, 0x2d, 0x1e, 0xf7, 0xab,
|
||||
|
13
server.go
13
server.go
@ -131,6 +131,9 @@ func newServer(listenAddrs []string, chanDB *channeldb.DB, cc *chainControl,
|
||||
}
|
||||
}
|
||||
|
||||
globalFeatures := lnwire.NewRawFeatureVector()
|
||||
localFeatures := lnwire.NewRawFeatureVector(lnwire.InitialRoutingSync)
|
||||
|
||||
serializedPubKey := privKey.PubKey().SerializeCompressed()
|
||||
s := &server{
|
||||
chanDB: chanDB,
|
||||
@ -159,8 +162,10 @@ func newServer(listenAddrs []string, chanDB *channeldb.DB, cc *chainControl,
|
||||
outboundPeers: make(map[string]*peer),
|
||||
peerConnectedListeners: make(map[string][]chan<- struct{}),
|
||||
|
||||
globalFeatures: globalFeatures,
|
||||
localFeatures: localFeatures,
|
||||
globalFeatures: lnwire.NewFeatureVector(globalFeatures,
|
||||
lnwire.GlobalFeatures),
|
||||
localFeatures: lnwire.NewFeatureVector(localFeatures,
|
||||
lnwire.LocalFeatures),
|
||||
|
||||
quit: make(chan struct{}),
|
||||
}
|
||||
@ -234,7 +239,7 @@ func newServer(listenAddrs []string, chanDB *channeldb.DB, cc *chainControl,
|
||||
Addresses: selfAddrs,
|
||||
PubKey: privKey.PubKey(),
|
||||
Alias: alias.String(),
|
||||
Features: globalFeatures,
|
||||
Features: s.globalFeatures,
|
||||
}
|
||||
|
||||
// If our information has changed since our last boot, then we'll
|
||||
@ -247,7 +252,7 @@ func newServer(listenAddrs []string, chanDB *channeldb.DB, cc *chainControl,
|
||||
Addresses: selfNode.Addresses,
|
||||
NodeID: selfNode.PubKey,
|
||||
Alias: alias,
|
||||
Features: selfNode.Features,
|
||||
Features: selfNode.Features.RawFeatureVector,
|
||||
}
|
||||
selfNode.AuthSig, err = discovery.SignAnnouncement(s.nodeSigner,
|
||||
s.identityPriv.PubKey(), nodeAnn,
|
||||
|
Loading…
Reference in New Issue
Block a user