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

suggestion to don't clone self in get_block #9044

Merged
merged 1 commit into from
Nov 29, 2024

Conversation

oxarbitrage
Copy link
Contributor

Motivation

In #9006 we are cloning self in the get_block implementation which could bring some problems in some tests.

Solution

This is an alternative to do that that @conradoplg might find useful, feel free to discard.

@oxarbitrage oxarbitrage requested a review from a team as a code owner November 19, 2024 20:19
@oxarbitrage oxarbitrage requested review from arya2 and removed request for a team November 19, 2024 20:19
@mpguerra mpguerra requested review from conradoplg and removed request for arya2 November 20, 2024 08:45
Comment on lines +757 to +761
let get_block_header_future = if matches!(verbosity, 1 | 2) {
Some(self.get_block_header(original_hash_or_height.clone(), Some(true)))
} else {
None
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Optional/Nitpick/Subjective: This may actually be a little less readable, but it's tempting to use then() here.

Suggested change
let get_block_header_future = if matches!(verbosity, 1 | 2) {
Some(self.get_block_header(original_hash_or_height.clone(), Some(true)))
} else {
None
};
let get_block_header_future = matches!(verbosity, 1 | 2)
.then(|| self.get_block_header(original_hash_or_height.clone(), Some(true)));

@arya2
Copy link
Contributor

arya2 commented Nov 29, 2024

@conradoplg There's very little in RpcImpl being cloned but this looks like a good cleanup if you'd like to merge it into your PR. @oxarbitrage This could be a good change to include in your jsonrpsee PR if the base branch merges without it.

@conradoplg conradoplg merged commit 46385ef into get-block Nov 29, 2024
144 of 147 checks passed
@conradoplg conradoplg deleted the get-block-suggestion branch November 29, 2024 16:32
@conradoplg
Copy link
Collaborator

Thanks! I'm not sure if this will solve the issues I'm getting implementing #9024 but I'll give it a shot there, inspired on this approoach.

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.

3 participants