Skip to content

Commit

Permalink
Refactor stake program into solana_program (solana-labs#17906)
Browse files Browse the repository at this point in the history
* Move stake state / instructions into solana_program

* Update account-decoder

* Update cli and runtime

* Update all other parts

* Commit Cargo.lock changes in programs/bpf

* Update cli stake instruction import

* Allow integer arithmetic

* Update ABI digest

* Bump rust mem instruction count

* Remove useless structs

* Move stake::id() -> stake::program::id()

* Re-export from solana_sdk and mark deprecated

* Address feedback

* Run cargo fmt
  • Loading branch information
joncinque authored Jun 15, 2021
1 parent 36b09db commit 1b1d34d
Show file tree
Hide file tree
Showing 59 changed files with 1,741 additions and 1,687 deletions.
9 changes: 0 additions & 9 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion account-decoder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ serde_derive = "1.0.103"
serde_json = "1.0.64"
solana-config-program = { path = "../programs/config", version = "=1.8.0" }
solana-sdk = { path = "../sdk", version = "=1.8.0" }
solana-stake-program = { path = "../programs/stake", version = "=1.8.0" }
solana-vote-program = { path = "../programs/vote", version = "=1.8.0" }
spl-token-v2-0 = { package = "spl-token", version = "=3.1.1", features = ["no-entrypoint"] }
thiserror = "1.0"
Expand Down
4 changes: 2 additions & 2 deletions account-decoder/src/parse_account_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ use crate::{
};
use inflector::Inflector;
use serde_json::Value;
use solana_sdk::{instruction::InstructionError, pubkey::Pubkey, system_program, sysvar};
use solana_sdk::{instruction::InstructionError, pubkey::Pubkey, stake, system_program, sysvar};
use std::collections::HashMap;
use thiserror::Error;

lazy_static! {
static ref BPF_UPGRADEABLE_LOADER_PROGRAM_ID: Pubkey = solana_sdk::bpf_loader_upgradeable::id();
static ref CONFIG_PROGRAM_ID: Pubkey = solana_config_program::id();
static ref STAKE_PROGRAM_ID: Pubkey = solana_stake_program::id();
static ref STAKE_PROGRAM_ID: Pubkey = stake::program::id();
static ref SYSTEM_PROGRAM_ID: Pubkey = system_program::id();
static ref SYSVAR_PROGRAM_ID: Pubkey = sysvar::id();
static ref TOKEN_PROGRAM_ID: Pubkey = spl_token_id_v2_0();
Expand Down
10 changes: 3 additions & 7 deletions account-decoder/src/parse_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ use bincode::deserialize;
use serde_json::Value;
use solana_config_program::{get_config_data, ConfigKeys};
use solana_sdk::pubkey::Pubkey;
use solana_stake_program::config::Config as StakeConfig;
use solana_sdk::stake::config::{self as stake_config, Config as StakeConfig};

pub fn parse_config(data: &[u8], pubkey: &Pubkey) -> Result<ConfigAccountType, ParseAccountError> {
let parsed_account = if pubkey == &solana_stake_program::config::id() {
let parsed_account = if pubkey == &stake_config::id() {
get_config_data(data)
.ok()
.and_then(|data| deserialize::<StakeConfig>(data).ok())
Expand Down Expand Up @@ -101,11 +101,7 @@ mod test {
};
let stake_config_account = create_config_account(vec![], &stake_config, 10);
assert_eq!(
parse_config(
&stake_config_account.data(),
&solana_stake_program::config::id()
)
.unwrap(),
parse_config(&stake_config_account.data(), &stake_config::id()).unwrap(),
ConfigAccountType::StakeConfig(UiStakeConfig {
warmup_cooldown_rate: 0.25,
slash_penalty: 50,
Expand Down
2 changes: 1 addition & 1 deletion account-decoder/src/parse_stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
};
use bincode::deserialize;
use solana_sdk::clock::{Epoch, UnixTimestamp};
use solana_stake_program::stake_state::{Authorized, Delegation, Lockup, Meta, Stake, StakeState};
use solana_sdk::stake::state::{Authorized, Delegation, Lockup, Meta, Stake, StakeState};

pub fn parse_stake(data: &[u8]) -> Result<StakeAccountType, ParseAccountError> {
let stake_state: StakeState = deserialize(data)
Expand Down
1 change: 0 additions & 1 deletion cli-output/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ solana-account-decoder = { path = "../account-decoder", version = "=1.8.0" }
solana-clap-utils = { path = "../clap-utils", version = "=1.8.0" }
solana-client = { path = "../client", version = "=1.8.0" }
solana-sdk = { path = "../sdk", version = "=1.8.0" }
solana-stake-program = { path = "../programs/stake", version = "=1.8.0" }
solana-transaction-status = { path = "../transaction-status", version = "=1.8.0" }
solana-vote-program = { path = "../programs/vote", version = "=1.8.0" }
spl-memo = { version = "=3.0.1", features = ["no-entrypoint"] }
Expand Down
2 changes: 1 addition & 1 deletion cli-output/src/cli_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ use {
native_token::lamports_to_sol,
pubkey::Pubkey,
signature::Signature,
stake::state::{Authorized, Lockup},
stake_history::StakeHistoryEntry,
transaction::{Transaction, TransactionError},
},
solana_stake_program::stake_state::{Authorized, Lockup},
solana_transaction_status::{
EncodedConfirmedBlock, EncodedTransaction, TransactionConfirmationStatus,
UiTransactionStatusMeta,
Expand Down
9 changes: 4 additions & 5 deletions cli-output/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use {
indicatif::{ProgressBar, ProgressStyle},
solana_sdk::{
clock::UnixTimestamp, hash::Hash, message::Message, native_token::lamports_to_sol,
program_utils::limited_deserialize, pubkey::Pubkey, transaction::Transaction,
program_utils::limited_deserialize, pubkey::Pubkey, stake, transaction::Transaction,
},
solana_transaction_status::UiTransactionStatusMeta,
spl_memo::id as spl_memo_id,
Expand Down Expand Up @@ -244,10 +244,9 @@ pub fn write_transaction<W: io::Write>(
writeln!(w, "{} {:?}", prefix, vote_instruction)?;
raw = false;
}
} else if program_pubkey == solana_stake_program::id() {
if let Ok(stake_instruction) = limited_deserialize::<
solana_stake_program::stake_instruction::StakeInstruction,
>(&instruction.data)
} else if program_pubkey == stake::program::id() {
if let Ok(stake_instruction) =
limited_deserialize::<stake::instruction::StakeInstruction>(&instruction.data)
{
writeln!(w, "{} {:?}", prefix, stake_instruction)?;
raw = false;
Expand Down
1 change: 0 additions & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ solana-net-utils = { path = "../net-utils", version = "=1.8.0" }
solana_rbpf = "=0.2.12"
solana-remote-wallet = { path = "../remote-wallet", version = "=1.8.0" }
solana-sdk = { path = "../sdk", version = "=1.8.0" }
solana-stake-program = { path = "../programs/stake", version = "=1.8.0" }
solana-transaction-status = { path = "../transaction-status", version = "=1.8.0" }
solana-version = { path = "../version", version = "=1.8.0" }
solana-vote-program = { path = "../programs/vote", version = "=1.8.0" }
Expand Down
21 changes: 11 additions & 10 deletions cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,15 @@ use solana_sdk::{
message::Message,
pubkey::Pubkey,
signature::{Signature, Signer, SignerError},
stake::{
self,
instruction::LockupArgs,
state::{Lockup, StakeAuthorize},
},
system_instruction::{self, SystemError},
system_program,
transaction::{Transaction, TransactionError},
};
use solana_stake_program::{
stake_instruction::LockupArgs,
stake_state::{Lockup, StakeAuthorize},
};
use solana_transaction_status::{EncodedTransaction, UiTransactionEncoding};
use solana_vote_program::vote_state::VoteAuthorize;
use std::{
Expand Down Expand Up @@ -932,7 +933,7 @@ pub type ProcessResult = Result<String, Box<dyn std::error::Error>>;
fn resolve_derived_address_program_id(matches: &ArgMatches<'_>, arg_name: &str) -> Option<Pubkey> {
matches.value_of(arg_name).and_then(|v| match v {
"NONCE" => Some(system_program::id()),
"STAKE" => Some(solana_stake_program::id()),
"STAKE" => Some(stake::program::id()),
"VOTE" => Some(solana_vote_program::id()),
_ => pubkey_of(matches, arg_name),
})
Expand Down Expand Up @@ -2487,7 +2488,7 @@ mod tests {
let from_pubkey = Some(solana_sdk::pubkey::new_rand());
let from_str = from_pubkey.unwrap().to_string();
for (name, program_id) in &[
("STAKE", solana_stake_program::id()),
("STAKE", stake::program::id()),
("VOTE", solana_vote_program::id()),
("NONCE", system_program::id()),
] {
Expand Down Expand Up @@ -2523,7 +2524,7 @@ mod tests {
command: CliCommand::CreateAddressWithSeed {
from_pubkey: None,
seed: "seed".to_string(),
program_id: solana_stake_program::id(),
program_id: stake::program::id(),
},
signers: vec![read_keypair_file(&keypair_file).unwrap().into()],
}
Expand Down Expand Up @@ -2786,11 +2787,11 @@ mod tests {
config.command = CliCommand::CreateAddressWithSeed {
from_pubkey: Some(from_pubkey),
seed: "seed".to_string(),
program_id: solana_stake_program::id(),
program_id: stake::program::id(),
};
let address = process_command(&config);
let expected_address =
Pubkey::create_with_seed(&from_pubkey, "seed", &solana_stake_program::id()).unwrap();
Pubkey::create_with_seed(&from_pubkey, "seed", &stake::program::id()).unwrap();
assert_eq!(address.unwrap(), expected_address.to_string());

// Need airdrop cases
Expand Down Expand Up @@ -3177,7 +3178,7 @@ mod tests {
memo: None,
fee_payer: 0,
derived_address_seed: Some(derived_address_seed),
derived_address_program_id: Some(solana_stake_program::id()),
derived_address_program_id: Some(stake::program::id()),
},
signers: vec![read_keypair_file(&default_keypair_file).unwrap().into(),],
}
Expand Down
7 changes: 4 additions & 3 deletions cli/src/cluster_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ use solana_sdk::{
rent::Rent,
rpc_port::DEFAULT_RPC_PORT_STR,
signature::Signature,
slot_history, system_instruction, system_program,
slot_history,
stake::{self, state::StakeState},
system_instruction, system_program,
sysvar::{
self,
slot_history::SlotHistory,
Expand All @@ -55,7 +57,6 @@ use solana_sdk::{
timing,
transaction::Transaction,
};
use solana_stake_program::stake_state::StakeState;
use solana_transaction_status::UiTransactionEncoding;
use solana_vote_program::vote_state::VoteState;
use std::{
Expand Down Expand Up @@ -1704,7 +1705,7 @@ pub fn process_show_stakes(
}
}
let all_stake_accounts = rpc_client
.get_program_accounts_with_config(&solana_stake_program::id(), program_accounts_config)?;
.get_program_accounts_with_config(&stake::program::id(), program_accounts_config)?;
let stake_history_account = rpc_client.get_account(&stake_history::id())?;
let clock_account = rpc_client.get_account(&sysvar::clock::id())?;
let clock: Clock = from_account(&clock_account).ok_or_else(|| {
Expand Down
29 changes: 13 additions & 16 deletions cli/src/stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,18 @@ use solana_sdk::{
feature, feature_set,
message::Message,
pubkey::Pubkey,
stake::{
self,
instruction::{self as stake_instruction, LockupArgs, StakeError},
state::{Authorized, Lockup, Meta, StakeAuthorize, StakeState},
},
system_instruction::SystemError,
sysvar::{
clock,
stake_history::{self, StakeHistory},
},
transaction::Transaction,
};
use solana_stake_program::{
stake_instruction::{self, LockupArgs, StakeError},
stake_state::{Authorized, Lockup, Meta, StakeAuthorize, StakeState},
};
use solana_vote_program::vote_state::VoteState;
use std::{ops::Deref, sync::Arc};

Expand Down Expand Up @@ -971,7 +972,7 @@ pub fn process_create_stake_account(
) -> ProcessResult {
let stake_account = config.signers[stake_account];
let stake_account_address = if let Some(seed) = seed {
Pubkey::create_with_seed(&stake_account.pubkey(), &seed, &solana_stake_program::id())?
Pubkey::create_with_seed(&stake_account.pubkey(), &seed, &stake::program::id())?
} else {
stake_account.pubkey()
};
Expand Down Expand Up @@ -1039,7 +1040,7 @@ pub fn process_create_stake_account(

if !sign_only {
if let Ok(stake_account) = rpc_client.get_account(&stake_account_address) {
let err_msg = if stake_account.owner == solana_stake_program::id() {
let err_msg = if stake_account.owner == stake::program::id() {
format!("Stake account {} already exists", stake_account_address)
} else {
format!(
Expand Down Expand Up @@ -1195,7 +1196,7 @@ pub fn process_deactivate_stake_account(
let stake_authority = config.signers[stake_authority];

let stake_account_address = if let Some(seed) = seed {
Pubkey::create_with_seed(&stake_account_pubkey, seed, &solana_stake_program::id())?
Pubkey::create_with_seed(&stake_account_pubkey, seed, &stake::program::id())?
} else {
*stake_account_pubkey
};
Expand Down Expand Up @@ -1273,7 +1274,7 @@ pub fn process_withdraw_stake(
let custodian = custodian.map(|index| config.signers[index]);

let stake_account_address = if let Some(seed) = seed {
Pubkey::create_with_seed(&stake_account_pubkey, seed, &solana_stake_program::id())?
Pubkey::create_with_seed(&stake_account_pubkey, seed, &stake::program::id())?
} else {
*stake_account_pubkey
};
Expand Down Expand Up @@ -1394,18 +1395,14 @@ pub fn process_split_stake(
let stake_authority = config.signers[stake_authority];

let split_stake_account_address = if let Some(seed) = split_stake_account_seed {
Pubkey::create_with_seed(
&split_stake_account.pubkey(),
&seed,
&solana_stake_program::id(),
)?
Pubkey::create_with_seed(&split_stake_account.pubkey(), &seed, &stake::program::id())?
} else {
split_stake_account.pubkey()
};

if !sign_only {
if let Ok(stake_account) = rpc_client.get_account(&split_stake_account_address) {
let err_msg = if stake_account.owner == solana_stake_program::id() {
let err_msg = if stake_account.owner == stake::program::id() {
format!(
"Stake account {} already exists",
split_stake_account_address
Expand Down Expand Up @@ -1540,7 +1537,7 @@ pub fn process_merge_stake(
if !sign_only {
for stake_account_address in &[stake_account_pubkey, source_stake_account_pubkey] {
if let Ok(stake_account) = rpc_client.get_account(stake_account_address) {
if stake_account.owner != solana_stake_program::id() {
if stake_account.owner != stake::program::id() {
return Err(CliError::BadParameter(format!(
"Account {} is not a stake account",
stake_account_address
Expand Down Expand Up @@ -1876,7 +1873,7 @@ pub fn process_show_stake_account(
with_rewards: Option<usize>,
) -> ProcessResult {
let stake_account = rpc_client.get_account(stake_account_address)?;
if stake_account.owner != solana_stake_program::id() {
if stake_account.owner != stake::program::id() {
return Err(CliError::RpcRequestError(format!(
"{:?} is not a stake account",
stake_account_address,
Expand Down
Loading

0 comments on commit 1b1d34d

Please sign in to comment.