mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-06-28 09:45:25 +02:00
Merge pull request #8779 from bufo24/chore/allow-zero-fail-amt-import-mc
Allow 0 failure amt on importmc
This commit is contained in:
commit
d7714efc88
@ -66,8 +66,9 @@ func importMissionControl(ctx *cli.Context) error {
|
|||||||
return fmt.Errorf("please provide amount in msat: %w", err)
|
return fmt.Errorf("please provide amount in msat: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if amt <= 0 {
|
// Allow 0 value as failure amount.
|
||||||
return errors.New("amount must be >0")
|
if !ctx.IsSet("failure") && amt <= 0 {
|
||||||
|
return errors.New("success amount must be >0")
|
||||||
}
|
}
|
||||||
|
|
||||||
client := routerrpc.NewRouterClient(conn)
|
client := routerrpc.NewRouterClient(conn)
|
||||||
|
@ -27,7 +27,15 @@
|
|||||||
# Improvements
|
# Improvements
|
||||||
## Functional Updates
|
## Functional Updates
|
||||||
## RPC Updates
|
## RPC Updates
|
||||||
|
|
||||||
|
* [`xImportMissionControl`](https://github.com/lightningnetwork/lnd/pull/8779)
|
||||||
|
now accepts `0` failure amounts.
|
||||||
|
|
||||||
## lncli Updates
|
## lncli Updates
|
||||||
|
|
||||||
|
* [`importmc`](https://github.com/lightningnetwork/lnd/pull/8779) now accepts
|
||||||
|
`0` failure amounts.
|
||||||
|
|
||||||
## Code Health
|
## Code Health
|
||||||
## Breaking Changes
|
## Breaking Changes
|
||||||
## Performance Improvements
|
## Performance Improvements
|
||||||
@ -40,3 +48,5 @@
|
|||||||
## Tooling and Documentation
|
## Tooling and Documentation
|
||||||
|
|
||||||
# Contributors (Alphabetical Order)
|
# Contributors (Alphabetical Order)
|
||||||
|
|
||||||
|
* Bufo
|
||||||
|
@ -1137,6 +1137,7 @@ func toPairSnapshot(pairResult *PairHistory) (*routing.MissionControlPairSnapsho
|
|||||||
lnwire.MilliSatoshi(pairResult.History.FailAmtMsat),
|
lnwire.MilliSatoshi(pairResult.History.FailAmtMsat),
|
||||||
btcutil.Amount(pairResult.History.FailAmtSat),
|
btcutil.Amount(pairResult.History.FailAmtSat),
|
||||||
pairResult.History.FailTime,
|
pairResult.History.FailTime,
|
||||||
|
true,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("%v invalid failure: %w", pairPrefix,
|
return nil, fmt.Errorf("%v invalid failure: %w", pairPrefix,
|
||||||
@ -1147,6 +1148,7 @@ func toPairSnapshot(pairResult *PairHistory) (*routing.MissionControlPairSnapsho
|
|||||||
lnwire.MilliSatoshi(pairResult.History.SuccessAmtMsat),
|
lnwire.MilliSatoshi(pairResult.History.SuccessAmtMsat),
|
||||||
btcutil.Amount(pairResult.History.SuccessAmtSat),
|
btcutil.Amount(pairResult.History.SuccessAmtSat),
|
||||||
pairResult.History.SuccessTime,
|
pairResult.History.SuccessTime,
|
||||||
|
false,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("%v invalid success: %w", pairPrefix,
|
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
|
// 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,
|
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)
|
amt, err := getMsatPairValue(amtMsat, amtSat)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -1189,16 +1193,21 @@ func getPair(amtMsat lnwire.MilliSatoshi, amtSat btcutil.Amount,
|
|||||||
)
|
)
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
|
// If a timestamp and amount if provided, return those values.
|
||||||
case timeSet && amountSet:
|
case timeSet && amountSet:
|
||||||
return amt, time.Unix(timestamp, 0), nil
|
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 " +
|
return 0, time.Time{}, errors.New("non-zero timestamp " +
|
||||||
"requires non-zero amount")
|
"requires non-zero amount for success pairs")
|
||||||
|
|
||||||
case !timeSet && amountSet:
|
// Return an error if it does have an amount without a timestamp, and
|
||||||
return 0, time.Time{}, errors.New("non-zero amount requires " +
|
// it's not expected to be a failure.
|
||||||
"non-zero timestamp")
|
case !isFailure && !timeSet && amountSet:
|
||||||
|
return 0, time.Time{}, errors.New("non-zero amount for " +
|
||||||
|
"success pairs requires non-zero timestamp")
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return 0, time.Time{}, nil
|
return 0, time.Time{}, nil
|
||||||
|
Loading…
x
Reference in New Issue
Block a user