From a394938dfd6067acf9a63be2da1009d1ea6740e7 Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Thu, 4 Sep 2025 10:27:34 +0200 Subject: [PATCH] models: simplify models.Node Simplify the struct by removing un-used methods and outdated comments. --- autopilot/prefattach_test.go | 9 ++++++--- graph/db/models/node.go | 22 ---------------------- routing/pathfind_test.go | 4 +--- routing/payment_session_source.go | 17 ++++++----------- 4 files changed, 13 insertions(+), 39 deletions(-) diff --git a/autopilot/prefattach_test.go b/autopilot/prefattach_test.go index 70f7e2b68..d93cda230 100644 --- a/autopilot/prefattach_test.go +++ b/autopilot/prefattach_test.go @@ -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 diff --git a/graph/db/models/node.go b/graph/db/models/node.go index 23d6a4268..d67aa4b7e 100644 --- a/graph/db/models/node.go +++ b/graph/db/models/node.go @@ -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) { diff --git a/routing/pathfind_test.go b/routing/pathfind_test.go index 77bad02e3..4414aa1c0 100644 --- a/routing/pathfind_test.go +++ b/routing/pathfind_test.go @@ -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 diff --git a/routing/payment_session_source.go b/routing/payment_session_source.go index bc1088d7b..15820059d 100644 --- a/routing/payment_session_source.go +++ b/routing/payment_session_source.go @@ -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,