Skip to content

Add local cluster utitlity functions#355

Merged
carllin merged 2 commits intoanza-xyz:masterfrom
carllin:FixLocalClusterUtility
Mar 26, 2024
Merged

Add local cluster utitlity functions#355
carllin merged 2 commits intoanza-xyz:masterfrom
carllin:FixLocalClusterUtility

Conversation

@carllin
Copy link
Copy Markdown

@carllin carllin commented Mar 21, 2024

Problem

Missing some useful utility function

Summary of Changes

  1. Add function to wait for a root > min root from the cluster
  2. Add function to simulate a vote in tower and store that tower

Fixes #

@carllin carllin changed the title Add utitlity functions Add local cluster utitlity functions Mar 21, 2024
@carllin carllin force-pushed the FixLocalClusterUtility branch from 9508ae0 to f6b4f6c Compare March 21, 2024 06:11
@carllin carllin force-pushed the FixLocalClusterUtility branch from f6b4f6c to 0026ec6 Compare March 21, 2024 06:13
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.9%. Comparing base (1e08e90) to head (0026ec6).

Additional details and impacted files
@@            Coverage Diff            @@
##           master     #355     +/-   ##
=========================================
- Coverage    81.9%    81.9%   -0.1%     
=========================================
  Files         838      838             
  Lines      227366   227366             
=========================================
- Hits       186292   186291      -1     
- Misses      41074    41075      +1     

Comment thread core/src/consensus.rs
self.last_vote = new_vote;
}

fn record_bank_vote_and_update_lockouts(
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit: can we reuse record_vote instead of changing the visibility on this? looks like that one is already used for tests.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

good call, changed

let client = ThinClient::new(rpc, tpu, connection_cache.clone());
loop {
let root_slot = client
.get_slot_with_commitment(CommitmentConfig::finalized())
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

don't know the context of where you plan to use this yet, but is this more preferable than checking root from VoteState?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

That was the other option, but this was intended as a faster replacement for check_for_new_roots() which goes over the client.

Directly introspecting the tower has always been more of a hack, since LocalCluster was always supposed to support a generic interface for interacting with any cluster, even one that's remote. So when possible, trying to avoid it

Comment thread local-cluster/src/cluster_tests.rs Outdated
}
}

pub fn simulate_tower(node_keypair: &Keypair, votes: Vec<(Slot, Hash)>, tower_path: PathBuf) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit: simulate_tower is vague, this is really building new tower from votes?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

It's applying new votes to an existing tower, so maybe apply_votes_to_tower(). changed.

}

pub fn check_min_slot_is_rooted(
min_slot: Slot,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I'm confused: why is this min_slot instead of just slot? (How is min_slot different from a normal slot?)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

it's not guaranteed that at the time you check that the root is exactly some slot X, the validator could have made another root. Thus we just check for a minimum

pub fn check_min_slot_is_rooted(
min_slot: Slot,
contact_infos: &[ContactInfo],
connection_cache: &Arc<ConnectionCache>,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit: Probably better to describe in function name or comments we are testing the designated slot is root on all given contact_infos?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

it's not that we are checking that min_slot is rooted, we are checking that some slot greater than the min_slot is rooted

for ingress_node in contact_infos.iter() {
let (rpc, tpu) = LegacyContactInfo::try_from(ingress_node)
.map(|node| get_client_facing_addr(connection_cache.protocol(), node))
.unwrap();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Are we sure this unwrap() will always succeed?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

yup if the contact info is well formed seems like it should always work

wen-coding
wen-coding previously approved these changes Mar 22, 2024
Comment thread core/src/consensus.rs
}
}

#[cfg(test)]
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

think you can use the new guy here:

#[cfg(feature = "dev-context-only-utils")]

Copy link
Copy Markdown
Author

@carllin carllin Mar 23, 2024

Choose a reason for hiding this comment

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

didn't even realize this existed, works much wao

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

huh strange. I'm fine if you push it without the flag for now

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

cool, removed

@carllin carllin merged commit b01d792 into anza-xyz:master Mar 26, 2024
OliverNChalk pushed a commit to OliverNChalk/agave that referenced this pull request Nov 11, 2025
I need to perform this kind of updates quite frequently.  It is good to
have the process documented and the commonly used command written done
for the purposes of copy and paste :)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants