diff --git a/.github/workflows/e2e-tests-main-devnet.yml b/.github/workflows/e2e-tests-main-devnet.yml index 4496db3c09..9f1547e4c8 100644 --- a/.github/workflows/e2e-tests-main-devnet.yml +++ b/.github/workflows/e2e-tests-main-devnet.yml @@ -439,23 +439,23 @@ jobs: follow-up-finalization-check: true timeout-minutes: 10 - run-e2e-authorities-are-staking: - needs: [build-test-docker, build-test-client] - name: Run authorities are staking test - runs-on: ubuntu-20.04 - steps: - - name: Checkout source code - uses: actions/checkout@v2 - - - name: Run e2e test - uses: ./.github/actions/run-e2e-test - with: - test-case: authorities_are_staking - node-count: 6 - reserved-seats: 3 - non-reserved-seats: 3 - follow-up-finalization-check: false - timeout-minutes: 15 +# run-e2e-authorities-are-staking: +# needs: [build-test-docker, build-test-client] +# name: Run authorities are staking test +# runs-on: ubuntu-20.04 +# steps: +# - name: Checkout source code +# uses: actions/checkout@v2 +# +# - name: Run e2e test +# uses: ./.github/actions/run-e2e-test +# with: +# test-case: authorities_are_staking +# node-count: 6 +# reserved-seats: 3 +# non-reserved-seats: 3 +# follow-up-finalization-check: false +# timeout-minutes: 15 run-e2e-ban-automatic: needs: [build-test-docker, build-test-client] @@ -535,85 +535,87 @@ jobs: UPGRADE_FINALIZATION_WAIT_SESSIONS: 2 timeout-minutes: 10 - run-e2e-failing-version-upgrade: - needs: [build-test-docker, build-test-client] - name: Run basic (failing) version-upgrade test - runs-on: ubuntu-20.04 - steps: - - name: Checkout source code - uses: actions/checkout@v2 - - - name: Run e2e test - uses: ./.github/actions/run-e2e-test - with: - test-case: doomed_version_upgrade - env: - OVERRIDE_DOCKER_COMPOSE: ./.github/scripts/docker-compose.no_quorum_without_old.override.yml - UPGRADE_VERSION: 1 - UPGRADE_SESSION: 3 - UPGRADE_FINALIZATION_WAIT_SESSIONS: 2 - ONLY_LEGACY: true - timeout-minutes: 10 - - run-e2e-version-upgrade-catchup: - needs: [build-test-docker, build-cliain-image] - name: Run series of tests where some of the nodes need to do version-upgrade during catch-up - runs-on: ubuntu-20.04 - strategy: - matrix: - include: - - nodes: "Node1" - ports: "9934" - ext_status: "finalized" - upgrade_before_disable: "true" - - - nodes: "Node1" - ports: "9934" - ext_status: "finalized" - upgrade_before_disable: "false" - - - nodes: "Node1:Node2" - ports: "9934:9935" - ext_status: "in-block" - upgrade_before_disable: "true" - - - nodes: "Node1:Node2" - ports: "9934:9935" - ext_status: "in-block" - upgrade_before_disable: "false" - steps: - - name: Checkout source code - uses: actions/checkout@v2 - - - name: Download artifact with docker image for aleph-node - uses: actions/download-artifact@v2 - with: - name: aleph-test-docker - - - name: Load node docker image - shell: bash - run: docker load -i aleph-node.tar - - - name: Download artifact with docker image for cliain - uses: actions/download-artifact@v2 - with: - name: cliain-docker - - - name: Load cliain docker image - shell: bash - run: docker load -i cliain.tar - - - name: Call catchup_test.sh - timeout-minutes: 10 - env: - UPGRADE_BLOCK: 31 - NODES: ${{ matrix.nodes }} - PORTS: ${{ matrix.ports }} - EXT_STATUS: ${{ matrix.ext_status }} - UPGRADE_BEFORE_DISABLE: ${{ matrix.upgrade_before_disable }} - DOCKER_COMPOSE: docker/docker-compose.bridged.yml - run: | - ./scripts/catchup_version_upgrade_test.sh +# The tests below were written under the assumption that nonfinalized blocks are being produced, they need a rewrite before being reenabled. +# TODO(A0-1644): Reenable these tests. +# run-e2e-failing-version-upgrade: +# needs: [build-test-docker, build-test-client] +# name: Run basic (failing) version-upgrade test +# runs-on: ubuntu-20.04 +# steps: +# - name: Checkout source code +# uses: actions/checkout@v2 +# +# - name: Run e2e test +# uses: ./.github/actions/run-e2e-test +# with: +# test-case: doomed_version_upgrade +# env: +# OVERRIDE_DOCKER_COMPOSE: ./.github/scripts/docker-compose.no_quorum_without_old.override.yml +# UPGRADE_VERSION: 1 +# UPGRADE_SESSION: 3 +# UPGRADE_FINALIZATION_WAIT_SESSIONS: 2 +# ONLY_LEGACY: true +# timeout-minutes: 10 + +# run-e2e-version-upgrade-catchup: +# needs: [build-test-docker, build-cliain-image] +# name: Run series of tests where some of the nodes need to do version-upgrade during catch-up +# runs-on: ubuntu-20.04 +# strategy: +# matrix: +# include: +# - nodes: "Node1" +# ports: "9934" +# ext_status: "finalized" +# upgrade_before_disable: "true" +# +# - nodes: "Node1" +# ports: "9934" +# ext_status: "finalized" +# upgrade_before_disable: "false" +# +# - nodes: "Node1:Node2" +# ports: "9934:9935" +# ext_status: "in-block" +# upgrade_before_disable: "true" +# +# - nodes: "Node1:Node2" +# ports: "9934:9935" +# ext_status: "in-block" +# upgrade_before_disable: "false" +# steps: +# - name: Checkout source code +# uses: actions/checkout@v2 +# +# - name: Download artifact with docker image for aleph-node +# uses: actions/download-artifact@v2 +# with: +# name: aleph-test-docker +# +# - name: Load node docker image +# shell: bash +# run: docker load -i aleph-node.tar +# +# - name: Download artifact with docker image for cliain +# uses: actions/download-artifact@v2 +# with: +# name: cliain-docker +# +# - name: Load cliain docker image +# shell: bash +# run: docker load -i cliain.tar +# +# - name: Call catchup_test.sh +# timeout-minutes: 10 +# env: +# UPGRADE_BLOCK: 31 +# NODES: ${{ matrix.nodes }} +# PORTS: ${{ matrix.ports }} +# EXT_STATUS: ${{ matrix.ext_status }} +# UPGRADE_BEFORE_DISABLE: ${{ matrix.upgrade_before_disable }} +# DOCKER_COMPOSE: docker/docker-compose.bridged.yml +# run: | +# ./scripts/catchup_version_upgrade_test.sh check-e2e-test-suite-completion: needs: [ @@ -634,14 +636,14 @@ jobs: run-e2e-rewards-stake-change, run-e2e-rewards-change-stake-force-new-era, run-e2e-rewards-points-basic, - run-e2e-authorities-are-staking, +# run-e2e-authorities-are-staking, run-e2e-ban-automatic, run-e2e-ban-manual, run-e2e-ban-counter-clearing, run-e2e-ban-threshold, run-e2e-version-upgrade, - run-e2e-failing-version-upgrade, - run-e2e-version-upgrade-catchup, +# run-e2e-failing-version-upgrade, +# run-e2e-version-upgrade-catchup, ] name: Check e2e test suite completion runs-on: ubuntu-20.04 diff --git a/Cargo.lock b/Cargo.lock index 8179605794..1d2230e8f9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -250,6 +250,7 @@ dependencies = [ "sc-client-api", "sc-consensus", "sc-consensus-aura", + "sc-consensus-slots", "sc-executor", "sc-keystore", "sc-network", @@ -263,6 +264,7 @@ dependencies = [ "serde_json", "sp-api", "sp-application-crypto", + "sp-arithmetic", "sp-block-builder", "sp-blockchain", "sp-consensus", diff --git a/bin/node/Cargo.toml b/bin/node/Cargo.toml index 50a67e406e..f414bcce88 100644 --- a/bin/node/Cargo.toml +++ b/bin/node/Cargo.toml @@ -43,6 +43,8 @@ sc-network = { git = "https://github.com/Cardinal-Cryptography/substrate.git", b sc-transaction-pool = { git = "https://github.com/Cardinal-Cryptography/substrate.git", branch = "aleph-v0.9.30" } sp-transaction-pool = { git = "https://github.com/Cardinal-Cryptography/substrate.git", branch = "aleph-v0.9.30" } sc-transaction-pool-api = { git = "https://github.com/Cardinal-Cryptography/substrate.git", branch = "aleph-v0.9.30" } +sp-arithmetic = { git = "https://github.com/Cardinal-Cryptography/substrate.git", branch = "aleph-v0.9.30" } +sc-consensus-slots = { git = "https://github.com/Cardinal-Cryptography/substrate.git", branch = "aleph-v0.9.30" } sc-consensus-aura = { git = "https://github.com/Cardinal-Cryptography/substrate.git", branch = "aleph-v0.9.30" } sp-consensus-aura = { git = "https://github.com/Cardinal-Cryptography/substrate.git", branch = "aleph-v0.9.30" } sp-consensus = { git = "https://github.com/Cardinal-Cryptography/substrate.git", branch = "aleph-v0.9.30" } diff --git a/bin/node/src/aleph_cli.rs b/bin/node/src/aleph_cli.rs index c43c3e336f..f2324c14b2 100644 --- a/bin/node/src/aleph_cli.rs +++ b/bin/node/src/aleph_cli.rs @@ -3,6 +3,7 @@ use std::path::PathBuf; use aleph_primitives::DEFAULT_UNIT_CREATION_DELAY; use clap::{ArgGroup, Parser}; use finality_aleph::UnitCreationDelay; +use log::warn; #[derive(Debug, Parser, Clone)] #[clap(group(ArgGroup::new("backup")))] @@ -33,6 +34,12 @@ pub struct AlephCli { /// with `--no-backup`, but note that that limits crash recoverability. #[clap(long, value_name = "PATH", group = "backup")] backup_path: Option, + + /// The maximum number of nonfinalized blocks, after which block production should be locally + /// stopped. DO NOT CHANGE THIS, PRODUCING MORE OR FEWER BLOCKS MIGHT BE CONSIDERED MALICIOUS + /// BEHAVIOUR AND PUNISHED ACCORDINGLY! + #[clap(long, default_value_t = 20)] + max_nonfinalized_blocks: u32, } impl AlephCli { @@ -55,4 +62,11 @@ impl AlephCli { pub fn no_backup(&self) -> bool { self.no_backup } + + pub fn max_nonfinalized_blocks(&self) -> u32 { + if self.max_nonfinalized_blocks != 20 { + warn!("Running block production with a value of max-nonfinalized-blocks {}, which is not the default of 20. THIS MIGHT BE CONSIDERED MALICIOUS BEHAVIOUR AND RESULT IN PENALTIES!", self.max_nonfinalized_blocks); + } + self.max_nonfinalized_blocks + } } diff --git a/bin/node/src/service.rs b/bin/node/src/service.rs index 561899ef35..044cfa2021 100644 --- a/bin/node/src/service.rs +++ b/bin/node/src/service.rs @@ -15,6 +15,7 @@ use futures::channel::mpsc; use log::warn; use sc_client_api::{Backend, HeaderBackend}; use sc_consensus_aura::{ImportQueueParams, SlotProportion, StartAuraParams}; +use sc_consensus_slots::BackoffAuthoringBlocksStrategy; use sc_network::NetworkService; use sc_service::{ error::Error as ServiceError, Configuration, KeystoreContainer, NetworkStarter, RpcHandlers, @@ -22,8 +23,9 @@ use sc_service::{ }; use sc_telemetry::{Telemetry, TelemetryWorker}; use sp_api::ProvideRuntimeApi; +use sp_arithmetic::traits::BaseArithmetic; use sp_blockchain::Backend as _; -use sp_consensus_aura::sr25519::AuthorityPair as AuraPair; +use sp_consensus_aura::{sr25519::AuthorityPair as AuraPair, Slot}; use sp_runtime::{ generic::BlockId, traits::{Block as BlockT, Header as HeaderT, Zero}, @@ -35,6 +37,30 @@ type FullClient = sc_service::TFullClient; type FullBackend = sc_service::TFullBackend; type FullSelectChain = sc_consensus::LongestChain; +struct LimitNonfinalized(u32); + +impl BackoffAuthoringBlocksStrategy for LimitNonfinalized { + fn should_backoff( + &self, + chain_head_number: N, + _chain_head_slot: Slot, + finalized_number: N, + _slow_now: Slot, + _logging_target: &str, + ) -> bool { + let nonfinalized_blocks: u32 = chain_head_number + .saturating_sub(finalized_number) + .unique_saturated_into(); + match nonfinalized_blocks >= self.0 { + true => { + warn!("We have {} nonfinalized blocks, with the limit being {}, delaying block production.", nonfinalized_blocks, self.0); + true + } + false => false, + } + } +} + fn backup_path(aleph_config: &AlephCli, base_path: &Path) -> Option { if aleph_config.no_backup() { return None; @@ -279,7 +305,7 @@ pub fn new_authority( ); let force_authoring = config.force_authoring; - let backoff_authoring_blocks: Option<()> = None; + let backoff_authoring_blocks = Some(LimitNonfinalized(aleph_config.max_nonfinalized_blocks())); let prometheus_registry = config.prometheus_registry().cloned(); let (_rpc_handlers, network, network_starter) = setup(