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

fix(levm): fix interaction with cache and db #1531

Merged
merged 13 commits into from
Dec 21, 2024
Merged

Conversation

JereSalo
Copy link
Contributor

@JereSalo JereSalo commented Dec 18, 2024

Motivation

Description

TLDR: We don't want to interact directly with the db without consulting before with the cache. This won't fix nor break tests because in every EFTest we send the cache empty, but it is a necessary fix for executing multiple transactions within a block. As a side effect we have to move contract creation and insertion to cache to transact(), so that we can revert if address is already occupied.

Idea:

  • Move contract creation and insertion to cache to transact(), not to new().
    • This is because we really want to check if the contract already exists both in the cache and in the db, and if when you want to create it you see that it already exists in one of those 2 there you revert. Currently we only check it in the db but the tests work because they test only one transaction each, so the cache always starts empty.
  • The idea is to stop using db.get_account_info() in the VM::new(), we want to query the cache first and then the DB. For this we have the get_account() method in VM, but in VM::new() it doesn't work because there is no vm created yet. The idea is to grab that behavior and take it to a get_account(address, mut cache, db) function that has the same behavior as now. The VM get_account method can be a handrail to call this, which does get_account(address, self.cache, self.db).

Additional Changes:

  • Remove unnecessary stuff in VM::new()
  • Remove receiver account every time a transaction reverts, independently of it's type.

Closes #issue_number

@JereSalo JereSalo added the levm Lambda EVM implementation label Dec 18, 2024
@JereSalo JereSalo self-assigned this Dec 18, 2024
@JereSalo JereSalo marked this pull request as ready for review December 20, 2024 12:43
@JereSalo JereSalo requested a review from a team as a code owner December 20, 2024 12:43
Copy link
Contributor

@lima-limon-inc lima-limon-inc left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@damiramirez damiramirez left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@maximopalopoli maximopalopoli left a comment

Choose a reason for hiding this comment

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

LGTM

account
}
}
get_account(&mut self.cache, &self.db, address)
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we could have a different name for the two functions, since having the same one could lead to confusion.

Copy link
Contributor Author

@JereSalo JereSalo Dec 20, 2024

Choose a reason for hiding this comment

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

hmm maybe, the arguments are different though. They have the same name because they do the same thing but the VM one is like a wrapper. A better name doesn't come to my mind, what do you suggest?

Copy link
Contributor

Choose a reason for hiding this comment

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

It's true that there isn't a good name for both, maybe it could be get_account_cache_or_db, but it says more about implementation than anything else. Actual version looks good to me in that sense 👍

@ilitteri ilitteri added this pull request to the merge queue Dec 21, 2024
Merged via the queue into main with commit 53c0829 Dec 21, 2024
4 checks passed
@ilitteri ilitteri deleted the levm/fixes_cache_db branch December 21, 2024 01:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
levm Lambda EVM implementation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants