Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Ethereum components from Frontier #9

Merged
merged 35 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
7504986
Get started, not yet compiling
notlesh Jun 7, 2023
a88b126
Compiling baseline
notlesh Jun 7, 2023
37d2d58
Remove ethereum_chain_id
notlesh Jun 8, 2023
73d7bec
Revert "Remove ethereum_chain_id"
notlesh Jun 8, 2023
f0c7c38
Initialize chain_id to something other than 0
notlesh Jun 8, 2023
b7f239b
Some progress towards Eth RPC
notlesh Jun 9, 2023
760cc46
Incremental progress
notlesh Jun 12, 2023
f16559b
Remove Eth pubsub
notlesh Jun 12, 2023
01b9550
command_sink for authorship
notlesh Jun 12, 2023
cbf9b49
Impl nonce api in runtime
notlesh Jun 12, 2023
6859a3b
Impl EthereumRuntimeRPCApi
notlesh Jun 12, 2023
cba6352
Getting close...
notlesh Jun 12, 2023
7d5e5ec
It compiles!
notlesh Jun 12, 2023
5641c09
Add address mapping pallet
notlesh Jun 12, 2023
fd81b24
Add pallet to workspace
notlesh Jun 13, 2023
ee393b9
Merge branch 'main' into notlesh-add-frontier (prefer ours @ conflicts)
notlesh Jun 13, 2023
5552de7
fmt
notlesh Jun 13, 2023
becddfd
Use frame_system::Config::AccountId for mapping type
notlesh Jun 14, 2023
72eff53
Hook up EVMAddressMapping to runtime
notlesh Jun 14, 2023
61479e9
Add reverse address mapping and implement EnsureADdressOrigin
notlesh Jun 14, 2023
ecb0132
Adopt Acala's approach to AddressMapping fallback
notlesh Jun 15, 2023
73cbc71
Probably not quite the FindAuthor we're looking for, but close
notlesh Jun 15, 2023
686d22d
Remove unused generics
notlesh Jun 15, 2023
ef6c9e0
Add basic precompiles
notlesh Jun 15, 2023
2b5b3de
Move ManagedAddressMapping to runtime/src
notlesh Jun 15, 2023
b2abaaa
Merge branch 'main' into notlesh-add-frontier
notlesh Jun 15, 2023
bf2cdb4
Remove duplicate RPC mod
notlesh Jun 19, 2023
d41421b
Resolve most clippy issues
notlesh Jun 20, 2023
a0a782e
Remove unused spawn_frontier_tasks
notlesh Jun 20, 2023
95dfbcd
More clippy fixes
notlesh Jun 20, 2023
d8305bf
Merge branch 'main' into notlesh-add-frontier
notlesh Jun 20, 2023
7bf3f4f
Update spec.json
notlesh Jun 20, 2023
ee93809
genesis config for address mapping
JoshOrndorff Jun 24, 2023
95a72f2
Disabling fees makes manual evm usage possible
JoshOrndorff Jun 24, 2023
eae5993
Merge branch 'main' into notlesh-add-frontier
JoshOrndorff Jun 24, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,10 @@ fn testnet_genesis(
difficulty_adjustment: DifficultyAdjustmentConfig {
initial_difficulty: 4_000_000.into(),
},

evm: Default::default(),
evm_chain_id: Default::default(),
ethereum: Default::default(),
base_fee: Default::default(),
}
}
12 changes: 12 additions & 0 deletions runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ sp-version = { default-features = false, git = "https://github.com/paritytech/su
pallet-timestamp = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
sp-keystore = { optional = true, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }

# Frontier
pallet-base-fee = { default-features = false, git = "https://github.com/paritytech/frontier.git", branch = "bar/polkadot-v0.9.42" }
pallet-evm = { default-features = false, git = "https://github.com/paritytech/frontier.git", branch = "bar/polkadot-v0.9.42" }
pallet-evm-chain-id = { default-features = false, git = "https://github.com/paritytech/frontier.git", branch = "bar/polkadot-v0.9.42" }
pallet-ethereum = { default-features = false, git = "https://github.com/paritytech/frontier.git", branch = "bar/polkadot-v0.9.42" }
fp-evm = { default-features = false, git = "https://github.com/paritytech/frontier.git", branch = "bar/polkadot-v0.9.42" }

[dev-dependencies]
hex-literal = "0.4.1"

Expand Down Expand Up @@ -63,4 +70,9 @@ std = [
'pallet-timestamp/std',
'async-trait',
'sp-keystore',
'pallet-evm/std',
'pallet-evm-chain-id/std',
'pallet-ethereum/std',
'pallet-base-fee/std',
'fp-evm/std',
]
100 changes: 96 additions & 4 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
use frame_support::traits::Currency;
use issuance::Issuance;
use sp_std::prelude::*;
use sp_core::{OpaqueMetadata, U256};
use sp_core::{OpaqueMetadata, H160, U256};
use sp_runtime::{
ApplyExtrinsicResult,
create_runtime_str,
Expand All @@ -33,19 +33,27 @@ use sp_api::impl_runtime_apis;
use sp_version::RuntimeVersion;
#[cfg(feature = "std")]
use sp_version::NativeVersion;
// Frontier
use pallet_ethereum::{Call::transact, PostLogContent, Transaction as EthereumTransaction};
use pallet_evm::{
Account as EVMAccount, EnsureAddressNever, FeeCalculator, IdentityAddressMapping, Runner,
AddressMapping,
};
use fp_evm::weight_per_gas;

// A few exports that help ease life for downstream crates.
#[cfg(any(feature = "std", test))]
pub use sp_runtime::BuildStorage;
pub use pallet_timestamp::Call as TimestampCall;
pub use pallet_balances::Call as BalancesCall;
pub use sp_runtime::{Permill, Perbill};
pub use sp_runtime::{AccountId32, ConsensusEngineId, Permill, Perbill};
pub use frame_support::{
StorageValue, construct_runtime, parameter_types,
dispatch::Callable,
traits::{IsSubType, ConstU128, ConstU32},
pallet_prelude::*,
traits::{IsSubType, ConstU128, ConstU32, FindAuthor},
weights::{
constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_REF_TIME_PER_SECOND},
constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_REF_TIME_PER_SECOND, WEIGHT_REF_TIME_PER_MILLIS},
Weight,
},
};
Expand Down Expand Up @@ -123,6 +131,12 @@ pub fn native_version() -> NativeVersion {
}

