Only allow votes when root distance gets too high (#19916)
This commit is contained in:
@ -50,6 +50,7 @@ use solana_sdk::{
|
|||||||
use solana_transaction_status::token_balances::{
|
use solana_transaction_status::token_balances::{
|
||||||
collect_token_balances, TransactionTokenBalancesSet,
|
collect_token_balances, TransactionTokenBalancesSet,
|
||||||
};
|
};
|
||||||
|
use solana_vote_program::vote_transaction;
|
||||||
use std::{
|
use std::{
|
||||||
borrow::Cow,
|
borrow::Cow,
|
||||||
cmp,
|
cmp,
|
||||||
@ -1025,12 +1026,16 @@ impl BankingStage {
|
|||||||
msgs: &Packets,
|
msgs: &Packets,
|
||||||
transaction_indexes: &[usize],
|
transaction_indexes: &[usize],
|
||||||
libsecp256k1_0_5_upgrade_enabled: bool,
|
libsecp256k1_0_5_upgrade_enabled: bool,
|
||||||
|
votes_only: bool,
|
||||||
) -> (Vec<HashedTransaction<'static>>, Vec<usize>) {
|
) -> (Vec<HashedTransaction<'static>>, Vec<usize>) {
|
||||||
transaction_indexes
|
transaction_indexes
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|tx_index| {
|
.filter_map(|tx_index| {
|
||||||
let p = &msgs.packets[*tx_index];
|
let p = &msgs.packets[*tx_index];
|
||||||
let tx: Transaction = limited_deserialize(&p.data[0..p.meta.size]).ok()?;
|
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)
|
tx.verify_precompiles(libsecp256k1_0_5_upgrade_enabled)
|
||||||
.ok()?;
|
.ok()?;
|
||||||
let message_bytes = Self::packet_message(p)?;
|
let message_bytes = Self::packet_message(p)?;
|
||||||
@ -1097,6 +1102,7 @@ impl BankingStage {
|
|||||||
msgs,
|
msgs,
|
||||||
&packet_indexes,
|
&packet_indexes,
|
||||||
bank.libsecp256k1_0_5_upgrade_enabled(),
|
bank.libsecp256k1_0_5_upgrade_enabled(),
|
||||||
|
bank.vote_only_bank(),
|
||||||
);
|
);
|
||||||
packet_conversion_time.stop();
|
packet_conversion_time.stop();
|
||||||
|
|
||||||
@ -1168,6 +1174,7 @@ impl BankingStage {
|
|||||||
msgs,
|
msgs,
|
||||||
&transaction_indexes,
|
&transaction_indexes,
|
||||||
bank.libsecp256k1_0_5_upgrade_enabled(),
|
bank.libsecp256k1_0_5_upgrade_enabled(),
|
||||||
|
false,
|
||||||
);
|
);
|
||||||
|
|
||||||
let tx_count = transaction_to_packet_indexes.len();
|
let tx_count = transaction_to_packet_indexes.len();
|
||||||
|
@ -1227,12 +1227,15 @@ impl ReplayStage {
|
|||||||
poh_slot, parent_slot, root_slot
|
poh_slot, parent_slot, root_slot
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let root_distance = poh_slot - root_slot;
|
||||||
|
|
||||||
let tpu_bank = Self::new_bank_from_parent_with_notify(
|
let tpu_bank = Self::new_bank_from_parent_with_notify(
|
||||||
&parent,
|
&parent,
|
||||||
poh_slot,
|
poh_slot,
|
||||||
root_slot,
|
root_slot,
|
||||||
my_pubkey,
|
my_pubkey,
|
||||||
subscriptions,
|
subscriptions,
|
||||||
|
root_distance > 500,
|
||||||
);
|
);
|
||||||
|
|
||||||
let tpu_bank = bank_forks.write().unwrap().insert(tpu_bank);
|
let tpu_bank = bank_forks.write().unwrap().insert(tpu_bank);
|
||||||
@ -2489,6 +2492,7 @@ impl ReplayStage {
|
|||||||
forks.root(),
|
forks.root(),
|
||||||
&leader,
|
&leader,
|
||||||
subscriptions,
|
subscriptions,
|
||||||
|
false,
|
||||||
);
|
);
|
||||||
let empty: Vec<Pubkey> = vec![];
|
let empty: Vec<Pubkey> = vec![];
|
||||||
Self::update_fork_propagated_threshold_from_votes(
|
Self::update_fork_propagated_threshold_from_votes(
|
||||||
@ -2515,9 +2519,10 @@ impl ReplayStage {
|
|||||||
root_slot: u64,
|
root_slot: u64,
|
||||||
leader: &Pubkey,
|
leader: &Pubkey,
|
||||||
subscriptions: &Arc<RpcSubscriptions>,
|
subscriptions: &Arc<RpcSubscriptions>,
|
||||||
|
vote_only_bank: bool,
|
||||||
) -> Bank {
|
) -> Bank {
|
||||||
subscriptions.notify_slot(slot, parent.slot(), root_slot);
|
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>) {
|
fn record_rewards(bank: &Bank, rewards_recorder_sender: &Option<RewardsRecorderSender>) {
|
||||||
|
@ -912,6 +912,8 @@ pub struct Bank {
|
|||||||
pub drop_callback: RwLock<OptionalDropCallback>,
|
pub drop_callback: RwLock<OptionalDropCallback>,
|
||||||
|
|
||||||
pub freeze_started: AtomicBool,
|
pub freeze_started: AtomicBool,
|
||||||
|
|
||||||
|
vote_only_bank: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for BlockhashQueue {
|
impl Default for BlockhashQueue {
|
||||||
@ -1012,7 +1014,22 @@ impl Bank {
|
|||||||
|
|
||||||
/// Create a new bank that points to an immutable checkpoint of another 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 {
|
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(
|
pub fn new_from_parent_with_tracer(
|
||||||
@ -1021,7 +1038,13 @@ impl Bank {
|
|||||||
slot: Slot,
|
slot: Slot,
|
||||||
reward_calc_tracer: impl FnMut(&RewardCalculationEvent),
|
reward_calc_tracer: impl FnMut(&RewardCalculationEvent),
|
||||||
) -> Self {
|
) -> 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(
|
fn _new_from_parent(
|
||||||
@ -1029,6 +1052,7 @@ impl Bank {
|
|||||||
collector_id: &Pubkey,
|
collector_id: &Pubkey,
|
||||||
slot: Slot,
|
slot: Slot,
|
||||||
reward_calc_tracer: &mut Option<impl FnMut(&RewardCalculationEvent)>,
|
reward_calc_tracer: &mut Option<impl FnMut(&RewardCalculationEvent)>,
|
||||||
|
vote_only_bank: bool,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
parent.freeze();
|
parent.freeze();
|
||||||
assert_ne!(slot, parent.slot());
|
assert_ne!(slot, parent.slot());
|
||||||
@ -1074,6 +1098,7 @@ impl Bank {
|
|||||||
fee_calculator: fee_rate_governor.create_fee_calculator(),
|
fee_calculator: fee_rate_governor.create_fee_calculator(),
|
||||||
fee_rate_governor,
|
fee_rate_governor,
|
||||||
capitalization: AtomicU64::new(parent.capitalization()),
|
capitalization: AtomicU64::new(parent.capitalization()),
|
||||||
|
vote_only_bank,
|
||||||
inflation: parent.inflation.clone(),
|
inflation: parent.inflation.clone(),
|
||||||
transaction_count: AtomicU64::new(parent.transaction_count()),
|
transaction_count: AtomicU64::new(parent.transaction_count()),
|
||||||
transaction_error_count: AtomicU64::new(0),
|
transaction_error_count: AtomicU64::new(0),
|
||||||
@ -1170,6 +1195,10 @@ impl Bank {
|
|||||||
*self.drop_callback.write().unwrap() = OptionalDropCallback(callback);
|
*self.drop_callback.write().unwrap() = OptionalDropCallback(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn vote_only_bank(&self) -> bool {
|
||||||
|
self.vote_only_bank
|
||||||
|
}
|
||||||
|
|
||||||
/// Like `new_from_parent` but additionally:
|
/// Like `new_from_parent` but additionally:
|
||||||
/// * Doesn't assume that the parent is anywhere near `slot`, parent could be millions of slots
|
/// * Doesn't assume that the parent is anywhere near `slot`, parent could be millions of slots
|
||||||
/// in the past
|
/// in the past
|
||||||
@ -1265,6 +1294,7 @@ impl Bank {
|
|||||||
feature_set: new(),
|
feature_set: new(),
|
||||||
drop_callback: RwLock::new(OptionalDropCallback(None)),
|
drop_callback: RwLock::new(OptionalDropCallback(None)),
|
||||||
freeze_started: AtomicBool::new(fields.hash != Hash::default()),
|
freeze_started: AtomicBool::new(fields.hash != Hash::default()),
|
||||||
|
vote_only_bank: false,
|
||||||
};
|
};
|
||||||
bank.finish_init(genesis_config, additional_builtins);
|
bank.finish_init(genesis_config, additional_builtins);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user