Skip to content

Commit

Permalink
feat(iota-framework): removing storage_fund ability to earn
Browse files Browse the repository at this point in the history
  • Loading branch information
Dkwcs committed Jul 2, 2024
1 parent bfa308f commit 2809508
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 78 deletions.
5 changes: 1 addition & 4 deletions crates/iota-framework/docs/iota-system/iota_system.md
Original file line number Diff line number Diff line change
Expand Up @@ -1362,7 +1362,7 @@ gas coins.
4. Update all validators.


<pre><code><b>fun</b> <a href="iota_system.md#0x3_iota_system_advance_epoch">advance_epoch</a>(storage_reward: <a href="../iota-framework/balance.md#0x2_balance_Balance">balance::Balance</a>&lt;<a href="../iota-framework/iota.md#0x2_iota_IOTA">iota::IOTA</a>&gt;, computation_reward: <a href="../iota-framework/balance.md#0x2_balance_Balance">balance::Balance</a>&lt;<a href="../iota-framework/iota.md#0x2_iota_IOTA">iota::IOTA</a>&gt;, wrapper: &<b>mut</b> <a href="iota_system.md#0x3_iota_system_IotaSystemState">iota_system::IotaSystemState</a>, new_epoch: u64, next_protocol_version: u64, storage_rebate: u64, non_refundable_storage_fee: u64, storage_fund_reinvest_rate: u64, reward_slashing_rate: u64, epoch_start_timestamp_ms: u64, ctx: &<b>mut</b> <a href="../iota-framework/tx_context.md#0x2_tx_context_TxContext">tx_context::TxContext</a>): <a href="../iota-framework/balance.md#0x2_balance_Balance">balance::Balance</a>&lt;<a href="../iota-framework/iota.md#0x2_iota_IOTA">iota::IOTA</a>&gt;
<pre><code><b>fun</b> <a href="iota_system.md#0x3_iota_system_advance_epoch">advance_epoch</a>(storage_reward: <a href="../iota-framework/balance.md#0x2_balance_Balance">balance::Balance</a>&lt;<a href="../iota-framework/iota.md#0x2_iota_IOTA">iota::IOTA</a>&gt;, computation_reward: <a href="../iota-framework/balance.md#0x2_balance_Balance">balance::Balance</a>&lt;<a href="../iota-framework/iota.md#0x2_iota_IOTA">iota::IOTA</a>&gt;, wrapper: &<b>mut</b> <a href="iota_system.md#0x3_iota_system_IotaSystemState">iota_system::IotaSystemState</a>, new_epoch: u64, next_protocol_version: u64, storage_rebate: u64, non_refundable_storage_fee: u64, reward_slashing_rate: u64, epoch_start_timestamp_ms: u64, ctx: &<b>mut</b> <a href="../iota-framework/tx_context.md#0x2_tx_context_TxContext">tx_context::TxContext</a>): <a href="../iota-framework/balance.md#0x2_balance_Balance">balance::Balance</a>&lt;<a href="../iota-framework/iota.md#0x2_iota_IOTA">iota::IOTA</a>&gt;
</code></pre>


Expand All @@ -1379,8 +1379,6 @@ gas coins.
next_protocol_version: u64,
storage_rebate: u64,
non_refundable_storage_fee: 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 <b>to</b> punish a <a href="validator.md#0x3_validator">validator</a>, in bps.
epoch_start_timestamp_ms: u64, // Timestamp of the epoch start
ctx: &<b>mut</b> TxContext,
Expand All @@ -1395,7 +1393,6 @@ gas coins.
computation_reward,
storage_rebate,
non_refundable_storage_fee,
storage_fund_reinvest_rate,
reward_slashing_rate,
epoch_start_timestamp_ms,
ctx,
Expand Down
25 changes: 3 additions & 22 deletions crates/iota-framework/docs/iota-system/iota_system_state_inner.md
Original file line number Diff line number Diff line change
Expand Up @@ -560,12 +560,6 @@ the epoch advancement transaction.
</dt>
<dd>

</dd>
<dt>
<code>storage_fund_reinvestment: u64</code>
</dt>
<dd>

</dd>
<dt>
<code>storage_charge: u64</code>
Expand Down Expand Up @@ -2076,7 +2070,7 @@ gas coins.
4. Update all validators.


