refactor: introduce MegaDatabase trait to ensure DB and SaltEnv consistency#176
Draft
WonderLawrence wants to merge 2 commits intomainfrom
Draft
refactor: introduce MegaDatabase trait to ensure DB and SaltEnv consistency#176WonderLawrence wants to merge 2 commits intomainfrom
WonderLawrence wants to merge 2 commits intomainfrom
Conversation
Collaborator
|
是个不错的思路,不过我不确定在下游组件中好不好改。这个新的trait在mega-reth的哪个分支用上了吗?我想看看mega-reth那边是怎么用的。 |
35b344d to
fe48ae2
Compare
fe48ae2 to
f69f08a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR addresses a correctness issue where
ExternalEnvs::salt_envcould not guarantee it accessed the same database snapshot as the EVM'sDatabase. The solution introduces aMegaDatabasetrait that combinesDatabase + SaltEnvwith matching error types, ensuring type-level consistency.Problem
Previously,
SaltEnvwas a separate field inExternalEnvs, which could not guarantee that it accessed the same database snapshot as the EVM'sDatabase. This could lead to correctness issues where SALT bucket capacity queries and database operations might read from different state snapshots.Solution
Introduce a
MegaDatabasetrait that requires any database implementation to also implementSaltEnvwith matching error types. This ensures at compile time that the database and SALT environment operate on the same underlying data source.Key Changes
Core Trait Definition
MegaDatabasetrait inexternal/salt.rswith blanket implementationDatabaseandSaltEnvwith matching error types automatically implementsMegaDatabaseRefactoring
salt_envfield fromDynamicGasCost, passdbparameter to methods insteadsalt_envfromExternalEnvs(now only containsoracle_env)DB: Databaseconstraints toDB: MegaDatabasethroughout the codebaseBlockNumberparameter fromExternalEnvFactory::external_envs()Supporting Changes
EmptyMegaDBwrapper implementing bothDatabaseandSaltEnvfor testingSaltEnvfor test databases (MemoryDatabase,ErrorInjectingDatabase)Benefits
DatabaseandSaltEnvare the same instanceBlockNumberparameterExternalEnvsnow only handles Oracle environment, SALT is provided by the databaseTesting
MemoryDatabase,ErrorInjectingDatabase) properly implementSaltEnvEmptyMegaDBprovides a working default implementation