Skip to content

Commit

Permalink
Merge pull request #68 from weaveVM/reth-toml-prune-config
Browse files Browse the repository at this point in the history
feat: Enable building prune nodes from CLI
  • Loading branch information
andreespirela authored Sep 24, 2024
2 parents 66c6754 + 62cd570 commit ada4e2e
Show file tree
Hide file tree
Showing 9 changed files with 142 additions and 33 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
*

# include source files
!/conf
!/bin
!/crates
!/testing
Expand Down
59 changes: 54 additions & 5 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -604,3 +604,5 @@ exex-wvm-da = { git = "https://github.com/weaveVM/exex-templates?a", branch = "m
tikv-jemalloc-ctl = "0.6"
tikv-jemallocator = "0.6"
tracy-client = "0.17.3"

parse_duration = "2.1.1"
46 changes: 23 additions & 23 deletions crates/ethereum/evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,29 +51,6 @@ impl EthEvmConfig {
}

impl ConfigureEvmEnv for EthEvmConfig {
fn fill_cfg_env(
&self,
cfg_env: &mut CfgEnvWithHandlerCfg,
header: &Header,
total_difficulty: U256,
) {
let spec_id = config::revm_spec(
self.chain_spec(),
&Head {
number: header.number,
timestamp: header.timestamp,
difficulty: header.difficulty,
total_difficulty,
hash: Default::default(),
},
);

cfg_env.chain_id = self.chain_spec.chain().id();
cfg_env.perf_analyse_created_bytecodes = AnalysisKind::Analyse;

cfg_env.handler_cfg.spec_id = spec_id;
}

fn fill_tx_env(&self, tx_env: &mut TxEnv, transaction: &TransactionSigned, sender: Address) {
transaction.fill_tx_env(tx_env, sender);
}
Expand Down Expand Up @@ -118,6 +95,29 @@ impl ConfigureEvmEnv for EthEvmConfig {
// disable the base fee check for this call by setting the base fee to zero
env.block.basefee = U256::ZERO;
}

fn fill_cfg_env(
&self,
cfg_env: &mut CfgEnvWithHandlerCfg,
header: &Header,
total_difficulty: U256,
) {
let spec_id = config::revm_spec(
self.chain_spec(),
&Head {
number: header.number,
timestamp: header.timestamp,
difficulty: header.difficulty,
total_difficulty,
hash: Default::default(),
},
);

cfg_env.chain_id = self.chain_spec.chain().id();
cfg_env.perf_analyse_created_bytecodes = AnalysisKind::Analyse;

cfg_env.handler_cfg.spec_id = spec_id;
}
}

impl ConfigureEvm for EthEvmConfig {
Expand Down
7 changes: 6 additions & 1 deletion crates/node/builder/src/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ pub struct NodeBuilder<DB> {
/// All settings for how the node should be configured.
config: NodeConfig,
/// The configured database for the node.
database: DB,
pub database: DB,
}

impl NodeBuilder<()> {
Expand Down Expand Up @@ -272,6 +272,11 @@ where
self.builder.config()
}

/// Returns a reference to the node builder's config.
pub const fn db(&self) -> &DB {
&self.builder.database
}

/// Configures the types of the node.
pub fn with_types<T>(self) -> WithLaunchContext<NodeBuilderWithTypes<RethFullAdapter<DB, T>>>
where
Expand Down
2 changes: 1 addition & 1 deletion crates/primitives-traits/src/constants/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub const EPOCH_SLOTS: u64 = 32;

/// The duration of a slot in seconds.
///
/// This is the time period of 12 seconds in which a randomly chosen validator has time to propose a
/// This is the time period of 1 seconds in which a randomly chosen validator has time to propose a
/// block.
pub const SLOT_DURATION: Duration = Duration::from_secs(1); // Wevm #356: 1s per block

Expand Down
2 changes: 2 additions & 0 deletions wvm-apps/wvm-exexed/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ types = { path = "crates/types" }
rbrotli = { path = "crates/brotli" }
borsh.workspace = true

parse_duration.workspace = true

[dev-dependencies]
reth-exex-test-utils.workspace = true
reth-testing-utils.workspace = true
Expand Down
3 changes: 2 additions & 1 deletion wvm-apps/wvm-exexed/crates/reth-exexed/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ arweave-upload = { path = "../arweave-upload" }
precompiles = { path = "../precompiles" }
rbrotli = { path = "../brotli" }
tokio.workspace = true
exex-wvm-da.workspace = true
exex-wvm-da.workspace = true
parse_duration.workspace = true
53 changes: 51 additions & 2 deletions wvm-apps/wvm-exexed/crates/reth-exexed/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ use repository::state_repository;
use reth::{api::FullNodeComponents, builder::Node};
use reth_exex::{ExExContext, ExExEvent, ExExNotification};
use std::env;

use std::ops::Mul;
use std::sync::Arc;
use crate::{network_tag::get_network_tag, util::check_block_existence};
use arweave_upload::{ArweaveRequest, UploaderProvider};
use exex_wvm_da::{DefaultWvmDataSettler, WvmDataSettler};
Expand All @@ -24,6 +25,9 @@ use reth_node_ethereum::{
};
use reth_tracing::tracing::info;
use serde_json::to_string;
use reth::args::PruningArgs;
use reth::builder::NodeBuilder;
use reth_primitives::constants::SLOT_DURATION;
use types::types::ExecutionTipState;
use wevm_borsh::block::BorshSealedBlockWithSenders;

Expand Down Expand Up @@ -96,7 +100,21 @@ async fn exex_etl_processor<Node: FullNodeComponents>(
/// Main loop of the exexed WVM node
fn main() -> eyre::Result<()> {
reth::cli::Cli::parse_args().run(|builder, _| async move {
let mut handle = builder
// Original config
let mut config = builder.config().clone();
let pruning_args = config.pruning.clone();
let prune_node = std::env::var("WVM_PRUNE");

if let Ok(prune_conf) = prune_node {
config = config.with_pruning(PruningArgs {
block_interval: parse_prune_config(prune_conf.as_str()),
..pruning_args
});
}

let mut handle = NodeBuilder::new(config)
.with_database(builder.db().clone())
.with_launch_context(builder.task_executor().clone())
.with_types::<EthereumNode>()
.with_components(EthereumNode::components().executor(WvmEthExecutorBuilder::default()))
.with_add_ons::<EthereumAddOns>();
Expand Down Expand Up @@ -140,3 +158,34 @@ fn main() -> eyre::Result<()> {
handle.wait_for_node_exit().await
})
}

fn parse_prune_config(prune_conf: &str) -> u64 {
let mut d = "";
if prune_conf == "true" {
d = "30d"
} else {
d = prune_conf;
}

let duration = parse_duration::parse(d).unwrap();
let secs = duration.as_secs();
SLOT_DURATION.as_secs() * secs
}

#[cfg(test)]
mod tests {
use crate::parse_prune_config;

#[test]
pub fn check_prune_config() {
let true_prune = parse_prune_config("true");
assert_eq!(true_prune, 2_592_000);

let thirty_days_prune = parse_prune_config("30d");
assert_eq!(thirty_days_prune, 2_592_000);

let thirty_days_prune = parse_prune_config("15d");
assert_eq!(thirty_days_prune, 1296000);
}

}

0 comments on commit ada4e2e

Please sign in to comment.