mirror of
https://github.com/aljazceru/breez-lnd.git
synced 2025-12-18 14:44:22 +01:00
channeldb+routing: add in-memory graph
Adds an in-memory channel graph cache for faster pathfinding. Original PoC by: Joost Jager Co-Authored by: Oliver Gugger
This commit is contained in:
committed by
Oliver Gugger
parent
d6fa912188
commit
369c09be61
@@ -304,6 +304,16 @@ func parseTestGraph(path string) (*testGraphInstance, error) {
|
||||
}
|
||||
}
|
||||
|
||||
aliasForNode := func(node route.Vertex) string {
|
||||
for alias, pubKey := range aliasMap {
|
||||
if pubKey == node {
|
||||
return alias
|
||||
}
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
// With all the vertexes inserted, we can now insert the edges into the
|
||||
// test graph.
|
||||
for _, edge := range g.Edges {
|
||||
@@ -353,10 +363,17 @@ func parseTestGraph(path string) (*testGraphInstance, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
channelFlags := lnwire.ChanUpdateChanFlags(edge.ChannelFlags)
|
||||
isUpdate1 := channelFlags&lnwire.ChanUpdateDirection == 0
|
||||
targetNode := edgeInfo.NodeKey1Bytes
|
||||
if isUpdate1 {
|
||||
targetNode = edgeInfo.NodeKey2Bytes
|
||||
}
|
||||
|
||||
edgePolicy := &channeldb.ChannelEdgePolicy{
|
||||
SigBytes: testSig.Serialize(),
|
||||
MessageFlags: lnwire.ChanUpdateMsgFlags(edge.MessageFlags),
|
||||
ChannelFlags: lnwire.ChanUpdateChanFlags(edge.ChannelFlags),
|
||||
ChannelFlags: channelFlags,
|
||||
ChannelID: edge.ChannelID,
|
||||
LastUpdate: testTime,
|
||||
TimeLockDelta: edge.Expiry,
|
||||
@@ -364,6 +381,10 @@ func parseTestGraph(path string) (*testGraphInstance, error) {
|
||||
MaxHTLC: lnwire.MilliSatoshi(edge.MaxHTLC),
|
||||
FeeBaseMSat: lnwire.MilliSatoshi(edge.FeeBaseMsat),
|
||||
FeeProportionalMillionths: lnwire.MilliSatoshi(edge.FeeRate),
|
||||
Node: &channeldb.LightningNode{
|
||||
Alias: aliasForNode(targetNode),
|
||||
PubKeyBytes: targetNode,
|
||||
},
|
||||
}
|
||||
if err := graph.UpdateEdgePolicy(edgePolicy); err != nil {
|
||||
return nil, err
|
||||
@@ -635,6 +656,11 @@ func createTestGraphFromChannels(testChannels []*testChannel, source string) (
|
||||
channelFlags |= lnwire.ChanUpdateDisabled
|
||||
}
|
||||
|
||||
node2Features := lnwire.EmptyFeatureVector()
|
||||
if node2.testChannelPolicy != nil {
|
||||
node2Features = node2.Features
|
||||
}
|
||||
|
||||
edgePolicy := &channeldb.ChannelEdgePolicy{
|
||||
SigBytes: testSig.Serialize(),
|
||||
MessageFlags: msgFlags,
|
||||
@@ -646,6 +672,11 @@ func createTestGraphFromChannels(testChannels []*testChannel, source string) (
|
||||
MaxHTLC: node1.MaxHTLC,
|
||||
FeeBaseMSat: node1.FeeBaseMsat,
|
||||
FeeProportionalMillionths: node1.FeeRate,
|
||||
Node: &channeldb.LightningNode{
|
||||
Alias: node2.Alias,
|
||||
PubKeyBytes: node2Vertex,
|
||||
Features: node2Features,
|
||||
},
|
||||
}
|
||||
if err := graph.UpdateEdgePolicy(edgePolicy); err != nil {
|
||||
return nil, err
|
||||
@@ -663,6 +694,11 @@ func createTestGraphFromChannels(testChannels []*testChannel, source string) (
|
||||
}
|
||||
channelFlags |= lnwire.ChanUpdateDirection
|
||||
|
||||
node1Features := lnwire.EmptyFeatureVector()
|
||||
if node1.testChannelPolicy != nil {
|
||||
node1Features = node1.Features
|
||||
}
|
||||
|
||||
edgePolicy := &channeldb.ChannelEdgePolicy{
|
||||
SigBytes: testSig.Serialize(),
|
||||
MessageFlags: msgFlags,
|
||||
@@ -674,6 +710,11 @@ func createTestGraphFromChannels(testChannels []*testChannel, source string) (
|
||||
MaxHTLC: node2.MaxHTLC,
|
||||
FeeBaseMSat: node2.FeeBaseMsat,
|
||||
FeeProportionalMillionths: node2.FeeRate,
|
||||
Node: &channeldb.LightningNode{
|
||||
Alias: node1.Alias,
|
||||
PubKeyBytes: node1Vertex,
|
||||
Features: node1Features,
|
||||
},
|
||||
}
|
||||
if err := graph.UpdateEdgePolicy(edgePolicy); err != nil {
|
||||
return nil, err
|
||||
@@ -2980,12 +3021,6 @@ func dbFindPath(graph *channeldb.ChannelGraph,
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer func() {
|
||||
err := routingTx.close()
|
||||
if err != nil {
|
||||
log.Errorf("Error closing db tx: %v", err)
|
||||
}
|
||||
}()
|
||||
|
||||
return findPath(
|
||||
&graphParams{
|
||||
|
||||
Reference in New Issue
Block a user