Refactor stake program into solana_program (#17906)

* 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
This commit is contained in:
Jon Cinque
2021-06-15 18:04:00 +02:00
committed by GitHub
parent 36b09db2d1
commit 1b1d34da59
59 changed files with 1765 additions and 1711 deletions

View File

@ -11,12 +11,13 @@ use solana_sdk::{
message::Message,
pubkey::Pubkey,
signature::{Keypair, Signer},
stake::{
self, instruction as stake_instruction,
state::{Authorized, Lockup, StakeState},
},
sysvar::{self, stake_history::StakeHistory},
};
use solana_stake_program::{
stake_instruction::{self},
stake_state::{self, StakeState},
};
use solana_stake_program::stake_state;
use solana_vote_program::{
vote_instruction,
vote_state::{Vote, VoteInit, VoteState, VoteStateVersions},
@ -69,7 +70,7 @@ fn fill_epoch_with_votes(
}
fn warmed_up(bank: &Bank, stake_pubkey: &Pubkey) -> bool {
let stake = StakeState::stake_from(&bank.get_account(stake_pubkey).unwrap()).unwrap();
let stake = stake_state::stake_from(&bank.get_account(stake_pubkey).unwrap()).unwrap();
stake.delegation.stake
== stake.stake(
@ -85,7 +86,7 @@ fn warmed_up(bank: &Bank, stake_pubkey: &Pubkey) -> bool {
}
fn get_staked(bank: &Bank, stake_pubkey: &Pubkey) -> u64 {
StakeState::stake_from(&bank.get_account(stake_pubkey).unwrap())
stake_state::stake_from(&bank.get_account(stake_pubkey).unwrap())
.unwrap()
.stake(
bank.epoch(),
@ -118,9 +119,9 @@ fn test_stake_create_and_split_single_signature() {
let bank_client = BankClient::new_shared(&Arc::new(Bank::new(&genesis_config)));
let stake_address =
Pubkey::create_with_seed(&staker_pubkey, "stake", &solana_stake_program::id()).unwrap();
Pubkey::create_with_seed(&staker_pubkey, "stake", &stake::program::id()).unwrap();
let authorized = stake_state::Authorized::auto(&staker_pubkey);
let authorized = Authorized::auto(&staker_pubkey);
let lamports = 1_000_000;
@ -132,7 +133,7 @@ fn test_stake_create_and_split_single_signature() {
&staker_pubkey, // base
"stake", // seed
&authorized,
&stake_state::Lockup::default(),
&Lockup::default(),
lamports,
),
Some(&staker_pubkey),
@ -145,8 +146,7 @@ fn test_stake_create_and_split_single_signature() {
// split the stake
let split_stake_address =
Pubkey::create_with_seed(&staker_pubkey, "split_stake", &solana_stake_program::id())
.unwrap();
Pubkey::create_with_seed(&staker_pubkey, "split_stake", &stake::program::id()).unwrap();
// Test split
let message = Message::new(
&stake_instruction::split_with_seed(
@ -189,9 +189,9 @@ fn test_stake_create_and_split_to_existing_system_account() {
let bank_client = BankClient::new_shared(&Arc::new(Bank::new(&genesis_config)));
let stake_address =
Pubkey::create_with_seed(&staker_pubkey, "stake", &solana_stake_program::id()).unwrap();
Pubkey::create_with_seed(&staker_pubkey, "stake", &stake::program::id()).unwrap();
let authorized = stake_state::Authorized::auto(&staker_pubkey);
let authorized = Authorized::auto(&staker_pubkey);
let lamports = 1_000_000;
@ -203,7 +203,7 @@ fn test_stake_create_and_split_to_existing_system_account() {
&staker_pubkey, // base
"stake", // seed
&authorized,
&stake_state::Lockup::default(),
&Lockup::default(),
lamports,
),
Some(&staker_pubkey),
@ -214,8 +214,7 @@ fn test_stake_create_and_split_to_existing_system_account() {
.expect("failed to create and delegate stake account");
let split_stake_address =
Pubkey::create_with_seed(&staker_pubkey, "split_stake", &solana_stake_program::id())
.unwrap();
Pubkey::create_with_seed(&staker_pubkey, "split_stake", &stake::program::id()).unwrap();
// First, put a system account where we want the new stake account
let existing_lamports = 42;
@ -290,7 +289,7 @@ fn test_stake_account_lifetime() {
.send_and_confirm_message(&[&mint_keypair, &vote_keypair, &identity_keypair], message)
.expect("failed to create vote account");
let authorized = stake_state::Authorized::auto(&stake_pubkey);
let authorized = Authorized::auto(&stake_pubkey);
// Create stake account and delegate to vote account
let message = Message::new(
&stake_instruction::create_account_and_delegate_stake(
@ -298,7 +297,7 @@ fn test_stake_account_lifetime() {
&stake_pubkey,
&vote_pubkey,
&authorized,
&stake_state::Lockup::default(),
&Lockup::default(),
1_000_000,
),
Some(&mint_pubkey),
@ -516,8 +515,7 @@ fn test_create_stake_account_from_seed() {
let bank_client = BankClient::new_shared(&bank);
let seed = "test-string";
let stake_pubkey =
Pubkey::create_with_seed(&mint_pubkey, seed, &solana_stake_program::id()).unwrap();
let stake_pubkey = Pubkey::create_with_seed(&mint_pubkey, seed, &stake::program::id()).unwrap();
// Create Vote Account
let message = Message::new(
@ -538,7 +536,7 @@ fn test_create_stake_account_from_seed() {
.send_and_confirm_message(&[&mint_keypair, &vote_keypair, &identity_keypair], message)
.expect("failed to create vote account");
let authorized = stake_state::Authorized::auto(&mint_pubkey);
let authorized = Authorized::auto(&mint_pubkey);
// Create stake account and delegate to vote account
let message = Message::new(
&stake_instruction::create_account_with_seed_and_delegate_stake(
@ -548,7 +546,7 @@ fn test_create_stake_account_from_seed() {
seed,
&vote_pubkey,
&authorized,
&stake_state::Lockup::default(),
&Lockup::default(),
1_000_000,
),
Some(&mint_pubkey),