models: simplify models.Node

Simplify the struct by removing un-used methods and outdated comments.
This commit is contained in:
Elle Mouton authored and yyforyongyu committed 2025-11-12 22:54:04 +08:00
1 parent 93c50bc69a
commit a394938dfd
4 files changed
+13 -39

No files matched your search

+6 -3
View File
@@ -429,7 +429,10 @@ func (d *testDBGraph) addRandChannel(node1, node2 *btcec.PublicKey,
), ),
AuthSigBytes: testSig.Serialize(), AuthSigBytes: testSig.Serialize(),
} }
graphNode.AddPubKey(pub) copy(
graphNode.PubKeyBytes[:],
pub.SerializeCompressed(),
)
err := d.db.AddNode( err := d.db.AddNode(
context.Background(), graphNode, context.Background(), graphNode,
) )
@@ -459,7 +462,7 @@ func (d *testDBGraph) addRandChannel(node1, node2 *btcec.PublicKey,
), ),
AuthSigBytes: testSig.Serialize(), AuthSigBytes: testSig.Serialize(),
} }
dbNode.AddPubKey(nodeKey) copy(dbNode.PubKeyBytes[:], nodeKey.SerializeCompressed())
if err := d.db.AddNode( if err := d.db.AddNode(
context.Background(), dbNode, context.Background(), dbNode,
); err != nil { ); err != nil {
@@ -560,7 +563,7 @@ func (d *testDBGraph) addRandNode() (*btcec.PublicKey, error) {
), ),
AuthSigBytes: testSig.Serialize(), AuthSigBytes: testSig.Serialize(),
} }
dbNode.AddPubKey(nodeKey) copy(dbNode.PubKeyBytes[:], nodeKey.SerializeCompressed())
err = d.db.AddNode(context.Background(), dbNode) err = d.db.AddNode(context.Background(), dbNode)
if err != nil { if err != nil {
return nil, err return nil, err
-22
View File
@@ -7,7 +7,6 @@ import (
"time" "time"
"github.com/btcsuite/btcd/btcec/v2" "github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcec/v2/ecdsa"
"github.com/lightningnetwork/lnd/lnwire" "github.com/lightningnetwork/lnd/lnwire"
) )
@@ -53,11 +52,6 @@ type Node struct {
// and ensure we're able to make upgrades to the network in a forwards // and ensure we're able to make upgrades to the network in a forwards
// compatible manner. // compatible manner.
ExtraOpaqueData []byte ExtraOpaqueData []byte
// TODO(roasbeef): discovery will need storage to keep it's last IP
// address and re-announce if interface changes?
// TODO(roasbeef): add update method and fetch?
} }
// 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
@@ -79,22 +73,6 @@ func (l *Node) PubKey() (*btcec.PublicKey, error) {
return key, nil return key, nil
} }
// AuthSig is a signature under the advertised public key which serves to
// authenticate the attributes announced by this node.
//
// NOTE: By having this method to access an attribute, we ensure we only need
// to fully deserialize the signature if absolutely necessary.
func (l *Node) AuthSig() (*ecdsa.Signature, error) {
return ecdsa.ParseSignature(l.AuthSigBytes)
}
// AddPubKey is a setter-link method that can be used to swap out the public
// key for a node.
func (l *Node) AddPubKey(key *btcec.PublicKey) {
l.pubKey = key
copy(l.PubKeyBytes[:], key.SerializeCompressed())
}
// 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 (l *Node) NodeAnnouncement(signed bool) (*lnwire.NodeAnnouncement1,
error) { error) {
+1 -3
View File
@@ -1250,11 +1250,9 @@ func runPathFindingWithAdditionalEdges(t *testing.T, useCache bool) {
dogePubKeyHex := "03dd46ff29a6941b4a2607525b043ec9b020b3f318a1bf281536fd7011ec59c882" dogePubKeyHex := "03dd46ff29a6941b4a2607525b043ec9b020b3f318a1bf281536fd7011ec59c882"
dogePubKeyBytes, err := hex.DecodeString(dogePubKeyHex) dogePubKeyBytes, err := hex.DecodeString(dogePubKeyHex)
require.NoError(t, err, "unable to decode public key") require.NoError(t, err, "unable to decode public key")
dogePubKey, err := btcec.ParsePubKey(dogePubKeyBytes)
require.NoError(t, err, "unable to parse public key from bytes")
doge := &models.Node{} doge := &models.Node{}
doge.AddPubKey(dogePubKey) copy(doge.PubKeyBytes[:], dogePubKeyBytes[:])
doge.Alias = "doge" doge.Alias = "doge"
copy(doge.PubKeyBytes[:], dogePubKeyBytes) copy(doge.PubKeyBytes[:], dogePubKeyBytes)
graph.aliasMap["doge"] = doge.PubKeyBytes graph.aliasMap["doge"] = doge.PubKeyBytes
+6 -11
View File
@@ -1,7 +1,6 @@
package routing package routing
import ( import (
"github.com/btcsuite/btcd/btcec/v2"
"github.com/lightningnetwork/lnd/fn/v2" "github.com/lightningnetwork/lnd/fn/v2"
"github.com/lightningnetwork/lnd/graph/db/models" "github.com/lightningnetwork/lnd/graph/db/models"
"github.com/lightningnetwork/lnd/htlcswitch" "github.com/lightningnetwork/lnd/htlcswitch"
@@ -102,17 +101,13 @@ func RouteHintsToEdges(routeHints [][]zpay32.HopHint, target route.Vertex) (
// we'll need to look at the next hint's start node. If // we'll need to look at the next hint's start node. If
// we've reached the end of the hints list, we can // we've reached the end of the hints list, we can
// assume we've reached the destination. // assume we've reached the destination.
endNode := &models.Node{} endNode := target
if i != len(routeHint)-1 { if i != len(routeHint)-1 {
endNode.AddPubKey(routeHint[i+1].NodeID) nodeID := routeHint[i+1].NodeID
} else { copy(
targetPubKey, err := btcec.ParsePubKey( endNode[:],
target[:], nodeID.SerializeCompressed(),
) )
if err != nil {
return nil, err
}
endNode.AddPubKey(targetPubKey)
} }
// Finally, create the channel edge from the hop hint // Finally, create the channel edge from the hop hint
@@ -120,7 +115,7 @@ func RouteHintsToEdges(routeHints [][]zpay32.HopHint, target route.Vertex) (
// at the start of the channel. // at the start of the channel.
edgePolicy := &models.CachedEdgePolicy{ edgePolicy := &models.CachedEdgePolicy{
ToNodePubKey: func() route.Vertex { ToNodePubKey: func() route.Vertex {
return endNode.PubKeyBytes return endNode
}, },
ToNodeFeatures: lnwire.EmptyFeatureVector(), ToNodeFeatures: lnwire.EmptyFeatureVector(),
ChannelID: hopHint.ChannelID, ChannelID: hopHint.ChannelID,