Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: send votes to the immediate next leader #2607

Merged
merged 2 commits into from
Aug 16, 2024

Conversation

jstarry
Copy link

@jstarry jstarry commented Aug 15, 2024

Problem

Votes are always sent to the "forward leader" which is defined as the leader of the slot which is 2 slots beyond our latest poh clock slot. This means that a vote for the third slot of a given leader's slot span will always be sent to the following leader for inclusion in the first slot of that leader's slot span. This adds an unnecessary slot of latency to votes because the vote could potentially land in current leader's fourth slot.

Summary of Changes

  • Send votes to the leaders of the next two slots to decrease vote latency

Fixes #

@jstarry jstarry added v1.18 v2.0 Backport to v2.0 branch labels Aug 15, 2024
Copy link

mergify bot commented Aug 15, 2024

Backports to the stable branch are to be avoided unless absolutely necessary for fixing bugs, security issues, and perf regressions. Changes intended for backport should be structured such that a minimum effective diff can be committed separately from any refactoring, plumbing, cleanup, etc that are not strictly necessary to achieve the goal. Any of the latter should go only into master and ride the normal stabilization schedule.

Copy link

mergify bot commented Aug 15, 2024

Backports to the beta branch are to be avoided unless absolutely necessary for fixing bugs, security issues, and perf regressions. Changes intended for backport should be structured such that a minimum effective diff can be committed separately from any refactoring, plumbing, cleanup, etc that are not strictly necessary to achieve the goal. Any of the latter should go only into master and ride the normal stabilization schedule. Exceptions include CI/metrics changes, CLI improvements and documentation updates on a case by case basis.

AshwinSekar
AshwinSekar previously approved these changes Aug 15, 2024
Copy link

@AshwinSekar AshwinSekar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for looking at this
would be nice to have a better source of truth for the next leader, maybe another PoH that can't be reset to account for forks.

core/src/next_leader.rs Show resolved Hide resolved
@jstarry
Copy link
Author

jstarry commented Aug 15, 2024

would be nice to have a better source of truth for the next leader

Yeah I was thinking we could use blockstore to find in-progress or potential descendants of the last voted slot. This change felt like a good quick fix though.

@StaRkeSolanaValidator
Copy link

StaRkeSolanaValidator commented Aug 15, 2024

Problem

Votes are always sent to the "forward leader" which is defined as the leader of the slot which is 2 slots beyond our latest poh clock slot. This means that a vote for the third slot of a given leader's slot span will always be sent to the following leader for inclusion in the first slot of that leader's slot span. This adds an unnecessary slot of latency to votes because the vote could potentially land in current leader's fourth slot.

Summary of Changes

  • Send votes to the leaders of the next two slots to decrease vote latency

Fixes #

Hi @jstarry,

Is this not also applicable for all the transactions? I was assuming the next leader offset logic was the same for all of them so this improvement would apply for everyone.

pub const FORWARD_TRANSACTIONS_TO_LEADER_AT_SLOT_OFFSET: u64 = 2;

Regards and thanks,

behzadnouri
behzadnouri previously approved these changes Aug 15, 2024
Copy link

@behzadnouri behzadnouri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

upcoming_leaders
.into_iter()
.flatten()
.unique()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will probably be enough to just use dedup instead of unique here:
https://docs.rs/itertools/latest/itertools/trait.Itertools.html#method.dedup

let mut upcoming_leaders = Vec::with_capacity(fanout_slots);
let poh_recorder = poh_recorder.read().unwrap();
for n_slots in 1..=fanout_slots {
upcoming_leaders.push(poh_recorder.leader_after_n_slots(n_slots as u64));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None values could be filtered out earlier here, for example:

upcoming_leaders.extend((1..=fanout_slots).flat_map(...))

also deduping (instead of unique) here would probably be fine.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason not to use filter_map here over flat_map

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah i guess both would work

pub(crate) fn upcoming_leader_tpu_vote_sockets(
cluster_info: &ClusterInfo,
poh_recorder: &RwLock<PohRecorder>,
fanout_slots: usize,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just use u64 here to be consistent with leader_after_n_slots api, and avoid as u64 below.

next_leader_tpu_vote(cluster_info, poh_recorder)
.map(|(_pubkey, target_addr)| target_addr),
// Attempt to send our vote transaction to the leaders for the next few slots
const UPCOMING_LEADER_FANOUT_SLOTS: usize = 2;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would personally define this constant equal to FORWARD_TRANSACTIONS_TO_LEADER_AT_SLOT_OFFSET, for sake of consistency, and maybe a const_assert that is equal to 2.

carllin
carllin previously approved these changes Aug 15, 2024
@jstarry
Copy link
Author

jstarry commented Aug 15, 2024

Is this not also applicable for all the transactions? I was assuming the next leader offset logic was the same for all of them so this improvement would apply for everyone.

@StaRkeSolanaValidator yes the offset logic is also the same for general tx forwarding and could benefit from a similar fix. Keeping this PR scoped to votes right now because improving vote latency is a priority given TVC will be enabled soon.

@jstarry jstarry dismissed stale reviews from carllin, behzadnouri, and AshwinSekar via 6e918e4 August 15, 2024 23:50
@jstarry jstarry merged commit f4e2fa9 into anza-xyz:master Aug 16, 2024
41 checks passed
@jstarry jstarry deleted the fix/vote-service-leader branch August 16, 2024 02:56
mergify bot pushed a commit that referenced this pull request Aug 16, 2024
* fix: send votes to the immediate next leader

* feedback

(cherry picked from commit f4e2fa9)

# Conflicts:
#	core/src/next_leader.rs
mergify bot pushed a commit that referenced this pull request Aug 16, 2024
* fix: send votes to the immediate next leader

* feedback

(cherry picked from commit f4e2fa9)
jstarry added a commit that referenced this pull request Aug 29, 2024
… (#2620)

* fix: send votes to the immediate next leader (#2607)

* fix: send votes to the immediate next leader

* feedback

(cherry picked from commit f4e2fa9)

# Conflicts:
#	core/src/next_leader.rs

* fix conflicts

---------

Co-authored-by: Justin Starry <justin@anza.xyz>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
v1.18 v2.0 Backport to v2.0 branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants