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

feat: integrate EvmOverrides to rpc types #906

Merged
merged 3 commits into from
Jun 16, 2024

Conversation

}

/// Creates a new instance with the given state overrides.
pub const fn state(state: Option<StateOverride>) -> Self {
Copy link
Member

Choose a reason for hiding this comment

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

why even allow None as an input?

Copy link
Member

Choose a reason for hiding this comment

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

this is also mainly useful from server POV because some methods only support StateOverrides or BlockOverrides and usually as Option.

Copy link
Member

Choose a reason for hiding this comment

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

My main point is that passing None to this function is always more clearly represented as Default::default which means this API is an artifact of a specific usage, not a good API on its own, and is not something we should make available to non-reth users

// `fn state(state:StateOverride) -> Self`
state_opt.map(EvmOverrides::state).unwrap_or_default()

// current api
EvmOverrides::state(state_opt)

// From<Option<_>> feels cleanest
state_opt.into()

Copy link
Member

Choose a reason for hiding this comment

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

/// Matches some other spots in reth
EvmOverrides::default().maybe_state(state_opt)

}

/// Creates a new instance with the given block overrides.
pub const fn block(block: Option<Box<BlockOverrides>>) -> Self {
Copy link
Member

Choose a reason for hiding this comment

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

same question

}
}

impl From<Option<StateOverride>> for EvmOverrides {
Copy link
Member

Choose a reason for hiding this comment

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

impl From<StateOverrides>
impl From<Box<BlockOverrides>>
impl From<Option<Box<BlockOverrides>>>

Copy link
Member

Choose a reason for hiding this comment

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

I'd actually like to remove this from impl entirely, the caller should call EvmOverrides::state instead

pub state: Option<StateOverride>,
/// Applies overrides to the block before execution.
///
/// This is a `Box` because less common and only available in debug trace endpoints.
Copy link
Member

Choose a reason for hiding this comment

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

if this type's only purpose is to be serialized, it could instead have borrows of each component?

Copy link
Member

Choose a reason for hiding this comment

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

these are only really useful from the server POV and are intended to bundle overrides that are separate arguments

Copy link
Member

Choose a reason for hiding this comment

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

so does this get deserialized as a unit? or does it get deser separately and then constructed?

Copy link
Member

Choose a reason for hiding this comment

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

separately then constructed, so in the method implementation we can pass overrides: EvmOverrides instead of two Option arguments

Copy link
Member

Choose a reason for hiding this comment

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

this smells like the API problem is minimizing diff for some existing-but-messy code. don't love it, but i won't block you merging it

Copy link
Member

@mattsse mattsse Jun 16, 2024

Choose a reason for hiding this comment

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

the issue here is that some endpoints support both override args or none at all, some only state, some only block, but a lot require the same setup, like eth_call, trace_call, call_many, estimate.
this helper type makes it possible to reuse the same setup

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.

pedantic nit re From impl

I'd like to have this type here as a helper even if not useful from the client POV, but on the server side this is very useful, hence this also does not require serde because it's not intended to be serialized

for example:

https://github.com/paradigmxyz/reth/blob/01b3757771496a6676a4e3c2b0ebde3978b70463/crates/rpc/rpc/src/eth/api/call.rs#L68-L74

pub state: Option<StateOverride>,
/// Applies overrides to the block before execution.
///
/// This is a `Box` because less common and only available in debug trace endpoints.
Copy link
Member

Choose a reason for hiding this comment

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

these are only really useful from the server POV and are intended to bundle overrides that are separate arguments

}

/// Creates a new instance with the given state overrides.
pub const fn state(state: Option<StateOverride>) -> Self {
Copy link
Member

Choose a reason for hiding this comment

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

this is also mainly useful from server POV because some methods only support StateOverrides or BlockOverrides and usually as Option.

}
}

impl From<Option<StateOverride>> for EvmOverrides {
Copy link
Member

Choose a reason for hiding this comment

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

I'd actually like to remove this from impl entirely, the caller should call EvmOverrides::state instead

@tcoratger
Copy link
Contributor Author

pedantic nit re From impl

I'd like to have this type here as a helper even if not useful from the client POV, but on the server side this is very useful, hence this also does not require serde because it's not intended to be serialized

for example:

https://github.com/paradigmxyz/reth/blob/01b3757771496a6676a4e3c2b0ebde3978b70463/crates/rpc/rpc/src/eth/api/call.rs#L68-L74

@mattsse As a result of these discussions I've just removed the extra From implementation, leading the user having to specify EvmOverrides::state(...). Let me know if this is ok to you

@mattsse mattsse merged commit 6cb3713 into alloy-rs:main Jun 16, 2024
22 checks passed
ben186 pushed a commit to ben186/alloy that referenced this pull request Jul 27, 2024
* feat: integrate EvmOverrides to rpc types

* fix clippy

* remove From impl
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