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

pallet-utility: if_else #6321

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

rainbow-promise
Copy link

Utility Call Fallback

Resolves #6000

@cla-bot-2021
Copy link

cla-bot-2021 bot commented Oct 31, 2024

User @rainbow-promise, please sign the CLA here.

Copy link
Contributor

@xlc xlc left a comment

Choose a reason for hiding this comment

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

I don't think you understand the requirements clearly because you have implemented batch, not if-else.
the fallback is only executed if and only if the main call failed. if main call successes, do not call fallback

substrate/frame/utility/src/lib.rs Outdated Show resolved Hide resolved
@rainbow-promise
Copy link
Author

rainbow-promise commented Nov 1, 2024

Need to take a closer look at the extrinsic executions, even with the revisions it Is not quit there yet.

@@ -120,6 +120,10 @@ pub mod pallet {
ItemFailed { error: DispatchError },
/// A call was dispatched.
DispatchedAs { result: DispatchResult },
/// one or both if_else calls failed.
IfElseFailure { which: String, error: DispatchError },
Copy link
Contributor

Choose a reason for hiding this comment

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

no string in pallets, the current implementation make it hard for sdk users to figure out the meaning of this
it could be an enum

but I don’t think the current event make sense as there are only 3 possibilities: main success, mail failed + fallback success, all failed
the all failed case should just result the whole call to be failed. ie no extra event. so we only really two event: main success, and fallback called

@rainbow-promise rainbow-promise marked this pull request as ready for review November 6, 2024 16:48
@rainbow-promise rainbow-promise requested a review from a team as a code owner November 6, 2024 16:48
@rainbow-promise
Copy link
Author

please review @xlc @ggwpez

@xlc
Copy link
Contributor

xlc commented Nov 6, 2024

looks fine now. need proper weights

@rainbow-promise
Copy link
Author

I am guessing the weight signature below the pallet index will have some form of condition as well?

@xlc
Copy link
Contributor

xlc commented Nov 7, 2024

use the worst case (i.e. main + fallback). extra weight will be refunded as the actual weight is returned in the call

@rainbow-promise
Copy link
Author

use the worst case (i.e. main + fallback). extra weight will be refunded as the actual weight is returned in the call

this also applies to dispatch class?

@gui1117
Copy link
Contributor

gui1117 commented Nov 7, 2024

use the worst case (i.e. main + fallback). extra weight will be refunded as the actual weight is returned in the call

this also applies to dispatch class?

I would say dispatch class is the lowest class of the 2. if both are operational then it is operational. if one is normal then it is normal. etc.

@rainbow-promise
Copy link
Author

I would say dispatch class is the lowest class of the 2. if both are operational then it is operational. if one is normal then it is normal. etc.

how can one determine the class of a RuntimeCall? if Operational or Normal?

@gui1117
Copy link
Contributor

gui1117 commented Nov 7, 2024

I would say dispatch class is the lowest class of the 2. if both are operational then it is operational. if one is normal then it is normal. etc.

how can one determine the class of a RuntimeCall? if Operational or Normal?

take a look at batch, they do similar operation. You can use get_dispatch_info on the call.

@rainbow-promise
Copy link
Author

Also the kitchensink-runtime has no genesis_config_presets.rs file, using frame-omni-bencher errors out for that runtime because of that.

@rainbow-promise
Copy link
Author

i have added weights to all runtimes containing pallet-utility please review @ggwpez @xlc @gui1117

@rainbow-promise
Copy link
Author

Also the kitchensink-runtime has no genesis_config_presets.rs file, using frame-omni-bencher errors out for that runtime because of that.

Should I raise an issue for this? @xlc @gui1117

let caller = whitelisted_caller();

#[extrinsic_call]
_(RawOrigin::Signed(caller), main_call, fallback_call);
Copy link
Contributor

Choose a reason for hiding this comment

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

The err branch should be slightly more costly, but difference should be negligible so it is ok.

Copy link
Author

Choose a reason for hiding this comment

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

So adjusting with a failed main call will give the proper weights as it enters the else branch? will update this.

Thanks for the review

substrate/frame/utility/src/lib.rs Outdated Show resolved Hide resolved
substrate/frame/utility/src/lib.rs Show resolved Hide resolved
assert_eq!(Balances::free_balance(1), 5);
assert_eq!(Balances::free_balance(2), 15);
});
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe 2 more tests:

  • successful main call.
  • failing else call.

Copy link
Member

@ggwpez ggwpez left a comment

Choose a reason for hiding this comment

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

Looks pretty good now, thanks!

I just put some comments.

prdoc/pr_6321.prdoc Outdated Show resolved Hide resolved
prdoc/pr_6321.prdoc Outdated Show resolved Hide resolved
substrate/frame/utility/src/lib.rs Outdated Show resolved Hide resolved
substrate/frame/utility/src/lib.rs Show resolved Hide resolved
substrate/frame/utility/src/lib.rs Show resolved Hide resolved
@ggwpez ggwpez added the T2-pallets This PR/Issue is related to a particular pallet. label Nov 13, 2024
@paritytech-review-bot paritytech-review-bot bot requested a review from a team November 13, 2024 14:21
@rainbow-promise
Copy link
Author

Need the CI to run some checks @ggwpez 🙏

gui1117
gui1117 previously approved these changes Nov 13, 2024
// Both calls have faild.
Self::deposit_event(Event::IfElseBothFailure { main_error: main_error.error, fallback_error: fallback_error.error });
return Err(Error::<T>::InvalidCalls.into())
Copy link
Contributor

Choose a reason for hiding this comment

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

We can also do the refund in case of failure.

Suggested change
return Err(Error::<T>::InvalidCalls.into())
return Err(DispatchErrorWithPostInfo { error: Error::<T>::InvalidCalls.into(), post_info: Some(weight).into() })

T::WeightInfo::if_else()
.saturating_add(main_dispatch_info.call_weight)
.saturating_add(fallback_dispatch_info.call_weight),
main_dispatch_info.class,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should take the lowest class between main and fallback.

Otherwise somebody can do a call with a failing operational main call. And a fallback with a batch of normal call.

@gui1117 gui1117 self-requested a review November 14, 2024 00:18
@paritytech-review-bot paritytech-review-bot bot requested a review from a team November 14, 2024 00:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T2-pallets This PR/Issue is related to a particular pallet.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Utility if_else call
4 participants