-
Notifications
You must be signed in to change notification settings - Fork 2.3k
routing: add mission control import rpc #5061
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
Merged
Roasbeef
merged 3 commits into
lightningnetwork:master
from
carlaKC:4483-importmissioncontrol
Mar 23, 2021
Merged
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "fmt" | ||
| "strconv" | ||
|
|
||
| "github.com/lightningnetwork/lnd/lnrpc/routerrpc" | ||
| "github.com/lightningnetwork/lnd/routing/route" | ||
| "github.com/urfave/cli" | ||
| ) | ||
|
|
||
| const argsStr = "[source node] [dest node] [unix ts seconds] [amount in msat]" | ||
|
|
||
| var importMissionControlCommand = cli.Command{ | ||
| Name: "importmc", | ||
| Category: "Payments", | ||
| Usage: "Import a result to the internal mission control state.", | ||
| ArgsUsage: fmt.Sprintf("importmc %v", argsStr), | ||
| Action: actionDecorator(importMissionControl), | ||
| Flags: []cli.Flag{ | ||
| cli.BoolFlag{ | ||
| Name: "failure", | ||
| Usage: "whether the routing history entry was a failure", | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| func importMissionControl(ctx *cli.Context) error { | ||
| conn := getClientConn(ctx, false) | ||
| defer conn.Close() | ||
|
|
||
| if ctx.NArg() != 4 { | ||
| return fmt.Errorf("please provide args: %v", argsStr) | ||
| } | ||
|
|
||
| args := ctx.Args() | ||
|
|
||
| sourceNode, err := route.NewVertexFromStr(args[0]) | ||
| if err != nil { | ||
| return fmt.Errorf("please provide valid source node: %v", err) | ||
| } | ||
|
|
||
| destNode, err := route.NewVertexFromStr(args[1]) | ||
| if err != nil { | ||
| return fmt.Errorf("please provide valid dest node: %v", err) | ||
| } | ||
|
|
||
| ts, err := strconv.ParseInt(args[2], 10, 64) | ||
| if err != nil { | ||
| return fmt.Errorf("please provide unix timestamp "+ | ||
| "in seconds: %v", err) | ||
| } | ||
|
|
||
| if ts <= 0 { | ||
| return errors.New("please provide positive timestamp") | ||
| } | ||
|
|
||
| amt, err := strconv.ParseInt(args[3], 10, 64) | ||
| if err != nil { | ||
| return fmt.Errorf("please provide amount in msat: %v", err) | ||
| } | ||
|
|
||
| if amt <= 0 { | ||
| return errors.New("amount must be >0") | ||
| } | ||
|
|
||
| client := routerrpc.NewRouterClient(conn) | ||
|
|
||
| importResult := &routerrpc.PairHistory{ | ||
| NodeFrom: sourceNode[:], | ||
| NodeTo: destNode[:], | ||
| History: &routerrpc.PairData{}, | ||
| } | ||
|
|
||
| if ctx.IsSet("failure") { | ||
| importResult.History.FailAmtMsat = amt | ||
| importResult.History.FailTime = ts | ||
| } else { | ||
| importResult.History.SuccessAmtMsat = amt | ||
| importResult.History.SuccessTime = ts | ||
| } | ||
|
|
||
| req := &routerrpc.XImportMissionControlRequest{ | ||
| Pairs: []*routerrpc.PairHistory{ | ||
| importResult, | ||
| }, | ||
| } | ||
|
|
||
| rpcCtx := context.Background() | ||
| _, err = client.XImportMissionControl(rpcCtx, req) | ||
| return err | ||
| } | ||
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
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.
This is very nice, maybe could also add csv import? (Otherwise MC may change if node is busy).
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.
What do you by MC might change?
I was picturing the main use case for bulk-import to be the rpc? Since you can pass the request from
QueryMissionControldirectly in, adding a csv is an extra step. Could add an option to feed the json output in like we do forSendToRouteif we want to do bulk import via cli?