-
Notifications
You must be signed in to change notification settings - Fork 2.2k
[g175] refactor: prep for multiple Node versions #10279
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ellemouton
wants to merge
6
commits into
lightningnetwork:0-21-0-staging
Choose a base branch
from
ellemouton:g175Prep2
base: 0-21-0-staging
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e180638
models: simplify models.Node
ellemouton 3cc7a40
multi: remove HaveNodeAnnouncement field from Node
ellemouton 0c162b3
multi: add models.Node V1 constructor
ellemouton 99955c9
graph/db: simplify auth proof and edge info
ellemouton cc6a2c5
graph: remove DB interface
ellemouton 258ca41
graph/db: remove outdated comment
ellemouton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,11 +19,6 @@ type Node struct { | |
| PubKeyBytes [33]byte | ||
| 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 | ||
| // been updated. | ||
| LastUpdate time.Time | ||
|
|
@@ -54,53 +49,60 @@ type Node struct { | |
| ExtraOpaqueData []byte | ||
| } | ||
|
|
||
| // HaveAnnouncement returns true if we have received a node announcement for | ||
| // this node. We determine this by checking if we 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 | ||
| // authenticated any advertisements/updates sent by the node. | ||
| // | ||
| // NOTE: By having this method to access an attribute, we ensure we only need | ||
| // to fully deserialize the pubkey if absolutely necessary. | ||
| func (l *Node) PubKey() (*btcec.PublicKey, error) { | ||
| if l.pubKey != nil { | ||
| return l.pubKey, nil | ||
| func (n *Node) PubKey() (*btcec.PublicKey, error) { | ||
| if n.pubKey != nil { | ||
| return n.pubKey, nil | ||
| } | ||
|
|
||
| key, err := btcec.ParsePubKey(l.PubKeyBytes[:]) | ||
| key, err := btcec.ParsePubKey(n.PubKeyBytes[:]) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| l.pubKey = key | ||
| n.pubKey = key | ||
|
|
||
| return key, nil | ||
| } | ||
|
|
||
| // 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) { | ||
|
|
||
| if !l.HaveNodeAnnouncement { | ||
| if !n.HaveAnnouncement() { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if we add |
||
| 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 { | ||
| return nil, err | ||
| } | ||
|
|
||
| nodeAnn := &lnwire.NodeAnnouncement1{ | ||
| Features: l.Features.RawFeatureVector, | ||
| NodeID: l.PubKeyBytes, | ||
| RGBColor: l.Color, | ||
| Features: n.Features.RawFeatureVector, | ||
| NodeID: n.PubKeyBytes, | ||
| RGBColor: n.Color, | ||
| Alias: alias, | ||
| Addresses: l.Addresses, | ||
| Timestamp: uint32(l.LastUpdate.Unix()), | ||
| ExtraOpaqueData: l.ExtraOpaqueData, | ||
| Addresses: n.Addresses, | ||
| Timestamp: uint32(n.LastUpdate.Unix()), | ||
| ExtraOpaqueData: n.ExtraOpaqueData, | ||
| } | ||
|
|
||
| if !signed { | ||
| return nodeAnn, nil | ||
| } | ||
|
|
||
| sig, err := lnwire.NewSigFromECDSARawSignature(l.AuthSigBytes) | ||
| sig, err := lnwire.NewSigFromECDSARawSignature(n.AuthSigBytes) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
@@ -117,14 +119,13 @@ func NodeFromWireAnnouncement(msg *lnwire.NodeAnnouncement1) *Node { | |
| features := lnwire.NewFeatureVector(msg.Features, lnwire.Features) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: could pass |
||
|
|
||
| return &Node{ | ||
| HaveNodeAnnouncement: true, | ||
| LastUpdate: timestamp, | ||
| Addresses: msg.Addresses, | ||
| PubKeyBytes: msg.NodeID, | ||
| Alias: msg.Alias.String(), | ||
| AuthSigBytes: msg.Signature.ToSignatureBytes(), | ||
| Features: features, | ||
| Color: msg.RGBColor, | ||
| ExtraOpaqueData: msg.ExtraOpaqueData, | ||
| LastUpdate: timestamp, | ||
| Addresses: msg.Addresses, | ||
| PubKeyBytes: msg.NodeID, | ||
| Alias: msg.Alias.String(), | ||
| AuthSigBytes: msg.Signature.ToSignatureBytes(), | ||
| Features: features, | ||
| Color: msg.RGBColor, | ||
| ExtraOpaqueData: msg.ExtraOpaqueData, | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice change 👍
nit:
have