Skip to content
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

Reduce boilerplate in applySteps: #4710

Merged
merged 1 commit into from
Oct 5, 2023

Conversation

seelabs
Copy link
Collaborator

@seelabs seelabs commented Sep 15, 2023

High Level Overview of Change

When a new transactor is added, there are several places in applySteps that need to be modified. This patch refactors the code so only one function needs to be modified.

Type of Change

  • [ x] Refactor (non-breaking change that only restructures code)

@seelabs seelabs requested review from ximinez and mvadari September 15, 2023 15:39
Copy link
Contributor

@nbougalis nbougalis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I like this a lot. It's certainly advanced C++ and some people may go "wha... ?!?" when they read it, but it does make it less error-prone to add new transaction types.

Good job!

src/ripple/app/tx/impl/applySteps.cpp Outdated Show resolved Hide resolved
src/ripple/app/tx/impl/applySteps.cpp Outdated Show resolved Hide resolved
default:
assert(false);
return XRPAmount{0};
return with_txn_type(tx.getTxnType(), [&]<typename T>() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do the view and tx parameters not need to be captured in the lambda?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The [&] will default capture all the needed variables by ref. So view and tx are both captured. This could have been written as [&view, &tx] but there's no reason to call attention to what variables are captured.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On a related note, will the const-ness of these refs be preserved through the lambda? I remember watching a lecture about this a long time ago, but I'm not able to discern it now.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i found some solutions for the const question here: https://stackoverflow.com/questions/3772867/lambda-capture-as-const-reference

Copy link
Collaborator

@mvadari mvadari left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not entirely sure this refactor will play nicely with the plugin code, but it doesn't really hurt anything, because the plugin code can just continue to do what it's doing, with separate code in each of the methods.

@intelliot
Copy link
Collaborator

@seelabs - do you you have an opinion on whether this should go in 2.0 (with XChainBridge and lots of other changes), or wait for 2024?

I hope this is a safe refactor, but you never know ;)

@ckeshava
Copy link
Collaborator

@mvadari What do you mean by plug-in code? Is it a different PR?

@mvadari
Copy link
Collaborator

mvadari commented Sep 25, 2023

@mvadari What do you mean by plug-in code? Is it a different PR?

It will be in a future PR - it's still WIP.

@seelabs
Copy link
Collaborator Author

seelabs commented Sep 26, 2023

@intelliot I don't think we need to delay this. I think we can merge this into the next release.

@intelliot intelliot added the Tech Debt Non-urgent improvements label Sep 26, 2023
@intelliot intelliot added this to the 2.0 milestone Sep 26, 2023
Copy link
Collaborator

@gregtatcam gregtatcam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Nice update! One minor suggestion to consider - change std::enable_if_t in consequences_helper() to requires. It just makes it a bit more readable.

@seelabs
Copy link
Collaborator Author

seelabs commented Oct 2, 2023

Force pushed to resync with my local branch. I also disabled maintainers from pushing to this branch. It's easier for me to track things if I'm the only one who pushes.

@intelliot
Copy link
Collaborator

note: do not merge until after PR author applies Passed label

@seelabs
Copy link
Collaborator Author

seelabs commented Oct 2, 2023

