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

Fee Alignment - Shibuya/local #1025

Merged
merged 24 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
23 changes: 21 additions & 2 deletions 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 @@ -278,6 +278,7 @@ pallet-xc-asset-config = { path = "./pallets/xc-asset-config", default-features
pallet-xvm = { path = "./pallets/xvm", default-features = false }
pallet-xcm = { path = "./pallets/pallet-xcm", default-features = false }
pallet-ethereum-checked = { path = "./pallets/ethereum-checked", default-features = false }
pallet-dynamic-evm-base-fee = { path = "./pallets/dynamic-evm-base-fee", default-features = false }
pallet-unified-accounts = { path = "./pallets/unified-accounts", default-features = false }

astar-primitives = { path = "./primitives", default-features = false }
Expand Down
12 changes: 4 additions & 8 deletions bin/collator/src/local/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
//! Chain specifications.

use local_runtime::{
wasm_binary_unwrap, AccountId, AuraConfig, AuraId, BalancesConfig, BaseFeeConfig,
BlockRewardConfig, CouncilConfig, DemocracyConfig, EVMConfig, GenesisConfig, GrandpaConfig,
GrandpaId, Precompiles, Signature, SudoConfig, SystemConfig, TechnicalCommitteeConfig,
TreasuryConfig, VestingConfig,
wasm_binary_unwrap, AccountId, AuraConfig, AuraId, BalancesConfig, BlockRewardConfig,
CouncilConfig, DemocracyConfig, EVMConfig, GenesisConfig, GrandpaConfig, GrandpaId,
Precompiles, Signature, SudoConfig, SystemConfig, TechnicalCommitteeConfig, TreasuryConfig,
VestingConfig,
};
use sc_service::ChainType;
use sp_core::{crypto::Ss58Codec, sr25519, Pair, Public};
Expand Down Expand Up @@ -154,10 +154,6 @@ fn testnet_genesis(
.collect(),
},
ethereum: Default::default(),
base_fee: BaseFeeConfig::new(
sp_core::U256::from(1_000_000_000u64),
sp_runtime::Permill::zero(),
),
sudo: SudoConfig {
key: Some(root_key),
},
Expand Down
13 changes: 4 additions & 9 deletions bin/collator/src/parachain/chain_spec/shibuya.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@
use cumulus_primitives_core::ParaId;
use sc_service::ChainType;
use shibuya_runtime::{
wasm_binary_unwrap, AccountId, AuraConfig, AuraId, Balance, BalancesConfig, BaseFeeConfig,
BlockRewardConfig, CollatorSelectionConfig, CouncilConfig, DemocracyConfig, EVMChainIdConfig,
EVMConfig, GenesisConfig, ParachainInfoConfig, Precompiles, SessionConfig, SessionKeys,
Signature, SudoConfig, SystemConfig, TechnicalCommitteeConfig, TreasuryConfig, VestingConfig,
SBY,
wasm_binary_unwrap, AccountId, AuraConfig, AuraId, Balance, BalancesConfig, BlockRewardConfig,
CollatorSelectionConfig, CouncilConfig, DemocracyConfig, EVMChainIdConfig, EVMConfig,
GenesisConfig, ParachainInfoConfig, Precompiles, SessionConfig, SessionKeys, Signature,
SudoConfig, SystemConfig, TechnicalCommitteeConfig, TreasuryConfig, VestingConfig, SBY,
};
use sp_core::{sr25519, Pair, Public};

Expand Down Expand Up @@ -158,10 +157,6 @@ fn make_genesis(
})
.collect(),
},
base_fee: BaseFeeConfig::new(
sp_core::U256::from(1_000_000_000),
sp_runtime::Permill::zero(),
),
evm_chain_id: EVMChainIdConfig { chain_id: 0x51 },
ethereum: Default::default(),
polkadot_xcm: Default::default(),
Expand Down
59 changes: 59 additions & 0 deletions pallets/dynamic-evm-base-fee/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
[package]
name = "pallet-dynamic-evm-base-fee"
version = "0.1.0"
license = "GPL-3.0-or-later"
description = "Handler for dynamic EVM base fee for Astar tokenomics v2."
authors.workspace = true
edition.workspace = true
homepage.workspace = true
repository.workspace = true

