Skip to content

Commit

Permalink
Shiden fee alignment (#1071)
Browse files Browse the repository at this point in the history
* Shiden Fee Alignment

* Missed updates

* Self-review fixes
  • Loading branch information
Dinonard authored Oct 31, 2023
1 parent 462f2a2 commit 34dc2a9
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 118 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions bin/collator/src/parachain/chain_spec/shiden.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
use cumulus_primitives_core::ParaId;
use sc_service::ChainType;
use shiden_runtime::{
wasm_binary_unwrap, AccountId, AuraId, Balance, BaseFeeConfig, BlockRewardConfig, EVMConfig,
wasm_binary_unwrap, AccountId, AuraId, Balance, BlockRewardConfig, EVMConfig,
ParachainInfoConfig, Precompiles, Signature, SystemConfig, SDN,
};
use sp_core::{sr25519, Pair, Public};
Expand Down Expand Up @@ -156,10 +156,6 @@ fn make_genesis(
})
.collect(),
},
base_fee: BaseFeeConfig::new(
sp_core::U256::from(1_000_000_000),
sp_runtime::Permill::zero(),
),
ethereum: Default::default(),
polkadot_xcm: Default::default(),
assets: Default::default(),
Expand Down
63 changes: 8 additions & 55 deletions runtime/shibuya/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ impl pallet_contracts::Config for Runtime {
// These values are based on the Astar 2.0 Tokenomics Modeling report.
parameter_types! {
pub const TransactionLengthFeeFactor: Balance = 23_500_000_000_000; // 0.000_023_500_000_000_000 SBY per byte
pub const WeightFeeFactor: Balance = 30_855_000_000_000_000; // Around 0.03 SBY per unit of ref time.
pub const WeightFeeFactor: Balance = 30_855_000_000_000_000; // Around 0.03 SBY per unit of base weight.
pub const TargetBlockFullness: Perquintill = Perquintill::from_percent(25);
pub const OperationalFeeMultiplier: u8 = 5;
pub AdjustmentVariable: Multiplier = Multiplier::saturating_from_rational(1, 666_667); // 0.000_015
Expand Down Expand Up @@ -718,17 +718,17 @@ pub struct DealWithFees;
impl OnUnbalanced<NegativeImbalance> for DealWithFees {
fn on_unbalanceds<B>(mut fees_then_tips: impl Iterator<Item = NegativeImbalance>) {
if let Some(fees) = fees_then_tips.next() {
// Burn 80% of fees, rest goes to collators, including 100% of the tips.
let (to_burn, mut collators) = fees.ration(80, 20);
// Burn 80% of fees, rest goes to collator, including 100% of the tips.
let (to_burn, mut collator) = fees.ration(80, 20);
if let Some(tips) = fees_then_tips.next() {
tips.merge_into(&mut collators);
tips.merge_into(&mut collator);
}

// burn part of fees
// burn part of the fees
drop(to_burn);

// pay fees to collators
<ToStakingPot as OnUnbalanced<_>>::on_unbalanced(collators);
// pay fees to collator
<ToStakingPot as OnUnbalanced<_>>::on_unbalanced(collator);
}
}
}
Expand Down Expand Up @@ -1311,57 +1311,10 @@ pub type Executive = frame_executive::Executive<
Migrations,
>;

// Used to cleanup BaseFee storage - remove once cleanup is done.
parameter_types! {
pub const BaseFeeStr: &'static str = "BaseFee";
}

/// Simple `OnRuntimeUpgrade` logic to prepare Shibuya runtime for `DynamicEvmBaseFee` pallet.
pub use frame_support::traits::{OnRuntimeUpgrade, StorageVersion};
pub struct DynamicEvmBaseFeeMigration;
impl OnRuntimeUpgrade for DynamicEvmBaseFeeMigration {
fn on_runtime_upgrade() -> Weight {
// Safety check to ensure we don't execute this migration twice
if pallet_dynamic_evm_base_fee::BaseFeePerGas::<Runtime>::exists() {
return <Runtime as frame_system::Config>::DbWeight::get().reads(1);
}

// Set the init value to what was set before on the old `BaseFee` pallet.
pallet_dynamic_evm_base_fee::BaseFeePerGas::<Runtime>::put(U256::from(1_000_000_000_u128));

// Shibuya's multiplier is so low that we have to set it to minimum value directly.
pallet_transaction_payment::NextFeeMultiplier::<Runtime>::put(MinimumMultiplier::get());

// Set init storage version for the pallet
StorageVersion::new(1).put::<pallet_dynamic_evm_base_fee::Pallet<Runtime>>();

<Runtime as frame_system::Config>::DbWeight::get().reads_writes(1, 3)
}
}

/// Simple `OnRuntimeUpgrade` logic to remove all corrupted mappings
/// after the fixing the typo in mapping names in pallet.
pub struct ClearCorruptedUnifiedMappings;
impl OnRuntimeUpgrade for ClearCorruptedUnifiedMappings {
fn on_runtime_upgrade() -> Weight {
let maybe_limit = pallet_unified_accounts::EvmToNative::<Runtime>::iter().count();
let total_rw = maybe_limit as u64 * 2;
// remove all items
let _ = pallet_unified_accounts::EvmToNative::<Runtime>::clear(maybe_limit as u32, None);
let _ = pallet_unified_accounts::NativeToEvm::<Runtime>::clear(maybe_limit as u32, None);

<Runtime as frame_system::Config>::DbWeight::get().reads_writes(total_rw, total_rw)
}
}

/// All migrations that will run on the next runtime upgrade.
///
/// Once done, migrations should be removed from the tuple.
pub type Migrations = (
frame_support::migrations::RemovePallet<BaseFeeStr, RocksDbWeight>,
DynamicEvmBaseFeeMigration,
ClearCorruptedUnifiedMappings,
);
pub type Migrations = ();

type EventRecord = frame_system::EventRecord<
<Runtime as frame_system::Config>::RuntimeEvent,
Expand Down
7 changes: 4 additions & 3 deletions runtime/shiden/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ pallet-assets = { workspace = true }
pallet-aura = { workspace = true }
pallet-authorship = { workspace = true }
pallet-balances = { workspace = true }
pallet-base-fee = { workspace = true }
pallet-contracts = { workspace = true }
pallet-contracts-primitives = { workspace = true }
pallet-dynamic-evm-base-fee = { workspace = true }
pallet-ethereum = { workspace = true }
pallet-evm = { workspace = true }
pallet-evm-precompile-blake2 = { workspace = true }
Expand Down Expand Up @@ -147,7 +147,7 @@ std = [
"pallet-contracts/std",
"pallet-contracts-primitives/std",
"pallet-block-reward/std",
"pallet-base-fee/std",
"pallet-dynamic-evm-base-fee/std",
"pallet-ethereum/std",
"pallet-evm/std",
"pallet-evm-precompile-blake2/std",
Expand Down Expand Up @@ -222,6 +222,7 @@ runtime-benchmarks = [
"pallet-collator-selection/runtime-benchmarks",
"astar-primitives/runtime-benchmarks",
"pallet-assets/runtime-benchmarks",
"pallet-dynamic-evm-base-fee/runtime-benchmarks",
]
try-runtime = [
"fp-self-contained/try-runtime",
Expand Down Expand Up @@ -257,7 +258,7 @@ try-runtime = [
"cumulus-pallet-xcm/try-runtime",
"cumulus-pallet-xcmp-queue/try-runtime",
"parachain-info/try-runtime",
"pallet-base-fee/try-runtime",
"pallet-dynamic-evm-base-fee/try-runtime",
"pallet-evm/try-runtime",
"orml-xtokens/try-runtime",
]
Expand Down
Loading

0 comments on commit 34dc2a9

Please sign in to comment.