<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="iota_system_state_inner.md#0x3_iota_system_state_inner_advance_epoch">advance_epoch</a>(self: &<b>mut</b> <a href="iota_system_state_inner.md#0x3_iota_system_state_inner_IotaSystemStateInnerV2">iota_system_state_inner::IotaSystemStateInnerV2</a>, new_epoch: u64, next_protocol_version: u64, storage_reward: <a href="../iota-framework/balance.md#0x2_balance_Balance">balance::Balance</a>&lt;<a href="../iota-framework/iota.md#0x2_iota_IOTA">iota::IOTA</a>&gt;, computation_reward: <a href="../iota-framework/balance.md#0x2_balance_Balance">balance::Balance</a>&lt;<a href="../iota-framework/iota.md#0x2_iota_IOTA">iota::IOTA</a>&gt;, storage_rebate_amount: u64, non_refundable_storage_fee_amount: u64, storage_fund_reinvest_rate: u64, reward_slashing_rate: u64, epoch_start_timestamp_ms: u64, ctx: &<b>mut</b> <a href="../iota-framework/tx_context.md#0x2_tx_context_TxContext">tx_context::TxContext</a>): <a href="../iota-framework/balance.md#0x2_balance_Balance">balance::Balance</a>&lt;<a href="../iota-framework/iota.md#0x2_iota_IOTA">iota::IOTA</a>&gt;
<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="iota_system_state_inner.md#0x3_iota_system_state_inner_advance_epoch">advance_epoch</a>(self: &<b>mut</b> <a href="iota_system_state_inner.md#0x3_iota_system_state_inner_IotaSystemStateInnerV2">iota_system_state_inner::IotaSystemStateInnerV2</a>, new_epoch: u64, next_protocol_version: u64, storage_reward: <a href="../iota-framework/balance.md#0x2_balance_Balance">balance::Balance</a>&lt;<a href="../iota-framework/iota.md#0x2_iota_IOTA">iota::IOTA</a>&gt;, computation_reward: <a href="../iota-framework/balance.md#0x2_balance_Balance">balance::Balance</a>&lt;<a href="../iota-framework/iota.md#0x2_iota_IOTA">iota::IOTA</a>&gt;, storage_rebate_amount: u64, non_refundable_storage_fee_amount: u64, reward_slashing_rate: u64, epoch_start_timestamp_ms: u64, ctx: &<b>mut</b> <a href="../iota-framework/tx_context.md#0x2_tx_context_TxContext">tx_context::TxContext</a>): <a href="../iota-framework/balance.md#0x2_balance_Balance">balance::Balance</a>&lt;<a href="../iota-framework/iota.md#0x2_iota_IOTA">iota::IOTA</a>&gt;
</code></pre>


Expand All @@ -2093,8 +2087,6 @@ gas coins.
<b>mut</b> computation_reward: Balance&lt;IOTA&gt;,
<b>mut</b> storage_rebate_amount: u64,
<b>mut</b> 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 <b>to</b> punish a <a href="validator.md#0x3_validator">validator</a>, in bps.
epoch_start_timestamp_ms: u64, // Timestamp of the epoch start
ctx: &<b>mut</b> TxContext,
Expand All @@ -2104,11 +2096,7 @@ gas coins.

<b>let</b> bps_denominator_u64 = <a href="iota_system_state_inner.md#0x3_iota_system_state_inner_BASIS_POINT_DENOMINATOR">BASIS_POINT_DENOMINATOR</a> <b>as</b> u64;
// Rates can't be higher than 100%.
<b>assert</b>!(
storage_fund_reinvest_rate &lt;= bps_denominator_u64
&& reward_slashing_rate &lt;= bps_denominator_u64,
<a href="iota_system_state_inner.md#0x3_iota_system_state_inner_EBpsTooLarge">EBpsTooLarge</a>,
);
<b>assert</b>!(reward_slashing_rate &lt;= bps_denominator_u64, <a href="iota_system_state_inner.md#0x3_iota_system_state_inner_EBpsTooLarge">EBpsTooLarge</a>);

