Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/e2e-tests-main-devnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]
Expand Down
16 changes: 9 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion bin/node/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "aleph-node"
version = "0.8.0+mainnet"
version = "0.8.2+mainnet"
authors = ["Cardinal Cryptography"]
description = "Aleph node binary"
edition = "2021"
Expand Down Expand Up @@ -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" }
Expand Down
14 changes: 14 additions & 0 deletions bin/node/src/aleph_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")))]
Expand Down Expand Up @@ -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<PathBuf>,

/// 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 {
Expand All @@ -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
}
}
68 changes: 60 additions & 8 deletions bin/node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,19 @@ use finality_aleph::{
};
use futures::channel::mpsc;
use log::warn;
use sc_client_api::ExecutorProvider;
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,
TFullClient, TaskManager,
};
use sc_telemetry::{Telemetry, TelemetryWorker};
use sp_api::ProvideRuntimeApi;
use sp_consensus_aura::sr25519::AuthorityPair as AuraPair;
use sp_arithmetic::traits::BaseArithmetic;
use sp_blockchain::Backend as _;
use sp_consensus_aura::{sr25519::AuthorityPair as AuraPair, Slot};
use sp_runtime::{
generic::BlockId,
traits::{Block as BlockT, Header as HeaderT, Zero},
Expand All @@ -34,7 +37,31 @@ type FullClient = sc_service::TFullClient<Block, RuntimeApi, AlephExecutor>;
type FullBackend = sc_service::TFullBackend<Block>;
type FullSelectChain = sc_consensus::LongestChain<FullBackend, Block>;

fn get_backup_path(aleph_config: &AlephCli, base_path: &Path) -> Option<PathBuf> {
struct LimitNonfinalized(u32);

impl<N: BaseArithmetic> BackoffAuthoringBlocksStrategy<N> 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<PathBuf> {
if aleph_config.no_backup() {
return None;
}
Expand Down Expand Up @@ -264,7 +291,7 @@ pub fn new_authority(
.extra_sets
.push(finality_aleph::peers_set_config(Protocol::Validator));

let backup_path = get_backup_path(
let backup_path = backup_path(
&aleph_config,
config
.base_path
Expand All @@ -288,12 +315,12 @@ 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(
config,
backend,
backend.clone(),
&keystore_container,
import_queue,
transaction_pool.clone(),
Expand Down Expand Up @@ -353,9 +380,11 @@ pub fn new_authority(
if aleph_config.external_addresses().is_empty() {
panic!("Cannot run a validator node without external addresses, stopping.");
}
let blockchain_backend = BlockchainBackendImpl { backend };
let aleph_config = AlephConfig {
network,
client,
blockchain_backend,
select_chain,
session_period,
millisecs_per_block,
Expand Down Expand Up @@ -393,7 +422,7 @@ pub fn new_full(
other: (_, justification_tx, justification_rx, mut telemetry, metrics),
} = new_partial(&config)?;

let backup_path = get_backup_path(
let backup_path = backup_path(
&aleph_config,
config
.base_path
Expand All @@ -404,7 +433,7 @@ pub fn new_full(

let (_rpc_handlers, network, network_starter) = setup(
config,
backend,
backend.clone(),
&keystore_container,
import_queue,
transaction_pool,
Expand All @@ -428,9 +457,11 @@ pub fn new_full(
.unwrap(),
);

let blockchain_backend = BlockchainBackendImpl { backend };
let aleph_config = AlephConfig {
network,
client,
blockchain_backend,
select_chain,
session_period,
millisecs_per_block,
Expand All @@ -453,3 +484,24 @@ pub fn new_full(
network_starter.start_network();
Ok(task_manager)
}

struct BlockchainBackendImpl {
backend: Arc<FullBackend>,
}
impl finality_aleph::BlockchainBackend<Block> for BlockchainBackendImpl {
fn children(&self, parent_hash: <Block as BlockT>::Hash) -> Vec<<Block as BlockT>::Hash> {
self.backend
.blockchain()
.children(parent_hash)
.unwrap_or_default()
}
fn info(&self) -> sp_blockchain::Info<Block> {
self.backend.blockchain().info()
}
fn header(
&self,
block_id: sp_api::BlockId<Block>,
) -> sp_blockchain::Result<Option<<Block as BlockT>::Header>> {
self.backend.blockchain().header(block_id)
}
}
2 changes: 1 addition & 1 deletion finality-aleph/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "finality-aleph"
version = "0.5.0"
version = "0.5.3"
authors = ["Cardinal Cryptography"]
edition = "2021"
license = "Apache 2.0"
Expand Down
25 changes: 10 additions & 15 deletions finality-aleph/src/justification/handler.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
use std::{
sync::Arc,
time::{Duration, Instant},
};
use std::time::{Duration, Instant};

use futures::{channel::mpsc, Stream, StreamExt};
use futures_timer::Delay;
use log::{debug, error};
use sc_client_api::HeaderBackend;
use sp_api::BlockT;
use sp_runtime::traits::Header;
use tokio::time::timeout;
Expand All @@ -17,53 +13,52 @@ use crate::{
requester::BlockRequester, JustificationHandlerConfig, JustificationNotification,
JustificationRequestScheduler, SessionInfo, SessionInfoProvider, Verifier,
},
network, Metrics, STATUS_REPORT_INTERVAL,
network, BlockchainBackend, Metrics, STATUS_REPORT_INTERVAL,
};

pub struct JustificationHandler<B, V, RB, C, S, SI, F>
pub struct JustificationHandler<B, V, RB, S, SI, F, BB>
where
B: BlockT,
V: Verifier<B>,
RB: network::RequestBlocks<B> + 'static,
C: HeaderBackend<B> + Send + Sync + 'static,
S: JustificationRequestScheduler,
SI: SessionInfoProvider<B, V>,
F: BlockFinalizer<B>,
BB: BlockchainBackend<B> + 'static,
{
session_info_provider: SI,
block_requester: BlockRequester<B, RB, C, S, F, V>,
block_requester: BlockRequester<B, RB, S, F, V, BB>,
verifier_timeout: Duration,
notification_timeout: Duration,
}

impl<B, V, RB, C, S, SI, F> JustificationHandler<B, V, RB, C, S, SI, F>
impl<B, V, RB, S, SI, F, BB> JustificationHandler<B, V, RB, S, SI, F, BB>
where
B: BlockT,
V: Verifier<B>,
RB: network::RequestBlocks<B> + 'static,
C: HeaderBackend<B> + Send + Sync + 'static,
S: JustificationRequestScheduler,
SI: SessionInfoProvider<B, V>,
F: BlockFinalizer<B>,
BB: BlockchainBackend<B> + 'static,
{
pub fn new(
session_info_provider: SI,
block_requester: RB,
client: Arc<C>,
blockchain_backend: BB,
finalizer: F,
justification_request_scheduler: S,
metrics: Option<Metrics<<B::Header as Header>::Hash>>,
justification_handler_config: JustificationHandlerConfig<B>,
justification_handler_config: JustificationHandlerConfig,
) -> Self {
Self {
session_info_provider,
block_requester: BlockRequester::new(
block_requester,
client,
blockchain_backend,
finalizer,
justification_request_scheduler,
metrics,
justification_handler_config.min_allowed_delay,
),
verifier_timeout: justification_handler_config.verifier_timeout,
notification_timeout: justification_handler_config.notification_timeout,
Expand Down
19 changes: 6 additions & 13 deletions finality-aleph/src/justification/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,36 +55,29 @@ pub struct JustificationNotification<Block: BlockT> {
}

#[derive(Clone)]
pub struct JustificationHandlerConfig<B: BlockT> {
pub struct JustificationHandlerConfig {
/// How long should we wait when the session verifier is not yet available.
verifier_timeout: Duration,
/// How long should we wait for any notification.
notification_timeout: Duration,
///Distance (in amount of blocks) between the best and the block we want to request justification
min_allowed_delay: NumberFor<B>,
}

impl<B: BlockT> Default for JustificationHandlerConfig<B> {
impl Default for JustificationHandlerConfig {
fn default() -> Self {
Self {
verifier_timeout: Duration::from_millis(500),
notification_timeout: Duration::from_millis(1000),
min_allowed_delay: 3u32.into(),
// request justifications slightly more frequently than they're created
notification_timeout: Duration::from_millis(800),
}
}
}

#[cfg(test)]
impl<B: BlockT> JustificationHandlerConfig<B> {
pub fn new(
verifier_timeout: Duration,
notification_timeout: Duration,
min_allowed_delay: NumberFor<B>,
) -> Self {
impl JustificationHandlerConfig {
pub fn new(verifier_timeout: Duration, notification_timeout: Duration) -> Self {
Self {
verifier_timeout,
notification_timeout,
min_allowed_delay,
}
}
}
Loading