Store FeeCalculator with blockhash in nonce accounts (#8650)
* Copy current state version to v0 * Add `FeeCalculator` to nonce state * fixup compile * Dump v0 handling... Since we new account data is all zeros, new `Current` versioned accounts look like v0. We could hack around this with some data size checks, but the `account_utils::*State` traits are applied to `Account`, not the state data, so we're kind SOL... * Create more representative test `RecentBlockhashes` * Improve CLI nonce account display Co-Authored-By: Michael Vines <mvines@gmail.com> * Fix that last bank test... * clippy/fmt Co-authored-by: Michael Vines <mvines@gmail.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
use solana_sdk::{
|
||||
account::Account,
|
||||
account_utils::StateMut,
|
||||
fee_calculator::FeeCalculator,
|
||||
hash::Hash,
|
||||
instruction::CompiledInstruction,
|
||||
nonce::{self, state::Versions, State},
|
||||
@@ -66,7 +67,7 @@ pub fn prepare_if_nonce_account(
|
||||
if let State::Initialized(ref data) = state {
|
||||
let new_data = Versions::new_current(State::Initialized(nonce::state::Data {
|
||||
blockhash: *last_blockhash,
|
||||
..*data
|
||||
..data.clone()
|
||||
}));
|
||||
account.set_state(&new_data).unwrap();
|
||||
}
|
||||
@@ -74,6 +75,16 @@ pub fn prepare_if_nonce_account(
|
||||
}
|
||||
}
|
||||
|
||||
pub fn fee_calculator_of(account: &Account) -> Option<FeeCalculator> {
|
||||
let state = StateMut::<Versions>::state(account)
|
||||
.ok()?
|
||||
.convert_to_current();
|
||||
match state {
|
||||
State::Initialized(data) => Some(data.fee_calculator),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@@ -244,10 +255,7 @@ mod tests {
|
||||
}
|
||||
|
||||
fn create_accounts_prepare_if_nonce_account() -> (Pubkey, Account, Account, Hash) {
|
||||
let data = Versions::new_current(State::Initialized(nonce::state::Data {
|
||||
authority: Pubkey::default(),
|
||||
blockhash: Hash::default(),
|
||||
}));
|
||||
let data = Versions::new_current(State::Initialized(nonce::state::Data::default()));
|
||||
let account = Account::new_data(42, &data, &system_program::id()).unwrap();
|
||||
let pre_account = Account {
|
||||
lamports: 43,
|
||||
@@ -300,8 +308,8 @@ mod tests {
|
||||
|
||||
let mut expect_account = post_account.clone();
|
||||
let data = Versions::new_current(State::Initialized(nonce::state::Data {
|
||||
authority: Pubkey::default(),
|
||||
blockhash: last_blockhash,
|
||||
..nonce::state::Data::default()
|
||||
}));
|
||||
expect_account.set_state(&data).unwrap();
|
||||
|
||||
@@ -360,8 +368,8 @@ mod tests {
|
||||
expect_account
|
||||
.set_state(&Versions::new_current(State::Initialized(
|
||||
nonce::state::Data {
|
||||
authority: Pubkey::default(),
|
||||
blockhash: last_blockhash,
|
||||
..nonce::state::Data::default()
|
||||
},
|
||||
)))
|
||||
.unwrap();
|
||||
|
Reference in New Issue
Block a user