Files
pezkuwi-subxt/polkadot/scripts/two-node-local-net.sh
T
Peter Goodspeed-Niklaus 1a25c41277 start working on building the real overseer (#1795)
* start working on building the real overseer

Unfortunately, this fails to compile right now due to an upstream
failure to compile which is probably brought on by a recent upgrade
to rustc v1.47.

* fill in AllSubsystems internal constructors

* replace fn make_metrics with Metrics::attempt_to_register

* update to account for #1740

* remove Metrics::register, rename Metrics::attempt_to_register

* add 'static bounds to real_overseer type params

* pass authority_discovery and network_service to real_overseer

It's not straightforwardly obvious that this is the best way to handle
the case when there is no authority discovery service, but it seems
to be the best option available at the moment.

* select a proper database configuration for the availability store db

* use subdirectory for av-store database path

* apply Basti's patch which avoids needing to parameterize everything on Block

* simplify path extraction

* get all tests to compile

* Fix Prometheus double-registry error

for debugging purposes, added this to node/subsystem-util/src/lib.rs:472-476:

```rust
Some(registry) => Self::try_register(registry).map_err(|err| {
	eprintln!("PrometheusError calling {}::register: {:?}", std::any::type_name::<Self>(), err);
	err
}),
```

That pointed out where the registration was failing, which led to
this fix. The test still doesn't pass, but it now fails in a new
and different way!

* authorities must have authority discovery, but not necessarily overseer handlers

* fix broken SpawnedSubsystem impls

detailed logging determined that using the `Box::new` style of
future generation, the `self.run` method was never being called,
leading to dropped receivers / closed senders for those subsystems,
causing the overseer to shut down immediately.

This is not the final fix needed to get things working properly,
but it's a good start.

* use prometheus properly

Prometheus lets us register simple counters, which aren't very
interesting. It also allows us to register CounterVecs, which are.
With a CounterVec, you can provide a set of labels, which can
later be used to filter the counts.

We were using them wrong, though. This pattern was repeated in a
variety of places in the code:

```rust
// panics with an cardinality mismatch
let my_counter = register(CounterVec::new(opts, &["succeeded", "failed"])?, registry)?;
my_counter.with_label_values(&["succeeded"]).inc()
```

The problem is that the labels provided in the constructor are not
the set of legal values which can be annotated, but a set of individual
label names which can have individual, arbitrary values.

This commit fixes that.

* get av-store subsystem to actually run properly and not die on first signal

* typo fix: incomming -> incoming

* don't disable authority discovery in test nodes

* Fix rococo-v1 missing session keys

* Update node/core/av-store/Cargo.toml

* try dummying out av-store on non-full-nodes

* overseer and subsystems are required only for full nodes

* Reduce the amount of warnings on browser target

* Fix two more warnings

* InclusionInherent should actually have an Inherent module on rococo

* Ancestry: don't return genesis' parent hash

* Update Cargo.lock

* fix broken test

* update test script: specify chainspec as script argument

* Apply suggestions from code review

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update node/service/src/lib.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* node/service/src/lib: Return error via ? operator

* post-merge blues

* add is_collator flag

* prevent occasional av-store test panic

* simplify fix; expand application

* run authority_discovery in Role::Discover when collating

* distinguish between proposer closed channel errors

* add IsCollator enum, remove is_collator CLI flag

* improve formatting

* remove nop loop

* Fix some stuff

Co-authored-by: Andronik Ordian <write@reusable.software>
Co-authored-by: Bastian Köcher <git@kchr.de>
Co-authored-by: Fedor Sakharov <fedor.sakharov@gmail.com>
Co-authored-by: Robert Habermeier <robert@Roberts-MBP.lan1>
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
Co-authored-by: Max Inden <mail@max-inden.de>
2020-10-28 10:26:50 +00:00

117 lines
3.0 KiB
Bash
Executable File

#!/usr/bin/env bash
# Run a two node local net.
# Unlike the docker-compose script in the /docker folder, this version builds the nodes based
# on the current state of the code, instead of depending on a published version.
set -e
# chainspec defaults to polkadot-local if no arguments are passed to this script;
# if arguments are passed in, the first is the chainspec
chainspec="${1:-polkadot-local}"
PROJECT_ROOT=$(git rev-parse --show-toplevel)
# shellcheck disable=SC1090
source "$(dirname "$0")"/common.sh
cd "$PROJECT_ROOT"
last_modified_rust_file=$(
find . -path ./target -prune -o -type f -name '*.rs' -printf '%T@ %p\n' |
sort -nr |
head -1 |
cut -d' ' -f2-
)
polkadot="target/release/polkadot"
# ensure the polkadot binary exists and is up to date
if [ ! -x "$polkadot" ] || [ "$polkadot" -ot "$last_modified_rust_file" ]; then
cargo build --release
fi
# setup variables
node_offset=0
declare -a node_pids
declare -a node_pipes
# create a sed expression which injects the node name and stream type into each line
function make_sed_expr() {
name="$1"
type="$2"
printf "s/^/%8s %s: /" "$name" "$type"
}
# turn a string into a flag
function flagify() {
printf -- '--%s' "$(tr '[:upper:]' '[:lower:]' <<< "$1")"
}
# start a node and label its output
#
# This function takes a single argument, the node name.
# The name must be one of those which can be passed to the polkadot binary, in un-flagged form,
# one of:
# alice, bob, charlie, dave, eve, ferdie, one, two
function run_node() {
name="$1"
# create a named pipe so we can get the node's PID while also sedding its output
local stdout
local stderr
stdout=$(mktemp --dry-run --tmpdir)
stderr=$(mktemp --dry-run --tmpdir)
mkfifo "$stdout"
mkfifo "$stderr"
node_pipes+=("$stdout")
node_pipes+=("$stderr")
# compute ports from offset
local port=$((30333+node_offset))
local rpc_port=$((9933+node_offset))
local ws_port=$((9944+node_offset))
node_offset=$((node_offset+1))
# start the node
"$polkadot" \
--chain "$chainspec" \
--tmp \
--port "$port" \
--rpc-port "$rpc_port" \
--ws-port "$ws_port" \
--rpc-cors all \
"$(flagify "$name")" \
> "$stdout" \
2> "$stderr" \
&
local pid=$!
node_pids+=("$pid")
# send output from the stdout pipe to stdout, prepending the node name
sed -e "$(make_sed_expr "$name" "OUT")" "$stdout" >&1 &
# send output from the stderr pipe to stderr, prepending the node name
sed -e "$(make_sed_expr "$name" "ERR")" "$stderr" >&2 &
}
# clean up the nodes when this script exits
function finish {
for node_pid in "${node_pids[@]}"; do
kill -9 "$node_pid"
done
for node_pipe in "${node_pipes[@]}"; do
rm "$node_pipe"
done
}
trap finish EXIT
# start the nodes
run_node Alice
run_node Bob
# now wait; this will exit on its own only if both subprocesses exit
# the practical implication, as both subprocesses are supposed to run forever, is that
# this script will also run forever, until killed, at which point the exit trap should kill
# the subprocesses
wait