-
Notifications
You must be signed in to change notification settings - Fork 3
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: reth-scroll crates #33
base: scroll
Are you sure you want to change the base?
Conversation
Signed-off-by: Gregory Edison <gregory.edison1993@gmail.com>
Signed-off-by: Gregory Edison <gregory.edison1993@gmail.com>
Signed-off-by: Gregory Edison <gregory.edison1993@gmail.com>
Signed-off-by: Gregory Edison <gregory.edison1993@gmail.com>
cdd8185
to
6c120a1
Compare
Signed-off-by: Gregory Edison <gregory.edison1993@gmail.com>
6c120a1
to
a667eae
Compare
Signed-off-by: Gregory Edison <gregory.edison1993@gmail.com>
Signed-off-by: Gregory Edison <gregory.edison1993@gmail.com>
@@ -152,7 +152,7 @@ jobs: | |||
with: | |||
cache-on-failure: true | |||
- uses: taiki-e/install-action@cargo-udeps | |||
- run: cargo udeps --workspace --lib --examples --tests --benches --all-features --locked | |||
- run: cargo udeps --workspace --lib --examples --tests --benches --all-features --locked --exclude "reth-optimism-*" --exclude op-reth |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because of the #![cfg(not(feature = "scroll"))]
conditional compilation in the optimism
crates, we exclude the udeps
check on the optimism crates.
#[cfg(not(feature = "scroll"))] | ||
type ExecutionContext = (); | ||
#[cfg(feature = "scroll")] | ||
type ExecutionContext = reth_scroll_primitives::ScrollPostExecutionContext; | ||
static DEFAULT_CONTEXT: LazyLock<ExecutionContext> = LazyLock::new(Default::default); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this allows CacheDB<DB>
and StateProviderDatabase<DB>
to always implement ContextFul
, whatever the feature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, thanks! Left some minor comments inline. Once comments are answered / addressed we can merge.
crates/optimism/payload/Cargo.toml
Outdated
] | ||
scroll = [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: new line at eof
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you prefer to remove new lines at eof in manifests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm indifferent but it seems to be the convention in reth from what I can tell so I think we should remain consistent.
@@ -20,7 +20,9 @@ alloy-genesis.workspace = true | |||
alloy-primitives.workspace = true | |||
alloy-rlp.workspace = true | |||
|
|||
revm-primitives = { workspace = true, features = ["serde"] } | |||
# revm-primitives scroll re-export | |||
revm-primitives = { package = "reth-scroll-revm", path = "../scroll/revm", features = ["serde"] } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: should we define this dependency at the workspace level?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you mean update revm-primitives
to point to reth-scroll-revm
from the workspace mainfest?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm mean when we define revm-primitives
in the workspace Cargo.toml
we redefine it such that it points to reth-scroll-revm
. Currently in workspace Cargo.toml
we have:
revm-primitives = { version = "14.0.0", features = [
"std",
], default-features = false }
We can change it to:
revm-primitives = { package = "reth-scroll-revm", path = "../scroll/revm", features = ["std"], default-features = false }
Then in this crate we shouldn't have to change the dependency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@frisitano I think this would work better in the follow up PR #39. The goal of the current PR was to introduce the Scroll crates with minimal propagation to the rest of the repo. Moving the dependency to workspace level would fit more 39's goal and limit the changes in this PR (which are done in 39 anyway).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep sounds good.
@@ -29,6 +28,9 @@ alloy-serde = { workspace = true, optional = true } | |||
alloy-eips = { workspace = true, features = ["serde"] } | |||
alloy-trie = { workspace = true, features = ["serde"] } | |||
|
|||
# scroll | |||
revm-primitives = { package = "reth-scroll-revm", path = "../scroll/revm", features = ["serde"] } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we define this in the workspace?
@@ -67,7 +69,7 @@ reth-codecs = { workspace = true, features = ["test-utils"] } | |||
reth-primitives-traits = { workspace = true, features = ["arbitrary"] } | |||
reth-testing-utils.workspace = true | |||
reth-trie-common.workspace = true | |||
revm-primitives = { workspace = true, features = ["arbitrary"] } | |||
revm-primitives = { package = "reth-scroll-revm", path = "../scroll/revm", features = ["arbitrary"] } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we define this in the workspace?
impl<DB> WithContext for CacheDB<DB> { | ||
type Context = ExecutionContext; | ||
|
||
fn context(&self) -> &Self::Context { | ||
&DEFAULT_CONTEXT | ||
} | ||
} | ||
|
||
impl<DB> WithContext for StateProviderDatabase<DB> { | ||
type Context = ExecutionContext; | ||
|
||
fn context(&self) -> &Self::Context { | ||
&DEFAULT_CONTEXT | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are the implications of returning a DEFAULT_CONTEXT
here. Is CacheDB
ever used for building blocks and generating the state root?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This default implementation is only used in tests. To be sure this is never used in production code I could move it behind a test-utils feature, what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I think putting it behind test-utils
feature makes sense.
/// Finalize the execution of the type and return the output | ||
pub trait FinalizeExecution<Output> { | ||
/// Finalize the state and return the output. | ||
fn finalize(&mut self) -> Output; | ||
} | ||
|
||
impl<DB: Database + ContextFul> FinalizeExecution<reth_scroll_revm::states::ScrollBundleState> | ||
for State<DB> | ||
{ | ||
fn finalize(&mut self) -> reth_scroll_revm::states::ScrollBundleState { | ||
let bundle = self.take_bundle(); | ||
(bundle, self.database.context()).into() | ||
} | ||
} | ||
|
||
/// A type that returns additional execution context. | ||
pub trait ContextFul: WithContext<Context = ExecutionContext> {} | ||
impl<T> ContextFul for T where T: WithContext<Context = ExecutionContext> {} | ||
|
||
/// Types that can provide a context. | ||
#[auto_impl::auto_impl(&, &mut)] | ||
pub trait WithContext { | ||
/// The context returned. | ||
type Context; | ||
|
||
/// Returns the context from the type. | ||
fn context(&self) -> &Self::Context; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets keep this as is for now but I'd like to see how this integrates with the BlockExecutor
in the follow up PR. I wonder if we can simplify it a bit.
b256!("2098f5fb9e239eab3ceac3f27b81e481dc3124d55ffed523a839ee8446b64864"); | ||
|
||
/// Poseidon code hash | ||
pub fn poseidon(code: &[u8]) -> B256 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we rename this to hash_code
? I think poseidon
is a bit ambiguous and doesn't represent that it's associated with hashing code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that's fair, maybe poseidon_hash_code
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That works but I would still prefer hash_code
, the reason being that we already have Poseidon in the import scope use scroll_primitives::poseidon::hash_code
however I'm not strongly opinionated.
crates/scroll/primitives/Cargo.toml
Outdated
reth-codecs.workspace = true | ||
|
||
# scroll | ||
poseidon-bn254 = { git = "https://github.com/scroll-tech/poseidon-bn254", branch = "master", features = ["bn254"] } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should create a tag or publish this to crates.io instead of using a master branch dependency. I think we should move the dependency to workspace Cargo.toml
and add a TODO which states that we should change this dep to point to the tag / crate onceds it's published. ref: scroll-tech/poseidon-bn254#6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agreed, I left a comment regarding this in the deny.toml
. Will move to the workspace
Signed-off-by: Gregory Edison <gregory.edison1993@gmail.com>
Signed-off-by: Gregory Edison <gregory.edison1993@gmail.com>
Cargo.toml
Outdated
@@ -470,6 +478,10 @@ alloy-transport-http = { version = "0.6.4", features = [ | |||
alloy-transport-ipc = { version = "0.6.4", default-features = false } | |||
alloy-transport-ws = { version = "0.6.4", default-features = false } | |||
|
|||
# scroll | |||
# TODO (scroll): point to crates.io/tag once the crate is published/ a tag is created. | |||
poseidon-bn254 = { git = "https://github.com/scroll-tech/poseidon-bn254", branch = "master", features = ["bn254"] } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we use a commit for now (instead of a branch)? So that things don't break unexpectedly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's fine with me, I was pointing it to master
because this is what is currently done on scroll-tech/revm
. I can check what commit is used in scroll-tech/revm
in the lock file and use that one for now.
pub mod states; | ||
|
||
#[cfg(feature = "optimism")] | ||
pub use revm::primitives::OptimismFields; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this left here intentionally?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, unfortunately because the reth-scroll-revm
crate is used as a re-export for revm
and revm-primitives
, which allows us to shadow specific types (BundleState
, BundleAccount
,...) with the Scroll types when the scroll
feature is active. This means we also need to re-export some of the Optimism types.
If you prefer I can modify the imports in the rest of the codebase (from revm_primitives:: OptimismFields
to revm::primitives::OptimismFields
) but I think just having this line is easier whenever we need to merge upstream.
Signed-off-by: Gregory Edison <gregory.edison1993@gmail.com>
Overview
Introduces the
scroll
feature flag and ScrollAccount
changes. The following changes are implemented:reth-scroll-*
crates: introduces 4 Scroll related crates, which will accumulate as much changes as possible, in order to limit diff with upstream.Account
extending fields:code_size
andposeidon_code_hash
are added on the Ethereum account. These fields are needed for the computation of the state root.ScrollStateProviderDatabase
: a storage provider that implements therevm::Database
trait and will thus be used during execution when thescroll
feature flag is used. It caches all Scroll added fields for touched accounts during execution and can be used to build theScrollBundleState
from arevm::BundleState
.Notes
// TODO (scroll): ...
. These were added in order to make the current changes satisfy allclippy
checks and will be updated in subsequent PR's related to theAccount
changes.Cargo.lock
file.Builds towards #7