Skip to content

Commit

Permalink
Refine Voting Error Codes (#15590)
Browse files Browse the repository at this point in the history
This commit refines voting error codes by introducing more specific classifications: ENO_VOTING_POWER, EINSUFFICIENT_STAKE_LOCKUP, and EPROPOSAL_EXPIRED.
  • Loading branch information
junkil-park authored Dec 20, 2024
1 parent 554f302 commit 2c9dece
Show file tree
Hide file tree
Showing 7 changed files with 289 additions and 317 deletions.
81 changes: 72 additions & 9 deletions aptos-move/framework/aptos-framework/doc/aptos_governance.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ on a proposal multiple times as long as the total voting power of these votes do
- [Function `get_required_proposer_stake`](#0x1_aptos_governance_get_required_proposer_stake)
- [Function `has_entirely_voted`](#0x1_aptos_governance_has_entirely_voted)
- [Function `get_remaining_voting_power`](#0x1_aptos_governance_get_remaining_voting_power)
- [Function `assert_proposal_expiration`](#0x1_aptos_governance_assert_proposal_expiration)
- [Function `create_proposal`](#0x1_aptos_governance_create_proposal)
- [Function `create_proposal_v2`](#0x1_aptos_governance_create_proposal_v2)
- [Function `create_proposal_v2_impl`](#0x1_aptos_governance_create_proposal_v2_impl)
Expand Down Expand Up @@ -74,6 +75,7 @@ on a proposal multiple times as long as the total voting power of these votes do
- [Function `get_required_proposer_stake`](#@Specification_1_get_required_proposer_stake)
- [Function `has_entirely_voted`](#@Specification_1_has_entirely_voted)
- [Function `get_remaining_voting_power`](#@Specification_1_get_remaining_voting_power)
- [Function `assert_proposal_expiration`](#@Specification_1_assert_proposal_expiration)
- [Function `create_proposal`](#@Specification_1_create_proposal)
- [Function `create_proposal_v2`](#@Specification_1_create_proposal_v2)
- [Function `create_proposal_v2_impl`](#@Specification_1_create_proposal_v2_impl)
Expand Down Expand Up @@ -758,6 +760,16 @@ Partial voting feature hasn't been properly initialized.



<a id="0x1_aptos_governance_EPROPOSAL_EXPIRED"></a>

The proposal has expired.


<pre><code><b>const</b> <a href="aptos_governance.md#0x1_aptos_governance_EPROPOSAL_EXPIRED">EPROPOSAL_EXPIRED</a>: u64 = 15;
</code></pre>



<a id="0x1_aptos_governance_EPROPOSAL_NOT_RESOLVABLE_YET"></a>

Proposal is not ready to be resolved. Waiting on time or votes
Expand Down Expand Up @@ -1160,6 +1172,43 @@ Note: a stake pool's voting power on a proposal could increase over time(e.g. re



</details>

<a id="0x1_aptos_governance_assert_proposal_expiration"></a>

## Function `assert_proposal_expiration`



<pre><code><b>public</b> <b>fun</b> <a href="aptos_governance.md#0x1_aptos_governance_assert_proposal_expiration">assert_proposal_expiration</a>(stake_pool: <b>address</b>, proposal_id: u64)
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="aptos_governance.md#0x1_aptos_governance_assert_proposal_expiration">assert_proposal_expiration</a>(stake_pool: <b>address</b>, proposal_id: u64) {
<a href="aptos_governance.md#0x1_aptos_governance_assert_voting_initialization">assert_voting_initialization</a>();
<b>let</b> proposal_expiration = <a href="voting.md#0x1_voting_get_proposal_expiration_secs">voting::get_proposal_expiration_secs</a>&lt;GovernanceProposal&gt;(
@aptos_framework,
proposal_id
);
// The voter's <a href="stake.md#0x1_stake">stake</a> needs <b>to</b> be locked up at least <b>as</b> long <b>as</b> the proposal's expiration.
<b>assert</b>!(
proposal_expiration &lt;= <a href="stake.md#0x1_stake_get_lockup_secs">stake::get_lockup_secs</a>(stake_pool),
<a href="../../aptos-stdlib/../move-stdlib/doc/error.md#0x1_error_invalid_argument">error::invalid_argument</a>(<a href="aptos_governance.md#0x1_aptos_governance_EINSUFFICIENT_STAKE_LOCKUP">EINSUFFICIENT_STAKE_LOCKUP</a>),
);
<b>assert</b>!(
<a href="timestamp.md#0x1_timestamp_now_seconds">timestamp::now_seconds</a>() &lt;= proposal_expiration,
<a href="../../aptos-stdlib/../move-stdlib/doc/error.md#0x1_error_invalid_argument">error::invalid_argument</a>(<a href="aptos_governance.md#0x1_aptos_governance_EPROPOSAL_EXPIRED">EPROPOSAL_EXPIRED</a>),
);
}
</code></pre>



</details>

<a id="0x1_aptos_governance_create_proposal"></a>
Expand Down Expand Up @@ -1498,15 +1547,7 @@ cannot vote on the proposal even after partial governance voting is enabled.
<b>let</b> voter_address = <a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer_address_of">signer::address_of</a>(voter);
<b>assert</b>!(<a href="stake.md#0x1_stake_get_delegated_voter">stake::get_delegated_voter</a>(stake_pool) == voter_address, <a href="../../aptos-stdlib/../move-stdlib/doc/error.md#0x1_error_invalid_argument">error::invalid_argument</a>(<a href="aptos_governance.md#0x1_aptos_governance_ENOT_DELEGATED_VOTER">ENOT_DELEGATED_VOTER</a>));

// The voter's <a href="stake.md#0x1_stake">stake</a> needs <b>to</b> be locked up at least <b>as</b> long <b>as</b> the proposal's expiration.
<b>let</b> proposal_expiration = <a href="voting.md#0x1_voting_get_proposal_expiration_secs">voting::get_proposal_expiration_secs</a>&lt;GovernanceProposal&gt;(
@aptos_framework,
proposal_id
);
<b>assert</b>!(
<a href="stake.md#0x1_stake_get_lockup_secs">stake::get_lockup_secs</a>(stake_pool) &gt;= proposal_expiration,
<a href="../../aptos-stdlib/../move-stdlib/doc/error.md#0x1_error_invalid_argument">error::invalid_argument</a>(<a href="aptos_governance.md#0x1_aptos_governance_EINSUFFICIENT_STAKE_LOCKUP">EINSUFFICIENT_STAKE_LOCKUP</a>),
);
<a href="aptos_governance.md#0x1_aptos_governance_assert_proposal_expiration">assert_proposal_expiration</a>(stake_pool, proposal_id);

// If a <a href="stake.md#0x1_stake">stake</a> pool <b>has</b> already voted on a proposal before partial governance <a href="voting.md#0x1_voting">voting</a> is enabled,
// `get_remaining_voting_power` returns 0.
Expand Down Expand Up @@ -2435,6 +2476,28 @@ Abort if structs have already been created.



<a id="@Specification_1_assert_proposal_expiration"></a>

### Function `assert_proposal_expiration`


<pre><code><b>public</b> <b>fun</b> <a href="aptos_governance.md#0x1_aptos_governance_assert_proposal_expiration">assert_proposal_expiration</a>(stake_pool: <b>address</b>, proposal_id: u64)
</code></pre>




<pre><code><b>include</b> <a href="aptos_governance.md#0x1_aptos_governance_VotingInitializationAbortIfs">VotingInitializationAbortIfs</a>;
<b>include</b> <a href="voting.md#0x1_voting_AbortsIfNotContainProposalID">voting::AbortsIfNotContainProposalID</a>&lt;GovernanceProposal&gt;{voting_forum_address: @aptos_framework};
<b>let</b> proposal_expiration = <a href="voting.md#0x1_voting_spec_get_proposal_expiration_secs">voting::spec_get_proposal_expiration_secs</a>&lt;GovernanceProposal&gt;(@aptos_framework, proposal_id);
<b>aborts_if</b> !<a href="stake.md#0x1_stake_stake_pool_exists">stake::stake_pool_exists</a>(stake_pool);
<b>aborts_if</b> proposal_expiration &gt; <a href="stake.md#0x1_stake_spec_get_lockup_secs">stake::spec_get_lockup_secs</a>(stake_pool);
<b>aborts_if</b> !<b>exists</b>&lt;<a href="timestamp.md#0x1_timestamp_CurrentTimeMicroseconds">timestamp::CurrentTimeMicroseconds</a>&gt;(@aptos_framework);
<b>aborts_if</b> <a href="timestamp.md#0x1_timestamp_now_seconds">timestamp::now_seconds</a>() &gt; proposal_expiration;
</code></pre>



<a id="@Specification_1_create_proposal"></a>

### Function `create_proposal`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2955,6 +2955,7 @@ Vote on a proposal with a voter's voting power. To successfully vote, the follow
<b>if</b> (voting_power &gt; remaining_voting_power) {
voting_power = remaining_voting_power;
};
<a href="aptos_governance.md#0x1_aptos_governance_assert_proposal_expiration">aptos_governance::assert_proposal_expiration</a>(pool_address, proposal_id);
<b>assert</b>!(voting_power &gt; 0, <a href="../../aptos-stdlib/../move-stdlib/doc/error.md#0x1_error_invalid_argument">error::invalid_argument</a>(<a href="delegation_pool.md#0x1_delegation_pool_ENO_VOTING_POWER">ENO_VOTING_POWER</a>));

<b>let</b> governance_records = <b>borrow_global_mut</b>&lt;<a href="delegation_pool.md#0x1_delegation_pool_GovernanceRecords">GovernanceRecords</a>&gt;(pool_address);
Expand Down
Loading

0 comments on commit 2c9dece

Please sign in to comment.