mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-29 15:11:09 +02:00
autopilot: continue threading context
Remove one context.TODO and add one more.
This commit is contained in:
@@ -169,8 +169,8 @@ func betweennessCentrality(g *SimpleGraph, s int, centrality []float64) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Refresh recalculates and stores centrality values.
|
// Refresh recalculates and stores centrality values.
|
||||||
func (bc *BetweennessCentrality) Refresh(graph ChannelGraph) error {
|
func (bc *BetweennessCentrality) Refresh(ctx context.Context,
|
||||||
ctx := context.TODO()
|
graph ChannelGraph) error {
|
||||||
|
|
||||||
cache, err := NewSimpleGraph(ctx, graph)
|
cache, err := NewSimpleGraph(ctx, graph)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
package autopilot
|
package autopilot
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@@ -30,6 +31,9 @@ func TestBetweennessCentralityMetricConstruction(t *testing.T) {
|
|||||||
|
|
||||||
// Tests that empty graph results in empty centrality result.
|
// Tests that empty graph results in empty centrality result.
|
||||||
func TestBetweennessCentralityEmptyGraph(t *testing.T) {
|
func TestBetweennessCentralityEmptyGraph(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
ctx := context.Background()
|
||||||
|
|
||||||
centralityMetric, err := NewBetweennessCentralityMetric(1)
|
centralityMetric, err := NewBetweennessCentralityMetric(1)
|
||||||
require.NoError(
|
require.NoError(
|
||||||
t, err,
|
t, err,
|
||||||
@@ -42,7 +46,7 @@ func TestBetweennessCentralityEmptyGraph(t *testing.T) {
|
|||||||
require.NoError(t, err, "unable to create graph")
|
require.NoError(t, err, "unable to create graph")
|
||||||
|
|
||||||
success := t.Run(chanGraph.name, func(t1 *testing.T) {
|
success := t.Run(chanGraph.name, func(t1 *testing.T) {
|
||||||
err = centralityMetric.Refresh(graph)
|
err = centralityMetric.Refresh(ctx, graph)
|
||||||
require.NoError(t1, err)
|
require.NoError(t1, err)
|
||||||
|
|
||||||
centrality := centralityMetric.GetMetric(false)
|
centrality := centralityMetric.GetMetric(false)
|
||||||
@@ -59,6 +63,9 @@ func TestBetweennessCentralityEmptyGraph(t *testing.T) {
|
|||||||
|
|
||||||
// Test betweenness centrality calculating using an example graph.
|
// Test betweenness centrality calculating using an example graph.
|
||||||
func TestBetweennessCentralityWithNonEmptyGraph(t *testing.T) {
|
func TestBetweennessCentralityWithNonEmptyGraph(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
ctx := context.Background()
|
||||||
|
|
||||||
workers := []int{1, 3, 9, 100}
|
workers := []int{1, 3, 9, 100}
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
@@ -100,7 +107,7 @@ func TestBetweennessCentralityWithNonEmptyGraph(t *testing.T) {
|
|||||||
t1, graph, centralityTestGraph,
|
t1, graph, centralityTestGraph,
|
||||||
)
|
)
|
||||||
|
|
||||||
err = metric.Refresh(graph)
|
err = metric.Refresh(ctx, graph)
|
||||||
require.NoError(t1, err)
|
require.NoError(t1, err)
|
||||||
|
|
||||||
for _, expected := range tests {
|
for _, expected := range tests {
|
||||||
|
@@ -157,7 +157,7 @@ type NodeMetric interface {
|
|||||||
Name() string
|
Name() string
|
||||||
|
|
||||||
// Refresh refreshes the metric values based on the current graph.
|
// Refresh refreshes the metric values based on the current graph.
|
||||||
Refresh(graph ChannelGraph) error
|
Refresh(ctx context.Context, graph ChannelGraph) error
|
||||||
|
|
||||||
// GetMetric returns the latest value of this metric. Values in the
|
// GetMetric returns the latest value of this metric. Values in the
|
||||||
// map are per node and can be in arbitrary domain. If normalize is
|
// map are per node and can be in arbitrary domain. If normalize is
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
package autopilot
|
package autopilot
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
"github.com/btcsuite/btcd/btcutil"
|
"github.com/btcsuite/btcd/btcutil"
|
||||||
@@ -54,8 +55,10 @@ func (g *TopCentrality) NodeScores(graph ChannelGraph, chans []LocalChannel,
|
|||||||
chanSize btcutil.Amount, nodes map[NodeID]struct{}) (
|
chanSize btcutil.Amount, nodes map[NodeID]struct{}) (
|
||||||
map[NodeID]*NodeScore, error) {
|
map[NodeID]*NodeScore, error) {
|
||||||
|
|
||||||
|
ctx := context.TODO()
|
||||||
|
|
||||||
// Calculate betweenness centrality for the whole graph.
|
// Calculate betweenness centrality for the whole graph.
|
||||||
if err := g.centralityMetric.Refresh(graph); err != nil {
|
if err := g.centralityMetric.Refresh(ctx, graph); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -6857,7 +6857,7 @@ func (r *rpcServer) GetNodeMetrics(ctx context.Context,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if err := centralityMetric.Refresh(channelGraph); err != nil {
|
if err := centralityMetric.Refresh(ctx, channelGraph); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user