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

Commit c5fcbef

Browse files
authored
Governance: Remove stats only fields to make room for more Config values (#3828)
* fix: Remove voting_proposal_count * chore: add governance size tests * chore: fix chat tests compilation
1 parent af7c378 commit c5fcbef

19 files changed

+94
-113
lines changed

governance/chat/program/tests/program_test/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ impl GovernanceChatProgramTest {
196196
council_veto_vote_threshold: VoteThreshold::YesVotePercentage(50),
197197
council_vote_tipping: spl_governance::state::enums::VoteTipping::Strict,
198198
community_veto_vote_threshold: VoteThreshold::YesVotePercentage(55),
199-
reserved: [0; 3],
199+
reserved: [0; 5],
200200
};
201201

202202
let token_owner_record_address = get_token_owner_record_address(

governance/program/src/instruction.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ pub enum GovernanceInstruction {
266266
/// Cancels Proposal by changing its state to Canceled
267267
///
268268
/// 0. `[writable]` Realm account
269-
/// 1. `[writable]` Governance account
269+
/// 1. `[]` Governance account
270270
/// 2. `[writable]` Proposal account
271271
/// 3. `[writable]` TokenOwnerRecord account of the Proposal owner
272272
/// 4. `[signer]` Governance Authority (Token Owner or Governance Delegate)
@@ -279,7 +279,7 @@ pub enum GovernanceInstruction {
279279
/// If Proposal owner doesn't designate any signatories then can sign off the Proposal themself
280280
///
281281
/// 0. `[writable]` Realm account
282-
/// 1. `[writable]` Governance account
282+
/// 1. `[]` Governance account
283283
/// 2. `[writable]` Proposal account
284284
/// 3. `[signer]` Signatory account signing off the Proposal
285285
/// Or Proposal owner if the owner hasn't appointed any signatories
@@ -292,7 +292,7 @@ pub enum GovernanceInstruction {
292292
/// If you tip the consensus then the transactions can begin to be run after their hold up time
293293
///
294294
/// 0. `[writable]` Realm account
295-
/// 1. `[writable]` Governance account
295+
/// 1. `[]` Governance account
296296
/// 2. `[writable]` Proposal account
297297
/// 3. `[writable]` TokenOwnerRecord of the Proposal owner
298298
/// 4. `[writable]` TokenOwnerRecord of the voter. PDA seeds: ['governance',realm, vote_governing_token_mint, governing_token_owner]
@@ -317,7 +317,7 @@ pub enum GovernanceInstruction {
317317
/// Finalizes vote in case the Vote was not automatically tipped within max_voting_time period
318318
///
319319
/// 0. `[writable]` Realm account
320-
/// 1. `[writable]` Governance account
320+
/// 1. `[]` Governance account
321321
/// 2. `[writable]` Proposal account
322322
/// 3. `[writable]` TokenOwnerRecord of the Proposal owner
323323
/// 4. `[]` Governing Token Mint
@@ -1010,7 +1010,7 @@ pub fn sign_off_proposal(
10101010
) -> Instruction {
10111011
let mut accounts = vec![
10121012
AccountMeta::new(*realm, false),
1013-
AccountMeta::new(*governance, false),
1013+
AccountMeta::new_readonly(*governance, false),
10141014
AccountMeta::new(*proposal, false),
10151015
AccountMeta::new_readonly(*signatory, true),
10161016
];
@@ -1055,7 +1055,7 @@ pub fn cast_vote(
10551055

10561056
let mut accounts = vec![
10571057
AccountMeta::new(*realm, false),
1058-
AccountMeta::new(*governance, false),
1058+
AccountMeta::new_readonly(*governance, false),
10591059
AccountMeta::new(*proposal, false),
10601060
AccountMeta::new(*proposal_owner_record, false),
10611061
AccountMeta::new(*voter_token_owner_record, false),
@@ -1096,7 +1096,7 @@ pub fn finalize_vote(
10961096
) -> Instruction {
10971097
let mut accounts = vec![
10981098
AccountMeta::new(*realm, false),
1099-
AccountMeta::new(*governance, false),
1099+
AccountMeta::new_readonly(*governance, false),
11001100
AccountMeta::new(*proposal, false),
11011101
AccountMeta::new(*proposal_owner_record, false),
11021102
AccountMeta::new_readonly(*governing_token_mint, false),
@@ -1169,7 +1169,7 @@ pub fn cancel_proposal(
11691169
) -> Instruction {
11701170
let accounts = vec![
11711171
AccountMeta::new(*realm, false),
1172-
AccountMeta::new(*governance, false),
1172+
AccountMeta::new_readonly(*governance, false),
11731173
AccountMeta::new(*proposal, false),
11741174
AccountMeta::new(*proposal_owner_record, false),
11751175
AccountMeta::new_readonly(*governance_authority, true),

governance/program/src/processor/process_cancel_proposal.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub fn process_cancel_proposal(program_id: &Pubkey, accounts: &[AccountInfo]) ->
2828

2929
let mut realm_data = get_realm_data(program_id, realm_info)?;
3030

31-
let mut governance_data =
31+
let governance_data =
3232
get_governance_data_for_realm(program_id, governance_info, realm_info.key)?;
3333

3434
let mut proposal_data =
@@ -51,11 +51,6 @@ pub fn process_cancel_proposal(program_id: &Pubkey, accounts: &[AccountInfo]) ->
5151
// Update Realm voting_proposal_count
5252
realm_data.voting_proposal_count = realm_data.voting_proposal_count.saturating_sub(1);
5353
realm_data.serialize(&mut *realm_info.data.borrow_mut())?;
54-
55-
// Update Governance voting_proposal_count
56-
governance_data.voting_proposal_count =
57-
governance_data.voting_proposal_count.saturating_sub(1);
58-
governance_data.serialize(&mut *governance_info.data.borrow_mut())?;
5954
}
6055

6156
proposal_data.state = ProposalState::Cancelled;

governance/program/src/processor/process_cast_vote.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ pub fn process_cast_vote(
6363
vote_governing_token_mint_info.key,
6464
)?;
6565

66-
let mut governance_data =
66+
let governance_data =
6767
get_governance_data_for_realm(program_id, governance_info, realm_info.key)?;
6868

6969
let vote_kind = get_vote_kind(&vote);
@@ -190,11 +190,6 @@ pub fn process_cast_vote(
190190
// Update Realm voting_proposal_count
191191
realm_data.voting_proposal_count = realm_data.voting_proposal_count.saturating_sub(1);
192192
realm_data.serialize(&mut *realm_info.data.borrow_mut())?;
193-
194-
// Update Governance voting_proposal_count
195-
governance_data.voting_proposal_count =
196-
governance_data.voting_proposal_count.saturating_sub(1);
197-
governance_data.serialize(&mut *governance_info.data.borrow_mut())?;
198193
}
199194

200195
let governing_token_owner = voter_token_owner_record_data.governing_token_owner;

governance/program/src/processor/process_create_governance.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pub fn process_create_governance(
5757
governed_account: *governed_account_info.key,
5858
config,
5959
proposals_count: 0,
60-
voting_proposal_count: 0,
60+
6161
reserved_v2: [0; 128],
6262
};
6363

governance/program/src/processor/process_create_mint_governance.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ pub fn process_create_mint_governance(
6969
governed_account: *governed_mint_info.key,
7070
config,
7171
proposals_count: 0,
72-
voting_proposal_count: 0,
7372
reserved_v2: [0; 128],
7473
};
7574

governance/program/src/processor/process_create_program_governance.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ pub fn process_create_program_governance(
6969
governed_account: *governed_program_info.key,
7070
config,
7171
proposals_count: 0,
72-
voting_proposal_count: 0,
7372
reserved_v2: [0; 128],
7473
};
7574

governance/program/src/processor/process_create_token_governance.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ pub fn process_create_token_governance(
6767
governed_account: *governed_token_info.key,
6868
config,
6969
proposals_count: 0,
70-
voting_proposal_count: 0,
7170
reserved_v2: [0; 128],
7271
};
7372

governance/program/src/processor/process_finalize_vote.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub fn process_finalize_vote(program_id: &Pubkey, accounts: &[AccountInfo]) -> P
3333
realm_info,
3434
governing_token_mint_info.key,
3535
)?;
36-
let mut governance_data =
36+
let governance_data =
3737
get_governance_data_for_realm(program_id, governance_info, realm_info.key)?;
3838

3939
let mut proposal_data = get_proposal_data_for_governance_and_governing_mint(
@@ -84,9 +84,5 @@ pub fn process_finalize_vote(program_id: &Pubkey, accounts: &[AccountInfo]) -> P
8484
realm_data.voting_proposal_count = realm_data.voting_proposal_count.saturating_sub(1);
8585
realm_data.serialize(&mut *realm_info.data.borrow_mut())?;
8686

87-
// Update Governance voting_proposal_count
88-
governance_data.voting_proposal_count = governance_data.voting_proposal_count.saturating_sub(1);
89-
governance_data.serialize(&mut *governance_info.data.borrow_mut())?;
90-
9187
Ok(())
9288
}

governance/program/src/processor/process_sign_off_proposal.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub fn process_sign_off_proposal(program_id: &Pubkey, accounts: &[AccountInfo])
2929

3030
let mut realm_data = get_realm_data(program_id, realm_info)?;
3131

32-
let mut governance_data =
32+
let _governance_data =
3333
get_governance_data_for_realm(program_id, governance_info, realm_info.key)?;
3434

3535
let mut proposal_data =
@@ -89,11 +89,5 @@ pub fn process_sign_off_proposal(program_id: &Pubkey, accounts: &[AccountInfo])
8989
realm_data.voting_proposal_count = realm_data.voting_proposal_count.checked_add(1).unwrap();
9090
realm_data.serialize(&mut *realm_info.data.borrow_mut())?;
9191

92-
governance_data.voting_proposal_count = governance_data
93-
.voting_proposal_count
94-
.checked_add(1)
95-
.unwrap();
96-
governance_data.serialize(&mut *governance_info.data.borrow_mut())?;
97-
9892
Ok(())
9993
}

0 commit comments

Comments
 (0)