const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);
/// We allow for 2000ms of compute with a 6 second average block time.
pub const WEIGHT_MILLISECS_PER_BLOCK: u64 = 2000;
pub const MAXIMUM_BLOCK_WEIGHT: Weight = Weight::from_parts(
WEIGHT_MILLISECS_PER_BLOCK * WEIGHT_REF_TIME_PER_MILLIS,
u64::MAX,
);

parameter_types! {
pub const BlockHashCount: BlockNumber = 2400;
Expand Down Expand Up @@ -264,6 +278,80 @@ impl block_author::Config for Runtime {
}
}

parameter_types! {
pub DefaultBaseFeePerGas: U256 = U256::from(1_000_000_000);
pub DefaultElasticity: Permill = Permill::from_parts(125_000);
}

pub struct BaseFeeThreshold;
impl pallet_base_fee::BaseFeeThreshold for BaseFeeThreshold {
fn lower() -> Permill {
Permill::zero()
}
fn ideal() -> Permill {
Permill::from_parts(500_000)
}
fn upper() -> Permill {
Permill::from_parts(1_000_000)
}
}

impl pallet_base_fee::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Threshold = BaseFeeThreshold;
type DefaultBaseFeePerGas = DefaultBaseFeePerGas;
type DefaultElasticity = DefaultElasticity;
}

impl pallet_evm_chain_id::Config for Runtime {}

const BLOCK_GAS_LIMIT: u64 = 75_000_000;

parameter_types! {
pub BlockGasLimit: U256 = U256::from(BLOCK_GAS_LIMIT);
pub WeightPerGas: Weight = Weight::from_parts(weight_per_gas(BLOCK_GAS_LIMIT, NORMAL_DISPATCH_RATIO, WEIGHT_MILLISECS_PER_BLOCK), 0);
}

pub struct TmpAddressMapping;
impl AddressMapping<AccountId32> for TmpAddressMapping {
fn into_account_id(address: H160) -> AccountId32 {
AccountId32::new([0; 32])
}
}

impl pallet_evm::Config for Runtime {
type FeeCalculator = BaseFee;
type GasWeightMapping = pallet_evm::FixedGasWeightMapping<Self>;
type WeightPerGas = WeightPerGas;
type BlockHashMapping = pallet_ethereum::EthereumBlockHashMapping<Self>;
type CallOrigin = EnsureAddressNever<Self::AccountId>;
type WithdrawOrigin = EnsureAddressNever<Self::AccountId>;
type AddressMapping = TmpAddressMapping;
type Currency = Balances;
type RuntimeEvent = RuntimeEvent;
type PrecompilesType = ();
type PrecompilesValue = ();
type ChainId = EVMChainId;
type BlockGasLimit = BlockGasLimit;
type Runner = pallet_evm::runner::stack::Runner<Self>;
type OnChargeTransaction = ();
type OnCreate = ();
type FindAuthor = ();
type Timestamp = Timestamp;
type WeightInfo = pallet_evm::weights::SubstrateWeight<Runtime>;
}

parameter_types! {
pub const PostBlockAndTxnHashes: PostLogContent = PostLogContent::BlockAndTxnHashes;
}

impl pallet_ethereum::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type StateRoot = pallet_ethereum::IntermediateStateRoot<Self>;
type PostLogContent = PostBlockAndTxnHashes;
type ExtraDataLength = ConstU32<30>;
}

construct_runtime!(
pub enum Runtime where
Block = Block,
Expand All @@ -278,6 +366,10 @@ construct_runtime!(
DifficultyAdjustment: difficulty,
BlockAuthor: block_author,
Faucet: faucet,
EVM: pallet_evm,
EVMChainId: pallet_evm_chain_id,
BaseFee: pallet_base_fee,
Ethereum: pallet_ethereum,
}
);

Expand Down