Skip to content

Commit

Permalink
Don't attempt to refresh votes on non voting validators (#32315)
Browse files Browse the repository at this point in the history
(cherry picked from commit e1576b5)

# Conflicts:
#	core/src/replay_stage.rs
  • Loading branch information
AshwinSekar committed Jul 7, 2023
1 parent 5c5910c commit 37e870d
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 14 deletions.
9 changes: 5 additions & 4 deletions core/src/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@ pub struct Tower {
// blockhash of the voted block itself, depending if the vote slot was refreshed.
// For instance, a vote for slot 5, may be refreshed/resubmitted for inclusion in
// block 10, in which case `last_vote_tx_blockhash` equals the blockhash of 10, not 5.
last_vote_tx_blockhash: Hash,
// For non voting validators this is None
last_vote_tx_blockhash: Option<Hash>,
last_timestamp: BlockTimestamp,
#[serde(skip)]
// Restored last voted slot which cannot be found in SlotHistory at replayed root
Expand All @@ -237,7 +238,7 @@ impl Default for Tower {
vote_state: VoteState::default(),
last_vote: VoteTransaction::from(VoteStateUpdate::default()),
last_timestamp: BlockTimestamp::default(),
last_vote_tx_blockhash: Hash::default(),
last_vote_tx_blockhash: None,
stray_restored_slot: Option::default(),
last_switch_threshold_check: Option::default(),
};
Expand Down Expand Up @@ -450,7 +451,7 @@ impl Tower {
self.vote_state.tower()
}

pub fn last_vote_tx_blockhash(&self) -> Hash {
pub fn last_vote_tx_blockhash(&self) -> Option<Hash> {
self.last_vote_tx_blockhash
}

Expand Down Expand Up @@ -494,7 +495,7 @@ impl Tower {
}

pub fn refresh_last_vote_tx_blockhash(&mut self, new_vote_tx_blockhash: Hash) {
self.last_vote_tx_blockhash = new_vote_tx_blockhash;
self.last_vote_tx_blockhash = Some(new_vote_tx_blockhash);
}

// Returns true if we have switched the new vote instruction that directly sets vote state
Expand Down
31 changes: 24 additions & 7 deletions core/src/replay_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2350,9 +2350,14 @@ impl ReplayStage {
last_voted_slot
);
}

// If we are a non voting validator or have an incorrect setup preventing us from
// generating vote txs, no need to refresh
let Some(last_vote_tx_blockhash) = tower.last_vote_tx_blockhash() else { return };

if my_latest_landed_vote >= last_voted_slot
|| heaviest_bank_on_same_fork
.is_hash_valid_for_age(&tower.last_vote_tx_blockhash(), MAX_PROCESSING_AGE)
.is_hash_valid_for_age(&last_vote_tx_blockhash, MAX_PROCESSING_AGE)
|| {
// In order to avoid voting on multiple forks all past MAX_PROCESSING_AGE that don't
// include the last voted blockhash
Expand Down Expand Up @@ -6786,7 +6791,10 @@ pub(crate) mod tests {
assert_eq!(votes.len(), 1);
let vote_tx = &votes[0];
assert_eq!(vote_tx.message.recent_blockhash, bank0.last_blockhash());
assert_eq!(tower.last_vote_tx_blockhash(), bank0.last_blockhash());
assert_eq!(
tower.last_vote_tx_blockhash().unwrap(),
bank0.last_blockhash()
);
assert_eq!(tower.last_voted_slot().unwrap(), 0);
bank1.process_transaction(vote_tx).unwrap();
bank1.freeze();
Expand Down Expand Up @@ -6815,7 +6823,10 @@ pub(crate) mod tests {
let votes = cluster_info.get_votes(&mut cursor);
assert!(votes.is_empty());
// Tower's latest vote tx blockhash hasn't changed either
assert_eq!(tower.last_vote_tx_blockhash(), bank0.last_blockhash());
assert_eq!(
tower.last_vote_tx_blockhash().unwrap(),
bank0.last_blockhash()
);
assert_eq!(tower.last_voted_slot().unwrap(), 0);
}

Expand Down Expand Up @@ -6848,7 +6859,10 @@ pub(crate) mod tests {
assert_eq!(votes.len(), 1);
let vote_tx = &votes[0];
assert_eq!(vote_tx.message.recent_blockhash, bank1.last_blockhash());
assert_eq!(tower.last_vote_tx_blockhash(), bank1.last_blockhash());
assert_eq!(
tower.last_vote_tx_blockhash().unwrap(),
bank1.last_blockhash()
);
assert_eq!(tower.last_voted_slot().unwrap(), 1);

// Trying to refresh the vote for bank 1 in bank 2 won't succeed because
Expand All @@ -6870,7 +6884,10 @@ pub(crate) mod tests {
// No new votes have been submitted to gossip
let votes = cluster_info.get_votes(&mut cursor);
assert!(votes.is_empty());
assert_eq!(tower.last_vote_tx_blockhash(), bank1.last_blockhash());
assert_eq!(
tower.last_vote_tx_blockhash().unwrap(),
bank1.last_blockhash()
);
assert_eq!(tower.last_voted_slot().unwrap(), 1);

// Create a bank where the last vote transaction will have expired
Expand Down Expand Up @@ -6929,7 +6946,7 @@ pub(crate) mod tests {
expired_bank.last_blockhash()
);
assert_eq!(
tower.last_vote_tx_blockhash(),
tower.last_vote_tx_blockhash().unwrap(),
expired_bank.last_blockhash()
);
assert_eq!(tower.last_voted_slot().unwrap(), 1);
Expand Down Expand Up @@ -6985,7 +7002,7 @@ pub(crate) mod tests {
expired_bank.last_blockhash()
);
assert_eq!(
tower.last_vote_tx_blockhash(),
tower.last_vote_tx_blockhash().unwrap(),
expired_bank.last_blockhash()
);
assert_eq!(tower.last_voted_slot().unwrap(), 1);
Expand Down
2 changes: 1 addition & 1 deletion core/src/tower1_14_11.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub struct Tower1_14_11 {
// blockhash of the voted block itself, depending if the vote slot was refreshed.
// For instance, a vote for slot 5, may be refreshed/resubmitted for inclusion in
// block 10, in which case `last_vote_tx_blockhash` equals the blockhash of 10, not 5.
pub(crate) last_vote_tx_blockhash: Hash,
pub(crate) last_vote_tx_blockhash: Option<Hash>,
pub(crate) last_timestamp: BlockTimestamp,
#[serde(skip)]
// Restored last voted slot which cannot be found in SlotHistory at replayed root
Expand Down
2 changes: 1 addition & 1 deletion core/src/tower1_7_14.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub struct Tower1_7_14 {
// blockhash of the voted block itself, depending if the vote slot was refreshed.
// For instance, a vote for slot 5, may be refreshed/resubmitted for inclusion in
// block 10, in which case `last_vote_tx_blockhash` equals the blockhash of 10, not 5.
pub(crate) last_vote_tx_blockhash: Hash,
pub(crate) last_vote_tx_blockhash: Option<Hash>,
pub(crate) last_timestamp: BlockTimestamp,
#[serde(skip)]
// Restored last voted slot which cannot be found in SlotHistory at replayed root
Expand Down
2 changes: 1 addition & 1 deletion core/src/tower_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ pub mod test {
vote_state: VoteState1_14_11::from(vote_state),
last_vote: vote.clone(),
last_timestamp: BlockTimestamp::default(),
last_vote_tx_blockhash: Hash::default(),
last_vote_tx_blockhash: None,
stray_restored_slot: Some(2),
last_switch_threshold_check: Option::default(),
};
Expand Down

0 comments on commit 37e870d

Please sign in to comment.