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

[framework] implement pre active validator and staking #8839

Merged
merged 2 commits into from
Mar 8, 2023

Conversation

emmazzz
Copy link
Contributor

@emmazzz emmazzz commented Mar 3, 2023

Description

This PR

  • Adds an entry function request_add_validator_candidate that adds an address as a validator candidate (aka preactive valdiator)
  • Modifies request_add_validator to be only callable by someone who has already registered as a candidate and enforces the minimum stake requirement
  • Adds support for delegation and undelegation for preactive staking pools

Test Plan

Added tests for preactive validators for scenarios including
- request_add_validator_candidate fails because already signed up as candidate
- request_add_validator_candidate fails because duplicate with an active validator
- request_add_validator_candidate fails because validator metadata is invalid
- request_add_validator fails because min stake threshold is not met
- request_add_delegation to a preactive validator, and withdraws when it's still preactive,
within the same epoch and a few epochs later
- request_add_delegation to a preactive validator, and withdraw should fail after the preactive
validator becomes pending (i.e., called request_add_validator but epoch hasn't changed yet).
- request_add_delegation to a preactive validator, and withdraw after it becomes active
- request_add_delegation to a preactive validator, and withdraw after it becomes inactive


If your changes are not user-facing and not a breaking change, you can skip the following section. Otherwise, please indicate what changed, and then add to the Release Notes section as highlighted during the release process.

Type of Change (Check all that apply)

  • user-visible impact
  • breaking change for a client SDKs
  • breaking change for FNs (FN binary must upgrade)
  • breaking change for validators or node operators (must upgrade binaries)
  • breaking change for on-chain data layout
  • necessitate either a data wipe or data migration

Release notes

@vercel
Copy link

vercel bot commented Mar 3, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

3 Ignored Deployments
Name Status Preview Comments Updated
explorer ⬜️ Ignored (Inspect) Visit Preview Mar 8, 2023 at 1:42AM (UTC)
explorer-storybook ⬜️ Ignored (Inspect) Visit Preview Mar 8, 2023 at 1:42AM (UTC)
wallet-adapter ⬜️ Ignored (Inspect) Visit Preview Mar 8, 2023 at 1:42AM (UTC)

@emmazzz emmazzz force-pushed the preactive branch 2 times, most recently from fff8c11 to a8b2417 Compare March 6, 2023 00:41
@vercel vercel bot temporarily deployed to Preview – explorer-storybook March 6, 2023 00:42 Inactive
@vercel vercel bot temporarily deployed to Preview – wallet-adapter March 6, 2023 00:43 Inactive
@vercel vercel bot temporarily deployed to Preview – explorer-storybook March 6, 2023 04:51 Inactive
@vercel vercel bot temporarily deployed to Preview – wallet-adapter March 6, 2023 04:52 Inactive
@emmazzz emmazzz changed the title preactive staking pool [framework] implement pre active validator and staking Mar 6, 2023
@vercel vercel bot temporarily deployed to Preview – wallet-adapter March 6, 2023 07:12 Inactive
@vercel vercel bot temporarily deployed to Preview – explorer-storybook March 6, 2023 07:14 Inactive
@vercel vercel bot temporarily deployed to Preview – wallet-adapter March 6, 2023 07:18 Inactive
@vercel vercel bot temporarily deployed to Preview – explorer-storybook March 6, 2023 07:19 Inactive
@vercel vercel bot temporarily deployed to Preview – explorer-storybook March 6, 2023 07:21 Inactive
@vercel vercel bot temporarily deployed to Preview – wallet-adapter March 6, 2023 07:21 Inactive
@emmazzz emmazzz marked this pull request as ready for review March 6, 2023 07:23
Copy link
Contributor

@tzakian tzakian left a comment

Choose a reason for hiding this comment

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

Overall looks good! Left a couple comments and some small nits.

crates/sui-framework/sources/governance/staking_pool.move Outdated Show resolved Hide resolved
crates/sui-framework/sources/governance/staking_pool.move Outdated Show resolved Hide resolved
option::fill(&mut pool.activation_epoch, activation_epoch);
}

public(friend) fun request_withdraw_delegation_preactive(
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be cleaner if this were combined with request_withdraw_delegation?

I'm thinking: if withdraw_rewards_and_burn_pool_tokens returns zero if the pool is preactive (/the pool token exchange rate at the given epoch doesn't exist) then this should fit in with the logic that already exists there?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was torn between these two options too. We could directly use the request_withdraw_delegation that's already there and as you said the rewards will just be a zero balance. But then we are making undelegation from a preactive pool unnecessarily expensive...

crates/sui-framework/sources/governance/staking_pool.move Outdated Show resolved Hide resolved
crates/sui-framework/sources/governance/staking_pool.move Outdated Show resolved Hide resolved
crates/sui-framework/sources/governance/staking_pool.move Outdated Show resolved Hide resolved

let tx_data = TransactionData::new_move_call_with_dummy_gas_price(
sender,
// Step 1: Add the new node as a validator candidate.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lxfind Do you see this validator joining flow being used in other future tests too? If so I'll put the three steps in a helper fun

@emmazzz emmazzz force-pushed the preactive branch 2 times, most recently from 3a2a87f to c39a911 Compare March 7, 2023 05:49
@emmazzz emmazzz requested a review from tzakian March 7, 2023 07:19
@emmazzz emmazzz requested review from 666lcz and bmwill March 7, 2023 17:40
option::none(),
gas_price,
commission_rate,
0, // start operating right away at epoch 0
true, // validator is active right away
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would like your review on the special casing we are doing here for genesis validators @bmwill. Genesis validators' staking pools are activated right away with some initial stake, while validators joining after genesis will have to start with empty preactive pools and follow the steps to activate their pools.

Copy link
Contributor

Choose a reason for hiding this comment

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

sounds good to me

min_validator_stake: u64,
/// Maximum number of validator candidates at any moment.
/// We do not allow the number of validators in any epoch to go above this.
max_validator_candidate_count: u64,
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the reason to limit the number of candidates?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This limit is on the number of active validators. Will update the comments to reflect that.

@@ -185,21 +185,11 @@ module sui::sui_system {
p2p_address: vector<u8>,
primary_address: vector<u8>,
worker_address: vector<u8>,
stake: Coin<SUI>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we sure we don't want any lower bound on self-stake for non-genesis validators who are trying to join?

Copy link
Contributor

@bmwill bmwill left a comment

Choose a reason for hiding this comment

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

changes wrt genesis look good to me

option::none(),
gas_price,
commission_rate,
0, // start operating right away at epoch 0
true, // validator is active right away
Copy link
Contributor

Choose a reason for hiding this comment

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

sounds good to me

@@ -110,15 +115,65 @@ module sui::validator_set {

// ==== functions to add or remove validators ====

/// Called by `sui_system`, add a new validator to `pending_validators`, which will be
/// Called by `sui_system` to add a new validator candidate.
public(friend) fun request_add_validator_candidate(self: &mut ValidatorSet, validator: Validator) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have a limit on the number of candidates or only on the limit of active validators?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't want or need to have a limit on the number of candidates (people who sign up to have empty staking pools) I believe. The limit is just on active validators.

@emmazzz emmazzz force-pushed the preactive branch 2 times, most recently from d2cd3a7 to 75e2e5d Compare March 7, 2023 22:53
@emmazzz emmazzz enabled auto-merge (squash) March 8, 2023 01:44
@emmazzz emmazzz merged commit 4189171 into MystenLabs:main Mar 8, 2023
@emmazzz emmazzz deleted the preactive branch March 8, 2023 02:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants