Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Request justification from forks
  • Loading branch information
Michal Swietek committed Nov 29, 2022
commit 6ae50cab6534337be84f26e7cc1a75000c3a1ad0
382 changes: 209 additions & 173 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 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"
version = "0.8.1"
authors = ["Cardinal Cryptography"]
description = "Aleph node binary"
edition = "2021"
Expand Down
38 changes: 32 additions & 6 deletions bin/node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ 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_network::NetworkService;
use sc_service::{
Expand All @@ -22,6 +22,7 @@ use sc_service::{
};
use sc_telemetry::{Telemetry, TelemetryWorker};
use sp_api::ProvideRuntimeApi;
use sp_blockchain::Backend as _;
use sp_consensus_aura::sr25519::AuthorityPair as AuraPair;
use sp_runtime::{
generic::BlockId,
Expand All @@ -34,7 +35,7 @@ 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> {
fn backup_path(aleph_config: &AlephCli, base_path: &Path) -> Option<PathBuf> {
if aleph_config.no_backup() {
return None;
}
Expand Down Expand Up @@ -264,7 +265,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 Down Expand Up @@ -293,7 +294,7 @@ pub fn new_authority(

let (_rpc_handlers, network, network_starter) = setup(
config,
backend,
backend.clone(),
&keystore_container,
import_queue,
transaction_pool.clone(),
Expand Down Expand Up @@ -353,9 +354,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 +396,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 +407,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 +431,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 +458,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 bin/runtime/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "aleph-runtime"
version = "0.8.0"
version = "0.8.1"
authors = ["Cardinal Cryptography"]
edition = "2021"
homepage = "https://alephzero.org"
Expand Down
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