-
Notifications
You must be signed in to change notification settings - Fork 1k
Shielded Inflation rewards #1025
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
Conversation
cdfe93e to
ea7bf48
Compare
| self.write( | ||
| &token::balance_key(addr, &masp_addr), | ||
| total_supply_in_masp.try_to_vec().unwrap(), | ||
| ) |
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'm not sure how this gets initialized on chain from the genesis config @brentstone @murisi would either of you know?
|
It seems that currently the |
|
Currently ifailures:
e2e::eth_bridge_tests::everything
e2e::ibc_tests::run_ledger_ibc
e2e::ledger_tests::double_signing_gets_slashed ; timeout
e2e::ledger_tests::implicit_account_reveal_pk
e2e::ledger_tests::invalid_transactions ; timeout
e2e::ledger_tests::ledger_many_txs_in_a_block
e2e::ledger_tests::ledger_txs_and_queries
;; Must be updated to the new rewards
;; "Needle: NAM: 0.2", in the temp file "NAM: 467977.4\r\n"
e2e::ledger_tests::masp_incentives
e2e::ledger_tests::masp_pinned_txs ; passes on rerun (timeout?)
e2e::ledger_tests::masp_txs_and_queries ; passes on rerun (timeout?)
e2e::ledger_tests::pos_bonds
e2e::ledger_tests::pos_init_validator
e2e::ledger_tests::pos_rewards
e2e::ledger_tests::proposal_offline
;; trying to connect: tcp connect error: OS error 111
;; Figure this might be due to a timeout somewhere
e2e::ledger_tests::proposal_submission
e2e::ledger_tests::run_ledger_load_state_and_reset
e2e::ledger_tests::test_genesis_validators ; timeout
e2e::ledger_tests::test_node_connectivity_and_consensus
e2e::wallet_tests::wallet_encrypted_key_cmdsMost of them are due to timeout, rerunning two of them locally has made it pass (likely again due to timeout). With two interesting the first is The other one is Overall, I think the pr should be fit to merge outside of fine tuning |
|
pls update wasm |
831a49a to
84343fd
Compare
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 for the changes! Overall the code looks good (though I've reviewed only your changes, not @brentstone 's). I'm mainly concerned about two and a half things:
- Is the inflation that is minted exactly equal to what is stored in
token::last_inflation(addr)? If it is, then maybe we can make this equivalence clearer in the code... If not, we need to fix the discrepancy lest it subtly affects the PID controller. - The conversion tree code was written under the assumption that no rewards are given for shielded NAM (and hence that no compounding takes place). This was my mistake. Since your code can potentially give rewards for locked NAM (meaning that compounding necessarily happens), the conversion tree code needs to be updated.
- Now that compounding of rewards can take place, we need to add an E2E test for this compounding behavior.
| pub const LOCKED_RATIO_TARGET_KEY: &str = "locked_ratio_target"; | ||
|
|
||
| /// The key for the max reward rate for a given asset | ||
| pub const MAX_REWARD_RATE: &str = "max_reward_rate"; |
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 could instead be named MAX_REWARD_RATE_KEY lest this variable be mistaken for an actual rate. This doesn't matter too much though since the variable's meaning should be clear from context.
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 agree with @murisi here
| pub const MAX_REWARD_RATE: &str = "max_reward_rate"; | |
| pub const MAX_REWARD_RATE_KEY: &str = "max_reward_rate"; |
| // Reward all tokens according to above reward rates | ||
| for (addr, reward) in &masp_rewards { | ||
| for addr in masp_rewards.keys() { | ||
| let reward = calculate_masp_rewards(wl_storage, addr) |
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.
The following code assumes that the reward for locked NAM is 0, i.e. it assumes that compounding doesn't happen. What follows would need to be modified to correctly handle NAM compounding. Something along the lines of deflating NAM_0 rewards, and not handing out NAM_0 rewards for NAM. Probably a test should be added to ensure that compounding happens correctly.
| } | ||
| } | ||
|
|
||
| impl Default for Parameters { |
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.
Maybe a better default would be to have 0 rewards and 0 locked ratio target? I.e. behave like there is no incentive system by default. But I guess this is debatable...
core/src/types/token/parameters.rs
Outdated
| /// Shielded Pool nominal proportional gain for the given token | ||
| kp_gain_nom: Decimal, | ||
| /// Locked ratio for the given token | ||
| locked_ratio_target_key: Decimal, |
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.
Did you instead mean locked_ratio_target? This variable doesn't seem to be a key...
| // Since floor(a) + floor(b) <= floor(a+b), there will always be | ||
| // enough rewards to reimburse users | ||
| total_reward += (addr_bal * *reward).0; | ||
| total_reward += (addr_bal * reward).0; |
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'm not sure that the right-hand-side, (addr_bal * reward).0, equals inflation as computed in calculate_masp_rewards. By the implementation of Mul for Amount, (addr_bal * reward).0=(addr_bal / reward.1)*reward.0=(addr_bal / 100)*(inflation * 100 / total_token_in_masp)=(addr_bal / 100)*(inflation * 100 / addr_bal). Algebraically this should equal inflation, but I suspect the first factor alone, (addr_bal / 100), will introduce rounding errors.
Overall it feels like we are recomputing a value that we already knew/computed before, but in a way that is vulnerable to overflows and rounding errors. Maybe we could move the mint_tokens call from this function into calculate_masp_rewards (where the inflation variable is available)? (Whatever we do with rounding errors, the MASP must always have exactly, or slightly more than enough account balance to redeem shielded conversions/withdrawals...)
13d918e to
8bf245e
Compare
e5d165e to
9ea97ef
Compare
9ea97ef to
38bb6bb
Compare
|
Last commit before merging v0.16.0. Note that the e2e incetives fails, but everything else works |
9bb003e to
a46b699
Compare
a46b699 to
67d9ce5
Compare
|
pls update wasms |
Namada 0.17.5
dd379ce to
5fc78f6
Compare
42998e2 to
31930e4
Compare
- _Changes_
+ We offset the denominations of the tokens by their denomination
relative to the nam token thus a 10^18 token gets offset to 10^6,
which is the base systems denomination
31930e4 to
7b3442b
Compare
| # Portion of a validator's stake that should be slashed on a light | ||
| # client attack. | ||
| light_client_attack_min_slash_rate = "0.001" | ||
| light_client_attack_min_slash_rate = "0.1" |
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 has this been changed in this PR? Not sure I follow?
A followup pr of #714 that adds the inflation rewards for the shielded pool.
The formulas follow from:
https://specs.namada.net/economics/inflation-system.html