Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue #1277: make PROTOCOL related config const or static ref frozen in binary rather than loaded from config.toml #1848

Merged
merged 1 commit into from Dec 8, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

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

8 changes: 4 additions & 4 deletions api/src/lib.rs
Expand Up @@ -19,7 +19,7 @@ use models::massa_hash::PubkeySig;
use models::node::NodeId;
use models::operation::{Operation, OperationId};
use models::{Address, BlockId, EndorsementId, Version};
use network::{NetworkCommandSender, NetworkConfig};
use network::{NetworkCommandSender, NetworkSettings};
use pool::PoolCommandSender;
use signature::PrivateKey;
use std::net::{IpAddr, SocketAddr};
Expand All @@ -35,9 +35,9 @@ mod public;
pub struct Public {
pub consensus_command_sender: ConsensusCommandSender,
pub pool_command_sender: PoolCommandSender,
pub consensus_settings: &'static ConsensusConfig,
pub consensus_config: ConsensusConfig,
pub api_settings: &'static APISettings,
pub network_settings: &'static NetworkConfig,
pub network_settings: &'static NetworkSettings,
pub version: Version,
pub network_command_sender: NetworkCommandSender,
pub compensation_millis: i64,
Expand All @@ -47,7 +47,7 @@ pub struct Public {
pub struct Private {
pub consensus_command_sender: ConsensusCommandSender,
pub network_command_sender: NetworkCommandSender,
pub consensus_settings: &'static ConsensusConfig,
pub consensus_config: ConsensusConfig,
pub api_settings: &'static APISettings,
pub stop_node_channel: mpsc::Sender<()>,
}
Expand Down
4 changes: 2 additions & 2 deletions api/src/private.rs
Expand Up @@ -22,14 +22,14 @@ impl API<Private> {
consensus_command_sender: ConsensusCommandSender,
network_command_sender: NetworkCommandSender,
api_settings: &'static APISettings,
consensus_settings: &'static ConsensusConfig,
consensus_settings: ConsensusConfig,
) -> (Self, mpsc::Receiver<()>) {
let (stop_node_channel, rx) = mpsc::channel(1);
(
API(Private {
consensus_command_sender,
network_command_sender,
consensus_settings,
consensus_config: consensus_settings,
api_settings,
stop_node_channel,
}),
Expand Down
18 changes: 9 additions & 9 deletions api/src/public.rs
Expand Up @@ -21,7 +21,7 @@ use models::{
Address, BlockHashSet, BlockId, EndorsementHashSet, EndorsementId, Operation, OperationHashMap,
OperationHashSet, OperationId, Slot, Version,
};
use network::{NetworkCommandSender, NetworkConfig};
use network::{NetworkCommandSender, NetworkSettings};
use pool::PoolCommandSender;
use signature::PrivateKey;
use std::net::{IpAddr, SocketAddr};
Expand All @@ -31,17 +31,17 @@ impl API<Public> {
pub fn new(
consensus_command_sender: ConsensusCommandSender,
api_settings: &'static APISettings,
consensus_settings: &'static ConsensusConfig,
consensus_settings: ConsensusConfig,
pool_command_sender: PoolCommandSender,
network_settings: &'static NetworkConfig,
network_settings: &'static NetworkSettings,
version: Version,
network_command_sender: NetworkCommandSender,
compensation_millis: i64,
node_id: NodeId,
) -> Self {
API(Public {
consensus_command_sender,
consensus_settings,
consensus_config: consensus_settings,
api_settings,
pool_command_sender,
network_settings,
Expand Down Expand Up @@ -94,11 +94,11 @@ impl Endpoints for API<Public> {
let network_command_sender = self.0.network_command_sender.clone();
let network_config = self.0.network_settings.clone();
let version = self.0.version;
let consensus_settings = self.0.consensus_settings.clone();
let consensus_settings = self.0.consensus_config.clone();
let compensation_millis = self.0.compensation_millis;
let mut pool_command_sender = self.0.pool_command_sender.clone();
let node_id = self.0.node_id;
let algo_config = consensus_settings.to_algo_config();
let config = consensus_settings.config();
let closure = async move || {
let now = UTime::now(compensation_millis)?;
let last_slot = get_latest_block_slot_at_timestamp(
Expand Down Expand Up @@ -138,7 +138,7 @@ impl Endpoints for API<Public> {
network_stats: network_stats?,
pool_stats: pool_stats?,

algo_config,
config,
current_cycle: last_slot
.unwrap_or_else(|| Slot::new(0, 0))
.get_cycle(consensus_settings.periods_per_cycle),
Expand Down Expand Up @@ -297,7 +297,7 @@ impl Endpoints for API<Public> {
time: TimeInterval,
) -> BoxFuture<Result<Vec<BlockSummary>, ApiError>> {
let consensus_command_sender = self.0.consensus_command_sender.clone();
let consensus_settings = self.0.consensus_settings.clone();
let consensus_settings = self.0.consensus_config.clone();
let closure = async move || {
// filter blocks from graph_export
let (start_slot, end_slot) = time_range_to_slot_range(
Expand Down Expand Up @@ -350,7 +350,7 @@ impl Endpoints for API<Public> {
addresses: Vec<Address>,
) -> BoxFuture<Result<Vec<AddressInfo>, ApiError>> {
let cmd_sender = self.0.consensus_command_sender.clone();
let cfg = self.0.consensus_settings.clone();
let cfg = self.0.consensus_config.clone();
let api_cfg = self.0.api_settings;
let pool_command_sender = self.0.pool_command_sender.clone();
let compensation_millis = self.0.compensation_millis;
Expand Down
5 changes: 3 additions & 2 deletions bootstrap/src/client_binder.rs
@@ -1,8 +1,9 @@
// Copyright (c) 2021 MASSA LABS <info@massa.net>

use super::messages::BootstrapMessage;
use crate::error::BootstrapError;
use crate::establisher::Duplex;
use crate::{error::BootstrapError, messages::BOOTSTRAP_RANDOMNES_SIZE_BYTES};
use crate::settings::BOOTSTRAP_RANDOMNESS_SIZE_BYTES;
use massa_hash::hash::Hash;
use models::{with_serialization_context, DeserializeCompact, DeserializeMinBEInt};
use rand::{rngs::StdRng, RngCore, SeedableRng};
Expand Down Expand Up @@ -42,7 +43,7 @@ impl BootstrapClientBinder {
pub async fn handshake(&mut self) -> Result<(), BootstrapError> {
// send randomnes and their hash
let rand_hash = {
let mut random_bytes = [0u8; BOOTSTRAP_RANDOMNES_SIZE_BYTES];
let mut random_bytes = [0u8; BOOTSTRAP_RANDOMNESS_SIZE_BYTES];
StdRng::from_entropy().fill_bytes(&mut random_bytes);
self.duplex.write_all(&random_bytes).await?;
let rand_hash = Hash::from(&random_bytes);
Expand Down
2 changes: 1 addition & 1 deletion bootstrap/src/lib.rs
Expand Up @@ -12,7 +12,7 @@ use messages::BootstrapMessage;
use models::Version;
use network::{BootstrapPeers, NetworkCommandSender};
use rand::{prelude::SliceRandom, rngs::StdRng, SeedableRng};
use settings::BootstrapSettings;
pub use settings::BootstrapSettings;
use signature::{PrivateKey, PublicKey};
use std::collections::{hash_map, HashMap};
use std::net::SocketAddr;
Expand Down
2 changes: 0 additions & 2 deletions bootstrap/src/messages.rs
Expand Up @@ -10,8 +10,6 @@ use serde::{Deserialize, Serialize};
use std::convert::TryInto;
use time::UTime;

pub const BOOTSTRAP_RANDOMNES_SIZE_BYTES: usize = 32;

/// Messages used during bootstrap
#[derive(Debug, Serialize, Deserialize)]
pub enum BootstrapMessage {
Expand Down
8 changes: 5 additions & 3 deletions bootstrap/src/server_binder.rs
@@ -1,9 +1,11 @@
// Copyright (c) 2021 MASSA LABS <info@massa.net>

use super::messages::BootstrapMessage;
use crate::error::BootstrapError;
use crate::establisher::Duplex;
use crate::{error::BootstrapError, messages::BOOTSTRAP_RANDOMNES_SIZE_BYTES};
use massa_hash::{hash::Hash, hash::HASH_SIZE_BYTES};
use crate::settings::BOOTSTRAP_RANDOMNESS_SIZE_BYTES;
use massa_hash::hash::Hash;
use massa_hash::HASH_SIZE_BYTES;
use models::SerializeMinBEInt;
use models::{with_serialization_context, SerializeCompact};
use signature::{sign, PrivateKey, Signature, SIGNATURE_SIZE_BYTES};
Expand Down Expand Up @@ -39,7 +41,7 @@ impl BootstrapServerBinder {
pub async fn handshake(&mut self) -> Result<(), BootstrapError> {
// read randomnes, check hash
let rand_hash = {
let mut random_bytes = [0u8; BOOTSTRAP_RANDOMNES_SIZE_BYTES];
let mut random_bytes = [0u8; BOOTSTRAP_RANDOMNESS_SIZE_BYTES];
self.duplex.read_exact(&mut random_bytes).await?;
let expected_hash = Hash::from(&random_bytes);
let mut hash_bytes = [0u8; HASH_SIZE_BYTES];
Expand Down
42 changes: 27 additions & 15 deletions bootstrap/src/settings.rs
Expand Up @@ -5,6 +5,29 @@ use signature::PublicKey;
use std::net::SocketAddr;
use time::UTime;

/// Max message size for bootstrap
pub const MAX_BOOTSTRAP_MESSAGE_SIZE: u32 = 1048576000;

/// Max number of blocks we provide/ take into account while bootstrapping
pub const MAX_BOOTSTRAP_BLOCKS: u32 = 1000000;

pub const MAX_BOOTSTRAP_CLIQUES: u32 = 1000;

pub const MAX_BOOTSTRAP_DEPS: u32 = 1000;

pub const MAX_BOOTSTRAP_CHILDREN: u32 = 1000;

/// Max number of cycles in PoS bootstrap
pub const MAX_BOOTSTRAP_POS_CYCLES: u32 = 5;

/// Max number of address and rng entries for PoS bootstrap
pub const MAX_BOOTSTRAP_POS_ENTRIES: u32 = 1000000000;

/// Max size of the IP list
pub const IP_LIST_MAX_SIZE: usize = 10000;

pub const BOOTSTRAP_RANDOMNESS_SIZE_BYTES: usize = 32;

#[derive(Debug, Deserialize, Clone)]
pub struct BootstrapSettings {
/// Ip address of our bootstrap nodes and their public key.
Expand All @@ -19,27 +42,16 @@ pub struct BootstrapSettings {
pub write_timeout: UTime,
/// Time we wait before retrying a bootstrap
pub retry_delay: UTime,
/// Max message size for bootstrap
pub max_bootstrap_message_size: u32,
/// Max number of blocks we provide/ take into account while bootstrapping
pub max_bootstrap_blocks: u32,
pub max_bootstrap_cliques: u32,
pub max_bootstrap_deps: u32,
pub max_bootstrap_children: u32,
/// Max ping delay.
pub max_ping: UTime,
/// Max number of cycles in PoS bootstrap
pub max_bootstrap_pos_cycles: u32,
/// Max number of address and rng entries for PoS bootstrap
pub max_bootstrap_pos_entries: u32,
/// Enable clock synchronization
pub enable_clock_synchronization: bool,
// Cache duration
/// Cache duration
pub cache_duration: UTime,
// Max simultaneous bootstraps
/// Max simultaneous bootstraps
pub max_simultaneous_bootstraps: u32,
// Minimum interval between two bootstrap attempts from a given IP
/// Minimum interval between two bootstrap attempts from a given IP
pub per_ip_min_interval: UTime,
// Max size of the IP list
/// Max size of the IP list
pub ip_list_max_size: usize,
}
7 changes: 0 additions & 7 deletions bootstrap/src/tests/tools.rs
Expand Up @@ -75,16 +75,9 @@ pub fn get_bootstrap_config(bootstrap_public_key: PublicKey) -> BootstrapSetting
bind: Some("0.0.0.0:31244".parse().unwrap()),
connect_timeout: 200.into(),
retry_delay: 200.into(),
max_bootstrap_blocks: 100,
max_bootstrap_cliques: 100,
max_bootstrap_deps: 100,
max_bootstrap_children: 100,
max_ping: UTime::from(500),
max_bootstrap_message_size: 100000000,
read_timeout: 1000.into(),
write_timeout: 1000.into(),
max_bootstrap_pos_entries: 1000,
max_bootstrap_pos_cycles: 5,
bootstrap_list: vec![(SocketAddr::new(BASE_BOOTSTRAP_IP, 16), bootstrap_public_key)],
enable_clock_synchronization: true,
cache_duration: 10000.into(),
Expand Down
1 change: 1 addition & 0 deletions consensus/Cargo.toml
Expand Up @@ -10,6 +10,7 @@ edition = "2021"
bitvec = { version = "0.22", features = ["serde"] }
displaydoc = "0.2"
futures = "0.3"
lazy_static = "1.4"
num = { version = "0.4", features = ["serde"] }
rand ="0.8"
rand_xoshiro = "0.6"
Expand Down