-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Conversation
There was a problem hiding this 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
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}")]); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool
crates/cheatcodes/src/config.rs
Outdated
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(); |
There was a problem hiding this comment.
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?
crates/config/src/endpoints.rs
Outdated
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 |
There was a problem hiding this comment.
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
crates/cheatcodes/src/config.rs
Outdated
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() { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
Thanks @anukul! This looks great |
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
andResolvedRpcEndpoint
that both contain the same data, with the exception that environment variables are resolved to their values inResolvedRpcEndpoint
.Extract shared fields out into a common struct field
RpcEndpointConfig
that doesn't need environment variable resolution.