models: simplify models.Node

Simplify the struct by removing un-used methods and outdated comments.
This commit is contained in:
Elle Mouton 2025-09-04 10:27:34 +02:00 committed by yyforyongyu
parent 93c50bc69a
commit a394938dfd
No known key found for this signature in database
GPG key ID: 9BCD95C4FF296868
4 changed files with 13 additions and 39 deletions

View file

@ -429,7 +429,10 @@ func (d *testDBGraph) addRandChannel(node1, node2 *btcec.PublicKey,
),
AuthSigBytes: testSig.Serialize(),
}
graphNode.AddPubKey(pub)
copy(
graphNode.PubKeyBytes[:],
pub.SerializeCompressed(),
)
err := d.db.AddNode(
context.Background(), graphNode,
)
@ -459,7 +462,7 @@ func (d *testDBGraph) addRandChannel(node1, node2 *btcec.PublicKey,
),
AuthSigBytes: testSig.Serialize(),
}
dbNode.AddPubKey(nodeKey)
copy(dbNode.PubKeyBytes[:], nodeKey.SerializeCompressed())
if err := d.db.AddNode(
context.Background(), dbNode,
); err != nil {
@ -560,7 +563,7 @@ func (d *testDBGraph) addRandNode() (*btcec.PublicKey, error) {
),
AuthSigBytes: testSig.Serialize(),
}
dbNode.AddPubKey(nodeKey)
copy(dbNode.PubKeyBytes[:], nodeKey.SerializeCompressed())
err = d.db.AddNode(context.Background(), dbNode)
if err != nil {
return nil, err

View file

@ -7,7 +7,6 @@ import (
"time"
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcec/v2/ecdsa"
"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
// compatible manner.
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
@ -79,22 +73,6 @@ func (l *Node) PubKey() (*btcec.PublicKey, error) {
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.
func (l *Node) NodeAnnouncement(signed bool) (*lnwire.NodeAnnouncement1,
error) {

View file

@ -1250,11 +1250,9 @@ func runPathFindingWithAdditionalEdges(t *testing.T, useCache bool) {
dogePubKeyHex := "03dd46ff29a6941b4a2607525b043ec9b020b3f318a1bf281536fd7011ec59c882"
dogePubKeyBytes, err := hex.DecodeString(dogePubKeyHex)
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.AddPubKey(dogePubKey)
copy(doge.PubKeyBytes[:], dogePubKeyBytes[:])
doge.Alias = "doge"
copy(doge.PubKeyBytes[:], dogePubKeyBytes)
graph.aliasMap["doge"] = doge.PubKeyBytes

View file

@ -1,7 +1,6 @@
package routing
import (
"github.com/btcsuite/btcd/btcec/v2"
"github.com/lightningnetwork/lnd/fn/v2"
"github.com/lightningnetwork/lnd/graph/db/models"
"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've reached the end of the hints list, we can
// assume we've reached the destination.
endNode := &models.Node{}
endNode := target
if i != len(routeHint)-1 {
endNode.AddPubKey(routeHint[i+1].NodeID)
} else {
targetPubKey, err := btcec.ParsePubKey(
target[:],
nodeID := routeHint[i+1].NodeID
copy(
endNode[:],
nodeID.SerializeCompressed(),
)
if err != nil {
return nil, err
}
endNode.AddPubKey(targetPubKey)
}
// 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.
edgePolicy := &models.CachedEdgePolicy{
ToNodePubKey: func() route.Vertex {
return endNode.PubKeyBytes
return endNode
},
ToNodeFeatures: lnwire.EmptyFeatureVector(),
ChannelID: hopHint.ChannelID,