Skip to content

Commit

Permalink
Updates frontier dependency (#146)
Browse files Browse the repository at this point in the history
* Update and add new inherent

* Update
  • Loading branch information
drewstone authored May 20, 2021
1 parent e1405f1 commit a183e53
Show file tree
Hide file tree
Showing 8 changed files with 395 additions and 196 deletions.
503 changes: 343 additions & 160 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ fc-mapping-sync = { default-features = false, git = "https://github.com/webb-too

pallet-evm = { git = "https://github.com/webb-tools/frontier", branch = "erup-4" }
pallet-ethereum = { git = "https://github.com/webb-tools/frontier", branch = "erup-4" }
pallet-dynamic-fee = { git = "https://github.com/webb-tools/frontier", branch = "erup-4" }

merkle = { package = "pallet-merkle", path = "../pallets/merkle" }
merkle-rpc = { package = "pallet-merkle-rpc", path = "../pallets/merkle/rpc" }
Expand Down
2 changes: 1 addition & 1 deletion node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ fn testnet_genesis(
// Configure endowed accounts with initial balance of 1 << 60.
balances: endowed_accounts.iter().cloned().map(|k| (k, 1 << 60)).collect(),
},
pallet_contracts: Default::default(),
pallet_aura: AuraConfig {
authorities: initial_authorities.iter().map(|x| (x.0.clone())).collect(),
},
Expand All @@ -168,5 +167,6 @@ fn testnet_genesis(
pallet_evm: EVMConfig {
accounts: evm_accounts,
},
pallet_dynamic_fee: Default::default(),
}
}
4 changes: 4 additions & 0 deletions node/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ pub struct RunCmd {
/// Maximum number of logs in a query.
#[structopt(long, default_value = "10000")]
pub max_past_logs: u32,

/// The dynamic-fee pallet target gas price set by block author
#[structopt(long, default_value = "1")]
pub target_gas_price: u64,
}

#[derive(Debug, StructOpt)]
Expand Down
11 changes: 9 additions & 2 deletions node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub use sc_executor::NativeExecutor;
use sc_service::{error::Error as ServiceError, BasePath, Configuration, TaskManager};
use sc_telemetry::{Telemetry, TelemetryWorker};
use sp_consensus_aura::sr25519::AuthorityPair as AuraPair;
use sp_core::U256;

use sp_consensus::SlotData;
use std::{
Expand Down Expand Up @@ -148,6 +149,8 @@ pub fn new_partial(
let slot_duration = sc_consensus_aura::slot_duration(&*client)?;
let raw_slot_duration = slot_duration.slot_duration();

let target_gas_price = U256::from(cli.run.target_gas_price);

let import_queue = sc_consensus_aura::import_queue::<AuraPair, _, _, _, _, _, _>(
ImportQueueParams {
block_import: aura_block_import.clone(),
Expand All @@ -161,8 +164,9 @@ pub fn new_partial(
*timestamp,
raw_slot_duration,
);
let fee = pallet_dynamic_fee::InherentDataProvider(target_gas_price);

Ok((timestamp, slot))
Ok((timestamp, slot, fee))
},
spawner: &task_manager.spawn_essential_handle(),
can_author_with: sp_consensus::CanAuthorWithNativeVersion::new(client.executor().clone()),
Expand Down Expand Up @@ -193,6 +197,7 @@ pub fn new_partial(
/// Builds a new service for a full client.
pub fn new_full(mut config: Configuration, cli: &Cli) -> Result<TaskManager, ServiceError> {
let enable_dev_signer = cli.run.enable_dev_signer;
let target_gas_price = U256::from(cli.run.target_gas_price);

let sc_service::PartialComponents {
client,
Expand Down Expand Up @@ -361,7 +366,9 @@ pub fn new_full(mut config: Configuration, cli: &Cli) -> Result<TaskManager, Ser
raw_slot_duration,
);

Ok((timestamp, slot))
let fee = pallet_dynamic_fee::InherentDataProvider(target_gas_price);

Ok((timestamp, slot, fee))
},
force_authoring,
backoff_authoring_blocks,
Expand Down
8 changes: 5 additions & 3 deletions runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ version = "3.0.0"
[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

[build-dependencies]
wasm-builder-runner = { package = "substrate-wasm-builder-runner", version = "2.0.0" }

# alias "parity-scale-code" to "codec"
[dependencies.codec]
default-features = false
Expand All @@ -37,6 +34,7 @@ pallet-contracts = { default-features = false, git = "https://github.com/webb-to
pallet-contracts-primitives = { default-features = false, git = "https://github.com/webb-tools/substrate.git", branch = "erup-4" }
pallet-contracts-rpc-runtime-api = { default-features = false, git = "https://github.com/webb-tools/substrate.git", branch = "erup-4" }

pallet-dynamic-fee = { git = "https://github.com/webb-tools/frontier", branch = "erup-4", default-features = false }
pallet-evm = { git = "https://github.com/webb-tools/frontier", branch = "erup-4", default-features = false }
pallet-ethereum = { git = "https://github.com/webb-tools/frontier", branch = "erup-4", default-features = false }
fp-rpc = { default-features = false, git = "https://github.com/webb-tools/frontier", branch = "erup-4" }
Expand Down Expand Up @@ -67,6 +65,9 @@ webb-currencies = { default-features = false, path = "../pallets/currencies" }
webb-traits = { default-features = false, path = "../pallets/traits" }
webb-tokens = { default-features = false, path = "../pallets/tokens" }

[build-dependencies]
substrate-wasm-builder = { git = "https://github.com/webb-tools/substrate.git", branch = "erup-4" }

[features]
default = ["std", "aura"]
aura = []
Expand Down Expand Up @@ -118,6 +119,7 @@ std = [
"webb-tokens/std",

"fp-rpc/std",
"pallet-dynamic-fee/std",
"pallet-ethereum/std",
"pallet-evm/std",
"pallet-evm-precompile-simple/std",
Expand Down
3 changes: 1 addition & 2 deletions runtime/build.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use wasm_builder_runner::WasmBuilder;
use substrate_wasm_builder::WasmBuilder;

fn main() {
WasmBuilder::new()
.with_current_project()
.with_wasm_builder_from_crates("2.0.0")
.export_heap_base()
.import_memory()
.build()
Expand Down
59 changes: 31 additions & 28 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ use merkle::utils::keys::ScalarData;
use webb_currencies::BasicCurrencyAdapter;

use pallet_ethereum::TransactionStatus;
use pallet_evm::{Account as EVMAccount, EnsureAddressTruncated, FeeCalculator, HashedAddressMapping, Runner};
use pallet_evm::{Account as EVMAccount, EnsureAddressTruncated, HashedAddressMapping, Runner};

use sp_core::crypto::Public;
#[cfg(any(feature = "std", test))]
Expand Down Expand Up @@ -289,7 +289,6 @@ parameter_types! {
pub RentFraction: Perbill = Perbill::from_rational(1u32, 30 * DAYS);
pub const SurchargeReward: Balance = 150 * MILLICENTS;
pub const SignedClaimHandicap: u32 = 2;
pub const MaxDepth: u32 = 32;
pub const MaxValueSize: u32 = 16 * 1024;
// The lazy deletion runs inside on_initialize.
pub DeletionWeightLimit: Weight = AVERAGE_ON_INITIALIZE_RATIO *
Expand All @@ -300,30 +299,29 @@ parameter_types! {
<Runtime as pallet_contracts::Config>::WeightInfo::on_initialize_per_queue_item(1) -
<Runtime as pallet_contracts::Config>::WeightInfo::on_initialize_per_queue_item(0)
)) / 5) as u32;
pub MaxCodeSize: u32 = 128 * 1024;
pub Schedule: pallet_contracts::Schedule<Runtime> = Default::default();
}

impl pallet_contracts::Config for Runtime {
type ChainExtension = ();
type Time = Timestamp;
type Randomness = RandomnessCollectiveFlip;
type Currency = Balances;
type DeletionQueueDepth = DeletionQueueDepth;
type DeletionWeightLimit = DeletionWeightLimit;
type Event = Event;
type RentPayment = ();
type SignedClaimHandicap = SignedClaimHandicap;
type TombstoneDeposit = TombstoneDeposit;
type DepositPerContract = DepositPerContract;
type DepositPerStorageByte = DepositPerStorageByte;
type DepositPerStorageItem = DepositPerStorageItem;
type Event = Event;
type MaxCodeSize = MaxCodeSize;
type MaxDepth = MaxDepth;
type MaxValueSize = MaxValueSize;
type Randomness = RandomnessCollectiveFlip;
type RentFraction = RentFraction;
type RentPayment = ();
type SignedClaimHandicap = SignedClaimHandicap;
type SurchargeReward = SurchargeReward;
type Time = Timestamp;
type TombstoneDeposit = TombstoneDeposit;
type WeightInfo = pallet_contracts::weights::SubstrateWeight<Self>;
type CallStack = [pallet_contracts::Frame<Self>; 31];
type WeightPrice = pallet_transaction_payment::Module<Self>;
type WeightInfo = pallet_contracts::weights::SubstrateWeight<Self>;
type ChainExtension = ();
type DeletionQueueDepth = DeletionQueueDepth;
type DeletionWeightLimit = DeletionWeightLimit;
type Schedule = Schedule;
}

parameter_types! {
Expand Down Expand Up @@ -439,26 +437,20 @@ impl pallet_evm::GasWeightMapping for AnonGasWeightMapping {
u64::try_from(weight.wrapping_div(WEIGHT_PER_GAS)).unwrap_or(u32::MAX as u64)
}
}
/// Fixed gas price of `1`.
pub struct FixedGasPrice;
impl FeeCalculator for FixedGasPrice {
fn min_gas_price() -> U256 {
// Gas price is always one token per gas.
1.into()
}
}

parameter_types! {
pub const ChainId: u64 = 42;
pub BlockGasLimit: U256 = U256::from(u32::max_value());
}

impl pallet_evm::Config for Runtime {
type AddressMapping = HashedAddressMapping<BlakeTwo256>;
type BlockGasLimit = BlockGasLimit;
type CallOrigin = EnsureAddressTruncated;
type ChainId = ChainId;
type Currency = Balances;
type Event = Event;
type FeeCalculator = FixedGasPrice;
type FeeCalculator = pallet_dynamic_fee::Pallet<Self>;
type GasWeightMapping = AnonGasWeightMapping;
type OnChargeTransaction = ();
type Precompiles = (
Expand All @@ -473,6 +465,7 @@ impl pallet_evm::Config for Runtime {
type Runner = pallet_evm::runner::stack::Runner<Self>;
type WithdrawOrigin = EnsureAddressTruncated;
}

pub struct EthereumFindAuthor<F>(PhantomData<F>);
impl<F: FindAuthor<u32>> FindAuthor<H160> for EthereumFindAuthor<F> {
fn find_author<'a, I>(digests: I) -> Option<H160>
Expand All @@ -492,6 +485,15 @@ impl pallet_ethereum::Config for Runtime {
type StateRoot = pallet_ethereum::IntermediateStateRoot;
}

frame_support::parameter_types! {
pub BoundDivision: U256 = U256::from(1024);
}

impl pallet_dynamic_fee::Config for Runtime {
type Event = Event;
type MinGasPriceBoundDivisor = BoundDivision;
}

// Create the runtime by composing the FRAME pallets that were previously
// configured.
construct_runtime!(
Expand All @@ -506,10 +508,11 @@ construct_runtime!(
Aura: pallet_aura::{Pallet, Config<T>},
Grandpa: pallet_grandpa::{Pallet, Call, Storage, Config, Event},
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
Contracts: pallet_contracts::{Pallet, Call, Config<T>, Storage, Event<T>},
Contracts: pallet_contracts::{Pallet, Call, Storage, Event<T>},

Ethereum: pallet_ethereum::{Pallet, Call, Storage, Event, Config, ValidateUnsigned},
EVM: pallet_evm::{Pallet, Config, Call, Storage, Event<T>},
DynamicFee: pallet_dynamic_fee::{Pallet, Call, Storage, Config, Event<T>, Inherent},

TransactionPayment: pallet_transaction_payment::{Pallet, Storage},
Sudo: pallet_sudo::{Pallet, Call, Config<T>, Storage, Event<T>},
Expand Down Expand Up @@ -684,7 +687,7 @@ impl_runtime_apis! {
gas_limit: u64,
input_data: Vec<u8>,
) -> pallet_contracts_primitives::ContractExecResult {
Contracts::bare_call(origin, dest, value, gas_limit, input_data)
Contracts::bare_call(origin, dest, value, gas_limit, input_data, true)
}

fn instantiate(
Expand All @@ -696,7 +699,7 @@ impl_runtime_apis! {
salt: Vec<u8>,
) -> pallet_contracts_primitives::ContractInstantiateResult<AccountId, BlockNumber>
{
Contracts::bare_instantiate(origin, endowment, gas_limit, code, data, salt, true)
Contracts::bare_instantiate(origin, endowment, gas_limit, code, data, salt, true, true)
}

fn get_storage(
Expand Down

0 comments on commit a183e53

Please sign in to comment.