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

Fixes and improvements for PoC-1 Testnet #143

Merged
merged 16 commits into from
May 7, 2018
Merged
103 changes: 102 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,104 @@
# Polkadot

Implementation of a https://polkadot.io node in Rust.
Implementation of a https://polkadot.io node in Rust.

## To play

If you'd like to play with Polkadot, you'll need to install a client like this
one. First, get Rust and the support software if you don't already have it:

```
curl https://sh.rustup.rs -sSf | sh
sudo apt install make clang
```

Then, install Polkadot PoC-1:

```
cargo install --git https://github.com/paritytech/polkadot.git --branch v0.1.0
```

You'll now have a `polkadot` binary installed to your `PATH`. You can drop the
`--branch v0.1.0` to get the very latest version of Polkadot, but these
instructions might not work in that case.

### Development

You can run a simple single-node development "network" on your machine by
running in a terminal:

```
polkadot --chain=dev --validator --key Alice
```

You can muck around by cloning and building the http://github.com/paritytech/polka-ui and http://github.com/paritytech/polkadot-ui or just heading to https://polkadot.js.org/apps.

### PoC-1 Testnet

You can also connect to the global PoC-1 testnet. To do this, just use:

```
polkadot --chain=poc-1
```

If you want to do anything on it (not that there's much to do), then you'll need
to get some PoC-1 testnet DOTs. Ask in the Polkadot watercooler.

## Local Two-node Testnet

If you want to see the multi-node consensus algorithm in action locally, then
you can create a local testnet. You'll need two terminals open. In one, run:

```
polkadot --chain=dev --validator --key Alice -d /tmp/alice
```

and in the other, run:

```
polkadot --chain=dev --validator --key Bob -d /tmp/bob --port 30334 --bootnodes 'enode://ALICE_BOOTNODE_ID_HERE@127.0.0.1:30333'
```

Ensure you replace `ALICE_BOOTNODE_ID_HERE` with the node ID from the output of
the first terminal.

## Hacking on Polkadot

If you'd actually like hack on Polkadot, you can just grab the source code and
build it. Ensure you have Rust and the support software installed:

```
curl https://sh.rustup.rs -sSf | sh
rustup update nightly
rustup target add wasm32-unknown-unknown --toolchain nightly
rustup update stable
cargo install --git https://github.com/alexcrichton/wasm-gc
cargo install --git https://github.com/pepyakin/wasm-export-table.git
sudo apt install make clang
```

Then, grab the Polkadot source code:

```
git clone https://github.com/paritytech/polkadot.git
cd polkadot
```

Then build the code:

```
./build.sh # Builds the WebAssembly binaries
cargo build # Builds all native code
```

You can run the tests if you like:

```
cargo test --all
```

You can start a development chain with:

```
cargo run -- --chain=dev --validator --key Alice
```
4 changes: 2 additions & 2 deletions demo/executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ mod tests {
construct_block(
1,
[69u8; 32].into(),
hex!("57ba67304318efaee95c4f9ab95ed5704eafe030bc8db2df00acb08c2f4979c8").into(),
hex!("a63d59c6a7347cd7a1dc1ec139723b531f0ac450e39b1c532d5ca69ff74ad811").into(),
vec![Extrinsic {
signed: Alice.into(),
index: 0,
Expand All @@ -210,7 +210,7 @@ mod tests {
construct_block(
2,
block1().1,
hex!("ead4c60c0cad06b7ee73e64efeec2d4eb82c651469fb2ec748cfe5026bea5c49").into(),
hex!("1c3623b2e3f7e43752debb9015bace4f6931593579b5af34457b931315f5e2ab").into(),
vec![
Extrinsic {
signed: Bob.into(),
Expand Down
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion polkadot/cli/src/cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,6 @@ args:
- chain:
long: chain
value_name: CHAIN_SPEC
help: Specify the chain specification (one of dev or poc-1)
help: Specify the chain specification (one of dev, local or poc-1)
takes_value: true
subcommands:
6 changes: 4 additions & 2 deletions polkadot/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,15 @@ pub fn run<I, T>(args: I) -> error::Result<()> where
}

match matches.value_of("chain") {
Some("poc-1") => config.chain_spec = ChainSpec::PoC1Testnet,
Some("dev") => config.chain_spec = ChainSpec::Development,
Some("local") => config.chain_spec = ChainSpec::LocalTestnet,
Some("poc-1") => config.chain_spec = ChainSpec::PoC1Testnet,
None => (),
Some(unknown) => panic!("Invalid chain name: {}", unknown),
}
info!("Chain specification: {}", match config.chain_spec {
ChainSpec::Development => "Local Development",
ChainSpec::Development => "Development",
ChainSpec::LocalTestnet => "Local Testnet",
ChainSpec::PoC1Testnet => "PoC-1 Testnet",
});

Expand Down
2 changes: 2 additions & 0 deletions polkadot/consensus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,7 @@ impl<C: PolkadotApi, R: TableRouter> bft::Proposer for Proposer<C, R> {
let mut pool = self.transaction_pool.lock();
let mut unqueue_invalid = Vec::new();
let mut pending_size = 0;
pool.cull(None, readiness_evaluator.clone());
for pending in pool.pending(readiness_evaluator.clone()) {
// skip and cull transactions which are too large.
if pending.encoded_size() > MAX_TRANSACTIONS_SIZE {
Expand Down Expand Up @@ -634,6 +635,7 @@ impl<C: PolkadotApi, R: TableRouter> bft::Proposer for Proposer<C, R> {
let mut next_index = {
let readiness_evaluator = Ready::create(self.parent_id.clone(), &*self.client);

pool.cull(None, readiness_evaluator.clone());
let cur_index = pool.pending(readiness_evaluator)
.filter(|tx| tx.as_ref().as_ref().signed == local_id)
.last()
Expand Down
28 changes: 14 additions & 14 deletions polkadot/consensus/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,22 +108,22 @@ impl Stream for Messages {
}

// check the network
match self.network_stream.poll() {
Err(_) => Err(bft::InputStreamConcluded.into()),
Ok(Async::NotReady) => Ok(Async::NotReady),
Ok(Async::Ready(None)) => Ok(Async::NotReady), // the input stream for agreements is never meant to logically end.
Ok(Async::Ready(Some(message))) => {
if message.parent_hash == self.parent_hash {
match process_message(message, &self.authorities) {
Ok(message) => Ok(Async::Ready(Some(message))),
Err(e) => {
debug!("Message validation failed: {:?}", e);
Ok(Async::NotReady)
loop {
match self.network_stream.poll() {
Err(_) => return Err(bft::InputStreamConcluded.into()),
Ok(Async::NotReady) => return Ok(Async::NotReady),
Ok(Async::Ready(None)) => return Ok(Async::NotReady), // the input stream for agreements is never meant to logically end.
Ok(Async::Ready(Some(message))) => {
if message.parent_hash == self.parent_hash {
match process_message(message, &self.authorities) {
Ok(message) => return Ok(Async::Ready(Some(message))),
Err(e) => {
debug!("Message validation failed: {:?}", e);
}
}
} else {
self.collection.push(message);
}
} else {
self.collection.push(message);
Ok(Async::NotReady)
}
}
}
Expand Down
24 changes: 24 additions & 0 deletions polkadot/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ extern crate substrate_runtime_support as runtime_support;
#[macro_use]
extern crate substrate_runtime_primitives as runtime_primitives;

#[cfg(feature = "std")]
#[macro_use]
extern crate hex_literal;

#[cfg(test)]
extern crate substrate_serializer;

Expand Down Expand Up @@ -298,4 +302,24 @@ mod tests {
println!("{}", HexDisplay::from(&v));
assert_eq!(UncheckedExtrinsic::decode(&mut &v[..]).unwrap(), tx);
}

#[test]
fn serialize_checked() {
let xt = Extrinsic {
signed: hex!["0d71d1a9cad6f2ab773435a7dec1bac019994d05d1dd5eb3108211dcf25c9d1e"],
index: 0u64,
function: Call::CouncilVoting(council::voting::Call::propose(Box::new(
PrivCall::Consensus(consensus::PrivCall::set_code(
vec![]
))
))),
};
let v = Slicable::encode(&xt);

let data = hex!["e00000000d71d1a9cad6f2ab773435a7dec1bac019994d05d1dd5eb3108211dcf25c9d1e000000000000000007000000000000006369D39D892B7B87A6769F90E14C618C2B84EBB293E2CC46640136E112C078C75619AC2E0815F2511568736623C055156C8FC427CE2AEE4AE2838F86EFE80208"];
let uxt: UncheckedExtrinsic = Slicable::decode(&mut &data[..]).unwrap();
assert_eq!(uxt.extrinsic, xt);

assert_eq!(Extrinsic::decode(&mut &v[..]).unwrap(), xt);
}
}
Binary file modified polkadot/runtime/wasm/genesis.wasm
Binary file not shown.
Binary file not shown.
Binary file not shown.
4 changes: 3 additions & 1 deletion polkadot/service/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ pub use network::NetworkConfiguration;
/// The chain specification (this should eventually be replaced by a more general JSON-based chain
/// specification).
pub enum ChainSpec {
/// Whatever the current runtime is, with simple Alice/Bob auths.
/// Whatever the current runtime is, with just Alice as an auth.
Development,
/// Whatever the current runtime is, with simple Alice/Bob auths.
LocalTestnet,
/// The PoC-1 testnet.
PoC1Testnet,
}
Expand Down
46 changes: 31 additions & 15 deletions polkadot/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ use parking_lot::Mutex;
use tokio_core::reactor::Core;
use codec::Slicable;
use primitives::block::{Id as BlockId, Extrinsic, ExtrinsicHash, HeaderHash};
use primitives::hashing;
use primitives::{AuthorityId, hashing};
use transaction_pool::TransactionPool;
use substrate_executor::NativeExecutor;
use polkadot_executor::Executor as LocalDispatch;
Expand Down Expand Up @@ -98,8 +98,9 @@ impl network::TransactionPool for TransactionPoolAdapter {
}
};
let id = self.client.check_id(BlockId::Hash(best_block)).expect("Best block is always valid; qed.");
let ready = transaction_pool::Ready::create(id, &*self.client);
self.pool.lock().pending(ready).map(|t| {
let mut pool = self.pool.lock();
pool.cull(None, transaction_pool::Ready::create(id, &*self.client));
pool.pending(transaction_pool::Ready::create(id, &*self.client)).map(|t| {
let hash = ::primitives::Hash::from(&t.hash()[..]);
let tx = codec::Slicable::encode(t.as_transaction());
(hash, tx)
Expand Down Expand Up @@ -135,9 +136,10 @@ fn poc_1_testnet_config() -> ChainConfig {
hex!["82c39b31a2b79a90f8e66e7a77fdb85a4ed5517f2ae39f6a80565e8ecae85cf5"].into(),
hex!["4de37a07567ebcbf8c64568428a835269a566723687058e017b6d69db00a77e7"].into(),
hex!["063d7787ebca768b7445dfebe7d62cbb1625ff4dba288ea34488da266dd6dca5"].into(),
hex!["8101764f45778d4980dadaceee6e8af2517d3ab91ac9bec9cd1714fa5994081c"].into(),
];
let endowed_accounts = vec![
hex!["24d132eb1a4cbf8e46de22652019f1e07fadd5037a6a057c75dbbfd4641ba85d"].into(),
hex!["f295940fa750df68a686fcf4abd4111c8a9c5a5a5a83c4c8639c451a94a7adfd"].into(),
];
let genesis_config = GenesisConfig {
consensus: Some(ConsensusConfig {
Expand All @@ -151,7 +153,7 @@ fn poc_1_testnet_config() -> ChainConfig {
}),
staking: Some(StakingConfig {
current_era: 0,
intentions: vec![],
intentions: initial_authorities.clone(),
transaction_fee: 100,
balances: endowed_accounts.iter().map(|&k|(k, 1u64 << 60)).collect(),
validator_count: 12,
Expand Down Expand Up @@ -180,15 +182,15 @@ fn poc_1_testnet_config() -> ChainConfig {
}),
parachains: Some(Default::default()),
};
let boot_nodes = Vec::new();
let boot_nodes = vec![
"enode://ce29df27adace5c2a08efc2fd58ce1a2587f2157061e7788861dfef3c0cbf275af8476f93b5f10ecbcd7d6c2fdac109b581502dd7a67a361f9efa7593308bedd@104.211.54.233:30333".into(),
"enode://db86cdf0d653c774cb9f357ba99ee035b2dc3ae4313e93a79a38d9e0089dc5eacdf01a5cab7d41b6a44c83bc78599b76318bc59501f9d62cc6b08cfb74777032@104.211.48.51:30333".into(),
"enode://a9458a01ccc278eab98ee329f529ca3bcb88e13e4e0cda7318a63c6ae704b74eca7c5a05cff106d531cdc41facfbe63540de5f733108fbbbb7d0235131ca39a0@104.211.48.247:30333".into(),
];
ChainConfig { genesis_config, boot_nodes }
}

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(),
];
fn testnet_config(initial_authorities: Vec<AuthorityId>) -> ChainConfig {
let endowed_accounts = vec![
ed25519::Pair::from_seed(b"Alice ").public().into(),
ed25519::Pair::from_seed(b"Bob ").public().into(),
Expand Down Expand Up @@ -222,15 +224,15 @@ fn local_testnet_config() -> ChainConfig {
minimum_deposit: 10,
}),
council: Some(CouncilConfig {
active_council: vec![],
active_council: endowed_accounts.iter().filter(|a| initial_authorities.iter().find(|b| a == b).is_none()).map(|a| (a.clone(), 1000000)).collect(),
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,
term_duration: 1000000,
desired_seats: (endowed_accounts.len() - initial_authorities.len()) as u32,
inactive_grace_period: 1,

cooloff_period: 75,
Expand All @@ -242,6 +244,19 @@ fn local_testnet_config() -> ChainConfig {
ChainConfig { genesis_config, boot_nodes }
}

fn development_config() -> ChainConfig {
testnet_config(vec![
ed25519::Pair::from_seed(b"Alice ").public().into(),
])
}

fn local_testnet_config() -> ChainConfig {
testnet_config(vec![
ed25519::Pair::from_seed(b"Alice ").public().into(),
ed25519::Pair::from_seed(b"Bob ").public().into(),
])
}

impl Service {
/// Creates and register protocol with the network service
pub fn new(mut config: Configuration) -> Result<Service, error::Error> {
Expand All @@ -264,7 +279,8 @@ impl Service {
}

let ChainConfig { genesis_config, boot_nodes } = match config.chain_spec {
ChainSpec::Development => local_testnet_config(),
ChainSpec::Development => development_config(),
ChainSpec::LocalTestnet => local_testnet_config(),
ChainSpec::PoC1Testnet => poc_1_testnet_config(),
};
config.network.boot_nodes.extend(boot_nodes);
Expand Down
Binary file not shown.
Binary file not shown.
Loading