Skip to content

Commit

Permalink
fix advance epoch specs
Browse files Browse the repository at this point in the history
  • Loading branch information
emmazzz committed Dec 20, 2022
1 parent 00ce6f1 commit 9e88b26
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 18 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ expression: common_costs_estimate
---
{
"MergeCoin": {
"computation_cost": 6236,
"storage_cost": 9208,
"computation_cost": 6243,
"storage_cost": 9218,
"storage_rebate": 0
},
"Publish": {
"computation_cost": 7029,
"storage_cost": 10312,
"computation_cost": 7035,
"storage_cost": 10322,
"storage_rebate": 0
},
"SharedCounterAssertValue": {
Expand All @@ -29,8 +29,8 @@ expression: common_costs_estimate
"storage_rebate": 0
},
"SplitCoin": {
"computation_cost": 6214,
"storage_cost": 9175,
"computation_cost": 6221,
"storage_cost": 9185,
"storage_rebate": 0
},
"TransferPortionSuiCoin": {
Expand Down
26 changes: 26 additions & 0 deletions crates/sui-framework/docs/stake_subsidy.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- [Function `create`](#0x2_stake_subsidy_create)
- [Function `advance_epoch`](#0x2_stake_subsidy_advance_epoch)
- [Function `withdraw_all`](#0x2_stake_subsidy_withdraw_all)
- [Function `current_epoch_subsidy_amount`](#0x2_stake_subsidy_current_epoch_subsidy_amount)


<pre><code><b>use</b> <a href="balance.md#0x2_balance">0x2::balance</a>;
Expand Down Expand Up @@ -178,4 +179,29 @@ Withdraw all the minted stake subsidy.



</details>

<a name="0x2_stake_subsidy_current_epoch_subsidy_amount"></a>

## Function `current_epoch_subsidy_amount`

Returns the amount of stake subsidy to be added at the end of the current epoch.


<pre><code><b>public</b> <b>fun</b> <a href="stake_subsidy.md#0x2_stake_subsidy_current_epoch_subsidy_amount">current_epoch_subsidy_amount</a>(subsidy: &<a href="stake_subsidy.md#0x2_stake_subsidy_StakeSubsidy">stake_subsidy::StakeSubsidy</a>): u64
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="stake_subsidy.md#0x2_stake_subsidy_current_epoch_subsidy_amount">current_epoch_subsidy_amount</a>(subsidy: &<a href="stake_subsidy.md#0x2_stake_subsidy_StakeSubsidy">StakeSubsidy</a>): u64 {
subsidy.current_epoch_amount
}
</code></pre>



</details>
4 changes: 2 additions & 2 deletions crates/sui-framework/docs/sui_system.md
Original file line number Diff line number Diff line change
Expand Up @@ -883,11 +883,11 @@ gas coins.
<summary>Specification</summary>


Total supply of SUI shouldn't change.
Total supply of SUI increases by the amount of stake subsidy we minted.


<pre><code><b>ensures</b> <a href="balance.md#0x2_balance_supply_value">balance::supply_value</a>(self.sui_supply)
== <b>old</b>(<a href="balance.md#0x2_balance_supply_value">balance::supply_value</a>(self.sui_supply));
== <b>old</b>(<a href="balance.md#0x2_balance_supply_value">balance::supply_value</a>(self.sui_supply)) + <b>old</b>(<a href="stake_subsidy.md#0x2_stake_subsidy_current_epoch_subsidy_amount">stake_subsidy::current_epoch_subsidy_amount</a>(self.<a href="stake_subsidy.md#0x2_stake_subsidy">stake_subsidy</a>));
</code></pre>


Expand Down
5 changes: 5 additions & 0 deletions crates/sui-framework/sources/governance/stake_subsidy.move
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,9 @@ module sui::stake_subsidy {
let amount = balance::value(&subsidy.balance);
balance::split(&mut subsidy.balance, amount)
}

/// Returns the amount of stake subsidy to be added at the end of the current epoch.
public fun current_epoch_subsidy_amount(subsidy: &StakeSubsidy): u64 {
subsidy.current_epoch_amount
}
}
4 changes: 2 additions & 2 deletions crates/sui-framework/sources/governance/sui_system.move
Original file line number Diff line number Diff line change
Expand Up @@ -427,9 +427,9 @@ module sui::sui_system {
}

spec advance_epoch {
/// Total supply of SUI shouldn't change.
/// Total supply of SUI increases by the amount of stake subsidy we minted.
ensures balance::supply_value(self.sui_supply)
== old(balance::supply_value(self.sui_supply));
== old(balance::supply_value(self.sui_supply)) + old(stake_subsidy::current_epoch_subsidy_amount(self.stake_subsidy));
}

/// Return the current epoch number. Useful for applications that need a coarse-grained concept of time,
Expand Down
33 changes: 27 additions & 6 deletions crates/sui-open-rpc/spec/openrpc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4468,6 +4468,29 @@
"BLS12381"
]
},
"StakeSubsidy": {
"type": "object",
"required": [
"balance",
"current_epoch_amount",
"epoch_counter"
],
"properties": {
"balance": {
"$ref": "#/components/schemas/Balance"
},
"current_epoch_amount": {
"type": "integer",
"format": "uint64",
"minimum": 0.0
},
"epoch_counter": {
"type": "integer",
"format": "uint64",
"minimum": 0.0
}
}
},
"StakingPool": {
"description": "Rust version of the Move sui::staking_pool::StakingPool type",
"type": "object",
Expand Down Expand Up @@ -5082,9 +5105,9 @@
"chain_id",
"epoch",
"info",
"next_epoch_stake_subsidy",
"parameters",
"reference_gas_price",
"stake_subsidy",
"storage_fund",
"treasury_cap",
"validator_report_records",
Expand All @@ -5102,11 +5125,6 @@
"info": {
"$ref": "#/components/schemas/UID"
},
"next_epoch_stake_subsidy": {
"type": "integer",
"format": "uint64",
"minimum": 0.0
},
"parameters": {
"$ref": "#/components/schemas/SystemParameters"
},
Expand All @@ -5115,6 +5133,9 @@
"format": "uint64",
"minimum": 0.0
},
"stake_subsidy": {
"$ref": "#/components/schemas/StakeSubsidy"
},
"storage_fund": {
"$ref": "#/components/schemas/Balance"
},
Expand Down
2 changes: 1 addition & 1 deletion crates/test-utils/src/sui_system_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use sui_types::crypto::{
use sui_types::id::UID;
use sui_types::sui_system_state::SystemParameters;
use sui_types::sui_system_state::{
StakingPool, StakeSubsidy, SuiSystemState, Validator, ValidatorMetadata, ValidatorSet,
StakeSubsidy, StakingPool, SuiSystemState, Validator, ValidatorMetadata, ValidatorSet,
};
use sui_types::SUI_SYSTEM_STATE_OBJECT_ID;

Expand Down

0 comments on commit 9e88b26

Please sign in to comment.