Skip to content

Commit

Permalink
Merge branch 'main' into refacto/network/split_crate
Browse files Browse the repository at this point in the history
  • Loading branch information
AureliaDolo committed Mar 9, 2022
2 parents 2affc1d + 4e3c498 commit feb24c5
Show file tree
Hide file tree
Showing 20 changed files with 219 additions and 123 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ jobs:
- uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: --all-features

# Full cross-platform tests required by bors to merge on main branch
full:
Expand Down Expand Up @@ -164,7 +163,7 @@ jobs:
- uses: actions-rs/cargo@v1
with:
command: test
args: --all-features --no-fail-fast
args: --features testing --no-fail-fast
env:
CARGO_INCREMENTAL: "0"
RUSTFLAGS: "-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cpanic=abort -Zpanic_abort_tests"
Expand Down
68 changes: 47 additions & 21 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ members = [
"massa-network-worker",
"massa-network-exports",
"massa-node",
"massa-sdk",
"massa-pool",
"massa-proof-of-stake-exports",
"massa-protocol-exports",
Expand Down
8 changes: 6 additions & 2 deletions massa-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ anyhow = "1.0"
atty = "0.2"
config = "0.11"
console = "0.15"
dialoguer = { version = "0.9", git = "https://github.com/yvan-sraka/dialoguer.git", branch = "completion-feature", features = ["history", "completion"] }
dialoguer = { version = "0.10", features = ["history", "completion"] }
directories = "4.0"
erased-serde = "0.3"
futures = "0.3"
jsonrpc-core-client = { version = "18.0", features = ["http", "tls"] }
glob = "0.3.0"
lazy_static = "1.4"
paw = "1.0"
rev_lines = "0.2"
Expand All @@ -29,8 +29,12 @@ tokio = { version = "1.15", features = ["full"] }
massa_models = { path = "../massa-models" }
massa_signature = { path = "../massa-signature" }
massa_time = { path = "../massa-time" }
massa_sdk = { path = "../massa-sdk" }
massa_wallet = { path = "../massa-wallet" }

[target.'cfg(not(windows))'.dependencies]
tilde-expand = "0.1.1"

[dev-dependencies]
assert_cmd = "2.0"
serial_test = "0.5"
Expand Down
2 changes: 1 addition & 1 deletion massa-client/src/cmds.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) 2022 MASSA LABS <[email protected]>

use crate::repl::Output;
use crate::rpc::Client;
use anyhow::{anyhow, bail, Result};
use console::style;
use massa_models::api::ReadOnlyExecution;
Expand All @@ -11,6 +10,7 @@ use massa_models::timeslots::get_current_latest_block_slot;
use massa_models::{
Address, Amount, BlockId, EndorsementId, OperationContent, OperationId, OperationType, Slot,
};
use massa_sdk::Client;
use massa_signature::{generate_random_private_key, PrivateKey, PublicKey};
use massa_time::MassaTime;
use massa_wallet::{Wallet, WalletError};
Expand Down
3 changes: 1 addition & 2 deletions massa-client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

#![feature(str_split_whitespace_as_str)]

use crate::rpc::Client;
use crate::settings::SETTINGS;
use anyhow::Result;
use atty::Stream;
use cmds::Command;
use console::style;
use massa_sdk::Client;
use massa_wallet::Wallet;
use serde::Serialize;
use std::net::IpAddr;
Expand All @@ -16,7 +16,6 @@ use structopt::StructOpt;

mod cmds;
mod repl;
mod rpc;
mod settings;
mod utils;

Expand Down
64 changes: 51 additions & 13 deletions massa-client/src/repl.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
// Copyright (c) 2022 MASSA LABS <[email protected]>

use crate::cmds::{Command, ExtendedWallet};
use crate::rpc::Client;
use crate::settings::SETTINGS;
use crate::utils::longest_common_prefix;
use console::style;
use dialoguer::{theme::ColorfulTheme, Completion, History, Input};
use erased_serde::{Serialize, Serializer};
use glob::glob;
use massa_models::api::{AddressInfo, BlockInfo, EndorsementInfo, NodeStatus, OperationInfo};
use massa_models::composite::PubkeySig;
use massa_models::execution::ExecuteReadOnlyResponse;
use massa_models::prehash::Set;
use massa_models::{Address, OperationId};
use massa_sdk::Client;
use massa_wallet::Wallet;
use rev_lines::RevLines;
use std::collections::VecDeque;
use std::io::Error;
use std::str;
use std::{
fs::File,
fs::OpenOptions,
io::{BufReader, Write},
};
use strum::IntoEnumIterator;
use strum::ParseError;
#[cfg(not(windows))]
use tilde_expand::tilde_expand;

