Skip to content

Commit

Permalink
wip: flagged eth
Browse files Browse the repository at this point in the history
  • Loading branch information
Supremesource committed Nov 24, 2024
1 parent 31ce9dd commit fc5aeee
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 7 deletions.
1 change: 1 addition & 0 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,6 @@ runtime-benchmarks = [
"sc-service/runtime-benchmarks",
"node-subspace-runtime/runtime-benchmarks",
]
testnet = ["node-subspace-runtime/testnet"]
try-runtime = ["node-subspace-runtime/try-runtime"]
testnet-faucet = ["node-subspace-runtime/testnet-faucet"]
2 changes: 2 additions & 0 deletions node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ pub fn run() -> sc_cli::Result<()> {
runner.sync_run(|config| {
// Remove Frontier offchain db
let db_config_dir = db_config_dir(&config);
#[cfg(feature = "testnet")]
match cli.eth.frontier_backend_type {
crate::eth::BackendType::KeyValue => {
let frontier_database_config = match config.database {
Expand All @@ -154,6 +155,7 @@ pub fn run() -> sc_cli::Result<()> {
};
cmd.run(frontier_database_config)?;
}
#[cfg(feature = "testnet")]
crate::eth::BackendType::Sql => {
let db_path = db_config_dir.join("sql");
match std::fs::remove_dir_all(&db_path) {
Expand Down
1 change: 1 addition & 0 deletions node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ mod chain_spec;
mod cli;
mod client;
mod command;
#[cfg(feature = "testnet")]
mod eth;
mod rpc;
mod service;
Expand Down
1 change: 1 addition & 0 deletions node/src/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ where
}

// Ethereum compatibility RPCs
#[cfg(feature = "testnet")]
let io = create_eth::<_, _, _, _, _, _, _, DefaultEthConfig<C, BE>>(
io,
eth,
Expand Down
14 changes: 9 additions & 5 deletions node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ use std::{
use crate::{
cli::Sealing,
client::{Client, FullBackend},
eth::{
new_frontier_partial, spawn_frontier_tasks, BackendType, FrontierBackend,
FrontierPartialComponents, StorageOverride, StorageOverrideHandler,
},
};

pub use crate::eth::{db_config_dir, EthConfiguration};
#[cfg(feature = "testnet")]
pub use crate::eth::{
db_config_dir, new_frontier_partial, spawn_frontier_tasks, BackendType, EthConfiguration,
FrontierBackend, FrontierPartialComponents, StorageOverride, StorageOverrideHandler,
};

mod decrypter;
mod manual_seal;
Expand Down Expand Up @@ -106,7 +106,9 @@ where
telemetry.as_ref().map(|x| x.handle()),
)?;

#[cfg(feature = "testnet")]
let storage_override = Arc::new(StorageOverrideHandler::new(client.clone()));
#[cfg(feature = "testnet")]
let frontier_backend = match eth_config.frontier_backend_type {
BackendType::KeyValue => FrontierBackend::KeyValue(Arc::new(fc_db::kv::Backend::open(
Arc::clone(&client),
Expand Down Expand Up @@ -259,6 +261,7 @@ where
mut other,
} = new_partial(config, eth_config, build_import_queue)?;

#[cfg(feature = "testnet")]
let FrontierPartialComponents {
filter_pool,
fee_history_cache,
Expand Down Expand Up @@ -461,6 +464,7 @@ where
telemetry: other.telemetry.as_mut(),
})?;

#[cfg(feature = "testnet")]
spawn_frontier_tasks(
&task_manager,
client.clone(),
Expand Down
34 changes: 32 additions & 2 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ pub use sp_runtime::BuildStorage;
pub use pallet_subspace;

// Precompiles module (for EVM precompiles)
#[cfg(feature = "testnet")]
mod precompiles;
#[cfg(feature = "testnet")]
use precompiles::FrontierPrecompiles;

use frame_system::RawOrigin;
Expand Down Expand Up @@ -186,7 +188,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("node-subspace"),
impl_name: create_runtime_str!("node-subspace"),
authoring_version: 1,
spec_version: 511,
spec_version: 512,
impl_version: 1,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
Expand Down Expand Up @@ -520,9 +522,12 @@ impl<F: FindAuthor<u32>> FindAuthor<H160> for FindAuthorTruncated<F> {
}
}

#[cfg(feature = "testnet")]
const BLOCK_GAS_LIMIT: u64 = 75_000_000;
#[cfg(feature = "testnet")]
const MAX_POV_SIZE: u64 = 5 * 1024 * 1024;

#[cfg(feature = "testnet")]
parameter_types! {
pub BlockGasLimit: U256 = U256::from(BLOCK_GAS_LIMIT);
pub const GasLimitPovSizeRatio: u64 = BLOCK_GAS_LIMIT.saturating_div(MAX_POV_SIZE);
Expand All @@ -531,6 +536,7 @@ parameter_types! {
pub SuicideQuickClearLimit: u32 = 0;
}

#[cfg(feature = "testnet")]
impl pallet_evm::Config for Runtime {
type FeeCalculator = BaseFee;
type GasWeightMapping = pallet_evm::FixedGasWeightMapping<Self>;
Expand All @@ -556,30 +562,37 @@ impl pallet_evm::Config for Runtime {
type WeightInfo = pallet_evm::weights::SubstrateWeight<Runtime>;
}

#[cfg(feature = "testnet")]
parameter_types! {
pub const PostBlockAndTxnHashes: PostLogContent = PostLogContent::BlockAndTxnHashes;
}

#[cfg(feature = "testnet")]
impl pallet_ethereum::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type StateRoot = pallet_ethereum::IntermediateStateRoot<Self>;
type PostLogContent = PostBlockAndTxnHashes;
type ExtraDataLength = ConstU32<30>;
}

#[cfg(feature = "testnet")]
parameter_types! {
pub BoundDivision: U256 = U256::from(1024);
}

#[cfg(feature = "testnet")]
impl pallet_dynamic_fee::Config for Runtime {
type MinGasPriceBoundDivisor = BoundDivision;
}

#[cfg(feature = "testnet")]
parameter_types! {
pub DefaultBaseFeePerGas: U256 = U256::from(1_000_000_000);
pub DefaultElasticity: Permill = Permill::from_parts(125_000);
}
#[cfg(feature = "testnet")]
pub struct BaseFeeThreshold;
#[cfg(feature = "testnet")]
impl pallet_base_fee::BaseFeeThreshold for BaseFeeThreshold {
fn lower() -> Permill {
Permill::zero()
Expand All @@ -591,6 +604,8 @@ impl pallet_base_fee::BaseFeeThreshold for BaseFeeThreshold {
Permill::from_parts(1_000_000)
}
}

#[cfg(feature = "testnet")]
impl pallet_base_fee::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Threshold = BaseFeeThreshold;
Expand Down Expand Up @@ -619,10 +634,14 @@ construct_runtime!(
#[cfg(feature = "testnet-faucet")]
FaucetModule: pallet_faucet,

// EVM Support
// EVM Support, for now only on testnet
#[cfg(feature = "testnet")]
EVM: pallet_evm,
#[cfg(feature = "testnet")]
Ethereum: pallet_ethereum,
#[cfg(feature = "testnet")]
BaseFee: pallet_base_fee,
#[cfg(feature = "testnet")]
DynamicFee: pallet_dynamic_fee,
}
);
Expand All @@ -636,6 +655,7 @@ impl<B> Default for TransactionConverter<B> {
}
}

#[cfg(feature = "testnet")]
impl<B: BlockT> fp_rpc::ConvertTransaction<<B as BlockT>::Extrinsic> for TransactionConverter<B> {
fn convert_transaction(
&self,
Expand Down Expand Up @@ -719,9 +739,16 @@ pub type SignedExtra = (
);

// Unchecked extrinsic type as expected by this runtime.
#[cfg(feature = "testnet")]
pub type UncheckedExtrinsic =
fp_self_contained::UncheckedExtrinsic<Address, RuntimeCall, Signature, SignedExtra>;

#[cfg(not(feature = "testnet"))]
pub type UncheckedExtrinsic =
generic::UncheckedExtrinsic<Address, RuntimeCall, Signature, SignedExtra>;

/// Extrinsic type that has already been checked.
#[cfg(feature = "testnet")]
pub type CheckedExtrinsic =
fp_self_contained::CheckedExtrinsic<AccountId, RuntimeCall, SignedExtra, H160>;
// The payload being signed in transactions.
Expand All @@ -736,6 +763,7 @@ pub type Executive = frame_executive::Executive<
Migrations,
>;

#[cfg(feature = "testnet")]
impl fp_self_contained::SelfContainedCall for RuntimeCall {
type SignedInfo = H160;

Expand Down Expand Up @@ -1007,6 +1035,7 @@ impl_runtime_apis! {
}


#[cfg(feature = "testnet")]
impl fp_rpc::EthereumRuntimeRPCApi<Block> for Runtime {
fn chain_id() -> u64 {
<Runtime as pallet_evm::Config>::ChainId::get()
Expand Down Expand Up @@ -1198,6 +1227,7 @@ impl_runtime_apis! {
}
}

#[cfg(feature = "testnet")]
impl fp_rpc::ConvertTransactionRuntimeApi<Block> for Runtime {
fn convert_transaction(transaction: EthereumTransaction) -> <Block as BlockT>::Extrinsic {
UncheckedExtrinsic::new_unsigned(
Expand Down

0 comments on commit fc5aeee

Please sign in to comment.