Commit 27d986ea authored by Éloïs's avatar Éloïs
Browse files

chore: split into 3 runtimes: gdev, gtest and g1

parent 1e263062
......@@ -162,6 +162,12 @@ version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9d6e24d2cce90c53b948c46271bfb053e4bdc2db9b5d3f65e20f8cf28a1b7fc3"
[[package]]
name = "assert_matches"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b34d609dfbaf33d6889b2b7106d3ca345eacad44200913df5ba02bfd31d2ba9"
[[package]]
name = "async-channel"
version = "1.6.1"
......@@ -807,6 +813,24 @@ dependencies = [
"bitflags",
]
[[package]]
name = "common-runtime"
version = "0.8.0-dev"
dependencies = [
"frame-support",
"frame-system",
"pallet-certification",
"pallet-identity",
"pallet-ud-accounts-storage",
"parity-scale-codec",
"serde",
"smallvec 1.6.1",
"sp-arithmetic",
"sp-core",
"sp-runtime",
"sp-std",
]
[[package]]
name = "concurrent-queue"
version = "1.2.2"
......@@ -1892,12 +1916,94 @@ dependencies = [
"slab",
]
[[package]]
name = "g1-runtime"
version = "3.0.0"
dependencies = [
"common-runtime",
"frame-benchmarking",
"frame-executive",
"frame-support",
"frame-system",
"frame-system-benchmarking",
"frame-system-rpc-runtime-api",
"hex-literal",
"pallet-aura",
"pallet-balances",
"pallet-certification",
"pallet-grandpa",
"pallet-identity",
"pallet-randomness-collective-flip",
"pallet-sudo",
"pallet-timestamp",
"pallet-transaction-payment",
"pallet-transaction-payment-rpc-runtime-api",
"pallet-ud-accounts-storage",
"pallet-universal-dividend",
"parity-scale-codec",
"serde",
"smallvec 1.6.1",
"sp-api",
"sp-arithmetic",
"sp-block-builder",
"sp-consensus-aura",
"sp-core",
"sp-inherents",
"sp-offchain",
"sp-runtime",
"sp-session",
"sp-std",
"sp-transaction-pool",
"sp-version",
"substrate-wasm-builder",
]
[[package]]
name = "gcc"
version = "0.3.55"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f5f3913fa0bfe7ee1fd8248b6b9f42a5af4b9d65ec2dd2c3c26132b950ecfc2"
[[package]]
name = "gdev-runtime"
version = "3.0.0"
dependencies = [
"common-runtime",
"frame-benchmarking",
"frame-executive",
"frame-support",
"frame-system",
"frame-system-benchmarking",
"frame-system-rpc-runtime-api",
"hex-literal",
"pallet-aura",
"pallet-balances",
"pallet-certification",
"pallet-grandpa",
"pallet-identity",
"pallet-randomness-collective-flip",
"pallet-sudo",
"pallet-transaction-payment",
"pallet-transaction-payment-rpc-runtime-api",
"pallet-ud-accounts-storage",
"pallet-universal-dividend",
"parity-scale-codec",
"serde",
"sp-api",
"sp-arithmetic",
"sp-block-builder",
"sp-consensus-aura",
"sp-core",
"sp-inherents",
"sp-offchain",
"sp-runtime",
"sp-session",
"sp-std",
"sp-transaction-pool",
"sp-version",
"substrate-wasm-builder",
]
[[package]]
name = "generic-array"
version = "0.12.4"
......@@ -1992,6 +2098,48 @@ dependencies = [
"web-sys",
]
[[package]]
name = "gtest-runtime"
version = "3.0.0"
dependencies = [
"common-runtime",
"frame-benchmarking",
"frame-executive",
"frame-support",
"frame-system",
"frame-system-benchmarking",
"frame-system-rpc-runtime-api",
"hex-literal",
"pallet-aura",
"pallet-balances",
"pallet-certification",
"pallet-grandpa",
"pallet-identity",
"pallet-randomness-collective-flip",
"pallet-sudo",
"pallet-timestamp",
"pallet-transaction-payment",
"pallet-transaction-payment-rpc-runtime-api",
"pallet-ud-accounts-storage",
"pallet-universal-dividend",
"parity-scale-codec",
"serde",
"smallvec 1.6.1",
"sp-api",
"sp-arithmetic",
"sp-block-builder",
"sp-consensus-aura",
"sp-core",
"sp-inherents",
"sp-offchain",
"sp-runtime",
"sp-session",
"sp-std",
"sp-transaction-pool",
"sp-version",
"substrate-wasm-builder",
]
[[package]]
name = "h2"
version = "0.1.26"
......@@ -2693,17 +2841,27 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
name = "lc-core"
version = "3.0.0"
dependencies = [
"async-io",
"common-runtime",
"frame-benchmarking",
"frame-benchmarking-cli",
"futures 0.3.15",
"g1-runtime",
"gdev-runtime",
"gtest-runtime",
"jsonrpc-core",
"lc-core-runtime",
"log",
"maplit",
"pallet-grandpa",
"pallet-transaction-payment-rpc",
"pallet-transaction-payment-rpc-runtime-api",
"sc-basic-authorship",
"sc-chain-spec",
"sc-cli",
"sc-client-api",
"sc-consensus",
"sc-consensus-aura",
"sc-consensus-manual-seal",
"sc-executor",
"sc-finality-grandpa",
"sc-keystore",
......@@ -2721,55 +2879,18 @@ dependencies = [
"sp-core",
"sp-finality-grandpa",
"sp-inherents",
"sp-offchain",
"sp-runtime",
"sp-session",
"sp-storage",
"sp-timestamp",
"sp-transaction-pool",
"sp-trie",
"structopt",
"substrate-build-script-utils",
"substrate-frame-rpc-system",
]
[[package]]
name = "lc-core-runtime"
version = "3.0.0"
dependencies = [
"frame-benchmarking",
"frame-executive",
"frame-support",
"frame-system",
"frame-system-benchmarking",
"frame-system-rpc-runtime-api",
"hex-literal",
"pallet-aura",
"pallet-balances",
"pallet-certification",
"pallet-grandpa",
"pallet-identity",
"pallet-randomness-collective-flip",
"pallet-sudo",
"pallet-timestamp",
"pallet-transaction-payment",
"pallet-transaction-payment-rpc-runtime-api",
"pallet-ud-accounts-storage",
"pallet-universal-dividend",
"parity-scale-codec",
"serde",
"smallvec 1.6.1",
"sp-api",
"sp-arithmetic",
"sp-block-builder",
"sp-consensus-aura",
"sp-core",
"sp-inherents",
"sp-offchain",
"sp-runtime",
"sp-session",
"sp-std",
"sp-transaction-pool",
"sp-version",
"substrate-wasm-builder",
]
[[package]]
name = "leb128"
version = "0.2.4"
......@@ -5475,6 +5596,41 @@ dependencies = [
"sp-runtime",
]
[[package]]
name = "sc-consensus-manual-seal"
version = "0.9.0"
source = "git+https://github.com/paritytech/substrate.git?tag=monthly-2021-07#83808aa815a9fbc528b76cd25ae1dec57e269771"
dependencies = [
"assert_matches",
"async-trait",
"derive_more",
"futures 0.3.15",
"jsonrpc-core",
"jsonrpc-core-client",
"jsonrpc-derive",
"log",
"parity-scale-codec",
"parking_lot 0.11.1",
"sc-client-api",
"sc-consensus-babe",
"sc-consensus-epochs",
"sc-transaction-pool",
"serde",
"sp-api",
"sp-blockchain",
"sp-consensus",
"sp-consensus-babe",
"sp-consensus-slots",
"sp-core",
"sp-inherents",
"sp-keyring",
"sp-keystore",
"sp-runtime",
"sp-timestamp",
"sp-transaction-pool",
"substrate-prometheus-endpoint",
]
[[package]]
name = "sc-consensus-slots"
version = "0.9.0"
......
......@@ -5,7 +5,9 @@ members = [
'pallets/identity',
'pallets/ud-accounts-storage',
'pallets/universal-dividend',
'runtime',
'runtime/common',
'runtime/gdev',
'runtime/gtest'
]
[profile.dev]
opt-level = 3
......
[features]
default = []
runtime-benchmarks = ['lc-core-runtime/runtime-benchmarks']
runtime-benchmarks = ['gdev-runtime/runtime-benchmarks']
[build-dependencies.substrate-build-script-utils]
git = 'https://github.com/paritytech/substrate.git'
......@@ -8,7 +7,7 @@ tag = 'monthly-2021-07'
version = '3.0.0'
[package]
authors = ['Substrate DevHub <https://github.com/substrate-developer-hub>']
authors = ['Axiom-Team Developers <https://axiom-team.fr>']
build = 'build.rs'
description = 'A fresh FRAME-based Substrate node, ready for hacking.'
edition = '2018'
......@@ -17,11 +16,20 @@ license = 'AGPL-3.0'
name = 'lc-core'
repository = 'https://git.duniter.org/nodes/rust/lc-core-substrate'
version = '3.0.0'
[package.metadata.docs.rs]
targets = ['x86_64-unknown-linux-gnu']
[dependencies]
async-io = "1.3"
futures = { version = "0.3.1", features = ["compat"] }
jsonrpc-core = '15.1.0'
log = "0.4"
maplit = '1.0.2'
common-runtime = { path = '../runtime/common' }
g1-runtime = { path = '../runtime/g1' }
gdev-runtime = { path = '../runtime/gdev' }
gtest-runtime = { path = '../runtime/gtest' }
structopt = '0.3.8'
[dependencies.frame-benchmarking]
......@@ -34,23 +42,32 @@ git = 'https://github.com/paritytech/substrate.git'
tag = 'monthly-2021-07'
version = '3.0.0'
[dependencies.lc-core-runtime]
path = '../runtime'
[dependencies.pallet-grandpa]
git = 'https://github.com/paritytech/substrate.git'
tag = 'monthly-2021-07'
version = '3.0.0'
[dependencies.maplit]
version = "1.0.2"
[dependencies.pallet-transaction-payment-rpc]
git = 'https://github.com/paritytech/substrate.git'
tag = 'monthly-2021-07'
version = '3.0.0'
[dependencies.pallet-transaction-payment-rpc-runtime-api]
default-features = false
git = 'https://github.com/paritytech/substrate.git'
tag = 'monthly-2021-07'
version = '3.0.0'
[dependencies.sc-basic-authorship]
git = 'https://github.com/paritytech/substrate.git'
tag = 'monthly-2021-07'
version = '0.9.0'
[dependencies.sc-chain-spec]
git = 'https://github.com/paritytech/substrate.git'
tag = 'monthly-2021-07'
version = '3.0.0'
[dependencies.sc-cli]
features = ['wasmtime']
git = 'https://github.com/paritytech/substrate.git'
......@@ -72,6 +89,11 @@ git = 'https://github.com/paritytech/substrate.git'
tag = 'monthly-2021-07'
version = '0.9.0'
[dependencies.sc-consensus-manual-seal]
git = 'https://github.com/paritytech/substrate.git'
tag = 'monthly-2021-07'
version = '0.9.0'
[dependencies.sc-executor]
features = ['wasmtime']
git = 'https://github.com/paritytech/substrate.git'
......@@ -152,6 +174,11 @@ git = 'https://github.com/paritytech/substrate.git'
tag = 'monthly-2021-07'
version = '3.0.0'
[dependencies.sp-offchain]
git = 'https://github.com/paritytech/substrate.git'
tag = 'monthly-2021-07'
version = '3.0.0'
[dependencies.sp-inherents]
git = 'https://github.com/paritytech/substrate.git'
tag = 'monthly-2021-07'
......@@ -162,6 +189,16 @@ git = 'https://github.com/paritytech/substrate.git'
tag = 'monthly-2021-07'
version = '3.0.0'
[dependencies.sp-session]
git = 'https://github.com/paritytech/substrate.git'
tag = 'monthly-2021-07'
version = '3.0.0'
[dependencies.sp-storage]
git = 'https://github.com/paritytech/substrate.git'
tag = 'monthly-2021-07'
version = '3.0.0'
[dependencies.sp-timestamp]
git = 'https://github.com/paritytech/substrate.git'
tag = 'monthly-2021-07'
......@@ -172,6 +209,11 @@ git = 'https://github.com/paritytech/substrate.git'
tag = 'monthly-2021-07'
version = '3.0.0'
[dependencies.sp-trie]
git = 'https://github.com/paritytech/substrate.git'
tag = 'monthly-2021-07'
version = '3.0.0'
[dependencies.substrate-frame-rpc-system]
git = 'https://github.com/paritytech/substrate.git'
tag = 'monthly-2021-07'
......
use lc_core_runtime::{
AccountId, AuraConfig, BalancesConfig, GenesisConfig, GrandpaConfig, IdentityConfig, IdtyDid,
IdtyIndex, IdtyRight, IdtyValue, Planet, Signature, StrongCertConfig, SudoConfig, SystemConfig,
UdAccountsStorageConfig, UniversalDividendConfig, WASM_BINARY,
// Copyright 2021 Axiom-Team
//
// This file is part of Substrate-Libre-Currency.
//
// Substrate-Libre-Currency is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, version 3 of the License.
//
// Substrate-Libre-Currency 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 Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with Substrate-Libre-Currency. If not, see <https://www.gnu.org/licenses/>.
pub mod g1;
pub mod gdev;
pub mod gtest;
use common_runtime::IdtyIndex;
use common_runtime::{
entities::{IdtyDid, Planet},
AccountId, Signature,
};
use maplit::btreemap;
use sc_service::ChainType;
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
use sp_core::{sr25519, Pair, Public};
use sp_finality_grandpa::AuthorityId as GrandpaId;
use sp_core::{Pair, Public};
use sp_runtime::traits::{IdentifyAccount, Verify};
use std::collections::{BTreeMap, BTreeSet};
/// Specialized `ChainSpec`. This is a specialization of the general Substrate ChainSpec type.
pub type ChainSpec = sc_service::GenericChainSpec<GenesisConfig>;
const TOKEN_DECIMALS: usize = 2;
const TOKEN_SYMBOL: &str = "ĞT";
// The URL for the telemetry server.
// const STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/";
pub type AccountPublic = <Signature as Verify>::Signer;
/// Generate a crypto pair from seed.
pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public {
......@@ -26,7 +36,13 @@ pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Pu
.public()
}
type AccountPublic = <Signature as Verify>::Signer;
/*/// Generate an account ID from pain.
pub fn get_account_id_from_pair<TPublic: Public>(pair: TPublic::Pair) -> AccountId
where
AccountPublic: From<<TPublic::Pair as Pair>::Public>,
{
AccountPublic::from(pair.public()).into_account()
}*/
/// Generate an account ID from seed.
pub fn get_account_id_from_seed<TPublic: Public>(seed: &str) -> AccountId
......@@ -36,183 +52,6 @@ where
AccountPublic::from(get_from_seed::<TPublic>(seed)).into_account()
}
/// Generate an Aura authority key.
pub fn authority_keys_from_seed(s: &str) -> (AuraId, GrandpaId) {
(get_from_seed::<AuraId>(s), get_from_seed::<GrandpaId>(s))
}
/// Create a fake did (for dev and testnet)
fn did(u8_: u8) -> IdtyDid {
IdtyDid {
hash: sp_core::H256::repeat_byte(u8_),
planet: Planet::Earth,
latitude: 0,
longitude: 0,
}
}
pub fn development_config() -> Result<ChainSpec, String> {
let wasm_binary = WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?;
Ok(ChainSpec::from_genesis(
// Name
"Development",
// ID
"dev",
ChainType::Development,
move || {
testnet_genesis(
wasm_binary,
// Initial PoA authorities
vec![authority_keys_from_seed("Alice")],
// Inital identities
btreemap![
did(1) => get_account_id_from_seed::<sr25519::Public>("Alice"),
did(2) => get_account_id_from_seed::<sr25519::Public>("Bob"),
did(3) => get_account_id_from_seed::<sr25519::Public>("Charlie"),
],
// Sudo account
get_account_id_from_seed::<sr25519::Public>("Alice"),
true,
)
},
// Bootnodes
vec![],
// Telemetry
None,
// Protocol ID
None,
// Properties
Some(
serde_json::json!({
"tokenDecimals": TOKEN_DECIMALS,
"tokenSymbol": TOKEN_SYMBOL,
})
.as_object()
.expect("must be a map")
.clone(),
),
// Extensions
None,
))
}
pub fn local_testnet_config() -> Result<ChainSpec, String> {
let wasm_binary = WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?;
Ok(ChainSpec::from_genesis(
// Name
"Local Testnet",
// ID
"local_testnet",
ChainType::Local,
move || {
testnet_genesis(
wasm_binary,
// Initial PoA authorities
vec![
authority_keys_from_seed("Alice"),
authority_keys_from_seed("Bob"),
],
// Initial identities
btreemap![
did(1) => get_account_id_from_seed::<sr25519::Public>("Alice"),
did(2) => get_account_id_from_seed::<sr25519::Public>("Bob"),
did(3) => get_account_id_from_seed::<sr25519::Public>("Charlie"),
did(4) => get_account_id_from_seed::<sr25519::Public>("Dave"),
did(5) => get_account_id_from_seed::<sr25519::Public>("Eve"),
did(6) => get_account_id_from_seed::<sr25519::Public>("Ferdie"),
],
// Sudo account
get_account_id_from_seed::<sr25519::Public>("Alice"),
true,
)
},
// Bootnodes
vec![],
// Telemetry
None,
// Protocol ID
None,
// Properties
Some(
serde_json::json!({
"tokenDecimals": TOKEN_DECIMALS,
"tokenSymbol": TOKEN_SYMBOL,
})
.as_object()
.expect("must be a map")
.clone(),
),
// Extensions
None,
))
}
/// Configure initial storage state for FRAME modules.
fn testnet_genesis(
wasm_binary: &[u8],
initial_authorities: Vec<(AuraId, GrandpaId)>,
initial_identities: BTreeMap<IdtyDid, AccountId>,
root_key: AccountId,
_enable_println: bool,
) -> GenesisConfig {
GenesisConfig {
system: SystemConfig {
// Add Wasm runtime to storage.
code: wasm_binary.to_vec(),
changes_trie_config: Default::default(),
},
balances: BalancesConfig {
// Configure endowed accounts with initial balance of INITIAL_BALANCE.
balances: Vec::with_capacity(0),
},
aura: AuraConfig {
authorities: initial_authorities.iter().map(|x| (x.0.clone())).collect(),
},
grandpa: GrandpaConfig {
authorities: initial_authorities