-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Move common implementation to runtime-common
- Loading branch information
Showing
8 changed files
with
122 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,69 @@ | ||
// This file is part of Noir. | ||
|
||
// Copyright (c) Haderech Pte. Ltd. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// This program 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. | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// This program 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. | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
//! Common implementation across Noir runtimes. | ||
|
||
#![cfg_attr(not(feature = "std"), no_std)] | ||
|
||
#[allow(non_upper_case_globals)] | ||
pub mod units { | ||
use noir_core_primitives::{Balance, Moment}; | ||
|
||
/// A unit of base currency. | ||
pub const DOLLARS: Balance = 1_000_000_000_000_000_000; | ||
/// One hundredth of a dollar. | ||
pub const CENTS: Balance = DOLLARS / 100; | ||
|
||
/// Kibibytes. | ||
pub const KiB: u32 = 1024; | ||
/// Mebibytes. | ||
pub const MiB: u32 = 1024 * KiB; | ||
|
||
/// A day in milliseconds. | ||
pub const DAYS: Moment = 24 * HOURS; | ||
/// An hour in milliseconds. | ||
pub const HOURS: Moment = 60 * MINUTES; | ||
/// A minute in milliseconds. | ||
pub const MINUTES: Moment = 60 * SECONDS; | ||
/// A second in milliseconds. | ||
pub const SECONDS: Moment = 1000; | ||
/// A millisecond. | ||
pub const MILLISECONDS: Moment = 1; | ||
pub mod units; | ||
|
||
use crate::units::MiB; | ||
use frame_support::{ | ||
parameter_types, | ||
sp_runtime::{traits::Bounded, FixedPointNumber, Perbill, Perquintill}, | ||
weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight}, | ||
}; | ||
use frame_system::limits; | ||
use pallet_transaction_payment::{Multiplier, TargetedFeeAdjustment}; | ||
use static_assertions::const_assert; | ||
|
||
/// Assumes that 1% of the block weight is used for initialization. | ||
pub const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(1); | ||
/// 75% of the block weight is used for `Normal` extrinsics. | ||
pub const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75); | ||
/// 2 seconds for block computation with 6-second average block time. | ||
pub const MAXIMUM_BLOCK_WEIGHT: Weight = | ||
Weight::from_parts(WEIGHT_REF_TIME_PER_SECOND.saturating_mul(2), u64::MAX); | ||
|
||
const_assert!(NORMAL_DISPATCH_RATIO.deconstruct() >= AVERAGE_ON_INITIALIZE_RATIO.deconstruct()); | ||
|
||
parameter_types! { | ||
/// 4096 block hashes are kept in storage. | ||
pub const BlockHashCount: u32 = 4096; | ||
/// The portion of `NORMAL_DISPATCH_RATIO` for adjusting fees. | ||
pub const TargetBlockFullness: Perquintill = Perquintill::from_percent(25); | ||
/// Adjustment variable that how much the fee should be adjusted. | ||
pub AdjustmentVariable: Multiplier = Multiplier::saturating_from_rational(75, 1000_000); | ||
/// Minimum amount of the multiplier. This value should be high enough to recover from the | ||
/// minimum. | ||
pub MinimumMultiplier: Multiplier = Multiplier::saturating_from_rational(1, 10u128); | ||
/// Maximum amount of the multiplier. | ||
pub MaximumMultiplier: Multiplier = Bounded::max_value(); | ||
/// 5 MiB block size limit. | ||
pub BlockLength: limits::BlockLength = | ||
limits::BlockLength::max_with_normal_ratio(5 * MiB, NORMAL_DISPATCH_RATIO); | ||
} | ||
|
||
/// Parameterized slow adjusting fee updated. | ||
pub type SlowAdjustingFeeUpdate<R> = TargetedFeeAdjustment< | ||
R, | ||
TargetBlockFullness, | ||
AdjustmentVariable, | ||
MinimumMultiplier, | ||
MaximumMultiplier, | ||
>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// This file is part of Noir. | ||
|
||
// Copyright (c) Haderech Pte. Ltd. | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
// This program 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. | ||
// | ||
// This program 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 this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
#![allow(non_upper_case_globals)] | ||
|
||
use noir_core_primitives::{Balance, Moment}; | ||
|
||
/// A unit of base currency. | ||
pub const DOLLARS: Balance = 1_000_000_000_000_000_000; | ||
/// One hundredth of a dollar. | ||
pub const CENTS: Balance = DOLLARS / 100; | ||
|
||
/// Kibibytes. | ||
pub const KiB: u32 = 1024; | ||
/// Mebibytes. | ||
pub const MiB: u32 = 1024 * KiB; | ||
|
||
/// A day in milliseconds. | ||
pub const DAYS: Moment = 24 * HOURS; | ||
/// An hour in milliseconds. | ||
pub const HOURS: Moment = 60 * MINUTES; | ||
/// A minute in milliseconds. | ||
pub const MINUTES: Moment = 60 * SECONDS; | ||
/// A second in milliseconds. | ||
pub const SECONDS: Moment = 1000; | ||
/// A millisecond. | ||
pub const MILLISECONDS: Moment = 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters