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

[sui system] SIP-39 (reroll) #21303

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ public fun later_epoch(
next_epoch(scenario, sender)
}

/// Advance the scenario to `epoch`
public fun set_epoch(scenario: &mut Scenario, epoch: u64) {
scenario.ctx.set_epoch(epoch)
}

/// Ends the test scenario
/// Returns the results from the final transaction
/// Will abort if shared or immutable objects were deleted, transferred, or wrapped.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ const EBadTxHashLength: u64 = 0;
/// Attempt to get the most recent created object ID when none has been created.
const ENoIDsCreated: u64 = 1;

#[test_only]
/// Attempt to set the epoch number to a value less than the current epoch number.
const EEpochCantGoBackward: u64 = 2;

/// Information about the transaction currently being executed.
/// This cannot be constructed by a transaction--it is a privileged object created by
/// the VM and passed in to the entrypoint of the transaction as `&mut TxContext`.
Expand Down Expand Up @@ -139,3 +143,9 @@ public fun increment_epoch_number(self: &mut TxContext) {
public fun increment_epoch_timestamp(self: &mut TxContext, delta_ms: u64) {
self.epoch_timestamp_ms = self.epoch_timestamp_ms + delta_ms
}

#[test_only]
public fun set_epoch(self: &mut TxContext, epoch: u64) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we call this advance_epoch? since it can't go backwards

Copy link
Contributor

Choose a reason for hiding this comment

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

We have APIs that should help address this already in test_scenario. I would vote we continue to use those and not build out competing APIs

assert!(epoch >= self.epoch, EEpochCantGoBackward);
self.epoch = epoch
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
module sui_system::sui_system;

use sui::balance::Balance;

use sui::coin::Coin;
use sui_system::staking_pool::{StakedSui, FungibleStakedSui};
use sui::sui::SUI;
Expand Down Expand Up @@ -710,11 +709,10 @@ public fun set_epoch_for_testing(wrapper: &mut SuiSystemState, epoch_num: u64) {
#[test_only]
public fun request_add_validator_for_testing(
wrapper: &mut SuiSystemState,
min_joining_stake_for_testing: u64,
ctx: &TxContext,
) {
let self = load_system_state_mut(wrapper);
self.request_add_validator_for_testing(min_joining_stake_for_testing, ctx)
self.request_add_validator_for_testing(ctx)
}

#[test_only]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,22 @@ public struct SystemParameters has store {
/// The starting epoch in which stake subsidies start being paid out
stake_subsidy_start_epoch: u64,

/// Deprecated.
/// Maximum number of active validators at any moment.
/// We do not allow the number of validators in any epoch to go above this.
max_validator_count: u64,

/// Deprecated.
/// Lower-bound on the amount of stake required to become a validator.
min_validator_joining_stake: u64,

// Deprecated.
/// Validators with stake amount below `validator_low_stake_threshold` are considered to
/// have low stake and will be escorted out of the validator set after being below this
/// threshold for more than `validator_low_stake_grace_period` number of epochs.
validator_low_stake_threshold: u64,

/// Deprecated.
/// Validators with stake below `validator_very_low_stake_threshold` will be removed
/// immediately at epoch change, no grace period.
validator_very_low_stake_threshold: u64,
Expand All @@ -72,18 +76,22 @@ public struct SystemParametersV2 has store {
/// Minimum number of active validators at any moment.
min_validator_count: u64,

/// Deprecated.
/// Maximum number of active validators at any moment.
/// We do not allow the number of validators in any epoch to go above this.
max_validator_count: u64,

/// Deprecated.
/// Lower-bound on the amount of stake required to become a validator.
min_validator_joining_stake: u64,

/// Deprecated.
/// Validators with stake amount below `validator_low_stake_threshold` are considered to
/// have low stake and will be escorted out of the validator set after being below this
/// threshold for more than `validator_low_stake_grace_period` number of epochs.
validator_low_stake_threshold: u64,

/// Deprecated.
/// Validators with stake below `validator_very_low_stake_threshold` will be removed
/// immediately at epoch change, no grace period.
validator_very_low_stake_threshold: u64,
Expand Down Expand Up @@ -407,12 +415,7 @@ public(package) fun request_add_validator(
self: &mut SuiSystemStateInnerV2,
ctx: &TxContext,
) {
assert!(
self.validators.next_epoch_validator_count() < self.parameters.max_validator_count,
ELimitExceeded,
);

self.validators.request_add_validator(self.parameters.min_validator_joining_stake, ctx);
self.validators.request_add_validator(ctx);
}

/// A validator can call this function to request a removal in the next epoch.
Expand Down Expand Up @@ -920,8 +923,6 @@ public(package) fun advance_epoch(
&mut storage_fund_reward,
&mut self.validator_report_records,
reward_slashing_rate,
self.parameters.validator_low_stake_threshold,
self.parameters.validator_very_low_stake_threshold,
self.parameters.validator_low_stake_grace_period,
ctx,
);
Expand Down Expand Up @@ -1139,15 +1140,9 @@ public(package) fun set_epoch_for_testing(self: &mut SuiSystemStateInnerV2, epoc
#[test_only]
public(package) fun request_add_validator_for_testing(
self: &mut SuiSystemStateInnerV2,
min_joining_stake_for_testing: u64,
ctx: &TxContext,
) {
assert!(
self.validators.next_epoch_validator_count() < self.parameters.max_validator_count,
ELimitExceeded,
);

self.validators.request_add_validator(min_joining_stake_for_testing, ctx);
self.validators.request_add_validator(ctx);
}

#[test_only]
Expand Down
Loading
Loading