-
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?
cmd/commands: add validation for MPP parameters #9238
Conversation
Important Review skippedAuto reviews are limited to specific labels. 🏷️ Labels to auto review (1)
Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Thanks for the contribution @anibilthare 🙏
I think this validation should be the routerrpc
though so that it can be applied no matter the interface being used :)
cmd/commands/cmd_payments.go
Outdated
// Validate maxShardSize | ||
if maxShardSize <= 0 { | ||
return fmt.Errorf("max_shard_size must be positive, got %v", maxShardSize) | ||
} | ||
|
||
// Validate maxParts | ||
if maxParts <= 0 { | ||
return fmt.Errorf("max_parts must be positive, got %v", maxParts) | ||
} |
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.
these are both unsigned integers. So they cannot be negative
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.
also note that we treat 0 for maxParts
as just the "default" which will later be replaced by 16. So 0 does not mean that MPP is not being used. Only not setting maxShardSize
(ie, leaving it at 0) results in MPP not being used.
cmd/commands/cmd_payments.go
Outdated
if err != nil { | ||
return status.Errorf(codes.InvalidArgument, | ||
"invalid MPP parameters: %v", err) | ||
} |
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.
note that this only applies validation if used via the CLI. I think we want the validation to apply regardless of how SendPayment is being called. I think a better place for this validation is thus here:
lnd/lnrpc/routerrpc/router_backend.go
Lines 851 to 867 in 684041b
// Attempt to parse the max parts value set by the user, if this value | |
// isn't set, then we'll use the current default value for this | |
// setting. | |
maxParts := rpcPayReq.MaxParts | |
if maxParts == 0 { | |
maxParts = DefaultMaxParts | |
} | |
payIntent.MaxParts = maxParts | |
// If this payment had a max shard amount specified, then we'll apply | |
// that now, which'll force us to always make payment splits smaller | |
// than this. | |
if rpcPayReq.MaxShardSizeMsat > 0 { | |
shardAmtMsat := lnwire.MilliSatoshi(rpcPayReq.MaxShardSizeMsat) | |
payIntent.MaxShardAmt = &shardAmtMsat | |
} |
Adds validation to ensure that the combination of max_parts and max_shard_size_msat parameters can accommodate the full payment amount before attempting the payment. This prevents payments from entering a path finding loop that would eventually timeout when parameters are incompatible.
d630dcc
to
2de5713
Compare
Thanks @ellemouton ! Done |
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.
thanks @anibilthare 🙏
note that the commit title is now out of date. Also, see the failing linter CI check & missing release notes check
// 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 comment
The reason will be displayed to describe this comment to others. Learn more.
i think you can just call it validateMPPParams
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.
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
@@ -1174,7 +1198,11 @@ func (r *RouterBackend) extractIntentFromSendRequest( | |||
|
|||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
nit: formatting
err = maybeValidateMPPParams( | ||
payIntent.Amount, maxParts, lnwire.MilliSatoshi(rpcPayReq.MaxShardSizeMsat)) | ||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
s/%v/%w
// 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 |
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
@anibilthare, remember to re-request review from reviewers when ready |
Fixes 8916
Change Description
Adds validation to ensure that the combination of max_parts and max_shard_size_msat parameters can accommodate the full payment amount before attempting the payment. This prevents payments from entering a path finding loop that would eventually timeout when parameters are incompatible.
Steps to Test