-
Notifications
You must be signed in to change notification settings - Fork 73
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
Fix xcmp_fee for automation-time #366
Conversation
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.
@imstar15 can you add comments on this webpage pointing out the core changes of this PR?
- What is the TransactInfo before change? What are the keys and values?
- What is the TransactInfo after? What are the keys and values?
- If any extrinsic interface has changed, please provide screenshots for before and after.
Adding @v9n for a look.
In addition, "This branch is out-of-date with the base branch". Please rebase master. |
We need to keep optimizing the Flow parameter in the transact_info for better functionality. Rather than specifying the flow for a destination, we should specify the supported flows instead(for example, config a supported array for each chain). Most destination could support both flows. In practice, this means that we will have separate extrinsics for each flow. The scheduleXcmpTask function would utilize the Normal flow, while scheduleXcmpTaskThroughProxy would utilize the Alternate flow. By distinguishing between the flows this way, we can achieve more efficient and targeted execution based on each task type’s requirements. Furthermore, it's important to note that the current names, Normal and Alternate, lack clear meaning. The key distinction between them lies in who pays for the fees. In the Normal flow, Turing's sovereign account covers the XCM fee through ReserveAssetDeposited. On the other hand, in the Alternate flow, the user's proxy wallet bears the XCM fee. Another key difference is that the Alternate flow requires the user to pay XCM fees on the receiving end, thereby reducing the required amount of tokens on Turing (we only need to charge for task scheduling). However, whether users truly care about the slight fee difference remains uncertain. You can find detailed instructions for each flow in the following code links: Normal flow instructions Alternate flow instructions While the name "Flow" is acceptable, it's worth considering more descriptive options since these sequences, combinations, or templates have distinct characteristics. I propose renaming the Flow selector to |
Discussed the new flow parametes with Charles, we don’t need the chain storage |
…tinationAssetFeePerSecond
1, What is the TransactInfo before change? What are the keys and values? We have removed TransactInfo storage.
ScheduleXcmpTask run with
Changes:
|
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.
A lot to improve for this code change.
pallets/automation-time/src/mock.rs
Outdated
@@ -50,6 +50,9 @@ pub const NATIVE: CurrencyId = 0; | |||
pub const NATIVE_LOCATION: MultiLocation = MultiLocation { parents: 0, interior: Here }; | |||
pub const FOREIGN_CURRENCY_ID: CurrencyId = 1; | |||
|
|||
pub const FEE_PER_SECOND: u128 = 100_000_000_000; | |||
pub const XCMP_TASK_REF_TIME: u128 = 20_000; |
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.
You need to map the fee_per_second to destination, so we have
dest1: {
weight,
refTime,
assets: [ {token 1, fee per second 1}, {token 2, fee per second 2} ]
}
dest2 ..
and test them.
pallets/automation-time/src/tests.rs
Outdated
AutomationTime::calculate_schedule_fee_amount(&action, execution_count) | ||
.expect("Calculate schedule fee amount should work"); | ||
let expected_schedule_fee_amount = | ||
FEE_PER_SECOND * XCMP_TASK_REF_TIME * (execution_count as u128) / |
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.
action
is what you passed in to the function calculate_schedule_fee_amount. You need to use the variable values within action for calculation, instead of using a separate const variable XCMP_TASK_REF_TIME. XCMP_TASK_REF_TIME is not used in mock.
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.
WEIGHT_REF_TIME_PER_SECOND is a global variable for our chain, so that’s the only constant variable which can be used in this line of validation.
Fee per second is in relation to each destination, you need to mock and to get them by destination.fee_per_second.
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.
If the task is a xcmp task. the weight of the task is a fixed variable.
It is defined here.
It is not calculated based on the data of the task/action.
So, I think it should be fine to define the XCMP_TASK_REF_TIME constant as well.
Ok(()) | ||
} | ||
|
||
/// Withdraw the fee. | ||
fn withdraw_fee(&self) -> Result<(), DispatchError> { | ||
let fee = self.execution_fee.saturating_add(self.xcmp_fee); | ||
let fee = self.schedule_fee_amount.saturating_add(self.execution_fee_amount); |
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.
let fee = self.schedule_fee_amount.saturating_add(self.execution_fee_amount);
we used this line in 2 places can_pay_fee
and withdraw_fee
. even though it's one liner I think it increase the chance of us accidently forgetting to keep sync that logic between the two. Instead, we may turn that single line into a method get_final_fee
or some similar name, to encapsulate the logic of how we calculate the final fee
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.
We will modify the FeeHandler
logic in a later version, so don't worry about it in this PR.
pallets/automation-time/src/tests.rs
Outdated
overall_weight: Weight::from_ref_time(200_000), | ||
schedule_as: Some(delegator_account), | ||
flow: InstructionSequence::PayThroughRemoteDerivativeAccount, | ||
let num_of_execution = 2; |
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.
This function is important. Could we use an arbitrary number such as 15, instead of 2? 2 is too common.
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.
Same applies to the below num_of_execution
values. Maybe just use a random value from 1 to 20.
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 have a couple of minor suggestions but apply to many tests.
pallets/automation-time/src/tests.rs
Outdated
overall_weight: Weight::from_ref_time(200_000), | ||
schedule_as: Some(delegator_account), | ||
flow: InstructionSequence::PayThroughRemoteDerivativeAccount, | ||
let num_of_execution = 2; |
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.
Same applies to the below num_of_execution
values. Maybe just use a random value from 1 to 20.
pallets/automation-time/src/tests.rs
Outdated
), | ||
..XcmpTaskParams::default() | ||
}); | ||
let fee_amount_1 = AutomationTime::calculate_schedule_fee_amount(&action, num_of_execution) |
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.
Please use fee_amount_absolute
instead of fee_amount_1
. The same goes to all _1
and _2
s. What are 1 and 2?
para_id: ParaId, | ||
currency_id: T::CurrencyId, | ||
xcm_asset_location: VersionedMultiLocation, | ||
destination: Box<VersionedMultiLocation>, |
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.
@imstar15 could you help add a comment on top of this because they are changed now? they used to be this:
375 /// Schedule a task through XCMP to fire an XCMP message with a provided call.
376 ///
377 /// Before the task can be scheduled the task must past validation checks.
378 /// * The transaction is signed
379 /// * The provided_id's length > 0
380 /// * The times are valid
381 /// * The given asset location is supported
382 ///
383 /// # Parameters
384 /// * `provided_id`: An id provided by the user. This id must be unique for the user.
385 /// * `execution_times`: The list of unix standard times in seconds for when the task should run.
386 /// * `para_id`: Parachain id the XCMP call will be sent to.
387 /// * `currency_id`: The currency in which fees will be paid.
388 /// * `encoded_call`: Call that will be sent via XCMP to the parachain id provided.
389 /// * `encoded_call_weight`: Required weight at most the provided call will take.
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.
Okay, I will update the comment
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 have updated the comment. Please review.
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.
Looks good to me!
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.
lgtm
OAK-blockchain PR: AvaProtocol/OAK-blockchain#366
No description provided.