-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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] governance multi-step proposal #5445
Conversation
944e8bc
to
2a5f21f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ahh this is clever!
70ca1fd
to
192338f
Compare
aptos-move/framework/aptos-framework/sources/aptos_governance.move
Outdated
Show resolved
Hide resolved
aptos-move/framework/aptos-framework/sources/aptos_governance.move
Outdated
Show resolved
Hide resolved
aptos-move/framework/aptos-framework/sources/aptos_governance.move
Outdated
Show resolved
Hide resolved
aptos-move/framework/aptos-framework/sources/aptos_governance.move
Outdated
Show resolved
Hide resolved
aptos-move/framework/aptos-framework/sources/aptos_governance.move
Outdated
Show resolved
Hide resolved
aptos-move/framework/aptos-framework/sources/aptos_governance.move
Outdated
Show resolved
Hide resolved
2f6e0fa
to
9fe7465
Compare
aptos-move/framework/aptos-framework/sources/aptos_governance.move
Outdated
Show resolved
Hide resolved
aptos-move/framework/aptos-framework/sources/aptos_governance.move
Outdated
Show resolved
Hide resolved
051c0e4
to
5c8b6cf
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a few minor comments left. Otherwise it's good to go :)
77a33a8
to
b46c395
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a minor nit but the overall logic makes sense to me! Great work!
/// 1. RESOLVABLE_TIME_METADATA_KEY: this is uesed to record the resolvable time to ensure that resolution has to be done non-atomically. | ||
/// 2. IS_MULTI_STEP_PROPOSAL_KEY: this is used to track if a proposal is single-step or multi-step. | ||
/// 3. IS_MULTI_STEP_PROPOSAL_IN_EXECUTION_KEY: this attribute only exists for and applies to multi-step proposals. The value is used to | ||
/// indicate if a multi-step proposal is in execution. If yes, we will disable further voting for this multi-step proposal. | ||
metadata: SimpleMap<String, vector<u8>>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be great if we can implement new move features to avoid having this heterogeneous map...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ahh yeah, any ideas on how we can make this better? it does seem kind of hacky to hardcode all the keys in this map.
/// @param voting_forum_address The address of the forum where the proposals are stored. | ||
/// @param proposal_id The proposal id. | ||
public fun resolve<ProposalType: store>( | ||
fun is_proposal_resolvable<ProposalType: store>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like this is a bad name because the function is actually mutating global states i.e: update is_multi_step_proposal_in_execution_value
, but the name suggests it's a pure function. Would be great if you can find a new name and provide some comments there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great point - will update the name of this function and add more comments!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just updated! I kept the name of this function but added some comment and moved the is_multi_step_proposal_in_execution_value
update logic to resolve_proposal_v2()
, since this logic doesn't apply to single-step proposal (so it's not a common check, and doesn't make sense to have it in is_proposal_resolvable()
).
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
✅ Forge suite
|
✅ Forge suite
|
Co-authored-by: chloeqjz <79347459+chloeqjz@users.noreply.github.com>
Description
Implementation of this AIP: aptos-foundation/AIPs#3.
TLDR: we're supporting multi-step proposals in this PR. We do so by updating
proposal.execution_hash
andApprovedExecutionHashes
on-chain to thenext_execution_hash
.Summary of changes included in this PR:
aptos_governance
module:Added:
aptos_governance::create_proposal_v2()
: this is similar to the existingaptos_governance::create_proposal
, but here we call the newly addedvoting::create_proposal_v2
to create an Aptos governance proposal.aptos_governance::resolve_multi_step_proposal()
: similar to the existingaptos_governance::resolve()
, but here we replace the current execution hash inApprovedExecutionHashes
withnext_execution_hash
, and callvoting::resolve_proposal_v2
to resolve the proposal.Modified:
aptos_governance::add_approved_script_hash()
: previously, we immediately return if theApprovedExecutionHashes
map already contains the givenproposal_id
. In the updated code, if theApprovedExecutionHashes
map already contains the givenproposal_id
, we will replace the existing value inApprovedExecutionHashes
with the updated execution hash.aptos_governance::create_proposal()
: redirected this function to call the newly addedaptos_governance::create_proposal_v2()
, so that we'll have metadata information about if this proposal is single-step or multi-step.voting
module:Added:
Two new constants:
IS_MULTI_STEP_PROPOSAL_KEY
andIS_MULTI_STEP_PROPOSAL_IN_EXECUTION_KEY
. They will be stored in theproposal.metadata
map upon creation of a proposal.voting:: create_proposal_v2()
: the flow of this function is similar to the existingvoting:: create_proposal()
function except that we are also adding metadata about this proposal in theproposal.metadata
map.IS_MULTI_STEP_PROPOSAL_KEY
:true
for multi-step proposals,false
for single-step proposals;IS_MULTI_STEP_PROPOSAL_IN_EXECUTION_KEY
only exists in multi-step proposals. Its value is by defaultfalse
.We update it to true when we start resolving the multi-step proposal. This flag is used to disable further voting when a multi-step proposal is already in execution.
voting:: is_proposal_resolvable()
: this includes all common checks on if a proposal is resolvable regardless if the proposal is single-step or multi-step.voting:: resolve_proposal_v2()
: this function can resolve a single-step proposal or a multi-step proposal. The flow for a single-step proposal remains mostly unchanged. The flow for a multi-step proposal will update theproposal.execution_hash
with thenext_execution_hash
on-chain, and check/updateproposal.metadata
values.voting:: is_multi_step_proposal_in_execution()
: this function returns true if the specified multi-step proposal is in execution.Modified:
voting::vote()
: added a check to abort when the specified proposal is multi-step and already in execution.voting::resolve()
: added a check to ensure that this function can only be called to resolve single-step proposals.Test Plan
Unit tests in this PR, smoke + e2e tests to come in future PRs.
This change is