Skip to content

Commit

Permalink
Add EVM pallets, rpc, and precompiles
Browse files Browse the repository at this point in the history
  • Loading branch information
gztensor committed Aug 29, 2024
1 parent 3fedd89 commit 4886e96
Show file tree
Hide file tree
Showing 19 changed files with 2,882 additions and 244 deletions.
970 changes: 943 additions & 27 deletions Cargo.lock

Large diffs are not rendered by default.

32 changes: 32 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type_complexity = "allow"
unwrap-used = "deny"

[workspace.dependencies]
async-trait = "0.1"
cargo-husky = { version = "1", default-features = false }
clap = "4.5.4"
codec = { version = "3.2.2", default-features = false }
Expand Down Expand Up @@ -152,6 +153,37 @@ substrate-build-script-utils = { git = "https://github.com/paritytech/polkadot-s
substrate-fixed = { git = "https://github.com/opentensor/substrate-fixed.git", tag = "v0.5.9" }
substrate-frame-rpc-system = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.11.0" }
substrate-wasm-builder = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.11.0" }

sc-consensus-manual-seal = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.11.0", default-features = false }
sc-network-sync = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.11.0", default-features = false }
substrate-prometheus-endpoint = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.11.0", default-features = false }

# Frontier
fp-evm = { git = "https://github.com/gztensor/frontier", branch = "polkadot-v1.11.0-subtensor", default-features = false }
fp-rpc = { git = "https://github.com/gztensor/frontier", branch = "polkadot-v1.11.0-subtensor", default-features = false }
fp-self-contained = { git = "https://github.com/gztensor/frontier", branch = "polkadot-v1.11.0-subtensor", default-features = false, features = [
"serde",
] }
fp-account = { git = "https://github.com/gztensor/frontier", branch = "polkadot-v1.11.0-subtensor", default-features = false }
fc-storage = { git = "https://github.com/gztensor/frontier", branch = "polkadot-v1.11.0-subtensor", default-features = false }
fc-db = { git = "https://github.com/gztensor/frontier", branch = "polkadot-v1.11.0-subtensor", default-features = false }
fc-consensus = { git = "https://github.com/gztensor/frontier", branch = "polkadot-v1.11.0-subtensor", default-features = false }
fp-dynamic-fee = { git = "https://github.com/gztensor/frontier", branch = "polkadot-v1.11.0-subtensor", default-features = false }
fc-api = { git = "https://github.com/gztensor/frontier", branch = "polkadot-v1.11.0-subtensor", default-features = false }
fc-rpc = { git = "https://github.com/gztensor/frontier", branch = "polkadot-v1.11.0-subtensor", default-features = false }
fc-rpc-core = { git = "https://github.com/gztensor/frontier", branch = "polkadot-v1.11.0-subtensor", default-features = false }
fc-mapping-sync = { git = "https://github.com/gztensor/frontier", branch = "polkadot-v1.11.0-subtensor", default-features = false }

# Frontier FRAME
pallet-base-fee = { git = "https://github.com/gztensor/frontier", branch = "polkadot-v1.11.0-subtensor", default-features = false }
pallet-dynamic-fee = { git = "https://github.com/gztensor/frontier", branch = "polkadot-v1.11.0-subtensor", default-features = false }
pallet-ethereum = { git = "https://github.com/gztensor/frontier", branch = "polkadot-v1.11.0-subtensor", default-features = false }
pallet-evm = { git = "https://github.com/gztensor/frontier", branch = "polkadot-v1.11.0-subtensor", default-features = false }
pallet-evm-chain-id = { git = "https://github.com/gztensor/frontier", branch = "polkadot-v1.11.0-subtensor", default-features = false }
pallet-evm-precompile-modexp = { git = "https://github.com/gztensor/frontier", branch = "polkadot-v1.11.0-subtensor", default-features = false }
pallet-evm-precompile-sha3fips = { git = "https://github.com/gztensor/frontier", branch = "polkadot-v1.11.0-subtensor", default-features = false }
pallet-evm-precompile-simple = { git = "https://github.com/gztensor/frontier", branch = "polkadot-v1.11.0-subtensor", default-features = false }
pallet-hotfix-sufficients = { git = "https://github.com/gztensor/frontier", branch = "polkadot-v1.11.0-subtensor", default-features = false }
frame-metadata = "16"

[profile.release]
Expand Down
34 changes: 33 additions & 1 deletion node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ targets = ["x86_64-unknown-linux-gnu"]
name = "node-subtensor"

[dependencies]
async-trait = { workspace = true }
clap = { workspace = true, features = ["derive"] }
futures = { workspace = true, features = ["thread-pool"] }
serde = { workspace = true, features = ["derive"] }
Expand Down Expand Up @@ -74,6 +75,22 @@ pallet-transaction-payment-rpc = { workspace = true }
frame-benchmarking = { workspace = true }
frame-benchmarking-cli = { workspace = true }

# Needed for Frontier
sc-consensus-manual-seal = { workspace = true }
sc-network-sync = { workspace = true }
substrate-prometheus-endpoint = { workspace = true }

# Frontier
fc-storage = { workspace = true }
fc-db = { workspace = true }
fc-consensus = { workspace = true }
fp-dynamic-fee = { workspace = true }
fc-api = { workspace = true }
fc-rpc = { workspace = true }
fc-rpc-core = { workspace = true }
fp-rpc = { workspace = true }
fc-mapping-sync = { workspace = true }

# Local Dependencies
node-subtensor-runtime = { path = "../runtime" }
subtensor-custom-rpc = { path = "../pallets/subtensor/rpc" }
Expand All @@ -83,7 +100,22 @@ subtensor-custom-rpc-runtime-api = { path = "../pallets/subtensor/runtime-api" }
substrate-build-script-utils = { workspace = true }

[features]
default = []
default = [
"rocksdb",
"sql",
"txpool",
]
sql = [
"fc-db/sql",
"fc-mapping-sync/sql",
]
rocksdb = [
"sc-service/rocksdb",
"fc-db/rocksdb",
"fc-mapping-sync/rocksdb",
]
txpool = ["fc-rpc/txpool"]

# Dependencies that are only required if runtime benchmarking should be build.
runtime-benchmarks = [
"node-subtensor-runtime/runtime-benchmarks",
Expand Down
18 changes: 18 additions & 0 deletions node/src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use sc_cli::RunCmd;
use crate::ethereum::EthConfiguration;

#[derive(Debug, clap::Parser)]
pub struct Cli {
Expand All @@ -7,6 +8,13 @@ pub struct Cli {

#[clap(flatten)]
pub run: RunCmd,

/// Choose sealing method.
#[arg(long, value_enum, ignore_case = true)]
pub sealing: Option<Sealing>,

#[command(flatten)]
pub eth: EthConfiguration,
}

#[allow(clippy::large_enum_variant)]
Expand Down Expand Up @@ -45,3 +53,13 @@ pub enum Subcommand {
// Db meta columns information.
ChainInfo(sc_cli::ChainInfoCmd),
}

/// Available Sealing methods.
#[derive(Copy, Clone, Debug, Default, clap::ValueEnum)]
pub enum Sealing {
/// Seal using rpc method.
#[default]
Manual,
/// Seal when transaction is executed.
Instant,
}
167 changes: 99 additions & 68 deletions node/src/command.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use crate::{
chain_spec,
cli::{Cli, Subcommand},
service,
ethereum::db_config_dir, service
};
use fc_db::{kv::frontier_database_dir, DatabaseSource};

#[cfg(feature = "runtime-benchmarks")]
pub use crate::benchmarking::{inherent_benchmark_data, RemarkBuilder, TransferKeepAliveBuilder};
Expand All @@ -17,7 +18,8 @@ use sp_runtime::traits::HashingFor;

use node_subtensor_runtime::Block;
use sc_cli::SubstrateCli;
use sc_service::{Configuration, PartialComponents};
use sc_service::Configuration;
use futures::TryFutureExt;

impl SubstrateCli for Cli {
fn impl_name() -> String {
Expand Down Expand Up @@ -66,72 +68,97 @@ pub fn run() -> sc_cli::Result<()> {
let runner = cli.create_runner(cmd)?;
runner.sync_run(|config| cmd.run(config.chain_spec, config.network))
}
Some(Subcommand::CheckBlock(cmd)) => {
let runner = cli.create_runner(cmd)?;
runner.async_run(|config| {
let PartialComponents {
client,
task_manager,
import_queue,
..
} = service::new_partial(&config)?;
Ok((cmd.run(client, import_queue), task_manager))
})
}
Some(Subcommand::ExportBlocks(cmd)) => {
let runner = cli.create_runner(cmd)?;
runner.async_run(|config| {
let PartialComponents {
client,
task_manager,
..
} = service::new_partial(&config)?;
Ok((cmd.run(client, config.database), task_manager))
})
}
Some(Subcommand::ExportState(cmd)) => {
let runner = cli.create_runner(cmd)?;
runner.async_run(|config| {
let PartialComponents {
client,
task_manager,
..
} = service::new_partial(&config)?;
Ok((cmd.run(client, config.chain_spec), task_manager))
})
}
Some(Subcommand::ImportBlocks(cmd)) => {
let runner = cli.create_runner(cmd)?;
runner.async_run(|config| {
let PartialComponents {
client,
task_manager,
import_queue,
..
} = service::new_partial(&config)?;
Ok((cmd.run(client, import_queue), task_manager))
})
}
Some(Subcommand::CheckBlock(cmd)) => {
let runner = cli.create_runner(cmd)?;
runner.async_run(|mut config| {
let (client, _, import_queue, task_manager, _) =
service::new_chain_ops(&mut config, &cli.eth)?;
Ok((cmd.run(client, import_queue), task_manager))
})
}
Some(Subcommand::ExportBlocks(cmd)) => {
let runner = cli.create_runner(cmd)?;
runner.async_run(|mut config| {
let (client, _, _, task_manager, _) =
service::new_chain_ops(&mut config, &cli.eth)?;
Ok((cmd.run(client, config.database), task_manager))
})
}
Some(Subcommand::ExportState(cmd)) => {
let runner = cli.create_runner(cmd)?;
runner.async_run(|mut config| {
let (client, _, _, task_manager, _) =
service::new_chain_ops(&mut config, &cli.eth)?;
Ok((cmd.run(client, config.chain_spec), task_manager))
})
}
Some(Subcommand::ImportBlocks(cmd)) => {
let runner = cli.create_runner(cmd)?;
runner.async_run(|mut config| {
let (client, _, import_queue, task_manager, _) =
service::new_chain_ops(&mut config, &cli.eth)?;
Ok((cmd.run(client, import_queue), task_manager))
})
}
Some(Subcommand::PurgeChain(cmd)) => {
let runner = cli.create_runner(cmd)?;
runner.sync_run(|config| cmd.run(config.database))
}
Some(Subcommand::Revert(cmd)) => {
let runner = cli.create_runner(cmd)?;
runner.async_run(|config| {
let PartialComponents {
client,
task_manager,
backend,
..
} = service::new_partial(&config)?;
let aux_revert = Box::new(|client, _, blocks| {
sc_consensus_grandpa::revert(client, blocks)?;
Ok(())
});
Ok((cmd.run(client, backend, Some(aux_revert)), task_manager))
})
let runner = cli.create_runner(cmd)?;
runner.sync_run(|config| {
// Remove Frontier offchain db
let db_config_dir = db_config_dir(&config);
match cli.eth.frontier_backend_type {
crate::ethereum::BackendType::KeyValue => {
let frontier_database_config = match config.database {
DatabaseSource::RocksDb { .. } => DatabaseSource::RocksDb {
path: frontier_database_dir(&db_config_dir, "db"),
cache_size: 0,
},
DatabaseSource::ParityDb { .. } => DatabaseSource::ParityDb {
path: frontier_database_dir(&db_config_dir, "paritydb"),
},
_ => {
return Err(format!(
"Cannot purge `{:?}` database",
config.database
)
.into())
}
};
cmd.run(frontier_database_config)?;
}
crate::ethereum::BackendType::Sql => {
let db_path = db_config_dir.join("sql");
match std::fs::remove_dir_all(&db_path) {
Ok(_) => {
println!("{:?} removed.", &db_path);
}
Err(ref err) if err.kind() == std::io::ErrorKind::NotFound => {
eprintln!("{:?} did not exist.", &db_path);
}
Err(err) => {
return Err(format!(
"Cannot purge `{:?}` database: {:?}",
db_path, err,
)
.into())
}
};
}
};
cmd.run(config.database)
})
}
Some(Subcommand::Revert(cmd)) => {
let runner = cli.create_runner(cmd)?;
runner.async_run(|mut config| {
let (client, backend, _, task_manager, _) =
service::new_chain_ops(&mut config, &cli.eth)?;
let aux_revert = Box::new(move |client, _, blocks| {
sc_consensus_grandpa::revert(client, blocks)?;
Ok(())
});
Ok((cmd.run(client, backend, Some(aux_revert)), task_manager))
})
}
#[cfg(feature = "runtime-benchmarks")]
Some(Subcommand::Benchmark(cmd)) => {
let runner = cli.create_runner(cmd)?;
Expand Down Expand Up @@ -210,8 +237,12 @@ pub fn run() -> sc_cli::Result<()> {
let runner = cli.create_runner(&cli.run)?;
runner.run_node_until_exit(|config| async move {
let config = override_default_heap_pages(config, 60_000);
service::new_full::<sc_network::Litep2pNetworkBackend>(config)
.map_err(sc_cli::Error::Service)
service::new_full::<sc_network::Litep2pNetworkBackend>(
config,
cli.eth,
cli.sealing
).map_err(Into::into)
.await
})
}
}
Expand Down
Loading

0 comments on commit 4886e96

Please sign in to comment.