-
Notifications
You must be signed in to change notification settings - Fork 104
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
Refactoring XcmExportFeeToSibling and more tests for outbound fee #1109
Changes from 19 commits
3ac5f12
319d4ba
279dbf2
7f7e4bc
4ddca9c
965e579
5fb402b
3894746
8361b26
79f79f1
3fa6fcd
76f4d4f
d359e19
6ca0929
5922a5e
122a5a2
986f19e
c789e69
7514bd1
18daf99
f43fce3
711720c
de03393
85cb976
af15053
122572d
15132aa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
use crate::gwei; | ||
use codec::{Decode, Encode, MaxEncodedLen}; | ||
use scale_info::TypeInfo; | ||
use sp_arithmetic::traits::{BaseArithmetic, Unsigned, Zero}; | ||
use sp_arithmetic::traits::{BaseArithmetic, Unsigned}; | ||
use sp_core::U256; | ||
use sp_runtime::{FixedU128, RuntimeDebug}; | ||
use sp_std::prelude::*; | ||
|
@@ -23,18 +24,20 @@ pub struct Rewards<Balance> { | |
pub remote: U256, | ||
} | ||
|
||
#[derive(RuntimeDebug)] | ||
#[derive(Clone, PartialEq, RuntimeDebug)] | ||
yrong marked this conversation as resolved.
Show resolved
Hide resolved
|
||
pub struct InvalidPricingParameters; | ||
|
||
impl<Balance> PricingParameters<Balance> | ||
where | ||
Balance: BaseArithmetic + Unsigned + Copy, | ||
{ | ||
pub fn validate(&self) -> Result<(), InvalidPricingParameters> { | ||
if self.exchange_rate == FixedU128::zero() { | ||
if self.exchange_rate < FixedU128::from_rational(1, 10000) || | ||
self.exchange_rate > FixedU128::from_rational(1, 1) | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I prefer not to change the validation logic. I also thought about this approach, but ultimately decided it wasn't worth it.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reverted in f43fce3 My only concern is #1109 (comment) but can be avoided by double check before sending the governance call so should be fine. |
||
return Err(InvalidPricingParameters) | ||
} | ||
if self.fee_per_gas == U256::zero() { | ||
if self.fee_per_gas < gwei(1) || self.fee_per_gas > gwei(1000) { | ||
yrong marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return Err(InvalidPricingParameters) | ||
} | ||
if self.rewards.local.is_zero() { | ||
|
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 checks don't make sense to me. The expectation is that
T::GasMeter::maximum_gas_used_at_most
andSelf::calculate_fee
always return correct values for any arbitraryCommand
.This behavior is important, as we can't reject commands because for some reason we could not calculate fees. To do otherwise would lead to a loss of user funds.
It seems these checks are acting as unit tests, and so we should convert them to actual unit tests.
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 check
fee.remote > 0
is for the test case as I mentioned here in #1109 (comment) in which theremote_fee
calculated being zero(though pricing parameters are all non-zero and valid). It will lead to the sovereign account of the sibling chain not being properly refunded inXcmExportFeeToSibling
and finally the agent on the Ethereum side can't be funded.That's also the reason why I introduced the sanity check of the pricing params, prefer to
reject commands because for some reason we could not calculate fees
rather than silently ignoring.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.
MAXIMUM_GAS_CAP
added here is a hard limit that applies to all commands. It's mainly for command Upgrade with a sanityinitializer_max_gas
. It also applies to the future arbitrary transact for which the gas is dynamic from the input of the end-user.MAXIMUM_GAS_CAP
should be consistent with the default relayer config otherwise the check in Gateway will always fail and the bridge stuck.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 Ron, that makes sense. But it seems there is a bug in our code if the calculated remote fee ends up being zero. Can you investigate why this happens? We should try and fix it so that we don't need to have these 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 don't think we should introduce
MAXIMUM_GAS_CAP
, for the same reasons I outlined in #1109 (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.
See #1109 (comment). I think its fine if calculated remote fee is zero. It just means the fee is too low to be represented using DOT decimals.
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.
Checks reverted in af15053