Skip to content

Commit

Permalink
pr feedback: yolo_hash -> vote_only_hash, use option for replay_slot
Browse files Browse the repository at this point in the history
  • Loading branch information
AshwinSekar committed Oct 1, 2024
1 parent b071342 commit 8fe05e7
Show file tree
Hide file tree
Showing 11 changed files with 89 additions and 78 deletions.
2 changes: 1 addition & 1 deletion core/src/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ pub(crate) enum BlockhashStatus {
#[cfg_attr(
feature = "frozen-abi",
derive(AbiExample),
frozen_abi(digest = "Lbx8JWmgAWq4SSo1XyrXprAgPtp9ncRNJJPCKH1pZ3W")
frozen_abi(digest = "jq28RP4SJpNQ3tZJ88zUcrEShMzhiTrNajyTXHgE7vR")
)]
#[derive(Clone, Serialize, Deserialize, Debug, PartialEq)]
pub struct Tower {
Expand Down
2 changes: 1 addition & 1 deletion core/src/consensus/tower1_14_11.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use {
#[cfg_attr(
feature = "frozen-abi",
derive(AbiExample),
frozen_abi(digest = "FYKsZaj6MH3hqA4ksJWEG8LHQZF3Ty5PQgfbexnpAPtB")
frozen_abi(digest = "FiF3sSBJQFoKAcU4xz3vpSopBqu1XfS7GE9SxNHaTzCq")
)]
#[derive(Clone, Serialize, Deserialize, Debug, PartialEq)]
pub struct Tower1_14_11 {
Expand Down
2 changes: 1 addition & 1 deletion cost-model/src/transaction_cost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ mod tests {
// expected vote tx cost: 2 write locks, 1 sig, 1 vote ix, 8cu of loaded accounts size,
let expected_vote_cost = SIMPLE_VOTE_USAGE_COST;
// expected non-vote tx cost would include default loaded accounts size cost (16384) additionally
let expected_none_vote_cost = 20553;
let expected_none_vote_cost = 20551;

let vote_cost = CostModel::calculate_cost(&vote_transaction, &FeatureSet::all_enabled());
let none_vote_cost =
Expand Down
2 changes: 1 addition & 1 deletion local-cluster/tests/local_cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3967,7 +3967,7 @@ fn run_duplicate_shreds_broadcast_leader(vote_on_duplicate: bool) {
AncestorIterator::new_inclusive(latest_vote_slot, &leader_blockstore)
.nth(MAX_LOCKOUT_HISTORY);
vote.root = root;
vote.hash = vote_hash;
vote.replay_hash = vote_hash;
let vote_tx = vote_transaction::new_tower_sync_transaction(
vote,
leader_vote_tx.message.recent_blockhash,
Expand Down
4 changes: 3 additions & 1 deletion programs/vote/benches/process_vote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,9 @@ fn bench_process_tower_sync(bencher: &mut Bencher) {
((num_initial_votes.saturating_add(1)..=last_vote_slot).zip((1u32..=31).rev())).collect();
let mut tower_sync = TowerSync::from(slots_and_lockouts);
tower_sync.root = Some(num_initial_votes);
tower_sync.hash = last_vote_hash;
tower_sync.vote_only_hash = Hash::default();
tower_sync.replay_slot = Some(last_vote_slot);
tower_sync.replay_hash = last_vote_hash;
tower_sync.block_id = Hash::new_unique();
let instruction_data = bincode::serialize(&VoteInstruction::TowerSync(tower_sync)).unwrap();

Expand Down
66 changes: 33 additions & 33 deletions programs/vote/src/vote_state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use {
#[cfg_attr(
feature = "frozen-abi",
derive(AbiExample, AbiEnumVisitor),
frozen_abi(digest = "5zYYafKxFiaQj4s1PUhK7bW2rKAXBBcnpHVxR8kfpZhQ")
frozen_abi(digest = "2ur9qpyZBfJBTLncyqwh9pyQR4U8Xgd2iyMJPPKoSC2f")
)]
#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
pub enum VoteTransaction {
Expand Down Expand Up @@ -90,7 +90,7 @@ impl VoteTransaction {
VoteTransaction::Vote(vote) => vote.hash,
VoteTransaction::VoteStateUpdate(vote_state_update) => vote_state_update.hash,
VoteTransaction::CompactVoteStateUpdate(vote_state_update) => vote_state_update.hash,
VoteTransaction::TowerSync(tower_sync) => tower_sync.hash,
VoteTransaction::TowerSync(tower_sync) => tower_sync.replay_hash,
}
}

Expand Down Expand Up @@ -1176,7 +1176,7 @@ fn do_process_tower_sync(
vote_state,
&mut tower_sync.lockouts,
&mut tower_sync.root,
tower_sync.hash,
tower_sync.replay_hash,
slot_hashes,
)?;
process_new_vote_state(
Expand Down Expand Up @@ -3178,7 +3178,7 @@ mod tests {
&empty_vote_state,
&mut tower_sync.lockouts,
&mut tower_sync.root,
tower_sync.hash,
tower_sync.replay_hash,
&empty_slot_hashes
),
Err(VoteError::EmptySlots),
Expand All @@ -3191,7 +3191,7 @@ mod tests {
&empty_vote_state,
&mut tower_sync.lockouts,
&mut tower_sync.root,
tower_sync.hash,
tower_sync.replay_hash,
&empty_slot_hashes
),
Err(VoteError::SlotsMismatch),
Expand All @@ -3212,7 +3212,7 @@ mod tests {
&vote_state,
&mut tower_sync.lockouts,
&mut tower_sync.root,
tower_sync.hash,
tower_sync.replay_hash,
&slot_hashes
),
Err(VoteError::VoteTooOld),
Expand All @@ -3229,7 +3229,7 @@ mod tests {
&vote_state,
&mut tower_sync.lockouts,
&mut tower_sync.root,
tower_sync.hash,
tower_sync.replay_hash,
&slot_hashes
),
Err(VoteError::VoteTooOld),
Expand Down Expand Up @@ -3279,13 +3279,13 @@ mod tests {
// Root slot in the `TowerSync` should be updated to match the root slot in the
// current vote state
let mut tower_sync = TowerSync::from(proposed_slots_and_lockouts);
tower_sync.hash = proposed_hash;
tower_sync.replay_hash = proposed_hash;
tower_sync.root = Some(proposed_root);
check_and_filter_proposed_vote_state(
&vote_state,
&mut tower_sync.lockouts,
&mut tower_sync.root,
tower_sync.hash,
tower_sync.replay_hash,
&slot_hashes,
)
.unwrap();
Expand Down Expand Up @@ -3451,27 +3451,27 @@ mod tests {
.unwrap()
.1;
let mut tower_sync = TowerSync::from(vec![(2, 2), (1, 3), (vote_slot, 1)]);
tower_sync.hash = vote_slot_hash;
tower_sync.replay_hash = vote_slot_hash;
assert_eq!(
check_and_filter_proposed_vote_state(
&vote_state,
&mut tower_sync.lockouts,
&mut tower_sync.root,
tower_sync.hash,
tower_sync.replay_hash,
&slot_hashes
),
Err(VoteError::SlotsNotOrdered),
);

// Test with a `TowerSync` where there are multiples of the same slot
let mut tower_sync = TowerSync::from(vec![(2, 2), (2, 2), (vote_slot, 1)]);
tower_sync.hash = vote_slot_hash;
tower_sync.replay_hash = vote_slot_hash;
assert_eq!(
check_and_filter_proposed_vote_state(
&vote_state,
&mut tower_sync.lockouts,
&mut tower_sync.root,
tower_sync.hash,
tower_sync.replay_hash,
&slot_hashes
),
Err(VoteError::SlotsNotOrdered),
Expand Down Expand Up @@ -3501,12 +3501,12 @@ mod tests {
(missing_older_than_history_slot, 2),
(vote_slot, 3),
]);
tower_sync.hash = vote_slot_hash;
tower_sync.replay_hash = vote_slot_hash;
check_and_filter_proposed_vote_state(
&vote_state,
&mut tower_sync.lockouts,
&mut tower_sync.root,
tower_sync.hash,
tower_sync.replay_hash,
&slot_hashes,
)
.unwrap();
Expand Down Expand Up @@ -3554,12 +3554,12 @@ mod tests {
let existing_older_than_history_slot = 4;
let mut tower_sync =
TowerSync::from(vec![(existing_older_than_history_slot, 3), (vote_slot, 2)]);
tower_sync.hash = vote_slot_hash;
tower_sync.replay_hash = vote_slot_hash;
check_and_filter_proposed_vote_state(
&vote_state,
&mut tower_sync.lockouts,
&mut tower_sync.root,
tower_sync.hash,
tower_sync.replay_hash,
&slot_hashes,
)
.unwrap();
Expand Down Expand Up @@ -3621,12 +3621,12 @@ mod tests {
(12, 2),
(vote_slot, 1),
]);
tower_sync.hash = vote_slot_hash;
tower_sync.replay_hash = vote_slot_hash;
check_and_filter_proposed_vote_state(
&vote_state,
&mut tower_sync.lockouts,
&mut tower_sync.root,
tower_sync.hash,
tower_sync.replay_hash,
&slot_hashes,
)
.unwrap();
Expand Down Expand Up @@ -3675,13 +3675,13 @@ mod tests {
.unwrap()
.1;
let mut tower_sync = TowerSync::from(vec![(missing_vote_slot, 2), (vote_slot, 3)]);
tower_sync.hash = vote_slot_hash;
tower_sync.replay_hash = vote_slot_hash;
assert_eq!(
check_and_filter_proposed_vote_state(
&vote_state,
&mut tower_sync.lockouts,
&mut tower_sync.root,
tower_sync.hash,
tower_sync.replay_hash,
&slot_hashes
),
Err(VoteError::SlotsMismatch),
Expand All @@ -3696,13 +3696,13 @@ mod tests {
(missing_vote_slot, 2),
(vote_slot, 1),
]);
tower_sync.hash = vote_slot_hash;
tower_sync.replay_hash = vote_slot_hash;
assert_eq!(
check_and_filter_proposed_vote_state(
&vote_state,
&mut tower_sync.lockouts,
&mut tower_sync.root,
tower_sync.hash,
tower_sync.replay_hash,
&slot_hashes
),
Err(VoteError::SlotsMismatch),
Expand Down Expand Up @@ -3731,14 +3731,14 @@ mod tests {
.unwrap()
.1;
let mut tower_sync = TowerSync::from(vec![(vote_slot, 1)]);
tower_sync.hash = vote_slot_hash;
tower_sync.replay_hash = vote_slot_hash;
tower_sync.root = Some(new_root);
assert_eq!(
check_and_filter_proposed_vote_state(
&vote_state,
&mut tower_sync.lockouts,
&mut tower_sync.root,
tower_sync.hash,
tower_sync.replay_hash,
&slot_hashes
),
Err(VoteError::RootOnDifferentFork),
Expand All @@ -3758,13 +3758,13 @@ mod tests {
let missing_vote_slot = slot_hashes.first().unwrap().0 + 1;
let vote_slot_hash = Hash::new_unique();
let mut tower_sync = TowerSync::from(vec![(8, 2), (missing_vote_slot, 3)]);
tower_sync.hash = vote_slot_hash;
tower_sync.replay_hash = vote_slot_hash;
assert_eq!(
check_and_filter_proposed_vote_state(
&vote_state,
&mut tower_sync.lockouts,
&mut tower_sync.root,
tower_sync.hash,
tower_sync.replay_hash,
&slot_hashes
),
Err(VoteError::SlotsMismatch),
Expand All @@ -3788,12 +3788,12 @@ mod tests {
.unwrap()
.1;
let mut tower_sync = TowerSync::from(vec![(2, 4), (4, 3), (6, 2), (vote_slot, 1)]);
tower_sync.hash = vote_slot_hash;
tower_sync.replay_hash = vote_slot_hash;
check_and_filter_proposed_vote_state(
&vote_state,
&mut tower_sync.lockouts,
&mut tower_sync.root,
tower_sync.hash,
tower_sync.replay_hash,
&slot_hashes,
)
.unwrap();
Expand Down Expand Up @@ -3841,12 +3841,12 @@ mod tests {
.unwrap()
.1;
let mut tower_sync = TowerSync::from(vec![(4, 2), (vote_slot, 1)]);
tower_sync.hash = vote_slot_hash;
tower_sync.replay_hash = vote_slot_hash;
check_and_filter_proposed_vote_state(
&vote_state,
&mut tower_sync.lockouts,
&mut tower_sync.root,
tower_sync.hash,
tower_sync.replay_hash,
&slot_hashes,
)
.unwrap();
Expand Down Expand Up @@ -3892,13 +3892,13 @@ mod tests {
let vote_slot = vote_state.votes.back().unwrap().slot() + 2;
let vote_slot_hash = Hash::new_unique();
let mut tower_sync = TowerSync::from(vec![(2, 4), (4, 3), (6, 2), (vote_slot, 1)]);
tower_sync.hash = vote_slot_hash;
tower_sync.replay_hash = vote_slot_hash;
assert_eq!(
check_and_filter_proposed_vote_state(
&vote_state,
&mut tower_sync.lockouts,
&mut tower_sync.root,
tower_sync.hash,
tower_sync.replay_hash,
&slot_hashes,
),
Err(VoteError::SlotHashMismatch),
Expand Down
4 changes: 3 additions & 1 deletion sdk/program/src/vote/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,9 @@ impl VoteInstruction {
| Self::UpdateVoteStateSwitch(vote_state_update, _)
| Self::CompactUpdateVoteState(vote_state_update)
| Self::CompactUpdateVoteStateSwitch(vote_state_update, _) => vote_state_update.hash,
Self::TowerSync(tower_sync) | Self::TowerSyncSwitch(tower_sync, _) => tower_sync.hash,
Self::TowerSync(tower_sync) | Self::TowerSyncSwitch(tower_sync, _) => {
tower_sync.replay_hash
}
_ => panic!("Tried to get hash on non simple vote instruction"),
}
}
Expand Down
Loading

0 comments on commit 8fe05e7

Please sign in to comment.