Skip to content
This repository has been archived by the owner on Mar 13, 2023. It is now read-only.

Commit

Permalink
Reset Pangolin/Pangoro (#959)
Browse files Browse the repository at this point in the history
* Adjust  `SS58Prefix`

* Refine Constants

* Sync Params with Darwinia/Crab

* Fix Global Replace Issues

* Update Rust Edition

* Update `BlockHashCount`

* Adjust Session Era Length

* Format
  • Loading branch information
AurevoirXavier authored Nov 29, 2021
1 parent b2dce1a commit 6b3493c
Show file tree
Hide file tree
Showing 50 changed files with 636 additions and 666 deletions.
67 changes: 23 additions & 44 deletions Cargo.lock

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

5 changes: 1 addition & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@ members = [
"node/primitives/common",
"node/primitives/bridge",
"node/rpc",
"node/runtime/common",
"node/runtime/pangolin",
"node/runtime/pangolin/src/constants",
"node/runtime/pangolin/src/pallets/system/params",
"node/runtime/pangoro",
"node/runtime/pangoro/src/constants",
"node/runtime/pangoro/src/pallets/system/params",
"node/service",
"client/dvm/db",
"client/dvm/mapping-sync",
Expand Down
50 changes: 50 additions & 0 deletions node/primitives/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,53 @@ pub type Header = generic::Header<BlockNumber, Hashing>;

/// Block type.
pub type OpaqueBlock = generic::Block<Header, OpaqueExtrinsic>;

/// 1 in u128.
pub const NANO: Balance = 1;
/// 1_000 in u128.
pub const MICRO: Balance = 1_000 * NANO;
/// 1_000_000 in u128.
pub const MILLI: Balance = 1_000 * MICRO;
/// 1_000_000_000 in u128.
pub const COIN: Balance = 1_000 * MILLI;

/// GWEI for DVM.
pub const GWEI: Balance = 1_000_000_000;

/// The hard cap of RING.
pub const RING_HARD_CAP: Balance = 10_000_000_000 * COIN;
/// The amount of total power.
pub const TOTAL_POWER: Power = 1_000_000_000;

/// Deposit calculator for Pangoro.
pub const fn pangoro_deposit(items: u32, bytes: u32) -> Balance {
items as Balance * 20 * MILLI + (bytes as Balance) * 100 * NANO
}
/// Deposit calculator for Pangolin.
pub const fn pangolin_deposit(items: u32, bytes: u32) -> Balance {
items as Balance * 20 * COIN + (bytes as Balance) * 100 * MICRO
}

/// Block time of Pangoro/Pangolin.
pub const MILLISECS_PER_BLOCK: Moment = 6000;

/// Minute in Pangoro/Pangolin.
pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber);
/// Hour in Pangoro/Pangolin.
pub const HOURS: BlockNumber = 60 * MINUTES;
/// Day in Pangoro/Pangolin.
pub const DAYS: BlockNumber = 24 * HOURS;
/// Slot duration in Pangoro/Pangolin.
pub const SLOT_DURATION: Moment = MILLISECS_PER_BLOCK;

/// Session length of Pangolin.
pub const PANGOLIN_BLOCKS_PER_SESSION: BlockNumber = 30 * MINUTES;
/// Era length of Pangolin.
pub const PANGOLIN_SESSIONS_PER_ERA: BlockNumber = 3;
/// Session length of Pangoro.
pub const PANGORO_BLOCKS_PER_SESSION: BlockNumber = 2 * HOURS;
/// Era length of Pangoro.
pub const PANGORO_SESSIONS_PER_ERA: BlockNumber = 3;

/// 1 in 4 blocks (on average, not counting collisions) will be primary BABE blocks.
pub const PRIMARY_PROBABILITY: (u64, u64) = (1, 4);
51 changes: 51 additions & 0 deletions node/runtime/common/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
[package]
authors = ["Darwinia Network <[email protected]>"]
description = "DRML node common runtime"
edition = "2021"
homepage = "https://darwinia.network"
license = "GPL-3.0"
name = "common-runtime"
repository = "https://github.com/darwinia-network/darwinia-common"
version = "2.7.0"

[dependencies]
# crates.io
codec = { package = "parity-scale-codec", version = "2.1", default-features = false }
static_assertions = { version = "1.1" }
# darwinia-network
common-primitives = { default-features = false, path = "../../primitives/common" }
darwinia-balances = { default-features = false, path = "../../../frame/balances" }
darwinia-support = { default-features = false, path = "../../../frame/support" }
# paritytech
frame-support = { default-features = false, git = "https://github.com/darwinia-network/substrate", tag = "darwinia-v0.11.6-1" }
frame-system = { default-features = false, git = "https://github.com/darwinia-network/substrate", tag = "darwinia-v0.11.6-1" }
pallet-authorship = { default-features = false, git = "https://github.com/darwinia-network/substrate", tag = "darwinia-v0.11.6-1" }
pallet-transaction-payment = { default-features = false, git = "https://github.com/darwinia-network/substrate", tag = "darwinia-v0.11.6-1" }
pallet-treasury = { default-features = false, git = "https://github.com/darwinia-network/substrate", tag = "darwinia-v0.11.6-1" }
sp-runtime = { default-features = false, git = "https://github.com/darwinia-network/substrate", tag = "darwinia-v0.11.6-1" }
sp-std = { default-features = false, git = "https://github.com/darwinia-network/substrate", tag = "darwinia-v0.11.6-1" }

# will be removed in later substrate version
max-encoded-len = { default-features = false, git = "https://github.com/darwinia-network/substrate", tag = "darwinia-v0.11.6-1" }

[features]
default = ["std"]

no_std = []
std = [
# crates.io
"codec/std",
# darwinia-network
"common-primitives/std",
"darwinia-balances/std",
"darwinia-support/std",
# paritytech
"frame-support/std",
"frame-system/std",
"pallet-authorship/std",
"pallet-transaction-payment/std",
"pallet-treasury/std",
"sp-runtime/std",
"sp-std/std",
"max-encoded-len/std",
]
88 changes: 88 additions & 0 deletions node/runtime/common/src/impls.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// This file is part of Darwinia.
//
// Copyright (C) 2018-2021 Darwinia Network
// SPDX-License-Identifier: GPL-3.0
//
// Darwinia 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.
//
// Darwinia 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 Darwinia. If not, see <https://www.gnu.org/licenses/>.

//! Auxillary struct/enums for Darwinia runtime.

// --- crates.io ---
use codec::{Decode, Encode};
// --- paritytech ---
use frame_support::traits::{Currency, Imbalance, MaxEncodedLen, OnUnbalanced};
use sp_runtime::RuntimeDebug;
// --- darwinia-network ---
use crate::*;

darwinia_support::impl_account_data! {
struct AccountData<Balance>
for
RingInstance,
KtonInstance
where
Balance = common_primitives::Balance
{
// other data
}
}

/// Logic for the author to get a portion of fees.
pub struct ToAuthor<R>(sp_std::marker::PhantomData<R>);
impl<R> OnUnbalanced<NegativeImbalance<R>> for ToAuthor<R>
where
R: darwinia_balances::Config<RingInstance> + pallet_authorship::Config,
<R as frame_system::Config>::AccountId: From<common_primitives::AccountId>,
<R as frame_system::Config>::AccountId: Into<common_primitives::AccountId>,
<R as frame_system::Config>::Event: From<darwinia_balances::Event<R, RingInstance>>,
{
fn on_nonzero_unbalanced(amount: NegativeImbalance<R>) {
let numeric_amount = amount.peek();
let author = <pallet_authorship::Pallet<R>>::author();
<darwinia_balances::Pallet<R, RingInstance>>::resolve_creating(
&<pallet_authorship::Pallet<R>>::author(),
amount,
);
<frame_system::Pallet<R>>::deposit_event(darwinia_balances::Event::Deposit(
author,
numeric_amount,
));
}
}

pub struct DealWithFees<R>(sp_std::marker::PhantomData<R>);
impl<R> OnUnbalanced<NegativeImbalance<R>> for DealWithFees<R>
where
R: darwinia_balances::Config<RingInstance>
+ pallet_treasury::Config
+ pallet_authorship::Config,
pallet_treasury::Pallet<R>: OnUnbalanced<NegativeImbalance<R>>,
<R as frame_system::Config>::AccountId: From<common_primitives::AccountId>,
<R as frame_system::Config>::AccountId: Into<common_primitives::AccountId>,
<R as frame_system::Config>::Event: From<darwinia_balances::Event<R, RingInstance>>,
{
fn on_unbalanceds<B>(mut fees_then_tips: impl Iterator<Item = NegativeImbalance<R>>) {
if let Some(fees) = fees_then_tips.next() {
// for fees, 80% to treasury, 20% to author
let mut split = fees.ration(80, 20);
if let Some(tips) = fees_then_tips.next() {
// for tips, if any, 100% to author
tips.merge_into(&mut split.1);
}
use pallet_treasury::Pallet as Treasury;
<Treasury<R> as OnUnbalanced<_>>::on_unbalanced(split.0);
<ToAuthor<R> as OnUnbalanced<_>>::on_unbalanced(split.1);
}
}
}
Loading

0 comments on commit 6b3493c

Please sign in to comment.