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

BlockRewards: Fix how it handle ED for Staking currency. #1802

Merged
merged 1 commit into from
Apr 16, 2024

Conversation

lemunozm
Copy link
Contributor

@lemunozm lemunozm commented Apr 9, 2024

Description

I guess this comes from the previous upgrade when balance/and currencies force ExistentialDeposit usage.

Issue 1: We're using an ED denominated in CFG for the StakingCurrency. This is not critical if both currencies use the same denomination, but we should use the correct ED for Staking.

Issue 2: Because Staking currencies were not in the asset registry. From orml_tokens perspective, the ED is 0 while from block-rewards perspective it's 1 * MICRO_CFG. I guess this is not a problem for us right now, but it should be fixed to avoid future problems.

@lemunozm lemunozm added I3-annoyance The code behaves as expected, but "expected" is an issue. Q3-medium Can be done with good experience in the language, but little knowledge of the codebase. P5-soon Issue should be addressed soon. crcl-protocol Circle protocol related. labels Apr 9, 2024
@lemunozm lemunozm self-assigned this Apr 9, 2024
@lemunozm lemunozm changed the base branch from main to polkadot-v1.1.0 April 9, 2024 06:27
@lemunozm lemunozm changed the base branch from polkadot-v1.1.0 to it/evm-to-generic April 9, 2024 06:27
Copy link
Contributor Author

@lemunozm lemunozm left a comment

Choose a reason for hiding this comment

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

Not sure if possible, but I guess staking currency should have an ED of 0 to avoid all this issues (and migrations each time we use a new reward system). Also for accounting, because now we have in centrifuge a total issuance of: 13,000,002,000,000,000,000 and I would say 2,000,000,000,000 is ED

<T::Tokens as Mutate<T::AccountId>>::mint_into(
T::StakeCurrencyId::get(),
who,
T::StakeAmount::get().saturating_add(T::ExistentialDeposit::get()),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here, we were using the CFG existential deposit instead of the one from StakeCurrencyId

@@ -81,6 +85,7 @@ where
fn get(currency_id: &CurrencyId) -> Balance {
match currency_id {
CurrencyId::Native => T::ExistentialDeposit::get(),
CurrencyId::Staking(StakingCurrency::BlockRewards) => T::ExistentialDeposit::get(),
Copy link
Contributor Author

@lemunozm lemunozm Apr 9, 2024

Choose a reason for hiding this comment

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

Here we were assuming the ED for StakingCurrency was registered in the orml asset registry or, if not, it was 0. But the value was always T::ExistentialDeposit::get() which maps to 1 * MICRO_CFG.

I maintain the same ED to avoid issues counting the current staking currency issued, but maybe it should ideally contain another value

@lemunozm
Copy link
Contributor Author

lemunozm commented Apr 9, 2024

Not sure if possible, but I guess staking currency should have an ED of 0 to avoid all these issues

From some tests I'm doing, it seems possible. I'm not sure exactly what the problem we had was.

Copy link

codecov bot commented Apr 9, 2024

Codecov Report

Attention: Patch coverage is 50.00000% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 48.53%. Comparing base (79c5800) to head (60c7b28).

Files Patch % Lines
pallets/block-rewards/src/lib.rs 66.66% 1 Missing ⚠️
runtime/common/src/lib.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1802   +/-   ##
=======================================
  Coverage   48.53%   48.53%           
=======================================
  Files         167      167           
  Lines       13311    13314    +3     
=======================================
+ Hits         6460     6462    +2     
- Misses       6851     6852    +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@wischli
Copy link
Contributor

wischli commented Apr 9, 2024

Not sure if possible, but I guess staking currency should have an ED of 0 to avoid all these issues

From some tests I'm doing, it seems possible. I'm not sure exactly what the problem we had was.

AFAIR the Polkadot v0.9.43 update introduced a required ED for all currencies. Beforehand, we did not require ED for any currency but native. Unfortunately, I don't remember whether relying on unit tests was sufficient here or whether the StakingCurrency ED requirement was a result from testing on a local chain. I think though, some unit tests indicated a failure with ED set to 0 because some balance assertions after distributing block rewards were failing.

@lemunozm
Copy link
Contributor Author

lemunozm commented Apr 9, 2024

Mmm... IIRC, when we "discovered" that ED requirement, we didn't have yet CurrencyED type and we were using the balance ExistentialDeposit for all currencies. Which we should't. Maybe for that we encountered that we needed ED != 0.

With some minor modifications, I've got all integration tests passing with ED = 0 for staking. Maybe it deserves after we merge this check if we have any issues in dev/demo if we use ED = 0 for staking.

@lemunozm lemunozm force-pushed the it/evm-to-generic branch 2 times, most recently from 13af112 to b03d7d5 Compare April 16, 2024 05:54
@lemunozm lemunozm changed the base branch from it/evm-to-generic to main April 16, 2024 09:16
@lemunozm lemunozm force-pushed the fix/block-rewards-ed branch from 26db2ff to 60c7b28 Compare April 16, 2024 09:37
@lemunozm
Copy link
Contributor Author

Can I have your approval on this @wischli @mustermeiszer @cdamian ?

Copy link
Contributor

@wischli wischli left a comment

Choose a reason for hiding this comment

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

Reapproving

@lemunozm lemunozm merged commit 56de771 into main Apr 16, 2024
12 checks passed
@lemunozm lemunozm deleted the fix/block-rewards-ed branch April 16, 2024 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crcl-protocol Circle protocol related. I3-annoyance The code behaves as expected, but "expected" is an issue. P5-soon Issue should be addressed soon. Q3-medium Can be done with good experience in the language, but little knowledge of the codebase.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants