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

Commit ebc91e8

Browse files
authored
Governance: add v2 account padding (#2842)
* chore: create RealmV2 account type * feat: add padding to Realm account * chore: move RealmConfigArgsV1 and GovernanceInstructionV1 to tests * chore: Add RealmV2 comments * chore: rename TokenOwnerRecord to V2 and add reserved space * feat: translate TokenOwnerRecordV1 * chore: rename Governance to GovernanceV2 * feat: add reserved_v2 to Governance * chore: make clippy happy * feat: translate GovernanceV1 accounts * chore: fix chat build * fix: update seeds logic for governance V1 accounts * fix: add check for RealmV1 and GovernanceV1 * chore: add padding to ProposalTransaction * chore: add padding to VoteRecordV2 * chore: add padding to SignatoryRecord V2 * feat: translate SignatoryRecordV1 account
1 parent 925f8f5 commit ebc91e8

36 files changed

+665
-325
lines changed

governance/chat/program/src/state.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use solana_program::{
55
account_info::AccountInfo, clock::UnixTimestamp, program_error::ProgramError, pubkey::Pubkey,
66
};
77

8-
use spl_governance_tools::account::{assert_is_valid_account, AccountMaxSize};
8+
use spl_governance_tools::account::{assert_is_valid_account_of_type, AccountMaxSize};
99

1010
/// Defines all GovernanceChat accounts types
1111
#[repr(C)]
@@ -67,7 +67,7 @@ pub fn assert_is_valid_chat_message(
6767
program_id: &Pubkey,
6868
chat_message_info: &AccountInfo,
6969
) -> Result<(), ProgramError> {
70-
assert_is_valid_account(
70+
assert_is_valid_account_of_type(
7171
chat_message_info,
7272
GovernanceChatAccountType::ChatMessage,
7373
program_id,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ impl GovernanceChatProgramTest {
223223
let create_governance_ix = create_governance(
224224
&self.governance_program_id,
225225
&realm_address,
226-
&governed_account_address,
226+
Some(&governed_account_address),
227227
&token_owner_record_address,
228228
&self.bench.payer.pubkey(),
229229
&token_owner.pubkey(),

governance/program/src/addins/voter_weight.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use solana_program::{
77
use spl_governance_addin_api::voter_weight::{VoterWeightAction, VoterWeightRecord};
88
use spl_governance_tools::account::get_account_data;
99

10-
use crate::{error::GovernanceError, state::token_owner_record::TokenOwnerRecord};
10+
use crate::{error::GovernanceError, state::token_owner_record::TokenOwnerRecordV2};
1111

1212
/// Asserts the VoterWeightRecord hasn't expired and matches the given action and target if specified
1313
pub fn assert_is_valid_voter_weight(
@@ -53,7 +53,7 @@ pub fn get_voter_weight_record_data(
5353
pub fn get_voter_weight_record_data_for_token_owner_record(
5454
program_id: &Pubkey,
5555
voter_weight_record_info: &AccountInfo,
56-
token_owner_record: &TokenOwnerRecord,
56+
token_owner_record: &TokenOwnerRecordV2,
5757
) -> Result<VoterWeightRecord, ProgramError> {
5858
let voter_weight_record_data =
5959
get_voter_weight_record_data(program_id, voter_weight_record_info)?;

governance/program/src/processor/process_add_signatory.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use spl_governance_tools::account::create_and_serialize_account_signed;
1212
use crate::state::{
1313
enums::GovernanceAccountType,
1414
proposal::get_proposal_data,
15-
signatory_record::{get_signatory_record_address_seeds, SignatoryRecord},
15+
signatory_record::{get_signatory_record_address_seeds, SignatoryRecordV2},
1616
token_owner_record::get_token_owner_record_data_for_proposal_owner,
1717
};
1818

@@ -46,14 +46,15 @@ pub fn process_add_signatory(
4646

4747
token_owner_record_data.assert_token_owner_or_delegate_is_signer(governance_authority_info)?;
4848

49-
let signatory_record_data = SignatoryRecord {
50-
account_type: GovernanceAccountType::SignatoryRecord,
49+
let signatory_record_data = SignatoryRecordV2 {
50+
account_type: GovernanceAccountType::SignatoryRecordV2,
5151
proposal: *proposal_info.key,
5252
signatory,
5353
signed_off: false,
54+
reserved_v2: [0; 8],
5455
};
5556

56-
create_and_serialize_account_signed::<SignatoryRecord>(
57+
create_and_serialize_account_signed::<SignatoryRecordV2>(
5758
payer_info,
5859
signatory_record_info,
5960
&signatory_record_data,

governance/program/src/processor/process_cancel_proposal.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//! Program state processor
22
3-
use borsh::BorshSerialize;
43
use solana_program::{
54
account_info::{next_account_info, AccountInfo},
65
clock::Clock,

governance/program/src/processor/process_cast_vote.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ use crate::{
2626
},
2727
};
2828

29-
use borsh::BorshSerialize;
30-
3129
/// Processes CastVote instruction
3230
pub fn process_cast_vote(
3331
program_id: &Pubkey,
@@ -176,6 +174,8 @@ pub fn process_cast_vote(
176174
governance_data.serialize(&mut *governance_info.data.borrow_mut())?;
177175
}
178176

177+
let governing_token_owner = voter_token_owner_record_data.governing_token_owner;
178+
179179
voter_token_owner_record_data
180180
.serialize(&mut *voter_token_owner_record_info.data.borrow_mut())?;
181181

@@ -185,10 +185,11 @@ pub fn process_cast_vote(
185185
let vote_record_data = VoteRecordV2 {
186186
account_type: GovernanceAccountType::VoteRecordV2,
187187
proposal: *proposal_info.key,
188-
governing_token_owner: voter_token_owner_record_data.governing_token_owner,
188+
governing_token_owner,
189189
voter_weight,
190190
vote,
191191
is_relinquished: false,
192+
reserved_v2: [0; 8],
192193
};
193194

194195
create_and_serialize_account_signed::<VoteRecordV2>(

governance/program/src/processor/process_create_governance.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
use crate::state::{
44
enums::GovernanceAccountType,
55
governance::{
6-
assert_valid_create_governance_args, get_governance_address_seeds, Governance,
7-
GovernanceConfig,
6+
assert_valid_create_governance_args, get_governance_address_seeds, GovernanceConfig,
7+
GovernanceV2,
88
},
99
realm::get_realm_data,
1010
};
@@ -51,17 +51,18 @@ pub fn process_create_governance(
5151
account_info_iter, // realm_config_info 7, voter_weight_record_info 8
5252
)?;
5353

54-
let governance_data = Governance {
55-
account_type: GovernanceAccountType::Governance,
54+
let governance_data = GovernanceV2 {
55+
account_type: GovernanceAccountType::GovernanceV2,
5656
realm: *realm_info.key,
5757
governed_account: *governed_account_info.key,
5858
config,
5959
proposals_count: 0,
6060
reserved: [0; 6],
6161
voting_proposal_count: 0,
62+
reserved_v2: [0; 128],
6263
};
6364

64-
create_and_serialize_account_signed::<Governance>(
65+
create_and_serialize_account_signed::<GovernanceV2>(
6566
payer_info,
6667
governance_info,
6768
&governance_data,

governance/program/src/processor/process_create_mint_governance.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use crate::{
44
state::{
55
enums::GovernanceAccountType,
66
governance::{
7-
assert_valid_create_governance_args, get_mint_governance_address_seeds, Governance,
8-
GovernanceConfig,
7+
assert_valid_create_governance_args, get_mint_governance_address_seeds,
8+
GovernanceConfig, GovernanceV2,
99
},
1010
realm::get_realm_data,
1111
},
@@ -63,17 +63,18 @@ pub fn process_create_mint_governance(
6363
account_info_iter, // realm_config_info 9, voter_weight_record_info 10
6464
)?;
6565

66-
let mint_governance_data = Governance {
67-
account_type: GovernanceAccountType::MintGovernance,
66+
let mint_governance_data = GovernanceV2 {
67+
account_type: GovernanceAccountType::MintGovernanceV2,
6868
realm: *realm_info.key,
6969
governed_account: *governed_mint_info.key,
7070
config,
7171
proposals_count: 0,
7272
reserved: [0; 6],
7373
voting_proposal_count: 0,
74+
reserved_v2: [0; 128],
7475
};
7576

76-
create_and_serialize_account_signed::<Governance>(
77+
create_and_serialize_account_signed::<GovernanceV2>(
7778
payer_info,
7879
mint_governance_info,
7980
&mint_governance_data,

governance/program/src/processor/process_create_program_governance.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Program state processor
22
33
use crate::{
4-
state::governance::Governance,
4+
state::governance::GovernanceV2,
55
state::{
66
enums::GovernanceAccountType,
77
governance::{
@@ -63,17 +63,18 @@ pub fn process_create_program_governance(
6363
account_info_iter, // realm_config_info 10, voter_weight_record_info 11
6464
)?;
6565

66-
let program_governance_data = Governance {
67-
account_type: GovernanceAccountType::ProgramGovernance,
66+
let program_governance_data = GovernanceV2 {
67+
account_type: GovernanceAccountType::ProgramGovernanceV2,
6868
realm: *realm_info.key,
6969
governed_account: *governed_program_info.key,
7070
config,
7171
proposals_count: 0,
7272
reserved: [0; 6],
7373
voting_proposal_count: 0,
74+
reserved_v2: [0; 128],
7475
};
7576

76-
create_and_serialize_account_signed::<Governance>(
77+
create_and_serialize_account_signed::<GovernanceV2>(
7778
payer_info,
7879
program_governance_info,
7980
&program_governance_data,

governance/program/src/processor/process_create_proposal.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//! Program state processor
22
3-
use borsh::BorshSerialize;
43
use solana_program::{
54
account_info::{next_account_info, AccountInfo},
65
clock::Clock,

0 commit comments

Comments
 (0)