alloy icon indicating copy to clipboard operation
alloy copied to clipboard

feat(alloy-provider): add abstraction for `NonceFiller` behavior

Open StackOverflowExcept1on opened this issue 1 year ago • 7 comments

Motivation

Resolves #1073

Solution

I added trait NonceManager and two implementations: SimpleNonceManager and CachedNonceManager to allow the user to choose the behavior of nonces filling. In the recommended fillers, I also changed the implementation from CachedNonceManager to SimpleNonceManager to make the recommended fillers more resilient to chain reorganizations. The issue was described in more detail in https://github.com/alloy-rs/alloy/issues/1073#issuecomment-2251181724.

PR Checklist

  • [ ] Added Tests
  • [x] Added Documentation
  • [x] Breaking changes

StackOverflowExcept1on avatar Jul 27 '24 13:07 StackOverflowExcept1on

Good point on the re-org resistance. An alternative solution could be to have a function a user can call to refetch the nonce, overwriting the cache entry. Assuming they have a system that is re-org aware they can simply call this function. I would prefer that over having two distinct implementations.

zerosnacks avatar Aug 08 '24 10:08 zerosnacks

@zerosnacks

An alternative solution could be to have a way of having a user be able to indicate that the nonce needs to be refetched.

Even if we indicate whether to fetch nonce from the rpc when sending the rpc request, it will still be inconvenient since you won't be able to fully customize the behavior as you wish.

StackOverflowExcept1on avatar Aug 08 '24 10:08 StackOverflowExcept1on

Even if we indicate whether to fetch nonce from the rpc when sending the rpc request, it will still be inconvenient since you won't be able to fully customize the behavior as you wish.

Could you expand on that? What kind of behavior would you be customizing that is not covered by my proposed approach?

zerosnacks avatar Aug 08 '24 11:08 zerosnacks

@zerosnacks this will help implement any behavior, but on the caller side you will need to pass a boolean value or use some wrapper, which seems inconvenient on the caller side. We will also need wrappers for providers, alloy::contract, etc.

StackOverflowExcept1on avatar Aug 08 '24 11:08 StackOverflowExcept1on

Also consider that you can't just get a NonceFiller instance and indicate it to fetch rpc, since it might be wrapped with JoinFill. So you'll have to invent some mechanism to interact with the NonceFiller via interior mutability.

StackOverflowExcept1on avatar Aug 08 '24 11:08 StackOverflowExcept1on

cc @onbjerg / @prestwich curious to hear your thoughts on this proposal / approach

zerosnacks avatar Aug 08 '24 11:08 zerosnacks

It makes sense to have other types of nonce management strategies. You can already do this using a custom filler, but this simplifies implementing a new nonce strategy somewhat, so I think this is ok.

Noting that this is a breaking change, though

cc @mattsse

onbjerg avatar Aug 08 '24 11:08 onbjerg

Hi, can someone take a look at the PR?

StackOverflowExcept1on avatar Aug 22 '24 10:08 StackOverflowExcept1on