@gregtatcam Nice suggestion! I agree the "requires" is nicer (it's not part of vocabulary yet so reached for enable_if just out of habbit). Fixed in c887c0bfd0 [fold] Use requires clause in place of enable_if. Can you do me a favor and give a thumbs up after you take a quick look so I know it's OK with you.

@gregtatcam
Copy link
Collaborator

@gregtatcam Nice suggestion! I agree the "requires" is nicer (it's not part of vocabulary yet so reached for enable_if just out of habbit). Fixed in c887c0bfd0 [fold] Use requires clause in place of enable_if. Can you do me a favor and give a thumbs up after you take a quick look so I know it's OK with you.

Sure, will do.

Copy link
Collaborator

@gregtatcam gregtatcam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 LGTM

Copy link
Collaborator

@ximinez ximinez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I freakin' love this. Approved as-is.

...But I am going to throw you a curve ball. What do you think of getting rid of the exception type, and using an UnknownTxn placholder transactor instead? To me, the big advantage is that it puts all the error conditions into one place (the class) instead of spread around the catch clauses.

Here's the change: seelabs/rippled@refactor-apply-steps...ximinez:rippled:sd-4710-apply-steps

When a new transactor is added, there are several places in applySteps
that need to be modified. This patch refactors the code so only one
function needs to be modified.
@seelabs
Copy link
Collaborator Author

seelabs commented Oct 5, 2023

@ximinez (I really wish I could respond to top level comment in github). That's an interesting design! It is nice that it gets rid of the try/catch. My biggest objection is it's a non-standard way to handle errors. It's relatively easy to look at the current code and understand what's going on - exceptions mean errors, there's a try/catch block...yeah, yeah, yeah we've seen it a million times. Your design is codes the error as concrete class that returns the correct error code. It's really clever! I kinda like it! But it's also a way of handling errors in a way we don't usually do in rippled. I'm a little hesitant to introduce another error handling mechanism.

Having said all that, I do like what you did. What do you think about getting this in now and maybe do your patch as a later PR? (I'll admit another minor concern is another round of reviews, and I'm trying to get this merged; But that shouldn't be a strong criteria).

@seelabs seelabs force-pushed the refactor-apply-steps branch from c887c0b to 6475511 Compare October 5, 2023 21:03
@seelabs
Copy link
Collaborator Author

seelabs commented Oct 5, 2023

Squashed and rebased onto the latest develop

@seelabs seelabs added the Passed Passed code review & PR owner thinks it's ready to merge. Perf sign-off may still be required. label Oct 5, 2023
ximinez added a commit to ximinez/rippled that referenced this pull request May 1, 2024
ximinez added a commit to ximinez/rippled that referenced this pull request May 7, 2024
sophiax851 pushed a commit to sophiax851/rippled that referenced this pull request Jun 12, 2024
When a new transactor is added, there are several places in applySteps
that need to be modified. This patch refactors the code so only one
function needs to be modified.
ximinez added a commit to ximinez/rippled that referenced this pull request Jul 5, 2024
ximinez added a commit to ximinez/rippled that referenced this pull request Jul 10, 2024
ximinez added a commit to ximinez/rippled that referenced this pull request Jul 19, 2024
ximinez added a commit to ximinez/rippled that referenced this pull request Jul 24, 2024
ximinez added a commit to ximinez/rippled that referenced this pull request Jul 25, 2024
ximinez added a commit to ximinez/rippled that referenced this pull request Jul 29, 2024
ximinez added a commit to ximinez/rippled that referenced this pull request Aug 2, 2024
ximinez added a commit to ximinez/rippled that referenced this pull request Aug 6, 2024
ximinez added a commit to ximinez/rippled that referenced this pull request Aug 9, 2024
ximinez added a commit to ximinez/rippled that referenced this pull request Aug 19, 2024
ximinez added a commit to ximinez/rippled that referenced this pull request Sep 6, 2024
ximinez added a commit to ximinez/rippled that referenced this pull request Sep 11, 2024
ximinez added a commit to ximinez/rippled that referenced this pull request Sep 11, 2024
ximinez added a commit to ximinez/rippled that referenced this pull request Sep 25, 2024
ximinez added a commit to ximinez/rippled that referenced this pull request Oct 15, 2024
ximinez added a commit to ximinez/rippled that referenced this pull request Oct 18, 2024
ximinez added a commit to ximinez/rippled that referenced this pull request Oct 31, 2024
ximinez added a commit to ximinez/rippled that referenced this pull request Nov 4, 2024
ximinez added a commit to ximinez/rippled that referenced this pull request Nov 5, 2024
ximinez added a commit to ximinez/rippled that referenced this pull request Nov 8, 2024
ximinez added a commit to ximinez/rippled that referenced this pull request Nov 13, 2024
ximinez added a commit to ximinez/rippled that referenced this pull request Nov 13, 2024
ximinez added a commit to ximinez/rippled that referenced this pull request Nov 27, 2024
ximinez added a commit to ximinez/rippled that referenced this pull request Dec 4, 2024
ximinez added a commit to ximinez/rippled that referenced this pull request Dec 5, 2024
ximinez added a commit to ximinez/rippled that referenced this pull request Dec 16, 2024
ximinez added a commit to ximinez/rippled that referenced this pull request Dec 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Passed Passed code review & PR owner thinks it's ready to merge. Perf sign-off may still be required. Tech Debt Non-urgent improvements
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

7 participants