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

[Doc] provider is arc'ed internally #2080

Open
Dvisacker opened this issue Feb 19, 2025 · 2 comments
Open

[Doc] provider is arc'ed internally #2080

Dvisacker opened this issue Feb 19, 2025 · 2 comments
Labels
c-provider documentation Improvements or additions to documentation question Further information is requested

Comments

@Dvisacker
Copy link

Dvisacker commented Feb 19, 2025

Component

provider, pubsub

What version of Alloy are you on?

alloy v0.11.1

Operating System

macOS (Apple Silicon)

Describe the bug

DynProvider in alloy v0.11.1 is really useful but I am having the following issue for functions that take Arc<P> where P: Provider as an argument.
In the example below changing provider: Arc<P> to provider: P fixes the problem but I am not sure that's ideal and many libraries have functions that require Arc<P>.

pub async fn get_token_balance<P: Provider>(
    provider: Arc<P>,
    token: Address,
    holder: Address,
) -> Result<U256> {
    let token = IERC20::new(token, provider.clone());
    let balance = token.balanceOf(holder).call().await?;
    Ok(balance._0)
}

DynProvider is a wrapper around an Arc but not directly an Arc and the functions above expects Arc<P> which results in a type mismatch.

pub struct DynProvider<N = Ethereum>(Arc<dyn Provider<N> + 'static>);

Perhaps adding a method like follows would help - I'm not sure -.

pub fn into_arc(self) -> Arc<dyn Provider> {
    self.0
}
@Dvisacker Dvisacker added the bug Something isn't working label Feb 19, 2025
@DaniPopes
Copy link
Member

Generally requiring Arc<P> is more restrictive and it's a leftover from ethers' middleware. If you want to clone the P then just add a + Clone bound, otherwise just P should be used.

That said we can still add such a method but I would highly recommend you try dropping the extra Arc everywhere as all providers are internally Arc'd anyway too.

@yash-atreya yash-atreya added question Further information is requested c-provider labels Feb 20, 2025
@Dvisacker
Copy link
Author

Dvisacker commented Feb 23, 2025

Makes sense, I didn't know providers where arc'd internally. Then feel free to close the issue if you wish - as you say I think it can make sense to add a method as some libraries require arc<P> but not needed for me personally.

@yash-atreya yash-atreya added documentation Improvements or additions to documentation and removed bug Something isn't working labels Feb 28, 2025
@yash-atreya yash-atreya changed the title [Bug] DynProvider type mismatch on functions that take Arc<P> as an argument. doc: provider is arc'ed internally Feb 28, 2025
@yash-atreya yash-atreya changed the title doc: provider is arc'ed internally [Doc]: provider is arc'ed internally Feb 28, 2025
@yash-atreya yash-atreya changed the title [Doc]: provider is arc'ed internally [Doc] provider is arc'ed internally Feb 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c-provider documentation Improvements or additions to documentation question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants