SDK: Re-org nonce state module to facilitate versioning (#8603)
automerge
This commit is contained in:
@@ -17,8 +17,7 @@ use solana_sdk::{
|
||||
account::Account,
|
||||
clock::Slot,
|
||||
hash::Hash,
|
||||
native_loader,
|
||||
nonce_state::NonceState,
|
||||
native_loader, nonce,
|
||||
pubkey::Pubkey,
|
||||
transaction::Result,
|
||||
transaction::{Transaction, TransactionError},
|
||||
@@ -160,7 +159,7 @@ impl Accounts {
|
||||
})? {
|
||||
SystemAccountKind::System => 0,
|
||||
SystemAccountKind::Nonce => {
|
||||
rent_collector.rent.minimum_balance(NonceState::size())
|
||||
rent_collector.rent.minimum_balance(nonce::State::size())
|
||||
}
|
||||
};
|
||||
|
||||
@@ -681,7 +680,7 @@ mod tests {
|
||||
hash::Hash,
|
||||
instruction::CompiledInstruction,
|
||||
message::Message,
|
||||
nonce_state,
|
||||
nonce,
|
||||
rent::Rent,
|
||||
signature::{Keypair, Signer},
|
||||
system_program,
|
||||
@@ -915,17 +914,15 @@ mod tests {
|
||||
..Rent::default()
|
||||
},
|
||||
);
|
||||
let min_balance = rent_collector
|
||||
.rent
|
||||
.minimum_balance(nonce_state::NonceState::size());
|
||||
let min_balance = rent_collector.rent.minimum_balance(nonce::State::size());
|
||||
let fee_calculator = FeeCalculator::new(min_balance);
|
||||
let nonce = Keypair::new();
|
||||
let mut accounts = vec![(
|
||||
nonce.pubkey(),
|
||||
Account::new_data(
|
||||
min_balance * 2,
|
||||
&nonce_state::NonceState::Initialized(
|
||||
nonce_state::Meta::new(&Pubkey::default()),
|
||||
&nonce::State::Initialized(
|
||||
nonce::state::Meta::new(&Pubkey::default()),
|
||||
Hash::default(),
|
||||
),
|
||||
&system_program::id(),
|
||||
|
@@ -40,8 +40,7 @@ use solana_sdk::{
|
||||
hard_forks::HardForks,
|
||||
hash::{extend_and_hash, hashv, Hash},
|
||||
inflation::Inflation,
|
||||
native_loader,
|
||||
nonce_state::NonceState,
|
||||
native_loader, nonce,
|
||||
pubkey::Pubkey,
|
||||
signature::{Keypair, Signature},
|
||||
slot_hashes::SlotHashes,
|
||||
@@ -1691,9 +1690,10 @@ impl Bank {
|
||||
match self.get_account(pubkey) {
|
||||
Some(mut account) => {
|
||||
let min_balance = match get_system_account_kind(&account) {
|
||||
Some(SystemAccountKind::Nonce) => {
|
||||
self.rent_collector.rent.minimum_balance(NonceState::size())
|
||||
}
|
||||
Some(SystemAccountKind::Nonce) => self
|
||||
.rent_collector
|
||||
.rent
|
||||
.minimum_balance(nonce::State::size()),
|
||||
_ => 0,
|
||||
};
|
||||
if lamports + min_balance > account.lamports {
|
||||
@@ -2173,7 +2173,7 @@ mod tests {
|
||||
genesis_config::create_genesis_config,
|
||||
instruction::{AccountMeta, CompiledInstruction, Instruction, InstructionError},
|
||||
message::{Message, MessageHeader},
|
||||
nonce_state,
|
||||
nonce,
|
||||
poh_config::PohConfig,
|
||||
rent::Rent,
|
||||
signature::{Keypair, Signer},
|
||||
@@ -3421,13 +3421,12 @@ mod tests {
|
||||
genesis_config.rent.lamports_per_byte_year = 42;
|
||||
let bank = Bank::new(&genesis_config);
|
||||
|
||||
let min_balance =
|
||||
bank.get_minimum_balance_for_rent_exemption(nonce_state::NonceState::size());
|
||||
let min_balance = bank.get_minimum_balance_for_rent_exemption(nonce::State::size());
|
||||
let nonce = Keypair::new();
|
||||
let nonce_account = Account::new_data(
|
||||
min_balance + 42,
|
||||
&nonce_state::NonceState::Initialized(
|
||||
nonce_state::Meta::new(&Pubkey::default()),
|
||||
&nonce::State::Initialized(
|
||||
nonce::state::Meta::new(&Pubkey::default()),
|
||||
Hash::default(),
|
||||
),
|
||||
&system_program::id(),
|
||||
@@ -5108,7 +5107,7 @@ mod tests {
|
||||
fn get_nonce_account(bank: &Bank, nonce_pubkey: &Pubkey) -> Option<Hash> {
|
||||
bank.get_account(&nonce_pubkey)
|
||||
.and_then(|acc| match acc.state() {
|
||||
Ok(nonce_state::NonceState::Initialized(_meta, hash)) => Some(hash),
|
||||
Ok(nonce::State::Initialized(_meta, hash)) => Some(hash),
|
||||
_ => None,
|
||||
})
|
||||
}
|
||||
@@ -5282,8 +5281,8 @@ mod tests {
|
||||
let nonce = Keypair::new();
|
||||
let nonce_account = Account::new_data(
|
||||
42424242,
|
||||
&nonce_state::NonceState::Initialized(
|
||||
nonce_state::Meta::new(&Pubkey::default()),
|
||||
&nonce::State::Initialized(
|
||||
nonce::state::Meta::new(&Pubkey::default()),
|
||||
Hash::default(),
|
||||
),
|
||||
&system_program::id(),
|
||||
|
@@ -3,7 +3,7 @@ use solana_sdk::{
|
||||
account_utils::StateMut,
|
||||
hash::Hash,
|
||||
instruction::CompiledInstruction,
|
||||
nonce_state::NonceState,
|
||||
nonce::State,
|
||||
program_utils::limited_deserialize,
|
||||
pubkey::Pubkey,
|
||||
system_instruction::SystemInstruction,
|
||||
@@ -40,7 +40,7 @@ pub fn get_nonce_pubkey_from_instruction<'a>(
|
||||
|
||||
pub fn verify_nonce_account(acc: &Account, hash: &Hash) -> bool {
|
||||
match acc.state() {
|
||||
Ok(NonceState::Initialized(_meta, ref nonce)) => hash == nonce,
|
||||
Ok(State::Initialized(_meta, ref nonce)) => hash == nonce,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
@@ -60,9 +60,9 @@ pub fn prepare_if_nonce_account(
|
||||
*account = nonce_acc.clone()
|
||||
}
|
||||
// Since hash_age_kind is DurableNonce, unwrap is safe here
|
||||
if let NonceState::Initialized(meta, _) = account.state().unwrap() {
|
||||
if let State::Initialized(meta, _) = account.state().unwrap() {
|
||||
account
|
||||
.set_state(&NonceState::Initialized(meta, *last_blockhash))
|
||||
.set_state(&State::Initialized(meta, *last_blockhash))
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
@@ -74,10 +74,10 @@ mod tests {
|
||||
use super::*;
|
||||
use solana_sdk::{
|
||||
account::Account,
|
||||
account_utils::State,
|
||||
account_utils::State as AccountUtilsState,
|
||||
hash::Hash,
|
||||
instruction::InstructionError,
|
||||
nonce_state::{with_test_keyed_account, Meta, NonceAccount},
|
||||
nonce::{self, account::with_test_keyed_account, Account as NonceAccount},
|
||||
pubkey::Pubkey,
|
||||
signature::{Keypair, Signer},
|
||||
system_instruction,
|
||||
@@ -193,9 +193,9 @@ mod tests {
|
||||
with_test_keyed_account(42, true, |nonce_account| {
|
||||
let mut signers = HashSet::new();
|
||||
signers.insert(nonce_account.signer_key().unwrap().clone());
|
||||
let state: NonceState = nonce_account.state().unwrap();
|
||||
let state: State = nonce_account.state().unwrap();
|
||||
// New is in Uninitialzed state
|
||||
assert_eq!(state, NonceState::Uninitialized);
|
||||
assert_eq!(state, State::Uninitialized);
|
||||
let recent_blockhashes = create_test_recent_blockhashes(0);
|
||||
let authorized = nonce_account.unsigned_key().clone();
|
||||
nonce_account
|
||||
@@ -223,9 +223,9 @@ mod tests {
|
||||
with_test_keyed_account(42, true, |nonce_account| {
|
||||
let mut signers = HashSet::new();
|
||||
signers.insert(nonce_account.signer_key().unwrap().clone());
|
||||
let state: NonceState = nonce_account.state().unwrap();
|
||||
let state: State = nonce_account.state().unwrap();
|
||||
// New is in Uninitialzed state
|
||||
assert_eq!(state, NonceState::Uninitialized);
|
||||
assert_eq!(state, State::Uninitialized);
|
||||
let recent_blockhashes = create_test_recent_blockhashes(0);
|
||||
let authorized = nonce_account.unsigned_key().clone();
|
||||
nonce_account
|
||||
@@ -242,7 +242,7 @@ mod tests {
|
||||
let stored_nonce = Hash::default();
|
||||
let account = Account::new_data(
|
||||
42,
|
||||
&NonceState::Initialized(Meta::new(&Pubkey::default()), stored_nonce),
|
||||
&State::Initialized(nonce::state::Meta::new(&Pubkey::default()), stored_nonce),
|
||||
&system_program::id(),
|
||||
)
|
||||
.unwrap();
|
||||
@@ -297,8 +297,8 @@ mod tests {
|
||||
|
||||
let mut expect_account = post_account.clone();
|
||||
expect_account
|
||||
.set_state(&NonceState::Initialized(
|
||||
Meta::new(&Pubkey::default()),
|
||||
.set_state(&State::Initialized(
|
||||
nonce::state::Meta::new(&Pubkey::default()),
|
||||
last_blockhash,
|
||||
))
|
||||
.unwrap();
|
||||
@@ -356,8 +356,8 @@ mod tests {
|
||||
|
||||
let mut expect_account = pre_account.clone();
|
||||
expect_account
|
||||
.set_state(&NonceState::Initialized(
|
||||
Meta::new(&Pubkey::default()),
|
||||
.set_state(&State::Initialized(
|
||||
nonce::state::Meta::new(&Pubkey::default()),
|
||||
last_blockhash,
|
||||
))
|
||||
.unwrap();
|
||||
|
@@ -3,7 +3,7 @@ use solana_sdk::{
|
||||
account::{get_signers, Account, KeyedAccount},
|
||||
account_utils::StateMut,
|
||||
instruction::InstructionError,
|
||||
nonce_state::{NonceAccount, NonceState},
|
||||
nonce::{self, Account as NonceAccount},
|
||||
program_utils::{limited_deserialize, next_keyed_account},
|
||||
pubkey::Pubkey,
|
||||
system_instruction::{
|
||||
@@ -306,7 +306,7 @@ pub fn get_system_account_kind(account: &Account) -> Option<SystemAccountKind> {
|
||||
if system_program::check_id(&account.owner) {
|
||||
if account.data.is_empty() {
|
||||
Some(SystemAccountKind::System)
|
||||
} else if let Ok(NonceState::Initialized(_, _)) = account.state() {
|
||||
} else if let Ok(nonce::State::Initialized(_, _)) = account.state() {
|
||||
Some(SystemAccountKind::Nonce)
|
||||
} else {
|
||||
None
|
||||
@@ -328,7 +328,7 @@ mod tests {
|
||||
hash::{hash, Hash},
|
||||
instruction::{AccountMeta, Instruction, InstructionError},
|
||||
message::Message,
|
||||
nonce_state,
|
||||
nonce,
|
||||
signature::{Keypair, Signer},
|
||||
system_instruction, system_program, sysvar,
|
||||
transaction::TransactionError,
|
||||
@@ -733,8 +733,8 @@ mod tests {
|
||||
let nonce = Pubkey::new_rand();
|
||||
let nonce_account = Account::new_ref_data(
|
||||
42,
|
||||
&nonce_state::NonceState::Initialized(
|
||||
nonce_state::Meta::new(&Pubkey::default()),
|
||||
&nonce::State::Initialized(
|
||||
nonce::state::Meta::new(&Pubkey::default()),
|
||||
Hash::default(),
|
||||
),
|
||||
&system_program::id(),
|
||||
@@ -875,7 +875,7 @@ mod tests {
|
||||
let from = Pubkey::new_rand();
|
||||
let from_account = Account::new_ref_data(
|
||||
100,
|
||||
&nonce_state::NonceState::Initialized(nonce_state::Meta::new(&from), Hash::default()),
|
||||
&nonce::State::Initialized(nonce::state::Meta::new(&from), Hash::default()),
|
||||
&system_program::id(),
|
||||
)
|
||||
.unwrap();
|
||||
@@ -1089,7 +1089,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_process_nonce_ix_ok() {
|
||||
let nonce_acc = nonce_state::create_account(1_000_000);
|
||||
let nonce_acc = nonce::create_account(1_000_000);
|
||||
super::process_instruction(
|
||||
&Pubkey::default(),
|
||||
&[
|
||||
@@ -1193,11 +1193,7 @@ mod tests {
|
||||
super::process_instruction(
|
||||
&Pubkey::default(),
|
||||
&[
|
||||
KeyedAccount::new(
|
||||
&Pubkey::default(),
|
||||
true,
|
||||
&nonce_state::create_account(1_000_000),
|
||||
),
|
||||
KeyedAccount::new(&Pubkey::default(), true, &nonce::create_account(1_000_000),),
|
||||
KeyedAccount::new(&Pubkey::default(), true, &create_default_account()),
|
||||
KeyedAccount::new(
|
||||
&sysvar::recent_blockhashes::id(),
|
||||
@@ -1218,11 +1214,7 @@ mod tests {
|
||||
super::process_instruction(
|
||||
&Pubkey::default(),
|
||||
&[
|
||||
KeyedAccount::new(
|
||||
&Pubkey::default(),
|
||||
true,
|
||||
&nonce_state::create_account(1_000_000),
|
||||
),
|
||||
KeyedAccount::new(&Pubkey::default(), true, &nonce::create_account(1_000_000),),
|
||||
KeyedAccount::new(&Pubkey::default(), true, &create_default_account()),
|
||||
KeyedAccount::new(
|
||||
&sysvar::recent_blockhashes::id(),
|
||||
@@ -1257,7 +1249,7 @@ mod tests {
|
||||
&[KeyedAccount::new(
|
||||
&Pubkey::default(),
|
||||
true,
|
||||
&nonce_state::create_account(1_000_000),
|
||||
&nonce::create_account(1_000_000),
|
||||
),],
|
||||
&serialize(&SystemInstruction::InitializeNonceAccount(Pubkey::default())).unwrap(),
|
||||
),
|
||||
@@ -1271,11 +1263,7 @@ mod tests {
|
||||
super::process_instruction(
|
||||
&Pubkey::default(),
|
||||
&[
|
||||
KeyedAccount::new(
|
||||
&Pubkey::default(),
|
||||
true,
|
||||
&nonce_state::create_account(1_000_000),
|
||||
),
|
||||
KeyedAccount::new(&Pubkey::default(), true, &nonce::create_account(1_000_000),),
|
||||
KeyedAccount::new(
|
||||
&sysvar::recent_blockhashes::id(),
|
||||
false,
|
||||
@@ -1294,11 +1282,7 @@ mod tests {
|
||||
super::process_instruction(
|
||||
&Pubkey::default(),
|
||||
&[
|
||||
KeyedAccount::new(
|
||||
&Pubkey::default(),
|
||||
true,
|
||||
&nonce_state::create_account(1_000_000),
|
||||
),
|
||||
KeyedAccount::new(&Pubkey::default(), true, &nonce::create_account(1_000_000),),
|
||||
KeyedAccount::new(
|
||||
&sysvar::recent_blockhashes::id(),
|
||||
false,
|
||||
@@ -1318,11 +1302,7 @@ mod tests {
|
||||
super::process_instruction(
|
||||
&Pubkey::default(),
|
||||
&[
|
||||
KeyedAccount::new(
|
||||
&Pubkey::default(),
|
||||
true,
|
||||
&nonce_state::create_account(1_000_000),
|
||||
),
|
||||
KeyedAccount::new(&Pubkey::default(), true, &nonce::create_account(1_000_000),),
|
||||
KeyedAccount::new(
|
||||
&sysvar::recent_blockhashes::id(),
|
||||
false,
|
||||
@@ -1338,7 +1318,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_process_authorize_ix_ok() {
|
||||
let nonce_acc = nonce_state::create_account(1_000_000);
|
||||
let nonce_acc = nonce::create_account(1_000_000);
|
||||
super::process_instruction(
|
||||
&Pubkey::default(),
|
||||
&[
|
||||
@@ -1388,8 +1368,8 @@ mod tests {
|
||||
fn test_get_system_account_kind_nonce_ok() {
|
||||
let nonce_account = Account::new_data(
|
||||
42,
|
||||
&nonce_state::NonceState::Initialized(
|
||||
nonce_state::Meta::new(&Pubkey::default()),
|
||||
&nonce::State::Initialized(
|
||||
nonce::state::Meta::new(&Pubkey::default()),
|
||||
Hash::default(),
|
||||
),
|
||||
&system_program::id(),
|
||||
@@ -1404,7 +1384,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_get_system_account_kind_uninitialized_nonce_account_fail() {
|
||||
assert_eq!(
|
||||
get_system_account_kind(&nonce_state::create_account(42).borrow()),
|
||||
get_system_account_kind(&nonce::create_account(42).borrow()),
|
||||
None
|
||||
);
|
||||
}
|
||||
@@ -1416,11 +1396,11 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_get_system_account_kind_nonsystem_owner_with_nonce_state_data_fail() {
|
||||
fn test_get_system_account_kind_nonsystem_owner_with_nonce_data_fail() {
|
||||
let nonce_account = Account::new_data(
|
||||
42,
|
||||
&nonce_state::NonceState::Initialized(
|
||||
nonce_state::Meta::new(&Pubkey::default()),
|
||||
&nonce::State::Initialized(
|
||||
nonce::state::Meta::new(&Pubkey::default()),
|
||||
Hash::default(),
|
||||
),
|
||||
&Pubkey::new_rand(),
|
||||
|
Reference in New Issue
Block a user