-
Notifications
You must be signed in to change notification settings - Fork 13
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
feat(iota-framework): storage fund's ability earn staking rewards #959
Changes from 2 commits
2809508
70dfa51
7abeb42
c9a118c
b2fa6ca
19162d0
08a4efd
8ce8447
e09aa98
66c9573
98e1ab7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -207,7 +207,6 @@ module iota_system::iota_system_state_inner { | |
protocol_version: u64, | ||
reference_gas_price: u64, | ||
total_stake: u64, | ||
storage_fund_reinvestment: u64, | ||
storage_charge: u64, | ||
storage_rebate: u64, | ||
storage_fund_balance: u64, | ||
|
@@ -831,8 +830,6 @@ module iota_system::iota_system_state_inner { | |
mut computation_reward: Balance<IOTA>, | ||
mut storage_rebate_amount: u64, | ||
mut non_refundable_storage_fee_amount: u64, | ||
storage_fund_reinvest_rate: u64, // share of storage fund's rewards that's reinvested | ||
// into storage fund, in basis point. | ||
reward_slashing_rate: u64, // how much rewards are slashed to punish a validator, in bps. | ||
epoch_start_timestamp_ms: u64, // Timestamp of the epoch start | ||
ctx: &mut TxContext, | ||
|
@@ -842,11 +839,7 @@ module iota_system::iota_system_state_inner { | |
|
||
let bps_denominator_u64 = BASIS_POINT_DENOMINATOR as u64; | ||
// Rates can't be higher than 100%. | ||
assert!( | ||
storage_fund_reinvest_rate <= bps_denominator_u64 | ||
&& reward_slashing_rate <= bps_denominator_u64, | ||
EBpsTooLarge, | ||
); | ||
assert!(reward_slashing_rate <= bps_denominator_u64, EBpsTooLarge); | ||
|
||
// TODO: remove this in later upgrade. | ||
if (self.parameters.stake_subsidy_start_epoch > 0) { | ||
|
@@ -890,11 +883,6 @@ module iota_system::iota_system_state_inner { | |
|
||
let storage_fund_reward_amount = storage_fund_balance as u128 * computation_charge_u128 / total_stake_u128; | ||
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. @Dkwcs This is the line where the storage fund is earning rewards, this and the following shall be removed. 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. So we have to completely remove the storage_fund_rewards from validators.advance_epoch or replace it with something? 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. In SUI the In IOTA the
Yes, remove it completely. |
||
let mut storage_fund_reward = computation_reward.split(storage_fund_reward_amount as u64); | ||
let storage_fund_reinvestment_amount = | ||
storage_fund_reward_amount * (storage_fund_reinvest_rate as u128) / BASIS_POINT_DENOMINATOR; | ||
let storage_fund_reinvestment = storage_fund_reward.split( | ||
storage_fund_reinvestment_amount as u64, | ||
); | ||
|
||
self.epoch = self.epoch + 1; | ||
// Sanity check to make sure we are advancing to the right epoch. | ||
|
@@ -931,12 +919,11 @@ module iota_system::iota_system_state_inner { | |
let mut leftover_staking_rewards = storage_fund_reward; | ||
leftover_staking_rewards.join(computation_reward); | ||
let leftover_storage_fund_inflow = leftover_staking_rewards.value(); | ||
|
||
|
||
self.iota_treasury_cap.supply_mut().decrease_supply(leftover_staking_rewards); | ||
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. We need to clarify what to do with the leftovers and make a final implementation or add a TODO. 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. In progress 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. This line fails to compile now since 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. Fixed |
||
let refunded_storage_rebate = | ||
self.storage_fund.advance_epoch( | ||
storage_reward, | ||
storage_fund_reinvestment, | ||
leftover_staking_rewards, | ||
storage_rebate_amount, | ||
non_refundable_storage_fee_amount, | ||
); | ||
|
@@ -948,7 +935,6 @@ module iota_system::iota_system_state_inner { | |
reference_gas_price: self.reference_gas_price, | ||
total_stake: new_total_stake, | ||
storage_charge, | ||
storage_fund_reinvestment: storage_fund_reinvestment_amount as u64, | ||
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. Needs to also be removed in 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. We'll create a separate issue for that |
||
storage_rebate: storage_rebate_amount, | ||
storage_fund_balance: self.storage_fund.total_balance(), | ||
stake_subsidy_amount, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,24 +34,15 @@ module iota_system::storage_fund { | |
public(package) fun advance_epoch( | ||
self: &mut StorageFund, | ||
storage_charges: Balance<IOTA>, | ||
storage_fund_reinvestment: Balance<IOTA>, | ||
leftover_staking_rewards: Balance<IOTA>, | ||
storage_rebate_amount: u64, | ||
non_refundable_storage_fee_amount: u64, | ||
//TODO: try the way to configure | ||
_non_refundable_storage_fee_amount: u64, | ||
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. should not be removed? 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 those changes. |
||
) : Balance<IOTA> { | ||
// Both the reinvestment and leftover rewards are not to be refunded so they go to the non-refundable balance. | ||
self.non_refundable_balance.join(storage_fund_reinvestment); | ||
self.non_refundable_balance.join(leftover_staking_rewards); | ||
|
||
// The storage charges for the epoch come from the storage rebate of the new objects created | ||
// and the new storage rebates of the objects modified during the epoch so we put the charges | ||
// into `total_object_storage_rebates`. | ||
self.total_object_storage_rebates.join(storage_charges); | ||
|
||
// Split out the non-refundable portion of the storage rebate and put it into the non-refundable balance. | ||
let non_refundable_storage_fee = self.total_object_storage_rebates.split(non_refundable_storage_fee_amount); | ||
self.non_refundable_balance.join(non_refundable_storage_fee); | ||
|
||
// `storage_rebates` include the already refunded rebates of deleted objects and old rebates of modified objects and | ||
// should be taken out of the `total_object_storage_rebates`. | ||
let storage_rebate = self.total_object_storage_rebates.split(storage_rebate_amount); | ||
|
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 param must also be removed in the call to advance_epoch in
iota_adapter_latest::execution_engine::checked::construct_advance_epoch_pt
(as well as v0, v1, v2).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.
We'll create a separate issue for that
Because of removing of storage_fund_reinvest_rate looks dangerous in some places.
We'll do it separately
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.
If you think it is better to do this in a separate issue, please, add a subtask and implement it based on this branch.
I think we should not merge this branch without removing
storage_fund_reinvest_rate
from the Rust side because our main branch will be broken in this case.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.
Issue - #970
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.
Exactly why I suggested these changes. Without this change and the
SystemEpochInfoEvent
update, the iota-test-validator does not work. The required changes are not huge, so we should do it in this branch, imo, otherwise we cannot merge this PR without breaking our issue 153 branch.Issue 970 deals with multiple things now. I think we simply should do the appropriate changes to the Rust types in this PR, and left 970 deal only with the naming changes. There are lots of variables and fields that contain the
storage_fund
name and those should be updated tostorage_deposit(s)
. So 970 should only be a renaming task, imho, not a logic change.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.
Okay, I'll fix
storage_fund_reinvest_rate
in Rust codeThere 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.
Check it out please