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
Fees in community currency #190
Conversation
balances/src/impl_fungibles.rs
Outdated
fn name(asset: &Self::AssetId) -> Vec<u8> { | ||
PalletString::from("Encointer").into() | ||
} | ||
|
||
fn symbol(asset: &Self::AssetId) -> Vec<u8> { | ||
PalletString::from("ETR").into() | ||
} |
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 should be community currency-specific entries and nod global ones. But this is only information afaik, so it should be fine in our case.
@@ -0,0 +1,180 @@ | |||
use super::*; |
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 left quite a few implementations out compared to the one in assets: https://github.com/paritytech/substrate/blob/master/frame/assets/src/impl_fungibles.rs
On what criteria did you decide? I am asking just out of curiosity. :)
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 just tried to implement the smallest subset necessary for our usecase :)
communities/src/lib.rs
Outdated
@@ -696,6 +701,83 @@ impl<T: Config> Pallet<T> { | |||
} | |||
} | |||
|
|||
pub type OnChargeTransactionOf<T> = <T as pallet_transaction_payment::Config>::OnChargeTransaction; |
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.
Why do you define this one here and not in the encointer-balances pallet?
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.
Ok, I see because of the dependency stuff, hence I propose to define this thing in a separate crate.
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 moved the stuff to the encointer-balances-tx-payment
crate
balances/src/impl_fungibles.rs
Outdated
((fungible_balance << 64) >> 64) as f64 / (10i128.pow(decimals as u32) as f64), | ||
); |
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.
((fungible_balance << 64) >> 64)
I guess this is to truncate, however we might find some higher level function for this. :)
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 is actually the same as fungible_balance as u64
primitives/src/balances.rs
Outdated
let mut result: BalanceType = BalanceType::from_num(0); | ||
|
||
result += BalanceType::from_num( | ||
((fungible_balance << 64) >> 64) as f64 / (10i128.pow(decimals as u32) as f64), |
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 conversions might happen in the runtime. You must never use indeterministic data types there.
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.
Changed to using fixed point types.
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.
Although I had quite a few comments, it looked good in general. I just resolved all the remarks myself due to time-constraints. Don't take it personally. :)
Just a few notes:
- never use floating-point types by stuff that is executed in the runtime. This is not deterministic and will lead to consensus errors.
- you sometimes use quite crazy math-ops. Although they might be very elegant, they are hard to follow. Some more doc there would be nice.
Ready to merge from my point of view. It compiles with the node.
…to be adjusted more freely
…to be adjusted more freely
…ee_conversion_factor`
balances-tx-payment/src/tests.rs
Outdated
use rstest::*; | ||
|
||
/// 1 micro KSM with 12 decimals | ||
const ONE_MICRO_KSM: u128 = 1_000_000; | ||
|
||
/// 1 community currency token with 18 decimals | ||
const ONE_CC: u128 = 1_000_000_000_000_000_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.
I don't get this. If we have BalanceType U64F64 (typecast from u128) this means one cc is 1 << 64
, not 1_000_000_000_000_000_000
This needs more explaining comments, even if the new constants already improve readability
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.
@pifragile Why did you arbitrarily chose to set ONE_CC=1_000_000_000_000_000_000? I get that you tried to pick a number that avoids overflow, but your choice has nothing to do with the real interpretation of "one CC". We don't need a power of 10, we need the "real" ONE_CC.
Or: why didn't you just set ONE_CC: u128 = 1 << 64
? Then we could typecast this value to U64F64 and would really get 1 CC
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.
@brenzi the rationale behind this is that i assumed that fungibles uses a system similar to Ethereum where numbers are represented as a large integer (like 256 or 128 bit) and a given amount of decimals.
See here: https://github.com/paritytech/substrate/blob/ded44948e2d5a398abcb4e342b0513cb690961bb/frame/support/src/traits/tokens/fungibles/metadata.rs#L29
So for example with 5 decimals, the number x
will be represented as x * 10^5
. I chose 18 decimals, hence this number.
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.
Ok, but that confirms my concern. We use fixpoint with a base of 2, not base of 10. Unless you can convince me otherwise, I'd like this changed to
ONE_CC: u128 = 1 << 64
throughout
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 only works if no client of the balances pallet ever uses the decimals
field, because we will obviously not be able to put a value in that field if we use your apporach. i will do some research. what is the reason you would like to change this? to avoid the conversions between base 2 / base 10 numbers?
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.
as requested in comments
This is the node integration of encointer/pallets#190 this only solves the node part. the client doesn't support CC fees yet. (left for #195 to do)
Fot the node integration see encointer/encointer-node#194