-
Notifications
You must be signed in to change notification settings - Fork 714
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
[Refactor] Combine parameter checking of budget commands #964
Conversation
d07fe95
to
41cbd92
Compare
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.
First of all, thanks for your continuing efforts to improve PIVX code.
The quality of your work is definitely appreciated.
I like the proposed changes (I have a question after code inspection, will test it asap).
One minor thing, I think it would be slightly better (from a styling and performance point of view) to include the following variables (either as references or pointers) directly as arguments in checkBudgetInputs
and parse them there from UniValue& params
:
std::string strProposalName,
std::string strURL,
int nPaymentCount,
int nBlockStart,
CBitcoinAddress address,
CAmount nAmount
It was one thing I was considering; since I don't like pulling them out in the routine, and then pulling them out again. Now that I ponder it more; since the routine is pretty specific to exactly the parameters that are required; it probably does make sense to do that. |
Some thoughts on this particular PR:
Personally, i'm ok with being uber strict on the URL scheme character casing. Saves from having to rely on boost or a locale dependent function, as well as many lines of code. I'm pretty sure that most browsers and URL shortening websites end up with the standard lowercase scheme in a users clipboard when copying, so someone would actually have to go out of their way to end up with all upper or mixed casing in she URL scheme. |
I think it makes sense to have both refactoring and new functionality in the same place, here, given the narrow focus of the PR. Maybe just split the commits. But, after pondering some more, I agree on the other points. |
@random-zebra I brought up the refactor + new functionality issue because I think everyone can agree that refactoring out the duplicate code is a good thing, but the new added functionality here is clearly still controversial and no consensus has been reached on the best way to proceed with it. For this particular situation, it shouldn't be too big of a deal as @CaveSpectre11 is very much active and open to the idea of multiple change requests, but it is good practice (and actually stated in our contributing guidelines) in general to not mix refactorings with functional changes. |
I'm thinking including Http and Https might be beneficial; since a lot of phones make it a hassle to get your first character to not be an uppercase. e..g. boil down to:
And expand on it at a later date if more checking is required. |
I think that if someone is advanced enough to manage to interact with a core wallet's RPC interface from their phone, they can ensure the URL scheme is in standard lowercase themselves :P Also, even phone browsers end up re-writing the URL scheme to standard lowercase when resolving/loading a URL, so copying to a phone's clipboard would still satisfy the all lowercase requirement. |
The code has been following the conversation; so it's pretty much good. What I'll do is push this one for the refactoring; and push the other one for the validateURL (after finding where best to move it), then just do the rebase when the time comes. The remaining question falls on the crash fixes... keep them in here, move them to the other one, or have them as a 3rd PR? |
Yeah I think that since the issue of how best to handle the URL scheme is still in debate, this PR can be changed to include just a code refactor of what currently exists in From there #950 can be retained for the purpose of enforcing whatever method of URL scheme restriction is eventually decided on. Also, to keep things as atomic as possible, yes a new PR can be opened which is specifically to address the crash fix only. |
09a4afd
to
7834c5e
Compare
PR is refactored to be just the refactor ;) |
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.
ACK 7834c5e and tested
getbudgetinfo
[
...
{
"Name": "PR964_testing",
...
"fValid": true
}
]
needs a quick rebase, looks like #951 may have caused a small conflict |
7834c5e
to
983d97a
Compare
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.
ACK 983d97a
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.
ACK 983d97a
983d97a [Refactor] Combine parameter checking of budget commands (Cave Spectre) Pull request description: ### **Release notes** - [Refactor] Move common budget parameter checking code into a function ### **Details** The code in both `preparebudget` and `submitbudget` used the same parameter checking. This pulls that parameter checking and loading into a common routine used by both; for ease of improvements and adjustments to the parameter checking... so the risk of not adjusting them consistently in both routines is removed. ### **Note** The early discussion below is based on a combined PR that addressed this, plus #950 and a PR to be named later. The decision was made to split and focus; so the discussions can be independent of each other and refactor as needed. ACKs for top commit: Fuzzbawls: ACK 983d97a random-zebra: ACK 983d97a Tree-SHA512: a88eb41e06d1936db77f1cd9c4f04360b446c48d27652d57dfd6e4b119140d56e24b24e00e0ac48890cc78d4130f8f688a711f74899f9c9301d1aba22dff5315
7261134 [Review] Convert runtime_error to JSONRPCError (Cave Spectre) f7ac53b [RPC] Correct issues with budget commands (Cave Spectre) Pull request description: ### **Release notes** - [RPC] Fix potential wallet crashes in budget commands - [RPC] Remove unnecessary conditionals in parameter checking of budget commands ### **Details** **wallet segfault** `preparebudget`, invoked before the wallet has fully started, caused a segfault and crashed. This was due to the lack of checking for `pwalletMain` before referencing cs_wallet. This is solved with a throw error to tell the user to try again after the wallet has started. Furthermore; both `preparebudget` and `submitbudget` has a check for `pindexPrev` to conditionalize the assignment of nBlockMin (which references `pindexPrev->nHeight`); however later checks, `pindexPrev->nHeight` is referenced even if the pindexPrev check failed; which would have caused a crash if pindexPrev was NULL. This would occur if `chainActive->Tip()` returns null. Given the logic of `getnextsuperblock`, the check added to preparebudget and submitbudget will generate a throw error if there is no active chain tip. **Remove unnecessary conditionals and code** `pindexPrev` is loaded from `chainActive.Tip()` pindexPrev->nHeight is checked multiple times in the parameter checking. For ease of reading, pindexPrev->nHeight is now saved in a variable as it is used multiple times in the execution of the RPC commands in question. Likewise, two function calls are used to determine the constant length of a budget cycle `Params().GetBudgetCycleBlocks()`; and is used several times. Storing this information in a constant is more efficient then several calls for the information. nBlockMin is determined (the next superblock). However later nNext was defined to be the exact same thing. It's not necessary to build them both. By nature of validating that the chosen budget cycle block is greater than the current block, and validating the number of cycles is greater than zero; the need to check the end of the budget cycle is unnecessary. Having a separate throw message for choosing the wrong block (not a budget block), and specifying a block that has passed is unnecessary. These have been combined so that the user, putting in the wrong block, is informed, in both cases, what the next budget block is. ### **Note** This PR was originally part of #964, but split out to distinguish between these changes and the other's refactoring. ACKs for top commit: random-zebra: ACK 7261134 Fuzzbawls: ACK 7261134 Tree-SHA512: b0ccabae52d02767971104353b48d4efb76926017d7099b52b341d525710aa3a70d343c92c260048bb1c288990a914730a4dd0832578f07e96abb384d628cd4e
Release notes
Details
The code in both
preparebudget
andsubmitbudget
used the same parameter checking. This pulls that parameter checking and loading into a common routine used by both; for ease of improvements and adjustments to the parameter checking... so the risk of not adjusting them consistently in both routines is removed.Note
The early discussion below is based on a combined PR that addressed this, plus #950 and a PR to be named later. The decision was made to split and focus; so the discussions can be independent of each other and refactor as needed.