Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate SysvarRecentBlockhashes #18875

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions account-decoder/src/parse_sysvar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use crate::{
};
use bincode::deserialize;
use bv::BitVec;
#[allow(deprecated)]
use solana_sdk::sysvar::recent_blockhashes::RecentBlockhashes;
use solana_sdk::{
clock::{Clock, Epoch, Slot, UnixTimestamp},
epoch_schedule::EpochSchedule,
Expand All @@ -12,10 +14,11 @@ use solana_sdk::{
slot_hashes::SlotHashes,
slot_history::{self, SlotHistory},
stake_history::{StakeHistory, StakeHistoryEntry},
sysvar::{self, fees::Fees, recent_blockhashes::RecentBlockhashes, rewards::Rewards},
sysvar::{self, fees::Fees, rewards::Rewards},
};

pub fn parse_sysvar(data: &[u8], pubkey: &Pubkey) -> Result<SysvarAccountType, ParseAccountError> {
#[allow(deprecated)]
let parsed_account = {
if pubkey == &sysvar::clock::id() {
deserialize::<Clock>(data)
Expand Down Expand Up @@ -213,10 +216,9 @@ pub struct UiStakeHistoryEntry {
#[cfg(test)]
mod test {
use super::*;
use solana_sdk::{
account::create_account_for_test, fee_calculator::FeeCalculator, hash::Hash,
sysvar::recent_blockhashes::IterItem,
};
#[allow(deprecated)]
use solana_sdk::sysvar::recent_blockhashes::IterItem;
use solana_sdk::{account::create_account_for_test, fee_calculator::FeeCalculator, hash::Hash};

#[test]
fn test_parse_sysvars() {
Expand Down Expand Up @@ -249,13 +251,15 @@ mod test {
let fee_calculator = FeeCalculator {
lamports_per_signature: 10,
};
#[allow(deprecated)]
let recent_blockhashes: RecentBlockhashes = vec![IterItem(0, &hash, &fee_calculator)]
.into_iter()
.collect();
let recent_blockhashes_sysvar = create_account_for_test(&recent_blockhashes);
assert_eq!(
parse_sysvar(
&recent_blockhashes_sysvar.data,
#[allow(deprecated)]
&sysvar::recent_blockhashes::id()
)
.unwrap(),
Expand Down
8 changes: 5 additions & 3 deletions programs/bpf/rust/sysvar/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//! @brief Example Rust-based BPF program that tests sysvar use

extern crate solana_program;
#[allow(deprecated)]
use solana_program::sysvar::recent_blockhashes::RecentBlockhashes;
use solana_program::{
account_info::AccountInfo,
entrypoint,
Expand All @@ -10,9 +12,8 @@ use solana_program::{
program_error::ProgramError,
pubkey::Pubkey,
sysvar::{
self, clock::Clock, epoch_schedule::EpochSchedule, fees::Fees, instructions,
recent_blockhashes::RecentBlockhashes, rent::Rent, slot_hashes::SlotHashes,
slot_history::SlotHistory, stake_history::StakeHistory, Sysvar,
self, clock::Clock, epoch_schedule::EpochSchedule, fees::Fees, instructions, rent::Rent,
slot_hashes::SlotHashes, slot_history::SlotHistory, stake_history::StakeHistory, Sysvar,
},
};

Expand Down Expand Up @@ -61,6 +62,7 @@ pub fn process_instruction(
assert_eq!(0, index);

// Recent Blockhashes
#[allow(deprecated)]
{
msg!("RecentBlockhashes identifier:");
sysvar::recent_blockhashes::id().log();
Expand Down
24 changes: 13 additions & 11 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ use log::*;
use rayon::ThreadPool;
use solana_measure::measure::Measure;
use solana_metrics::{datapoint_debug, inc_new_counter_debug, inc_new_counter_info};
#[allow(deprecated)]
use solana_sdk::recent_blockhashes_account;
use solana_sdk::{
account::{
create_account_shared_data_with_fields as create_account, from_account, Account,
Expand Down Expand Up @@ -96,7 +98,6 @@ use solana_sdk::{
process_instruction::{ComputeMeter, Executor, ProcessInstructionWithContext},
program_utils::limited_deserialize,
pubkey::Pubkey,
recent_blockhashes_account,
sanitized_transaction::{SanitizedTransaction, SanitizedTransactionSlice},
signature::{Keypair, Signature},
slot_hashes::SlotHashes,
Expand Down Expand Up @@ -2157,6 +2158,7 @@ impl Bank {
}

fn update_recent_blockhashes_locked(&self, locked_blockhash_queue: &BlockhashQueue) {
#[allow(deprecated)]
self.update_sysvar_account(&sysvar::recent_blockhashes::id(), |account| {
let recent_blockhash_iter = locked_blockhash_queue.get_recent_blockhashes();
recent_blockhashes_account::create_account_with_data_and_fields(
Expand Down Expand Up @@ -5292,6 +5294,7 @@ impl Bank {
sysvar::clock::id(),
sysvar::epoch_schedule::id(),
sysvar::fees::id(),
#[allow(deprecated)]
sysvar::recent_blockhashes::id(),
sysvar::rent::id(),
sysvar::rewards::id(),
Expand Down Expand Up @@ -9737,6 +9740,7 @@ pub(crate) mod tests {
);
}

#[allow(deprecated)]
#[test]
fn test_recent_blockhashes_sysvar() {
let (genesis_config, _mint_keypair) = create_genesis_config(500);
Expand All @@ -9756,6 +9760,7 @@ pub(crate) mod tests {
}
}

#[allow(deprecated)]
#[test]
fn test_blockhash_queue_sysvar_consistency() {
let (genesis_config, _mint_keypair) = create_genesis_config(100_000);
Expand Down Expand Up @@ -11990,6 +11995,7 @@ pub(crate) mod tests {
sysvar::clock::id(),
sysvar::epoch_schedule::id(),
sysvar::fees::id(),
#[allow(deprecated)]
sysvar::recent_blockhashes::id(),
sysvar::rent::id(),
sysvar::slot_hashes::id(),
Expand Down Expand Up @@ -12100,6 +12106,7 @@ pub(crate) mod tests {
sysvar::clock::id(),
sysvar::epoch_schedule::id(),
sysvar::fees::id(),
#[allow(deprecated)]
sysvar::recent_blockhashes::id(),
sysvar::rent::id(),
sysvar::rewards::id(),
Expand Down Expand Up @@ -13614,12 +13621,9 @@ pub(crate) mod tests {
bank.add_builtin("mock_program1", program_id, mock_ix_processor);

let blockhash = bank.last_blockhash();
let blockhash_sysvar = sysvar::recent_blockhashes::id();
let orig_lamports = bank
.get_account(&sysvar::recent_blockhashes::id())
.unwrap()
.lamports();
info!("{:?}", bank.get_account(&sysvar::recent_blockhashes::id()));
let blockhash_sysvar = sysvar::fees::id();
let orig_lamports = bank.get_account(&sysvar::fees::id()).unwrap().lamports();
info!("{:?}", bank.get_account(&sysvar::fees::id()));
let tx = system_transaction::transfer(&mint_keypair, &blockhash_sysvar, 10, blockhash);
assert_eq!(
bank.process_transaction(&tx),
Expand All @@ -13629,12 +13633,10 @@ pub(crate) mod tests {
))
);
assert_eq!(
bank.get_account(&sysvar::recent_blockhashes::id())
.unwrap()
.lamports(),
bank.get_account(&sysvar::fees::id()).unwrap().lamports(),
orig_lamports
);
info!("{:?}", bank.get_account(&sysvar::recent_blockhashes::id()));
info!("{:?}", bank.get_account(&sysvar::fees::id()));

let accounts = vec![
AccountMeta::new(mint_keypair.pubkey(), true),
Expand Down
20 changes: 14 additions & 6 deletions runtime/src/blockhash_queue.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use serde::{Deserialize, Serialize};
use solana_sdk::{
fee_calculator::FeeCalculator, hash::Hash, sysvar::recent_blockhashes, timing::timestamp,
};
#[allow(deprecated)]
use solana_sdk::sysvar::recent_blockhashes;
use solana_sdk::{fee_calculator::FeeCalculator, hash::Hash, timing::timestamp};
use std::collections::HashMap;

#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize, AbiExample)]
Expand Down Expand Up @@ -121,6 +121,11 @@ impl BlockhashQueue {
None
}

#[deprecated(
since = "1.8.0",
note = "Please do not use, will no longer be available in the future"
)]
#[allow(deprecated)]
pub fn get_recent_blockhashes(&self) -> impl Iterator<Item = recent_blockhashes::IterItem> {
(&self.ages)
.iter()
Expand All @@ -135,9 +140,9 @@ impl BlockhashQueue {
mod tests {
use super::*;
use bincode::serialize;
use solana_sdk::{
clock::MAX_RECENT_BLOCKHASHES, hash::hash, sysvar::recent_blockhashes::IterItem,
};
#[allow(deprecated)]
use solana_sdk::sysvar::recent_blockhashes::IterItem;
use solana_sdk::{clock::MAX_RECENT_BLOCKHASHES, hash::hash};

#[test]
fn test_register_hash() {
Expand Down Expand Up @@ -180,15 +185,18 @@ mod tests {
#[test]
fn test_get_recent_blockhashes() {
let mut blockhash_queue = BlockhashQueue::new(MAX_RECENT_BLOCKHASHES);
#[allow(deprecated)]
let recent_blockhashes = blockhash_queue.get_recent_blockhashes();
// Sanity-check an empty BlockhashQueue
assert_eq!(recent_blockhashes.count(), 0);
for i in 0..MAX_RECENT_BLOCKHASHES {
let hash = hash(&serialize(&i).unwrap());
blockhash_queue.register_hash(&hash, &FeeCalculator::default());
}
#[allow(deprecated)]
let recent_blockhashes = blockhash_queue.get_recent_blockhashes();
// Verify that the returned hashes are most recent
#[allow(deprecated)]
for IterItem(_slot, hash, _fee_calc) in recent_blockhashes {
assert_eq!(
Some(true),
Expand Down
23 changes: 21 additions & 2 deletions runtime/src/system_instruction_processor.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use log::*;
#[allow(deprecated)]
use solana_sdk::sysvar::recent_blockhashes::RecentBlockhashes;
use solana_sdk::{
account::{AccountSharedData, ReadableAccount, WritableAccount},
account_utils::StateMut,
Expand All @@ -12,7 +14,7 @@ use solana_sdk::{
pubkey::Pubkey,
system_instruction::{SystemError, SystemInstruction, MAX_PERMITTED_DATA_LENGTH},
system_program,
sysvar::{self, recent_blockhashes::RecentBlockhashes, rent::Rent},
sysvar::{self, rent::Rent},
};
use std::collections::HashSet;

Expand Down Expand Up @@ -352,6 +354,7 @@ pub fn process_instruction(
SystemInstruction::AdvanceNonceAccount => {
let me = &mut keyed_account_at_index(keyed_accounts, 0)?;
me.advance_nonce_account(
#[allow(deprecated)]
&from_keyed_account::<RecentBlockhashes>(keyed_account_at_index(
keyed_accounts,
1,
Expand All @@ -366,6 +369,7 @@ pub fn process_instruction(
me.withdraw_nonce_account(
lamports,
to,
#[allow(deprecated)]
&from_keyed_account::<RecentBlockhashes>(keyed_account_at_index(
keyed_accounts,
2,
Expand All @@ -379,6 +383,7 @@ pub fn process_instruction(
let me = &mut keyed_account_at_index(keyed_accounts, 0)?;
me.initialize_nonce_account(
&authorized,
#[allow(deprecated)]
&from_keyed_account::<RecentBlockhashes>(keyed_account_at_index(
keyed_accounts,
1,
Expand Down Expand Up @@ -462,6 +467,8 @@ mod tests {
use super::*;
use crate::{bank::Bank, bank_client::BankClient};
use bincode::serialize;
#[allow(deprecated)]
use solana_sdk::sysvar::recent_blockhashes::IterItem;
use solana_sdk::{
account::{self, Account, AccountSharedData},
client::SyncClient,
Expand All @@ -475,7 +482,6 @@ mod tests {
recent_blockhashes_account,
signature::{Keypair, Signer},
system_instruction, system_program, sysvar,
sysvar::recent_blockhashes::IterItem,
transaction::TransactionError,
};
use std::cell::RefCell;
Expand Down Expand Up @@ -507,6 +513,7 @@ mod tests {
}
fn create_default_recent_blockhashes_account() -> RefCell<AccountSharedData> {
RefCell::new(
#[allow(deprecated)]
recent_blockhashes_account::create_account_with_data_for_test(
vec![
IterItem(0u64, &Hash::default(), &FeeCalculator::default());
Expand Down Expand Up @@ -1456,6 +1463,7 @@ mod tests {
.accounts
.iter()
.map(|meta| {
#[allow(deprecated)]
RefCell::new(if sysvar::recent_blockhashes::check_id(&meta.pubkey) {
create_default_recent_blockhashes_account().into_inner()
} else if sysvar::rent::check_id(&meta.pubkey) {
Expand Down Expand Up @@ -1524,6 +1532,7 @@ mod tests {
vec![
KeyedAccount::new(&Pubkey::default(), true, &create_default_account()),
KeyedAccount::new(
#[allow(deprecated)]
&sysvar::recent_blockhashes::id(),
false,
&create_default_account(),
Expand All @@ -1543,6 +1552,7 @@ mod tests {
vec![
KeyedAccount::new(&Pubkey::default(), true, &nonce_acc),
KeyedAccount::new(
#[allow(deprecated)]
&sysvar::recent_blockhashes::id(),
false,
&create_default_recent_blockhashes_account(),
Expand All @@ -1553,6 +1563,7 @@ mod tests {
)
.unwrap();
let new_recent_blockhashes_account = RefCell::new(
#[allow(deprecated)]
solana_sdk::recent_blockhashes_account::create_account_with_data_for_test(
vec![
IterItem(
Expand All @@ -1570,6 +1581,7 @@ mod tests {
&Pubkey::default(),
vec![
KeyedAccount::new(&Pubkey::default(), true, &nonce_acc,),
#[allow(deprecated)]
KeyedAccount::new(
&sysvar::recent_blockhashes::id(),
false,
Expand Down Expand Up @@ -1632,6 +1644,7 @@ mod tests {
KeyedAccount::new(&Pubkey::default(), true, &create_default_account()),
KeyedAccount::new(&Pubkey::default(), false, &create_default_account()),
KeyedAccount::new(
#[allow(deprecated)]
&sysvar::recent_blockhashes::id(),
false,
&create_default_account()
Expand All @@ -1656,6 +1669,7 @@ mod tests {
),
KeyedAccount::new(&Pubkey::default(), true, &create_default_account()),
KeyedAccount::new(
#[allow(deprecated)]
&sysvar::recent_blockhashes::id(),
false,
&create_default_recent_blockhashes_account(),
Expand All @@ -1681,6 +1695,7 @@ mod tests {
),
KeyedAccount::new(&Pubkey::default(), true, &create_default_account()),
KeyedAccount::new(
#[allow(deprecated)]
&sysvar::recent_blockhashes::id(),
false,
&create_default_recent_blockhashes_account(),
Expand Down Expand Up @@ -1733,6 +1748,7 @@ mod tests {
&nonce_account::create_account(1_000_000),
),
KeyedAccount::new(
#[allow(deprecated)]
&sysvar::recent_blockhashes::id(),
false,
&create_default_account()
Expand All @@ -1756,6 +1772,7 @@ mod tests {
&nonce_account::create_account(1_000_000),
),
KeyedAccount::new(
#[allow(deprecated)]
&sysvar::recent_blockhashes::id(),
false,
&create_default_recent_blockhashes_account(),
Expand All @@ -1780,6 +1797,7 @@ mod tests {
&nonce_account::create_account(1_000_000),
),
KeyedAccount::new(
#[allow(deprecated)]
&sysvar::recent_blockhashes::id(),
false,
&create_default_recent_blockhashes_account(),
Expand All @@ -1800,6 +1818,7 @@ mod tests {
vec![
KeyedAccount::new(&Pubkey::default(), true, &nonce_acc),
KeyedAccount::new(
#[allow(deprecated)]
&sysvar::recent_blockhashes::id(),
false,
&create_default_recent_blockhashes_account(),
Expand Down
Loading