macro_rules! massa_fancy_ascii_art_logo {
() => {
Expand Down Expand Up @@ -132,24 +136,58 @@ impl Default for CommandCompletion {
}
}

#[cfg(not(windows))]
fn expand_path(partial_path: &str) -> Vec<u8> {
tilde_expand(partial_path.as_bytes())
}

#[cfg(windows)]
fn expand_path(partial_path: &str) -> Vec<u8> {
partial_path.as_bytes().to_vec()
}

impl Completion for CommandCompletion {
/// Simple completion implementation based on substring
fn get(&self, input: &str) -> Option<String> {
let input = input.to_string();
let suggestions: Vec<&str> = self
.options
.iter()
.filter(|s| s.len() >= input.len() && input == s[..input.len()])
.map(|s| &s[..])
.collect();
if !suggestions.is_empty() {
println!();
for suggestion in &suggestions {
println!("{}", style(suggestion).dim());
if input.contains(' ') {
let mut args: Vec<&str> = input.split(' ').collect();
let mut default_path = "./";
let path_to_complete = args.last_mut().unwrap_or(&mut default_path);
let expanded_path = expand_path(path_to_complete);
*path_to_complete = str::from_utf8(&expanded_path).unwrap_or(path_to_complete);
if let Ok(paths) = glob(&(path_to_complete.to_owned() + "*")) {
let suggestions: Vec<String> = paths
.filter_map(|x| x.map(|path| path.display().to_string()).ok())
.collect();
if !suggestions.is_empty() {
println!();
for path in &suggestions {
println!("{}", style(path).dim())
}
*path_to_complete =
longest_common_prefix(suggestions.iter().map(|s| &s[..]).collect());
}
Some(args.join(" "))
} else {
Some(args.join(" "))
}
Some(String::from(longest_common_prefix(suggestions)))
} else {
None
let suggestions: Vec<&str> = self
.options
.iter()
.filter(|s| s.len() >= input.len() && input == s[..input.len()])
.map(|s| &s[..])
.collect();
if !suggestions.is_empty() {
println!();
for suggestion in &suggestions {
println!("{}", style(suggestion).dim());
}
Some(String::from(longest_common_prefix(suggestions)))
} else {
None
}
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions massa-client/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,9 @@ pub struct DefaultNode {
pub private_port: u16,
pub public_port: u16,
}

#[cfg(test)]
#[test]
fn test_load_client_config() {
let _ = *SETTINGS;
}
4 changes: 3 additions & 1 deletion massa-consensus-worker/src/tests/scenario_block_creation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ async fn test_genesis_block_creation() {
LedgerData::new(Amount::from_str("1000").unwrap()),
);
let mut cfg = ConsensusConfig {
genesis_timestamp: MassaTime::from_str("1633301290000").unwrap(),
genesis_timestamp: MassaTime::now()
.unwrap()
.saturating_sub(MassaTime::from(30000)),
..ConsensusConfig::default_with_staking_keys_and_ledger(&[priv_1, priv_2], &ledger)
};
// init roll count
Expand Down
12 changes: 9 additions & 3 deletions massa-execution-worker/src/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,21 @@ impl ExecutionState {
/// Slots after that point will need to be (re-executed) to account for the new sequence.
///
/// # Arguments
/// * active_slots: A HashMap mapping each slot to a block or None if the slot is a miss
pub fn truncate_history(&mut self, active_slots: &HashMap<Slot, Option<(BlockId, Block)>>) {
/// * active_slots: A HashMap mapping each active slot to a block or None if the slot is a miss
/// * ready_final_slots: A HashMap mapping each ready-to-execute final slot to a block or None if the slot is a miss
pub fn truncate_history(
&mut self,
active_slots: &HashMap<Slot, Option<(BlockId, Block)>>,
ready_final_slots: &HashMap<Slot, Option<(BlockId, Block)>>,
) {
// find mismatch point (included)
let mut truncate_at = None;
// iterate over the output history, in chronological order
for (hist_index, exec_output) in self.active_history.iter().enumerate() {
// try to find the corresponding slot in active_slots
// try to find the corresponding slot in active_slots or ready_final_slots
let found_block_id = active_slots
.get(&exec_output.slot)
.or_else(|| ready_final_slots.get(&exec_output.slot))
.map(|opt_b| opt_b.as_ref().map(|(b_id, _b)| *b_id));
if found_block_id == Some(exec_output.block_id) {
// the slot number and block ID still match. Continue scanning
Expand Down
Loading

0 comments on commit feb24c5

Please sign in to comment.