Only allow votes when root distance gets too high (#19916)

This commit is contained in:
sakridge
2021-09-17 23:28:11 +03:00
committed by GitHub
parent 3b3822846b
commit eaa6aa0998
3 changed files with 45 additions and 3 deletions

View File

@ -50,6 +50,7 @@ use solana_sdk::{
use solana_transaction_status::token_balances::{
collect_token_balances, TransactionTokenBalancesSet,
};
use solana_vote_program::vote_transaction;
use std::{
borrow::Cow,
cmp,
@ -1025,12 +1026,16 @@ impl BankingStage {
msgs: &Packets,
transaction_indexes: &[usize],
libsecp256k1_0_5_upgrade_enabled: bool,
votes_only: bool,
) -> (Vec<HashedTransaction<'static>>, Vec<usize>) {
transaction_indexes
.iter()
.filter_map(|tx_index| {
let p = &msgs.packets[*tx_index];
let tx: Transaction = limited_deserialize(&p.data[0..p.meta.size]).ok()?;
if votes_only && vote_transaction::parse_vote_transaction(&tx).is_none() {
return None;
}
tx.verify_precompiles(libsecp256k1_0_5_upgrade_enabled)
.ok()?;
let message_bytes = Self::packet_message(p)?;
@ -1097,6 +1102,7 @@ impl BankingStage {
msgs,
&packet_indexes,
bank.libsecp256k1_0_5_upgrade_enabled(),
bank.vote_only_bank(),
);
packet_conversion_time.stop();
@ -1168,6 +1174,7 @@ impl BankingStage {
msgs,
&transaction_indexes,
bank.libsecp256k1_0_5_upgrade_enabled(),
false,
);
let tx_count = transaction_to_packet_indexes.len();

View File

@ -1227,12 +1227,15 @@ impl ReplayStage {
poh_slot, parent_slot, root_slot
);
let root_distance = poh_slot - root_slot;
let tpu_bank = Self::new_bank_from_parent_with_notify(
&parent,
poh_slot,
root_slot,
my_pubkey,
subscriptions,
root_distance > 500,
);
let tpu_bank = bank_forks.write().unwrap().insert(tpu_bank);
@ -2489,6 +2492,7 @@ impl ReplayStage {
forks.root(),
&leader,
subscriptions,
false,
);
let empty: Vec<Pubkey> = vec![];
Self::update_fork_propagated_threshold_from_votes(
@ -2515,9 +2519,10 @@ impl ReplayStage {
root_slot: u64,
leader: &Pubkey,
subscriptions: &Arc<RpcSubscriptions>,
vote_only_bank: bool,
) -> Bank {
subscriptions.notify_slot(slot, parent.slot(), root_slot);
Bank::new_from_parent(parent, leader, slot)
Bank::new_from_parent_with_vote_only(parent, leader, slot, vote_only_bank)
}
fn record_rewards(bank: &Bank, rewards_recorder_sender: &Option<RewardsRecorderSender>) {

View File

@ -912,6 +912,8 @@ pub struct Bank {
pub drop_callback: RwLock<OptionalDropCallback>,
pub freeze_started: AtomicBool,
vote_only_bank: bool,
}
impl Default for BlockhashQueue {
@ -1012,7 +1014,22 @@ impl Bank {
/// Create a new bank that points to an immutable checkpoint of another bank.
pub fn new_from_parent(parent: &Arc<Bank>, collector_id: &Pubkey, slot: Slot) -> Self {
Self::_new_from_parent(parent, collector_id, slot, &mut null_tracer())
Self::_new_from_parent(parent, collector_id, slot, &mut null_tracer(), false)
}
pub fn new_from_parent_with_vote_only(
parent: &Arc<Bank>,
collector_id: &Pubkey,
slot: Slot,
vote_only_bank: bool,
) -> Self {
Self::_new_from_parent(
parent,
collector_id,
slot,
&mut null_tracer(),
vote_only_bank,
)
}
pub fn new_from_parent_with_tracer(
@ -1021,7 +1038,13 @@ impl Bank {
slot: Slot,
reward_calc_tracer: impl FnMut(&RewardCalculationEvent),
) -> Self {
Self::_new_from_parent(parent, collector_id, slot, &mut Some(reward_calc_tracer))
Self::_new_from_parent(
parent,
collector_id,
slot,
&mut Some(reward_calc_tracer),
false,
)
}
fn _new_from_parent(
@ -1029,6 +1052,7 @@ impl Bank {
collector_id: &Pubkey,
slot: Slot,
reward_calc_tracer: &mut Option<impl FnMut(&RewardCalculationEvent)>,
vote_only_bank: bool,
) -> Self {
parent.freeze();
assert_ne!(slot, parent.slot());
@ -1074,6 +1098,7 @@ impl Bank {
fee_calculator: fee_rate_governor.create_fee_calculator(),
fee_rate_governor,
capitalization: AtomicU64::new(parent.capitalization()),
vote_only_bank,
inflation: parent.inflation.clone(),
transaction_count: AtomicU64::new(parent.transaction_count()),
transaction_error_count: AtomicU64::new(0),
@ -1170,6 +1195,10 @@ impl Bank {
*self.drop_callback.write().unwrap() = OptionalDropCallback(callback);
}
pub fn vote_only_bank(&self) -> bool {
self.vote_only_bank
}
/// Like `new_from_parent` but additionally:
/// * Doesn't assume that the parent is anywhere near `slot`, parent could be millions of slots
/// in the past
@ -1265,6 +1294,7 @@ impl Bank {
feature_set: new(),
drop_callback: RwLock::new(OptionalDropCallback(None)),
freeze_started: AtomicBool::new(fields.hash != Hash::default()),
vote_only_bank: false,
};
bank.finish_init(genesis_config, additional_builtins);