multi: remove HaveNodeAnnouncement field from Node
Remove the 2 sources of truth here. If we have a signature for the node, then we have the announcement.
This commit is contained in:
1 parent
a394938dfd
commit
8f205e2d1c
15 files changed
+154
-182
No files matched your search
@@ -418,7 +418,6 @@ func (d *testDBGraph) addRandChannel(node1, node2 *btcec.PublicKey,
|
|||||||
fallthrough
|
fallthrough
|
||||||
case errors.Is(err, graphdb.ErrGraphNotFound):
|
case errors.Is(err, graphdb.ErrGraphNotFound):
|
||||||
graphNode := &models.Node{
|
graphNode := &models.Node{
|
||||||
HaveNodeAnnouncement: true,
|
|
||||||
Addresses: []net.Addr{&net.TCPAddr{
|
Addresses: []net.Addr{&net.TCPAddr{
|
||||||
IP: bytes.Repeat(
|
IP: bytes.Repeat(
|
||||||
[]byte("a"), 16,
|
[]byte("a"), 16,
|
||||||
@@ -451,7 +450,6 @@ func (d *testDBGraph) addRandChannel(node1, node2 *btcec.PublicKey,
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
dbNode := &models.Node{
|
dbNode := &models.Node{
|
||||||
HaveNodeAnnouncement: true,
|
|
||||||
Addresses: []net.Addr{
|
Addresses: []net.Addr{
|
||||||
&net.TCPAddr{
|
&net.TCPAddr{
|
||||||
IP: bytes.Repeat([]byte("a"), 16),
|
IP: bytes.Repeat([]byte("a"), 16),
|
||||||
@@ -552,7 +550,6 @@ func (d *testDBGraph) addRandNode() (*btcec.PublicKey, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
dbNode := &models.Node{
|
dbNode := &models.Node{
|
||||||
HaveNodeAnnouncement: true,
|
|
||||||
Addresses: []net.Addr{
|
Addresses: []net.Addr{
|
||||||
&net.TCPAddr{
|
&net.TCPAddr{
|
||||||
IP: bytes.Repeat([]byte("a"), 16),
|
IP: bytes.Repeat([]byte("a"), 16),
|
||||||
|
|||||||
@@ -812,13 +812,12 @@ func createNode(priv *btcec.PrivateKey) *models.Node {
|
|||||||
|
|
||||||
pub := priv.PubKey().SerializeCompressed()
|
pub := priv.PubKey().SerializeCompressed()
|
||||||
n := &models.Node{
|
n := &models.Node{
|
||||||
HaveNodeAnnouncement: true,
|
AuthSigBytes: testSig.Serialize(),
|
||||||
AuthSigBytes: testSig.Serialize(),
|
LastUpdate: time.Unix(updateTime, 0),
|
||||||
LastUpdate: time.Unix(updateTime, 0),
|
Color: color.RGBA{1, 2, 3, 0},
|
||||||
Color: color.RGBA{1, 2, 3, 0},
|
Alias: "kek" + string(pub),
|
||||||
Alias: "kek" + string(pub),
|
Features: testFeatures,
|
||||||
Features: testFeatures,
|
Addresses: testAddrs,
|
||||||
Addresses: testAddrs,
|
|
||||||
}
|
}
|
||||||
copy(n.PubKeyBytes[:], priv.PubKey().SerializeCompressed())
|
copy(n.PubKeyBytes[:], priv.PubKey().SerializeCompressed())
|
||||||
|
|
||||||
|
|||||||
@@ -295,7 +295,7 @@ func (c *ChanSeries) FetchChanAnns(chain chainhash.Hash,
|
|||||||
// If this edge has a validated node announcement, that
|
// If this edge has a validated node announcement, that
|
||||||
// we haven't yet sent, then we'll send that as well.
|
// we haven't yet sent, then we'll send that as well.
|
||||||
nodePub := channel.Node2.PubKeyBytes
|
nodePub := channel.Node2.PubKeyBytes
|
||||||
hasNodeAnn := channel.Node2.HaveNodeAnnouncement
|
hasNodeAnn := channel.Node2.HaveAnnouncement()
|
||||||
if _, ok := nodePubsSent[nodePub]; !ok && hasNodeAnn {
|
if _, ok := nodePubsSent[nodePub]; !ok && hasNodeAnn {
|
||||||
nodeAnn, err := channel.Node2.NodeAnnouncement(
|
nodeAnn, err := channel.Node2.NodeAnnouncement(
|
||||||
true,
|
true,
|
||||||
@@ -321,7 +321,7 @@ func (c *ChanSeries) FetchChanAnns(chain chainhash.Hash,
|
|||||||
// If this edge has a validated node announcement, that
|
// If this edge has a validated node announcement, that
|
||||||
// we haven't yet sent, then we'll send that as well.
|
// we haven't yet sent, then we'll send that as well.
|
||||||
nodePub := channel.Node1.PubKeyBytes
|
nodePub := channel.Node1.PubKeyBytes
|
||||||
hasNodeAnn := channel.Node1.HaveNodeAnnouncement
|
hasNodeAnn := channel.Node1.HaveAnnouncement()
|
||||||
if _, ok := nodePubsSent[nodePub]; !ok && hasNodeAnn {
|
if _, ok := nodePubsSent[nodePub]; !ok && hasNodeAnn {
|
||||||
nodeAnn, err := channel.Node1.NodeAnnouncement(
|
nodeAnn, err := channel.Node1.NodeAnnouncement(
|
||||||
true,
|
true,
|
||||||
|
|||||||
+22
-26
@@ -98,13 +98,12 @@ func TestIgnoreNodeAnnouncement(t *testing.T) {
|
|||||||
|
|
||||||
pub := priv1.PubKey()
|
pub := priv1.PubKey()
|
||||||
node := &models.Node{
|
node := &models.Node{
|
||||||
HaveNodeAnnouncement: true,
|
LastUpdate: time.Unix(123, 0),
|
||||||
LastUpdate: time.Unix(123, 0),
|
Addresses: testAddrs,
|
||||||
Addresses: testAddrs,
|
Color: color.RGBA{1, 2, 3, 0},
|
||||||
Color: color.RGBA{1, 2, 3, 0},
|
Alias: "node11",
|
||||||
Alias: "node11",
|
AuthSigBytes: testSig.Serialize(),
|
||||||
AuthSigBytes: testSig.Serialize(),
|
Features: testFeatures,
|
||||||
Features: testFeatures,
|
|
||||||
}
|
}
|
||||||
copy(node.PubKeyBytes[:], pub.SerializeCompressed())
|
copy(node.PubKeyBytes[:], pub.SerializeCompressed())
|
||||||
|
|
||||||
@@ -1085,13 +1084,12 @@ func TestIsStaleNode(t *testing.T) {
|
|||||||
// With the node stub in the database, we'll add the fully node
|
// With the node stub in the database, we'll add the fully node
|
||||||
// announcement to the database.
|
// announcement to the database.
|
||||||
n1 := &models.Node{
|
n1 := &models.Node{
|
||||||
HaveNodeAnnouncement: true,
|
LastUpdate: updateTimeStamp,
|
||||||
LastUpdate: updateTimeStamp,
|
Addresses: testAddrs,
|
||||||
Addresses: testAddrs,
|
Color: color.RGBA{1, 2, 3, 0},
|
||||||
Color: color.RGBA{1, 2, 3, 0},
|
Alias: "node11",
|
||||||
Alias: "node11",
|
AuthSigBytes: testSig.Serialize(),
|
||||||
AuthSigBytes: testSig.Serialize(),
|
Features: testFeatures,
|
||||||
Features: testFeatures,
|
|
||||||
}
|
}
|
||||||
copy(n1.PubKeyBytes[:], priv1.PubKey().SerializeCompressed())
|
copy(n1.PubKeyBytes[:], priv1.PubKey().SerializeCompressed())
|
||||||
if err := ctx.builder.AddNode(t.Context(), n1); err != nil {
|
if err := ctx.builder.AddNode(t.Context(), n1); err != nil {
|
||||||
@@ -1402,12 +1400,11 @@ func parseTestGraph(t *testing.T, useCache bool, path string) (
|
|||||||
}
|
}
|
||||||
|
|
||||||
dbNode := &models.Node{
|
dbNode := &models.Node{
|
||||||
HaveNodeAnnouncement: true,
|
AuthSigBytes: testSig.Serialize(),
|
||||||
AuthSigBytes: testSig.Serialize(),
|
LastUpdate: testTime,
|
||||||
LastUpdate: testTime,
|
Addresses: testAddrs,
|
||||||
Addresses: testAddrs,
|
Alias: node.Alias,
|
||||||
Alias: node.Alias,
|
Features: testFeatures,
|
||||||
Features: testFeatures,
|
|
||||||
}
|
}
|
||||||
copy(dbNode.PubKeyBytes[:], pubBytes)
|
copy(dbNode.PubKeyBytes[:], pubBytes)
|
||||||
|
|
||||||
@@ -1788,12 +1785,11 @@ func createTestGraphFromChannels(t *testing.T, useCache bool,
|
|||||||
}
|
}
|
||||||
|
|
||||||
dbNode := &models.Node{
|
dbNode := &models.Node{
|
||||||
HaveNodeAnnouncement: true,
|
AuthSigBytes: testSig.Serialize(),
|
||||||
AuthSigBytes: testSig.Serialize(),
|
LastUpdate: testTime,
|
||||||
LastUpdate: testTime,
|
Addresses: testAddrs,
|
||||||
Addresses: testAddrs,
|
Alias: alias,
|
||||||
Alias: alias,
|
Features: features,
|
||||||
Features: features,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
copy(dbNode.PubKeyBytes[:], pubKey.SerializeCompressed())
|
copy(dbNode.PubKeyBytes[:], pubKey.SerializeCompressed())
|
||||||
|
|||||||
+22
-26
@@ -72,13 +72,12 @@ var (
|
|||||||
func createNode(priv *btcec.PrivateKey) *models.Node {
|
func createNode(priv *btcec.PrivateKey) *models.Node {
|
||||||
pub := priv.PubKey().SerializeCompressed()
|
pub := priv.PubKey().SerializeCompressed()
|
||||||
n := &models.Node{
|
n := &models.Node{
|
||||||
HaveNodeAnnouncement: true,
|
AuthSigBytes: testSig.Serialize(),
|
||||||
AuthSigBytes: testSig.Serialize(),
|
LastUpdate: nextUpdateTime(),
|
||||||
LastUpdate: nextUpdateTime(),
|
Color: color.RGBA{1, 2, 3, 0},
|
||||||
Color: color.RGBA{1, 2, 3, 0},
|
Alias: "kek" + hex.EncodeToString(pub),
|
||||||
Alias: "kek" + hex.EncodeToString(pub),
|
Features: testFeatures,
|
||||||
Features: testFeatures,
|
Addresses: testAddrs,
|
||||||
Addresses: testAddrs,
|
|
||||||
}
|
}
|
||||||
copy(n.PubKeyBytes[:], priv.PubKey().SerializeCompressed())
|
copy(n.PubKeyBytes[:], priv.PubKey().SerializeCompressed())
|
||||||
|
|
||||||
@@ -107,15 +106,14 @@ func TestNodeInsertionAndDeletion(t *testing.T) {
|
|||||||
nodeWithAddrs := func(addrs []net.Addr) *models.Node {
|
nodeWithAddrs := func(addrs []net.Addr) *models.Node {
|
||||||
timeStamp++
|
timeStamp++
|
||||||
return &models.Node{
|
return &models.Node{
|
||||||
HaveNodeAnnouncement: true,
|
AuthSigBytes: testSig.Serialize(),
|
||||||
AuthSigBytes: testSig.Serialize(),
|
LastUpdate: time.Unix(timeStamp, 0),
|
||||||
LastUpdate: time.Unix(timeStamp, 0),
|
Color: color.RGBA{1, 2, 3, 0},
|
||||||
Color: color.RGBA{1, 2, 3, 0},
|
Alias: "kek",
|
||||||
Alias: "kek",
|
Features: testFeatures,
|
||||||
Features: testFeatures,
|
Addresses: addrs,
|
||||||
Addresses: addrs,
|
ExtraOpaqueData: []byte{1, 1, 1, 2, 2, 2, 2},
|
||||||
ExtraOpaqueData: []byte{1, 1, 1, 2, 2, 2, 2},
|
PubKeyBytes: testPub,
|
||||||
PubKeyBytes: testPub,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -316,10 +314,9 @@ func TestPartialNode(t *testing.T) {
|
|||||||
// The two nodes should match exactly! (with default values for
|
// The two nodes should match exactly! (with default values for
|
||||||
// LastUpdate and db set to satisfy compareNodes())
|
// LastUpdate and db set to satisfy compareNodes())
|
||||||
expectedNode1 := &models.Node{
|
expectedNode1 := &models.Node{
|
||||||
HaveNodeAnnouncement: false,
|
LastUpdate: time.Unix(0, 0),
|
||||||
LastUpdate: time.Unix(0, 0),
|
PubKeyBytes: pubKey1,
|
||||||
PubKeyBytes: pubKey1,
|
Features: lnwire.EmptyFeatureVector(),
|
||||||
Features: lnwire.EmptyFeatureVector(),
|
|
||||||
}
|
}
|
||||||
compareNodes(t, expectedNode1, dbNode1)
|
compareNodes(t, expectedNode1, dbNode1)
|
||||||
|
|
||||||
@@ -330,10 +327,9 @@ func TestPartialNode(t *testing.T) {
|
|||||||
// The two nodes should match exactly! (with default values for
|
// The two nodes should match exactly! (with default values for
|
||||||
// LastUpdate and db set to satisfy compareNodes())
|
// LastUpdate and db set to satisfy compareNodes())
|
||||||
expectedNode2 := &models.Node{
|
expectedNode2 := &models.Node{
|
||||||
HaveNodeAnnouncement: false,
|
LastUpdate: time.Unix(0, 0),
|
||||||
LastUpdate: time.Unix(0, 0),
|
PubKeyBytes: pubKey2,
|
||||||
PubKeyBytes: pubKey2,
|
Features: lnwire.EmptyFeatureVector(),
|
||||||
Features: lnwire.EmptyFeatureVector(),
|
|
||||||
}
|
}
|
||||||
compareNodes(t, expectedNode2, dbNode2)
|
compareNodes(t, expectedNode2, dbNode2)
|
||||||
|
|
||||||
@@ -3782,11 +3778,11 @@ func TestAddChannelEdgeShellNodes(t *testing.T) {
|
|||||||
// a shell node present.
|
// a shell node present.
|
||||||
node1, err := graph.FetchNode(ctx, node1.PubKeyBytes)
|
node1, err := graph.FetchNode(ctx, node1.PubKeyBytes)
|
||||||
require.NoError(t, err, "unable to fetch node1")
|
require.NoError(t, err, "unable to fetch node1")
|
||||||
require.True(t, node1.HaveNodeAnnouncement)
|
require.True(t, node1.HaveAnnouncement())
|
||||||
|
|
||||||
node2, err = graph.FetchNode(ctx, node2.PubKeyBytes)
|
node2, err = graph.FetchNode(ctx, node2.PubKeyBytes)
|
||||||
require.NoError(t, err, "unable to fetch node2")
|
require.NoError(t, err, "unable to fetch node2")
|
||||||
require.False(t, node2.HaveNodeAnnouncement)
|
require.False(t, node2.HaveAnnouncement())
|
||||||
|
|
||||||
// Show that attempting to add the channel again will result in an
|
// Show that attempting to add the channel again will result in an
|
||||||
// error.
|
// error.
|
||||||
|
|||||||
+4
-12
@@ -1206,8 +1206,7 @@ func (c *KVStore) addChannelEdge(tx kvdb.RwTx,
|
|||||||
switch {
|
switch {
|
||||||
case errors.Is(node1Err, ErrGraphNodeNotFound):
|
case errors.Is(node1Err, ErrGraphNodeNotFound):
|
||||||
node1Shell := models.Node{
|
node1Shell := models.Node{
|
||||||
PubKeyBytes: edge.NodeKey1Bytes,
|
PubKeyBytes: edge.NodeKey1Bytes,
|
||||||
HaveNodeAnnouncement: false,
|
|
||||||
}
|
}
|
||||||
err := addLightningNode(tx, &node1Shell)
|
err := addLightningNode(tx, &node1Shell)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -1222,8 +1221,7 @@ func (c *KVStore) addChannelEdge(tx kvdb.RwTx,
|
|||||||
switch {
|
switch {
|
||||||
case errors.Is(node2Err, ErrGraphNodeNotFound):
|
case errors.Is(node2Err, ErrGraphNodeNotFound):
|
||||||
node2Shell := models.Node{
|
node2Shell := models.Node{
|
||||||
PubKeyBytes: edge.NodeKey2Bytes,
|
PubKeyBytes: edge.NodeKey2Bytes,
|
||||||
HaveNodeAnnouncement: false,
|
|
||||||
}
|
}
|
||||||
err := addLightningNode(tx, &node2Shell)
|
err := addLightningNode(tx, &node2Shell)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -4369,7 +4367,7 @@ func putLightningNode(nodeBucket, aliasBucket, updateIndex kvdb.RwBucket,
|
|||||||
|
|
||||||
// If we got a node announcement for this node, we will have the rest
|
// If we got a node announcement for this node, we will have the rest
|
||||||
// of the data available. If not we don't have more data to write.
|
// of the data available. If not we don't have more data to write.
|
||||||
if !node.HaveNodeAnnouncement {
|
if !node.HaveAnnouncement() {
|
||||||
// Write HaveNodeAnnouncement=0.
|
// Write HaveNodeAnnouncement=0.
|
||||||
byteOrder.PutUint16(scratch[:2], 0)
|
byteOrder.PutUint16(scratch[:2], 0)
|
||||||
if _, err := b.Write(scratch[:2]); err != nil {
|
if _, err := b.Write(scratch[:2]); err != nil {
|
||||||
@@ -4562,15 +4560,9 @@ func deserializeLightningNode(r io.Reader) (models.Node, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
hasNodeAnn := byteOrder.Uint16(scratch[:2])
|
hasNodeAnn := byteOrder.Uint16(scratch[:2])
|
||||||
if hasNodeAnn == 1 {
|
|
||||||
node.HaveNodeAnnouncement = true
|
|
||||||
} else {
|
|
||||||
node.HaveNodeAnnouncement = false
|
|
||||||
}
|
|
||||||
|
|
||||||
// The rest of the data is optional, and will only be there if we got a
|
// The rest of the data is optional, and will only be there if we got a
|
||||||
// node announcement for this node.
|
// node announcement for this node.
|
||||||
if !node.HaveNodeAnnouncement {
|
if hasNodeAnn == 0 {
|
||||||
return node, nil
|
return node, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+32
-29
@@ -19,11 +19,6 @@ type Node struct {
|
|||||||
PubKeyBytes [33]byte
|
PubKeyBytes [33]byte
|
||||||
pubKey *btcec.PublicKey
|
pubKey *btcec.PublicKey
|
||||||
|
|
||||||
// HaveNodeAnnouncement indicates whether we received a node
|
|
||||||
// announcement for this particular node. If true, the remaining fields
|
|
||||||
// will be set, if false only the PubKey is known for this node.
|
|
||||||
HaveNodeAnnouncement bool
|
|
||||||
|
|
||||||
// LastUpdate is the last time the vertex information for this node has
|
// LastUpdate is the last time the vertex information for this node has
|
||||||
// been updated.
|
// been updated.
|
||||||
LastUpdate time.Time
|
LastUpdate time.Time
|
||||||
@@ -54,53 +49,62 @@ type Node struct {
|
|||||||
ExtraOpaqueData []byte
|
ExtraOpaqueData []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HaveAnnouncement returns true if we have received a node announcement for
|
||||||
|
// this node. We determine this by checking if we have a signature for the
|
||||||
|
// announcement.
|
||||||
|
func (n *Node) HaveAnnouncement() bool {
|
||||||
|
return len(n.AuthSigBytes) > 0
|
||||||
|
}
|
||||||
|
|
||||||
// PubKey is the node's long-term identity public key. This key will be used to
|
// PubKey is the node's long-term identity public key. This key will be used to
|
||||||
// authenticated any advertisements/updates sent by the node.
|
// authenticated any advertisements/updates sent by the node.
|
||||||
//
|
//
|
||||||
// NOTE: By having this method to access an attribute, we ensure we only need
|
// NOTE: By having this method to access an attribute, we ensure we only need
|
||||||
// to fully deserialize the pubkey if absolutely necessary.
|
// to fully deserialize the pubkey if absolutely necessary.
|
||||||
func (l *Node) PubKey() (*btcec.PublicKey, error) {
|
func (n *Node) PubKey() (*btcec.PublicKey, error) {
|
||||||
if l.pubKey != nil {
|
if n.pubKey != nil {
|
||||||
return l.pubKey, nil
|
return n.pubKey, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
key, err := btcec.ParsePubKey(l.PubKeyBytes[:])
|
key, err := btcec.ParsePubKey(n.PubKeyBytes[:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
l.pubKey = key
|
n.pubKey = key
|
||||||
|
|
||||||
return key, nil
|
return key, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// NodeAnnouncement retrieves the latest node announcement of the node.
|
// NodeAnnouncement retrieves the latest node announcement of the node.
|
||||||
func (l *Node) NodeAnnouncement(signed bool) (*lnwire.NodeAnnouncement1,
|
func (n *Node) NodeAnnouncement(signed bool) (*lnwire.NodeAnnouncement1,
|
||||||
error) {
|
error) {
|
||||||
|
|
||||||
if !l.HaveNodeAnnouncement {
|
// Error out if we request the signed announcement, but we don't have
|
||||||
|
// a signature for this announcement.
|
||||||
|
if !n.HaveAnnouncement() && signed {
|
||||||
return nil, fmt.Errorf("node does not have node announcement")
|
return nil, fmt.Errorf("node does not have node announcement")
|
||||||
}
|
}
|
||||||
|
|
||||||
alias, err := lnwire.NewNodeAlias(l.Alias)
|
alias, err := lnwire.NewNodeAlias(n.Alias)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
nodeAnn := &lnwire.NodeAnnouncement1{
|
nodeAnn := &lnwire.NodeAnnouncement1{
|
||||||
Features: l.Features.RawFeatureVector,
|
Features: n.Features.RawFeatureVector,
|
||||||
NodeID: l.PubKeyBytes,
|
NodeID: n.PubKeyBytes,
|
||||||
RGBColor: l.Color,
|
RGBColor: n.Color,
|
||||||
Alias: alias,
|
Alias: alias,
|
||||||
Addresses: l.Addresses,
|
Addresses: n.Addresses,
|
||||||
Timestamp: uint32(l.LastUpdate.Unix()),
|
Timestamp: uint32(n.LastUpdate.Unix()),
|
||||||
ExtraOpaqueData: l.ExtraOpaqueData,
|
ExtraOpaqueData: n.ExtraOpaqueData,
|
||||||
}
|
}
|
||||||
|
|
||||||
if !signed {
|
if !signed {
|
||||||
return nodeAnn, nil
|
return nodeAnn, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
sig, err := lnwire.NewSigFromECDSARawSignature(l.AuthSigBytes)
|
sig, err := lnwire.NewSigFromECDSARawSignature(n.AuthSigBytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -117,14 +121,13 @@ func NodeFromWireAnnouncement(msg *lnwire.NodeAnnouncement1) *Node {
|
|||||||
features := lnwire.NewFeatureVector(msg.Features, lnwire.Features)
|
features := lnwire.NewFeatureVector(msg.Features, lnwire.Features)
|
||||||
|
|
||||||
return &Node{
|
return &Node{
|
||||||
HaveNodeAnnouncement: true,
|
LastUpdate: timestamp,
|
||||||
LastUpdate: timestamp,
|
Addresses: msg.Addresses,
|
||||||
Addresses: msg.Addresses,
|
PubKeyBytes: msg.NodeID,
|
||||||
PubKeyBytes: msg.NodeID,
|
Alias: msg.Alias.String(),
|
||||||
Alias: msg.Alias.String(),
|
AuthSigBytes: msg.Signature.ToSignatureBytes(),
|
||||||
AuthSigBytes: msg.Signature.ToSignatureBytes(),
|
Features: features,
|
||||||
Features: features,
|
Color: msg.RGBColor,
|
||||||
Color: msg.RGBColor,
|
ExtraOpaqueData: msg.ExtraOpaqueData,
|
||||||
ExtraOpaqueData: msg.ExtraOpaqueData,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1449,7 +1449,7 @@ func insertNodeSQLMig(ctx context.Context, db SQLQueries,
|
|||||||
PubKey: node.PubKeyBytes[:],
|
PubKey: node.PubKeyBytes[:],
|
||||||
}
|
}
|
||||||
|
|
||||||
if node.HaveNodeAnnouncement {
|
if node.HaveAnnouncement() {
|
||||||
params.LastUpdate = sqldb.SQLInt64(node.LastUpdate.Unix())
|
params.LastUpdate = sqldb.SQLInt64(node.LastUpdate.Unix())
|
||||||
params.Color = sqldb.SQLStrValid(EncodeHexColor(node.Color))
|
params.Color = sqldb.SQLStrValid(EncodeHexColor(node.Color))
|
||||||
params.Alias = sqldb.SQLStrValid(node.Alias)
|
params.Alias = sqldb.SQLStrValid(node.Alias)
|
||||||
@@ -1463,7 +1463,7 @@ func insertNodeSQLMig(ctx context.Context, db SQLQueries,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// We can exit here if we don't have the announcement yet.
|
// We can exit here if we don't have the announcement yet.
|
||||||
if !node.HaveNodeAnnouncement {
|
if !node.HaveAnnouncement() {
|
||||||
return nodeID, nil
|
return nodeID, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -385,8 +385,7 @@ func TestMigrateGraphToSQL(t *testing.T) {
|
|||||||
// node be set. So that is the first object
|
// node be set. So that is the first object
|
||||||
// we will write.
|
// we will write.
|
||||||
&models.Node{
|
&models.Node{
|
||||||
HaveNodeAnnouncement: false,
|
PubKeyBytes: testPub,
|
||||||
PubKeyBytes: testPub,
|
|
||||||
},
|
},
|
||||||
// Now we add some block heights to prune
|
// Now we add some block heights to prune
|
||||||
// the graph at.
|
// the graph at.
|
||||||
@@ -748,15 +747,14 @@ type testNodeOpt func(*models.Node)
|
|||||||
// functional options can be used to modify the node's attributes.
|
// functional options can be used to modify the node's attributes.
|
||||||
func makeTestNode(t *testing.T, opts ...testNodeOpt) *models.Node {
|
func makeTestNode(t *testing.T, opts ...testNodeOpt) *models.Node {
|
||||||
n := &models.Node{
|
n := &models.Node{
|
||||||
HaveNodeAnnouncement: true,
|
AuthSigBytes: testSigBytes,
|
||||||
AuthSigBytes: testSigBytes,
|
LastUpdate: testTime,
|
||||||
LastUpdate: testTime,
|
Color: testColor,
|
||||||
Color: testColor,
|
Alias: "kek",
|
||||||
Alias: "kek",
|
Features: testFeatures,
|
||||||
Features: testFeatures,
|
Addresses: testAddrs,
|
||||||
Addresses: testAddrs,
|
ExtraOpaqueData: testExtraData,
|
||||||
ExtraOpaqueData: testExtraData,
|
PubKeyBytes: genPubKey(t),
|
||||||
PubKeyBytes: genPubKey(t),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, opt := range opts {
|
for _, opt := range opts {
|
||||||
@@ -777,10 +775,9 @@ func makeTestShellNode(t *testing.T,
|
|||||||
opts ...testNodeOpt) *models.Node {
|
opts ...testNodeOpt) *models.Node {
|
||||||
|
|
||||||
n := &models.Node{
|
n := &models.Node{
|
||||||
HaveNodeAnnouncement: false,
|
PubKeyBytes: genPubKey(t),
|
||||||
PubKeyBytes: genPubKey(t),
|
Features: testEmptyFeatures,
|
||||||
Features: testEmptyFeatures,
|
LastUpdate: time.Unix(0, 0),
|
||||||
LastUpdate: time.Unix(0, 0),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, opt := range opts {
|
for _, opt := range opts {
|
||||||
@@ -1817,11 +1814,10 @@ func genRandomNode(t *rapid.T) *models.Node {
|
|||||||
}
|
}
|
||||||
|
|
||||||
node := &models.Node{
|
node := &models.Node{
|
||||||
HaveNodeAnnouncement: true,
|
AuthSigBytes: sigBytes,
|
||||||
AuthSigBytes: sigBytes,
|
LastUpdate: randTime,
|
||||||
LastUpdate: randTime,
|
Color: randColor,
|
||||||
Color: randColor,
|
Alias: alias.String(),
|
||||||
Alias: alias.String(),
|
|
||||||
Features: lnwire.NewFeatureVector(
|
Features: lnwire.NewFeatureVector(
|
||||||
features, lnwire.Features,
|
features, lnwire.Features,
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -3495,7 +3495,6 @@ func buildNodeWithBatchData(dbNode sqlc.GraphNode,
|
|||||||
return node, nil
|
return node, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
node.HaveNodeAnnouncement = true
|
|
||||||
node.AuthSigBytes = dbNode.Signature
|
node.AuthSigBytes = dbNode.Signature
|
||||||
node.Alias = dbNode.Alias.String
|
node.Alias = dbNode.Alias.String
|
||||||
node.LastUpdate = time.Unix(dbNode.LastUpdate.Int64, 0)
|
node.LastUpdate = time.Unix(dbNode.LastUpdate.Int64, 0)
|
||||||
@@ -3608,7 +3607,7 @@ func upsertNode(ctx context.Context, db SQLQueries,
|
|||||||
PubKey: node.PubKeyBytes[:],
|
PubKey: node.PubKeyBytes[:],
|
||||||
}
|
}
|
||||||
|
|
||||||
if node.HaveNodeAnnouncement {
|
if node.HaveAnnouncement() {
|
||||||
params.LastUpdate = sqldb.SQLInt64(node.LastUpdate.Unix())
|
params.LastUpdate = sqldb.SQLInt64(node.LastUpdate.Unix())
|
||||||
params.Color = sqldb.SQLStrValid(EncodeHexColor(node.Color))
|
params.Color = sqldb.SQLStrValid(EncodeHexColor(node.Color))
|
||||||
params.Alias = sqldb.SQLStrValid(node.Alias)
|
params.Alias = sqldb.SQLStrValid(node.Alias)
|
||||||
@@ -3622,7 +3621,7 @@ func upsertNode(ctx context.Context, db SQLQueries,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// We can exit here if we don't have the announcement yet.
|
// We can exit here if we don't have the announcement yet.
|
||||||
if !node.HaveNodeAnnouncement {
|
if !node.HaveAnnouncement() {
|
||||||
return nodeID, nil
|
return nodeID, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -84,13 +84,12 @@ func createTestNode(t *testing.T) *models.Node {
|
|||||||
|
|
||||||
pub := priv.PubKey().SerializeCompressed()
|
pub := priv.PubKey().SerializeCompressed()
|
||||||
n := &models.Node{
|
n := &models.Node{
|
||||||
HaveNodeAnnouncement: true,
|
LastUpdate: time.Unix(updateTime, 0),
|
||||||
LastUpdate: time.Unix(updateTime, 0),
|
Addresses: testAddrs,
|
||||||
Addresses: testAddrs,
|
Color: color.RGBA{1, 2, 3, 0},
|
||||||
Color: color.RGBA{1, 2, 3, 0},
|
Alias: "kek" + hex.EncodeToString(pub),
|
||||||
Alias: "kek" + hex.EncodeToString(pub),
|
AuthSigBytes: testSig.Serialize(),
|
||||||
AuthSigBytes: testSig.Serialize(),
|
Features: testFeatures,
|
||||||
Features: testFeatures,
|
|
||||||
}
|
}
|
||||||
copy(n.PubKeyBytes[:], pub)
|
copy(n.PubKeyBytes[:], pub)
|
||||||
|
|
||||||
|
|||||||
@@ -227,11 +227,14 @@ func (s *Server) ImportGraph(ctx context.Context,
|
|||||||
var err error
|
var err error
|
||||||
for _, rpcNode := range graph.Nodes {
|
for _, rpcNode := range graph.Nodes {
|
||||||
node := &models.Node{
|
node := &models.Node{
|
||||||
HaveNodeAnnouncement: true,
|
|
||||||
LastUpdate: time.Unix(
|
LastUpdate: time.Unix(
|
||||||
int64(rpcNode.LastUpdate), 0,
|
int64(rpcNode.LastUpdate), 0,
|
||||||
),
|
),
|
||||||
Alias: rpcNode.Alias,
|
Alias: rpcNode.Alias,
|
||||||
|
// NOTE: this is a workaround to ensure that
|
||||||
|
// HaveAnnouncement() returns true so that the other
|
||||||
|
// fields are properly persisted. However,
|
||||||
|
AuthSigBytes: []byte{0},
|
||||||
}
|
}
|
||||||
|
|
||||||
node.PubKeyBytes, err = parsePubKey(rpcNode.PubKey)
|
node.PubKeyBytes, err = parsePubKey(rpcNode.PubKey)
|
||||||
|
|||||||
+10
-12
@@ -229,12 +229,11 @@ func parseTestGraph(t *testing.T, useCache bool, path string) (
|
|||||||
}
|
}
|
||||||
|
|
||||||
dbNode := &models.Node{
|
dbNode := &models.Node{
|
||||||
HaveNodeAnnouncement: true,
|
AuthSigBytes: testSig.Serialize(),
|
||||||
AuthSigBytes: testSig.Serialize(),
|
LastUpdate: testTime,
|
||||||
LastUpdate: testTime,
|
Addresses: testAddrs,
|
||||||
Addresses: testAddrs,
|
Alias: node.Alias,
|
||||||
Alias: node.Alias,
|
Features: testFeatures,
|
||||||
Features: testFeatures,
|
|
||||||
}
|
}
|
||||||
copy(dbNode.PubKeyBytes[:], pubBytes)
|
copy(dbNode.PubKeyBytes[:], pubBytes)
|
||||||
|
|
||||||
@@ -566,12 +565,11 @@ func createTestGraphFromChannels(t *testing.T, useCache bool,
|
|||||||
}
|
}
|
||||||
|
|
||||||
dbNode := &models.Node{
|
dbNode := &models.Node{
|
||||||
HaveNodeAnnouncement: true,
|
AuthSigBytes: testSig.Serialize(),
|
||||||
AuthSigBytes: testSig.Serialize(),
|
LastUpdate: testTime,
|
||||||
LastUpdate: testTime,
|
Addresses: testAddrs,
|
||||||
Addresses: testAddrs,
|
Alias: alias,
|
||||||
Alias: alias,
|
Features: features,
|
||||||
Features: features,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
copy(dbNode.PubKeyBytes[:], pubKey.SerializeCompressed())
|
copy(dbNode.PubKeyBytes[:], pubKey.SerializeCompressed())
|
||||||
|
|||||||
+18
-21
@@ -193,13 +193,12 @@ func createTestNode() (*models.Node, error) {
|
|||||||
|
|
||||||
pub := priv.PubKey().SerializeCompressed()
|
pub := priv.PubKey().SerializeCompressed()
|
||||||
n := &models.Node{
|
n := &models.Node{
|
||||||
HaveNodeAnnouncement: true,
|
LastUpdate: time.Unix(updateTime, 0),
|
||||||
LastUpdate: time.Unix(updateTime, 0),
|
Addresses: testAddrs,
|
||||||
Addresses: testAddrs,
|
Color: color.RGBA{1, 2, 3, 0},
|
||||||
Color: color.RGBA{1, 2, 3, 0},
|
Alias: "kek" + string(pub),
|
||||||
Alias: "kek" + string(pub),
|
AuthSigBytes: testSig.Serialize(),
|
||||||
AuthSigBytes: testSig.Serialize(),
|
Features: testFeatures,
|
||||||
Features: testFeatures,
|
|
||||||
}
|
}
|
||||||
copy(n.PubKeyBytes[:], pub)
|
copy(n.PubKeyBytes[:], pub)
|
||||||
|
|
||||||
@@ -2872,26 +2871,24 @@ func TestAddEdgeUnknownVertexes(t *testing.T) {
|
|||||||
// Now check that we can update the node info for the partial node
|
// Now check that we can update the node info for the partial node
|
||||||
// without messing up the channel graph.
|
// without messing up the channel graph.
|
||||||
n1 := &models.Node{
|
n1 := &models.Node{
|
||||||
HaveNodeAnnouncement: true,
|
LastUpdate: time.Unix(123, 0),
|
||||||
LastUpdate: time.Unix(123, 0),
|
Addresses: testAddrs,
|
||||||
Addresses: testAddrs,
|
Color: color.RGBA{1, 2, 3, 0},
|
||||||
Color: color.RGBA{1, 2, 3, 0},
|
Alias: "node11",
|
||||||
Alias: "node11",
|
AuthSigBytes: testSig.Serialize(),
|
||||||
AuthSigBytes: testSig.Serialize(),
|
Features: testFeatures,
|
||||||
Features: testFeatures,
|
|
||||||
}
|
}
|
||||||
copy(n1.PubKeyBytes[:], priv1.PubKey().SerializeCompressed())
|
copy(n1.PubKeyBytes[:], priv1.PubKey().SerializeCompressed())
|
||||||
|
|
||||||
require.NoError(t, ctx.graph.AddNode(ctxb, n1))
|
require.NoError(t, ctx.graph.AddNode(ctxb, n1))
|
||||||
|
|
||||||
n2 := &models.Node{
|
n2 := &models.Node{
|
||||||
HaveNodeAnnouncement: true,
|
LastUpdate: time.Unix(123, 0),
|
||||||
LastUpdate: time.Unix(123, 0),
|
Addresses: testAddrs,
|
||||||
Addresses: testAddrs,
|
Color: color.RGBA{1, 2, 3, 0},
|
||||||
Color: color.RGBA{1, 2, 3, 0},
|
Alias: "node22",
|
||||||
Alias: "node22",
|
AuthSigBytes: testSig.Serialize(),
|
||||||
AuthSigBytes: testSig.Serialize(),
|
Features: testFeatures,
|
||||||
Features: testFeatures,
|
|
||||||
}
|
}
|
||||||
copy(n2.PubKeyBytes[:], priv2.PubKey().SerializeCompressed())
|
copy(n2.PubKeyBytes[:], priv2.PubKey().SerializeCompressed())
|
||||||
|
|
||||||
|
|||||||
@@ -3300,10 +3300,9 @@ func (s *server) createNewHiddenService(ctx context.Context) error {
|
|||||||
// Finally, we'll update the on-disk version of our announcement so it
|
// Finally, we'll update the on-disk version of our announcement so it
|
||||||
// will eventually propagate to nodes in the network.
|
// will eventually propagate to nodes in the network.
|
||||||
selfNode := &models.Node{
|
selfNode := &models.Node{
|
||||||
HaveNodeAnnouncement: true,
|
LastUpdate: time.Unix(int64(newNodeAnn.Timestamp), 0),
|
||||||
LastUpdate: time.Unix(int64(newNodeAnn.Timestamp), 0),
|
Addresses: newNodeAnn.Addresses,
|
||||||
Addresses: newNodeAnn.Addresses,
|
Alias: newNodeAnn.Alias.String(),
|
||||||
Alias: newNodeAnn.Alias.String(),
|
|
||||||
Features: lnwire.NewFeatureVector(
|
Features: lnwire.NewFeatureVector(
|
||||||
newNodeAnn.Features, lnwire.Features,
|
newNodeAnn.Features, lnwire.Features,
|
||||||
),
|
),
|
||||||
@@ -3424,7 +3423,6 @@ func (s *server) updateAndBroadcastSelfNode(ctx context.Context,
|
|||||||
return fmt.Errorf("unable to get current source node: %w", err)
|
return fmt.Errorf("unable to get current source node: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
selfNode.HaveNodeAnnouncement = true
|
|
||||||
selfNode.LastUpdate = time.Unix(int64(newNodeAnn.Timestamp), 0)
|
selfNode.LastUpdate = time.Unix(int64(newNodeAnn.Timestamp), 0)
|
||||||
selfNode.Addresses = newNodeAnn.Addresses
|
selfNode.Addresses = newNodeAnn.Addresses
|
||||||
selfNode.Alias = newNodeAnn.Alias.String()
|
selfNode.Alias = newNodeAnn.Alias.String()
|
||||||
@@ -5646,12 +5644,11 @@ func (s *server) setSelfNode(ctx context.Context, nodePub route.Vertex,
|
|||||||
// TODO(abdulkbk): potentially find a way to use the source node's
|
// TODO(abdulkbk): potentially find a way to use the source node's
|
||||||
// features in the self node.
|
// features in the self node.
|
||||||
selfNode := &models.Node{
|
selfNode := &models.Node{
|
||||||
HaveNodeAnnouncement: true,
|
LastUpdate: nodeLastUpdate,
|
||||||
LastUpdate: nodeLastUpdate,
|
Addresses: addrs,
|
||||||
Addresses: addrs,
|
Alias: nodeAlias.String(),
|
||||||
Alias: nodeAlias.String(),
|
Color: color,
|
||||||
Color: color,
|
Features: s.featureMgr.Get(feature.SetNodeAnn),
|
||||||
Features: s.featureMgr.Get(feature.SetNodeAnn),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
copy(selfNode.PubKeyBytes[:], nodePub[:])
|
copy(selfNode.PubKeyBytes[:], nodePub[:])
|
||||||
|
|||||||
Reference in new issue
Block a user