[dependencies]
parity-scale-codec = { workspace = true }
scale-info = { workspace = true }

# Substrate
frame-benchmarking = { workspace = true, optional = true }
frame-support = { workspace = true }
frame-system = { workspace = true }
pallet-transaction-payment = { workspace = true }
sp-core = { workspace = true }
sp-runtime = { workspace = true }

# Frontier
fp-evm = { workspace = true }

[dev-dependencies]
num-traits = { workspace = true }
pallet-balances = { workspace = true }
pallet-timestamp = { workspace = true }

[features]
default = ["std"]
std = [
"parity-scale-codec/std",
"scale-info/std",
"num-traits/std",
# Substrate
"frame-support/std",
"frame-system/std",
"sp-core/std",
"sp-runtime/std",
"pallet-transaction-payment/std",
"pallet-balances/std",
"pallet-timestamp/std",
"frame-benchmarking/std",
# Frontier
"fp-evm/std",
]
runtime-benchmarks = [
"frame-benchmarking",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]
try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
"pallet-transaction-payment/try-runtime",
]
99 changes: 99 additions & 0 deletions pallets/dynamic-evm-base-fee/src/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// This file is part of Astar.

// Copyright (C) 2019-2023 Stake Technologies Pte.Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later

// Astar is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Astar is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Astar. If not, see <http://www.gnu.org/licenses/>.

use super::*;

use fp_evm::FeeCalculator;
use frame_benchmarking::v2::*;
use frame_support::traits::Hooks;
use frame_system::RawOrigin;

#[benchmarks]
mod benchmarks {
use super::*;

#[benchmark]
fn base_fee_per_gas_adjustment() {
let (first_block, second_block) = (T::BlockNumber::from(1u32), T::BlockNumber::from(2u32));

// Setup actions, should ensure some value is written to storage.
Pallet::<T>::on_initialize(first_block);
Pallet::<T>::on_finalize(first_block);
assert!(
BaseFeePerGas::<T>::exists(),
"Value should exist in storage after first on_finalize call"
);

Pallet::<T>::on_initialize(second_block);
shaunxw marked this conversation as resolved.
Show resolved Hide resolved
let init_bfpg = BaseFeePerGas::<T>::get();

#[block]
{
Pallet::<T>::on_finalize(second_block);
}

// Ensure that the value has changed.
assert!(BaseFeePerGas::<T>::get() != init_bfpg);
}

#[benchmark]
fn set_base_fee_per_gas() {
let old_bfpg = BaseFeePerGas::<T>::get();
let new_bfpg = old_bfpg + 1;

#[extrinsic_call]
_(RawOrigin::Root, new_bfpg);

// Ensure that the value has changed.
assert_eq!(BaseFeePerGas::<T>::get(), new_bfpg);
}

#[benchmark]
fn min_gas_price() {
let first_block = T::BlockNumber::from(1u32);

// Setup actions, should ensure some value is written to storage.
Pallet::<T>::on_initialize(first_block);
Pallet::<T>::on_finalize(first_block);
assert!(
BaseFeePerGas::<T>::exists(),
"Value should exist in storage after first on_finalize call"
);

#[block]
{
let _ = Pallet::<T>::min_gas_price();
}
}

impl_benchmark_test_suite!(
Pallet,
crate::benchmarking::tests::new_test_ext(),
crate::mock::TestRuntime,
);
}

#[cfg(test)]
mod tests {
use crate::mock;
use frame_support::sp_io::TestExternalities;

pub fn new_test_ext() -> TestExternalities {
mock::ExtBuilder::build()
}
}
Loading
Loading