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

Preparing light client structure #142

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Cargo.lock

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

5 changes: 3 additions & 2 deletions demo/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,9 @@ pub fn run<I, T>(args: I) -> error::Result<()> where

let _rpc_servers = {
let handler = || {
let chain = rpc::apis::chain::Chain::new(client.clone(), core.remote());
rpc::rpc_handler(client.clone(), chain, DummyPool)
let chain = rpc::apis::chain::Chain::new(client.clone(), client.clone(), client.clone(), core.remote());
let state = rpc::apis::state::State::new(client.clone(), client.clone(), client.clone());
rpc::rpc_handler(state, chain, DummyPool)
};
let http_address = "127.0.0.1:9933".parse().unwrap();
let ws_address = "127.0.0.1:9944".parse().unwrap();
Expand Down
4 changes: 4 additions & 0 deletions polkadot/cli/src/cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ args:
long: validator
help: Enable validator mode
takes_value: false
- light:
long: light
help: Run in light client mode
takes_value: false
- port:
long: port
value_name: PORT
Expand Down
9 changes: 4 additions & 5 deletions polkadot/cli/src/informant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ use tokio_core::reactor;
use network::{SyncState, SyncProvider};
use runtime_support::Hashable;
use primitives::block::HeaderHash;
use client::BlockchainEvents;

const TIMER_INTERVAL_MS: u64 = 5000;

Expand All @@ -33,12 +32,12 @@ pub fn start(service: &Service, handle: reactor::Handle) {
.expect("Error creating informant timer");

let network = service.network();
let client = service.client();
let chain_head = service.chain_head();

let display_notifications = interval.map_err(|e| debug!("Timer error: {:?}", e)).for_each(move |_| {
let sync_status = network.status();

if let Ok(best_block) = client.best_block_header() {
if let Ok(best_block) = chain_head.best_block_header() {
let hash: HeaderHash = best_block.blake2_256().into();
let status = match (sync_status.sync.state, sync_status.sync.best_seen_block) {
(SyncState::Idle, _) => "Idle".into(),
Expand All @@ -52,8 +51,8 @@ pub fn start(service: &Service, handle: reactor::Handle) {
Ok(())
});

let client = service.client();
let display_block_import = client.import_notification_stream().for_each(|n| {
let chain_events = service.chain_events();
let display_block_import = chain_events.import_notification_stream().for_each(|n| {
info!(target: "polkadot", "Imported #{} ({})", n.header.number, n.hash);
Ok(())
});
Expand Down
16 changes: 14 additions & 2 deletions polkadot/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ pub fn run<I, T>(args: I) -> error::Result<()> where
info!("Starting validator.");
role = service::Role::VALIDATOR;
}
else if matches.is_present("light") {
info!("Starting light.");
role = service::Role::LIGHT;
}

match matches.value_of("chain") {
Some("poc-1") => config.chain_spec = ChainSpec::PoC1Testnet,
Expand Down Expand Up @@ -160,8 +164,16 @@ pub fn run<I, T>(args: I) -> error::Result<()> where
let ws_address = parse_address("127.0.0.1:9944", "ws-port", &matches)?;

let handler = || {
let chain = rpc::apis::chain::Chain::new(service.client(), core.remote());
rpc::rpc_handler(service.client(), chain, service.transaction_pool())
let chain = rpc::apis::chain::Chain::new(
service.chain_head(),
service.chain_data(),
service.chain_events(),
core.remote());
let state = rpc::apis::state::State::new(
service.chain_head(),
service.state_data(),
service.contract_caller());
rpc::rpc_handler(state, chain, service.transaction_pool())
};
(
start_server(http_address, |address| rpc::start_http(address, handler())),
Expand Down
1 change: 1 addition & 0 deletions polkadot/service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ substrate-network = { path = "../../substrate/network" }
substrate-client = { path = "../../substrate/client" }
substrate-codec = { path = "../../substrate/codec" }
substrate-executor = { path = "../../substrate/executor" }
substrate-light = { path = "../../substrate/light" }
142 changes: 142 additions & 0 deletions polkadot/service/src/chain_config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
// Copyright 2017 Parity Technologies (UK) Ltd.
// This file is part of Polkadot.

// Polkadot 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.

// Polkadot 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 Polkadot. If not, see <http://www.gnu.org/licenses/>.?

//! Chain configuration.

use ed25519;
use polkadot_runtime::{GenesisConfig, ConsensusConfig, CouncilConfig, DemocracyConfig,
SessionConfig, StakingConfig};

/// Chain configuration.
pub struct ChainConfig {
/// Genesis block confguration.
pub genesis_config: GenesisConfig,
/// List of bootnodes.
pub boot_nodes: Vec<String>,
}
/// Prepare chain configuration for POC-1 testnet.
pub fn poc_1_testnet_config() -> ChainConfig {
let initial_authorities = vec![
hex!["82c39b31a2b79a90f8e66e7a77fdb85a4ed5517f2ae39f6a80565e8ecae85cf5"].into(),
hex!["4de37a07567ebcbf8c64568428a835269a566723687058e017b6d69db00a77e7"].into(),
hex!["063d7787ebca768b7445dfebe7d62cbb1625ff4dba288ea34488da266dd6dca5"].into(),
];
let endowed_accounts = vec![
hex!["24d132eb1a4cbf8e46de22652019f1e07fadd5037a6a057c75dbbfd4641ba85d"].into(),
];
let genesis_config = GenesisConfig {
consensus: Some(ConsensusConfig {
code: include_bytes!("../../runtime/wasm/genesis.wasm").to_vec(), // TODO change
authorities: initial_authorities.clone(),
}),
system: None,
session: Some(SessionConfig {
validators: initial_authorities.clone(),
session_length: 720, // that's 1 hour per session.
}),
staking: Some(StakingConfig {
current_era: 0,
intentions: vec![],
transaction_fee: 100,
balances: endowed_accounts.iter().map(|&k|(k, 1u64 << 60)).collect(),
validator_count: 12,
sessions_per_era: 24, // 24 hours per era.
bonding_duration: 90, // 90 days per bond.
}),
democracy: Some(DemocracyConfig {
launch_period: 120 * 24 * 14, // 2 weeks per public referendum
voting_period: 120 * 24 * 28, // 4 weeks to discuss & vote on an active referendum
minimum_deposit: 1000, // 1000 as the minimum deposit for a referendum
}),
council: Some(CouncilConfig {
active_council: vec![],
candidacy_bond: 1000, // 1000 to become a council candidate
voter_bond: 100, // 100 down to vote for a candidate
present_slash_per_voter: 1, // slash by 1 per voter for an invalid presentation.
carry_count: 24, // carry over the 24 runners-up to the next council election
presentation_duration: 120 * 24, // one day for presenting winners.
approval_voting_period: 7 * 120 * 24, // one week period between possible council elections.
term_duration: 180 * 120 * 24, // 180 day term duration for the council.
desired_seats: 0, // start with no council: we'll raise this once the stake has been dispersed a bit.
inactive_grace_period: 1, // one addition vote should go by before an inactive voter can be reaped.

cooloff_period: 90 * 120 * 24, // 90 day cooling off period if council member vetoes a proposal.
voting_period: 7 * 120 * 24, // 7 day voting period for council members.
}),
parachains: Some(Default::default()),
};
let boot_nodes = Vec::new();
ChainConfig { genesis_config, boot_nodes }
}

/// Prepare chain configuration for local testnet.
pub fn local_testnet_config() -> ChainConfig {
let initial_authorities = vec![
ed25519::Pair::from_seed(b"Alice ").public().into(),
ed25519::Pair::from_seed(b"Bob ").public().into(),
];
let endowed_accounts = vec![
ed25519::Pair::from_seed(b"Alice ").public().into(),
ed25519::Pair::from_seed(b"Bob ").public().into(),
ed25519::Pair::from_seed(b"Charlie ").public().into(),
ed25519::Pair::from_seed(b"Dave ").public().into(),
ed25519::Pair::from_seed(b"Eve ").public().into(),
ed25519::Pair::from_seed(b"Ferdie ").public().into(),
];
let genesis_config = GenesisConfig {
consensus: Some(ConsensusConfig {
code: include_bytes!("../../runtime/wasm/target/wasm32-unknown-unknown/release/polkadot_runtime.compact.wasm").to_vec(),
authorities: initial_authorities.clone(),
}),
system: None,
session: Some(SessionConfig {
validators: initial_authorities.clone(),
session_length: 10,
}),
staking: Some(StakingConfig {
current_era: 0,
intentions: initial_authorities.clone(),
transaction_fee: 1,
balances: endowed_accounts.iter().map(|&k|(k, 1u64 << 60)).collect(),
validator_count: 2,
sessions_per_era: 5,
bonding_duration: 2,
}),
democracy: Some(DemocracyConfig {
launch_period: 9,
voting_period: 18,
minimum_deposit: 10,
}),
council: Some(CouncilConfig {
active_council: vec![],
candidacy_bond: 10,
voter_bond: 2,
present_slash_per_voter: 1,
carry_count: 4,
presentation_duration: 10,
approval_voting_period: 20,
term_duration: 40,
desired_seats: 0,
inactive_grace_period: 1,

cooloff_period: 75,
voting_period: 20,
}),
parachains: Some(Default::default()),
};
let boot_nodes = Vec::new();
ChainConfig { genesis_config, boot_nodes }
}
Loading