Skip to content

Commit

Permalink
[sui-system] add voting power to epoch info event (#10124)
Browse files Browse the repository at this point in the history
## Description 

We should include the voting power of validators in emitted events too.

## Test Plan 

How did you test the new or updated feature?

---
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
  • Loading branch information
emmazzz authored Mar 31, 2023
1 parent 456f1b3 commit 97b411a
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 2 deletions.
92 changes: 91 additions & 1 deletion crates/sui-framework/docs/validator_set.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

- [Struct `ValidatorSet`](#0x3_validator_set_ValidatorSet)
- [Struct `ValidatorEpochInfoEvent`](#0x3_validator_set_ValidatorEpochInfoEvent)
- [Struct `ValidatorEpochInfoEventV2`](#0x3_validator_set_ValidatorEpochInfoEventV2)
- [Struct `ValidatorJoinEvent`](#0x3_validator_set_ValidatorJoinEvent)
- [Struct `ValidatorLeaveEvent`](#0x3_validator_set_ValidatorLeaveEvent)
- [Constants](#@Constants_0)
Expand Down Expand Up @@ -256,6 +257,94 @@ each validator, emitted during epoch advancement.
</dl>


</details>

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

## Struct `ValidatorEpochInfoEventV2`

V2 of ValidatorEpochInfoEvent containing more information about the validator.


<pre><code><b>struct</b> <a href="validator_set.md#0x3_validator_set_ValidatorEpochInfoEventV2">ValidatorEpochInfoEventV2</a> <b>has</b> <b>copy</b>, drop
</code></pre>



<details>
<summary>Fields</summary>


<dl>
<dt>
<code>epoch: u64</code>
</dt>
<dd>

</dd>
<dt>
<code>validator_address: <b>address</b></code>
</dt>
<dd>

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

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

</dd>
<dt>
<code><a href="voting_power.md#0x3_voting_power">voting_power</a>: u64</code>
</dt>
<dd>

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

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

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

</dd>
<dt>
<code>pool_token_exchange_rate: <a href="staking_pool.md#0x3_staking_pool_PoolTokenExchangeRate">staking_pool::PoolTokenExchangeRate</a></code>
</dt>
<dd>

</dd>
<dt>
<code>tallying_rule_reporters: <a href="">vector</a>&lt;<b>address</b>&gt;</code>
</dt>
<dd>

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

</dd>
</dl>


</details>

<a name="0x3_validator_set_ValidatorJoinEvent"></a>
Expand Down Expand Up @@ -2606,11 +2695,12 @@ including stakes, rewards, performance, etc.
<b>if</b> (<a href="_contains">vector::contains</a>(slashed_validators, &validator_address)) 0
<b>else</b> 1;
<a href="_emit">event::emit</a>(
<a href="validator_set.md#0x3_validator_set_ValidatorEpochInfoEvent">ValidatorEpochInfoEvent</a> {
<a href="validator_set.md#0x3_validator_set_ValidatorEpochInfoEventV2">ValidatorEpochInfoEventV2</a> {
epoch: new_epoch,
validator_address,
reference_gas_survey_quote: <a href="validator.md#0x3_validator_gas_price">validator::gas_price</a>(v),
stake: <a href="validator.md#0x3_validator_total_stake_amount">validator::total_stake_amount</a>(v),
<a href="voting_power.md#0x3_voting_power">voting_power</a>: <a href="validator.md#0x3_validator_voting_power">validator::voting_power</a>(v),
commission_rate: <a href="validator.md#0x3_validator_commission_rate">validator::commission_rate</a>(v),
pool_staking_reward: *<a href="_borrow">vector::borrow</a>(pool_staking_reward_amounts, i),
storage_fund_staking_reward: *<a href="_borrow">vector::borrow</a>(storage_fund_staking_reward_amounts, i),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,21 @@ module sui_system::validator_set {
tallying_rule_global_score: u64,
}

/// V2 of ValidatorEpochInfoEvent containing more information about the validator.
struct ValidatorEpochInfoEventV2 has copy, drop {
epoch: u64,
validator_address: address,
reference_gas_survey_quote: u64,
stake: u64,
voting_power: u64,
commission_rate: u64,
pool_staking_reward: u64,
storage_fund_staking_reward: u64,
pool_token_exchange_rate: PoolTokenExchangeRate,
tallying_rule_reporters: vector<address>,
tallying_rule_global_score: u64,
}

/// Event emitted every time a new validator joins the committee.
/// The epoch value corresponds to the first epoch this change takes place.
struct ValidatorJoinEvent has copy, drop {
Expand Down Expand Up @@ -1176,11 +1191,12 @@ module sui_system::validator_set {
if (vector::contains(slashed_validators, &validator_address)) 0
else 1;
event::emit(
ValidatorEpochInfoEvent {
ValidatorEpochInfoEventV2 {
epoch: new_epoch,
validator_address,
reference_gas_survey_quote: validator::gas_price(v),
stake: validator::total_stake_amount(v),
voting_power: validator::voting_power(v),
commission_rate: validator::commission_rate(v),
pool_staking_reward: *vector::borrow(pool_staking_reward_amounts, i),
storage_fund_staking_reward: *vector::borrow(storage_fund_staking_reward_amounts, i),
Expand Down

0 comments on commit 97b411a

Please sign in to comment.