Skip to content

Commit

Permalink
first bin for Keth
Browse files Browse the repository at this point in the history
  • Loading branch information
greged93 committed Jul 22, 2024
1 parent 11dc7fd commit 38e31a4
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ target/
# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb

.idea/

# Added by cargo

Expand Down
29 changes: 28 additions & 1 deletion Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ exclude = [".github/"]

[workspace]
members = [
"bin/keth",
"crates/node",
"crates/pool",
]
Expand Down
36 changes: 36 additions & 0 deletions bin/keth/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
[package]
name = "keth"
version.workspace = true
edition.workspace = true
description.workspace = true
homepage.workspace = true
repository.workspace = true
readme.workspace = true
license.workspace = true
rust-version.workspace = true
exclude.workspace = true

[dependencies]
#Alloy
alloy-genesis = { version = "0.1.2", default-features = false }

# Kakarot
kakarot-node.workspace = true

# Reth
reth-db = { git = "https://github.com/paradigmxyz/reth.git", tag = "v1.0.0", default-features = false }
reth-chainspec = { git = "https://github.com/paradigmxyz/reth.git", tag = "v1.0.0", default-features = false }
reth-cli-runner = { git = "https://github.com/paradigmxyz/reth.git", tag = "v1.0.0", default-features = false }
reth-node-builder.workspace = true
reth-node-core = { git = "https://github.com/paradigmxyz/reth.git", tag = "v1.0.0", default-features = false }
reth-primitives.workspace = true

# Tracing
tracing = { version = "0.1.40", default-features = false }
tracing-subscriber = { version = "0.3.18", default-features = false }

# Other
clap = { version = "4.5.9", features = ["derive"] }

[lints]
workspace = true
18 changes: 17 additions & 1 deletion bin/keth/src/cli/mod.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,29 @@
use clap::Parser;
use tracing_subscriber::EnvFilter;

#[derive(Debug, Parser)]
pub struct Cli {
#[command(flatten)]
log: LogArgs,
pub chain: ChainArgs,
#[command(flatten)]
pub log: LogArgs,
}

#[derive(Debug, Parser)]
pub struct LogArgs {
#[clap(short, long, default_value = "info")]
pub filter: String,
}

impl LogArgs {
pub fn init_tracing(&self) {
let filter = EnvFilter::builder().parse(&self.filter).expect("failed to parse filter");
tracing_subscriber::fmt().with_env_filter(filter).init();
}
}

#[derive(Debug, Parser)]
pub struct ChainArgs {
#[clap(short, long, default_value = "1")]
pub id: u64,
}
48 changes: 48 additions & 0 deletions bin/keth/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
use alloy_genesis::Genesis;
use clap::Parser;
use kakarot_node::node::KakarotNode;
use keth::cli::Cli;
use reth_chainspec::{Chain, ChainSpec};
use reth_cli_runner::CliRunner;
use reth_db::init_db;
use reth_node_builder::{NodeBuilder, NodeConfig};
use reth_node_core::args::RpcServerArgs;
use reth_primitives::Address;
use std::str::FromStr;
use std::sync::Arc;

fn main() {
let args = Cli::parse();
args.log.init_tracing();

let chain_id = args.chain.id;
let chain = ChainSpec::builder()
.cancun_activated()
.chain(Chain::from_id(chain_id))
.genesis(Genesis::clique_genesis(
chain_id,
Address::from_str("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266").unwrap(),
))
.build();

let config =
NodeConfig::default().with_chain(chain).with_rpc(RpcServerArgs::default().with_http());

let data_dir = config.datadir();
let db_path = data_dir.db();

tracing::info!(target: "kkrt::cli", ?db_path, "Starting DB");
let database =
Arc::new(init_db(db_path, config.db.database_args()).expect("failed to init db"));

let builder = NodeBuilder::new(config).with_database(database);

let runner = CliRunner::default();
runner
.run_command_until_exit(|ctx| async {
let builder = builder.with_launch_context(ctx.task_executor);
let handle = builder.launch_node(KakarotNode::default()).await?;
handle.node_exit_future.await
})
.expect("failed to run command until exit")
}
2 changes: 2 additions & 0 deletions crates/node/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ use reth_node_ethereum::{
pub type KakarotPayloadBuilder = EthereumPayloadBuilder;

/// Type alias for the Kakarot network builder.
/// TODO: we don't need a network for now, so just implement a type that does nothing.
pub type KakarotNetworkBuilder = EthereumNetworkBuilder;

/// Type alias for the Kakarot consensus builder.
/// TODO: we don't need a consensus for now, so just implement a type that does nothing.
pub type KakarotConsensusBuilder = EthereumConsensusBuilder;

/// Type configuration for a regular Kakarot node.
Expand Down
1 change: 1 addition & 0 deletions crates/pool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ pub type KakarotPool<Client, S> = Pool<Validator<Client>, TransactionOrdering, S
/// implementation, utilizing components from the Ethereum node framework provided by Reth.
///
/// It configures the transaction pool specific to Kakarot's requirements.
/// TODO: incorrect, this needs to use the custom Validator<Client>.
pub type KakarotPoolBuilder = EthereumPoolBuilder;

0 comments on commit 38e31a4

Please sign in to comment.