Skip to content
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

Allow 0 failure amt on importmc #8779

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions cmd/lncli/cmd_import_mission_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions docs/release-notes/release-notes-0.18.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -40,3 +48,5 @@
## Tooling and Documentation

# Contributors (Alphabetical Order)

* Bufo
23 changes: 16 additions & 7 deletions lnrpc/routerrpc/router_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand Down
Loading