Skip to content

Commit

Permalink
Add docs and fix latest warnings
Browse files Browse the repository at this point in the history
Add documentation for the worker execution, to complete later, it will
help me to do the execution tests.

This commit also fix new/last warnings in the code.
  • Loading branch information
adrien-zinger committed Feb 14, 2022
1 parent 4d16e6b commit 2604975
Show file tree
Hide file tree
Showing 9 changed files with 256 additions and 138 deletions.
26 changes: 13 additions & 13 deletions massa-consensus-worker/src/tests/scenarios_ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use super::tools::*;
use massa_consensus_exports::tools::*;

use massa_consensus_exports::settings::ConsensusChannels;
use massa_graph::ledger::Ledger;
use massa_graph::{ledger::Ledger, LedgerConfig};
use massa_models::ledger_models::LedgerData;
use massa_models::ledger_models::{LedgerChange, LedgerChanges};
use massa_models::{Address, Amount, Slot};
Expand All @@ -33,7 +33,7 @@ async fn test_ledger_init() {
roll_counts_file.path(),
staking_file.path(),
);
let ledger = Ledger::new((&cfg).into(), None);
let ledger = Ledger::new(LedgerConfig::from(&cfg), None);
assert!(ledger.is_ok());
}

Expand All @@ -49,7 +49,7 @@ async fn test_ledger_initializes_get_latest_final_periods() {
roll_counts_file.path(),
staking_file.path(),
);
let ledger = Ledger::new((&cfg).into(), None).unwrap();
let ledger = Ledger::new(LedgerConfig::from(&cfg), None).unwrap();

for latest_final in ledger
.get_latest_final_periods()
Expand All @@ -71,7 +71,7 @@ async fn test_ledger_final_balance_increment_new_address() {
roll_counts_file.path(),
staking_file.path(),
);
let ledger = Ledger::new((&cfg).into(), None).unwrap();
let ledger = Ledger::new(LedgerConfig::from(&cfg), None).unwrap();

let private_key = generate_random_private_key();
let public_key = derive_public_key(&private_key);
Expand Down Expand Up @@ -118,7 +118,7 @@ async fn test_ledger_final_balance_increment_address_above_max() {
roll_counts_file.path(),
staking_file.path(),
);
let ledger = Ledger::new((&cfg).into(), None).unwrap();
let ledger = Ledger::new(LedgerConfig::from(&cfg), None).unwrap();

let private_key = generate_random_private_key();
let public_key = derive_public_key(&private_key);
Expand Down Expand Up @@ -178,7 +178,7 @@ async fn test_ledger_final_balance_decrement_address_balance_to_zero() {
roll_counts_file.path(),
staking_file.path(),
);
let ledger = Ledger::new((&cfg).into(), None).unwrap();
let ledger = Ledger::new(LedgerConfig::from(&cfg), None).unwrap();

let private_key = generate_random_private_key();
let public_key = derive_public_key(&private_key);
Expand Down Expand Up @@ -251,7 +251,7 @@ async fn test_ledger_final_balance_decrement_address_below_zero() {
roll_counts_file.path(),
staking_file.path(),
);
let ledger = Ledger::new((&cfg).into(), None).unwrap();
let ledger = Ledger::new(LedgerConfig::from(&cfg), None).unwrap();

let private_key = generate_random_private_key();
let public_key = derive_public_key(&private_key);
Expand Down Expand Up @@ -338,7 +338,7 @@ async fn test_ledger_final_balance_decrement_non_existing_address() {
roll_counts_file.path(),
staking_file.path(),
);
let ledger = Ledger::new((&cfg).into(), None).unwrap();
let ledger = Ledger::new(LedgerConfig::from(&cfg), None).unwrap();

let private_key = generate_random_private_key();
let public_key = derive_public_key(&private_key);
Expand Down Expand Up @@ -372,7 +372,7 @@ async fn test_ledger_final_balance_non_existing_address() {
roll_counts_file.path(),
staking_file.path(),
);
let ledger = Ledger::new((&cfg).into(), None).unwrap();
let ledger = Ledger::new(LedgerConfig::from(&cfg), None).unwrap();

let private_key = generate_random_private_key();
let public_key = derive_public_key(&private_key);
Expand Down Expand Up @@ -400,7 +400,7 @@ async fn test_ledger_final_balance_duplicate_address() {
roll_counts_file.path(),
staking_file.path(),
);
let ledger = Ledger::new((&cfg).into(), None).unwrap();
let ledger = Ledger::new(LedgerConfig::from(&cfg), None).unwrap();

