Skip to content

Commit

Permalink
Move nonce into system program (bp #7645) (#7671)
Browse files Browse the repository at this point in the history
automerge
  • Loading branch information
mergify[bot] authored and solana-grimes committed Jan 4, 2020
1 parent 0d13352 commit cee2226
Show file tree
Hide file tree
Showing 16 changed files with 1,137 additions and 855 deletions.
10 changes: 4 additions & 6 deletions cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,6 @@ pub fn parse_create_address_with_seed(
"STAKE" => solana_stake_program::id(),
"VOTE" => solana_vote_program::id(),
"STORAGE" => solana_storage_program::id(),
"NONCE" => solana_sdk::nonce_program::id(),
_ => pubkey_of(matches, "program_id").unwrap(),
};

Expand Down Expand Up @@ -1769,7 +1768,7 @@ pub fn app<'ab, 'v>(name: &str, about: &'ab str, version: &'v str) -> App<'ab, '
.required(true)
.help(
"The program_id that the address will ultimately be used for, \n\
or one of STAKE, VOTE, NONCE, and STORAGE keywords",
or one of STAKE, VOTE, and STORAGE keywords",
),
)
.arg(
Expand Down Expand Up @@ -1985,9 +1984,9 @@ mod tests {
};
use solana_sdk::{
account::Account,
nonce_program,
nonce_state::{Meta as NonceMeta, NonceState},
signature::{read_keypair_file, write_keypair_file},
system_program,
transaction::TransactionError,
};
use std::{collections::HashMap, path::PathBuf};
Expand Down Expand Up @@ -2123,7 +2122,6 @@ mod tests {
for (name, program_id) in &[
("STAKE", solana_stake_program::id()),
("VOTE", solana_vote_program::id()),
("NONCE", solana_sdk::nonce_program::id()),
("STORAGE", solana_storage_program::id()),
] {
let test_create_address_with_seed = test_commands.clone().get_matches_from(vec![
Expand Down Expand Up @@ -2665,7 +2663,7 @@ mod tests {
value: json!(Account::new_data(
1,
&NonceState::Initialized(NonceMeta::new(&config.keypair.pubkey()), blockhash),
&nonce_program::ID,
&system_program::ID,
)
.unwrap()),
});
Expand All @@ -2691,7 +2689,7 @@ mod tests {
value: json!(Account::new_data(
1,
&NonceState::Initialized(NonceMeta::new(&bob_pubkey), blockhash),
&nonce_program::ID,
&system_program::ID,
)
.unwrap()),
});
Expand Down
32 changes: 17 additions & 15 deletions cli/src/nonce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ use solana_sdk::{
account::Account,
account_utils::State,
hash::Hash,
nonce_instruction::{authorize, create_nonce_account, nonce, withdraw, NonceError},
nonce_program,
nonce_state::NonceState,
pubkey::Pubkey,
signature::{Keypair, KeypairUtil},
system_instruction::SystemError,
system_instruction::{
create_nonce_account, nonce_advance, nonce_authorize, nonce_withdraw, NonceError,
SystemError,
},
system_program,
transaction::Transaction,
};

Expand Down Expand Up @@ -298,7 +300,7 @@ pub fn check_nonce_account(
nonce_authority: &Pubkey,
nonce_hash: &Hash,
) -> Result<(), Box<CliError>> {
if nonce_account.owner != nonce_program::ID {
if nonce_account.owner != system_program::ID {
return Err(CliError::InvalidNonce(CliNonceError::InvalidAccountOwner).into());
}
let nonce_state: NonceState = nonce_account
Expand Down Expand Up @@ -330,7 +332,7 @@ pub fn process_authorize_nonce_account(
let (recent_blockhash, fee_calculator) = rpc_client.get_recent_blockhash()?;

let nonce_authority = nonce_authority.unwrap_or(&config.keypair);
let ix = authorize(nonce_account, &nonce_authority.pubkey(), new_authority);
let ix = nonce_authorize(nonce_account, &nonce_authority.pubkey(), new_authority);
let mut tx = Transaction::new_signed_with_payer(
vec![ix],
Some(&config.keypair.pubkey()),
Expand Down Expand Up @@ -405,7 +407,7 @@ pub fn process_create_nonce_account(

pub fn process_get_nonce(rpc_client: &RpcClient, nonce_account_pubkey: &Pubkey) -> ProcessResult {
let nonce_account = rpc_client.get_account(nonce_account_pubkey)?;
if nonce_account.owner != nonce_program::id() {
if nonce_account.owner != system_program::id() {
return Err(CliError::RpcRequestError(format!(
"{:?} is not a nonce account",
nonce_account_pubkey
Expand Down Expand Up @@ -442,7 +444,7 @@ pub fn process_new_nonce(
}

let nonce_authority = nonce_authority.unwrap_or(&config.keypair);
let ix = nonce(&nonce_account, &nonce_authority.pubkey());
let ix = nonce_advance(&nonce_account, &nonce_authority.pubkey());
let (recent_blockhash, fee_calculator) = rpc_client.get_recent_blockhash()?;
let mut tx = Transaction::new_signed_with_payer(
vec![ix],
Expand All @@ -467,7 +469,7 @@ pub fn process_show_nonce_account(
use_lamports_unit: bool,
) -> ProcessResult {
let nonce_account = rpc_client.get_account(nonce_account_pubkey)?;
if nonce_account.owner != nonce_program::id() {
if nonce_account.owner != system_program::id() {
return Err(CliError::RpcRequestError(format!(
"{:?} is not a nonce account",
nonce_account_pubkey
Expand Down Expand Up @@ -515,7 +517,7 @@ pub fn process_withdraw_from_nonce_account(
let (recent_blockhash, fee_calculator) = rpc_client.get_recent_blockhash()?;

let nonce_authority = nonce_authority.unwrap_or(&config.keypair);
let ix = withdraw(
let ix = nonce_withdraw(
nonce_account,
&nonce_authority.pubkey(),
destination_account_pubkey,
Expand Down Expand Up @@ -802,14 +804,14 @@ mod tests {
let valid = Account::new_data(
1,
&NonceState::Initialized(NonceMeta::new(&nonce_pubkey), blockhash),
&nonce_program::ID,
&system_program::ID,
);
assert!(check_nonce_account(&valid.unwrap(), &nonce_pubkey, &blockhash).is_ok());

let invalid_owner = Account::new_data(
1,
&NonceState::Initialized(NonceMeta::new(&nonce_pubkey), blockhash),
&system_program::ID,
&Pubkey::new(&[1u8; 32]),
);
assert_eq!(
check_nonce_account(&invalid_owner.unwrap(), &nonce_pubkey, &blockhash),
Expand All @@ -818,7 +820,7 @@ mod tests {
))),
);

let invalid_data = Account::new_data(1, &"invalid", &nonce_program::ID);
let invalid_data = Account::new_data(1, &"invalid", &system_program::ID);
assert_eq!(
check_nonce_account(&invalid_data.unwrap(), &nonce_pubkey, &blockhash),
Err(Box::new(CliError::InvalidNonce(
Expand All @@ -829,7 +831,7 @@ mod tests {
let invalid_hash = Account::new_data(
1,
&NonceState::Initialized(NonceMeta::new(&nonce_pubkey), hash(b"invalid")),
&nonce_program::ID,
&system_program::ID,
);
assert_eq!(
check_nonce_account(&invalid_hash.unwrap(), &nonce_pubkey, &blockhash),
Expand All @@ -839,7 +841,7 @@ mod tests {
let invalid_authority = Account::new_data(
1,
&NonceState::Initialized(NonceMeta::new(&Pubkey::new_rand()), blockhash),
&nonce_program::ID,
&system_program::ID,
);
assert_eq!(
check_nonce_account(&invalid_authority.unwrap(), &nonce_pubkey, &blockhash),
Expand All @@ -848,7 +850,7 @@ mod tests {
))),
);

let invalid_state = Account::new_data(1, &NonceState::Uninitialized, &nonce_program::ID);
let invalid_state = Account::new_data(1, &NonceState::Uninitialized, &system_program::ID);
assert_eq!(
check_nonce_account(&invalid_state.unwrap(), &nonce_pubkey, &blockhash),
Err(Box::new(CliError::InvalidNonce(
Expand Down
9 changes: 2 additions & 7 deletions genesis-programs/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use solana_sdk::{
clock::Epoch, genesis_config::OperatingMode, inflation::Inflation,
move_loader::solana_move_loader_program, nonce_program::solana_nonce_program, pubkey::Pubkey,
system_program::solana_system_program,
move_loader::solana_move_loader_program, pubkey::Pubkey, system_program::solana_system_program,
};

#[macro_use]
Expand Down Expand Up @@ -59,7 +58,6 @@ pub fn get_programs(operating_mode: OperatingMode, epoch: Epoch) -> Option<Vec<(
solana_system_program(),
solana_bpf_loader_program!(),
solana_config_program!(),
solana_nonce_program(),
solana_stake_program!(),
solana_storage_program!(),
solana_vest_program!(),
Expand All @@ -77,7 +75,6 @@ pub fn get_programs(operating_mode: OperatingMode, epoch: Epoch) -> Option<Vec<(
if epoch == 0 {
// Nonce, Voting, Staking and System Program only at epoch 0
Some(vec![
solana_nonce_program(),
solana_stake_program!(),
solana_system_program(),
solana_vote_program!(),
Expand Down Expand Up @@ -127,7 +124,6 @@ pub fn get_entered_epoch_callback(operating_mode: OperatingMode) -> EnteredEpoch
#[cfg(test)]
mod tests {
use super::*;
use solana_sdk::nonce_program::solana_nonce_program;
use std::collections::HashSet;

#[test]
Expand All @@ -150,7 +146,7 @@ mod tests {
fn test_development_programs() {
assert_eq!(
get_programs(OperatingMode::Development, 0).unwrap().len(),
11
10
);
assert_eq!(get_programs(OperatingMode::Development, 1), None);
}
Expand All @@ -173,7 +169,6 @@ mod tests {
assert_eq!(
get_programs(OperatingMode::SoftLaunch, 0),
Some(vec![
solana_nonce_program(),
solana_stake_program!(),
solana_system_program(),
solana_vote_program!(),
Expand Down
Loading

0 comments on commit cee2226

Please sign in to comment.