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

Commit cf4b264

Browse files
Governance: future proofing for v2 (#2002)
* chore: upgrade instruction serialisation * chore: add assert for base64 encoded instruction * chore: move fields with dynamic size to account end * chore: Add VoteThresholdPercentageType to support quorum votes in future versions * chore: Add VoteWeightSource to support account snapshots as voter weights in future versions * chore: Add InstructionExecutionStatus to support failing proposal instructions in future versions * fix: update voting_at_slot when proposal enters voting state * fix: change min_tokens_to_create_proposal to u64 to support large mints * chore: add InstructionExecutionFlags to support ordered and transactional instruction in future versions * chore: add withdraw tests with relinquished and unrelinquished votes * chore: add placeholder for proposal_cool_off_time * chore: add padding to permanent accounts to use in future versions * chore: add ProposalCoolOffTimeNotSupported error * chore: start governance errors from 500 * chore: update versions * chore: update comments * chore: use slice for reserved account space * chore: use VoteThresholdPercentage enum to store percentage value * chore: use enum None value instead of Option for execution_status * chore: use enum None instead of Option for execution_flags * chore: make clippy happy Co-authored-by: Jon Cinque <[email protected]>
1 parent 299b39e commit cf4b264

28 files changed

+479
-130
lines changed

Cargo.lock

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

governance/program/Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "spl-governance"
3-
version = "0.1.0"
4-
description = "Solana Program Library Governance"
3+
version = "1.0.1"
4+
description = "Solana Program Library Governance Program"
55
authors = ["Solana Maintainers <[email protected]>"]
66
repository = "https://github.com/solana-labs/solana-program-library"
77
license = "Apache-2.0"
@@ -20,11 +20,12 @@ num-traits = "0.2"
2020
serde = "1.0.126"
2121
serde_derive = "1.0.103"
2222
solana-program = "1.7.4"
23-
spl-token = { path = "../../token/program", features = [ "no-entrypoint" ] }
23+
spl-token = { version = "3.1.1", path = "../../token/program", features = [ "no-entrypoint" ] }
2424
thiserror = "1.0"
2525

2626
[dev-dependencies]
2727
assert_matches = "1.5.0"
28+
base64 = "0.13"
2829
proptest = "1.0"
2930
solana-program-test = "1.7.4"
3031
solana-sdk = "1.7.4"

governance/program/src/error.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use thiserror::Error;
1313
pub enum GovernanceError {
1414
/// Invalid instruction passed to program
1515
#[error("Invalid instruction passed to program")]
16-
InvalidInstruction,
16+
InvalidInstruction = 500, // Start Governance custom errors from 500 to avoid conflicts with programs invoked via CPI
1717

1818
/// Realm with the given name and governing mints already exists
1919
#[error("Realm with the given name and governing mints already exists")]
@@ -259,6 +259,18 @@ pub enum GovernanceError {
259259
/// Current token owner must sign transaction
260260
#[error("Current token owner must sign transaction")]
261261
TokenOwnerMustSign,
262+
263+
/// Given VoteThresholdPercentageType is not supported
264+
#[error("Given VoteThresholdPercentageType is not supported")]
265+
VoteThresholdPercentageTypeNotSupported,
266+
267+
/// Given VoteWeightSource is not supported
268+
#[error("Given VoteWeightSource is not supported")]
269+
VoteWeightSourceNotSupported,
270+
271+
/// Proposal cool off time is not supported
272+
#[error("Proposal cool off time is not supported")]
273+
ProposalCoolOffTimeNotSupported,
262274
}
263275

264276
impl PrintProgramError for GovernanceError {

governance/program/src/processor/process_create_account_governance.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ pub fn process_create_account_governance(
4040
account_type: GovernanceAccountType::AccountGovernance,
4141
config: config.clone(),
4242
proposals_count: 0,
43+
reserved: [0; 8],
4344
};
4445

4546
create_and_serialize_account_signed::<Governance>(

governance/program/src/processor/process_create_mint_governance.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ pub fn process_create_mint_governance(
5050
account_type: GovernanceAccountType::MintGovernance,
5151
config: config.clone(),
5252
proposals_count: 0,
53+
reserved: [0; 8],
5354
};
5455

5556
create_and_serialize_account_signed::<Governance>(

governance/program/src/processor/process_create_program_governance.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ pub fn process_create_program_governance(
5353
account_type: GovernanceAccountType::ProgramGovernance,
5454
config: config.clone(),
5555
proposals_count: 0,
56+
reserved: [0; 8],
5657
};
5758

5859
create_and_serialize_account_signed::<Governance>(

governance/program/src/processor/process_create_proposal.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use solana_program::{
1313
use crate::{
1414
error::GovernanceError,
1515
state::{
16-
enums::{GovernanceAccountType, ProposalState},
16+
enums::{GovernanceAccountType, InstructionExecutionFlags, ProposalState},
1717
governance::get_governance_data,
1818
proposal::{get_proposal_address_seeds, Proposal},
1919
token_owner_record::get_token_owner_record_data_for_realm_and_governing_mint,
@@ -84,6 +84,7 @@ pub fn process_create_proposal(
8484
draft_at: clock.unix_timestamp,
8585
signing_off_at: None,
8686
voting_at: None,
87+
voting_at_slot: None,
8788
voting_completed_at: None,
8889
executing_at: None,
8990
closed_at: None,
@@ -92,6 +93,8 @@ pub fn process_create_proposal(
9293
instructions_count: 0,
9394
instructions_next_index: 0,
9495

96+
execution_flags: InstructionExecutionFlags::None,
97+
9598
yes_votes_count: 0,
9699
no_votes_count: 0,
97100
};

governance/program/src/processor/process_create_realm.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ pub fn process_create_realm(
8383
community_mint: *governance_token_mint_info.key,
8484
council_mint: council_token_mint_address,
8585
name: name.clone(),
86+
reserved: [0; 8],
8687
};
8788

8889
create_and_serialize_account_signed::<Realm>(

governance/program/src/processor/process_create_token_governance.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ pub fn process_create_token_governance(
5050
account_type: GovernanceAccountType::TokenGovernance,
5151
config: config.clone(),
5252
proposals_count: 0,
53+
reserved: [0; 8],
5354
};
5455

5556
create_and_serialize_account_signed::<Governance>(

governance/program/src/processor/process_deposit_governing_tokens.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ pub fn process_deposit_governing_tokens(
8787
governance_delegate: None,
8888
unrelinquished_votes_count: 0,
8989
total_votes_count: 0,
90+
reserved: [0; 8],
9091
};
9192

9293
create_and_serialize_account_signed(

0 commit comments

Comments
 (0)