Skip to content

Commit

Permalink
Merge branch 'testnet_23' into versioning-test-branch
Browse files Browse the repository at this point in the history
  • Loading branch information
Eitu33 committed May 30, 2023
2 parents e92ad2d + cdf72c6 commit 2e782bd
Show file tree
Hide file tree
Showing 21 changed files with 189 additions and 209 deletions.
5 changes: 3 additions & 2 deletions Cargo.lock

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

69 changes: 37 additions & 32 deletions massa-client/src/cmds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -774,42 +774,47 @@ impl Command {
// In order to generate a KeyPair we need to get the MIP statuses and use the latest
// active version
let req = grpc::GetMipStatusRequest { id: "".to_string() };
let versioning_status = match client.grpc.get_mip_status(req).await {
Ok(resp_) => {
let resp = resp_.into_inner();
resp.entry
}
Err(e) => {
// FIXME: Should we default to the last known version - default to 0?
grpc_error!(e)
}
};

// Note: unused for now as AddressFactory is not yet merged
let _address_version = versioning_status
.into_iter()
.rev()
.find_map(|entry| {
let state = grpc::ComponentStateId::from_i32(entry.state_id)
.unwrap_or(grpc::ComponentStateId::Error);
match state {
grpc::ComponentStateId::Active => Some(entry.state_id),
_ => None,
if let Some(ref mut grpc) = client.grpc {
let versioning_status = match grpc.get_mip_status(req).await {
Ok(resp_) => {
let resp = resp_.into_inner();
resp.entry
}
})
.unwrap_or(0);
println!("Should create address with version: {}", _address_version);
Err(e) => {
// FIXME: Should we default to the last known version - default to 0?
grpc_error!(e)
}
};

let key = KeyPair::generate(0).unwrap();
let ad = wallet.add_keypairs(vec![key])?[0];
if json {
Ok(Box::new(ad.to_string()))
// Note: unused for now as AddressFactory is not yet merged
let _address_version = versioning_status
.into_iter()
.rev()
.find_map(|entry| {
let state = grpc::ComponentStateId::from_i32(entry.state_id)
.unwrap_or(grpc::ComponentStateId::Error);
match state {
grpc::ComponentStateId::Active => Some(entry.state_id),
_ => None,
}
})
.unwrap_or(0);
println!("Should create address with version: {}", _address_version);

let key = KeyPair::generate(0).unwrap();
let ad = wallet.add_keypairs(vec![key])?[0];
if json {
Ok(Box::new(ad.to_string()))
} else {
println!("Generated {} address and added it to the wallet", ad);
println!(
"Type `wallet_info` to show wallet info (keys, addresses, balances ...) and/or `node_add_staking_secret_keys <your secret key>` to start staking with this key.\n"
);
Ok(Box::new(()))
}
} else {
println!("Generated {} address and added it to the wallet", ad);
println!(
"Type `node_start_staking <address>` to start staking with this address.\n"
);
Ok(Box::new(()))
bail!("GRPC is not enabled");
}
}

Expand Down
2 changes: 1 addition & 1 deletion massa-execution-exports/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ massa_final_state = { path = "../massa-final-state" }
massa_ledger_exports = { path = "../massa-ledger-exports", optional = true }
massa_module_cache = { path = "../massa-module-cache" }
massa_versioning = { path = "../massa-versioning" }
massa-sc-runtime = { git = "https://github.com/massalabs/massa-sc-runtime", branch = "testnet_23" }
massa-sc-runtime = { git = "https://github.com/massalabs/massa-sc-runtime", branch = "main" }

[dev-dependencies]
mockall = "0.11.4"
Expand Down
4 changes: 1 addition & 3 deletions massa-execution-exports/src/test_exports/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ impl Default for ExecutionConfig {
fn default() -> Self {
let storage_costs_constants = StorageCostsConstants {
ledger_cost_per_byte: LEDGER_COST_PER_BYTE,
ledger_entry_base_cost: LEDGER_COST_PER_BYTE
.checked_mul_u64(LEDGER_ENTRY_BASE_SIZE as u64)
.expect("Overflow when creating constant ledger_entry_base_cost"),
ledger_entry_base_cost: LEDGER_ENTRY_BASE_COST,
ledger_entry_datastore_base_cost: LEDGER_COST_PER_BYTE
.checked_mul_u64(LEDGER_ENTRY_DATASTORE_BASE_SIZE as u64)
.expect("Overflow when creating constant ledger_entry_datastore_base_size"),
Expand Down
2 changes: 1 addition & 1 deletion massa-execution-worker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ massa_execution_exports = { path = "../massa-execution-exports" }
massa_models = { path = "../massa-models" }
massa_storage = { path = "../massa-storage" }
massa_hash = { path = "../massa-hash" }
massa-sc-runtime = { git = "https://github.com/massalabs/massa-sc-runtime", branch = "testnet_23" }
massa-sc-runtime = { git = "https://github.com/massalabs/massa-sc-runtime", branch = "main" }
massa_module_cache = { path = "../massa-module-cache" }
massa_signature = { path = "../massa-signature" }
massa_time = { path = "../massa-time" }
Expand Down
9 changes: 2 additions & 7 deletions massa-execution-worker/src/tests/scenarios_mandatories.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ mod tests {
ReadOnlyExecutionRequest, ReadOnlyExecutionTarget,
};
use massa_models::config::{
LEDGER_ENTRY_BASE_SIZE, LEDGER_ENTRY_DATASTORE_BASE_SIZE, MIP_STORE_STATS_BLOCK_CONSIDERED,
LEDGER_ENTRY_BASE_COST, LEDGER_ENTRY_DATASTORE_BASE_SIZE, MIP_STORE_STATS_BLOCK_CONSIDERED,
MIP_STORE_STATS_COUNTERS_MAX,
};
use massa_models::prehash::PreHashMap;
Expand Down Expand Up @@ -1220,12 +1220,7 @@ mod tests {
Amount::from_str("100")
.unwrap()
// Storage cost base
.saturating_sub(
exec_cfg
.storage_costs_constants
.ledger_cost_per_byte
.saturating_mul_u64(LEDGER_ENTRY_BASE_SIZE as u64)
)
.saturating_sub(LEDGER_ENTRY_BASE_COST)
);
// stop the execution controller
manager.stop();
Expand Down
4 changes: 2 additions & 2 deletions massa-models/src/config/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ pub const BLOCK_REWARD: Amount = Amount::from_mantissa_scale(3, 1);
pub const LEDGER_COST_PER_BYTE: Amount = Amount::from_mantissa_scale(25, 5);
/// Address size in bytes
pub const ADDRESS_SIZE_BYTES: usize = 32;
/// Cost for a base entry (address + balance (5 bytes constant))
pub const LEDGER_ENTRY_BASE_SIZE: usize = ADDRESS_SIZE_BYTES + 8;
/// Cost for a base entry default 0.01 MASSA
pub const LEDGER_ENTRY_BASE_COST: Amount = Amount::from_mantissa_scale(1, 2);
/// Cost for a base entry datastore 10 bytes constant to avoid paying more for longer keys
pub const LEDGER_ENTRY_DATASTORE_BASE_SIZE: usize = 10;
/// Time between the periods in the same thread.
Expand Down
2 changes: 1 addition & 1 deletion massa-module-cache/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ tracing = "0.1"
massa_hash = { path = "../massa-hash" }
massa_models = { path = "../massa-models" }
massa_serialization = { path = "../massa-serialization" }
massa-sc-runtime = { git = "https://github.com/massalabs/massa-sc-runtime", branch = "testnet_23", features = [
massa-sc-runtime = { git = "https://github.com/massalabs/massa-sc-runtime", branch = "main", features = [
"testing",
] }

Expand Down
2 changes: 1 addition & 1 deletion massa-node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ tracing = { version = "0.1", features = [
"max_level_debug",
"release_max_level_debug",
] }
peernet = { git = "https://github.com/massalabs/PeerNet", branch = "debuig" }
peernet = { git = "https://github.com/massalabs/PeerNet", rev = "bf8adf5" }
tracing-subscriber = "0.3"
paw = "1.0"
structopt = { version = "0.3", features = ["paw"] }
Expand Down
6 changes: 2 additions & 4 deletions massa-node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ use massa_models::config::constants::{
CONSENSUS_BOOTSTRAP_PART_SIZE, DEFERRED_CREDITS_BOOTSTRAP_PART_SIZE, DELTA_F0,
DENUNCIATION_EXPIRE_PERIODS, ENDORSEMENT_COUNT, END_TIMESTAMP,
EXECUTED_OPS_BOOTSTRAP_PART_SIZE, GENESIS_KEY, GENESIS_TIMESTAMP, INITIAL_DRAW_SEED,
LEDGER_COST_PER_BYTE, LEDGER_ENTRY_BASE_SIZE, LEDGER_ENTRY_DATASTORE_BASE_SIZE,
LEDGER_COST_PER_BYTE, LEDGER_ENTRY_BASE_COST, LEDGER_ENTRY_DATASTORE_BASE_SIZE,
LEDGER_PART_SIZE_MESSAGE_BYTES, MAX_ADVERTISE_LENGTH, MAX_ASK_BLOCKS_PER_MESSAGE,
MAX_ASYNC_GAS, MAX_ASYNC_MESSAGE_DATA, MAX_ASYNC_POOL_LENGTH, MAX_BLOCK_SIZE,
MAX_BOOTSTRAP_ASYNC_POOL_CHANGES, MAX_BOOTSTRAP_BLOCKS, MAX_BOOTSTRAP_ERROR_LENGTH,
Expand Down Expand Up @@ -332,9 +332,7 @@ async fn launch(
// Storage costs constants
let storage_costs_constants = StorageCostsConstants {
ledger_cost_per_byte: LEDGER_COST_PER_BYTE,
ledger_entry_base_cost: LEDGER_COST_PER_BYTE
.checked_mul_u64(LEDGER_ENTRY_BASE_SIZE as u64)
.expect("Overflow when creating constant ledger_entry_base_cost"),
ledger_entry_base_cost: LEDGER_ENTRY_BASE_COST,
ledger_entry_datastore_base_cost: LEDGER_COST_PER_BYTE
.checked_mul_u64(LEDGER_ENTRY_DATASTORE_BASE_SIZE as u64)
.expect("Overflow when creating constant ledger_entry_datastore_base_size"),
Expand Down
2 changes: 1 addition & 1 deletion massa-protocol-exports/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ thiserror = "1.0"
nom = "7.1"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
peernet = { git = "https://github.com/massalabs/PeerNet", branch = "debuig" }
peernet = { git = "https://github.com/massalabs/PeerNet", rev = "bf8adf5" }
tempfile = { version = "3.3", optional = true } # use with testing feature
mockall = "0.11.4"

Expand Down
2 changes: 1 addition & 1 deletion massa-protocol-worker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ crossbeam = "0.8"
serde_json = "1.0"
nom = "7.1"
num_enum = "0.5"
peernet = { git = "https://github.com/massalabs/PeerNet", branch = "debuig" }
peernet = { git = "https://github.com/massalabs/PeerNet", rev = "bf8adf5" }
tempfile = { version = "3.3", optional = true } # use with testing feature
rayon = "1.7.0"
schnellru = "0.2.1"
Expand Down
34 changes: 33 additions & 1 deletion massa-protocol-worker/src/handlers/block_handler/cache.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{sync::Arc, time::Instant};
use std::{collections::HashSet, sync::Arc, time::Instant};

use massa_models::{block_header::SecuredHeader, block_id::BlockId};
use massa_protocol_exports::PeerId;
Expand Down Expand Up @@ -47,6 +47,38 @@ impl BlockCache {
max_known_blocks_by_peer,
}
}

pub fn update_cache(
&mut self,
peers_connected: HashSet<PeerId>,
max_known_blocks_by_peer: u32,
) {
let peers: Vec<PeerId> = self
.blocks_known_by_peer
.iter()
.map(|(id, _)| id.clone())
.collect();

// Clean shared cache if peers do not exist anymore
for peer_id in peers {
if !peers_connected.contains(&peer_id) {
self.blocks_known_by_peer.remove(&peer_id);
}
}

// Add new potential peers
for peer_id in peers_connected {
if self.blocks_known_by_peer.peek(&peer_id).is_none() {
self.blocks_known_by_peer.insert(
peer_id.clone(),
(
LruMap::new(ByLength::new(max_known_blocks_by_peer)),
Instant::now(),
),
);
}
}
}
}

pub type SharedBlockCache = Arc<RwLock<BlockCache>>;
43 changes: 9 additions & 34 deletions massa-protocol-worker/src/handlers/block_handler/propagation.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use std::{collections::VecDeque, thread::JoinHandle, time::Instant};
use std::{collections::VecDeque, thread::JoinHandle};

use crossbeam::channel::{Receiver, Sender};
use massa_logging::massa_trace;
use massa_models::{block_id::BlockId, prehash::PreHashSet};
use massa_protocol_exports::PeerId;
use massa_protocol_exports::{ProtocolConfig, ProtocolError};
use massa_storage::Storage;
use schnellru::{ByLength, LruMap};
use tracing::{debug, info, warn};

use crate::{
Expand Down Expand Up @@ -64,38 +63,14 @@ impl PropagationThread {
continue;
}
};

// Clean shared cache if peers do not exist anymore
{
let mut cache_write = self.cache.write();
let peers: Vec<PeerId> = cache_write
.blocks_known_by_peer
.iter()
.map(|(id, _)| id.clone())
.collect();
let peers_connected =
self.active_connections.get_peer_ids_connected();
for peer_id in peers {
if !peers_connected.contains(&peer_id) {
cache_write.blocks_known_by_peer.remove(&peer_id);
}
}
for peer_id in peers_connected {
if cache_write.blocks_known_by_peer.peek(&peer_id).is_none() {
//TODO: Change to detect the connection before
cache_write.blocks_known_by_peer.insert(
peer_id,
(
LruMap::new(
ByLength::new(self.config.max_node_known_blocks_size.try_into()
.expect("max_node_known_blocks_size in config must be > 0")),
),
Instant::now(),
),
);
}
}
}
let peers_connected = self.active_connections.get_peer_ids_connected();
self.cache.write().update_cache(
peers_connected,
self.config
.max_node_known_blocks_size
.try_into()
.expect("max_node_known_blocks_size is too big"),
);
{
let cache_read = self.cache.read();
for (peer_id, (blocks_known, _)) in
Expand Down
Loading

0 comments on commit 2e782bd

Please sign in to comment.