Skip to content
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

routing: use correct fees by searching backwards #1321

Closed
wants to merge 5 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 15 additions & 29 deletions channeldb/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -1836,37 +1836,18 @@ func (l *LightningNode) ForEachChannel(tx *bolt.Tx,
return err
}

outgoingPolicy, err := fetchChanEdgePolicy(
edges, chanID, nodePub, nodes,
)

otherNode, err := edgeInfo.OtherNodeKeyBytes(nodePub)
if err != nil {
return err
}

policy1, policy2, err := fetchChanEdgePolicies(edgeIndex,
edges, nodes, chanID, l.db)

var incomingPolicy, outgoingPolicy *ChannelEdgePolicy

if policy1 != nil {
switch {
case bytes.Equal(nodePub, policy1.Node.PubKeyBytes[:]):
incomingPolicy = policy1
case bytes.Equal(otherNode, policy1.Node.PubKeyBytes[:]):
outgoingPolicy = policy1
default:
return fmt.Errorf("Unexpected node in policy")
}
}

if policy2 != nil {
switch {
case bytes.Equal(nodePub, policy2.Node.PubKeyBytes[:]):
incomingPolicy = policy2
case bytes.Equal(otherNode, policy2.Node.PubKeyBytes[:]):
outgoingPolicy = policy2
default:
return fmt.Errorf("Unexpected node in policy")
}
}
incomingPolicy, err := fetchChanEdgePolicy(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignoring the error here and above.

edges, chanID, otherNode, nodes,
)

// Finally, we execute the callback.
err = cb(tx, &edgeInfo, outgoingPolicy, incomingPolicy)
Expand Down Expand Up @@ -2915,7 +2896,9 @@ func putChanEdgePolicy(edges *bolt.Bucket, edge *ChannelEdgePolicy, from, to []b
// delete the old one to ensure we don't leave around any after-images.
// An unknown policy value does not have a update time recorded, so
// it also does not need to be removed.
if edgeBytes := edges.Get(edgeKey[:]); edgeBytes != nil && !bytes.Equal(edgeBytes[:], unknownPolicy) {
if edgeBytes := edges.Get(edgeKey[:]); edgeBytes != nil &&
!bytes.Equal(edgeBytes[:], unknownPolicy) {

// In order to delete the old entry, we'll need to obtain the
// *prior* update time in order to delete it. To do this, we'll
// create an offset to slice in. Starting backwards, we'll
Expand Down Expand Up @@ -2943,8 +2926,11 @@ func putChanEdgePolicy(edges *bolt.Bucket, edge *ChannelEdgePolicy, from, to []b
return edges.Put(edgeKey[:], b.Bytes()[:])
}

// putChanEdgePolicyUnknown marks the edge policy as unknown in the edges bucket.
func putChanEdgePolicyUnknown(edges *bolt.Bucket, channelID uint64, from []byte) error {
// putChanEdgePolicyUnknown marks the edge policy as unknown
// in the edges bucket.
func putChanEdgePolicyUnknown(edges *bolt.Bucket, channelID uint64,
from []byte) error {

var edgeKey [33 + 8]byte
copy(edgeKey[:], from)
byteOrder.PutUint64(edgeKey[33:], channelID)
Expand Down