// TODO: remove this in later upgrade.
<b>if</b> (self.parameters.stake_subsidy_start_epoch &gt; 0) {
Expand Down Expand Up @@ -2152,11 +2140,6 @@ gas coins.

<b>let</b> storage_fund_reward_amount = storage_fund_balance <b>as</b> u128 * computation_charge_u128 / total_stake_u128;
<b>let</b> <b>mut</b> storage_fund_reward = computation_reward.split(storage_fund_reward_amount <b>as</b> u64);
<b>let</b> storage_fund_reinvestment_amount =
storage_fund_reward_amount * (storage_fund_reinvest_rate <b>as</b> u128) / <a href="iota_system_state_inner.md#0x3_iota_system_state_inner_BASIS_POINT_DENOMINATOR">BASIS_POINT_DENOMINATOR</a>;
<b>let</b> storage_fund_reinvestment = storage_fund_reward.split(
storage_fund_reinvestment_amount <b>as</b> u64,
);

self.epoch = self.epoch + 1;
// Sanity check <b>to</b> make sure we are advancing <b>to</b> the right epoch.
Expand Down Expand Up @@ -2194,11 +2177,10 @@ gas coins.
leftover_staking_rewards.join(computation_reward);
<b>let</b> leftover_storage_fund_inflow = leftover_staking_rewards.value();

self.iota_treasury_cap.supply_mut().decrease_supply(leftover_staking_rewards);
<b>let</b> refunded_storage_rebate =
self.<a href="storage_fund.md#0x3_storage_fund">storage_fund</a>.<a href="iota_system_state_inner.md#0x3_iota_system_state_inner_advance_epoch">advance_epoch</a>(
storage_reward,
storage_fund_reinvestment,
leftover_staking_rewards,
storage_rebate_amount,
non_refundable_storage_fee_amount,
);
Expand All @@ -2210,7 +2192,6 @@ gas coins.
reference_gas_price: self.reference_gas_price,
total_stake: new_total_stake,
storage_charge,
storage_fund_reinvestment: storage_fund_reinvestment_amount <b>as</b> u64,
storage_rebate: storage_rebate_amount,
storage_fund_balance: self.<a href="storage_fund.md#0x3_storage_fund">storage_fund</a>.total_balance(),
stake_subsidy_amount,
Expand Down
15 changes: 3 additions & 12 deletions crates/iota-framework/docs/iota-system/storage_fund.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ Called by <code><a href="iota_system.md#0x3_iota_system">iota_system</a></code>
Called by <code><a href="iota_system.md#0x3_iota_system">iota_system</a></code> at epoch change times to process the inflows and outflows of storage fund.


<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="storage_fund.md#0x3_storage_fund_advance_epoch">advance_epoch</a>(self: &<b>mut</b> <a href="storage_fund.md#0x3_storage_fund_StorageFund">storage_fund::StorageFund</a>, storage_charges: <a href="../iota-framework/balance.md#0x2_balance_Balance">balance::Balance</a>&lt;<a href="../iota-framework/iota.md#0x2_iota_IOTA">iota::IOTA</a>&gt;, storage_fund_reinvestment: <a href="../iota-framework/balance.md#0x2_balance_Balance">balance::Balance</a>&lt;<a href="../iota-framework/iota.md#0x2_iota_IOTA">iota::IOTA</a>&gt;, leftover_staking_rewards: <a href="../iota-framework/balance.md#0x2_balance_Balance">balance::Balance</a>&lt;<a href="../iota-framework/iota.md#0x2_iota_IOTA">iota::IOTA</a>&gt;, storage_rebate_amount: u64, non_refundable_storage_fee_amount: u64): <a href="../iota-framework/balance.md#0x2_balance_Balance">balance::Balance</a>&lt;<a href="../iota-framework/iota.md#0x2_iota_IOTA">iota::IOTA</a>&gt;
<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="storage_fund.md#0x3_storage_fund_advance_epoch">advance_epoch</a>(self: &<b>mut</b> <a href="storage_fund.md#0x3_storage_fund_StorageFund">storage_fund::StorageFund</a>, storage_charges: <a href="../iota-framework/balance.md#0x2_balance_Balance">balance::Balance</a>&lt;<a href="../iota-framework/iota.md#0x2_iota_IOTA">iota::IOTA</a>&gt;, storage_rebate_amount: u64, _non_refundable_storage_fee_amount: u64): <a href="../iota-framework/balance.md#0x2_balance_Balance">balance::Balance</a>&lt;<a href="../iota-framework/iota.md#0x2_iota_IOTA">iota::IOTA</a>&gt;
</code></pre>


Expand All @@ -106,24 +106,15 @@ Called by <code><a href="iota_system.md#0x3_iota_system">iota_system</a></code>
<pre><code><b>public</b>(package) <b>fun</b> <a href="storage_fund.md#0x3_storage_fund_advance_epoch">advance_epoch</a>(
self: &<b>mut</b> <a href="storage_fund.md#0x3_storage_fund_StorageFund">StorageFund</a>,
storage_charges: Balance&lt;IOTA&gt;,
storage_fund_reinvestment: Balance&lt;IOTA&gt;,
leftover_staking_rewards: Balance&lt;IOTA&gt;,
storage_rebate_amount: u64,
non_refundable_storage_fee_amount: u64,
//TODO: try the way <b>to</b> configure
_non_refundable_storage_fee_amount: u64,
) : Balance&lt;IOTA&gt; {
// Both the reinvestment and leftover rewards are not <b>to</b> be refunded so they go <b>to</b> the non-refundable <a href="../iota-framework/balance.md#0x2_balance">balance</a>.
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 <a href="../iota-framework/balance.md#0x2_balance">balance</a>.
<b>let</b> 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` <b>include</b> the already refunded rebates of deleted objects and <b>old</b> rebates of modified objects and
// should be taken out of the `total_object_storage_rebates`.
<b>let</b> storage_rebate = self.total_object_storage_rebates.split(storage_rebate_amount);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -545,8 +545,6 @@ module iota_system::iota_system {
next_protocol_version: u64,
storage_rebate: u64,
non_refundable_storage_fee: 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,
Expand All @@ -561,7 +559,6 @@ module iota_system::iota_system {
computation_reward,
storage_rebate,
non_refundable_storage_fee,
storage_fund_reinvest_rate,
reward_slashing_rate,
epoch_start_timestamp_ms,
ctx,
Expand Down Expand Up @@ -750,7 +747,6 @@ module iota_system::iota_system {
computation_charge: u64,
storage_rebate: u64,
non_refundable_storage_fee: u64,
storage_fund_reinvest_rate: u64,
reward_slashing_rate: u64,
epoch_start_timestamp_ms: u64,
ctx: &mut TxContext,
Expand All @@ -765,7 +761,6 @@ module iota_system::iota_system {
next_protocol_version,
storage_rebate,
non_refundable_storage_fee,
storage_fund_reinvest_rate,
reward_slashing_rate,
epoch_start_timestamp_ms,
ctx,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
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.
Expand Down Expand Up @@ -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);
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,
);
Expand All @@ -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,
storage_rebate: storage_rebate_amount,
storage_fund_balance: self.storage_fund.total_balance(),
stake_subsidy_amount,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) : 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ module iota_system::governance_test_utils {
let ctx = scenario.ctx();

let storage_rebate = system_state.advance_epoch_for_testing(
new_epoch, 1, storage_charge, computation_charge, stoarge_rebate, non_refundable_storage_rebate, 0, 0, 0, ctx,
new_epoch, 1, storage_charge, computation_charge, stoarge_rebate, non_refundable_storage_rebate, 0, 0, ctx,
);
test_scenario::return_shared(system_state);
scenario.next_epoch(@0x0);
Expand All @@ -153,7 +153,7 @@ module iota_system::governance_test_utils {
let ctx = scenario.ctx();

let storage_rebate = system_state.advance_epoch_for_testing(
new_epoch, 1, storage_charge * MICROS_PER_IOTA, computation_charge * MICROS_PER_IOTA, 0, 0, 0, reward_slashing_rate, 0, ctx
new_epoch, 1, storage_charge * MICROS_PER_IOTA, computation_charge * MICROS_PER_IOTA, 0, 0, reward_slashing_rate, 0, ctx
);
test_utils::destroy(storage_rebate);
test_scenario::return_shared(system_state);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -996,7 +996,7 @@ module iota_system::iota_system_tests {
let prev_counter = system_state.get_stake_subsidy_distribution_counter();

let rebate = system_state.advance_epoch_for_testing(
new_epoch, 1, 0, 0, 0, 0, 0, 0, prev_epoch_time + epoch_length, scenario.ctx()
new_epoch, 1, 0, 0, 0, 0, 0, prev_epoch_time + epoch_length, scenario.ctx()
);
destroy(rebate);
assert_eq(system_state.get_stake_subsidy_distribution_counter(), prev_counter + (if (should_increment_counter) 1 else 0));
Expand Down
Loading

0 comments on commit 2809508

Please sign in to comment.