Skip to content

Commit

Permalink
Fix/refact (#115)
Browse files Browse the repository at this point in the history
* refact

* fix

* fmt

* release json

* fix
  • Loading branch information
zqhxuyuan authored Aug 2, 2021
1 parent 326b0f8 commit 597e4e6
Show file tree
Hide file tree
Showing 15 changed files with 209 additions and 331 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.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ For now, we only running our own private parachain(collator) node use aura algor
```bash
./jupiter --chain ./jupiter-westend-patract.json --execution wasm --wasm-execution=compiled --force-authoring --parachain-id=2000 --tmp \
--chain ./westend-patract.json --no-beefy --execution wasm --wasm-execution=compiled --tmp \
--bootnodes /dns/ws.patract-westend.patract.cn/tcp/30333/p2p/12D3KooWHfn9r5cLyVQRuLin1wsB3KUiVaMWPnnpFd7Hhff6rhUX
--bootnodes /dns/ws.patract-westend.patract.cn/tcp/30333/p2p/12D3KooWFBrd6SrevJ4vLi3SY7KRYQEVbRSeoENmdDouAW7wGCvZ
```

> Notice, currently we didn't make seed node into westend-patract.json, so you have to specify our private westend bootnode.
Expand Down
6 changes: 3 additions & 3 deletions bin/node-prep/cli/src/chain_spec/jupiter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ pub fn poa_development_config() -> Result<ChainSpec, String> {
// Properties
Some(
json!({
"ss58Format": jupiter_runtime::SS58Prefix::get(),
"ss58Format": jupiter_runtime_common::SS58Prefix::get(),
"tokenDecimals": 10,
"tokenSymbol": "DOT"
})
Expand Down Expand Up @@ -179,7 +179,7 @@ pub fn poa_local_config() -> Result<ChainSpec, String> {
// Properties
Some(
json!({
"ss58Format": jupiter_runtime::SS58Prefix::get(),
"ss58Format": jupiter_runtime_common::SS58Prefix::get(),
"tokenDecimals": 10,
"tokenSymbol": "DOT"
})
Expand Down Expand Up @@ -358,7 +358,7 @@ pub fn poa_staging_config() -> Result<ChainSpec, String> {
// Properties
Some(
json!({
"ss58Format": jupiter_runtime::SS58Prefix::get(),
"ss58Format": jupiter_runtime_common::SS58Prefix::get(),
"tokenDecimals": 10,
"tokenSymbol": "DOT"
})
Expand Down
1 change: 1 addition & 0 deletions bin/node/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ polkadot-parachain = { git = "https://github.com/patractlabs/polkadot", branch =
# Jupiter
jupiter-io = { path = "../../../primitives/io" }
jupiter-primitives = { path = "../../../primitives" }
jupiter-runtime-common = { path = "../../../runtime/common" }
jupiter-rpc = { path = "../../../rpc" }
jupiter-runtime = { path = "../../../runtime/jupiter" }

Expand Down
2 changes: 1 addition & 1 deletion bin/node/cli/res/jupiter-westend-2000-genesis
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0x0000000000000000000000000000000000000000000000000000000000000000006acfbd3b0bc197d7f3c3297ec192adce0962ea1418e422014a811bd7e1e7fde303170a2e7597b7b7e3d84c05391d139a62b157e78786d8c082f29dcf4c11131400
0x000000000000000000000000000000000000000000000000000000000000000000b32a2c0f7322d2d841898ea2c89cca0866df8f200dbef73ac0a57b328fbceb0103170a2e7597b7b7e3d84c05391d139a62b157e78786d8c082f29dcf4c11131400
2 changes: 1 addition & 1 deletion bin/node/cli/res/jupiter-westend-2000-wasm

Large diffs are not rendered by default.

81 changes: 39 additions & 42 deletions bin/node/cli/res/jupiter-westend-patract.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions bin/node/cli/src/chain_spec/jupiter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ pub fn development_config(id: ParaId, relay_chain: &str) -> Result<ChainSpec, St
// Properties
Some(
json!({
"ss58Format": jupiter_runtime::SS58Prefix::get(),
"ss58Format": jupiter_runtime_common::SS58Prefix::get(),
"tokenDecimals": 10,
"tokenSymbol": "DOT"
})
Expand Down Expand Up @@ -164,7 +164,7 @@ pub fn staging_config(id: ParaId) -> Result<ChainSpec, String> {
Some("jupiter_pc1_staging"),
Some(
json!({
"ss58Format": jupiter_runtime::SS58Prefix::get(),
"ss58Format": jupiter_runtime_common::SS58Prefix::get(),
"tokenDecimals": 12,
"tokenSymbol": "WND"
})
Expand Down
98 changes: 19 additions & 79 deletions runtime/common/src/constants.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
//! A set of constant values used in substrate runtime.
/// Time.
pub mod time {
use jupiter_primitives::{BlockNumber, Moment};

pub const MILLISECS_PER_BLOCK: Moment = 6000;
pub const SECS_PER_BLOCK: Moment = MILLISECS_PER_BLOCK / 1000;

pub const SLOT_DURATION: Moment = MILLISECS_PER_BLOCK;
pub const EPOCH_DURATION_IN_BLOCKS: BlockNumber = 1 * HOURS;

// These time units are defined in number of blocks.
pub const MINUTES: BlockNumber = 60 / (SECS_PER_BLOCK as BlockNumber);
pub const HOURS: BlockNumber = MINUTES * 60;
pub const DAYS: BlockNumber = HOURS * 24;

// 1 in 4 blocks (on average, not counting collisions) will be primary babe blocks.
pub const PRIMARY_PROBABILITY: (u64, u64) = (1, 4);
}

/// Money matters.
pub mod jupiter_currency {
use super::jupiter_fee::{Weight2FeeNumerator, WeightToFee};
Expand All @@ -25,58 +44,6 @@ pub mod jupiter_currency {
pub type JupiterWeight2Fee = WeightToFee<JupiterNumerator>;
}

pub mod currency {
use jupiter_primitives::Balance;

/// The existential deposit. Set to 1/10 of its parent Relay Chain.
pub const EXISTENTIAL_DEPOSIT: Balance = 100 * MILLICENTS;

pub const UNITS: Balance = 1_000_000_000_000;
pub const CENTS: Balance = UNITS / 100;
pub const MILLICENTS: Balance = CENTS / 1_000;
pub const GRAND: Balance = CENTS * 100_000;

pub const fn deposit(items: u32, bytes: u32) -> Balance {
// 1/10 of Westend testnet
(items as Balance * 100 * CENTS + (bytes as Balance) * 5 * MILLICENTS) / 10
}
}

/// Time.
pub mod time {
use jupiter_primitives::{BlockNumber, Moment};

pub const MILLISECS_PER_BLOCK: Moment = 6000;
pub const SECS_PER_BLOCK: Moment = MILLISECS_PER_BLOCK / 1000;

pub const SLOT_DURATION: Moment = MILLISECS_PER_BLOCK;
pub const EPOCH_DURATION_IN_BLOCKS: BlockNumber = 1 * HOURS;

// These time units are defined in number of blocks.
pub const MINUTES: BlockNumber = 60 / (SECS_PER_BLOCK as BlockNumber);
pub const HOURS: BlockNumber = MINUTES * 60;
pub const DAYS: BlockNumber = HOURS * 24;

// 1 in 4 blocks (on average, not counting collisions) will be primary babe blocks.
pub const PRIMARY_PROBABILITY: (u64, u64) = (1, 4);
}

/// Common constants
pub mod constants {
use frame_support::weights::{constants::WEIGHT_PER_SECOND, Weight};
use sp_runtime::Perbill;

/// We assume that ~5% of the block weight is consumed by `on_initialize` handlers. This is
/// used to limit the maximal weight of a single extrinsic.
pub const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(5);
/// We allow `Normal` extrinsics to fill up the block up to 75%, the rest can be used by
/// Operational extrinsics.
pub const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);

/// We allow for 0.5 seconds of compute with a 6 second average block time.
pub const MAXIMUM_BLOCK_WEIGHT: Weight = WEIGHT_PER_SECOND / 2;
}

/// Fee-related.
pub mod jupiter_fee {
use frame_support::weights::{
Expand Down Expand Up @@ -120,30 +87,3 @@ pub mod jupiter_fee {
}
}
}

pub mod fee {
use frame_support::weights::{
constants::ExtrinsicBaseWeight, WeightToFeeCoefficient, WeightToFeeCoefficients,
WeightToFeePolynomial,
};
use jupiter_primitives::Balance;
use smallvec::smallvec;
pub use sp_runtime::Perbill;

pub const TARGET_BLOCK_FULLNESS: Perbill = Perbill::from_percent(25);

pub struct WeightToFee;
impl WeightToFeePolynomial for WeightToFee {
type Balance = Balance;
fn polynomial() -> WeightToFeeCoefficients<Self::Balance> {
let p = super::currency::CENTS;
let q = 100 * Balance::from(ExtrinsicBaseWeight::get());
smallvec![WeightToFeeCoefficient {
degree: 1,
negative: false,
coeff_frac: Perbill::from_rational(p % q, q),
coeff_integer: p / q,
}]
}
}
}
6 changes: 1 addition & 5 deletions runtime/common/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,12 @@ use frame_support::{
parameter_types,
traits::{Currency, Imbalance, OnUnbalanced},
};
// use pallet_balances::NegativeImbalance;
use pallet_balances::NegativeImbalance;
use pallet_transaction_payment::{Multiplier, TargetedFeeAdjustment};
use sp_runtime::{FixedPointNumber, Perquintill};

use jupiter_primitives::AccountId;

pub type NegativeImbalance<T> = <pallet_balances::Pallet<T> as Currency<
<T as frame_system::Config>::AccountId,
>>::NegativeImbalance;

pub struct ToAuthor<R>(sp_std::marker::PhantomData<R>);
impl<R> OnUnbalanced<NegativeImbalance<R>> for ToAuthor<R>
where
Expand Down
138 changes: 123 additions & 15 deletions runtime/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pub mod constants;
pub mod impls;
pub mod weights;

use sp_runtime::{FixedPointNumber, Perbill, Perquintill};
use sp_runtime::{transaction_validity::TransactionPriority, Perbill};

pub use frame_support::{
parameter_types,
Expand All @@ -16,9 +16,9 @@ pub use frame_support::{
};
use frame_system::limits;

use pallet_transaction_payment::Multiplier;

use jupiter_primitives::BlockNumber;
use constants::jupiter_currency::*;
use constants::time::*;
use jupiter_primitives::*;

/// We assume that an on-initialize consumes 2.5% of the weight on average, hence a single extrinsic
/// will not be allowed to consume more than `AvailableBlockRatio - 2.5%`.
Expand All @@ -33,22 +33,14 @@ static_assertions::const_assert!(
NORMAL_DISPATCH_RATIO.deconstruct() >= AVERAGE_ON_INITIALIZE_RATIO.deconstruct()
);

// Common constants used in all runtimes.
// frame_system
parameter_types! {
pub const BlockHashCount: BlockNumber = 2400;
/// The portion of the `NORMAL_DISPATCH_RATIO` that we adjust the fees with. Blocks filled less
/// than this will decrease the weight and more will increase.
pub const TargetBlockFullness: Perquintill = Perquintill::from_percent(25);
/// The adjustment variable of the runtime. Higher values will cause `TargetBlockFullness` to
/// change the fees more rapidly.
pub AdjustmentVariable: Multiplier = Multiplier::saturating_from_rational(3, 100_000);
/// Minimum amount of the multiplier. This value cannot be too low. A test case should ensure
/// that combined with `AdjustmentVariable`, we can recover from the minimum.
/// See `multiplier_can_grow_from_zero`.
pub MinimumMultiplier: Multiplier = Multiplier::saturating_from_rational(1, 1_000_000_000u128);

/// Maximum length of block. Up to 5MB.
pub BlockLength: limits::BlockLength =
limits::BlockLength::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO);

/// Block weights base values and limits.
pub BlockWeights: limits::BlockWeights = limits::BlockWeights::builder()
.base_block(BlockExecutionWeight::get())
Expand All @@ -68,6 +60,122 @@ parameter_types! {
})
.avg_block_initialization(AVERAGE_ON_INITIALIZE_RATIO)
.build_or_panic();

pub const SS58Prefix: u8 = 26;
}

// pallet_scheduler
parameter_types! {
pub MaximumSchedulerWeight: Weight = Perbill::from_percent(80) *
BlockWeights::get().max_block;

pub const MaxScheduledPerBlock: u32 = 50;
}

// pallet_authorship
parameter_types! {
pub const UncleGenerations: u32 = 0;
}

// pallet_babe
parameter_types! {
pub const EpochDuration: u64 = EPOCH_DURATION_IN_BLOCKS as u64;
pub const ExpectedBlockTime: Moment = MILLISECS_PER_BLOCK;
}

// pallet_offences
parameter_types! {
pub OffencesWeightSoftLimit: Weight = Perbill::from_percent(60) * BlockWeights::get().max_block;
}

// pallet_im_online
parameter_types! {
pub const ImOnlineUnsignedPriority: TransactionPriority = TransactionPriority::max_value();
}

// pallet_session (Parachain:33)
parameter_types! {
pub const DisabledValidatorsThreshold: Perbill = Perbill::from_percent(17);
pub const Period: u32 = 6 * HOURS;
pub const Offset: u32 = 0;
}

// pallet_democracy
parameter_types! {
pub const LaunchPeriod: BlockNumber = 1 * DAYS;
pub const VotingPeriod: BlockNumber = 1 * DAYS;
pub const FastTrackVotingPeriod: BlockNumber = 3 * HOURS;
pub const MinimumDeposit: Balance = 1 * DOLLARS;
pub const EnactmentPeriod: BlockNumber = 1 * DAYS;
pub const CooloffPeriod: BlockNumber = 1 * DAYS;
// One cent: $10,000 / MB
pub const PreimageByteDeposit: Balance = 1 * CENTS;
pub const InstantAllowed: bool = true;
pub const MaxVotes: u32 = 100;
pub const MaxProposals: u32 = 100;
}

// pallet_collective<CouncilCollective>
parameter_types! {
pub const CouncilMotionDuration: BlockNumber = 3 * DAYS;
pub const CouncilMaxProposals: u32 = 100;
pub const CouncilMaxMembers: u32 = 100;
}

// pallet_collective<TechnicalCollective>
parameter_types! {
pub const TechnicalMotionDuration: BlockNumber = 3 * DAYS;
pub const TechnicalMaxProposals: u32 = 100;
pub const TechnicalMaxMembers: u32 = 100;
}

// pallet_timestamp
parameter_types! {
pub const MinimumPeriod: u64 = SLOT_DURATION / 2;
}

// pallet_indices
parameter_types! {
pub const IndexDeposit: Balance = 1 * DOLLARS;
}

// pallet_balances
parameter_types! {
pub const ExistentialDeposit: Balance = 0;
// For weight estimation, we assume that the most locks on an individual account will be 50.
// This number may need to be adjusted in the future if this assumption no longer holds true.
pub const MaxLocks: u32 = 50;
pub const MaxReserves: u32 = 50;
}

// pallet_transaction_payment (Parachain:1)
parameter_types! {
pub const TransactionByteFee: Balance = 10 * MILLICENTS;
}

// pallet_identity
parameter_types! {
pub const BasicDeposit: Balance = 10 * DOLLARS; // 258 bytes on-chain
pub const FieldDeposit: Balance = 250 * CENTS; // 66 bytes on-chain
pub const SubAccountDeposit: Balance = 2 * DOLLARS; // 53 bytes on-chain
pub const MaxSubAccounts: u32 = 100;
pub const MaxAdditionalFields: u32 = 100;
pub const MaxRegistrars: u32 = 20;
}

// pallet_contracts
parameter_types! {
pub const TombstoneDeposit: Balance = 0;
pub const DepositPerContract: Balance = 0;
pub const DepositPerStorageByte: Balance = TombstoneDeposit::get();
pub const DepositPerStorageItem: Balance = 0;
pub RentFraction: Perbill = Perbill::zero();
pub const SurchargeReward: Balance = 0;
pub const SignedClaimHandicap: u32 = 0;

// The lazy deletion runs inside on_initialize.
pub DeletionWeightLimit: Weight = AVERAGE_ON_INITIALIZE_RATIO *
BlockWeights::get().max_block;
}

parameter_types! {
Expand Down
Loading

0 comments on commit 597e4e6

Please sign in to comment.