mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-02-23 14:40:30 +01:00
autopilot+lnrpc: wire up SetNodeScores RPC to set scores of agent
This commit is contained in:
parent
b23e53ea33
commit
5dabb1ae29
2 changed files with 42 additions and 0 deletions
|
@ -287,3 +287,27 @@ func (m *Manager) QueryHeuristics(nodes []NodeID) (HeuristicScores, error) {
|
||||||
log.Debugf("Querying heuristics for %d nodes", len(n))
|
log.Debugf("Querying heuristics for %d nodes", len(n))
|
||||||
return m.pilot.queryHeuristics(n)
|
return m.pilot.queryHeuristics(n)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetNodeScores is used to set the scores of the given heuristic, if it is
|
||||||
|
// active, and ScoreSettable.
|
||||||
|
func (m *Manager) SetNodeScores(name string, scores map[NodeID]float64) error {
|
||||||
|
// It must be ScoreSettable to be available for external
|
||||||
|
// scores.
|
||||||
|
s, ok := m.cfg.PilotCfg.Heuristic.(ScoreSettable)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("current heuristic doesn't support " +
|
||||||
|
"external scoring")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Heuristic was found, set its node scores.
|
||||||
|
applied, err := s.SetNodeScores(name, scores)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !applied {
|
||||||
|
return fmt.Errorf("heuristic with name %v not found", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
|
@ -220,5 +220,23 @@ func (s *Server) QueryScores(ctx context.Context, in *QueryScoresRequest) (
|
||||||
func (s *Server) SetScores(ctx context.Context,
|
func (s *Server) SetScores(ctx context.Context,
|
||||||
in *SetScoresRequest) (*SetScoresResponse, error) {
|
in *SetScoresRequest) (*SetScoresResponse, error) {
|
||||||
|
|
||||||
|
scores := make(map[autopilot.NodeID]float64)
|
||||||
|
for pubStr, score := range in.Scores {
|
||||||
|
pubHex, err := hex.DecodeString(pubStr)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
pubKey, err := btcec.ParsePubKey(pubHex, btcec.S256())
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
nID := autopilot.NewNodeID(pubKey)
|
||||||
|
scores[nID] = score
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := s.manager.SetNodeScores(in.Heuristic, scores); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
return &SetScoresResponse{}, nil
|
return &SetScoresResponse{}, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue