Skip to content

Commit

Permalink
integrated rWASM virtual machine
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitry123 committed Oct 10, 2023
1 parent 394a3a9 commit ee56fe7
Show file tree
Hide file tree
Showing 30 changed files with 1,589 additions and 20 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ crates/stages/testdata

# Prometheus data dir
data/
datadir/

# Proptest data
proptest-regressions/
Expand Down
110 changes: 110 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ members = [
"crates/rpc/rpc-engine-api",
"crates/rpc/rpc-types",
"crates/rpc/rpc-testing-util",
"crates/rwasm",
"crates/rwasm/rwasm-primitives",
"crates/stages",
"crates/storage/codecs",
"crates/storage/db",
Expand Down Expand Up @@ -101,6 +103,10 @@ reth-rpc-types-compat = { path = "./crates/rpc/rpc-types-compat" }
revm = { git = "https://github.com/bluealloy/revm" }
revm-primitives = { git = "https://github.com/bluealloy/revm" }

# rwasm
fluentbase-rwasm = { git = "https://github.com/fluentlabs-xyz/fluentbase", branch = "devel" }
fluentbase-runtime = { git = "https://github.com/fluentlabs-xyz/fluentbase", branch = "devel" }

## eth
ethers-core = { version = "2.0", default-features = false }
ethers-providers = { version = "2.0", default-features = false }
Expand Down
9 changes: 6 additions & 3 deletions bin/reth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ reth-primitives = { workspace = true, features = ["arbitrary"] }
reth-db = { path = "../../crates/storage/db", features = ["mdbx", "test-utils"] }
# TODO: Temporary use of the test-utils feature
reth-provider = { workspace = true, features = ["test-utils"] }
reth-revm = { path = "../../crates/revm" }
reth-revm-inspectors = { path = "../../crates/revm/revm-inspectors" }
reth-revm = { path = "../../crates/revm", optional = true }
reth-revm-inspectors = { path = "../../crates/revm/revm-inspectors", optional = true }
reth-rwasm = { path = "../../crates/rwasm", optional = true }
reth-stages = { path = "../../crates/stages" }
reth-interfaces = { workspace = true, features = ["test-utils", "clap"] }
reth-transaction-pool.workspace = true
Expand Down Expand Up @@ -107,14 +108,16 @@ jemallocator = { version = "0.5.0", optional = true }
jemalloc-ctl = { version = "0.5.0", optional = true }

[features]
default = ["jemalloc"]
default = ["jemalloc", "rwasm"]
jemalloc = ["dep:jemallocator", "dep:jemalloc-ctl"]
jemalloc-prof = ["jemalloc", "jemallocator?/profiling"]
min-error-logs = ["tracing/release_max_level_error"]
min-warn-logs = ["tracing/release_max_level_warn"]
min-info-logs = ["tracing/release_max_level_info"]
min-debug-logs = ["tracing/release_max_level_debug"]
min-trace-logs = ["tracing/release_max_level_trace"]
rwasm = ["dep:reth-rwasm"]
revm = ["dep:reth-revm", "dep:reth-revm-inspectors"]

[build-dependencies]
vergen = { version = "8.0.0", features = ["build", "cargo", "git", "gitcl"] }
7 changes: 6 additions & 1 deletion bin/reth/src/args/utils.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
//! Clap parser utilities
use reth_primitives::{
fs, AllGenesisFormats, BlockHashOrNumber, ChainSpec, DEV, GOERLI, HOLESKY, MAINNET, SEPOLIA,
fs, AllGenesisFormats, BlockHashOrNumber, ChainSpec, DEV, GOERLI, HOLESKY, MAINNET, SEPOLIA, FLUENT_DEVNET,
};
#[cfg(feature = "revm")]
use reth_revm::primitives::B256 as H256;
#[cfg(feature = "rwasm")]
use reth_rwasm::primitives::B256 as H256;
use std::{
net::{IpAddr, Ipv4Addr, SocketAddr, ToSocketAddrs},
path::PathBuf,
Expand All @@ -27,6 +30,7 @@ pub fn chain_spec_value_parser(s: &str) -> eyre::Result<Arc<ChainSpec>, eyre::Er
"sepolia" => SEPOLIA.clone(),
"holesky" => HOLESKY.clone(),
"dev" => DEV.clone(),
"fluent-devnet" => FLUENT_DEVNET.clone(),
_ => {
let raw = fs::read_to_string(PathBuf::from(shellexpand::full(s)?.into_owned()))?;
serde_json::from_str(&raw)?
Expand All @@ -43,6 +47,7 @@ pub fn genesis_value_parser(s: &str) -> eyre::Result<Arc<ChainSpec>, eyre::Error
"sepolia" => SEPOLIA.clone(),
"holesky" => HOLESKY.clone(),
"dev" => DEV.clone(),
"fluent-devnet" => FLUENT_DEVNET.clone(),
_ => {
let raw = fs::read_to_string(PathBuf::from(shellexpand::full(s)?.into_owned()))?;
let genesis: AllGenesisFormats = serde_json::from_str(&raw)?;
Expand Down
3 changes: 3 additions & 0 deletions bin/reth/src/chain/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,10 @@ impl ImportCommand {
.into_task();

let (tip_tx, tip_rx) = watch::channel(H256::zero());
#[cfg(feature = "revm")]
let factory = reth_revm::Factory::new(self.chain.clone());
#[cfg(feature = "rwasm")]
let factory = reth_rwasm::Factory::new(self.chain.clone());

let max_block = file_client.max_block().unwrap_or(0);
let mut pipeline = Pipeline::builder()
Expand Down
3 changes: 3 additions & 0 deletions bin/reth/src/cli/config.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
//! Config traits for various node components.
#[cfg(feature = "revm")]
use reth_revm::primitives::bytes::BytesMut;
#[cfg(feature = "rwasm")]
use reth_rwasm::primitives::bytes::BytesMut;
use reth_rlp::Encodable;
use reth_rpc::{eth::gas_oracle::GasPriceOracleConfig, JwtError, JwtSecret};
use reth_rpc_builder::{
Expand Down
3 changes: 3 additions & 0 deletions bin/reth/src/debug_cmd/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,10 @@ impl Command {
let stage_conf = &config.stages;

let (tip_tx, tip_rx) = watch::channel(H256::zero());
#[cfg(feature = "revm")]
let factory = reth_revm::Factory::new(self.chain.clone());
#[cfg(feature = "rwasm")]
let factory = reth_rwasm::Factory::new(self.chain.clone());

let header_mode = HeaderSyncMode::Tip(tip_rx);
let pipeline = Pipeline::builder()
Expand Down
3 changes: 3 additions & 0 deletions bin/reth/src/debug_cmd/in_memory_merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,10 @@ impl Command {
)
.await?;

#[cfg(feature = "revm")]
let executor_factory = reth_revm::Factory::new(self.chain.clone());
#[cfg(feature = "rwasm")]
let executor_factory = reth_rwasm::Factory::new(self.chain.clone());
let mut executor =
executor_factory.with_state(LatestStateProviderRef::new(provider.tx_ref()));

Expand Down
4 changes: 3 additions & 1 deletion bin/reth/src/debug_cmd/merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,10 @@ impl Command {
checkpoint.block_number != execution_checkpoint_block ||
checkpoint.stage_checkpoint.is_some()
});

#[cfg(feature = "revm")]
let factory = reth_revm::Factory::new(self.chain.clone());
#[cfg(feature = "rwasm")]
let factory = reth_rwasm::Factory::new(self.chain.clone());
let mut execution_stage = ExecutionStage::new(
factory,
ExecutionStageThresholds {
Expand Down
3 changes: 3 additions & 0 deletions bin/reth/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ pub mod blockchain_tree {

/// Re-exported from `reth_revm`.
pub mod revm {
#[cfg(feature = "revm")]
pub use reth_revm::*;
#[cfg(feature = "rwasm")]
pub use reth_rwasm::*;
}

/// Re-exported from `reth_tasks`.
Expand Down
10 changes: 10 additions & 0 deletions bin/reth/src/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ use reth_provider::{
providers::BlockchainProvider, BlockHashReader, BlockReader, CanonStateSubscriptions,
HeaderProvider, ProviderFactory, StageCheckpointReader,
};
#[cfg(feature = "revm")]
use reth_revm::Factory;
#[cfg(feature = "rwasm")]
use reth_rwasm::Factory;
#[cfg(feature = "revm")]
use reth_revm_inspectors::stack::Hook;
use reth_rpc_engine_api::EngineApi;
use reth_stages::{
Expand Down Expand Up @@ -806,9 +810,14 @@ impl<Ext: RethCliExt> NodeCommand<Ext> {
}

let (tip_tx, tip_rx) = watch::channel(H256::zero());
#[cfg(feature = "revm")]
use reth_revm_inspectors::stack::InspectorStackConfig;
#[cfg(feature = "revm")]
let factory = reth_revm::Factory::new(self.chain.clone());
#[cfg(feature = "rwasm")]
let factory = reth_rwasm::Factory::new(self.chain.clone());

#[cfg(feature = "revm")]
let stack_config = InspectorStackConfig {
use_printer_tracer: self.debug.print_inspector,
hook: if let Some(hook_block) = self.debug.hook_block {
Expand All @@ -822,6 +831,7 @@ impl<Ext: RethCliExt> NodeCommand<Ext> {
},
};

#[cfg(feature = "revm")]
let factory = factory.with_stack_config(stack_config);

let prune_modes = prune_config.map(|prune| prune.parts).unwrap_or_default();
Expand Down
3 changes: 3 additions & 0 deletions bin/reth/src/stage/dump/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ use reth_db::{
};
use reth_primitives::{stage::StageCheckpoint, ChainSpec};
use reth_provider::ProviderFactory;
#[cfg(feature = "revm")]
use reth_revm::Factory;
#[cfg(feature = "rwasm")]
use reth_rwasm::Factory;
use reth_stages::{stages::ExecutionStage, Stage, UnwindInput};
use std::{path::PathBuf, sync::Arc};
use tracing::info;
Expand Down
7 changes: 6 additions & 1 deletion bin/reth/src/stage/dump/merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,14 @@ async fn unwind_and_copy<DB: Database>(

MerkleStage::default_unwind().unwind(&provider, unwind).await?;

#[cfg(feature = "revm")]
let execution_factory = reth_revm::Factory::new(db_tool.chain.clone());
#[cfg(feature = "rwasm")]
let execution_factory = reth_rwasm::Factory::new(db_tool.chain.clone());

// Bring Plainstate to TO (hashing stage execution requires it)
let mut exec_stage = ExecutionStage::new(
reth_revm::Factory::new(db_tool.chain.clone()),
execution_factory,
ExecutionStageThresholds {
max_blocks: Some(u64::MAX),
max_changes: None,
Expand Down
3 changes: 3 additions & 0 deletions bin/reth/src/stage/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,10 @@ impl Command {
}
StageEnum::Senders => (Box::new(SenderRecoveryStage::new(batch_size)), None),
StageEnum::Execution => {
#[cfg(feature = "revm")]
let factory = reth_revm::Factory::new(self.chain.clone());
#[cfg(feature = "rwasm")]
let factory = reth_rwasm::Factory::new(self.chain.clone());
(
Box::new(ExecutionStage::new(
factory,
Expand Down
Loading

0 comments on commit ee56fe7

Please sign in to comment.