Skip to content

Commit

Permalink
Governance: Voter-weight-addin cleanup (solana-labs#2512)
Browse files Browse the repository at this point in the history
* chore: Ensure voter-weight-addin is built for tests

fix: build addin during test run

fix: build voter weight addin for tests using the addin only

chore: use mutex to build addin only once

chore: move build guard to separate file

chore: update governance version for chat

* chore: create tools crate for common utility functions in governance ecosystem

* chore: add test-sdk and tools readme

* chore: rename reserved addins to specific names

* chore: remove todo comment

* chore: remove unnecessary var drop

* chore: move all account tools to shared crate

* chore: fix chat compilation

* chore: move program_id to first position
  • Loading branch information
SebastianBor authored Oct 19, 2021
1 parent f95e390 commit d6d0b92
Show file tree
Hide file tree
Showing 51 changed files with 317 additions and 236 deletions.
27 changes: 23 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ members = [
"governance/voter-weight-addin/program",
"governance/program",
"governance/test-sdk",
"governance/tools",
"governance/chat/program",
"libraries/math",
"memo/program",
Expand Down
3 changes: 2 additions & 1 deletion governance/chat/program/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ serde = "1.0.127"
serde_derive = "1.0.103"
solana-program = "1.8.0"
spl-token = { version = "3.2", path = "../../../token/program", features = [ "no-entrypoint" ] }
spl-governance= { version = "2.1.0", path ="../../program", features = [ "no-entrypoint" ]}
spl-governance= { version = "2.1.2", path ="../../program", features = [ "no-entrypoint" ]}
spl-governance-tools= { version = "0.1.0", path ="../../tools"}
thiserror = "1.0"


Expand Down
1 change: 0 additions & 1 deletion governance/chat/program/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ pub mod error;
pub mod instruction;
pub mod processor;
pub mod state;
pub mod tools;

// Export current sdk types for downstream users building with a different sdk version
pub use solana_program;
2 changes: 1 addition & 1 deletion governance/chat/program/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use crate::{
error::GovernanceChatError,
instruction::GovernanceChatInstruction,
state::{assert_is_valid_chat_message, ChatMessage, GovernanceChatAccountType, MessageBody},
tools::account::create_and_serialize_account,
};
use borsh::BorshDeserialize;

Expand All @@ -21,6 +20,7 @@ use spl_governance::state::{
governance::get_governance_data, proposal::get_proposal_data_for_governance,
token_owner_record::get_token_owner_record_data_for_realm,
};
use spl_governance_tools::account::create_and_serialize_account;

/// Processes an instruction
pub fn process_instruction(
Expand Down
3 changes: 2 additions & 1 deletion governance/chat/program/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use borsh::{BorshDeserialize, BorshSchema, BorshSerialize};
use solana_program::{
account_info::AccountInfo, clock::UnixTimestamp, program_error::ProgramError, pubkey::Pubkey,
};
use spl_governance::tools::account::{assert_is_valid_account, AccountMaxSize};

use spl_governance_tools::account::{assert_is_valid_account, AccountMaxSize};

/// Defines all GovernanceChat accounts types
#[repr(C)]
Expand Down
62 changes: 0 additions & 62 deletions governance/chat/program/src/tools/account.rs

This file was deleted.

3 changes: 0 additions & 3 deletions governance/chat/program/src/tools/mod.rs

This file was deleted.

5 changes: 3 additions & 2 deletions governance/program/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "spl-governance"
version = "2.1.1"
version = "2.1.2"
description = "Solana Program Library Governance Program"
authors = ["Solana Maintainers <[email protected]>"]
repository = "https://github.com/solana-labs/solana-program-library"
Expand All @@ -21,17 +21,18 @@ serde = "1.0.130"
serde_derive = "1.0.103"
solana-program = "1.8.0"
spl-token = { version = "3.2", path = "../../token/program", features = [ "no-entrypoint" ] }
spl-governance-tools= { version = "0.1.0", path ="../tools"}
thiserror = "1.0"

[dev-dependencies]
assert_matches = "1.5.0"
base64 = "0.13"
lazy_static = "1.4.0"
proptest = "1.0"
solana-program-test = "1.8.0"
solana-sdk = "1.8.0"
spl-governance-test-sdk = { version = "0.1.0", path ="../test-sdk"}
spl-governance-v1 = {package="spl-governance", version = "1.1.1", features = [ "no-entrypoint" ] }


[lib]
crate-type = ["cdylib", "lib"]
9 changes: 3 additions & 6 deletions governance/program/src/addins/voter_weight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@ use solana_program::{
pubkey::Pubkey,
sysvar::Sysvar,
};
use spl_governance_tools::account::{get_account_data, AccountMaxSize};

use crate::{
error::GovernanceError,
state::token_owner_record::TokenOwnerRecord,
tools::account::{get_account_data, AccountMaxSize},
};
use crate::{error::GovernanceError, state::token_owner_record::TokenOwnerRecord};

/// VoterWeight account type
#[derive(Clone, Debug, PartialEq, BorshDeserialize, BorshSerialize, BorshSchema)]
Expand Down Expand Up @@ -82,7 +79,7 @@ pub fn get_voter_weight_record_data(
program_id: &Pubkey,
voter_weight_record_info: &AccountInfo,
) -> Result<VoterWeightRecord, ProgramError> {
get_account_data::<VoterWeightRecord>(voter_weight_record_info, program_id)
get_account_data::<VoterWeightRecord>(program_id, voter_weight_record_info)
}

/// Deserializes VoterWeightRecord account, checks owner program and asserts it's for the same realm, mint and token owner as the provided TokenOwnerRecord
Expand Down
14 changes: 0 additions & 14 deletions governance/program/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,20 +162,6 @@ pub enum GovernanceError {
#[error("Invalid Signatory Mint")]
InvalidSignatoryMint,

/// ---- Account Tools Errors ----
/// Invalid account owner
#[error("Invalid account owner")]
InvalidAccountOwner,

/// Account doesn't exist
#[error("Account doesn't exist")]
AccountDoesNotExist,

/// Invalid Account type
#[error("Invalid Account type")]
InvalidAccountType,

/// Proposal does not belong to the given Governance
#[error("Proposal does not belong to the given Governance")]
InvalidGovernanceForProposal,
Expand Down
14 changes: 6 additions & 8 deletions governance/program/src/processor/process_add_signatory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@ use solana_program::{
rent::Rent,
sysvar::Sysvar,
};
use spl_governance_tools::account::create_and_serialize_account_signed;

use crate::{
state::{
enums::GovernanceAccountType,
proposal::get_proposal_data,
signatory_record::{get_signatory_record_address_seeds, SignatoryRecord},
token_owner_record::get_token_owner_record_data_for_proposal_owner,
},
tools::account::create_and_serialize_account_signed,
use crate::state::{
enums::GovernanceAccountType,
proposal::get_proposal_data,
signatory_record::{get_signatory_record_address_seeds, SignatoryRecord},
token_owner_record::get_token_owner_record_data_for_proposal_owner,
};

/// Processes AddSignatory instruction
Expand Down
3 changes: 2 additions & 1 deletion governance/program/src/processor/process_cast_vote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use solana_program::{
rent::Rent,
sysvar::Sysvar,
};
use spl_governance_tools::account::create_and_serialize_account_signed;

use crate::{
error::GovernanceError,
Expand All @@ -23,7 +24,7 @@ use crate::{
},
vote_record::{get_vote_record_address_seeds, VoteRecord},
},
tools::{account::create_and_serialize_account_signed, spl_token::get_spl_token_mint_supply},
tools::spl_token::get_spl_token_mint_supply,
};

use borsh::BorshSerialize;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
//! Program state processor
use crate::{
state::{
enums::GovernanceAccountType,
governance::{
assert_valid_create_governance_args, get_account_governance_address_seeds, Governance,
GovernanceConfig,
},
realm::get_realm_data,
token_owner_record::get_token_owner_record_data_for_realm,
use crate::state::{
enums::GovernanceAccountType,
governance::{
assert_valid_create_governance_args, get_account_governance_address_seeds, Governance,
GovernanceConfig,
},
tools::account::create_and_serialize_account_signed,
realm::get_realm_data,
token_owner_record::get_token_owner_record_data_for_realm,
};
use solana_program::{
account_info::{next_account_info, AccountInfo},
Expand All @@ -19,6 +16,7 @@ use solana_program::{
rent::Rent,
sysvar::Sysvar,
};
use spl_governance_tools::account::create_and_serialize_account_signed;

/// Processes CreateAccountGovernance instruction
pub fn process_create_account_governance(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ use crate::{
realm::get_realm_data,
token_owner_record::get_token_owner_record_data_for_realm,
},
tools::{
account::create_and_serialize_account_signed,
spl_token::{assert_spl_token_mint_authority_is_signer, set_spl_token_mint_authority},
},
tools::spl_token::{assert_spl_token_mint_authority_is_signer, set_spl_token_mint_authority},
};
use solana_program::{
account_info::{next_account_info, AccountInfo},
Expand All @@ -22,6 +19,7 @@ use solana_program::{
rent::Rent,
sysvar::Sysvar,
};
use spl_governance_tools::account::create_and_serialize_account_signed;

/// Processes CreateMintGovernance instruction
pub fn process_create_mint_governance(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@ use crate::{
realm::get_realm_data,
token_owner_record::get_token_owner_record_data_for_realm,
},
tools::{
account::create_and_serialize_account_signed,
bpf_loader_upgradeable::{
assert_program_upgrade_authority_is_signer, set_program_upgrade_authority,
},
tools::bpf_loader_upgradeable::{
assert_program_upgrade_authority_is_signer, set_program_upgrade_authority,
},
};
use solana_program::{
Expand All @@ -25,6 +22,7 @@ use solana_program::{
rent::Rent,
sysvar::Sysvar,
};
use spl_governance_tools::account::create_and_serialize_account_signed;

/// Processes CreateProgramGovernance instruction
pub fn process_create_program_governance(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use solana_program::{
rent::Rent,
sysvar::Sysvar,
};
use spl_governance_tools::account::create_and_serialize_account_signed;

use crate::{
error::GovernanceError,
Expand All @@ -19,7 +20,6 @@ use crate::{
realm::get_realm_data_for_governing_token_mint,
token_owner_record::get_token_owner_record_data_for_realm,
},
tools::account::create_and_serialize_account_signed,
};

/// Processes CreateProposal instruction
Expand Down
Loading

0 comments on commit d6d0b92

Please sign in to comment.