Skip to content

feat(driver): BundleDriver for driving bundles to completion #34

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

Merged
merged 32 commits into from
Aug 12, 2024

Conversation

Evalir
Copy link
Member

@Evalir Evalir commented Aug 5, 2024

Adds a simple BundleDriver trait, which can drive bundles to completion.

Conceptually, it starts from an EvmNeedsTx state, and ends there. This means that this driver simply allows to run a group of transactions, while applying post-multi-tx logic after. It does not open or close blocks. This also allows us to run several bundles, one after another.

This BundleDriver trait is then composed with a BlockProcessor struct, which then takes charge of implementing a BundleDriver for a combination of a bundle type, and a response type. This allows us, for example, to quickly grab bundles that conform to flashbots bundles, simulate them, and return a properly calculated & formatted response. Vanilla impls for EthCallBundle & EthSendBundle are also provided which do not accumulate results.

A few macros were also added, mirroring eyre macros:

  • unwrap_or_trevm_err!: Unwraps a Result, returning the value if successful, or returning an errored Trevm if not.
  • trevm_ensure!: Executes a condition, returning an errored Trevm if not successful.
  • trevm_bail!: Returns an errored Trevm with the provided error.

And lastly, try_with_* fns were added to have fallible with_* functions. The behavior of these was modified as well to use clone instead of mem::take to avoid having default values, which might be unexpected for the user.

  • Driver trait
  • sample alloy-rpc-types-mev implementation

fixes ENG-311

@Evalir Evalir requested a review from prestwich August 5, 2024 21:55
@Evalir Evalir changed the title feat(driver: BundleDriver for driving bundles to completion feat(driver): BundleDriver for driving bundles to completion Aug 5, 2024
@Evalir Evalir marked this pull request as draft August 5, 2024 23:14
@Evalir Evalir force-pushed the evalir/bundledriver branch from e9ea919 to 9ec0ac7 Compare August 6, 2024 14:24
@Evalir Evalir force-pushed the evalir/bundledriver branch from 027b68b to 1d1772e Compare August 6, 2024 15:13
@Evalir Evalir marked this pull request as ready for review August 6, 2024 16:45
@Evalir Evalir requested a review from prestwich August 6, 2024 16:48

let bundle_filler = BundleBlockFiller::from(self.clone());

let run_result = trevm.try_with_block(&bundle_filler, |trevm| {
Copy link
Member

Choose a reason for hiding this comment

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

the way this is implemented will cause anything not set by the filler to be default value. do we want that to be the case? or should we not use std::mem::take in with_block/try_with_block ?

Copy link
Member

Choose a reason for hiding this comment

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

I think we should remove the mem::takes and instead clone the env

@Evalir Evalir requested a review from prestwich August 12, 2024 10:52
@Evalir Evalir force-pushed the evalir/bundledriver branch from 37e53c6 to 02bbba0 Compare August 12, 2024 14:53
@Evalir Evalir requested a review from prestwich August 12, 2024 17:21
@Evalir Evalir marked this pull request as ready for review August 12, 2024 17:21
@Evalir Evalir force-pushed the evalir/bundledriver branch from cf0772f to 299fb4b Compare August 12, 2024 17:22
@Evalir Evalir force-pushed the evalir/bundledriver branch from 6b2dbd3 to 7d37311 Compare August 12, 2024 17:41
Copy link
Member

@prestwich prestwich left a comment

Choose a reason for hiding this comment

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

looking good. Almost done

also needs try_with_cfg and try_with_tx (unless I'm blind)

@Evalir Evalir requested a review from prestwich August 12, 2024 19:11
@Evalir Evalir merged commit fe82c5a into main Aug 12, 2024
4 checks passed
@Evalir Evalir deleted the evalir/bundledriver branch August 12, 2024 19:25
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.

2 participants