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

Commit dede5ab

Browse files
committed
Merge remote-tracking branch 'origin/master' into v0.2
2 parents 3a7bbc6 + 6e581f6 commit dede5ab

File tree

37 files changed

+639
-210
lines changed

37 files changed

+639
-210
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ substrate/pwasm-libc/Cargo.lock
1212
demo/runtime/wasm/target/
1313
**/._*
1414
.vscode
15-
polkadot.*
15+
polkadot.*
16+
.DS_Store

Cargo.lock

Lines changed: 105 additions & 105 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,5 @@ is-it-maintained-issue-resolution = { repository = "paritytech/polkadot" }
9191
is-it-maintained-open-issues = { repository = "paritytech/polkadot" }
9292

9393
[profile.release]
94-
panic = "abort"
94+
# Substrate runtime requires unwinding.
95+
panic = "unwind"

README.adoc

Lines changed: 104 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
Implementation of a https://polkadot.network node in Rust.
88

9+
910
== To play
1011

1112
If you'd like to play with Polkadot, you'll need to install a client like this
@@ -46,6 +47,7 @@ polkadot --dev
4647

4748
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.
4849

50+
4951
== Local Two-node Testnet
5052

5153
If you want to see the multi-node consensus algorithm in action locally, then
@@ -62,6 +64,7 @@ polkadot --chain=local --validator --key Bob -d /tmp/bob --port 30334 --bootnode
6264
Ensure you replace `ALICE_BOOTNODE_ID_HERE` with the node ID from the output of
6365
the first terminal.
6466

67+
6568
== Hacking on Polkadot
6669

6770
If you'd actually like hack on Polkadot, you can just grab the source code and
@@ -74,7 +77,7 @@ rustup update nightly
7477
rustup target add wasm32-unknown-unknown --toolchain nightly
7578
rustup update stable
7679
cargo install --git https://github.com/alexcrichton/wasm-gc
77-
sudo apt install cmake pkg-config libssl-dev
80+
sudo apt install cmake pkg-config libssl-dev git
7881
----
7982

8083
Then, grab the Polkadot source code:
@@ -103,4 +106,104 @@ You can start a development chain with:
103106
[source, shell]
104107
cargo run -- --dev
105108

109+
110+
== Using Docker
111+
112+
=== The easiest way
113+
114+
The easiest/faster option is to use the latest image.
115+
116+
117+
.First run
118+
Let´s first check the version we have. The first time you run this command, the polkadot docker image will be downloaded. This takes a bit of time and bandwidth, be patient:
119+
120+
[source, shell]
121+
docker run --rm -it chevdor/polkadot:latest ./version
122+
123+
124+
.Polkadot arguments
125+
You can also pass any argument/flag that polkadot supports:
126+
127+
[source, shell]
128+
docker run --rm -it chevdor/polkadot:latest polkadot --name "PolkaDocker"
129+
130+
131+
.Run as deamon
132+
Once you are done experimenting and picking the best node name :) you can start polkadot as daemon, exposes the polkadot ports and mount a volume that will keep your blockchain data locally:
133+
134+
[source, shell]
135+
docker run -d -p 30333:30333 -p 9933:9933 -p 9944:9944 -v /my/local/folder:/data chevdor/polkadot:latest polkadot
136+
137+
.Docker image update
138+
If you have an image such as `latest` locally, docker will *not* bother downloading the very latest that may be available.
139+
To update:
140+
141+
- stop and delete your containers (`docker stop ...` `docker rm ...`)
142+
- delete your previous image (`docker rmi chevdor/polkadot:latest`)
143+
- run as daemon again, the very latest image will be downloaded again
144+
145+
=== Build your own image
146+
147+
To get up and running with the smallest footprint on your system, you may use the Polkadot Docker image.
148+
You can either build it yourself (it takes a while...):
149+
150+
[source, shell]
151+
----
152+
ccd docker
153+
./build.sh
154+
----
155+
156+
=== Reporting issues
157+
158+
If you run into issues with polkadot when using docker, please run the following command
159+
(replace the tag with the appropriate one if you do not use latest):
160+
161+
[source, shell]
162+
docker run --rm -it chevdor/polkadot:latest version
163+
164+
This will show you the polkadot version as well as the git commit ref that was used to build your container.
165+
Just paste that in the issue you create.
166+
167+
168+
== Shell completion
169+
170+
The Polkadot cli command supports shell auto-completion. For this to work, you will need to run the completion script matching you build and system.
171+
172+
Assuming you built a release version using `cargo build --release` and use `bash` run the following:
173+
174+
[source, shell]
175+
source target/release/completion-scripts/polkadot.bash
176+
177+
You can find completion scripts for:
178+
- bash
179+
- fish
180+
- zsh
181+
- elvish
182+
- powershell
183+
184+
To make this change persistent, you can proceed as follow:
185+
186+
=== First install
187+
188+
[source, shell]
189+
----
190+
COMPL_DIR=$HOME/.completion
191+
mkdir -p $COMPL_DIR
192+
cp -f target/release/completion-scripts/polkadot.bash $COMPL_DIR/
193+
echo "source $COMPL_DIR/polkadot.bash" >> $HOME/.bash_profile
194+
source $HOME/.bash_profile
195+
----
196+
197+
=== Update
198+
199+
When you build a new version of Polkadot, the following will ensure you auto-completion script matches the current binary:
200+
201+
[source, shell]
202+
----
203+
COMPL_DIR=$HOME/.completion
204+
mkdir -p $COMPL_DIR
205+
cp -f target/release/completion-scripts/polkadot.bash $COMPL_DIR/
206+
source $HOME/.bash_profile
207+
----
208+
106209
include::doc/packages.adoc[]
Binary file not shown.
Binary file not shown.

