Blockhashes is one word
This commit is contained in:
@ -288,7 +288,7 @@ impl Bank {
|
||||
bank.update_clock();
|
||||
bank.update_rent();
|
||||
bank.update_epoch_schedule();
|
||||
bank.update_recent_block_hashes();
|
||||
bank.update_recent_blockhashes();
|
||||
bank
|
||||
}
|
||||
|
||||
@ -382,7 +382,7 @@ impl Bank {
|
||||
new.update_stake_history(Some(parent.epoch()));
|
||||
new.update_clock();
|
||||
new.update_fees();
|
||||
new.update_recent_block_hashes();
|
||||
new.update_recent_blockhashes();
|
||||
new
|
||||
}
|
||||
|
||||
@ -537,15 +537,15 @@ impl Bank {
|
||||
);
|
||||
}
|
||||
|
||||
fn update_recent_block_hashes(&self) {
|
||||
let recent_block_hashes = self
|
||||
fn update_recent_blockhashes(&self) {
|
||||
let recent_blockhashes = self
|
||||
.blockhash_queue
|
||||
.read()
|
||||
.unwrap()
|
||||
.get_recent_blockhashes(sysvar::recent_block_hashes::MAX_ENTRIES);
|
||||
.get_recent_blockhashes(sysvar::recent_blockhashes::MAX_ENTRIES);
|
||||
self.store_account(
|
||||
&sysvar::recent_block_hashes::id(),
|
||||
&sysvar::recent_block_hashes::create_account(1, recent_block_hashes),
|
||||
&sysvar::recent_blockhashes::id(),
|
||||
&sysvar::recent_blockhashes::create_account(1, recent_blockhashes),
|
||||
);
|
||||
}
|
||||
|
||||
@ -3357,22 +3357,22 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_recent_block_hashes_sysvar() {
|
||||
fn test_recent_blockhashes_sysvar() {
|
||||
let (genesis_block, _mint_keypair) = create_genesis_block(500);
|
||||
let mut bank = Arc::new(Bank::new(&genesis_block));
|
||||
let bhq_account = bank
|
||||
.get_account(&sysvar::recent_block_hashes::id())
|
||||
.get_account(&sysvar::recent_blockhashes::id())
|
||||
.unwrap();
|
||||
let recent_block_hashes =
|
||||
sysvar::recent_block_hashes::RecentBlockHashes::from_account(&bhq_account).unwrap();
|
||||
assert_eq!(recent_block_hashes.len(), 1);
|
||||
let recent_blockhashes =
|
||||
sysvar::recent_blockhashes::RecentBlockhashes::from_account(&bhq_account).unwrap();
|
||||
assert_eq!(recent_blockhashes.len(), 1);
|
||||
goto_end_of_slot(Arc::get_mut(&mut bank).unwrap());
|
||||
let bank = Arc::new(new_from_parent(&bank));
|
||||
let bhq_account = bank
|
||||
.get_account(&sysvar::recent_block_hashes::id())
|
||||
.get_account(&sysvar::recent_blockhashes::id())
|
||||
.unwrap();
|
||||
let recent_block_hashes =
|
||||
sysvar::recent_block_hashes::RecentBlockHashes::from_account(&bhq_account).unwrap();
|
||||
assert_eq!(recent_block_hashes.len(), 2);
|
||||
let recent_blockhashes =
|
||||
sysvar::recent_blockhashes::RecentBlockhashes::from_account(&bhq_account).unwrap();
|
||||
assert_eq!(recent_blockhashes.len(), 2);
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ use crate::pubkey::Pubkey;
|
||||
pub mod clock;
|
||||
pub mod epoch_schedule;
|
||||
pub mod fees;
|
||||
pub mod recent_block_hashes;
|
||||
pub mod recent_blockhashes;
|
||||
pub mod rent;
|
||||
pub mod rewards;
|
||||
pub mod slot_hashes;
|
||||
@ -15,7 +15,7 @@ pub fn is_sysvar_id(id: &Pubkey) -> bool {
|
||||
clock::check_id(id)
|
||||
|| epoch_schedule::check_id(id)
|
||||
|| fees::check_id(id)
|
||||
|| recent_block_hashes::check_id(id)
|
||||
|| recent_blockhashes::check_id(id)
|
||||
|| rent::check_id(id)
|
||||
|| rewards::check_id(id)
|
||||
|| slot_hashes::check_id(id)
|
||||
|
@ -12,15 +12,15 @@ crate::solana_sysvar_id!(ID, "SysvarRecentB1ockHashes11111111111111111111");
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Serialize, Deserialize, Debug, PartialEq)]
|
||||
pub struct RecentBlockHashes(Vec<Hash>);
|
||||
pub struct RecentBlockhashes(Vec<Hash>);
|
||||
|
||||
impl Default for RecentBlockHashes {
|
||||
impl Default for RecentBlockhashes {
|
||||
fn default() -> Self {
|
||||
Self(Vec::with_capacity(MAX_ENTRIES))
|
||||
}
|
||||
}
|
||||
|
||||
impl RecentBlockHashes {
|
||||
impl RecentBlockhashes {
|
||||
pub fn from_account(account: &Account) -> Option<Self> {
|
||||
account.deserialize_data().ok()
|
||||
}
|
||||
@ -35,21 +35,21 @@ impl RecentBlockHashes {
|
||||
account.serialize_data(self).ok()
|
||||
}
|
||||
pub fn size_of() -> usize {
|
||||
serialized_size(&RecentBlockHashes(vec![Hash::default(); MAX_ENTRIES])).unwrap() as usize
|
||||
serialized_size(&RecentBlockhashes(vec![Hash::default(); MAX_ENTRIES])).unwrap() as usize
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for RecentBlockHashes {
|
||||
impl Deref for RecentBlockhashes {
|
||||
type Target = Vec<Hash>;
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
pub fn create_account(lamports: u64, recent_block_hashes: Vec<Hash>) -> Account {
|
||||
let mut account = Account::new(lamports, RecentBlockHashes::size_of(), &sysvar::id());
|
||||
let recent_block_hashes = RecentBlockHashes(recent_block_hashes);
|
||||
recent_block_hashes.to_account(&mut account).unwrap();
|
||||
pub fn create_account(lamports: u64, recent_blockhashes: Vec<Hash>) -> Account {
|
||||
let mut account = Account::new(lamports, RecentBlockhashes::size_of(), &sysvar::id());
|
||||
let recent_blockhashes = RecentBlockhashes(recent_blockhashes);
|
||||
recent_blockhashes.to_account(&mut account).unwrap();
|
||||
account
|
||||
}
|
||||
|
||||
@ -61,21 +61,21 @@ mod tests {
|
||||
#[test]
|
||||
fn test_create_account_empty() {
|
||||
let account = create_account(42, vec![]);
|
||||
let recent_block_hashes = RecentBlockHashes::from_account(&account).unwrap();
|
||||
assert_eq!(recent_block_hashes, RecentBlockHashes::default());
|
||||
let recent_blockhashes = RecentBlockhashes::from_account(&account).unwrap();
|
||||
assert_eq!(recent_blockhashes, RecentBlockhashes::default());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_create_account_full() {
|
||||
let account = create_account(42, vec![Hash::default(); MAX_ENTRIES]);
|
||||
let recent_block_hashes = RecentBlockHashes::from_account(&account).unwrap();
|
||||
assert_eq!(recent_block_hashes.len(), MAX_ENTRIES);
|
||||
let recent_blockhashes = RecentBlockhashes::from_account(&account).unwrap();
|
||||
assert_eq!(recent_blockhashes.len(), MAX_ENTRIES);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_create_account_too_big() {
|
||||
let account = create_account(42, vec![Hash::default(); MAX_ENTRIES + 1]);
|
||||
RecentBlockHashes::from_account(&account).unwrap();
|
||||
RecentBlockhashes::from_account(&account).unwrap();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user