Skip to content

Commit

Permalink
Merge branch 'main' into testnet
Browse files Browse the repository at this point in the history
  • Loading branch information
damip committed May 9, 2022
2 parents 986ad4b + a725017 commit 8a11c67
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 62 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ It shows that throughput of 10'000 transactions per second is reached
even in a fully decentralized network with thousands of nodes.

An easy-to-read blog post introduction with videos is written
[here](https://massa.net/blog/post/0/).
[here](https://massa.net/blog/introduction/).

We are now releasing the **Massa testnet** in this Gitlab repository,
with its explorer available at <https://test.massa.net>.
Expand Down
5 changes: 3 additions & 2 deletions docs/smart-contracts/getting-started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,16 @@ Everything is in place, we can now execute the `hello world` smart contract on y

.. code-block:: shell
send_smart_contract <address> <path to wasm file> 0 0 0 0
send_smart_contract <address> <path to wasm file> 100000 0 0 0
.. note::

We are executing the send_smart_contract command with 6 parameters:

- <address>: the address of your wallet kept during previous step;
- <path to wasm file>: the full path (from the root directory to the file extension .wasm) of the hello smart contract generated in the previous chapter.
- Four 0 parameters that can be safely ignored by now. If you want more info on them, use the command `help send_smart_contract`.
- 100000: the maximum amount of gas that the execution of your smart-contract is allowed to use.
- Three 0 parameters that can be safely ignored by now. If you want more info on them, use the command `help send_smart_contract`.


If everything went fine, the following prompted message should be prompted:
Expand Down
56 changes: 34 additions & 22 deletions massa-bootstrap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use massa_logging::massa_trace;
use massa_models::Version;
use massa_network_exports::{BootstrapPeers, NetworkCommandSender};
use massa_proof_of_stake_exports::ExportProofOfStake;
use massa_signature::PrivateKey;
use massa_signature::{PrivateKey, PublicKey};
use massa_time::MassaTime;
use messages::BootstrapMessage;
use parking_lot::RwLock;
Expand Down Expand Up @@ -241,6 +241,20 @@ async fn get_state_internal(
})
}

async fn connect_to_server(
establisher: &mut Establisher,
bootstrap_settings: &BootstrapSettings,
addr: &SocketAddr,
pub_key: &PublicKey,
) -> Result<BootstrapClientBinder, BootstrapError> {
// connect
let mut connector = establisher
.get_connector(bootstrap_settings.connect_timeout)
.await?; // cancellable
let socket = connector.connect(*addr).await?; // cancellable
Ok(BootstrapClientBinder::new(socket, *pub_key))
}