let private_key = generate_random_private_key();
let public_key = derive_public_key(&private_key);
Expand Down Expand Up @@ -432,7 +432,7 @@ async fn test_ledger_final_balance_multiple_addresses() {
roll_counts_file.path(),
staking_file.path(),
);
let ledger = Ledger::new((&cfg).into(), None).unwrap();
let ledger = Ledger::new(LedgerConfig::from(&cfg), None).unwrap();

let mut addresses = vec![];
for _ in 0..5 {
Expand Down Expand Up @@ -469,7 +469,7 @@ async fn test_ledger_clear() {
roll_counts_file.path(),
staking_file.path(),
);
let ledger = Ledger::new((&cfg).into(), None).unwrap();
let ledger = Ledger::new(LedgerConfig::from(&cfg), None).unwrap();

let private_key = generate_random_private_key();
let public_key = derive_public_key(&private_key);
Expand Down Expand Up @@ -527,7 +527,7 @@ async fn test_ledger_read_whole() {
roll_counts_file.path(),
staking_file.path(),
);
let ledger = Ledger::new((&cfg).into(), None).unwrap();
let ledger = Ledger::new(LedgerConfig::from(&cfg), None).unwrap();

let private_key = generate_random_private_key();
let public_key = derive_public_key(&private_key);
Expand Down
45 changes: 33 additions & 12 deletions massa-consensus-worker/src/tests/test_block_graph.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::tests::tools::get_dummy_block_id;
use massa_consensus_exports::ConsensusConfig;
use massa_graph::{
create_genesis_block, export_active_block::ExportActiveBlock, ledger::LedgerSubset, BlockGraph,
BootstrapableGraph,
create_genesis_block, export_active_block::ExportActiveBlock, ledger::LedgerSubset,
settings::GraphConfig, BlockGraph, BootstrapableGraph,
};
use massa_hash::hash::Hash;
use massa_models::{
Expand Down Expand Up @@ -146,8 +146,9 @@ pub async fn test_get_ledger_at_parents() {
Address::from_bs58_check("21bU2xruH7bFzfcUhJ6SGjnLmC9cMt1kxzqFr11eV58uj7Ui8h").unwrap();
assert_eq!(1, address_d.get_thread(thread_count));

let (hash_genesist0, block_genesist0) = create_genesis_block(&(&cfg).into(), 0).unwrap();
let (hash_genesist1, block_genesist1) = create_genesis_block(&(&cfg).into(), 1).unwrap();
let graph_cfg = GraphConfig::from(&cfg);
let (hash_genesist0, block_genesist0) = create_genesis_block(&graph_cfg, 0).unwrap();
let (hash_genesist1, block_genesist1) = create_genesis_block(&graph_cfg, 1).unwrap();
let export_genesist0 = ExportActiveBlock {
block: block_genesist0,
parents: vec![], // one (hash, period) per thread ( if not genesis )
Expand Down Expand Up @@ -363,12 +364,30 @@ pub async fn test_get_ledger_at_parents() {
active_blocks: vec![
(hash_genesist0, export_genesist0),
(hash_genesist1, export_genesist1),
(get_dummy_block_id("blockp1t0"), (&blockp1t0).into()),
(get_dummy_block_id("blockp1t1"), (&blockp1t1).into()),
(get_dummy_block_id("blockp2t0"), (&blockp2t0).into()),
(get_dummy_block_id("blockp2t1"), (&blockp2t1).into()),
(get_dummy_block_id("blockp3t0"), (&blockp3t0).into()),
(get_dummy_block_id("blockp3t1"), (&blockp3t1).into()),
(
get_dummy_block_id("blockp1t0"),
ExportActiveBlock::from(&blockp1t0),
),
(
get_dummy_block_id("blockp1t1"),
ExportActiveBlock::from(&blockp1t1),
),
(
get_dummy_block_id("blockp2t0"),
ExportActiveBlock::from(&blockp2t0),
),
(
get_dummy_block_id("blockp2t1"),
ExportActiveBlock::from(&blockp2t1),
),
(
get_dummy_block_id("blockp3t0"),
ExportActiveBlock::from(&blockp3t0),
),
(
get_dummy_block_id("blockp3t1"),
ExportActiveBlock::from(&blockp3t1),
),
]
.into_iter()
.collect(),
Expand Down Expand Up @@ -407,7 +426,7 @@ pub async fn test_get_ledger_at_parents() {
),
};

let block_graph = BlockGraph::new((&cfg).into(), Some(export_graph))
let block_graph = BlockGraph::new(GraphConfig::from(&cfg), Some(export_graph))
.await
.unwrap();

Expand Down Expand Up @@ -587,7 +606,9 @@ fn test_bootsrapable_graph_serialize_compact() {
async fn test_clique_calculation() {
let ledger_file = generate_ledger_file(&Map::default());
let cfg = ConsensusConfig::from(ledger_file.path());
let mut block_graph = BlockGraph::new((&cfg).into(), None).await.unwrap();
let mut block_graph = BlockGraph::new(GraphConfig::from(&cfg), None)
.await
.unwrap();
let hashes: Vec<BlockId> = vec![
"VzCRpnoZVYY1yQZTXtVQbbxwzdu6hYtdCUZB5BXWSabsiXyfP",
"JnWwNHRR1tUD7UJfnEFgDB4S4gfDTX2ezLadr7pcwuZnxTvn1",
Expand Down
14 changes: 9 additions & 5 deletions massa-consensus-worker/src/tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ use tracing::{debug, error, info};

use crate::consensus_worker::ConsensusWorker;
use massa_consensus_exports::settings::ConsensusConfig;
use massa_graph::{BlockGraph, BootstrapableGraph};
use massa_graph::{settings::GraphConfig, BlockGraph, BootstrapableGraph};
use massa_models::{prehash::Map, Address};
use massa_proof_of_stake_exports::{ExportProofOfStake, ProofOfStake};
use massa_proof_of_stake_exports::{ExportProofOfStake, ProofOfStake, ProofOfStakeConfig};
use massa_signature::{derive_public_key, PrivateKey, PublicKey};
use std::path::Path;
use tokio::sync::mpsc;
Expand Down Expand Up @@ -75,9 +75,13 @@ pub async fn start_consensus_controller(
let staking_keys = load_initial_staking_keys(&cfg.staking_keys_path).await?;

// start worker
let block_db = BlockGraph::new((&cfg).into(), boot_graph).await?;
let mut pos =
ProofOfStake::new((&cfg).into(), block_db.get_genesis_block_ids(), boot_pos).await?;
let block_db = BlockGraph::new(GraphConfig::from(&cfg), boot_graph).await?;
let mut pos = ProofOfStake::new(
ProofOfStakeConfig::from(&cfg),
block_db.get_genesis_block_ids(),
boot_pos,
)
.await?;
pos.set_watched_addresses(staking_keys.keys().copied().collect());
let (command_tx, command_rx) = mpsc::channel::<ConsensusCommand>(CHANNEL_SIZE);
let (event_tx, event_rx) = mpsc::channel::<ConsensusEvent>(CHANNEL_SIZE);
Expand Down
4 changes: 0 additions & 4 deletions massa-execution/src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,6 @@ impl ExecutionManager {
///
/// # Arguments
/// * cfg: execution configuration
/// * thread_count: number of threads
/// * genesis_timestamp: genesis timestamp
/// * t0: period duration
/// * clock_compensation: clock compensation in milliseconds
/// * bootstrap_state: optional bootstrap state
///
/// TODO: add a consensus command sender,
Expand Down
17 changes: 17 additions & 0 deletions massa-execution/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ impl VM {
/// runs an SCE-final execution step
/// See https://github.com/massalabs/massa/wiki/vm_ledger_interaction
///
/// If the node has already compute the bytecodes and found corresponding
/// `ledger_changes`, use it, clear step history and run the `step` again
/// otherwise.
///
/// Prune old `final_events` if `max_final_events` overflow
/// # Parameters
/// * step: execution step to run
/// * max_final_events: max number of events kept in cache (todo should be removed when config become static)
Expand Down Expand Up @@ -314,6 +319,12 @@ impl VM {
}

/// Run code in read-only mode
/// Same as `run_step_internal()` but don't save ledger_changes.
/// Execute a `bytecode` with an `address` as sender context and a
/// `simulated_gas_price` with some input parameters as context.
///
/// As resulted and send a `ExecuteReadOnlyResponse` through the result
/// sender.
pub(crate) fn run_read_only(
&self,
slot: Slot,
Expand Down Expand Up @@ -485,6 +496,12 @@ impl VM {
/// runs an SCE-active execution step
/// See https://github.com/massalabs/massa/wiki/vm_ledger_interaction
///
/// Truncate the history by the number of slots between last added step in
/// `step_history` and the `step` in parameter. (todo: explain why)
///
/// Call the internal `run_step_internal()` and push the `StepHistoryItem`
/// into `self.step_history`.
///
/// # Parameters
/// * step: execution step to run
pub(crate) fn run_active_step(&mut self, step: ExecutionStep) {
Expand Down
Loading

0 comments on commit 2604975

Please sign in to comment.