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

Harden block handler (Versioning) #4178

Merged
merged 13 commits into from
Jul 4, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 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 massa-bootstrap/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ bitvec = { version = "1.0", features = ["serde"] }
lazy_static = "1.4"
tempfile = "3.3"
serial_test = "2.0.0"
num = "0.4"
massa_final_state = { path = "../massa-final-state", features = ["testing"] }
massa_async_pool = { path = "../massa-async-pool", features = ["testing"] }
massa_ledger_exports = { path = "../massa-ledger-exports" }
Expand Down
4 changes: 3 additions & 1 deletion massa-bootstrap/src/tests/tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ use massa_serialization::{DeserializeError, Deserializer, Serializer};
use massa_signature::KeyPair;
use massa_time::MassaTime;
use massa_versioning::versioning::{MipStatsConfig, MipStore};
use num::rational::Ratio;
use rand::Rng;
use std::collections::{HashMap, HashSet};
use std::str::FromStr;
Expand Down Expand Up @@ -338,6 +339,7 @@ pub fn get_random_final_state_bootstrap(
[],
MipStatsConfig {
block_count_considered: 10,
warn_announced_version_ratio: Ratio::new_raw(30, 100),
},
))
.unwrap();
Expand Down Expand Up @@ -453,7 +455,7 @@ pub fn get_boot_state() -> BootstrapableGraph {
header: BlockHeader::new_verifiable(
BlockHeader {
current_version: 0,
announced_version: 0,
announced_version: None,
// associated slot
// all header endorsements are supposed to point towards this one
slot: Slot::new(1, 0),
Expand Down
2 changes: 1 addition & 1 deletion massa-consensus-exports/src/export_active_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ impl Deserializer<ExportActiveBlock> for ExportActiveBlockDeserializer {
/// let orig_header = BlockHeader::new_verifiable(
/// BlockHeader {
/// current_version: 0,
/// announced_version: 0,
/// announced_version: None,
/// slot: Slot::new(1, 1),
/// parents,
/// operation_merkle_root: Hash::compute_from("mno".as_bytes()),
Expand Down
2 changes: 1 addition & 1 deletion massa-consensus-worker/src/tests/tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ pub fn create_block_with_merkle_root(
let header = BlockHeader::new_verifiable(
BlockHeader {
current_version: 0,
announced_version: 0,
announced_version: None,
denunciations: vec![],
slot,
parents: best_parents,
Expand Down
2 changes: 1 addition & 1 deletion massa-consensus-worker/src/worker/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub fn create_genesis_block(
// VERSIONNING TODO: what to implement here in case of restart?
BlockHeader {
current_version: 0,
announced_version: 0,
announced_version: None,
slot: Slot::new(cfg.last_start_period, thread_number),
parents: Vec::new(),
operation_merkle_root: Hash::compute_from(&Vec::new()),
Expand Down
2 changes: 1 addition & 1 deletion massa-execution-exports/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ pub struct ExecutedBlockInfo {
/// Current network version (see Versioning doc)
pub current_version: u32,
/// Announced network version (see Versioning doc)
pub announced_version: u32,
pub announced_version: Option<u32>,
}

/// structure describing the output of a single execution
Expand Down
3 changes: 3 additions & 0 deletions massa-execution-worker/src/interface_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ use massa_models::{
};
use massa_sc_runtime::RuntimeModule;
use massa_sc_runtime::{Interface, InterfaceClone};
#[cfg(feature = "testing")]
use num::rational::Ratio;
use parking_lot::Mutex;
use rand::Rng;
use sha2::{Digest, Sha256};
Expand Down Expand Up @@ -101,6 +103,7 @@ impl InterfaceImpl {
// create an empty default store
let mip_stats_config = MipStatsConfig {
block_count_considered: MIP_STORE_STATS_BLOCK_CONSIDERED,
warn_announced_version_ratio: Ratio::new_raw(30, 100),
};
let mip_store =
MipStore::try_from(([], mip_stats_config)).expect("Cannot create an empty MIP store");
Expand Down
4 changes: 3 additions & 1 deletion massa-execution-worker/src/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use massa_pos_worker::start_selector_worker;
use massa_signature::KeyPair;
use massa_time::MassaTime;
use massa_versioning::versioning::{MipStatsConfig, MipStore};
use num::rational::Ratio;
use parking_lot::RwLock;
use std::str::FromStr;
use std::{
Expand Down Expand Up @@ -117,6 +118,7 @@ pub fn get_sample_state(
[],
MipStatsConfig {
block_count_considered: 10,
warn_announced_version_ratio: Ratio::new_raw(30, 100),
},
))
.unwrap();
Expand Down Expand Up @@ -172,7 +174,7 @@ pub fn create_block(
let header = BlockHeader::new_verifiable(
BlockHeader {
current_version: 0,
announced_version: 0,
announced_version: None,
slot,
parents: vec![],
operation_merkle_root,
Expand Down
25 changes: 25 additions & 0 deletions massa-execution-worker/src/tests/scenarios_mandatories.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ mod tests {
// init the MIP store
let mip_stats_config = MipStatsConfig {
block_count_considered: MIP_STORE_STATS_BLOCK_CONSIDERED,
warn_announced_version_ratio: Ratio::new_raw(30, 100),
};
let mip_store = MipStore::try_from(([], mip_stats_config)).unwrap();

Expand Down Expand Up @@ -101,6 +102,7 @@ mod tests {
// init the MIP store
let mip_stats_config = MipStatsConfig {
block_count_considered: MIP_STORE_STATS_BLOCK_CONSIDERED,
warn_announced_version_ratio: Ratio::new_raw(30, 100),
};
let mip_store = MipStore::try_from(([], mip_stats_config)).unwrap();

Expand Down Expand Up @@ -148,6 +150,7 @@ mod tests {
// init the MIP store
let mip_stats_config = MipStatsConfig {
block_count_considered: MIP_STORE_STATS_BLOCK_CONSIDERED,
warn_announced_version_ratio: Ratio::new_raw(30, 100),
};
let mip_store = MipStore::try_from(([], mip_stats_config)).unwrap();
// get a sample final state
Expand Down Expand Up @@ -258,6 +261,7 @@ mod tests {
// init the MIP store
let mip_stats_config = MipStatsConfig {
block_count_considered: MIP_STORE_STATS_BLOCK_CONSIDERED,
warn_announced_version_ratio: Ratio::new_raw(30, 100),
};
let mip_store = MipStore::try_from(([], mip_stats_config)).unwrap();
// get a sample final state
Expand Down Expand Up @@ -425,6 +429,7 @@ mod tests {
// init the MIP store
let mip_stats_config = MipStatsConfig {
block_count_considered: MIP_STORE_STATS_BLOCK_CONSIDERED,
warn_announced_version_ratio: Ratio::new_raw(30, 100),
};
let mip_store = MipStore::try_from(([], mip_stats_config)).unwrap();
// get a sample final state
Expand Down Expand Up @@ -587,6 +592,7 @@ mod tests {
// init the MIP store
let mip_stats_config = MipStatsConfig {
block_count_considered: MIP_STORE_STATS_BLOCK_CONSIDERED,
warn_announced_version_ratio: Ratio::new_raw(30, 100),
};
let mip_store = MipStore::try_from(([], mip_stats_config)).unwrap();

Expand Down Expand Up @@ -704,6 +710,7 @@ mod tests {
// init the MIP store
let mip_stats_config = MipStatsConfig {
block_count_considered: MIP_STORE_STATS_BLOCK_CONSIDERED,
warn_announced_version_ratio: Ratio::new_raw(30, 100),
};
let mip_store = MipStore::try_from(([], mip_stats_config)).unwrap();

Expand Down Expand Up @@ -812,6 +819,7 @@ mod tests {
// init the MIP store
let mip_stats_config = MipStatsConfig {
block_count_considered: MIP_STORE_STATS_BLOCK_CONSIDERED,
warn_announced_version_ratio: Ratio::new_raw(30, 100),
};
let mip_store = MipStore::try_from(([], mip_stats_config)).unwrap();

Expand Down Expand Up @@ -942,6 +950,7 @@ mod tests {
// init the MIP store
let mip_stats_config = MipStatsConfig {
block_count_considered: MIP_STORE_STATS_BLOCK_CONSIDERED,
warn_announced_version_ratio: Ratio::new_raw(30, 100),
};
let mip_store = MipStore::try_from(([], mip_stats_config)).unwrap();

Expand Down Expand Up @@ -1061,6 +1070,7 @@ mod tests {
// init the MIP store
let mip_stats_config = MipStatsConfig {
block_count_considered: MIP_STORE_STATS_BLOCK_CONSIDERED,
warn_announced_version_ratio: Ratio::new_raw(30, 100),
};
let mip_store = MipStore::try_from(([], mip_stats_config)).unwrap();

Expand Down Expand Up @@ -1221,6 +1231,7 @@ mod tests {
// init the MIP store
let mip_stats_config = MipStatsConfig {
block_count_considered: MIP_STORE_STATS_BLOCK_CONSIDERED,
warn_announced_version_ratio: Ratio::new_raw(30, 100),
};
let mip_store = MipStore::try_from(([], mip_stats_config)).unwrap();

Expand Down Expand Up @@ -1326,6 +1337,7 @@ mod tests {
// init the MIP store
let mip_stats_config = MipStatsConfig {
block_count_considered: MIP_STORE_STATS_BLOCK_CONSIDERED,
warn_announced_version_ratio: Ratio::new_raw(30, 100),
};
let mip_store = MipStore::try_from(([], mip_stats_config)).unwrap();

Expand Down Expand Up @@ -1446,6 +1458,7 @@ mod tests {
// init the MIP store
let mip_stats_config = MipStatsConfig {
block_count_considered: MIP_STORE_STATS_BLOCK_CONSIDERED,
warn_announced_version_ratio: Ratio::new_raw(30, 100),
};
let mip_store = MipStore::try_from(([], mip_stats_config)).unwrap();

Expand Down Expand Up @@ -1549,6 +1562,7 @@ mod tests {
// init the MIP store
let mip_stats_config = MipStatsConfig {
block_count_considered: MIP_STORE_STATS_BLOCK_CONSIDERED,
warn_announced_version_ratio: Ratio::new_raw(30, 100),
};
let mip_store = MipStore::try_from(([], mip_stats_config)).unwrap();

Expand Down Expand Up @@ -1654,6 +1668,7 @@ mod tests {
// init the MIP store
let mip_stats_config = MipStatsConfig {
block_count_considered: MIP_STORE_STATS_BLOCK_CONSIDERED,
warn_announced_version_ratio: Ratio::new_raw(30, 100),
};
let mip_store = MipStore::try_from(([], mip_stats_config)).unwrap();

Expand Down Expand Up @@ -1865,6 +1880,7 @@ mod tests {
// init the MIP store
let mip_stats_config = MipStatsConfig {
block_count_considered: MIP_STORE_STATS_BLOCK_CONSIDERED,
warn_announced_version_ratio: Ratio::new_raw(30, 100),
};
let mip_store = MipStore::try_from(([], mip_stats_config)).unwrap();

Expand Down Expand Up @@ -2033,6 +2049,7 @@ mod tests {
// init the MIP store
let mip_stats_config = MipStatsConfig {
block_count_considered: MIP_STORE_STATS_BLOCK_CONSIDERED,
warn_announced_version_ratio: Ratio::new_raw(30, 100),
};
let mip_store = MipStore::try_from(([], mip_stats_config)).unwrap();

Expand Down Expand Up @@ -2208,6 +2225,7 @@ mod tests {
// init the MIP store
let mip_stats_config = MipStatsConfig {
block_count_considered: MIP_STORE_STATS_BLOCK_CONSIDERED,
warn_announced_version_ratio: Ratio::new_raw(30, 100),
};
let mip_store = MipStore::try_from(([], mip_stats_config)).unwrap();

Expand Down Expand Up @@ -2303,6 +2321,7 @@ mod tests {
// init the MIP store
let mip_stats_config = MipStatsConfig {
block_count_considered: MIP_STORE_STATS_BLOCK_CONSIDERED,
warn_announced_version_ratio: Ratio::new_raw(30, 100),
};
let mip_store = MipStore::try_from(([], mip_stats_config)).unwrap();

Expand Down Expand Up @@ -2395,6 +2414,7 @@ mod tests {
// init the MIP store
let mip_stats_config = MipStatsConfig {
block_count_considered: MIP_STORE_STATS_BLOCK_CONSIDERED,
warn_announced_version_ratio: Ratio::new_raw(30, 100),
};
let mip_store = MipStore::try_from(([], mip_stats_config)).unwrap();

Expand Down Expand Up @@ -2487,6 +2507,7 @@ mod tests {
// init the MIP store
let mip_stats_config = MipStatsConfig {
block_count_considered: MIP_STORE_STATS_BLOCK_CONSIDERED,
warn_announced_version_ratio: Ratio::new_raw(30, 100),
};
let mip_store = MipStore::try_from(([], mip_stats_config)).unwrap();

Expand Down Expand Up @@ -2640,6 +2661,7 @@ mod tests {
// init the MIP store
let mip_stats_config = MipStatsConfig {
block_count_considered: MIP_STORE_STATS_BLOCK_CONSIDERED,
warn_announced_version_ratio: Ratio::new_raw(30, 100),
};
let mip_store = MipStore::try_from(([], mip_stats_config)).unwrap();

Expand Down Expand Up @@ -2756,6 +2778,7 @@ mod tests {
// init the MIP store
let mip_stats_config = MipStatsConfig {
block_count_considered: MIP_STORE_STATS_BLOCK_CONSIDERED,
warn_announced_version_ratio: Ratio::new_raw(30, 100),
};
let mip_store = MipStore::try_from(([], mip_stats_config)).unwrap();

Expand Down Expand Up @@ -2907,6 +2930,7 @@ mod tests {
// init the MIP store
let mip_stats_config = MipStatsConfig {
block_count_considered: MIP_STORE_STATS_BLOCK_CONSIDERED,
warn_announced_version_ratio: Ratio::new_raw(30, 100),
};
let mip_store = MipStore::try_from(([], mip_stats_config)).unwrap();
// init the storage
Expand Down Expand Up @@ -3008,6 +3032,7 @@ mod tests {
// init the MIP store
let mip_stats_config = MipStatsConfig {
block_count_considered: MIP_STORE_STATS_BLOCK_CONSIDERED,
warn_announced_version_ratio: Ratio::new_raw(30, 100),
};
let mip_store = MipStore::try_from(([], mip_stats_config)).unwrap();
// init the storage
Expand Down
2 changes: 1 addition & 1 deletion massa-factory-exports/src/test_exports/tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub fn create_empty_block(keypair: &KeyPair, slot: &Slot) -> SecureShareBlock {
let header = BlockHeader::new_verifiable(
BlockHeader {
current_version: 0,
announced_version: 0,
announced_version: None,
slot: *slot,
parents: Vec::new(),
operation_merkle_root: Hash::compute_from(&Vec::new()),
Expand Down
1 change: 1 addition & 0 deletions massa-factory-worker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ massa_pool_exports = { path = "../massa-pool-exports" }
massa_versioning = { path = "../massa-versioning" }

[dev-dependencies]
num = "0.4"
massa_protocol_exports = { path = "../massa-protocol-exports", features=["testing"] }
massa_consensus_exports = { path = "../massa-consensus-exports", features = ["testing"] }
massa_factory_exports = { path = "../massa-factory-exports", features=["testing"] }
Expand Down
2 changes: 2 additions & 0 deletions massa-factory-worker/src/tests/tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use massa_consensus_exports::test_exports::{
use massa_models::config::MIP_STORE_STATS_BLOCK_CONSIDERED;
use massa_versioning::versioning::MipStatsConfig;
use massa_versioning::versioning::MipStore;
use num::rational::Ratio;
use parking_lot::RwLock;
use std::{sync::Arc, thread::sleep, time::Duration};

Expand Down Expand Up @@ -83,6 +84,7 @@ impl TestFactory {
// create an empty default store
let mip_stats_config = MipStatsConfig {
block_count_considered: MIP_STORE_STATS_BLOCK_CONSIDERED,
warn_announced_version_ratio: Ratio::new_raw(30, 100),
};
let mip_store =
MipStore::try_from(([], mip_stats_config)).expect("Cannot create an empty MIP store");
Expand Down
1 change: 1 addition & 0 deletions massa-final-state/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ nom = "=7.1"
bs58 = { version = "0.4", features = ["check"] }
thiserror = "1.0"
tracing = "0.1"
num = "0.4"

# custom modules
massa_ledger_exports = { path = "../massa-ledger-exports" }
Expand Down
Loading