/// Gets the state from a bootstrap server
/// needs to be CANCELLABLE
pub async fn get_state(
Expand Down Expand Up @@ -276,30 +290,28 @@ pub async fn get_state(
info!("Start bootstrapping from {}", addr);

//Scope life cycle of the socket
{
// connect
let mut connector = establisher
.get_connector(bootstrap_settings.connect_timeout)
.await?; // cancellable
let socket = connector.connect(*addr).await?; // cancellable
let mut client = BootstrapClientBinder::new(socket, *pub_key);
match get_state_internal(bootstrap_settings, &mut client, version)
match connect_to_server(&mut establisher, bootstrap_settings, addr, pub_key).await {
Ok(mut client) => {
match get_state_internal(bootstrap_settings, &mut client, version)
.await // cancellable
{
Err(BootstrapError::ReceivedError(error)) => warn!("error received from bootstrap server: {}", error),
Err(e) => {
warn!("error while bootstrapping: {}", e);
// We allow unused result because we don't care if an error is thrown when sending the error message to the server we will close the socket anyway.
let _ = tokio::time::timeout(bootstrap_settings.write_error_timeout.into(), client.send(BootstrapMessage::BootstrapError { error: e.to_string() })).await;
// Sleep a bit to give time for the server to read the error.
sleep(bootstrap_settings.write_error_timeout.into()).await;
}
Ok(res) => {
return Ok(res)
{
Err(BootstrapError::ReceivedError(error)) => warn!("Error received from bootstrap server: {}", error),
Err(e) => {
warn!("Error while bootstrapping: {}", e);
// We allow unused result because we don't care if an error is thrown when sending the error message to the server we will close the socket anyway.
let _ = tokio::time::timeout(bootstrap_settings.write_error_timeout.into(), client.send(BootstrapMessage::BootstrapError { error: e.to_string() })).await;
}
Ok(res) => {
return Ok(res)
}
}
}
}
info!("Bootstrap from server {} failed. Your node will try to bootstrap from another server in {:#?} milliseconds.", addr, bootstrap_settings.retry_delay.to_duration());
Err(e) => {
warn!("Error while connecting to bootstrap server: {}", e);
}
};

info!("Bootstrap from server {} failed. Your node will try to bootstrap from another server in {:#?}.", addr, bootstrap_settings.retry_delay.to_duration());
sleep(bootstrap_settings.retry_delay.into()).await;
}
}
Expand Down
15 changes: 7 additions & 8 deletions massa-client/src/cmds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use massa_time::MassaTime;
use massa_wallet::{Wallet, WalletError};
use serde::Serialize;
use std::collections::HashMap;
use std::fmt::Write as _;
use std::fmt::{Debug, Display};
use std::net::IpAddr;
use std::path::PathBuf;
Expand Down Expand Up @@ -627,16 +628,14 @@ impl Command {
for key in parse_vec::<Address>(parameters)?.into_iter() {
match wallet.remove_address(key) {
Ok(_) => {
res.push_str(&format!("Removed address {} from the wallet\n", key));
let _ = writeln!(res, "Removed address {} from the wallet", key);
}
Err(WalletError::MissingKeyError(_)) => {
res.push_str(&format!("Address {} wasn't in the wallet\n", key));
let _ = writeln!(res, "Address {} wasn't in the wallet", key);
}
Err(_) => {
res.push_str(&format!(
"Failed to remove address {} from the wallet\n",
key
));
let _ =
writeln!(res, "Failed to remove address {} from the wallet", key);
}
}
}
Expand Down Expand Up @@ -785,9 +784,9 @@ impl Command {
let (days, hours, mins, secs) =
e.saturating_sub(MassaTime::now()?).days_hours_mins_secs()?; // compensation milliseconds is zero

res.push_str(&format!("{} days, {} hours, {} minutes, {} seconds remaining until the end of the current episode", days, hours, mins, secs));
let _ = write!(res, "{} days, {} hours, {} minutes, {} seconds remaining until the end of the current episode", days, hours, mins, secs);
} else {
res.push_str("There is no end !")
let _ = write!(res, "There is no end !");
}
if !json {
println!("{}", res);
Expand Down
1 change: 0 additions & 1 deletion massa-consensus-exports/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) 2022 MASSA LABS <[email protected]>
//! Consensus exports
#![feature(async_closure)]
#![feature(bool_to_option)]
#![feature(hash_drain_filter)]
#![feature(map_first_last)]
#![feature(int_roundings)]
Expand Down
1 change: 0 additions & 1 deletion massa-consensus-worker/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#![doc = include_str!("../endorsements.md")]
#![feature(async_closure)]
#![feature(bool_to_option)]
#![feature(hash_drain_filter)]
#![feature(map_first_last)]
#![feature(int_roundings)]
Expand Down
1 change: 0 additions & 1 deletion massa-graph/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#![warn(missing_docs)]
#![warn(unused_crate_dependencies)]
#![feature(async_closure)]
#![feature(bool_to_option)]
#![feature(hash_drain_filter)]
#![feature(map_first_last)]
#![feature(int_roundings)]
Expand Down
2 changes: 1 addition & 1 deletion massa-models/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl std::fmt::Display for NodeStatus {

writeln!(f, "Connected nodes:")?;
for (node_id, ip_addr) in &self.connected_nodes {
writeln!(f, "\t[\"{}:31245\", \"{}\"],", ip_addr, node_id)?;
writeln!(f, "\t[\"{}\", \"{}\"],", ip_addr, node_id)?
}
Ok(())
}
Expand Down
29 changes: 23 additions & 6 deletions massa-protocol-worker/src/node_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,21 @@ use tokio::time::Instant;
pub(crate) struct NodeInfo {
/// The blocks the node "knows about",
/// defined as the one the node propagated headers to us for.
pub known_blocks: Map<BlockId, (bool, Instant)>,
pub(crate) known_blocks: Map<BlockId, (bool, Instant)>,
/// The blocks the node asked for.
pub wanted_blocks: Map<BlockId, Instant>,
pub(crate) wanted_blocks: Map<BlockId, Instant>,
/// Blocks we asked that node for
pub asked_blocks: Map<BlockId, Instant>,
/// Instant when the node was added
pub connection_instant: Instant,
/// all known operations
pub known_operations: OperationIds,
known_operations: OperationIds,
/// Same as `known_operations` but sorted for a premature optimization :-)
pub known_operations_queue: VecDeque<OperationId>,
known_operations_queue: VecDeque<OperationId>,
/// all known endorsements
pub known_endorsements: Set<EndorsementId>,
known_endorsements: Set<EndorsementId>,
/// Same as `known_endorsements` but sorted for a premature optimization :-)
pub known_endorsements_queue: VecDeque<EndorsementId>,
known_endorsements_queue: VecDeque<EndorsementId>,
}

impl NodeInfo {
Expand Down Expand Up @@ -145,6 +145,23 @@ impl NodeInfo {
}
}

/// Remove a list of operation IDs from the list of operation IDs known by a remote node
///
/// Note: this is INEFFICIENT when an element is actually removed (linear traversal of the deque) and should be used sparingly
pub fn remove_known_ops(&mut self, ops: &Set<OperationId>) {
for op_id in ops.iter() {
if self.known_operations.remove(op_id) {
if let Some(pos) = self
.known_operations_queue
.iter()
.position(|id| id == op_id)
{
self.known_operations_queue.remove(pos);
}
}
}
}

pub fn knows_op(&self, op: &OperationId) -> bool {
self.known_operations.contains(op)
}
Expand Down
26 changes: 7 additions & 19 deletions massa-protocol-worker/src/worker_operations_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use massa_models::{
node::NodeId,
operation::{OperationIds, Operations},
prehash::BuildMap,
signed::Signable,
};
use massa_network_exports::NetworkError;
use massa_protocol_exports::{ProtocolError, ProtocolPoolEvent};
Expand Down Expand Up @@ -70,6 +69,7 @@ impl ProtocolWorker {
OperationIds::with_capacity_and_hasher(op_batch.len(), BuildMap::default());
// exactitude isn't important, we want to have a now for that function call
let now = Instant::now();
let mut count_reask = 0;
for op_id in op_batch {
if self.checked_operations.contains(&op_id) {
continue;
Expand All @@ -92,11 +92,7 @@ impl ProtocolWorker {
.checked_sub(self.protocol_settings.operation_batch_proc_period.into())
.ok_or(TimeError::TimeOverflowError)?
{
debug!(
"re-ask operation {:?} asked for the first time {:?} millis ago.",
op_id,
wish.0.elapsed().as_millis()
);
count_reask += 1;
ask_set.insert(op_id);
wish.0 = now;
wish.1.push(node_id);
Expand All @@ -108,6 +104,9 @@ impl ProtocolWorker {
self.asked_operations.insert(op_id, (now, vec![node_id]));
}
} // EndOf for op_id in op_batch:
if count_reask > 0 {
debug!("re-ask {:#?} operations.", count_reask);
}
if self.op_batch_buffer.len() < self.protocol_settings.operation_batch_buffer_capacity
&& !future_set.is_empty()
{
Expand All @@ -134,16 +133,6 @@ impl ProtocolWorker {
/// `node_info.known_operations`
/// - Notify the operations to he local node, to be propagated
pub(crate) async fn on_operations_received(&mut self, node_id: NodeId, operations: Operations) {
let operation_ids: OperationIds = operations
.iter()
.filter_map(|signed_op| match signed_op.content.compute_id() {
Ok(op_id) => Some(op_id),
_ => None,
})
.collect();
if let Some(node_info) = self.active_nodes.get_mut(&node_id) {
node_info.known_operations.extend(operation_ids.iter());
}
if self
.note_operations_from_node(operations, &node_id, true)
.await
Expand Down Expand Up @@ -214,9 +203,8 @@ impl ProtocolWorker {
op_ids: OperationIds,
) -> Result<(), ProtocolError> {
if let Some(node_info) = self.active_nodes.get_mut(&node_id) {
for op_ids in op_ids.iter() {
node_info.known_operations.remove(op_ids);
}
// remove_known_ops is inefficient when actually removing an entry, but this is almost never the case
node_info.remove_known_ops(&op_ids);
}
let mut operation_ids = OperationIds::default();
for op_id in op_ids.iter() {
Expand Down

0 comments on commit 8a11c67

Please sign in to comment.