feat: add client method to estimate recent blockhash#121
Merged
Conversation
c3cc025 to
c3d1ca3
Compare
1f569d1 to
9ba9444
Compare
This reverts commit fa97200.
407dedc to
01d568a
Compare
gregorydemay
reviewed
Jun 6, 2025
Contributor
gregorydemay
left a comment
There was a problem hiding this comment.
thanks a lot for this PR @lpahlavi ! Only some minor comments from my side.
libs/client/src/request/mod.rs
Outdated
| RpcError::from(e), | ||
| )), | ||
| } | ||
| continue; |
Contributor
There was a problem hiding this comment.
nit: continue appears quite often and some times it's easy to miss that one is missing. I would rewrite the code a bit to be safer. Something like
pub async fn send(self) -> Result<Hash, Vec<EstimateRecentBlockhashError>> {
let mut errors = Vec::with_capacity(self.num_tries.into());
while errors.len() <= self.num_tries.into() {
match self.get_slot_then_get_block().await {
Ok(hash) => return Ok(hash),
Err(e) => {
errors.push(e);
continue;
}
}
}
Err(errors)
}
async fn get_slot_then_get_block(&self) -> Result<Hash, EstimateRecentBlockhashError> {
let slot = self.get_slot().await?;
match self.get_block(slot).await? {
Some(block) => match Hash::from_str(&block.blockhash) {
Ok(blockhash) => return Ok(blockhash),
Err(e) => Err(EstimateRecentBlockhashError::GetBlockRpcError(
RpcError::from(e),
)),
},
None => Err(EstimateRecentBlockhashError::MissingBlock(slot)),
}
}
async fn get_slot(&self) -> Result<Slot, EstimateRecentBlockhashError> {
todo!()
}
async fn get_block(
&self,
slot: Slot,
) -> Result<Option<UiConfirmedBlock>, EstimateRecentBlockhashError> {
todo!()
}
gregorydemay
approved these changes
Jun 11, 2025
Contributor
gregorydemay
left a comment
There was a problem hiding this comment.
Very cool PR, thanks a lot for all the improvements @lpahlavi !
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
(XC-317): Add client method to estimate recent blockhash by repeatedly fetching
getSlotandgetBlockuntil either the maximum number of retries is reached, or a blockhash is obtained.The new method is tested in end-to-end tests and
solana_test_validator.rs, however further integration tests will follow in another PR due to the mock runtime currently not supporting mocking responses for sequential calls.