-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
cmd/commands: add validation for MPP parameters #9238
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -800,6 +800,30 @@ | |
return route, nil | ||
} | ||
|
||
// maybeValidateMPPParams validates that the MPP parameters are compatible with the | ||
// payment amount. It returns an error if the parameters don't allow the full | ||
// payment amount to be sent. | ||
// maybeValidateMPPParams could be enhanced with additional checks | ||
func maybeValidateMPPParams(amt lnwire.MilliSatoshi, maxParts uint32, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think you can just call it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also, i think it may be worth adding a test for this. Perhaps there is an itest we can expand on just to make sure the call to SendPaymentV2 fails as expected |
||
maxShardSize lnwire.MilliSatoshi) error { | ||
|
||
// Early return if MPP is not being used | ||
if maxShardSize == 0 { | ||
return nil | ||
} | ||
|
||
// Calculate maximum possible amount | ||
maxPossibleAmount := lnwire.MilliSatoshi(maxParts) * maxShardSize | ||
|
||
if amt > maxPossibleAmount { | ||
return fmt.Errorf("payment amount %v exceeds maximum possible "+ | ||
"amount %v with max_parts=%v and max_shard_size_msat=%v", | ||
amt, maxPossibleAmount, maxParts, maxShardSize) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// extractIntentFromSendRequest attempts to parse the SendRequest details | ||
// required to dispatch a client from the information presented by an RPC | ||
// client. | ||
|
@@ -1174,7 +1198,11 @@ | |
|
||
payIntent.DestFeatures = features | ||
} | ||
|
||
err = maybeValidateMPPParams( | ||
payIntent.Amount, maxParts, lnwire.MilliSatoshi(rpcPayReq.MaxShardSizeMsat)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: formatting |
||
if err != nil { | ||
return nil, fmt.Errorf("invalid MPP parameters: %v", err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/%v/%w |
||
} | ||
// Do bounds checking with the block padding so the router isn't | ||
// left with a zombie payment in case the user messes up. | ||
err = routing.ValidateCLTVLimit( | ||
|
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.
i dont think we need this last line. Validation functions can always be enhanced - this is implied