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

Fees in community currency #190

Merged
merged 39 commits into from Apr 4, 2022
Merged

Fees in community currency #190

merged 39 commits into from Apr 4, 2022

Conversation

pifragile
Copy link
Contributor

@pifragile pifragile commented Mar 30, 2022

Fot the node integration see encointer/encointer-node#194

Comment on lines 13 to 19
fn name(asset: &Self::AssetId) -> Vec<u8> {
PalletString::from("Encointer").into()
}

fn symbol(asset: &Self::AssetId) -> Vec<u8> {
PalletString::from("ETR").into()
}
Copy link
Member

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::*;
Copy link
Member

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. :)

Copy link
Contributor Author

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 :)

@@ -696,6 +701,83 @@ impl<T: Config> Pallet<T> {
}
}

pub type OnChargeTransactionOf<T> = <T as pallet_transaction_payment::Config>::OnChargeTransaction;
Copy link
Member

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?

Copy link
Member

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.

Copy link
Member

@clangenb clangenb Mar 31, 2022

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

communities/Cargo.toml Outdated Show resolved Hide resolved
balances/src/lib.rs Outdated Show resolved Hide resolved
Comment on lines 58 to 59
((fungible_balance << 64) >> 64) as f64 / (10i128.pow(decimals as u32) as f64),
);
Copy link
Member

@clangenb clangenb Mar 31, 2022

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. :)

Copy link
Member

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

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),
Copy link
Member

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.

Copy link
Member

@clangenb clangenb Apr 2, 2022

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.

Copy link
Member

@clangenb clangenb left a 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.

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;
Copy link
Member

@brenzi brenzi Apr 2, 2022

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

Copy link
Member

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

Copy link
Contributor Author

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.

Copy link
Member

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

Copy link
Contributor Author

@pifragile pifragile Apr 4, 2022

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?

Copy link
Member

@brenzi brenzi left a 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

@brenzi brenzi merged commit 80442d3 into master Apr 4, 2022
@clangenb clangenb deleted the fees-in-community-currency branch April 5, 2022 20:49
brenzi pushed a commit to encointer/encointer-node that referenced this pull request Apr 10, 2022
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants