Skip to content

Commit

Permalink
Merge pull request lightningnetwork#8779 from bufo24/chore/allow-zero…
Browse files Browse the repository at this point in the history
…-fail-amt-import-mc

Allow 0 failure amt on importmc
  • Loading branch information
guggero authored Jun 3, 2024
2 parents 613bfc0 + 4a3af51 commit d7714ef
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
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

0 comments on commit d7714ef

Please sign in to comment.