Skip to content
Closed
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
3 changes: 1 addition & 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 runtime/moonbase/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ build = "build.rs"
serde = { version = "1.0.101", default-features = false, optional = true, features = ["derive"] }
parity-scale-codec = { version = "2.0.0", default-features = false, features = ["derive"] }
log = "0.4"
smallvec = "1.4.1"

runtime-common = { path = "../common", default-features = false }

Expand Down
57 changes: 47 additions & 10 deletions runtime/moonbase/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,16 @@ use frame_support::{
construct_runtime, parameter_types,
traits::{Filter, Get, Imbalance, InstanceFilter, OnUnbalanced},
weights::{
constants::{RocksDbWeight, WEIGHT_PER_SECOND},
IdentityFee, Weight,
constants::{RocksDbWeight, WEIGHT_PER_SECOND, WEIGHT_PER_MICROS},
WeightToFeeCoefficients, WeightToFeeCoefficient, WeightToFeePolynomial,
DispatchClass, IdentityFee, Weight,
},
PalletId,
};
use frame_system::{EnsureOneOf, EnsureRoot};
use frame_system::{
limits::BlockWeights,
EnsureOneOf, EnsureRoot,
};
pub use moonbeam_core_primitives::{
AccountId, AccountIndex, Address, Balance, BlockNumber, DigestItem, Hash, Header, Index,
Signature,
Expand Down Expand Up @@ -70,6 +74,8 @@ use sp_version::RuntimeVersion;

use nimbus_primitives::{CanAuthor, NimbusId};

use smallvec::smallvec;

mod precompiles;
use precompiles::MoonbasePrecompiles;

Expand All @@ -93,6 +99,7 @@ pub mod currency {

pub const TRANSACTION_BYTE_FEE: Balance = 10 * MICROUNIT;
pub const STORAGE_BYTE_FEE: Balance = 100 * MICROUNIT;
pub const WEIGHT_FEE: Balance = MEGAWEI;

pub const fn deposit(items: u32, bytes: u32) -> Balance {
items as Balance * 1 * UNIT + (bytes as Balance) * STORAGE_BYTE_FEE
Expand Down Expand Up @@ -149,14 +156,30 @@ pub fn native_version() -> NativeVersion {
}

const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);
const NORMAL_WEIGHT: Weight = MAXIMUM_BLOCK_WEIGHT * 3 / 4; // TODO: derive from NORMAL_DISPATCH_RATIO
const EXTRINSIC_BASE_WEIGHT: Weight = 21000 * WEIGHT_PER_GAS;

pub struct RuntimeBlockWeights;
impl Get<BlockWeights> for RuntimeBlockWeights {
fn get() -> BlockWeights {
BlockWeights::builder()
.for_class(DispatchClass::Normal, |weights| {
weights.base_extrinsic = EXTRINSIC_BASE_WEIGHT;
weights.max_total = NORMAL_WEIGHT.into();
})
.for_class(DispatchClass::Operational, |weights| {
weights.max_total = MAXIMUM_BLOCK_WEIGHT.into();
weights.reserved = (MAXIMUM_BLOCK_WEIGHT - NORMAL_WEIGHT).into();
})
.avg_block_initialization(Perbill::from_percent(10))
.build()
.expect("Should work")
}
}

parameter_types! {
pub const BlockHashCount: BlockNumber = 256;
pub const Version: RuntimeVersion = VERSION;
/// We allow for one half second of compute with a 6 second average block time.
/// These values are dictated by Polkadot for the parachain.
pub BlockWeights: frame_system::limits::BlockWeights = frame_system::limits::BlockWeights
::with_sensible_defaults(MAXIMUM_BLOCK_WEIGHT, NORMAL_DISPATCH_RATIO);
/// We allow for 5 MB blocks.
pub BlockLength: frame_system::limits::BlockLength = frame_system::limits::BlockLength
::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO);
Expand Down Expand Up @@ -187,7 +210,7 @@ impl frame_system::Config for Runtime {
/// Maximum number of block number to block hash mappings to keep (oldest pruned first).
type BlockHashCount = BlockHashCount;
/// Maximum weight of each block. With a default weight system of 1byte == 1weight, 4mb is ok.
type BlockWeights = BlockWeights;
type BlockWeights = RuntimeBlockWeights;
/// Maximum size of all encoded transactions (in bytes) that are allowed in one block.
type BlockLength = BlockLength;
/// Runtime version.
Expand Down Expand Up @@ -263,10 +286,24 @@ parameter_types! {
pub const TransactionByteFee: Balance = currency::TRANSACTION_BYTE_FEE;
}

pub struct WeightToFee;
impl WeightToFeePolynomial for WeightToFee {
type Balance = Balance;

fn polynomial() -> WeightToFeeCoefficients<Self::Balance> {
smallvec![WeightToFeeCoefficient {
degree: 1,
coeff_frac: Perbill::zero(),
coeff_integer: currency::WEIGHT_FEE,
negative: false,
}]
}
}

impl pallet_transaction_payment::Config for Runtime {
type OnChargeTransaction = CurrencyAdapter<Balances, DealWithFees<Runtime>>;
type TransactionByteFee = TransactionByteFee;
type WeightToFee = IdentityFee<Balance>;
type WeightToFee = WeightToFee;
type FeeMultiplierUpdate = SlowAdjustingFeeUpdate<Runtime>;
}

Expand Down Expand Up @@ -356,7 +393,7 @@ impl pallet_evm::Config for Runtime {
}

parameter_types! {
pub MaximumSchedulerWeight: Weight = NORMAL_DISPATCH_RATIO * BlockWeights::get().max_block;
pub MaximumSchedulerWeight: Weight = NORMAL_DISPATCH_RATIO * RuntimeBlockWeights::get().max_block;
pub const MaxScheduledPerBlock: u32 = 50;
}

Expand Down