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: read rpc config when using fork cheatcodes #9547

Merged
merged 12 commits into from
Dec 14, 2024

Conversation

anukul
Copy link
Contributor

@anukul anukul commented Dec 12, 2024

Motivation

Closes #9162 - Set retry config (backoff, max retries) from rpc configuration when a fork is created using cheatcodes

Solution

Idea - #9162 (comment)

Implementation:

Use two structs RpcEndpoint and ResolvedRpcEndpoint that both contain the same data, with the exception that environment variables are resolved to their values in ResolvedRpcEndpoint.

Extract shared fields out into a common struct field RpcEndpointConfig that doesn't need environment variable resolution.

@anukul anukul changed the title read rpc config when using fork cheatcodes fix: read rpc config when using fork cheatcodes Dec 12, 2024
Copy link
Member

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

this is great,

a few nits/questions

Comment on lines +333 to +337
evm_opts.fork_retries = rpc_endpoint.config.retries;
evm_opts.fork_retry_backoff = rpc_endpoint.config.retry_backoff;
if let Some(Ok(auth)) = rpc_endpoint.auth {
evm_opts.fork_headers = Some(vec![format!("Authorization: {auth}")]);
}
Copy link
Member

Choose a reason for hiding this comment

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

cool

Some(Err(err)) => {
pub fn rpc_endpoint(&self, url_or_alias: &str) -> Result<ResolvedRpcEndpoint> {
if let Some(endpoint) = self.rpc_endpoints.get(url_or_alias) {
let mut endpoint = endpoint.clone();
Copy link
Member

Choose a reason for hiding this comment

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

do we need this clone here?

looks like we can return endpoint.try_resolve() instead if unresolved?

Comment on lines 443 to 450
let mut new_endpoint = self.clone();
if let Err(err) = self.endpoint {
new_endpoint.endpoint = err.try_resolve()
}
if let Some(Err(err)) = &new_endpoint.auth {
new_endpoint.auth = Some(err.try_resolve())
}
new_endpoint
Copy link
Member

Choose a reason for hiding this comment

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

this looks slightly weird

this clone shouldn't be necessary here

pub fn rpc_endpoint(&self, url_or_alias: &str) -> Result<ResolvedRpcEndpoint> {
if let Some(endpoint) = self.rpc_endpoints.get(url_or_alias) {
let mut endpoint = endpoint.clone();
if endpoint.is_unresolved() {
Copy link
Member

Choose a reason for hiding this comment

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

isn't this check redundant because this is also called in try_resolve?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks for catching that, pushed some fixes

@anukul anukul requested a review from mattsse December 12, 2024 20:02
@zerosnacks
Copy link
Member

Thanks @anukul! This looks great

crates/cheatcodes/src/config.rs Outdated Show resolved Hide resolved
@mattsse mattsse merged commit 233bff2 into foundry-rs:master Dec 14, 2024
22 checks passed
@anukul anukul deleted the rpc-config branch December 14, 2024 21:16
@grandizzy grandizzy added T-bug Type: bug C-forge Command: forge labels Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-forge Command: forge T-bug Type: bug
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

feat(cheatcodes): add --fork-retry + --fork-retry-backoff equivalent to vm.create*Fork
4 participants