Skip to content

Commit

Permalink
Fix/upgrade setcode (#113)
Browse files Browse the repository at this point in the history
* setcode took too long

* copy westmint runtime and add self def works

* setcode works

* update dependency and json

* update seed

* add version

* runtime fix

* fmt
  • Loading branch information
zqhxuyuan authored Jul 30, 2021
1 parent fd6dcac commit a2f94ef
Show file tree
Hide file tree
Showing 17 changed files with 1,306 additions and 982 deletions.
950 changes: 512 additions & 438 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,12 +265,12 @@ After running relaychain and parachain, upload parachain genenis file to relaych
##### 4.2.2 join Jupiter Parachain testnet
For now, we only running our own private parachain(collator) node use aura algorithm, outside node should running in sync mode.
```bash
./jupiter --chain ./jupiter-westend-098.json --execution wasm --wasm-execution=compiled --force-authoring --parachain-id=2000 --tmp \
--chain ./westend-098.json --no-beefy --execution wasm --wasm-execution=compiled --tmp \
--bootnodes /dns/ws.patract-westend.patract.cn/tcp/30333/p2p/12D3KooWPuxozEWKs7D9Pno7wCd1WtmrEwQnMKQQ9oqZfvzSjmJY
./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/12D3KooW9xfo1rf4i67TAPN3hTXASNvqytVQjAnKeB5SEjmkv1yz
```

> Notice, currently we didn't make seed node into westend-098.json, so you have to specify our private westend bootnode.
> Notice, currently we didn't make seed node into westend-patract.json, so you have to specify our private westend bootnode.
#### 4.3 Jupiter Dev Node
`jupiter-dev` just use for local development, it providers a nice and quick experience for contract developing for developers
Expand Down
65 changes: 0 additions & 65 deletions bin/node/cli/res/jupiter-westend-098.json

This file was deleted.

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 @@
0x000000000000000000000000000000000000000000000000000000000000000000ea369fc5d88d73a80de3b5e9250b2c7185b3a39ff14d624d84b0d0971a97e09903170a2e7597b7b7e3d84c05391d139a62b157e78786d8c082f29dcf4c11131400
0x0000000000000000000000000000000000000000000000000000000000000000004b52f24961080d761b142f1e8d3951bbd6ec36e7f24d3100195dd51fec06530703170a2e7597b7b7e3d84c05391d139a62b157e78786d8c082f29dcf4c11131400
2 changes: 1 addition & 1 deletion bin/node/cli/res/jupiter-westend-2000-wasm

Large diffs are not rendered by default.

80 changes: 80 additions & 0 deletions bin/node/cli/res/jupiter-westend-patract.json

Large diffs are not rendered by default.

191 changes: 0 additions & 191 deletions bin/node/cli/res/westend-098.json

This file was deleted.

191 changes: 191 additions & 0 deletions bin/node/cli/res/westend-patract.json

Large diffs are not rendered by default.

77 changes: 62 additions & 15 deletions bin/node/cli/src/chain_spec/jupiter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ use serde_json::json;
use sc_chain_spec::ChainSpecExtension;
use sc_service::ChainType;
use sp_core::{crypto::UncheckedInto, sr25519, Pair, Public};
use sp_runtime::traits::{IdentifyAccount, Verify};
use sp_runtime::traits::{IdentifyAccount, Verify, Zero};

use cumulus_primitives_core::ParaId;
use jupiter_runtime::{AccountId, AuraId, Signature};
use jupiter_primitives::{AccountId, Signature};
use jupiter_runtime::{
AuraId,
BalancesConfig,
GenesisConfig,
IndicesConfig,
ParachainInfoConfig,
SudoConfig,
SystemConfig, //ContractsConfig,
Expand Down Expand Up @@ -59,6 +59,14 @@ where
AccountPublic::from(get_from_seed::<TPublic>(seed)).into_account()
}

pub fn get_collator_keys_from_seed(seed: &str) -> AuraId {
get_from_seed::<AuraId>(seed)
}

pub fn session_keys(keys: AuraId) -> jupiter_runtime::opaque::SessionKeys {
jupiter_runtime::opaque::SessionKeys { aura: keys }
}

/// Jupiter Development Chain Config
pub fn development_config(id: ParaId, relay_chain: &str) -> Result<ChainSpec, String> {
Ok(ChainSpec::from_genesis(
Expand All @@ -72,8 +80,14 @@ pub fn development_config(id: ParaId, relay_chain: &str) -> Result<ChainSpec, St
// Sudo account
get_account_id_from_seed::<sr25519::Public>("Alice"),
vec![
get_from_seed::<AuraId>("Alice"),
get_from_seed::<AuraId>("Bob"),
(
get_account_id_from_seed::<sr25519::Public>("Alice"),
get_collator_keys_from_seed("Alice"),
),
(
get_account_id_from_seed::<sr25519::Public>("Bob"),
get_collator_keys_from_seed("Bob"),
),
],
// Pre-funded accounts
vec![
Expand Down Expand Up @@ -120,12 +134,21 @@ pub fn staging_config(id: ParaId) -> Result<ChainSpec, String> {
testnet_genesis(
// subkey inspect "$SECRET"
hex!["426d8def6146e8ae997b24f81401e46e8439d7f392489549b10410bcca20b64e"].into(),
// for i in 1 2; do subkey inspect "$SECRET//$i"
// for i in 1 2; do for j in aura; do subkey inspect --scheme Sr25519 "$SECRET//$i//$j"; done; done
vec![
hex!["0a7d580f81d12479b6fd1e27af50cd67a1c95bfee8b9527d56915363d97f4618"]
.unchecked_into(),
hex!["e8780f81d1448511c7fedc40284070042bfc422f7863d1a8291fb15e4ef0f72f"]
.unchecked_into(),
(
hex!["b4ae25a975444e139b44bfe7fcdc4e8389c29687492b6c6958f4250e989cc877"]
.into(),
hex!["0a7d580f81d12479b6fd1e27af50cd67a1c95bfee8b9527d56915363d97f4618"]
.unchecked_into(),
),
(
hex!["964974e3fb8dd02a34baa3381a7a7242e99a5677e807aab940437a22912e0f6b"]
.into(),
hex!["e8780f81d1448511c7fedc40284070042bfc422f7863d1a8291fb15e4ef0f72f"]
.unchecked_into(),
),
],
vec![
hex!["426d8def6146e8ae997b24f81401e46e8439d7f392489549b10410bcca20b64e"].into(),
Expand Down Expand Up @@ -158,13 +181,13 @@ pub fn staging_config(id: ParaId) -> Result<ChainSpec, String> {

/// Jupiter Chain Config
pub fn jupiter_config() -> Result<ChainSpec, String> {
ChainSpec::from_json_bytes(&include_bytes!("../../res/jupiter-westend-098.json")[..])
ChainSpec::from_json_bytes(&include_bytes!("../../res/jupiter-westend-patract.json")[..])
}

/// Configure initial storage state for FRAME modules.
fn testnet_genesis(
root_key: AccountId,
initial_authorities: Vec<AuraId>,
initial_authorities: Vec<(AccountId, AuraId)>,
endowed_accounts: Vec<AccountId>,
id: ParaId,
) -> GenesisConfig {
Expand All @@ -181,18 +204,42 @@ fn testnet_genesis(
balances: endowed_accounts
.iter()
.cloned()
.map(|k| (k, 1 << 60))
.map(|k| (k, 1 << 100))
.collect(),
},
indices: IndicesConfig { indices: vec![] },
// indices: IndicesConfig { indices: vec![] },
sudo: SudoConfig {
// Assign network admin rights.
key: root_key,
},
parachain_info: ParachainInfoConfig { parachain_id: id },
aura: jupiter_runtime::AuraConfig {
authorities: initial_authorities,
collator_selection: jupiter_runtime::CollatorSelectionConfig {
invulnerables: initial_authorities
.iter()
.cloned()
.map(|(acc, _)| acc)
.collect(),
candidacy_bond: Zero::zero(),
..Default::default()
},
session: jupiter_runtime::SessionConfig {
keys: initial_authorities
.iter()
.cloned()
.map(|(acc, aura)| {
(
acc.clone(), // account id
acc.clone(), // validator id
session_keys(aura), // session keys
)
})
.collect(),
},
aura: Default::default(),
// aura: jupiter_runtime::AuraConfig {
// authorities: initial_authorities,
// },
aura_ext: Default::default(),
parachain_system: Default::default(),
}
}
3 changes: 2 additions & 1 deletion bin/node/cli/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ use sc_service::{
};

use jupiter_primitives::Block;
use jupiter_runtime::{self, RpcPort, RuntimeApi, OCW_DB_RANDOM};
use jupiter_runtime::{self, RuntimeApi};
use jupiter_runtime::{RpcPort, OCW_DB_RANDOM};

use codec::Encode;
use cumulus_client_consensus_aura::SlotProportion;
Expand Down
2 changes: 2 additions & 0 deletions runtime/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pallet-treasury = { version = "3.0.0", git = "https://github.com/paritytech/subs
pallet-bounties = { version = "3.0.0", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false }
pallet-tips = { version = "3.0.0", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false }
pallet-utility = { version = "3.0.0", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false }
pallet-collator-selection = { version = "3.0.0", git = "https://github.com/patractlabs/cumulus", branch = "patract-sandbox-098", default-features = false }

jupiter-primitives = { path = "../../primitives", default-features = false }

Expand Down Expand Up @@ -62,6 +63,7 @@ std = [
"pallet-bounties/std",
"pallet-tips/std",
"pallet-utility/std",
"pallet-collator-selection/std",

"jupiter-primitives/std",
]
Expand Down
64 changes: 62 additions & 2 deletions runtime/common/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/// Money matters.
pub mod jupiter_currency {
use super::fee::{Weight2FeeNumerator, WeightToFee};
use super::jupiter_fee::{Weight2FeeNumerator, WeightToFee};
use jupiter_primitives::Balance;

pub const DOTS: Balance = 1_000_000_000_000; // old dot, one Dot is 100 Dot(new) now
Expand All @@ -25,6 +25,23 @@ 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};
Expand All @@ -44,8 +61,24 @@ pub mod time {
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 fee {
pub mod jupiter_fee {
use frame_support::weights::{
constants::ExtrinsicBaseWeight, WeightToFeeCoefficient, WeightToFeeCoefficients,
WeightToFeePolynomial,
Expand Down Expand Up @@ -87,3 +120,30 @@ pub mod 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,
}]
}
}
}
46 changes: 44 additions & 2 deletions runtime/common/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ 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 struct ToAuthor<R>(sp_std::marker::PhantomData<R>);
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
R: pallet_balances::Config + pallet_authorship::Config,
Expand All @@ -31,6 +34,44 @@ where
}
}

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

pub struct DealWithFees<R>(sp_std::marker::PhantomData<R>);
impl<R> OnUnbalanced<NegativeImbalance<R>> for DealWithFees<R>
where
R: pallet_balances::Config + pallet_collator_selection::Config,
<R as frame_system::Config>::AccountId: From<AccountId>,
<R as frame_system::Config>::AccountId: Into<AccountId>,
<R as frame_system::Config>::Event: From<pallet_balances::Event<R>>,
{
fn on_unbalanceds<B>(mut fees_then_tips: impl Iterator<Item = NegativeImbalance<R>>) {
if let Some(mut fees) = fees_then_tips.next() {
if let Some(tips) = fees_then_tips.next() {
tips.merge_into(&mut fees);
}
<ToStakingPot<R> as OnUnbalanced<_>>::on_unbalanced(fees);
}
}
}

parameter_types! {
/// The portion of the `AvailableBlockRatio` that we adjust the fees with. Blocks filled less
/// than this will decrease the weight and more will increase.
Expand All @@ -43,6 +84,7 @@ parameter_types! {
/// See `multiplier_can_grow_from_zero`.
pub MinimumMultiplier: Multiplier = Multiplier::saturating_from_rational(1, 1_000_000_000u128);
}

/// Parameterized slow adjusting fee updated based on
/// https://w3f-research.readthedocs.io/en/latest/polkadot/Token%20Economics.html#-2.-slow-adjusting-mechanism
pub type SlowAdjustingFeeUpdate<R> =
Expand Down
1 change: 1 addition & 0 deletions runtime/common/src/weights/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
pub mod frame_system;
pub mod pallet_balances;
pub mod pallet_bounties;
pub mod pallet_collator_selection;
pub mod pallet_collective;
pub mod pallet_democracy;
pub mod pallet_identity;
Expand Down
Loading

0 comments on commit a2f94ef

Please sign in to comment.