docker/Dockerfile

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
FROM phusion/baseimage:0.10.1
2+
LABEL maintainer "[email protected]"
3+
4+
ARG PROFILE=release
5+
6+
RUN mkdir -p polkadot && \
7+
apt-get update && \
8+
apt-get upgrade -y && \
9+
apt-get install -y cmake pkg-config libssl-dev git && \
10+
apt-get clean && \
11+
mkdir -p /root/.local/share/Polkadot && \
12+
ln -s /root/.local/share/Polkadot /data
13+
14+
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y && \
15+
export PATH=$PATH:$HOME/.cargo/bin && \
16+
rustup update nightly && \
17+
rustup target add wasm32-unknown-unknown --toolchain nightly && \
18+
rustup update stable && \
19+
cargo install --git https://github.com/alexcrichton/wasm-gc && \
20+
git clone https://github.com/paritytech/polkadot.git && \
21+
cd polkadot && \
22+
./build.sh && \
23+
cargo build --$PROFILE && \
24+
mv target/$PROFILE/polkadot /usr/local/bin && \
25+
cargo clean && \
26+
rm -rf /root/.cargo /root/.rustup /tmp/*
27+
28+
COPY version /polkadot
29+
WORKDIR /polkadot
30+
EXPOSE 30333 9933 9944
31+
VOLUME ["/data"]
32+
33+
CMD ["/bin/sh", "polkadot"]

docker/build.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
# Find the current version from Cargo.toml
5+
VERSION=`grep "^version" ../Cargo.toml | egrep -o "([0-9\.]+)"`
6+
GITUSER=chevdor
7+
GITREPO=polkadot
8+
9+
# Build the image
10+
echo "Building ${GITREPO}:$VERSION docker image, hang on!"
11+
time docker build --build-arg PROFILE=release -t ${GITUSER}/${GITREPO}:$VERSION .
12+
13+
# Show the list of available images for this repo
14+
echo "Image is ready"
15+
docker images | grep ${GITREPO}
16+
17+
echo -e "\nIf you just built the latest, you may want to update your tag:"
18+
echo " $ docker tag ${GITUSER}/${GITREPO}:$VERSION ${GITUSER}/${GITREPO}:latest"

docker/cleanup.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
# This script helps reduce the size of the built image
3+
# It removes data that is not required.
4+
5+
export PATH=$PATH:$HOME/.cargo/bin
6+
7+
cargo clean
8+
rm -rf /root/.cargo /root/.rustup /tmp/*

docker/docker-compose.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
version: '3'
2+
services:
3+
polkadot:
4+
build:
5+
context: .
6+
ports:
7+
- "127.0.0.1:30333:30333/tcp"
8+
- "127.0.0.1:9933:9933/tcp"
9+
image: chevdor/polkadot:latest
10+
volumes:
11+
- "polkadot-data:/data"
12+
command: polkadot
13+
14+
volumes:
15+
polkadot-data:

docker/readme-docker.adoc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
== Polkadot Docker
3+
4+
=== Start a Polkadot docker container
5+
6+
Run the following command
7+
8+
docker run -d chevdor/polkadot:latest polkadot
9+
10+
=== Building the image
11+
12+
To build your own image from the source, you can run the following command:
13+
14+
./build.sh
15+
16+
NOTE: Building the image takes a while. Count at least 30min on a good machine.

docker/version

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env bash
2+
# This script show the polkadot version and commit ref that was
3+
# used to build the image.
4+
# If you report an issue, call this script to get all details.
5+
# This script will no longer be required once the polkadot cli
6+
# can report its commit ref.
7+
8+
echo "-----------------------------------------"
9+
printf "Polkadot Docker Container: "
10+
polkadot --version
11+
printf " "
12+
git rev-parse HEAD
13+
echo "-----------------------------------------"

polkadot/cli/src/lib.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ use chain_spec::ChainSpec;
3838
use futures::Future;
3939
use tokio::runtime::Runtime;
4040
pub use service::{Components as ServiceComponents, Service, CustomConfiguration};
41-
pub use cli::VersionInfo;
41+
pub use cli::{VersionInfo, IntoExit};
4242

4343
fn load_spec(id: &str) -> Result<Option<service::ChainSpec>, String> {
4444
Ok(match ChainSpec::from(id) {
@@ -51,22 +51,16 @@ fn load_spec(id: &str) -> Result<Option<service::ChainSpec>, String> {
5151
///
5252
/// This will be invoked with the service and spawn a future that resolves
5353
/// when complete.
54-
pub trait Worker {
54+
pub trait Worker: IntoExit {
5555
/// A future that resolves when the work is done or the node should exit.
5656
/// This will be run on a tokio runtime.
5757
type Work: Future<Item=(),Error=()> + Send + 'static;
5858

59-
/// An exit scheduled for the future.
60-
type Exit: Future<Item=(),Error=()> + Send + 'static;
61-
6259
/// Return configuration for the polkadot node.
6360
// TODO: make this the full configuration, so embedded nodes don't need
6461
// string CLI args
6562
fn configuration(&self) -> service::CustomConfiguration { Default::default() }
6663

67-
/// Don't work, but schedule an exit.
68-
fn exit_only(&self) -> Self::Exit;
69-
7064
/// Do work and schedule exit.
7165
fn work<C: service::Components>(self, service: &service::Service<C>) -> Self::Work;
7266
}
@@ -85,9 +79,9 @@ pub fn run<I, T, W>(args: I, worker: W, version: cli::VersionInfo) -> error::Res
8579
W: Worker,
8680
{
8781

88-
match cli::prepare_execution::<service::Factory, _, _, _, _>(args, worker.exit_only(), version, load_spec, "parity-polkadot")? {
82+
match cli::prepare_execution::<service::Factory, _, _, _, _>(args, worker, version, load_spec, "parity-polkadot")? {
8983
cli::Action::ExecutedInternally => (),
90-
cli::Action::RunService(mut config) => {
84+
cli::Action::RunService((mut config, worker)) => {
9185
info!("Parity ·:· Polkadot");
9286
info!(" version {}", config.full_version());
9387
info!(" by Parity Technologies, 2017, 2018");

polkadot/collator/src/lib.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ use polkadot_api::PolkadotApi;
6969
use polkadot_primitives::{AccountId, BlockId, SessionKey};
7070
use polkadot_primitives::parachain::{self, BlockData, DutyRoster, HeadData, ConsolidatedIngress, Message, Id as ParaId};
7171
use polkadot_cli::{ServiceComponents, Service, CustomConfiguration, VersionInfo};
72-
use polkadot_cli::Worker;
72+
use polkadot_cli::{Worker, IntoExit};
7373
use tokio::timer::Deadline;
7474

7575
const COLLATION_TIMEOUT: Duration = Duration::from_secs(30);
@@ -211,12 +211,21 @@ struct CollationNode<P, E> {
211211
key: Arc<ed25519::Pair>,
212212
}
213213

214+
impl<P, E> IntoExit for CollationNode<P, E> where
215+
P: ParachainContext + Send + 'static,
216+
E: Future<Item=(),Error=()> + Send + 'static
217+
{
218+
type Exit = E;
219+
fn into_exit(self) -> Self::Exit {
220+
self.exit
221+
}
222+
}
223+
214224
impl<P, E> Worker for CollationNode<P, E> where
215225
P: ParachainContext + Send + 'static,
216-
E: Future<Item=(),Error=()> + Send + Clone + 'static
226+
E: Future<Item=(),Error=()> + Send + 'static
217227
{
218228
type Work = Box<Future<Item=(),Error=()> + Send>;
219-
type Exit = E;
220229

221230
fn configuration(&self) -> CustomConfiguration {
222231
let mut config = CustomConfiguration::default();
@@ -227,10 +236,6 @@ impl<P, E> Worker for CollationNode<P, E> where
227236
config
228237
}
229238

230-
fn exit_only(&self) -> Self::Exit {
231-
self.exit.clone()
232-
}
233-
234239
fn work<C: ServiceComponents>(self, service: &Service<C>) -> Self::Work {
235240
let CollationNode { parachain_context, exit, para_id, key } = self;
236241
let client = service.client();
Binary file not shown.

polkadot/src/main.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,9 @@ mod vergen {
3838

3939
// the regular polkadot worker simply does nothing until ctrl-c
4040
struct Worker;
41-
impl cli::Worker for Worker {
42-
type Work = Self::Exit;
41+
impl cli::IntoExit for Worker {
4342
type Exit = future::MapErr<oneshot::Receiver<()>, fn(oneshot::Canceled) -> ()>;
44-
45-
fn exit_only(&self) -> Self::Exit {
43+
fn into_exit(self) -> Self::Exit {
4644
// can't use signal directly here because CtrlC takes only `Fn`.
4745
let (exit_send, exit) = oneshot::channel();
4846

@@ -55,9 +53,13 @@ impl cli::Worker for Worker {
5553

5654
exit.map_err(drop)
5755
}
56+
}
5857

59-
fn work<C: ServiceComponents>(self, _service: &Service<C>) -> Self::Exit {
60-
self.exit_only()
58+
impl cli::Worker for Worker {
59+
type Work = <Self as cli::IntoExit>::Exit;
60+
fn work<C: ServiceComponents>(self, _service: &Service<C>) -> Self::Work {
61+
use cli::IntoExit;
62+
self.into_exit()
6163
}
6264
}
6365

0 commit comments

Comments
 (0)