Skip to content

Comments

Refactor: Split transaction pre verification to separate function#573

Merged
rakita merged 4 commits intobluealloy:mainfrom
thedevbirb:refactor_split_tx_preverification
Aug 25, 2023
Merged

Refactor: Split transaction pre verification to separate function#573
rakita merged 4 commits intobluealloy:mainfrom
thedevbirb:refactor_split_tx_preverification

Conversation

@thedevbirb
Copy link
Contributor

Hi! I tried to give a shot to #432 in this PR. I hope to have understood and addressed the problem indicated by the issue.

@thedevbirb thedevbirb force-pushed the refactor_split_tx_preverification branch from f283376 to 2d68733 Compare August 22, 2023 08:03
Copy link
Member

@rakita rakita left a comment

Choose a reason for hiding this comment

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

Left comments.

And I apologise for a long wait I wanted to think about some additional things to make this more flexible but it missed me, we can push this over the line.

} else {
evm.transact_commit()
evm.preverify_transaction()
.and_then(|_| evm.transact_commit())
Copy link
Member

Choose a reason for hiding this comment

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

I like this pattern

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! Now I moved it to the transact function which does preverify_transaction and then transact_preverified, according to the other comment you made

Ok(())
}

fn transact(&mut self) -> EVMResult<DB::Error> {
Copy link
Member

@rakita rakita Aug 22, 2023

Choose a reason for hiding this comment

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

It will be a footgun if we silently remove some checks.
We should probably add an additional function transact_preverified to make it explicit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right! Sorry for the dumb take. Now I added the transact_preverified function in the Transact trait

@thedevbirb thedevbirb force-pushed the refactor_split_tx_preverification branch from 2d68733 to 9e807d0 Compare August 23, 2023 13:21
@thedevbirb
Copy link
Contributor Author

Left comments.

And I apologise for a long wait I wanted to think about some additional things to make this more flexible but it missed me, we can push this over the line.

Hi @rakita! I made some small changes according to the comments. Thanks for the feedback. I hope it is ok now.

fn transact(&mut self) -> EVMResult<DB::Error> {
self.env().validate_block_env::<GSPEC, DB::Error>()?;
self.env().validate_tx::<GSPEC>()?;
fn preverify_transaction(&mut self) -> Result<(), EVMError<DB::Error>> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Interesting - I wonder how much time we spend doing these checks, and whether we could potentially run all these checks in parallel at the beginning of each block in Reth?

I have seen similar separations to be valuable in the context of account abstraction where you'd want to verify e.g. all signatures in parallel (we do that alrd) and then execute.

Copy link
Member

@rakita rakita Aug 25, 2023

Choose a reason for hiding this comment

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

It is negligible, check these measurments #499 (comment)
It is 250ms for 100k blocks that took 56s (on sepolia). Although tx num varies it is under 0.5% of overall the time spent.

@rakita rakita merged commit b2d6f7a into bluealloy:main Aug 25, 2023
@thedevbirb thedevbirb deleted the refactor_split_tx_preverification branch September 6, 2023 08:59
mikelodder7 pushed a commit to LIT-Protocol/revm that referenced this pull request Sep 12, 2023
…uealloy#573)

* feat(transaction): preverify_transaction function in Transact trait

* chore(transaction): implemented tx preverification and removed checks from transaction functions

* chore: documentation

* feat(transaction): transact_preverified function in Transact trait; updated docs
Evalir pushed a commit to Evalir/revm that referenced this pull request Sep 14, 2023
…uealloy#573)

* feat(transaction): preverify_transaction function in Transact trait

* chore(transaction): implemented tx preverification and removed checks from transaction functions

* chore: documentation

* feat(transaction): transact_preverified function in Transact trait; updated docs
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