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

Commit 720a355

Browse files
authored
Governance: Remove TokenOwnerRecord total_votes_count (#130)
* feat: Extend unrelinquished_votes_count to u64 * chore: Update comments and names * chore: Update asserts * chore: Update comments * chore: Use u32:MAX to trim unrelinquished_votes_count * chore: Make Clippy happy * chore: Update versioning cleanup comments
1 parent 49c5cd7 commit 720a355

15 files changed

+209
-68
lines changed

governance/program/src/processor/process_cast_vote.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,6 @@ pub fn process_cast_vote(
100100
.checked_add(1)
101101
.unwrap();
102102

103-
voter_token_owner_record_data.total_votes_count = voter_token_owner_record_data
104-
.total_votes_count
105-
.checked_add(1)
106-
.unwrap();
107-
108103
let realm_config_info = next_account_info(account_info_iter)?; // 9
109104
let realm_config_data =
110105
get_realm_config_data_for_realm(program_id, realm_config_info, realm_info.key)?;

governance/program/src/processor/process_create_token_owner_record.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ use crate::{
1414
state::{
1515
enums::GovernanceAccountType,
1616
realm::get_realm_data,
17-
token_owner_record::{get_token_owner_record_address_seeds, TokenOwnerRecordV2},
17+
token_owner_record::{
18+
get_token_owner_record_address_seeds, TokenOwnerRecordV2, TOKEN_OWNER_RECORD_VERSION,
19+
},
1820
},
1921
};
2022

@@ -48,9 +50,9 @@ pub fn process_create_token_owner_record(
4850
governing_token_mint: *governing_token_mint_info.key,
4951
governance_delegate: None,
5052
unrelinquished_votes_count: 0,
51-
total_votes_count: 0,
5253
outstanding_proposal_count: 0,
53-
reserved: [0; 7],
54+
version: TOKEN_OWNER_RECORD_VERSION,
55+
reserved: [0; 6],
5456
reserved_v2: [0; 128],
5557
};
5658

governance/program/src/processor/process_deposit_governing_tokens.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use crate::{
1717
realm_config::get_realm_config_data_for_realm,
1818
token_owner_record::{
1919
get_token_owner_record_address_seeds, get_token_owner_record_data_for_seeds,
20-
TokenOwnerRecordV2,
20+
TokenOwnerRecordV2, TOKEN_OWNER_RECORD_VERSION,
2121
},
2222
},
2323
tools::spl_token::{
@@ -104,9 +104,9 @@ pub fn process_deposit_governing_tokens(
104104
governing_token_mint,
105105
governance_delegate: None,
106106
unrelinquished_votes_count: 0,
107-
total_votes_count: 0,
108107
outstanding_proposal_count: 0,
109-
reserved: [0; 7],
108+
version: TOKEN_OWNER_RECORD_VERSION,
109+
reserved: [0; 6],
110110
reserved_v2: [0; 128],
111111
};
112112

governance/program/src/processor/process_relinquish_vote.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,6 @@ pub fn process_relinquish_vote(program_id: &Pubkey, accounts: &[AccountInfo]) ->
110110
proposal_data.serialize(&mut *proposal_info.data.borrow_mut())?;
111111

112112
dispose_account(vote_record_info, beneficiary_info)?;
113-
114-
token_owner_record_data.total_votes_count = token_owner_record_data
115-
.total_votes_count
116-
.checked_sub(1)
117-
.unwrap();
118113
} else {
119114
// After Proposal voting time ends and it's not tipped then it enters implicit (time based) Finalizing state
120115
// and releasing tokens in this state should be disallowed

governance/program/src/processor/process_set_realm_config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ pub fn process_set_realm_config(
9595

9696
// Update or create RealmConfigAccount
9797
if realm_config_info.data_is_empty() {
98-
// For older Realms (pre v3) RealmConfigAccount might not exist yet and we have to create it
98+
// For older Realm accounts (pre program V3) RealmConfigAccount might not exist yet and we have to create it
9999

100100
// We need the payer to pay for the new account if it's created
101101
let payer_info = next_account_info(account_info_iter)?; // 10

governance/program/src/state/governance.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ pub fn get_governance_data(
294294
// Note: assert_is_valid_governance_config() prevents setting council_vote_threshold to VoteThreshold::YesVotePercentage(0)
295295
// which gives as guarantee that it is a legacy account layout set with proposal_cool_off_time = 0
296296
//
297-
// Note: All the settings below are one time config migration from V1 & V2 account data to V3
297+
// Note: All the settings below are one time config migration from program V1 & V2 account data to V3
298298
if governance_data.config.council_vote_threshold == VoteThreshold::YesVotePercentage(0) {
299299
// Set council_vote_threshold to community_vote_threshold which was used for both council and community thresholds before
300300
governance_data.config.council_vote_threshold =
@@ -652,7 +652,7 @@ mod test {
652652
}
653653

654654
#[test]
655-
fn test_migrate_governance_config_from_legacy_data_to_v3() {
655+
fn test_migrate_governance_config_from_legacy_data_to_program_v3() {
656656
// Arrange
657657
let mut governance_legacy_data = create_test_governance();
658658

@@ -689,32 +689,32 @@ mod test {
689689
Epoch::default(),
690690
);
691691
// Act
692-
let governance_v3 = get_governance_data(&program_id, &legacy_account_info).unwrap();
692+
let governance_program_v3 = get_governance_data(&program_id, &legacy_account_info).unwrap();
693693

694694
// Assert
695695
assert_eq!(
696-
governance_v3.config.council_vote_threshold,
696+
governance_program_v3.config.council_vote_threshold,
697697
VoteThreshold::YesVotePercentage(60)
698698
);
699699

700700
assert_eq!(
701-
governance_v3.config.council_veto_vote_threshold,
701+
governance_program_v3.config.council_veto_vote_threshold,
702702
VoteThreshold::YesVotePercentage(60)
703703
);
704704

705705
assert_eq!(
706-
governance_v3.config.community_veto_vote_threshold,
706+
governance_program_v3.config.community_veto_vote_threshold,
707707
VoteThreshold::Disabled
708708
);
709709

710710
assert_eq!(
711-
governance_v3.config.council_vote_tipping,
711+
governance_program_v3.config.council_vote_tipping,
712712
VoteTipping::Strict
713713
);
714714

715-
assert_eq!(governance_v3.config.voting_cool_off_time, 0);
715+
assert_eq!(governance_program_v3.config.voting_cool_off_time, 0);
716716

717-
assert_eq!(governance_v3.config.reserved, 0);
717+
assert_eq!(governance_program_v3.config.reserved, 0);
718718
}
719719

720720
#[test]

governance/program/src/state/legacy.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,20 +74,19 @@ pub struct TokenOwnerRecordV1 {
7474

7575
/// The number of votes cast by TokenOwner but not relinquished yet
7676
/// Every time a vote is cast this number is increased and it's always decreased when relinquishing a vote regardless of the vote state
77-
pub unrelinquished_votes_count: u32,
78-
79-
/// The total number of votes cast by the TokenOwner
80-
/// If TokenOwner withdraws vote while voting is still in progress total_votes_count is decreased and the vote doesn't count towards the total
81-
pub total_votes_count: u32,
77+
pub unrelinquished_votes_count: u64,
8278

8379
/// The number of outstanding proposals the TokenOwner currently owns
8480
/// The count is increased when TokenOwner creates a proposal
8581
/// and decreased once it's either voted on (Succeeded or Defeated) or Cancelled
86-
/// By default it's restricted to 1 outstanding Proposal per token owner
82+
/// By default it's restricted to 10 outstanding Proposal per token owner
8783
pub outstanding_proposal_count: u8,
8884

85+
/// Version introduced in program V3
86+
pub version: u8,
87+
8988
/// Reserved space for future versions
90-
pub reserved: [u8; 7],
89+
pub reserved: [u8; 6],
9190

9291
/// A single account that is allowed to operate governance with the deposited governing tokens
9392
/// It can be delegated to by the governing_token_owner or current governance_delegate

governance/program/src/state/realm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ pub struct RealmV2 {
137137
/// Reserved space for future versions
138138
pub reserved: [u8; 6],
139139

140-
/// Legacy field not used since V3 any longer
140+
/// Legacy field not used since program V3 any longer
141141
/// Note: If the field is going to be reused in future version it must be taken under consideration
142142
/// that for some Realms it might be already set to none zero because it was used as voting_proposal_count before
143143
pub legacy1: u16,

0 commit comments

Comments
 (0)