Skip to content

Commit

Permalink
Merge branch 'main' into testnet
Browse files Browse the repository at this point in the history
  • Loading branch information
AurelienFT committed Mar 9, 2023
2 parents 8e53f3a + a3c6e03 commit 9aee0dd
Show file tree
Hide file tree
Showing 23 changed files with 673 additions and 350 deletions.
168 changes: 70 additions & 98 deletions Cargo.lock

Large diffs are not rendered by default.

13 changes: 11 additions & 2 deletions massa-bootstrap/src/establisher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,18 @@ pub mod types {
/// * `addr`: `SocketAddr` we want to bind to.
pub async fn get_listener(&mut self, addr: SocketAddr) -> io::Result<DefaultListener> {
// Create a socket2 TCP listener to manually set the IPV6_V6ONLY flag
let socket = socket2::Socket::new(socket2::Domain::IPV6, socket2::Type::STREAM, None)?;
// This is needed to get the same behavior on all OS
// However, if IPv6 is disabled system-wide, you may need to bind to an IPv4 address instead.
let domain = match addr.is_ipv4() {
true => socket2::Domain::IPV4,
_ => socket2::Domain::IPV6,
};

socket.set_only_v6(false)?;
let socket = socket2::Socket::new(domain, socket2::Type::STREAM, None)?;

if addr.is_ipv6() {
socket.set_only_v6(false)?;
}
socket.set_nonblocking(true)?;
socket.bind(&addr.into())?;

Expand Down
12 changes: 9 additions & 3 deletions massa-consensus-exports/src/channels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,23 @@ use massa_protocol_exports::ProtocolCommandSender;

use crate::events::ConsensusEvent;

/// Contains a reference to the pool, selector and execution controller
/// Contains a channel to send info to protocol
/// Contains channels to send info to api
/// Contains links to other modules of the node to be able to interact with them.
#[derive(Clone)]
pub struct ConsensusChannels {
/// Interface to interact with Execution module
pub execution_controller: Box<dyn ExecutionController>,
/// Interface to interact with PoS module
pub selector_controller: Box<dyn SelectorController>,
/// Interface to interact with Pool module
pub pool_command_sender: Box<dyn PoolController>,
/// Channel used by the consensus to send events to the node globally
pub controller_event_tx: crossbeam_channel::Sender<ConsensusEvent>,
/// Channel to send commands to the Protocol module
pub protocol_command_sender: ProtocolCommandSender,
/// Channel used for Websocket broadcast (if enabled) of new blocks being integrated in the graph
pub block_sender: tokio::sync::broadcast::Sender<Block>,
/// Channel used for Websocket broadcast (if enabled) of new block headers being integrated in the graph
pub block_header_sender: tokio::sync::broadcast::Sender<BlockHeader>,
/// Channel use by Websocket (if they are enable) to broadcast a new block integrated
pub filled_block_sender: tokio::sync::broadcast::Sender<FilledBlock>,
}
19 changes: 12 additions & 7 deletions massa-consensus-exports/src/controller_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use massa_models::{
};
use massa_storage::Storage;

/// interface that communicates with the graph worker thread
/// Interface that communicates with the graph worker thread
pub trait ConsensusController: Send + Sync {
/// Get an export of a part of the graph
///
Expand All @@ -27,7 +27,7 @@ pub trait ConsensusController: Send + Sync {
/// Get statuses of a list of blocks
///
/// # Arguments
/// * `block_ids`: the list of block ids to get the status of
/// * `ids`: the list of block ids to get the status of
///
/// # Returns
/// The statuses of the blocks sorted by the order of the input list
Expand All @@ -39,12 +39,17 @@ pub trait ConsensusController: Send + Sync {
/// The list of cliques
fn get_cliques(&self) -> Vec<Clique>;

/// Get a graph to bootstrap from
/// Get a part of the graph to send to a node for it to setup its graph.
/// Used for bootstrap.
///
/// # Returns
/// * a part of the graph
/// * outdated block ids
/// * the updated streaming step
/// # Arguments:
/// * `cursor`: streaming cursor containing the current state of bootstrap and what blocks have previously been sent to the client
/// * `execution_cursor`: streaming cursor of the final state to ensure that last slot of the bootstrap info match the slot of the execution
///
/// # Returns:
/// * A portion of the graph
/// * The list of outdated block ids
/// * The streaming step value after the current iteration to be saved to be able to use it as parameters and resume the bootstrap
#[allow(clippy::type_complexity)]
fn get_bootstrap_part(
&self,
Expand Down
15 changes: 14 additions & 1 deletion massa-consensus-worker/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) 2022 MASSA LABS <info@massa.net>

//! # General description
//! # General module description
//!
//! The consensus worker launches a persistent thread that will run in the background.
//! This thread has a `run` function that triggers the consensus algorithm each slot. It can be interrupted by commands
Expand All @@ -11,6 +11,19 @@
//! when protocol sends informations to this module.
//!
//! This module doesn't use asynchronous code.
//!
//! ## Workflow description
//!
//! The consensus worker is launched and initializes a shared state that contains caches, counters and other info.
//! The consensus worker wakes up at each slot or when it receives a command.
//! If a command is received, the worker executes it and goes back to sleep.
//! * When an incoming block header is fed to the module, it registers it and asks the Protocol module for the dependencies of the block (including the full block itself) if needed.
//! * When an incoming full block is fed to the module, it registers it and asks the Protocol module for its dependencies if needed.
//! * If the dependencies are already available, the module checks if it can validate the block and add it to a clique.
//! * If it's the second block received for the same slot we save it in order to denounce the creator in the future.
//! * If it's the third or more we ignore the block unless we asked for it explicitly as a dependency.
//! If a queued block reaches the slot time at which it should be processed, the worker wakes up to check it and trigger, if necessary, the consensus algorithm.
//! It then prunes the block graph and the caches.
#![feature(deadline_api)]
#![feature(let_chains)]
Expand Down
3 changes: 3 additions & 0 deletions massa-consensus-worker/src/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ pub struct ConsensusState {
pub wishlist: PreHashMap<BlockId, Option<SecuredHeader>>,
/// previous blockclique notified to Execution
pub prev_blockclique: PreHashMap<BlockId, Slot>,
/// Blocks indexed by slot (used for multi-stake limiting). Blocks
/// should be saved in this map when we receive the header or the full block directly.
pub nonfinal_active_blocks_per_slot: HashMap<Slot, PreHashSet<BlockId>>,
}

impl ConsensusState {
Expand Down
Loading

0 comments on commit 9aee0dd

Please sign in to comment.