From 3f9fa3b7a0ea3bb77d714a311e204675596d8bbd Mon Sep 17 00:00:00 2001 From: Maciej Hirsz Date: Fri, 26 Mar 2021 10:30:10 +0100 Subject: [PATCH 01/27] Kill all nodes from "Earth" for now --- backend/src/node/connector.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/backend/src/node/connector.rs b/backend/src/node/connector.rs index c219acf..c810b7b 100644 --- a/backend/src/node/connector.rs +++ b/backend/src/node/connector.rs @@ -115,7 +115,12 @@ impl NodeConnector { match &*node.chain { "Kusama CC3" => node.chain = "Kusama".into(), "Polkadot CC1" => node.chain = "Polkadot".into(), - _ => (), + "Earth" => { + // Temp, there is too many of them + ctx.stop(); + return; + }, + _ => () } self.aggregator.do_send(AddNode { node, conn_id, rec }); From d0850103839a4aed4023a66b9e215a5649f079de Mon Sep 17 00:00:00 2001 From: David Palm Date: Fri, 26 Mar 2021 11:20:57 +0100 Subject: [PATCH 02/27] actix-web enables `compression` and `cookies` by default. I don't think we need either. --- backend/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/Cargo.toml b/backend/Cargo.toml index 70f5030..681e40c 100644 --- a/backend/Cargo.toml +++ b/backend/Cargo.toml @@ -7,7 +7,7 @@ license = "GPL-3.0" [dependencies] actix = "0.11.1" -actix-web = "4.0.0-beta.4" +actix-web = { version = "4.0.0-beta.4", default-features = false } actix-web-actors = "4.0.0-beta.3" actix-http = "3.0.0-beta.4" bytes = "1.0.1" From 1c0ba7c3b19fa4dd6a45a5e107553ca52bc75399 Mon Sep 17 00:00:00 2001 From: David Palm Date: Fri, 26 Mar 2021 11:22:35 +0100 Subject: [PATCH 03/27] lockfile --- backend/Cargo.lock | 71 ---------------------------------------------- 1 file changed, 71 deletions(-) diff --git a/backend/Cargo.lock b/backend/Cargo.lock index 8e11065..11663d4 100644 --- a/backend/Cargo.lock +++ b/backend/Cargo.lock @@ -56,14 +56,11 @@ dependencies = [ "ahash", "base64", "bitflags", - "brotli2", "bytes", "bytestring", "cfg-if 1.0.0", - "cookie", "derive_more", "encoding_rs", - "flate2", "futures-core", "futures-util", "h2", @@ -256,12 +253,6 @@ dependencies = [ "syn", ] -[[package]] -name = "adler" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee2a4ec343196209d6594e19543ae87a39f96d5534d7174822a3ad825dd6ed7e" - [[package]] name = "ahash" version = "0.7.2" @@ -376,26 +367,6 @@ dependencies = [ "generic-array", ] -[[package]] -name = "brotli-sys" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4445dea95f4c2b41cde57cc9fee236ae4dbae88d8fcbdb4750fc1bb5d86aaecd" -dependencies = [ - "cc", - "libc", -] - -[[package]] -name = "brotli2" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0cb036c3eade309815c15ddbacec5b22c4d1f3983a774ab2eac2e3e9ea85568e" -dependencies = [ - "brotli-sys", - "libc", -] - [[package]] name = "bumpalo" version = "3.4.0" @@ -519,17 +490,6 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ce90df4c658c62f12d78f7508cf92f9173e5184a539c10bfe54a3107b3ffd0f2" -[[package]] -name = "cookie" -version = "0.14.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1373a16a4937bc34efec7b391f9c1500c30b8478a701a4f44c9165cc0475a6e0" -dependencies = [ - "percent-encoding", - "time 0.2.26", - "version_check", -] - [[package]] name = "core-foundation" version = "0.9.1" @@ -552,15 +512,6 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8aebca1129a03dc6dc2b127edd729435bbc4a37e1d5f4d7513165089ceb02634" -[[package]] -name = "crc32fast" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81156fece84ab6a9f2afdb109ce3ae577e42b1228441eded99bd77f627953b1a" -dependencies = [ - "cfg-if 1.0.0", -] - [[package]] name = "crossbeam-channel" version = "0.5.0" @@ -641,18 +592,6 @@ dependencies = [ "static_assertions", ] -[[package]] -name = "flate2" -version = "1.0.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da80be589a72651dcda34d8b35bcdc9b7254ad06325611074d9cc0fbb19f60ee" -dependencies = [ - "cfg-if 0.1.10", - "crc32fast", - "libc", - "miniz_oxide", -] - [[package]] name = "fnv" version = "1.0.7" @@ -1017,16 +956,6 @@ version = "0.3.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" -[[package]] -name = "miniz_oxide" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f2d26ec3309788e423cfbf68ad1800f061638098d76a83681af979dc4eda19d" -dependencies = [ - "adler", - "autocfg", -] - [[package]] name = "mio" version = "0.7.11" From af28d23e6ab8ab5eac38a7453bf9b65d5a80f847 Mon Sep 17 00:00:00 2001 From: "e.g. magical unicorn" Date: Fri, 26 Mar 2021 12:02:45 +0100 Subject: [PATCH 04/27] Why can't you just be normal? remove musl image and replace with the maintained CI Rust image for now. --- backend/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/Dockerfile b/backend/Dockerfile index fb14b46..addeade 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -1,5 +1,5 @@ #### BUILDER IMAGE -- quite big one #### -FROM paritytech/musl-ci-linux as builder +FROM paritytech/ci-linux:production as builder LABEL maintainer="Daniel Maricic daniel@woss.io" LABEL description="Polkadot Telemetry backend builder image" From 2edb9195f638019be7c5ccfd78d93fabab544412 Mon Sep 17 00:00:00 2001 From: David Palm Date: Fri, 26 Mar 2021 12:28:07 +0100 Subject: [PATCH 05/27] Dockerfile fixes --- backend/Dockerfile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/backend/Dockerfile b/backend/Dockerfile index fb14b46..7abbf62 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -1,6 +1,6 @@ #### BUILDER IMAGE -- quite big one #### FROM paritytech/musl-ci-linux as builder -LABEL maintainer="Daniel Maricic daniel@woss.io" +LABEL maintainer="Parity Technologies" LABEL description="Polkadot Telemetry backend builder image" ARG PROFILE=release @@ -8,19 +8,19 @@ WORKDIR /app COPY . . -RUN cargo build --${PROFILE} --bins --target x86_64-unknown-linux-musl +RUN cargo build --${PROFILE} --bins # MAIN IMAGE FOR PEOPLE TO PULL --- small one# FROM scratch -LABEL maintainer="Daniel Maricic daniel@woss.io" +LABEL maintainer="Parity Technologies" LABEL description="Polkadot Telemetry backend, static build" ARG PROFILE=release WORKDIR /usr/local/bin COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ -COPY --from=builder /app/target/x86_64-unknown-linux-musl/$PROFILE/telemetry /usr/local/bin +COPY --from=builder /app/target/$PROFILE/telemetry /usr/local/bin EXPOSE 8000 From 894f7ef742f0b1ac7c270d0cdc146fff90d4f29a Mon Sep 17 00:00:00 2001 From: David Palm Date: Fri, 26 Mar 2021 12:30:12 +0100 Subject: [PATCH 06/27] merge --- backend/Dockerfile | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/backend/Dockerfile b/backend/Dockerfile index 5bb29ea..8178129 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -1,11 +1,6 @@ #### BUILDER IMAGE -- quite big one #### -<<<<<<< HEAD -FROM paritytech/musl-ci-linux as builder -LABEL maintainer="Parity Technologies" -======= FROM paritytech/ci-linux:production as builder -LABEL maintainer="Daniel Maricic daniel@woss.io" ->>>>>>> origin/master +LABEL maintainer="Parity Technologies" LABEL description="Polkadot Telemetry backend builder image" ARG PROFILE=release From f449dc66670db030903b46ec07293bb4e63f5096 Mon Sep 17 00:00:00 2001 From: David Palm Date: Fri, 26 Mar 2021 13:24:54 +0100 Subject: [PATCH 07/27] Add a `Mute` message Send a `Mute` message to `NodeConnector` when a node is from a chain on the denylist OR if the chain is overquota. (Also: dial down logging of finalized blocks a bit) --- backend/src/aggregator.rs | 13 +++++++++---- backend/src/chain.rs | 2 +- backend/src/node/connector.rs | 19 ++++++++++++++++--- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/backend/src/aggregator.rs b/backend/src/aggregator.rs index 10b02a0..459118b 100644 --- a/backend/src/aggregator.rs +++ b/backend/src/aggregator.rs @@ -2,7 +2,7 @@ use std::collections::{HashMap, HashSet}; use actix::prelude::*; use lazy_static::lazy_static; -use crate::node::connector::Initialize; +use crate::node::connector::{Initialize, Mute}; use crate::feed::connector::{FeedConnector, Connected, FeedId}; use crate::util::DenseMap; use crate::feed::{self, FeedMessageSerializer}; @@ -30,7 +30,7 @@ pub struct ChainEntry { } lazy_static! { - /// Labels of chains we consider "first party". These chains are allowed any + /// Labels of chains we consider "first party". These chains allow any /// number of nodes to connect. static ref FIRST_PARTY_NETWORKS: HashSet<&'static str> = { let mut set = HashSet::new(); @@ -131,6 +131,8 @@ pub struct AddNode { pub conn_id: ConnId, /// Recipient for the initialization message pub rec: Recipient, + /// Recipient for the mute message + pub mute: Recipient, } /// Message sent from the Chain to the Aggregator when the Chain loses all nodes @@ -196,10 +198,12 @@ impl Handler for Aggregator { fn handle(&mut self, msg: AddNode, ctx: &mut Self::Context) { if self.denylist.contains(&*msg.node.chain) { - log::debug!(target: "Aggregator::AddNode", "'{}' is on the denylist.", msg.node.chain); + log::warn!(target: "Aggregator::AddNode", "'{}' is on the denylist.", msg.node.chain); + let AddNode { mute, .. } = msg; + let _ = mute.do_send(Mute {}); return; } - let AddNode { node, conn_id, rec } = msg; + let AddNode { node, conn_id, rec, mute } = msg; log::trace!(target: "Aggregator::AddNode", "New node connected. Chain '{}'", node.chain); let cid = self.lazy_chain(&node.chain, ctx); @@ -212,6 +216,7 @@ impl Handler for Aggregator { }); } else { log::warn!(target: "Aggregator::AddNode", "Chain {} is over quota ({})", chain.label, chain.max_nodes); + let _ = mute.do_send(Mute {}); } } } diff --git a/backend/src/chain.rs b/backend/src/chain.rs index 1f4ea4c..bcef302 100644 --- a/backend/src/chain.rs +++ b/backend/src/chain.rs @@ -284,7 +284,7 @@ impl Chain { if node.update_block(*block) { if block.height > self.best.height { self.best = *block; - log::info!( + log::debug!( "[{}] [nodes={}/feeds={}] new best block={}/{:?}", self.label.0, nodes_len, diff --git a/backend/src/node/connector.rs b/backend/src/node/connector.rs index c810b7b..3363751 100644 --- a/backend/src/node/connector.rs +++ b/backend/src/node/connector.rs @@ -109,8 +109,6 @@ impl NodeConnector { ConnMultiplex::Waiting { backlog } => { if let Payload::SystemConnected(connected) = msg.payload() { let mut node = connected.node.clone(); - let rec = ctx.address().recipient(); - // FIXME: Use genesis hash instead of names to avoid this mess match &*node.chain { "Kusama CC3" => node.chain = "Kusama".into(), @@ -123,7 +121,10 @@ impl NodeConnector { _ => () } - self.aggregator.do_send(AddNode { node, conn_id, rec }); + let rec = ctx.address().recipient(); + let mute = ctx.address().recipient(); + + self.aggregator.do_send(AddNode { node, conn_id, rec, mute }); } else { if backlog.len() >= 10 { backlog.remove(0); @@ -157,6 +158,18 @@ impl NodeConnector { } } +#[derive(Message)] +#[rtype(result = "()")] +pub struct Mute; + +impl Handler for NodeConnector { + type Result = (); + fn handle(&mut self, _msg: Mute, ctx: &mut Self::Context) { + log::trace!(target: "NodeConnector::Mute", "Muting a node"); + ctx.stop(); + } +} + #[derive(Message)] #[rtype(result = "()")] pub struct Initialize { From 44eada6eb92f96b48070907864b122d265ebed7c Mon Sep 17 00:00:00 2001 From: Martin Pugh Date: Fri, 26 Mar 2021 13:28:12 +0100 Subject: [PATCH 08/27] update docker actions to v2 --- .github/workflows/backend.yml | 11 ++++++----- .github/workflows/frontend.yml | 13 +++++++------ 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml index c6f6b41..b1a44e5 100644 --- a/.github/workflows/backend.yml +++ b/.github/workflows/backend.yml @@ -22,14 +22,15 @@ jobs: - name: Build release and call executable working-directory: ./backend run: cargo run --release -- --help - - name: Build and Push template image - uses: docker/build-push-action@v1 # https://github.com/docker/build-push-action + - name: Login to Dockerhub + uses: docker/login-action@v1 with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - path: ./backend/ - dockerfile: ./backend/Dockerfile + - name: Build and Push template image + uses: docker/build-push-action@v2 # https://github.com/docker/build-push-action + context: . repository: parity/substrate-telemetry-backend push: ${{ startsWith(github.ref, 'refs/tags/') }} tags: latest - add_git_labels: true + # add_git_labels: true diff --git a/.github/workflows/frontend.yml b/.github/workflows/frontend.yml index f5f7040..fb74543 100644 --- a/.github/workflows/frontend.yml +++ b/.github/workflows/frontend.yml @@ -36,15 +36,16 @@ jobs: - name: Build working-directory: ./frontend run: yarn build - - name: Build and Push template image - uses: docker/build-push-action@v1 # https://github.com/docker/build-push-action - if: matrix.node-version == '12.x' + - name: Login to Dockerhub + uses: docker/login-action@v1 with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - path: ./frontend/ - dockerfile: ./frontend/Dockerfile + - name: Build and Push template image + uses: docker/build-push-action@v2 # https://github.com/docker/build-push-action + if: matrix.node-version == '12.x' + context: ./frontend/ repository: parity/substrate-telemetry-frontend push: ${{ startsWith(github.ref, 'refs/tags/') }} tags: latest - add_git_labels: true + # add_git_labels: true From 9a268c5d4928616b3b5c6e04943da7842a438d81 Mon Sep 17 00:00:00 2001 From: Martin Pugh Date: Fri, 26 Mar 2021 13:29:47 +0100 Subject: [PATCH 09/27] fix strings --- .github/workflows/backend.yml | 2 +- .github/workflows/frontend.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml index b1a44e5..7bce742 100644 --- a/.github/workflows/backend.yml +++ b/.github/workflows/backend.yml @@ -29,7 +29,7 @@ jobs: password: ${{ secrets.DOCKER_PASSWORD }} - name: Build and Push template image uses: docker/build-push-action@v2 # https://github.com/docker/build-push-action - context: . + context: './backend' repository: parity/substrate-telemetry-backend push: ${{ startsWith(github.ref, 'refs/tags/') }} tags: latest diff --git a/.github/workflows/frontend.yml b/.github/workflows/frontend.yml index fb74543..c06b2e8 100644 --- a/.github/workflows/frontend.yml +++ b/.github/workflows/frontend.yml @@ -44,7 +44,7 @@ jobs: - name: Build and Push template image uses: docker/build-push-action@v2 # https://github.com/docker/build-push-action if: matrix.node-version == '12.x' - context: ./frontend/ + context: './frontend' repository: parity/substrate-telemetry-frontend push: ${{ startsWith(github.ref, 'refs/tags/') }} tags: latest From 673a649a9c0f0aeeeac6fb1417e1879d02169f07 Mon Sep 17 00:00:00 2001 From: Martin Pugh Date: Fri, 26 Mar 2021 13:30:48 +0100 Subject: [PATCH 10/27] fix frontend.yml --- .github/workflows/frontend.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/frontend.yml b/.github/workflows/frontend.yml index c06b2e8..d6258c3 100644 --- a/.github/workflows/frontend.yml +++ b/.github/workflows/frontend.yml @@ -44,6 +44,7 @@ jobs: - name: Build and Push template image uses: docker/build-push-action@v2 # https://github.com/docker/build-push-action if: matrix.node-version == '12.x' + with: context: './frontend' repository: parity/substrate-telemetry-frontend push: ${{ startsWith(github.ref, 'refs/tags/') }} From de83475e1029ed0ae5782eee93673a6b68745baf Mon Sep 17 00:00:00 2001 From: Martin Pugh Date: Fri, 26 Mar 2021 13:31:25 +0100 Subject: [PATCH 11/27] fix backend.yml --- .github/workflows/backend.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml index 7bce742..ad30c05 100644 --- a/.github/workflows/backend.yml +++ b/.github/workflows/backend.yml @@ -29,6 +29,7 @@ jobs: password: ${{ secrets.DOCKER_PASSWORD }} - name: Build and Push template image uses: docker/build-push-action@v2 # https://github.com/docker/build-push-action + with: context: './backend' repository: parity/substrate-telemetry-backend push: ${{ startsWith(github.ref, 'refs/tags/') }} From 7fd740e25d10f582f592e935d7c71888fccc8b57 Mon Sep 17 00:00:00 2001 From: Martin Pugh Date: Fri, 26 Mar 2021 13:35:16 +0100 Subject: [PATCH 12/27] fix tags maybe --- .github/workflows/backend.yml | 3 +-- .github/workflows/frontend.yml | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml index ad30c05..cd653c1 100644 --- a/.github/workflows/backend.yml +++ b/.github/workflows/backend.yml @@ -31,7 +31,6 @@ jobs: uses: docker/build-push-action@v2 # https://github.com/docker/build-push-action with: context: './backend' - repository: parity/substrate-telemetry-backend push: ${{ startsWith(github.ref, 'refs/tags/') }} - tags: latest + tags: parity/substrate-telemetry-backend:latest # add_git_labels: true diff --git a/.github/workflows/frontend.yml b/.github/workflows/frontend.yml index d6258c3..4c739d2 100644 --- a/.github/workflows/frontend.yml +++ b/.github/workflows/frontend.yml @@ -46,7 +46,6 @@ jobs: if: matrix.node-version == '12.x' with: context: './frontend' - repository: parity/substrate-telemetry-frontend push: ${{ startsWith(github.ref, 'refs/tags/') }} - tags: latest + tags: parity/substrate-telemetry-frontend:latest # add_git_labels: true From ac8a4c4d8b6bf51ac36e326c5cb514e0a44f913c Mon Sep 17 00:00:00 2001 From: Martin Pugh Date: Fri, 26 Mar 2021 13:38:54 +0100 Subject: [PATCH 13/27] lets run CI when CI gets updated.... --- .github/workflows/backend.yml | 1 + .github/workflows/frontend.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml index cd653c1..796dc6f 100644 --- a/.github/workflows/backend.yml +++ b/.github/workflows/backend.yml @@ -3,6 +3,7 @@ name: Backend CI on: push: paths: + - '.github/workflows/**' - 'backend/**' - '!frontend/**' diff --git a/.github/workflows/frontend.yml b/.github/workflows/frontend.yml index 4c739d2..b6b55ef 100644 --- a/.github/workflows/frontend.yml +++ b/.github/workflows/frontend.yml @@ -6,6 +6,7 @@ name: Frontend CI on: push: paths: + - '.github/workflows/**' - 'frontend/**' - '!backend/**' From 600ed304e357db46be2f1b7e4d6a3b831a5528ca Mon Sep 17 00:00:00 2001 From: Martin Pugh Date: Fri, 26 Mar 2021 17:20:43 +0100 Subject: [PATCH 14/27] Revert "Why can't you just be normal?" This reverts commit af28d23e6ab8ab5eac38a7453bf9b65d5a80f847. --- backend/Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/Dockerfile b/backend/Dockerfile index 8178129..00f9f07 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -1,5 +1,5 @@ #### BUILDER IMAGE -- quite big one #### -FROM paritytech/ci-linux:production as builder +FROM paritytech/musl-ci-linux as builder LABEL maintainer="Parity Technologies" LABEL description="Polkadot Telemetry backend builder image" @@ -20,7 +20,7 @@ ARG PROFILE=release WORKDIR /usr/local/bin COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ -COPY --from=builder /app/target/$PROFILE/telemetry /usr/local/bin +COPY --from=builder /app/target/x86_64-unknown-linux-musl/$PROFILE/telemetry /usr/local/bin EXPOSE 8000 From 30492d2874f79894b03cf0b252a416d100019e55 Mon Sep 17 00:00:00 2001 From: Martin Pugh Date: Fri, 26 Mar 2021 17:33:16 +0100 Subject: [PATCH 15/27] point to latest --- backend/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/Dockerfile b/backend/Dockerfile index 00f9f07..013df37 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -1,5 +1,5 @@ #### BUILDER IMAGE -- quite big one #### -FROM paritytech/musl-ci-linux as builder +FROM paritytech/musl-ci-linux:latest as builder LABEL maintainer="Parity Technologies" LABEL description="Polkadot Telemetry backend builder image" From 9746a420d783ded205476823e5c657bfd6392fed Mon Sep 17 00:00:00 2001 From: Martin Pugh Date: Fri, 26 Mar 2021 17:51:59 +0100 Subject: [PATCH 16/27] smdh... --- backend/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/Dockerfile b/backend/Dockerfile index 013df37..41bf56b 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -8,7 +8,7 @@ WORKDIR /app COPY . . -RUN cargo build --${PROFILE} --bins +RUN cargo build --${PROFILE} --bins --target x86_64-unknown-linux-musl # MAIN IMAGE FOR PEOPLE TO PULL --- small one# From 9e8ce96fecc5bc552862e05ef92e51efc1107cb7 Mon Sep 17 00:00:00 2001 From: Martin Pugh Date: Fri, 26 Mar 2021 19:52:10 +0100 Subject: [PATCH 17/27] use alpine --- backend/Dockerfile | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/backend/Dockerfile b/backend/Dockerfile index 41bf56b..85981f9 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -1,15 +1,11 @@ -#### BUILDER IMAGE -- quite big one #### -FROM paritytech/musl-ci-linux:latest as builder -LABEL maintainer="Parity Technologies" -LABEL description="Polkadot Telemetry backend builder image" +FROM rust:alpine as builder ARG PROFILE=release WORKDIR /app COPY . . -RUN cargo build --${PROFILE} --bins --target x86_64-unknown-linux-musl - +RUN apk add musl-dev openssl-dev; cargo build --${PROFILE} --bins # MAIN IMAGE FOR PEOPLE TO PULL --- small one# FROM scratch @@ -20,7 +16,7 @@ ARG PROFILE=release WORKDIR /usr/local/bin COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ -COPY --from=builder /app/target/x86_64-unknown-linux-musl/$PROFILE/telemetry /usr/local/bin +COPY --from=builder /app/target/$PROFILE/telemetry /usr/local/bin EXPOSE 8000 From c1a14a01b6f23e528ab67b50ddccc1e973183bce Mon Sep 17 00:00:00 2001 From: Martin Pugh Date: Fri, 26 Mar 2021 20:20:49 +0100 Subject: [PATCH 18/27] fix backend for real this time --- backend/Dockerfile | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/backend/Dockerfile b/backend/Dockerfile index 85981f9..a19f453 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -1,14 +1,14 @@ -FROM rust:alpine as builder +FROM paritytech/ci-linux:production as builder ARG PROFILE=release WORKDIR /app COPY . . -RUN apk add musl-dev openssl-dev; cargo build --${PROFILE} --bins +RUN cargo build --${PROFILE} --bins # MAIN IMAGE FOR PEOPLE TO PULL --- small one# -FROM scratch +FROM debian:buster-slim LABEL maintainer="Parity Technologies" LABEL description="Polkadot Telemetry backend, static build" @@ -17,6 +17,7 @@ WORKDIR /usr/local/bin COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ COPY --from=builder /app/target/$PROFILE/telemetry /usr/local/bin +RUN apt-get -y update && apt-get -y install openssl && apt-get autoremove -y && apt-get clean && rm -rf /var/lib/apt/lists/ EXPOSE 8000 From d39f6b561769f5b1d0564782fc394e283442f688 Mon Sep 17 00:00:00 2001 From: David Palm Date: Fri, 26 Mar 2021 21:59:36 +0100 Subject: [PATCH 19/27] Fix doc --- backend/src/node/connector.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/node/connector.rs b/backend/src/node/connector.rs index 3363751..dbc3fe2 100644 --- a/backend/src/node/connector.rs +++ b/backend/src/node/connector.rs @@ -24,7 +24,7 @@ const CONT_BUF_LIMIT: usize = 10 * 1024 * 1024; pub struct NodeConnector { /// Multiplexing connections by id multiplex: BTreeMap, - /// Client must send ping at least once per 10 seconds (CLIENT_TIMEOUT), + /// Client must send ping at least once every 60 seconds (CLIENT_TIMEOUT), hb: Instant, /// Aggregator actor address aggregator: Addr, From 9b42bf4af00bac745c6a9514cd8d4e7d970e5a81 Mon Sep 17 00:00:00 2001 From: David Palm Date: Fri, 26 Mar 2021 23:06:52 +0100 Subject: [PATCH 20/27] Close websocket with a reason when muting --- backend/src/aggregator.rs | 9 ++++++--- backend/src/node/connector.rs | 16 +++++++++++----- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/backend/src/aggregator.rs b/backend/src/aggregator.rs index 459118b..05d9970 100644 --- a/backend/src/aggregator.rs +++ b/backend/src/aggregator.rs @@ -1,5 +1,6 @@ use std::collections::{HashMap, HashSet}; use actix::prelude::*; +use actix_web_actors::ws::{CloseReason, CloseCode}; use lazy_static::lazy_static; use crate::node::connector::{Initialize, Mute}; @@ -42,7 +43,7 @@ lazy_static! { }; } /// Max number of nodes allowed to connect to the telemetry server. -const THIRD_PARTY_NETWORKS_MAX_NODES: usize = 500; +const THIRD_PARTY_NETWORKS_MAX_NODES: usize = 2; impl Aggregator { pub fn new(denylist: HashSet) -> Self { @@ -200,7 +201,8 @@ impl Handler for Aggregator { if self.denylist.contains(&*msg.node.chain) { log::warn!(target: "Aggregator::AddNode", "'{}' is on the denylist.", msg.node.chain); let AddNode { mute, .. } = msg; - let _ = mute.do_send(Mute {}); + let reason = CloseReason{ code: CloseCode::Abnormal, description: Some("Denied".into()) }; + let _ = mute.do_send(Mute { reason }); return; } let AddNode { node, conn_id, rec, mute } = msg; @@ -216,7 +218,8 @@ impl Handler for Aggregator { }); } else { log::warn!(target: "Aggregator::AddNode", "Chain {} is over quota ({})", chain.label, chain.max_nodes); - let _ = mute.do_send(Mute {}); + let reason = CloseReason{ code: CloseCode::Again, description: Some("Overquota".into()) }; + let _ = mute.do_send(Mute { reason }); } } } diff --git a/backend/src/node/connector.rs b/backend/src/node/connector.rs index dbc3fe2..eef8f2b 100644 --- a/backend/src/node/connector.rs +++ b/backend/src/node/connector.rs @@ -5,7 +5,7 @@ use std::mem; use bytes::{Bytes, BytesMut}; use actix::prelude::*; -use actix_web_actors::ws; +use actix_web_actors::ws::{self, CloseReason}; use actix_http::ws::Item; use crate::aggregator::{Aggregator, AddNode}; use crate::chain::{Chain, UpdateNode, RemoveNode}; @@ -160,12 +160,17 @@ impl NodeConnector { #[derive(Message)] #[rtype(result = "()")] -pub struct Mute; +pub struct Mute { + pub reason: CloseReason, +} impl Handler for NodeConnector { type Result = (); - fn handle(&mut self, _msg: Mute, ctx: &mut Self::Context) { - log::trace!(target: "NodeConnector::Mute", "Muting a node"); + fn handle(&mut self, msg: Mute, ctx: &mut Self::Context) { + let Mute { reason } = msg; + log::debug!(target: "NodeConnector::Mute", "Muting a node. Reason: {:?}", reason.description); + + ctx.close(Some(reason)); ctx.stop(); } } @@ -216,7 +221,8 @@ impl StreamHandler> for NodeConnector { Ok(ws::Message::Pong(_)) => return, Ok(ws::Message::Text(text)) => text.into_bytes(), Ok(ws::Message::Binary(data)) => data, - Ok(ws::Message::Close(_)) => { + Ok(ws::Message::Close(reason)) => { + ctx.close(reason); ctx.stop(); return; } From 3d6bdbcef6a3299afcc210f587ef88f3204c6e3a Mon Sep 17 00:00:00 2001 From: David Date: Sat, 27 Mar 2021 22:08:12 +0100 Subject: [PATCH 21/27] Update backend/src/aggregator.rs Co-authored-by: Maciej Hirsz <1096222+maciejhirsz@users.noreply.github.com> --- backend/src/aggregator.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/aggregator.rs b/backend/src/aggregator.rs index 05d9970..94c4df3 100644 --- a/backend/src/aggregator.rs +++ b/backend/src/aggregator.rs @@ -131,7 +131,7 @@ pub struct AddNode { /// Connection id used by the node connector for multiplexing parachains pub conn_id: ConnId, /// Recipient for the initialization message - pub rec: Recipient, + pub rec: Addr, /// Recipient for the mute message pub mute: Recipient, } From 5571cf85e5d2a5000e4547c83b8bcc73bcc7c84b Mon Sep 17 00:00:00 2001 From: David Date: Sat, 27 Mar 2021 22:08:25 +0100 Subject: [PATCH 22/27] Update backend/src/aggregator.rs Co-authored-by: Maciej Hirsz <1096222+maciejhirsz@users.noreply.github.com> --- backend/src/aggregator.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/aggregator.rs b/backend/src/aggregator.rs index 94c4df3..ad27b90 100644 --- a/backend/src/aggregator.rs +++ b/backend/src/aggregator.rs @@ -205,7 +205,7 @@ impl Handler for Aggregator { let _ = mute.do_send(Mute { reason }); return; } - let AddNode { node, conn_id, rec, mute } = msg; + let AddNode { node, conn_id, rec } = msg; log::trace!(target: "Aggregator::AddNode", "New node connected. Chain '{}'", node.chain); let cid = self.lazy_chain(&node.chain, ctx); From 41a6060be70b09379691f2a0cc3d550352283b89 Mon Sep 17 00:00:00 2001 From: David Date: Sat, 27 Mar 2021 22:08:32 +0100 Subject: [PATCH 23/27] Update backend/src/aggregator.rs Co-authored-by: Maciej Hirsz <1096222+maciejhirsz@users.noreply.github.com> --- backend/src/aggregator.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/aggregator.rs b/backend/src/aggregator.rs index ad27b90..3d9c489 100644 --- a/backend/src/aggregator.rs +++ b/backend/src/aggregator.rs @@ -219,7 +219,7 @@ impl Handler for Aggregator { } else { log::warn!(target: "Aggregator::AddNode", "Chain {} is over quota ({})", chain.label, chain.max_nodes); let reason = CloseReason{ code: CloseCode::Again, description: Some("Overquota".into()) }; - let _ = mute.do_send(Mute { reason }); + let _ = rec.do_send(Mute { reason }); } } } From 47f5df81047086fd813fbda43201931561b57efe Mon Sep 17 00:00:00 2001 From: David Date: Sat, 27 Mar 2021 22:08:43 +0100 Subject: [PATCH 24/27] Update backend/src/node/connector.rs Co-authored-by: Maciej Hirsz <1096222+maciejhirsz@users.noreply.github.com> --- backend/src/node/connector.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/backend/src/node/connector.rs b/backend/src/node/connector.rs index eef8f2b..9a558da 100644 --- a/backend/src/node/connector.rs +++ b/backend/src/node/connector.rs @@ -121,10 +121,8 @@ impl NodeConnector { _ => () } - let rec = ctx.address().recipient(); - let mute = ctx.address().recipient(); - - self.aggregator.do_send(AddNode { node, conn_id, rec, mute }); + let rec = ctx.address(); + self.aggregator.do_send(AddNode { node, conn_id, rec }); } else { if backlog.len() >= 10 { backlog.remove(0); From 8d2441b7fb8d6824621f104207cfe87516198a99 Mon Sep 17 00:00:00 2001 From: David Palm Date: Sat, 27 Mar 2021 22:36:03 +0100 Subject: [PATCH 25/27] No need for duplicate refs to the NodeConnector Addr's version of `do_send` does not return `Result` --- backend/src/aggregator.rs | 18 ++++++++---------- backend/src/chain.rs | 10 +++++----- backend/src/node/connector.rs | 3 +-- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/backend/src/aggregator.rs b/backend/src/aggregator.rs index 3d9c489..253a2b8 100644 --- a/backend/src/aggregator.rs +++ b/backend/src/aggregator.rs @@ -3,7 +3,7 @@ use actix::prelude::*; use actix_web_actors::ws::{CloseReason, CloseCode}; use lazy_static::lazy_static; -use crate::node::connector::{Initialize, Mute}; +use crate::node::connector::{Mute, NodeConnector}; use crate::feed::connector::{FeedConnector, Connected, FeedId}; use crate::util::DenseMap; use crate::feed::{self, FeedMessageSerializer}; @@ -130,10 +130,8 @@ pub struct AddNode { pub node: NodeDetails, /// Connection id used by the node connector for multiplexing parachains pub conn_id: ConnId, - /// Recipient for the initialization message - pub rec: Addr, - /// Recipient for the mute message - pub mute: Recipient, + /// Address of the NodeConnector actor + pub node_connector: Addr, } /// Message sent from the Chain to the Aggregator when the Chain loses all nodes @@ -200,12 +198,12 @@ impl Handler for Aggregator { fn handle(&mut self, msg: AddNode, ctx: &mut Self::Context) { if self.denylist.contains(&*msg.node.chain) { log::warn!(target: "Aggregator::AddNode", "'{}' is on the denylist.", msg.node.chain); - let AddNode { mute, .. } = msg; + let AddNode { node_connector, .. } = msg; let reason = CloseReason{ code: CloseCode::Abnormal, description: Some("Denied".into()) }; - let _ = mute.do_send(Mute { reason }); + node_connector.do_send(Mute { reason }); return; } - let AddNode { node, conn_id, rec } = msg; + let AddNode { node, conn_id, node_connector } = msg; log::trace!(target: "Aggregator::AddNode", "New node connected. Chain '{}'", node.chain); let cid = self.lazy_chain(&node.chain, ctx); @@ -214,12 +212,12 @@ impl Handler for Aggregator { chain.addr.do_send(chain::AddNode { node, conn_id, - rec, + node_connector, }); } else { log::warn!(target: "Aggregator::AddNode", "Chain {} is over quota ({})", chain.label, chain.max_nodes); let reason = CloseReason{ code: CloseCode::Again, description: Some("Overquota".into()) }; - let _ = rec.do_send(Mute { reason }); + node_connector.do_send(Mute { reason }); } } } diff --git a/backend/src/chain.rs b/backend/src/chain.rs index bcef302..1db3e11 100644 --- a/backend/src/chain.rs +++ b/backend/src/chain.rs @@ -5,7 +5,7 @@ use bytes::Bytes; use rustc_hash::FxHashMap; use crate::aggregator::{Aggregator, DropChain, RenameChain, NodeCount}; -use crate::node::{Node, connector::Initialize, message::{NodeMessage, Payload}}; +use crate::node::{Node, connector::{Initialize, NodeConnector}, message::{NodeMessage, Payload}}; use crate::feed::connector::{FeedId, FeedConnector, Subscribed, Unsubscribed}; use crate::feed::{self, FeedMessageSerializer}; use crate::util::{DenseMap, NumStats, now}; @@ -196,8 +196,8 @@ pub struct AddNode { pub node: NodeDetails, /// Connection id used by the node connector for multiplexing parachains pub conn_id: ConnId, - /// Recipient for the initialization message - pub rec: Recipient, + /// Address of the NodeConnector actor to which we send [`Initialize`] or [`Mute`] messages. + pub node_connector: Addr, } /// Message sent from the NodeConnector to the Chain when it receives new telemetry data @@ -250,14 +250,14 @@ impl Handler for Chain { type Result = (); fn handle(&mut self, msg: AddNode, ctx: &mut Self::Context) { - let AddNode { node, conn_id, rec } = msg; + let AddNode { node, conn_id, node_connector } = msg; log::trace!(target: "Chain::AddNode", "New node connected. Chain '{}', node count goes from {} to {}", node.chain, self.nodes.len(), self.nodes.len() + 1); self.increment_label_count(&node.chain); let nid = self.nodes.add(Node::new(node)); let chain = ctx.address(); - if rec.do_send(Initialize { nid, conn_id, chain }).is_err() { + if node_connector.try_send(Initialize { nid, conn_id, chain }).is_err() { self.nodes.remove(nid); } else if let Some(node) = self.nodes.get(nid) { self.serializer.push(feed::AddedNode(nid, node)); diff --git a/backend/src/node/connector.rs b/backend/src/node/connector.rs index 9a558da..d1aa5fd 100644 --- a/backend/src/node/connector.rs +++ b/backend/src/node/connector.rs @@ -121,8 +121,7 @@ impl NodeConnector { _ => () } - let rec = ctx.address(); - self.aggregator.do_send(AddNode { node, conn_id, rec }); + self.aggregator.do_send(AddNode { node, conn_id, node_connector: ctx.address() }); } else { if backlog.len() >= 10 { backlog.remove(0); From bbfe118965cdf4b8d1f4b6a7d217799c2e7ed75f Mon Sep 17 00:00:00 2001 From: David Palm Date: Sat, 27 Mar 2021 23:00:36 +0100 Subject: [PATCH 26/27] Use ctor instead of lazy_static --- backend/Cargo.lock | 20 +++++++++++++++----- backend/Cargo.toml | 2 +- backend/src/aggregator.rs | 28 ++++++++++++++-------------- 3 files changed, 30 insertions(+), 20 deletions(-) diff --git a/backend/Cargo.lock b/backend/Cargo.lock index 8e11065..5a459e1 100644 --- a/backend/Cargo.lock +++ b/backend/Cargo.lock @@ -588,6 +588,16 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" +[[package]] +name = "ctor" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e98e2ad1a782e33928b96fc3948e7c355e5af34ba4de7670fe8bac2a3b2006d" +dependencies = [ + "quote", + "syn", +] + [[package]] name = "derive_more" version = "0.99.11" @@ -1303,9 +1313,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.7" +version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37" +checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7" dependencies = [ "proc-macro2", ] @@ -1726,9 +1736,9 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "syn" -version = "1.0.48" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc371affeffc477f42a221a1e4297aedcea33d47d19b61455588bd9d8f6b19ac" +checksum = "f3a1d708c221c5a612956ef9f75b37e454e88d1f7b899fbd3a18d4252012d663" dependencies = [ "proc-macro2", "quote", @@ -1752,8 +1762,8 @@ dependencies = [ "bytes", "chrono", "clap", + "ctor", "fnv", - "lazy_static", "log", "num-traits", "parking_lot", diff --git a/backend/Cargo.toml b/backend/Cargo.toml index 70f5030..be0dcb6 100644 --- a/backend/Cargo.toml +++ b/backend/Cargo.toml @@ -23,7 +23,7 @@ parking_lot = "0.11" reqwest = { version = "0.11.1", features = ["blocking", "json"] } rustc-hash = "1.1.0" clap = "3.0.0-beta.2" -lazy_static = "1" +ctor = "0.1.20" [profile.release] lto = true diff --git a/backend/src/aggregator.rs b/backend/src/aggregator.rs index 253a2b8..205899d 100644 --- a/backend/src/aggregator.rs +++ b/backend/src/aggregator.rs @@ -1,7 +1,7 @@ use std::collections::{HashMap, HashSet}; use actix::prelude::*; use actix_web_actors::ws::{CloseReason, CloseCode}; -use lazy_static::lazy_static; +use ctor::ctor; use crate::node::connector::{Mute, NodeConnector}; use crate::feed::connector::{FeedConnector, Connected, FeedId}; @@ -30,20 +30,20 @@ pub struct ChainEntry { max_nodes: usize, } -lazy_static! { - /// Labels of chains we consider "first party". These chains allow any - /// number of nodes to connect. - static ref FIRST_PARTY_NETWORKS: HashSet<&'static str> = { - let mut set = HashSet::new(); - set.insert("Polkadot"); - set.insert("Kusama"); - set.insert("Westend"); - set.insert("Rococo"); - set - }; -} +#[ctor] +/// Labels of chains we consider "first party". These chains allow any +/// number of nodes to connect. +static FIRST_PARTY_NETWORKS: HashSet<&'static str> = { + let mut set = HashSet::new(); + set.insert("Polkadot"); + set.insert("Kusama"); + set.insert("Westend"); + set.insert("Rococo"); + set +}; + /// Max number of nodes allowed to connect to the telemetry server. -const THIRD_PARTY_NETWORKS_MAX_NODES: usize = 2; +const THIRD_PARTY_NETWORKS_MAX_NODES: usize = 500; impl Aggregator { pub fn new(denylist: HashSet) -> Self { From f328b5f5d3f2c61a0621d25b9b59157fe38a07a7 Mon Sep 17 00:00:00 2001 From: David Palm Date: Mon, 29 Mar 2021 22:13:14 +0200 Subject: [PATCH 27/27] =?UTF-8?q?No=20use=20denying=20"Earth"=20=E2=80=93?= =?UTF-8?q?=20they=20renamed=20Send=20Close=20frame=20with=20reason=20when?= =?UTF-8?q?=20the=20remote=20missed=20a=20heartbeat?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/node/connector.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/backend/src/node/connector.rs b/backend/src/node/connector.rs index d1aa5fd..fc71a19 100644 --- a/backend/src/node/connector.rs +++ b/backend/src/node/connector.rs @@ -90,6 +90,7 @@ impl NodeConnector { // check client heartbeats if Instant::now().duration_since(act.hb) > CLIENT_TIMEOUT { // stop actor + ctx.close(Some(CloseReason { code: ws::CloseCode::Abnormal, description: Some("Missed heartbeat".into())})); ctx.stop(); } }); @@ -113,11 +114,6 @@ impl NodeConnector { match &*node.chain { "Kusama CC3" => node.chain = "Kusama".into(), "Polkadot CC1" => node.chain = "Polkadot".into(), - "Earth" => { - // Temp, there is too many of them - ctx.stop(); - return; - }, _ => () }