Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit f013deb

Browse files
authored
Governance: assertion for proposal final state (#3964)
1 parent a376c30 commit f013deb

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

governance/program/src/error.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,10 @@ pub enum GovernanceError {
462462
///Invalid deposit Payer for ProposalDeposit
463463
#[error("Invalid deposit Payer for ProposalDeposit")]
464464
InvalidDepositPayerForProposalDeposit, // 611
465+
466+
/// Invalid State: Proposal is not in final state
467+
#[error("Invalid State: Proposal is not in final state")]
468+
InvalidStateNotFinal, // 612
465469
}
466470

467471
impl PrintProgramError for GovernanceError {

governance/program/src/state/proposal.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,23 @@ impl ProposalV2 {
259259
Ok(())
260260
}
261261

262+
/// Checks the Proposal was finalized (no more state transition will happen)
263+
pub fn assert_is_final_state(&self) -> Result<(), ProgramError> {
264+
match self.state {
265+
ProposalState::Completed
266+
| ProposalState::Cancelled
267+
| ProposalState::Defeated
268+
| ProposalState::Vetoed => Ok(()),
269+
ProposalState::Executing
270+
| ProposalState::ExecutingWithErrors
271+
| ProposalState::SigningOff
272+
| ProposalState::Voting
273+
| ProposalState::Draft
274+
// state transition bug: non executable proposals could be stuck in Succeeded state
275+
| ProposalState::Succeeded => Err(GovernanceError::InvalidStateNotFinal.into()),
276+
}
277+
}
278+
262279
/// Checks if Proposal can be voted on
263280
pub fn assert_can_cast_vote(
264281
&self,

0 commit comments

Comments
 (0)