-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Secure sysvars under hash by freezing all strictly #7892
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,7 +38,6 @@ use solana_sdk::bank_hash::BankHash; | |
| use solana_sdk::clock::{Epoch, Slot}; | ||
| use solana_sdk::hash::{Hash, Hasher}; | ||
| use solana_sdk::pubkey::Pubkey; | ||
| use solana_sdk::sysvar; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bye bye, leaky abstraction; Feels so good. :) |
||
| use std::collections::{HashMap, HashSet}; | ||
| use std::fmt; | ||
| use std::io::{BufReader, Cursor, Error as IOError, ErrorKind, Read, Result as IOResult}; | ||
|
|
@@ -759,6 +758,14 @@ impl AccountsDB { | |
| let hash_info = bank_hashes | ||
| .get(&parent_slot) | ||
| .expect("accounts_db::set_hash::no parent slot"); | ||
| if bank_hashes.get(&slot).is_some() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this additional line in scope for this PR?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @rob-solana Yes! First, this PR added additional tests for the lazy initialization of slot hashes sysvar around here. That exact line internally hits here and bails out with this I know such sharing of a slot between child banks doesn't occur in the real validator behavior. Thus, I alternatively could replace this In other words, AccountsDB isn't aware of anything called forks and free of leaky abstraction now and forever. I think that's nice and beautiful design and separation of concern. :) |
||
| error!( | ||
| "set_hash: already exists; multiple forks with shared slot {} as child (parent: {})!?", | ||
| slot, parent_slot, | ||
| ); | ||
| return; | ||
| } | ||
|
|
||
| let hash = hash_info.hash; | ||
| let new_hash_info = BankHashInfo { | ||
| hash, | ||
|
|
@@ -1028,18 +1035,16 @@ impl AccountsDB { | |
| |(collector, mismatch_found): &mut (Vec<BankHash>, bool), | ||
| option: Option<(&Pubkey, Account, Slot)>| { | ||
| if let Some((pubkey, account, slot)) = option { | ||
| if !sysvar::check_id(&account.owner) { | ||
| let hash = Self::hash_account(slot, &account, pubkey); | ||
| if hash != account.hash { | ||
| *mismatch_found = true; | ||
| } | ||
| if *mismatch_found { | ||
| return; | ||
| } | ||
| let hash = BankHash::from_hash(&hash); | ||
| debug!("xoring..{} key: {}", hash, pubkey); | ||
| collector.push(hash); | ||
| let hash = Self::hash_account(slot, &account, pubkey); | ||
| if hash != account.hash { | ||
| *mismatch_found = true; | ||
| } | ||
| if *mismatch_found { | ||
| return; | ||
| } | ||
| let hash = BankHash::from_hash(&hash); | ||
| debug!("xoring..{} key: {}", hash, pubkey); | ||
| collector.push(hash); | ||
| } | ||
| }, | ||
| ); | ||
|
|
@@ -1162,26 +1167,22 @@ impl AccountsDB { | |
| let hashes: Vec<_> = accounts | ||
| .iter() | ||
| .map(|(pubkey, account)| { | ||
| if !sysvar::check_id(&account.owner) { | ||
| let hash = BankHash::from_hash(&account.hash); | ||
| stats.update(account); | ||
| let new_hash = Self::hash_account(slot_id, account, pubkey); | ||
| let new_bank_hash = BankHash::from_hash(&new_hash); | ||
| debug!( | ||
| "hash_accounts: key: {} xor {} current: {}", | ||
| pubkey, hash, hash_state | ||
| ); | ||
| if !had_account { | ||
| hash_state = hash; | ||
| had_account = true; | ||
| } else { | ||
| hash_state.xor(hash); | ||
| } | ||
| hash_state.xor(new_bank_hash); | ||
| new_hash | ||
| let hash = BankHash::from_hash(&account.hash); | ||
| stats.update(account); | ||
| let new_hash = Self::hash_account(slot_id, account, pubkey); | ||
| let new_bank_hash = BankHash::from_hash(&new_hash); | ||
| debug!( | ||
| "hash_accounts: key: {} xor {} current: {}", | ||
| pubkey, hash, hash_state | ||
| ); | ||
| if !had_account { | ||
| hash_state = hash; | ||
| had_account = true; | ||
| } else { | ||
| Hash::default() | ||
| hash_state.xor(hash); | ||
| } | ||
| hash_state.xor(new_bank_hash); | ||
| new_hash | ||
| }) | ||
| .collect(); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sysvars are now the first citizen in the AccountsDB land. :)