Add ability to hard fork at any slot (#7801)

automerge
This commit is contained in:
Michael Vines
2020-01-24 18:27:04 -07:00
committed by Grimes
parent a2f2c46f87
commit 989355e885
8 changed files with 227 additions and 36 deletions

View File

@@ -6,6 +6,7 @@ use crate::{
accounts::{Accounts, TransactionAccounts, TransactionLoadResult, TransactionLoaders},
accounts_db::{AccountStorageEntry, AccountsDBSerialize, AppendVecId, ErrorCounters},
blockhash_queue::BlockhashQueue,
hard_forks::HardForks,
message_processor::{MessageProcessor, ProcessInstruction},
nonce_utils,
rent_collector::RentCollector,
@@ -35,7 +36,7 @@ use solana_sdk::{
epoch_schedule::EpochSchedule,
fee_calculator::FeeCalculator,
genesis_config::GenesisConfig,
hash::{hashv, Hash},
hash::{extend_and_hash, hashv, Hash},
inflation::Inflation,
native_loader,
nonce_state::NonceState,
@@ -226,6 +227,9 @@ pub struct Bank {
/// parent's slot
parent_slot: Slot,
/// slots to hard fork at
hard_forks: Arc<RwLock<HardForks>>,
/// The number of transactions processed without error
#[serde(serialize_with = "serialize_atomicu64")]
#[serde(deserialize_with = "deserialize_atomicu64")]
@@ -422,6 +426,7 @@ impl Bank {
signature_count: AtomicU64::new(0),
message_processor: MessageProcessor::default(),
entered_epoch_callback: parent.entered_epoch_callback.clone(),
hard_forks: parent.hard_forks.clone(),
last_vote_sync: AtomicU64::new(parent.last_vote_sync.load(Ordering::Relaxed)),
};
@@ -1685,6 +1690,10 @@ impl Bank {
*self.inflation.write().unwrap() = inflation;
}
pub fn hard_forks(&self) -> Arc<RwLock<HardForks>> {
self.hard_forks.clone()
}
pub fn set_entered_epoch_callback(&self, entered_epoch_callback: EnteredEpochCallback) {
*self.entered_epoch_callback.write().unwrap() = Some(entered_epoch_callback);
}
@@ -1779,20 +1788,33 @@ impl Bank {
let accounts_delta_hash = self.rc.accounts.bank_hash_info_at(self.slot());
let mut signature_count_buf = [0u8; 8];
LittleEndian::write_u64(&mut signature_count_buf[..], self.signature_count() as u64);
let hash = hashv(&[
let mut hash = hashv(&[
self.parent_hash.as_ref(),
accounts_delta_hash.hash.as_ref(),
&signature_count_buf,
self.last_blockhash().as_ref(),
]);
if let Some(buf) = self
.hard_forks
.read()
.unwrap()
.get_hash_data(self.slot(), self.parent_slot())
{
info!("hard fork at bank {}", self.slot());
hash = extend_and_hash(&hash, &buf)
}
info!(
"bank frozen: {} hash: {} accounts_delta: {} signature_count: {} last_blockhash: {}",
self.slot(),
hash,
accounts_delta_hash.hash,
self.signature_count(),
self.last_blockhash()
self.last_blockhash(),
);
info!(
"accounts hash slot: {} stats: {:?}",
self.slot(),
@@ -2147,6 +2169,7 @@ impl From<LegacyBank0223> for Bank {
storage_accounts: bank.storage_accounts,
parent_hash: bank.parent_hash,
parent_slot: bank.parent_slot,
hard_forks: Arc::new(RwLock::new(HardForks::default())),
collector_id: bank.collector_id,
collector_fees: bank.collector_fees,
ancestors: bank.ancestors,