From 4a3af519b84af9a5c6d96b7d4f230d616602f821 Mon Sep 17 00:00:00 2001 From: Bufo Date: Mon, 3 Jun 2024 11:28:26 +0200 Subject: [PATCH] chore: allow 0 failure amount on import mission control --- cmd/lncli/cmd_import_mission_control.go | 5 +++-- docs/release-notes/release-notes-0.18.1.md | 10 ++++++++++ lnrpc/routerrpc/router_server.go | 23 +++++++++++++++------- 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/cmd/lncli/cmd_import_mission_control.go b/cmd/lncli/cmd_import_mission_control.go index 23935753d2..420396322f 100644 --- a/cmd/lncli/cmd_import_mission_control.go +++ b/cmd/lncli/cmd_import_mission_control.go @@ -66,8 +66,9 @@ func importMissionControl(ctx *cli.Context) error { return fmt.Errorf("please provide amount in msat: %w", err) } - if amt <= 0 { - return errors.New("amount must be >0") + // Allow 0 value as failure amount. + if !ctx.IsSet("failure") && amt <= 0 { + return errors.New("success amount must be >0") } client := routerrpc.NewRouterClient(conn) diff --git a/docs/release-notes/release-notes-0.18.1.md b/docs/release-notes/release-notes-0.18.1.md index 742307b5bd..9d48e76c8d 100644 --- a/docs/release-notes/release-notes-0.18.1.md +++ b/docs/release-notes/release-notes-0.18.1.md @@ -27,7 +27,15 @@ # Improvements ## Functional Updates ## RPC Updates + +* [`xImportMissionControl`](https://github.com/lightningnetwork/lnd/pull/8779) + now accepts `0` failure amounts. + ## lncli Updates + +* [`importmc`](https://github.com/lightningnetwork/lnd/pull/8779) now accepts + `0` failure amounts. + ## Code Health ## Breaking Changes ## Performance Improvements @@ -40,3 +48,5 @@ ## Tooling and Documentation # Contributors (Alphabetical Order) + +* Bufo diff --git a/lnrpc/routerrpc/router_server.go b/lnrpc/routerrpc/router_server.go index 090fef0ed5..be9609893f 100644 --- a/lnrpc/routerrpc/router_server.go +++ b/lnrpc/routerrpc/router_server.go @@ -1137,6 +1137,7 @@ func toPairSnapshot(pairResult *PairHistory) (*routing.MissionControlPairSnapsho lnwire.MilliSatoshi(pairResult.History.FailAmtMsat), btcutil.Amount(pairResult.History.FailAmtSat), pairResult.History.FailTime, + true, ) if err != nil { return nil, fmt.Errorf("%v invalid failure: %w", pairPrefix, @@ -1147,6 +1148,7 @@ func toPairSnapshot(pairResult *PairHistory) (*routing.MissionControlPairSnapsho lnwire.MilliSatoshi(pairResult.History.SuccessAmtMsat), btcutil.Amount(pairResult.History.SuccessAmtSat), pairResult.History.SuccessTime, + false, ) if err != nil { return nil, fmt.Errorf("%v invalid success: %w", pairPrefix, @@ -1174,9 +1176,11 @@ func toPairSnapshot(pairResult *PairHistory) (*routing.MissionControlPairSnapsho } // getPair validates the values provided for a mission control result and -// returns the msat amount and timestamp for it. +// returns the msat amount and timestamp for it. `isFailure` can be used to +// default values to 0 instead of returning an error. func getPair(amtMsat lnwire.MilliSatoshi, amtSat btcutil.Amount, - timestamp int64) (lnwire.MilliSatoshi, time.Time, error) { + timestamp int64, isFailure bool) (lnwire.MilliSatoshi, time.Time, + error) { amt, err := getMsatPairValue(amtMsat, amtSat) if err != nil { @@ -1189,16 +1193,21 @@ func getPair(amtMsat lnwire.MilliSatoshi, amtSat btcutil.Amount, ) switch { + // If a timestamp and amount if provided, return those values. case timeSet && amountSet: return amt, time.Unix(timestamp, 0), nil - case timeSet && !amountSet: + // Return an error if it does have a timestamp without an amount, and + // it's not expected to be a failure. + case !isFailure && timeSet && !amountSet: return 0, time.Time{}, errors.New("non-zero timestamp " + - "requires non-zero amount") + "requires non-zero amount for success pairs") - case !timeSet && amountSet: - return 0, time.Time{}, errors.New("non-zero amount requires " + - "non-zero timestamp") + // Return an error if it does have an amount without a timestamp, and + // it's not expected to be a failure. + case !isFailure && !timeSet && amountSet: + return 0, time.Time{}, errors.New("non-zero amount for " + + "success pairs requires non-zero timestamp") default: return 0, time.Time{}, nil