diff --git a/.github/workflows/e2e-tests-main-devnet.yml b/.github/workflows/e2e-tests-main-devnet.yml index 2c4bf8d040..95dc16e129 100644 --- a/.github/workflows/e2e-tests-main-devnet.yml +++ b/.github/workflows/e2e-tests-main-devnet.yml @@ -454,7 +454,7 @@ 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-version-upgrade, ] diff --git a/Cargo.lock b/Cargo.lock index 19c9d7a2c8..77a28868de 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -227,7 +227,7 @@ dependencies = [ [[package]] name = "aleph-node" -version = "0.8.1" +version = "0.8.2" dependencies = [ "aleph-runtime", "clap", @@ -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 08af44903c..e2f4b4998a 100644 --- a/bin/node/Cargo.toml +++ b/bin/node/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "aleph-node" -version = "0.8.1" +version = "0.8.2" authors = ["Cardinal Cryptography"] description = "Aleph node binary" edition = "2021" @@ -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.28" } sp-transaction-pool = { git = "https://github.com/Cardinal-Cryptography/substrate.git", branch = "aleph-v0.9.28" } sc-transaction-pool-api = { git = "https://github.com/Cardinal-Cryptography/substrate.git", branch = "aleph-v0.9.28" } +sp-arithmetic = { git = "https://github.com/Cardinal-Cryptography/substrate.git", branch = "aleph-v0.9.28" } +sc-consensus-slots = { git = "https://github.com/Cardinal-Cryptography/substrate.git", branch = "aleph-v0.9.28" } sc-consensus-aura = { git = "https://github.com/Cardinal-Cryptography/substrate.git", branch = "aleph-v0.9.28" } sp-consensus-aura = { git = "https://github.com/Cardinal-Cryptography/substrate.git", branch = "aleph-v0.9.28" } sp-consensus = { git = "https://github.com/Cardinal-Cryptography/substrate.git", branch = "aleph-v0.9.28" } 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 dc959eed0a..7fdf2e2d4a 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, ExecutorProvider, 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; @@ -289,7 +315,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(