From 3db8c6f6f8e8724c9e19d02c368098b5e85b152b Mon Sep 17 00:00:00 2001 From: Moncef AOUDIA Date: Mon, 9 Oct 2023 18:02:43 +0200 Subject: [PATCH 01/13] feat: implement missing filter parsing --- .../src/stream/new_slot_execution_outputs.rs | 124 ++++++++++++------ 1 file changed, 83 insertions(+), 41 deletions(-) diff --git a/massa-grpc/src/stream/new_slot_execution_outputs.rs b/massa-grpc/src/stream/new_slot_execution_outputs.rs index 5004dd848a4..0d4e6a59462 100644 --- a/massa-grpc/src/stream/new_slot_execution_outputs.rs +++ b/massa-grpc/src/stream/new_slot_execution_outputs.rs @@ -6,12 +6,15 @@ use crate::server::MassaPublicGrpc; use crate::SlotRange; use futures_util::StreamExt; use massa_execution_exports::{ExecutionOutput, SlotExecutionOutput}; +use massa_models::address::Address; +use massa_models::operation::OperationId; use massa_models::slot::Slot; use massa_proto_rs::massa::api::v1::{self as grpc_api, NewSlotExecutionOutputsRequest}; use massa_proto_rs::massa::model::v1::{self as grpc_model}; use std::collections::HashSet; use std::io::ErrorKind; use std::pin::Pin; +use std::str::FromStr; use tokio::select; use tonic::{Request, Streaming}; use tracing::log::{error, warn}; @@ -26,7 +29,6 @@ pub type NewSlotExecutionOutputsStreamType = Pin< >, >; -//TODO implement remaining sub filters // Type declaration for NewSlotExecutionOutputsFilter #[derive(Clone, Debug, Default)] struct Filter { @@ -50,6 +52,17 @@ struct Filter { struct AsyncPoolChangesFilter { // Do not return any message none: Option<()>, + // The type of the change + change_type: Option, + // The handler function name within the destination address bytecode + handler: Option, + // The address towards which the message is being sent + destination_address: Option
, + // The address that sent the message + emitter_address: Option
, + // Boolean that determine if the message can be executed. For messages without filter this boolean is always true. + // For messages with filter, this boolean is true if the filter has been matched between `validity_start` and current slot. + can_be_executed: Option, } #[derive(Clone, Debug, Default)] @@ -62,18 +75,30 @@ struct ExecutedDenounciationFilter { struct ExecutionEventFilter { // Do not return any message none: Option<()>, + // Caller address + caller_address: Option
, + // Emitter address + emitter_address: Option
, + // Original operation id + original_operation_id: Option, + // Whether the event is a failure + is_failure: Option, } #[derive(Clone, Debug, Default)] struct ExecutedOpsChangesFilter { // Do not return any message none: Option<()>, + // Operation id + operation_id: Option, } #[derive(Clone, Debug, Default)] struct LedgerChangesFilter { // Do not return any message none: Option<()>, + // Address for which we have ledger changes + address: Option
, } /// Creates a new stream of new produced and received slot execution outputs @@ -240,75 +265,92 @@ fn get_filter( }, grpc_api::new_slot_execution_outputs_filter::Filter::AsyncPoolChangesFilter(filter) => { if let Some(filter) = filter.filter { + let mut nested_filter = AsyncPoolChangesFilter::default(); match filter { grpc_api::async_pool_changes_filter::Filter::None(_) => { - async_pool_changes_filter = Some(AsyncPoolChangesFilter { - none: Some(()), - }); + nested_filter.none = Some(()); + }, + grpc_api::async_pool_changes_filter::Filter::Type(change_type) => { + nested_filter.change_type = Some(change_type); + }, + grpc_api::async_pool_changes_filter::Filter::Handler(function) => { + nested_filter.handler = Some(function); + }, + grpc_api::async_pool_changes_filter::Filter::DestinationAddress(addr) => { + nested_filter.destination_address = Some(Address::from_str(&addr)?); + }, + grpc_api::async_pool_changes_filter::Filter::EmitterAddress(addr) => { + nested_filter.emitter_address = Some(Address::from_str(&addr)?); + }, + grpc_api::async_pool_changes_filter::Filter::CanBeExecuted(can_be_executed) => { + nested_filter.can_be_executed = Some(can_be_executed); }, - _ => { - async_pool_changes_filter = Some(AsyncPoolChangesFilter { - none: None, - }) } + async_pool_changes_filter = Some(nested_filter); } - } - }, + }, grpc_api::new_slot_execution_outputs_filter::Filter::ExecutedDenounciationFilter(filter) => { if let Some(filter) = filter.filter { + let mut nested_filter = ExecutedDenounciationFilter::default(); match filter { grpc_api::executed_denounciation_filter::Filter::None(_) => { - executed_denounciation_filter = Some(ExecutedDenounciationFilter { - none: Some(()), - }); + nested_filter.none = Some(()); }, + } + executed_denounciation_filter = Some(nested_filter); } - }}, + }, grpc_api::new_slot_execution_outputs_filter::Filter::EventFilter(filter) => { if let Some(filter) = filter.filter { + let mut nested_filter = ExecutionEventFilter::default(); match filter { grpc_api::execution_event_filter::Filter::None(_) => { - execution_event_filter = Some(ExecutionEventFilter { - none: Some(()), - }); + nested_filter.none = Some(()); + }, + grpc_api::execution_event_filter::Filter::CallerAddress(addr) => { + nested_filter.caller_address = Some(Address::from_str(&addr)?); + }, + grpc_api::execution_event_filter::Filter::EmitterAddress(addr) => { + nested_filter.emitter_address = Some(Address::from_str(&addr)?); + }, + grpc_api::execution_event_filter::Filter::OriginalOperationId(op) => { + nested_filter.original_operation_id = Some(OperationId::from_str(&op)?); + }, + grpc_api::execution_event_filter::Filter::IsFailure(is_failure) => { + nested_filter.is_failure = Some(is_failure); }, - _ => { - execution_event_filter = Some(ExecutionEventFilter { - none: None, - }) } - } - }}, + execution_event_filter = Some(nested_filter); + } + }, grpc_api::new_slot_execution_outputs_filter::Filter::ExecutedOpsChangesFilter(filter) => { if let Some(filter) = filter.filter { + let mut nested_filter = ExecutedOpsChangesFilter::default(); match filter { grpc_api::executed_ops_changes_filter::Filter::None(_) => { - executed_ops_changes_filter = Some(ExecutedOpsChangesFilter { - none: Some(()), - }); + nested_filter.none = Some(()); + }, + grpc_api::executed_ops_changes_filter::Filter::OperationId(op_id) => { + nested_filter.operation_id = Some(OperationId::from_str(&op_id)?); }, - _ => { - executed_ops_changes_filter = Some(ExecutedOpsChangesFilter { - none: None, - }) } - } - }}, + executed_ops_changes_filter = Some(nested_filter); + } + }, grpc_api::new_slot_execution_outputs_filter::Filter::LedgerChangesFilter(filter) => { if let Some(filter) = filter.filter { + let mut nested_filter = LedgerChangesFilter::default(); match filter { grpc_api::ledger_changes_filter::Filter::None(_) => { - ledger_changes_filter = Some(LedgerChangesFilter { - none: Some(()), - }); + nested_filter.none = Some(()); + }, + grpc_api::ledger_changes_filter::Filter::Address(addr) => { + nested_filter.address = Some(Address::from_str(&addr)?); }, - _ => { - ledger_changes_filter = Some(LedgerChangesFilter { - none: None, - }) } - } - }}, + ledger_changes_filter = Some(nested_filter); + } + }, } } } From 4115b5daf86b3b05dac9746dc39ae8bd281ae4b6 Mon Sep 17 00:00:00 2001 From: Moncef AOUDIA Date: Mon, 9 Oct 2023 18:56:33 +0200 Subject: [PATCH 02/13] feat: implement some filters logic --- massa-grpc/src/stream/new_slot_execution_outputs.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/massa-grpc/src/stream/new_slot_execution_outputs.rs b/massa-grpc/src/stream/new_slot_execution_outputs.rs index 0d4e6a59462..0e350fceb1c 100644 --- a/massa-grpc/src/stream/new_slot_execution_outputs.rs +++ b/massa-grpc/src/stream/new_slot_execution_outputs.rs @@ -444,7 +444,7 @@ fn filter_map_exec_output( exec_output.events.clear(); } } - + //TODO to be implemented if let Some(async_pool_changes_filter) = &filters.async_pool_changes_filter { if async_pool_changes_filter.none.is_some() { exec_output.state_changes.async_pool_changes.0.clear(); @@ -461,11 +461,22 @@ fn filter_map_exec_output( if let Some(executed_ops_changes_filter) = &filters.executed_ops_changes_filter { if executed_ops_changes_filter.none.is_some() { exec_output.state_changes.executed_ops_changes.clear(); + } else if let Some(op_id) = executed_ops_changes_filter.operation_id { + exec_output + .state_changes + .executed_ops_changes + .retain(|operation_id, _| operation_id == &op_id); } } if let Some(ledger_changes_filter) = &filters.ledger_changes_filter { if ledger_changes_filter.none.is_some() { exec_output.state_changes.ledger_changes.0.clear(); + } else if let Some(addr) = ledger_changes_filter.address { + exec_output + .state_changes + .ledger_changes + .0 + .retain(|address, _| address == &addr); } } From 58339c4fe0a44f8861bff1226db19eea82b4fd4f Mon Sep 17 00:00:00 2001 From: Moncef AOUDIA Date: Tue, 10 Oct 2023 15:46:03 +0200 Subject: [PATCH 03/13] fix: nested filters definitions --- .../src/stream/new_slot_execution_outputs.rs | 80 +++++++++---------- 1 file changed, 38 insertions(+), 42 deletions(-) diff --git a/massa-grpc/src/stream/new_slot_execution_outputs.rs b/massa-grpc/src/stream/new_slot_execution_outputs.rs index 0e350fceb1c..3f5ac87308d 100644 --- a/massa-grpc/src/stream/new_slot_execution_outputs.rs +++ b/massa-grpc/src/stream/new_slot_execution_outputs.rs @@ -52,14 +52,14 @@ struct Filter { struct AsyncPoolChangesFilter { // Do not return any message none: Option<()>, - // The type of the change - change_type: Option, - // The handler function name within the destination address bytecode - handler: Option, - // The address towards which the message is being sent - destination_address: Option
, - // The address that sent the message - emitter_address: Option
, + // The types of the change + change_types: Option>, + // The handlers functions names within the destination address bytecode + handlers: Option>, + // The addresses towards which the message is being sent + destination_addresses: Option>, + // The addresses that sent the message + emitter_addresses: Option>, // Boolean that determine if the message can be executed. For messages without filter this boolean is always true. // For messages with filter, this boolean is true if the filter has been matched between `validity_start` and current slot. can_be_executed: Option, @@ -75,12 +75,12 @@ struct ExecutedDenounciationFilter { struct ExecutionEventFilter { // Do not return any message none: Option<()>, - // Caller address - caller_address: Option
, - // Emitter address - emitter_address: Option
, - // Original operation id - original_operation_id: Option, + // Caller addresses + caller_addresses: Option>, + // Emitter addresses + emitter_addresses: Option>, + // Original operation ids + original_operation_ids: Option>, // Whether the event is a failure is_failure: Option, } @@ -89,16 +89,16 @@ struct ExecutionEventFilter { struct ExecutedOpsChangesFilter { // Do not return any message none: Option<()>, - // Operation id - operation_id: Option, + // Operation ids + operation_ids: Option>, } #[derive(Clone, Debug, Default)] struct LedgerChangesFilter { // Do not return any message none: Option<()>, - // Address for which we have ledger changes - address: Option
, + // Addresses for which we have ledger changes + addresses: Option>, } /// Creates a new stream of new produced and received slot execution outputs @@ -265,28 +265,27 @@ fn get_filter( }, grpc_api::new_slot_execution_outputs_filter::Filter::AsyncPoolChangesFilter(filter) => { if let Some(filter) = filter.filter { - let mut nested_filter = AsyncPoolChangesFilter::default(); + let nested_filter = async_pool_changes_filter.get_or_insert(AsyncPoolChangesFilter::default()); match filter { grpc_api::async_pool_changes_filter::Filter::None(_) => { nested_filter.none = Some(()); }, grpc_api::async_pool_changes_filter::Filter::Type(change_type) => { - nested_filter.change_type = Some(change_type); + nested_filter.change_types.get_or_insert_with(HashSet::new).insert(change_type); }, grpc_api::async_pool_changes_filter::Filter::Handler(function) => { - nested_filter.handler = Some(function); + nested_filter.handlers.get_or_insert_with(HashSet::new).insert(function); }, grpc_api::async_pool_changes_filter::Filter::DestinationAddress(addr) => { - nested_filter.destination_address = Some(Address::from_str(&addr)?); + nested_filter.destination_addresses.get_or_insert_with(HashSet::new).insert(Address::from_str(&addr)?); }, grpc_api::async_pool_changes_filter::Filter::EmitterAddress(addr) => { - nested_filter.emitter_address = Some(Address::from_str(&addr)?); + nested_filter.emitter_addresses.get_or_insert_with(HashSet::new).insert(Address::from_str(&addr)?); }, grpc_api::async_pool_changes_filter::Filter::CanBeExecuted(can_be_executed) => { nested_filter.can_be_executed = Some(can_be_executed); }, - } - async_pool_changes_filter = Some(nested_filter); + }; } }, grpc_api::new_slot_execution_outputs_filter::Filter::ExecutedDenounciationFilter(filter) => { @@ -302,53 +301,50 @@ fn get_filter( }, grpc_api::new_slot_execution_outputs_filter::Filter::EventFilter(filter) => { if let Some(filter) = filter.filter { - let mut nested_filter = ExecutionEventFilter::default(); + let nested_filter = execution_event_filter.get_or_insert(ExecutionEventFilter::default()); match filter { grpc_api::execution_event_filter::Filter::None(_) => { nested_filter.none = Some(()); }, grpc_api::execution_event_filter::Filter::CallerAddress(addr) => { - nested_filter.caller_address = Some(Address::from_str(&addr)?); + nested_filter.caller_addresses.get_or_insert_with(HashSet::new).insert(Address::from_str(&addr)?); }, grpc_api::execution_event_filter::Filter::EmitterAddress(addr) => { - nested_filter.emitter_address = Some(Address::from_str(&addr)?); + nested_filter.emitter_addresses.get_or_insert_with(HashSet::new).insert(Address::from_str(&addr)?); }, - grpc_api::execution_event_filter::Filter::OriginalOperationId(op) => { - nested_filter.original_operation_id = Some(OperationId::from_str(&op)?); + grpc_api::execution_event_filter::Filter::OriginalOperationId(op_id) => { + nested_filter.original_operation_ids.get_or_insert_with(HashSet::new).insert(OperationId::from_str(&op_id)?); }, grpc_api::execution_event_filter::Filter::IsFailure(is_failure) => { nested_filter.is_failure = Some(is_failure); }, - } - execution_event_filter = Some(nested_filter); + }; } }, grpc_api::new_slot_execution_outputs_filter::Filter::ExecutedOpsChangesFilter(filter) => { if let Some(filter) = filter.filter { - let mut nested_filter = ExecutedOpsChangesFilter::default(); + let nested_filter = executed_ops_changes_filter.get_or_insert(ExecutedOpsChangesFilter::default()); match filter { grpc_api::executed_ops_changes_filter::Filter::None(_) => { nested_filter.none = Some(()); }, grpc_api::executed_ops_changes_filter::Filter::OperationId(op_id) => { - nested_filter.operation_id = Some(OperationId::from_str(&op_id)?); + nested_filter.operation_ids.get_or_insert_with(HashSet::new).insert(OperationId::from_str(&op_id)?); }, } - executed_ops_changes_filter = Some(nested_filter); } }, grpc_api::new_slot_execution_outputs_filter::Filter::LedgerChangesFilter(filter) => { if let Some(filter) = filter.filter { - let mut nested_filter = LedgerChangesFilter::default(); + let nested_filter = ledger_changes_filter.get_or_insert(LedgerChangesFilter::default()); match filter { grpc_api::ledger_changes_filter::Filter::None(_) => { nested_filter.none = Some(()); }, grpc_api::ledger_changes_filter::Filter::Address(addr) => { - nested_filter.address = Some(Address::from_str(&addr)?); + nested_filter.addresses.get_or_insert_with(HashSet::new).insert(Address::from_str(&addr)?); }, } - ledger_changes_filter = Some(nested_filter); } }, } @@ -461,22 +457,22 @@ fn filter_map_exec_output( if let Some(executed_ops_changes_filter) = &filters.executed_ops_changes_filter { if executed_ops_changes_filter.none.is_some() { exec_output.state_changes.executed_ops_changes.clear(); - } else if let Some(op_id) = executed_ops_changes_filter.operation_id { + } else if let Some(operation_ids) = executed_ops_changes_filter.operation_ids.clone() { exec_output .state_changes .executed_ops_changes - .retain(|operation_id, _| operation_id == &op_id); + .retain(|operation_id, _| operation_ids.contains(operation_id)); } } if let Some(ledger_changes_filter) = &filters.ledger_changes_filter { if ledger_changes_filter.none.is_some() { exec_output.state_changes.ledger_changes.0.clear(); - } else if let Some(addr) = ledger_changes_filter.address { + } else if let Some(addresses) = ledger_changes_filter.addresses.clone() { exec_output .state_changes .ledger_changes .0 - .retain(|address, _| address == &addr); + .retain(|address, _| addresses.contains(address)); } } From dae5f9abe332bcab2f5f7171033938d96a7117f3 Mon Sep 17 00:00:00 2001 From: Moncef AOUDIA Date: Tue, 10 Oct 2023 17:33:51 +0200 Subject: [PATCH 04/13] feat: add execution_event_filter --- .../src/stream/new_slot_execution_outputs.rs | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/massa-grpc/src/stream/new_slot_execution_outputs.rs b/massa-grpc/src/stream/new_slot_execution_outputs.rs index 3f5ac87308d..7c49f6b2f46 100644 --- a/massa-grpc/src/stream/new_slot_execution_outputs.rs +++ b/massa-grpc/src/stream/new_slot_execution_outputs.rs @@ -438,6 +438,47 @@ fn filter_map_exec_output( if let Some(execution_event_filter) = &filters.execution_event_filter { if execution_event_filter.none.is_some() { exec_output.events.clear(); + } else { + exec_output.events.0.retain(|event| { + if let Some(is_failure) = execution_event_filter.is_failure { + if event.context.is_error != is_failure { + return false; + } + } + + if let (Some(original_operation_ids), Some(origin_operation_id)) = ( + execution_event_filter.original_operation_ids.clone(), + event.context.origin_operation_id, + ) { + if !original_operation_ids.contains(&origin_operation_id) { + return false; + } + } + + if let Some(caller_addresses) = execution_event_filter.caller_addresses.clone() { + if !caller_addresses + .into_iter() + .any(|caller_address| event.context.call_stack.contains(&caller_address)) + { + return false; + }; + } + //TODO to be confirmed + if let Some(emitter_addresses) = execution_event_filter.emitter_addresses.clone() { + if !emitter_addresses + .into_iter() + .any(|emitter_address| event.context.call_stack.contains(&emitter_address)) + { + return false; + }; + } + + true + }); + + if exec_output.events.0.is_empty() { + return None; + } } } //TODO to be implemented @@ -446,6 +487,7 @@ fn filter_map_exec_output( exec_output.state_changes.async_pool_changes.0.clear(); } } + if let Some(executed_denounciation_filter) = &filters.executed_denounciation_filter { if executed_denounciation_filter.none.is_some() { exec_output @@ -462,6 +504,10 @@ fn filter_map_exec_output( .state_changes .executed_ops_changes .retain(|operation_id, _| operation_ids.contains(operation_id)); + + if exec_output.state_changes.executed_ops_changes.is_empty() { + return None; + } } } if let Some(ledger_changes_filter) = &filters.ledger_changes_filter { @@ -473,6 +519,10 @@ fn filter_map_exec_output( .ledger_changes .0 .retain(|address, _| addresses.contains(address)); + + if exec_output.state_changes.ledger_changes.0.is_empty() { + return None; + } } } From 0ee1d8f49ee8fd8f44dbf3e043d1c27895b3be75 Mon Sep 17 00:00:00 2001 From: Moncef AOUDIA Date: Tue, 10 Oct 2023 19:03:29 +0200 Subject: [PATCH 05/13] feat: add AsyncPoolChanges filters --- Cargo.lock | 1 + massa-grpc/Cargo.toml | 61 +++++---- .../src/stream/new_slot_execution_outputs.rs | 117 +++++++++++++++++- massa-grpc/src/tests/stream.rs | 4 +- 4 files changed, 153 insertions(+), 30 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7395b2738d9..a3feffdc47f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2971,6 +2971,7 @@ dependencies = [ "massa_execution_exports", "massa_final_state", "massa_hash", + "massa_ledger_exports", "massa_models", "massa_pool_exports", "massa_pos_exports", diff --git a/massa-grpc/Cargo.toml b/massa-grpc/Cargo.toml index 102b448186f..838a2a92936 100644 --- a/massa-grpc/Cargo.toml +++ b/massa-grpc/Cargo.toml @@ -11,44 +11,51 @@ documentation = "https://docs.massa.net/" testing = [] [dependencies] -massa-proto-rs = { workspace = true, "features" = ["tonic"] } -displaydoc = { workspace = true } -thiserror = { workspace = true } -tonic = { workspace = true, "features" = ["gzip", "tls"] } -tonic-web = { workspace = true } -tonic-reflection = { workspace = true } -tonic-health = { workspace = true } -tower-http = { workspace = true, "features" = ["cors"] } -hyper = { workspace = true } -futures-util = { workspace = true } -serde = { workspace = true, "features" = ["derive"] } -tokio = { workspace = true, "features" = ["rt-multi-thread", "macros"] } -tokio-stream = { workspace = true } # BOM UPGRADE Revert to "0.1.12" if problem -tracing = { workspace = true } -parking_lot = { workspace = true, "features" = ["deadlock_detection"] } -h2 = { workspace = true } -itertools = { workspace = true } -# test - +# Internal packages +massa_bootstrap = { workspace = true } massa_consensus_exports = { workspace = true } +massa_execution_exports = { workspace = true } massa_hash = { workspace = true } +massa_ledger_exports = { workspace = true } massa_models = { workspace = true } -massa_pos_exports = { workspace = true } massa_pool_exports = { workspace = true } +massa_pos_exports = { workspace = true } massa_protocol_exports = { workspace = true } -massa_execution_exports = { workspace = true } +massa_sdk = { workspace = true } +massa_serialization = { workspace = true } +massa_signature = { workspace = true } massa_storage = { workspace = true } massa_time = { workspace = true } -massa_wallet = { workspace = true } -massa_serialization = { workspace = true } massa_versioning = { workspace = true } -massa_signature = { workspace = true } -massa_bootstrap = { workspace = true } -massa_sdk = { workspace = true } +massa_wallet = { workspace = true } + +# Massa projects dependencies +massa-proto-rs = { workspace = true, "features" = ["tonic"] } + +# Common dependencies +displaydoc = { workspace = true } +futures-util = { workspace = true } +h2 = { workspace = true } +hyper = { workspace = true } +itertools = { workspace = true } + +parking_lot = { workspace = true, "features" = ["deadlock_detection"] } +serde = { workspace = true, "features" = ["derive"] } +thiserror = { workspace = true } +tokio = { workspace = true, "features" = ["rt-multi-thread", "macros"] } +tokio-stream = { workspace = true } # BOM UPGRADE Revert to "0.1.12" if problem +tonic = { workspace = true, "features" = ["gzip", "tls"] } +tonic-health = { workspace = true } +tonic-reflection = { workspace = true } +tonic-web = { workspace = true } +tower-http = { workspace = true, "features" = ["cors"] } +tracing = { workspace = true } [dev-dependencies] +massa_channel = { workspace = true } massa_consensus_exports = { workspace = true, "features" = ["testing"] } -massa_protocol_exports = { workspace = true, "features" = ["testing"] } massa_final_state = { workspace = true } +mockall = { workspace = true } +num = { workspace = true } tokio = { workspace = true, "features" = ["test-util", "time"] } num = {workspace = true} diff --git a/massa-grpc/src/stream/new_slot_execution_outputs.rs b/massa-grpc/src/stream/new_slot_execution_outputs.rs index 7c49f6b2f46..afebf3ba5bb 100644 --- a/massa-grpc/src/stream/new_slot_execution_outputs.rs +++ b/massa-grpc/src/stream/new_slot_execution_outputs.rs @@ -6,6 +6,7 @@ use crate::server::MassaPublicGrpc; use crate::SlotRange; use futures_util::StreamExt; use massa_execution_exports::{ExecutionOutput, SlotExecutionOutput}; +use massa_ledger_exports::SetUpdateOrDelete; use massa_models::address::Address; use massa_models::operation::OperationId; use massa_models::slot::Slot; @@ -481,10 +482,124 @@ fn filter_map_exec_output( } } } - //TODO to be implemented + if let Some(async_pool_changes_filter) = &filters.async_pool_changes_filter { if async_pool_changes_filter.none.is_some() { exec_output.state_changes.async_pool_changes.0.clear(); + } else { + exec_output + .state_changes + .async_pool_changes + .0 + .retain(|_, change| { + match change { + SetUpdateOrDelete::Set(value) => { + if let Some(change_types) = &async_pool_changes_filter.change_types { + if !change_types + .contains(&(grpc_model::AsyncPoolChangeType::Set as i32)) + { + return false; + } + } + //TODO to be confirmed + if let Some(handlers) = &async_pool_changes_filter.handlers { + if !handlers.contains(&value.function) { + return false; + } + } + if let Some(destination_addresses) = + &async_pool_changes_filter.destination_addresses + { + if !destination_addresses.contains(&value.destination) { + return false; + } + } + + if let Some(emitter_addresses) = + &async_pool_changes_filter.emitter_addresses + { + if !emitter_addresses.contains(&value.sender) { + return false; + } + } + + if let Some(can_be_executed) = async_pool_changes_filter.can_be_executed + { + if value.can_be_executed != can_be_executed { + return false; + } + } + } + SetUpdateOrDelete::Update(value) => { + if let Some(change_types) = &async_pool_changes_filter.change_types { + if !change_types + .contains(&(grpc_model::AsyncPoolChangeType::Set as i32)) + { + return false; + } + } + //TODO to be confirmed + if let Some(handlers) = &async_pool_changes_filter.handlers { + match value.function.clone() { + massa_ledger_exports::SetOrKeep::Set(function_name) => { + if !handlers.contains(&function_name) { + return false; + } + } + //TODO to be confirmed + massa_ledger_exports::SetOrKeep::Keep => { + return false; + } + } + } + + if let Some(destination_addresses) = + &async_pool_changes_filter.destination_addresses + { + match value.destination { + massa_ledger_exports::SetOrKeep::Set(addr) => { + if !destination_addresses.contains(&addr) { + return false; + } + } + massa_ledger_exports::SetOrKeep::Keep => {} + } + } + + if let Some(emitter_addresses) = + &async_pool_changes_filter.emitter_addresses + { + match value.sender { + massa_ledger_exports::SetOrKeep::Set(addr) => { + if !emitter_addresses.contains(&addr) { + return false; + } + } + massa_ledger_exports::SetOrKeep::Keep => {} + } + } + + if let Some(can_be_executed) = async_pool_changes_filter.can_be_executed + { + match value.can_be_executed { + massa_ledger_exports::SetOrKeep::Set(can_be_ex) => { + if can_be_executed != can_be_ex { + return false; + } + } + massa_ledger_exports::SetOrKeep::Keep => {} + } + } + } + SetUpdateOrDelete::Delete => {} + } + + true + }); + + if exec_output.state_changes.async_pool_changes.0.is_empty() { + return None; + } } } diff --git a/massa-grpc/src/tests/stream.rs b/massa-grpc/src/tests/stream.rs index 00cfe6ea4b5..a3fb48b88eb 100644 --- a/massa-grpc/src/tests/stream.rs +++ b/massa-grpc/src/tests/stream.rs @@ -1190,7 +1190,7 @@ async fn new_slot_execution_outputs() { // TODO add test when filter is updated - /* filter = massa_proto_rs::massa::api::v1::NewSlotExecutionOutputsFilter { + filter = massa_proto_rs::massa::api::v1::NewSlotExecutionOutputsFilter { filter: Some( massa_proto_rs::massa::api::v1::new_slot_execution_outputs_filter::Filter::EventFilter( massa_proto_rs::massa::api::v1::ExecutionEventFilter { @@ -1218,7 +1218,7 @@ async fn new_slot_execution_outputs() { let result = tokio::time::timeout(Duration::from_secs(2), resp_stream.next()).await; dbg!(&result); - assert!(result.is_err()); */ + assert!(result.is_err()); stop_handle.stop(); } From 66196007e2d1af4e95e460a229392c5e0f6de752 Mon Sep 17 00:00:00 2001 From: Moncef AOUDIA Date: Fri, 13 Oct 2023 00:12:20 +0200 Subject: [PATCH 06/13] refactor: start generating test data --- Cargo.lock | 2 ++ massa-grpc/Cargo.toml | 3 ++ massa-grpc/src/tests/stream.rs | 61 ++++++++++++++++++++++++++++++---- 3 files changed, 60 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a3feffdc47f..e66f7c4c4b8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2966,8 +2966,10 @@ dependencies = [ "hyper", "itertools 0.11.0", "massa-proto-rs", + "massa_async_pool", "massa_bootstrap", "massa_consensus_exports", + "massa_executed_ops", "massa_execution_exports", "massa_final_state", "massa_hash", diff --git a/massa-grpc/Cargo.toml b/massa-grpc/Cargo.toml index 838a2a92936..69942bfd60f 100644 --- a/massa-grpc/Cargo.toml +++ b/massa-grpc/Cargo.toml @@ -52,8 +52,11 @@ tower-http = { workspace = true, "features" = ["cors"] } tracing = { workspace = true } [dev-dependencies] +massa_async_pool = { workspace = true } +massa_bootstrap = { workspace = true , "features" = ["testing"]} massa_channel = { workspace = true } massa_consensus_exports = { workspace = true, "features" = ["testing"] } +massa_executed_ops = { workspace = true } massa_final_state = { workspace = true } mockall = { workspace = true } num = { workspace = true } diff --git a/massa-grpc/src/tests/stream.rs b/massa-grpc/src/tests/stream.rs index a3fb48b88eb..0b52820ac9a 100644 --- a/massa-grpc/src/tests/stream.rs +++ b/massa-grpc/src/tests/stream.rs @@ -1,11 +1,21 @@ // Copyright (c) 2023 MASSA LABS -use crate::tests::mock::grpc_public_service; -use massa_consensus_exports::MockConsensusController; -use massa_execution_exports::{ExecutionOutput, MockExecutionController, SlotExecutionOutput}; +use crate::tests::mock::{grpc_public_service, MockExecutionCtrl, MockPoolCtrl}; +use massa_async_pool::{AsyncMessage, AsyncPoolChanges}; +use massa_consensus_exports::test_exports::MockConsensusControllerImpl; +use massa_executed_ops::ExecutedDenunciationsChanges; +use massa_execution_exports::{ExecutionOutput, SlotExecutionOutput}; +use massa_final_state::StateChanges; +use massa_ledger_exports::SetUpdateOrDelete; use massa_models::{ - address::Address, block::FilledBlock, secure_share::SecureShareSerializer, slot::Slot, + address::Address, + amount::Amount, + block::FilledBlock, + denunciation::{Denunciation, DenunciationIndex}, + secure_share::SecureShareSerializer, + slot::Slot, stats::ExecutionStats, + test_exports::{gen_block_headers_for_denunciation, gen_endorsements_for_denunciation}, }; use massa_pool_exports::MockPoolController; use massa_proto_rs::massa::{ @@ -26,7 +36,7 @@ use massa_protocol_exports::{ use massa_serialization::Serializer; use massa_signature::KeyPair; use massa_time::MassaTime; -use std::{net::SocketAddr, ops::Add, time::Duration}; +use std::{collections::HashSet, net::SocketAddr, ops::Add, str::FromStr, time::Duration}; use tokio_stream::StreamExt; #[tokio::test] @@ -1062,10 +1072,49 @@ async fn new_slot_execution_outputs() { let stop_handle = public_server.serve(&config).await.unwrap(); + // Given + let mut state_changes = StateChanges::default(); + + // Create async pool changes + let message = AsyncMessage::new( + Slot::new(1, 0), + 0, + Address::from_str("AU12dG5xP1RDEB5ocdHkymNVvvSJmUL9BgHwCksDowqmGWxfpm93x").unwrap(), + Address::from_str("AU12htxRWiEm8jDJpJptr6cwEhWNcCSFWstN1MLSa96DDkVM9Y42G").unwrap(), + String::from("test"), + 10000000, + Amount::from_str("1").unwrap(), + Amount::from_str("1").unwrap(), + Slot::new(2, 0), + Slot::new(3, 0), + vec![1, 2, 3, 4], + None, + None, + ); + let mut async_pool_changes = AsyncPoolChanges::default(); + async_pool_changes + .0 + .insert(message.compute_id(), SetUpdateOrDelete::Set(message)); + state_changes.async_pool_changes = async_pool_changes; + + // Create executed denunciations changes + let (_, _, s_block_header_1, s_block_header_2, _) = + gen_block_headers_for_denunciation(None, None); + let denunciation_1: Denunciation = (&s_block_header_1, &s_block_header_2).try_into().unwrap(); + let denunciation_index_1 = DenunciationIndex::from(&denunciation_1); + + let (_, _, s_endorsement_1, s_endorsement_2, _) = gen_endorsements_for_denunciation(None, None); + let denunciation_2 = Denunciation::try_from((&s_endorsement_1, &s_endorsement_2)).unwrap(); + let denunciation_index_2 = DenunciationIndex::from(&denunciation_2); + + let p_de_changes: ExecutedDenunciationsChanges = + HashSet::from([(denunciation_index_1), (denunciation_index_2)]); + state_changes.executed_denunciations_changes = p_de_changes; + let exec_output_1 = ExecutionOutput { slot: Slot::new(1, 5), block_info: None, - state_changes: massa_final_state::StateChanges::default(), + state_changes, events: Default::default(), }; From 75583fe5bbad8e8ee876fc7fa49ecafb756d5c7d Mon Sep 17 00:00:00 2001 From: Moncef AOUDIA Date: Mon, 16 Oct 2023 18:04:24 +0200 Subject: [PATCH 07/13] refactor: bootstrap test tools --- Cargo.lock | 119 +++++++++--------- massa-bootstrap/Cargo.toml | 11 +- massa-bootstrap/src/lib.rs | 4 + massa-bootstrap/src/test_exports/mod.rs | 5 + .../src/{tests => test_exports}/tools.rs | 15 ++- massa-bootstrap/src/tests/binders.rs | 2 +- massa-bootstrap/src/tests/mod.rs | 1 - massa-bootstrap/src/tests/scenarios.rs | 18 ++- massa-grpc/Cargo.toml | 7 +- massa-grpc/src/tests/stream.rs | 59 +++------ 10 files changed, 118 insertions(+), 123 deletions(-) create mode 100644 massa-bootstrap/src/test_exports/mod.rs rename massa-bootstrap/src/{tests => test_exports}/tools.rs (97%) diff --git a/Cargo.lock b/Cargo.lock index e66f7c4c4b8..5942550c226 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -258,9 +258,9 @@ dependencies = [ [[package]] name = "async-trait" -version = "0.1.73" +version = "0.1.74" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc00ceb34980c03614e35a3a4e218276a0a824e911d07651cd0d858a51e8c0f0" +checksum = "a66537f1bb974b254c98ed142ff995236e81b9d0fe4db0575f46612cb15eb0f9" dependencies = [ "proc-macro2 1.0.69", "quote 1.0.33", @@ -389,9 +389,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.4.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635" +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" [[package]] name = "bitvec" @@ -1129,10 +1129,11 @@ dependencies = [ [[package]] name = "deranged" -version = "0.3.8" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2696e8a945f658fd14dc3b87242e6b80cd0f36ff04ea560fa39082368847946" +checksum = "0f32d04922c60427da6f9fef14d042d9edddef64cb9d4ce0d64d0685fbeb1fd3" dependencies = [ + "powerfmt", "serde", ] @@ -1257,9 +1258,9 @@ dependencies = [ [[package]] name = "ed25519" -version = "2.2.2" +version = "2.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60f6d271ca33075c88028be6f04d502853d63a5ece419d269c15315d4fc1cf1d" +checksum = "115531babc129696a58c64a4fef0a8bf9e9698629fb97e9e40767d235cfbcd53" dependencies = [ "pkcs8", "signature", @@ -2088,9 +2089,9 @@ dependencies = [ [[package]] name = "jsonrpsee" -version = "0.20.1" +version = "0.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ad9b31183a8bcbe843e32ca8554ad2936633548d95a7bb6a8e14c767dea6b05" +checksum = "de902baa44bf34a58b1a4906f8b840d7d60dcec5f41fe08b4dbc14cf9efa821c" dependencies = [ "jsonrpsee-client-transport", "jsonrpsee-core", @@ -2106,9 +2107,9 @@ dependencies = [ [[package]] name = "jsonrpsee-client-transport" -version = "0.20.1" +version = "0.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97f2743cad51cc86b0dbfe316309eeb87a9d96a3d7f4dd7a99767c4b5f065335" +checksum = "58d9851f8f5653e0433a898e9032bde4910b35d625bd9dcf33ef6e36e7c3d456" dependencies = [ "futures-channel", "futures-util", @@ -2129,9 +2130,9 @@ dependencies = [ [[package]] name = "jsonrpsee-core" -version = "0.20.1" +version = "0.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35dc957af59ce98373bcdde0c1698060ca6c2d2e9ae357b459c7158b6df33330" +checksum = "51f45d37af23707750136379f6799e76ebfcf2d425ec4e36d0deb7921da5e65c" dependencies = [ "anyhow", "async-lock", @@ -2155,9 +2156,9 @@ dependencies = [ [[package]] name = "jsonrpsee-http-client" -version = "0.20.1" +version = "0.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dd865d0072764cb937b0110a92b5f53e995f7101cb346beca03d93a2dea79de" +checksum = "02308562f2e8162a32f8d6c3dc19c29c858d5d478047c886a5c3c25b5f7fa868" dependencies = [ "async-trait", "hyper", @@ -2175,9 +2176,9 @@ dependencies = [ [[package]] name = "jsonrpsee-proc-macros" -version = "0.20.1" +version = "0.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cef91b1017a4edb63f65239381c18de39f88d0e0760ab626d806e196f7f51477" +checksum = "f26b3675a943d083d0bf6e367ec755dccec56c41888afa13b191c1c4ff87c652" dependencies = [ "heck", "proc-macro-crate", @@ -2188,9 +2189,9 @@ dependencies = [ [[package]] name = "jsonrpsee-server" -version = "0.20.1" +version = "0.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24f4e2f3d223d810e363fb8b5616ec4c6254243ee7f452d05ac281cdc9cf76b2" +checksum = "2ed2bec9c76cee118c27138cc1c877938bcaa01207a5d902b80dbfc60466bc9c" dependencies = [ "futures-util", "http", @@ -2211,9 +2212,9 @@ dependencies = [ [[package]] name = "jsonrpsee-types" -version = "0.20.1" +version = "0.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa9e25aec855b2a7d3ed90fded6c41e8c3fb72b63f071e1be3f0004eba19b625" +checksum = "05eaff23af19f10ba6fbb76519bed6da4d3b9bbaef13d39b7c2b6c14e532d27e" dependencies = [ "anyhow", "beef", @@ -2225,9 +2226,9 @@ dependencies = [ [[package]] name = "jsonrpsee-wasm-client" -version = "0.20.1" +version = "0.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "010306151579898dc1000bab239ef7a73a73f04cb8ef267ee28b9a000267e813" +checksum = "d7ae1c71afe02a21713e197438f1bcfaa171c3dfe533b9505a0990cb8297779e" dependencies = [ "jsonrpsee-client-transport", "jsonrpsee-core", @@ -2236,9 +2237,9 @@ dependencies = [ [[package]] name = "jsonrpsee-ws-client" -version = "0.20.1" +version = "0.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d88e35e9dfa89248ae3e92f689c1f0a190ce12d377eba7d2d08e5a7f6cc5694a" +checksum = "cd34d3ab8c09f02fd4c432f256bc8b143b616b222b03050f941ee53f0e8d7b24" dependencies = [ "http", "jsonrpsee-client-transport", @@ -2966,10 +2967,8 @@ dependencies = [ "hyper", "itertools 0.11.0", "massa-proto-rs", - "massa_async_pool", "massa_bootstrap", "massa_consensus_exports", - "massa_executed_ops", "massa_execution_exports", "massa_final_state", "massa_hash", @@ -3529,7 +3528,7 @@ version = "0.27.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2eb04e9c688eff1c89d72b407f168cf79bb9e867a9d3323ed6c01519eb9cc053" dependencies = [ - "bitflags 2.4.0", + "bitflags 2.4.1", "cfg-if", "libc", ] @@ -4029,6 +4028,12 @@ dependencies = [ "universal-hash", ] +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + [[package]] name = "ppv-lite86" version = "0.2.17" @@ -4413,9 +4418,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.10.0" +version = "1.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d119d7c7ca818f8a53c300863d4f87566aac09943aef5b355bb83969dae75d87" +checksum = "aaac441002f822bc9705a681810a4dd2963094b9ca0ddc41cb963a4c189189ea" dependencies = [ "aho-corasick", "memchr", @@ -4425,9 +4430,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.1" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "465c6fc0621e4abc4187a2bda0937bfd4f722c2730b29562e19689ea796c9a4b" +checksum = "5011c7e263a695dc8ca064cddb722af1be54e517a280b12a5356f98366899e5d" dependencies = [ "aho-corasick", "memchr", @@ -4436,9 +4441,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.8.1" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56d84fdd47036b038fc80dd333d10b6aab10d5d31f4a366e20014def75328d33" +checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" [[package]] name = "region" @@ -4602,7 +4607,7 @@ version = "0.38.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "745ecfa778e66b2b63c88a61cb36e0eea109e803b0b86bf9879fbc77c70e86ed" dependencies = [ - "bitflags 2.4.0", + "bitflags 2.4.1", "errno", "libc", "linux-raw-sys 0.4.10", @@ -4674,7 +4679,7 @@ version = "12.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "994eca4bca05c87e86e15d90fc7a91d1be64b4482b38cb2d27474568fe7c9db9" dependencies = [ - "bitflags 2.4.0", + "bitflags 2.4.1", "cfg-if", "clipboard-win", "fd-lock", @@ -5127,9 +5132,9 @@ dependencies = [ [[package]] name = "strum_macros" -version = "0.25.2" +version = "0.25.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad8d03b598d3d0fff69bf533ee3ef19b8eeb342729596df84bcc7e1f96ec4059" +checksum = "23dc1fa9ac9c169a78ba62f0b841814b7abae11bdd047b9c58f893439e309ea0" dependencies = [ "heck", "proc-macro2 1.0.69", @@ -5278,12 +5283,13 @@ dependencies = [ [[package]] name = "time" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "426f806f4089c493dcac0d24c29c01e2c38baf8e30f1b716ee37e83d200b18fe" +checksum = "c4a34ab300f2dee6e562c10a046fc05e358b29f9bf92277f30c3c8d82275f6f5" dependencies = [ "deranged", "itoa", + "powerfmt", "serde", "time-core", "time-macros", @@ -5560,7 +5566,7 @@ version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "61c5bb1d698276a2443e5ecfabc1008bf15a36c12e6a7176e7bf089ea9131140" dependencies = [ - "bitflags 2.4.0", + "bitflags 2.4.1", "bytes", "futures-core", "futures-util", @@ -5586,11 +5592,10 @@ checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" [[package]] name = "tracing" -version = "0.1.37" +version = "0.1.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" +checksum = "ee2ef2af84856a50c1d430afce2fdded0a4ec7eda868db86409b4543df0797f9" dependencies = [ - "cfg-if", "log", "pin-project-lite", "tracing-attributes", @@ -5599,9 +5604,9 @@ dependencies = [ [[package]] name = "tracing-attributes" -version = "0.1.26" +version = "0.1.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f4f31f56159e98206da9efd823404b79b6ef3143b4a7ab76e67b1751b25a4ab" +checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2 1.0.69", "quote 1.0.33", @@ -5610,9 +5615,9 @@ dependencies = [ [[package]] name = "tracing-core" -version = "0.1.31" +version = "0.1.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0955b8137a1df6f1a2e9a37d8a6656291ff0297c1a97c24e0d8425fe2312f79a" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" dependencies = [ "once_cell", "valuable", @@ -5932,9 +5937,9 @@ checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1" [[package]] name = "wasm-encoder" -version = "0.34.1" +version = "0.35.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f14a94e06a3e2ed1af4e80cac712fed883142019ebe33c3899fd1b5e8550df9d" +checksum = "9ca90ba1b5b0a70d3d49473c5579951f3bddc78d47b59256d2f9d4922b150aca" dependencies = [ "leb128", ] @@ -6124,9 +6129,9 @@ dependencies = [ [[package]] name = "wast" -version = "66.0.1" +version = "66.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49d1457e95d4b8e1f72bd50f5ed804931f94cf1b5449697255aef466e46fa4b0" +checksum = "93cb43b0ac6dd156f2c375735ccfd72b012a7c0a6e6d09503499b8d3cb6e6072" dependencies = [ "leb128", "memchr", @@ -6136,9 +6141,9 @@ dependencies = [ [[package]] name = "wat" -version = "1.0.76" +version = "1.0.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "964639e3c731f12b7bf6be78f0b2c3e646321acab18e7cb9f18e44c6720bb4fa" +checksum = "e367582095d2903caeeea9acbb140e1db9c7677001efa4347c3687fd34fe7072" dependencies = [ "wast", ] @@ -6397,9 +6402,9 @@ checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "winnow" -version = "0.5.16" +version = "0.5.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "037711d82167854aff2018dfd193aa0fef5370f456732f0d5a0c59b0f1b4b907" +checksum = "a3b801d0e0a6726477cc207f60162da452f3a95adb368399bef20a946e06f65c" dependencies = [ "memchr", ] diff --git a/massa-bootstrap/Cargo.toml b/massa-bootstrap/Cargo.toml index 078f4b7a7d3..99496357195 100644 --- a/massa-bootstrap/Cargo.toml +++ b/massa-bootstrap/Cargo.toml @@ -5,7 +5,9 @@ authors = ["Massa Labs "] edition = "2021" [features] -testing = ["massa_final_state/testing", "massa_ledger_worker/testing", "massa_consensus_exports/testing", "massa_async_pool/testing"] +testing = ["massa_final_state/testing", "massa_ledger_worker/testing", "massa_consensus_exports/testing", "massa_async_pool/testing", + "dep:bitvec", "dep:massa_async_pool", "dep:massa_executed_ops", "dep:massa_ledger_exports", "dep:massa_ledger_worker", "dep:num" ] + sandbox = ["massa_async_pool/sandbox", "massa_final_state/sandbox", "massa_models/sandbox"] [dependencies] @@ -39,6 +41,13 @@ massa_db_exports = {workspace = true} massa_versioning = {workspace = true} massa_metrics = {workspace = true} +bitvec = {workspace = true, "features" = ["serde"], optional = true} +massa_async_pool = {workspace = true, optional = true} +massa_executed_ops = {workspace = true, optional = true} +massa_ledger_exports = {workspace = true, optional = true} +massa_ledger_worker = {workspace = true, optional = true} +num = {workspace = true, optional = true} + [dev-dependencies] mockall = {workspace = true} bitvec = {workspace = true, "features" = ["serde"]} diff --git a/massa-bootstrap/src/lib.rs b/massa-bootstrap/src/lib.rs index b152e838cf3..56b5ca402c9 100644 --- a/massa-bootstrap/src/lib.rs +++ b/massa-bootstrap/src/lib.rs @@ -44,6 +44,10 @@ pub use settings::{BootstrapConfig, BootstrapServerMessageDeserializerArgs}; #[cfg(test)] pub(crate) mod tests; +#[cfg(any(test, feature = "testing"))] +/// Export the test toolkit +pub mod test_exports; + /// a collection of the bootstrap state snapshots of all relevant modules pub struct GlobalBootstrapState { /// state of the final state diff --git a/massa-bootstrap/src/test_exports/mod.rs b/massa-bootstrap/src/test_exports/mod.rs new file mode 100644 index 00000000000..63a5b5e4ee4 --- /dev/null +++ b/massa-bootstrap/src/test_exports/mod.rs @@ -0,0 +1,5 @@ +/// Toolkit for testing purposes +mod tools; + +/// Export the toolkit for testing purposes +pub use tools::*; diff --git a/massa-bootstrap/src/tests/tools.rs b/massa-bootstrap/src/test_exports/tools.rs similarity index 97% rename from massa-bootstrap/src/tests/tools.rs rename to massa-bootstrap/src/test_exports/tools.rs index 6269cc0b7fe..09cc0257eb9 100644 --- a/massa-bootstrap/src/tests/tools.rs +++ b/massa-bootstrap/src/test_exports/tools.rs @@ -1,4 +1,4 @@ -// Copyright (c) 2022 MASSA LABS +// Copyright (c) 2023 MASSA LABS use crate::settings::{BootstrapConfig, IpType}; use bitvec::vec::BitVec; @@ -67,7 +67,7 @@ use std::{ path::PathBuf, }; -// Use loop-back address. use port 0 to auto-assign a port +/// Use loop-back address. use port 0 to auto-assign a port pub const BASE_BOOTSTRAP_IP: IpAddr = IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)); /// generates a small random number of bytes @@ -97,6 +97,7 @@ fn get_random_ledger_entry() -> LedgerEntry { } } +/// generates random ledger changes pub fn get_random_ledger_changes(r_limit: u64) -> LedgerChanges { let mut changes = LedgerChanges::default(); for _ in 0..r_limit { @@ -201,6 +202,7 @@ pub fn get_random_pos_changes(r_limit: u64) -> PoSChanges { } } +/// generates a random async pool changes pub fn get_random_async_pool_changes(r_limit: u64, thread_count: u8) -> AsyncPoolChanges { let mut changes = AsyncPoolChanges::default(); for _ in 0..(r_limit / 2) { @@ -219,6 +221,7 @@ pub fn get_random_async_pool_changes(r_limit: u64, thread_count: u8) -> AsyncPoo changes } +/// generates a random execution executed ops pub fn get_random_executed_ops( _r_limit: u64, slot: Slot, @@ -232,6 +235,7 @@ pub fn get_random_executed_ops( executed_ops } +/// generates random executed ops changes pub fn get_random_executed_ops_changes(r_limit: u64) -> PreHashMap { let mut ops_changes = PreHashMap::default(); for i in 0..r_limit { @@ -249,6 +253,7 @@ pub fn get_random_executed_ops_changes(r_limit: u64) -> PreHashMap ExecutedDenunciationsChanges { let mut de_changes = HashSet::default(); @@ -371,15 +377,18 @@ pub fn get_random_final_state_bootstrap( final_state } +/// generates a dummy block id pub fn get_dummy_block_id(s: &str) -> BlockId { BlockId::generate_from_hash(Hash::compute_from(s.as_bytes())) } +/// generates a random address pub fn get_random_address() -> Address { let priv_key = KeyPair::generate(0).unwrap(); Address::from_public_key(&priv_key.get_public_key()) } +/// get bootstrap config pub fn get_bootstrap_config(bootstrap_public_key: NodeId) -> BootstrapConfig { BootstrapConfig { listen_addr: Some("0.0.0.0:31244".parse().unwrap()), @@ -459,6 +468,7 @@ pub fn assert_eq_bootstrap_graph(v1: &BootstrapableGraph, v2: &BootstrapableGrap assert_eq!(data1, data2, "BootstrapableGraph mismatch") } +/// get bootstrap state pub fn get_boot_state() -> BootstrapableGraph { let keypair = KeyPair::generate(0).unwrap(); @@ -543,6 +553,7 @@ pub fn get_boot_state() -> BootstrapableGraph { boot_graph } +/// get bootstrap peers pub fn get_peers(keypair: &KeyPair) -> BootstrapPeers { let mut listeners1 = HashMap::default(); listeners1.insert("82.245.123.77:8080".parse().unwrap(), TransportType::Tcp); diff --git a/massa-bootstrap/src/tests/binders.rs b/massa-bootstrap/src/tests/binders.rs index 9e6802d1998..6168c481bb6 100644 --- a/massa-bootstrap/src/tests/binders.rs +++ b/massa-bootstrap/src/tests/binders.rs @@ -2,7 +2,7 @@ use crate::messages::{BootstrapClientMessage, BootstrapServerMessage}; use crate::settings::{BootstrapClientConfig, BootstrapSrvBindCfg}; use crate::{ bindings::{BootstrapClientBinder, BootstrapServerBinder}, - tests::tools::get_bootstrap_config, + test_exports::get_bootstrap_config, BootstrapPeers, }; use crate::{BootstrapConfig, BootstrapError}; diff --git a/massa-bootstrap/src/tests/mod.rs b/massa-bootstrap/src/tests/mod.rs index 9f9e1914cae..1b133061932 100644 --- a/massa-bootstrap/src/tests/mod.rs +++ b/massa-bootstrap/src/tests/mod.rs @@ -2,4 +2,3 @@ mod binders; mod scenarios; -pub(crate) mod tools; diff --git a/massa-bootstrap/src/tests/scenarios.rs b/massa-bootstrap/src/tests/scenarios.rs index ceae4d18882..7e50239bc37 100644 --- a/massa-bootstrap/src/tests/scenarios.rs +++ b/massa-bootstrap/src/tests/scenarios.rs @@ -1,18 +1,14 @@ -// Copyright (c) 2022 MASSA LABS +// Copyright (c) 2023 MASSA LABS -use super::tools::{ - get_boot_state, get_peers, get_random_final_state_bootstrap, get_random_ledger_changes, -}; use crate::listener::PollEvent; -use crate::tests::tools::{ - assert_eq_bootstrap_graph, get_random_async_pool_changes, get_random_executed_de_changes, - get_random_executed_ops_changes, get_random_execution_trail_hash_change, - get_random_pos_changes, +use crate::test_exports::{ + assert_eq_bootstrap_graph, get_boot_state, get_bootstrap_config, get_peers, + get_random_async_pool_changes, get_random_executed_de_changes, get_random_executed_ops_changes, + get_random_execution_trail_hash_change, get_random_final_state_bootstrap, + get_random_ledger_changes, get_random_pos_changes, }; use crate::BootstrapError; -use crate::{ - client::MockBSConnector, get_state, start_bootstrap_server, tests::tools::get_bootstrap_config, -}; +use crate::{client::MockBSConnector, get_state, start_bootstrap_server}; use crate::{ listener::MockBootstrapTcpListener, BootstrapConfig, BootstrapManager, BootstrapTcpListener, }; diff --git a/massa-grpc/Cargo.toml b/massa-grpc/Cargo.toml index 69942bfd60f..92d0d78971d 100644 --- a/massa-grpc/Cargo.toml +++ b/massa-grpc/Cargo.toml @@ -8,7 +8,7 @@ homepage = "https://massa.net" documentation = "https://docs.massa.net/" [features] -testing = [] +testing = ["dep:mockall", "dep:num", "dep:massa_channel"] [dependencies] # Internal packages @@ -52,11 +52,8 @@ tower-http = { workspace = true, "features" = ["cors"] } tracing = { workspace = true } [dev-dependencies] -massa_async_pool = { workspace = true } -massa_bootstrap = { workspace = true , "features" = ["testing"]} -massa_channel = { workspace = true } +massa_bootstrap = { workspace = true, "features" = ["testing"] } massa_consensus_exports = { workspace = true, "features" = ["testing"] } -massa_executed_ops = { workspace = true } massa_final_state = { workspace = true } mockall = { workspace = true } num = { workspace = true } diff --git a/massa-grpc/src/tests/stream.rs b/massa-grpc/src/tests/stream.rs index 0b52820ac9a..1ea1bbe431e 100644 --- a/massa-grpc/src/tests/stream.rs +++ b/massa-grpc/src/tests/stream.rs @@ -1,21 +1,16 @@ // Copyright (c) 2023 MASSA LABS use crate::tests::mock::{grpc_public_service, MockExecutionCtrl, MockPoolCtrl}; -use massa_async_pool::{AsyncMessage, AsyncPoolChanges}; +use massa_bootstrap::test_exports::{ + get_random_async_pool_changes, get_random_executed_de_changes, get_random_executed_ops_changes, + get_random_execution_trail_hash_change, get_random_ledger_changes, +}; use massa_consensus_exports::test_exports::MockConsensusControllerImpl; -use massa_executed_ops::ExecutedDenunciationsChanges; use massa_execution_exports::{ExecutionOutput, SlotExecutionOutput}; use massa_final_state::StateChanges; -use massa_ledger_exports::SetUpdateOrDelete; use massa_models::{ - address::Address, - amount::Amount, - block::FilledBlock, - denunciation::{Denunciation, DenunciationIndex}, - secure_share::SecureShareSerializer, - slot::Slot, + address::Address, block::FilledBlock, secure_share::SecureShareSerializer, slot::Slot, stats::ExecutionStats, - test_exports::{gen_block_headers_for_denunciation, gen_endorsements_for_denunciation}, }; use massa_pool_exports::MockPoolController; use massa_proto_rs::massa::{ @@ -36,7 +31,7 @@ use massa_protocol_exports::{ use massa_serialization::Serializer; use massa_signature::KeyPair; use massa_time::MassaTime; -use std::{collections::HashSet, net::SocketAddr, ops::Add, str::FromStr, time::Duration}; +use std::{net::SocketAddr, ops::Add, time::Duration}; use tokio_stream::StreamExt; #[tokio::test] @@ -1074,42 +1069,16 @@ async fn new_slot_execution_outputs() { // Given let mut state_changes = StateChanges::default(); - // Create async pool changes - let message = AsyncMessage::new( - Slot::new(1, 0), - 0, - Address::from_str("AU12dG5xP1RDEB5ocdHkymNVvvSJmUL9BgHwCksDowqmGWxfpm93x").unwrap(), - Address::from_str("AU12htxRWiEm8jDJpJptr6cwEhWNcCSFWstN1MLSa96DDkVM9Y42G").unwrap(), - String::from("test"), - 10000000, - Amount::from_str("1").unwrap(), - Amount::from_str("1").unwrap(), - Slot::new(2, 0), - Slot::new(3, 0), - vec![1, 2, 3, 4], - None, - None, - ); - let mut async_pool_changes = AsyncPoolChanges::default(); - async_pool_changes - .0 - .insert(message.compute_id(), SetUpdateOrDelete::Set(message)); - state_changes.async_pool_changes = async_pool_changes; - + state_changes.async_pool_changes = get_random_async_pool_changes(10, config.thread_count); // Create executed denunciations changes - let (_, _, s_block_header_1, s_block_header_2, _) = - gen_block_headers_for_denunciation(None, None); - let denunciation_1: Denunciation = (&s_block_header_1, &s_block_header_2).try_into().unwrap(); - let denunciation_index_1 = DenunciationIndex::from(&denunciation_1); - - let (_, _, s_endorsement_1, s_endorsement_2, _) = gen_endorsements_for_denunciation(None, None); - let denunciation_2 = Denunciation::try_from((&s_endorsement_1, &s_endorsement_2)).unwrap(); - let denunciation_index_2 = DenunciationIndex::from(&denunciation_2); - - let p_de_changes: ExecutedDenunciationsChanges = - HashSet::from([(denunciation_index_1), (denunciation_index_2)]); - state_changes.executed_denunciations_changes = p_de_changes; + state_changes.executed_denunciations_changes = get_random_executed_de_changes(10); + // Create executed operations changes + state_changes.executed_ops_changes = get_random_executed_ops_changes(10); + // Create ledger changes + state_changes.ledger_changes = get_random_ledger_changes(10); + // Create execution trail hash change + state_changes.execution_trail_hash_change = get_random_execution_trail_hash_change(true); let exec_output_1 = ExecutionOutput { slot: Slot::new(1, 5), From 9044d949b475f141fc25a10d676d519c8706770f Mon Sep 17 00:00:00 2001 From: Moncef AOUDIA Date: Tue, 17 Oct 2023 12:10:09 +0200 Subject: [PATCH 08/13] feat: add event store rand --- Cargo.lock | 15 ++++---- massa-execution-exports/Cargo.toml | 7 ++-- .../src/test_exports/mod.rs | 5 +++ .../src/test_exports/tools.rs | 34 +++++++++++++++++++ massa-grpc/src/tests/stream.rs | 14 ++++---- 5 files changed, 60 insertions(+), 15 deletions(-) create mode 100644 massa-execution-exports/src/test_exports/tools.rs diff --git a/Cargo.lock b/Cargo.lock index 5942550c226..422b1b8f2b3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2837,6 +2837,8 @@ dependencies = [ "massa_versioning", "mockall", "num", + "parking_lot", + "rand", "tempfile", "thiserror", "tokio", @@ -4418,9 +4420,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.10.1" +version = "1.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aaac441002f822bc9705a681810a4dd2963094b9ca0ddc41cb963a4c189189ea" +checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343" dependencies = [ "aho-corasick", "memchr", @@ -4430,9 +4432,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.2" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5011c7e263a695dc8ca064cddb722af1be54e517a280b12a5356f98366899e5d" +checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f" dependencies = [ "aho-corasick", "memchr", @@ -5262,12 +5264,11 @@ dependencies = [ [[package]] name = "thread-id" -version = "4.2.0" +version = "4.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79474f573561cdc4871a0de34a51c92f7f5a56039113fbb5b9c9f96bdb756669" +checksum = "f0ec81c46e9eb50deaa257be2f148adf052d1fb7701cfd55ccfab2525280b70b" dependencies = [ "libc", - "redox_syscall 0.2.16", "winapi", ] diff --git a/massa-execution-exports/Cargo.toml b/massa-execution-exports/Cargo.toml index 032cd49a35a..52de6a2ae1f 100644 --- a/massa-execution-exports/Cargo.toml +++ b/massa-execution-exports/Cargo.toml @@ -5,8 +5,8 @@ authors = ["Massa Labs "] edition = "2021" [features] -gas_calibration = ["tempfile"] -testing = ["massa_models/testing", "tempfile", "mockall"] +gas_calibration = ["massa_ledger_exports/testing", "parking_lot", "tempfile"] +testing = ["massa_models/testing", "massa_ledger_exports/testing", "parking_lot", "tempfile", "mockall", "rand"] [dependencies] displaydoc = {workspace = true} @@ -22,9 +22,12 @@ massa_time = {workspace = true} massa_storage = {workspace = true} massa_final_state = {workspace = true} massa_pos_exports = {workspace = true} +massa_ledger_exports = {workspace = true, optional = true} massa_module_cache = {workspace = true} massa_versioning = {workspace = true} massa-sc-runtime = {workspace = true} +rand = {workspace = true, optional = true} + [dev-dependencies] mockall = {workspace = true} diff --git a/massa-execution-exports/src/test_exports/mod.rs b/massa-execution-exports/src/test_exports/mod.rs index 0de87216b74..84c781a3c50 100644 --- a/massa-execution-exports/src/test_exports/mod.rs +++ b/massa-execution-exports/src/test_exports/mod.rs @@ -14,4 +14,9 @@ //! with an execution worker within tests. mod config; +mod mock; +mod tools; + pub use config::*; +pub use mock::*; +pub use tools::*; diff --git a/massa-execution-exports/src/test_exports/tools.rs b/massa-execution-exports/src/test_exports/tools.rs new file mode 100644 index 00000000000..1a28c28c25f --- /dev/null +++ b/massa-execution-exports/src/test_exports/tools.rs @@ -0,0 +1,34 @@ +// Copyright (c) 2023 MASSA LABS + +use crate::EventStore; +use massa_models::output_event::{EventExecutionContext, SCOutputEvent}; +use massa_models::slot::Slot; +use rand::Rng; + +use std::collections::VecDeque; + +/// generates a random eventstore +pub fn get_random_eventstore(limit: u64) -> EventStore { + let mut rng = rand::thread_rng(); + let mut store = EventStore(VecDeque::new()); + + for i in 0..limit { + let is_final: bool = rng.gen(); + let is_error = !is_final; + store.push(SCOutputEvent { + context: EventExecutionContext { + slot: Slot::new(i, 0), + block: None, + read_only: false, + index_in_slot: 1, + call_stack: VecDeque::new(), + origin_operation_id: None, + is_final, + is_error, + }, + data: i.to_string(), + }); + } + + store +} diff --git a/massa-grpc/src/tests/stream.rs b/massa-grpc/src/tests/stream.rs index 1ea1bbe431e..0808254ca46 100644 --- a/massa-grpc/src/tests/stream.rs +++ b/massa-grpc/src/tests/stream.rs @@ -6,7 +6,9 @@ use massa_bootstrap::test_exports::{ get_random_execution_trail_hash_change, get_random_ledger_changes, }; use massa_consensus_exports::test_exports::MockConsensusControllerImpl; -use massa_execution_exports::{ExecutionOutput, SlotExecutionOutput}; +use massa_execution_exports::{ + test_exports::get_random_eventstore, ExecutionOutput, SlotExecutionOutput, +}; use massa_final_state::StateChanges; use massa_models::{ address::Address, block::FilledBlock, secure_share::SecureShareSerializer, slot::Slot, @@ -1070,13 +1072,13 @@ async fn new_slot_execution_outputs() { // Given let mut state_changes = StateChanges::default(); // Create async pool changes - state_changes.async_pool_changes = get_random_async_pool_changes(10, config.thread_count); + state_changes.async_pool_changes = get_random_async_pool_changes(3, config.thread_count); // Create executed denunciations changes - state_changes.executed_denunciations_changes = get_random_executed_de_changes(10); + state_changes.executed_denunciations_changes = get_random_executed_de_changes(3); // Create executed operations changes - state_changes.executed_ops_changes = get_random_executed_ops_changes(10); + state_changes.executed_ops_changes = get_random_executed_ops_changes(3); // Create ledger changes - state_changes.ledger_changes = get_random_ledger_changes(10); + state_changes.ledger_changes = get_random_ledger_changes(3); // Create execution trail hash change state_changes.execution_trail_hash_change = get_random_execution_trail_hash_change(true); @@ -1084,7 +1086,7 @@ async fn new_slot_execution_outputs() { slot: Slot::new(1, 5), block_info: None, state_changes, - events: Default::default(), + events: get_random_eventstore(3), }; let (tx_request, rx) = tokio::sync::mpsc::channel(10); From 338c753586c20212c98042db95a7ade471d58847 Mon Sep 17 00:00:00 2001 From: Moncef AOUDIA Date: Tue, 17 Oct 2023 17:50:33 +0200 Subject: [PATCH 09/13] refactor: add some basic tests --- .../src/stream/new_slot_execution_outputs.rs | 18 +- massa-grpc/src/tests/stream.rs | 620 ++++++++++-------- 2 files changed, 350 insertions(+), 288 deletions(-) diff --git a/massa-grpc/src/stream/new_slot_execution_outputs.rs b/massa-grpc/src/stream/new_slot_execution_outputs.rs index afebf3ba5bb..802a94f5020 100644 --- a/massa-grpc/src/stream/new_slot_execution_outputs.rs +++ b/massa-grpc/src/stream/new_slot_execution_outputs.rs @@ -126,7 +126,10 @@ pub(crate) async fn new_slot_execution_outputs( error!("failed to get filter: {}", err); // Send the error response back to the client if let Err(e) = tx.send(Err(err.into())).await { - error!("failed to send back NewBlocks error response: {}", e); + error!( + "failed to send back NewSlotExecutionOutputs error response: {}", + e + ); } return; } @@ -447,11 +450,14 @@ fn filter_map_exec_output( } } - if let (Some(original_operation_ids), Some(origin_operation_id)) = ( - execution_event_filter.original_operation_ids.clone(), - event.context.origin_operation_id, - ) { - if !original_operation_ids.contains(&origin_operation_id) { + if let Some(original_operation_ids) = + execution_event_filter.original_operation_ids.clone() + { + if let Some(origin_operation_id) = event.context.origin_operation_id { + if !original_operation_ids.contains(&origin_operation_id) { + return false; + } + } else { return false; } } diff --git a/massa-grpc/src/tests/stream.rs b/massa-grpc/src/tests/stream.rs index 0808254ca46..459c6a5c86b 100644 --- a/massa-grpc/src/tests/stream.rs +++ b/massa-grpc/src/tests/stream.rs @@ -2,8 +2,9 @@ use crate::tests::mock::{grpc_public_service, MockExecutionCtrl, MockPoolCtrl}; use massa_bootstrap::test_exports::{ - get_random_async_pool_changes, get_random_executed_de_changes, get_random_executed_ops_changes, - get_random_execution_trail_hash_change, get_random_ledger_changes, + get_dummy_block_id, get_random_async_pool_changes, get_random_executed_de_changes, + get_random_executed_ops_changes, get_random_execution_trail_hash_change, + get_random_ledger_changes, }; use massa_consensus_exports::test_exports::MockConsensusControllerImpl; use massa_execution_exports::{ @@ -14,7 +15,8 @@ use massa_models::{ address::Address, block::FilledBlock, secure_share::SecureShareSerializer, slot::Slot, stats::ExecutionStats, }; -use massa_pool_exports::MockPoolController; +use massa_proto_rs::massa::api::v1::{self as grpc_api}; +use massa_proto_rs::massa::model::v1::{self as grpc_model}; use massa_proto_rs::massa::{ api::v1::{ public_service_client::PublicServiceClient, NewBlocksRequest, NewFilledBlocksRequest, @@ -23,6 +25,7 @@ use massa_proto_rs::massa::{ }, model::v1::{Addresses, Slot as ProtoSlot, SlotRange}, }; + use massa_protocol_exports::{ test_exports::tools::{ create_block, create_block_with_operations, create_endorsement, @@ -202,16 +205,14 @@ async fn new_operations() { .unwrap() .into_inner(); - let filter = massa_proto_rs::massa::api::v1::NewOperationsFilter { - filter: Some( - massa_proto_rs::massa::api::v1::new_operations_filter::Filter::OperationIds( - massa_proto_rs::massa::model::v1::OperationIds { - operation_ids: vec![ - "O1q4CBcuYo8YANEV34W4JRWVHrzcYns19VJfyAB7jT4qfitAnMC".to_string() - ], - }, - ), - ), + let filter = grpc_api::NewOperationsFilter { + filter: Some(grpc_api::new_operations_filter::Filter::OperationIds( + grpc_model::OperationIds { + operation_ids: vec![ + "O1q4CBcuYo8YANEV34W4JRWVHrzcYns19VJfyAB7jT4qfitAnMC".to_string() + ], + }, + )), }; // send filter with unknow op id @@ -230,14 +231,12 @@ async fn new_operations() { assert!(result.is_err()); // send filter with known op id - let filter_id = massa_proto_rs::massa::api::v1::NewOperationsFilter { - filter: Some( - massa_proto_rs::massa::api::v1::new_operations_filter::Filter::OperationIds( - massa_proto_rs::massa::model::v1::OperationIds { - operation_ids: vec![op.id.to_string()], - }, - ), - ), + let filter_id = grpc_api::NewOperationsFilter { + filter: Some(grpc_api::new_operations_filter::Filter::OperationIds( + grpc_model::OperationIds { + operation_ids: vec![op.id.to_string()], + }, + )), }; tx_request @@ -261,14 +260,12 @@ async fn new_operations() { keypair.get_public_key().to_string() ); - let mut filter_type = massa_proto_rs::massa::api::v1::NewOperationsFilter { - filter: Some( - massa_proto_rs::massa::api::v1::new_operations_filter::Filter::OperationTypes( - massa_proto_rs::massa::model::v1::OpTypes { - op_types: vec![massa_proto_rs::massa::model::v1::OpType::CallSc as i32], - }, - ), - ), + let mut filter_type = grpc_api::NewOperationsFilter { + filter: Some(grpc_api::new_operations_filter::Filter::OperationTypes( + grpc_model::OpTypes { + op_types: vec![grpc_model::OpType::CallSc as i32], + }, + )), }; tx_request @@ -284,14 +281,12 @@ async fn new_operations() { assert!(result.is_err()); - filter_type = massa_proto_rs::massa::api::v1::NewOperationsFilter { - filter: Some( - massa_proto_rs::massa::api::v1::new_operations_filter::Filter::OperationTypes( - massa_proto_rs::massa::model::v1::OpTypes { - op_types: vec![massa_proto_rs::massa::model::v1::OpType::Transaction as i32], - }, - ), - ), + filter_type = grpc_api::NewOperationsFilter { + filter: Some(grpc_api::new_operations_filter::Filter::OperationTypes( + grpc_model::OpTypes { + op_types: vec![grpc_model::OpType::Transaction as i32], + }, + )), }; tx_request @@ -331,16 +326,12 @@ async fn new_operations() { keypair.get_public_key().to_string() ); - let mut filter_addr = massa_proto_rs::massa::api::v1::NewOperationsFilter { - filter: Some( - massa_proto_rs::massa::api::v1::new_operations_filter::Filter::Addresses( - massa_proto_rs::massa::model::v1::Addresses { - addresses: vec![ - "AU12BTfZ7k1z6PsLEUZeHYNirz6WJ3NdrWto9H4TkVpkV9xE2TJg2".to_string() - ], - }, - ), - ), + let mut filter_addr = grpc_api::NewOperationsFilter { + filter: Some(grpc_api::new_operations_filter::Filter::Addresses( + grpc_model::Addresses { + addresses: vec!["AU12BTfZ7k1z6PsLEUZeHYNirz6WJ3NdrWto9H4TkVpkV9xE2TJg2".to_string()], + }, + )), }; tx_request @@ -355,14 +346,12 @@ async fn new_operations() { // unknown address assert!(result.is_err()); - filter_addr = massa_proto_rs::massa::api::v1::NewOperationsFilter { - filter: Some( - massa_proto_rs::massa::api::v1::new_operations_filter::Filter::Addresses( - massa_proto_rs::massa::model::v1::Addresses { - addresses: vec![address.to_string()], - }, - ), - ), + filter_addr = grpc_api::NewOperationsFilter { + filter: Some(grpc_api::new_operations_filter::Filter::Addresses( + grpc_model::Addresses { + addresses: vec![address.to_string()], + }, + )), }; tx_request @@ -425,16 +414,14 @@ async fn new_blocks() { .unwrap() .into_inner(); - let mut filter_slot = massa_proto_rs::massa::api::v1::NewBlocksFilter { - filter: Some( - massa_proto_rs::massa::api::v1::new_blocks_filter::Filter::SlotRange(SlotRange { - start_slot: Some(ProtoSlot { - period: 1, - thread: 1, - }), - end_slot: None, + let mut filter_slot = grpc_api::NewBlocksFilter { + filter: Some(grpc_api::new_blocks_filter::Filter::SlotRange(SlotRange { + start_slot: Some(ProtoSlot { + period: 1, + thread: 1, }), - ), + end_slot: None, + })), }; tx_request .send(NewBlocksRequest { @@ -455,16 +442,14 @@ async fn new_blocks() { // assert block is received assert!(result.signed_block.is_some()); - filter_slot = massa_proto_rs::massa::api::v1::NewBlocksFilter { - filter: Some( - massa_proto_rs::massa::api::v1::new_blocks_filter::Filter::SlotRange(SlotRange { - start_slot: Some(ProtoSlot { - period: 1, - thread: 15, - }), - end_slot: None, + filter_slot = grpc_api::NewBlocksFilter { + filter: Some(grpc_api::new_blocks_filter::Filter::SlotRange(SlotRange { + start_slot: Some(ProtoSlot { + period: 1, + thread: 15, }), - ), + end_slot: None, + })), }; // update filter @@ -484,16 +469,14 @@ async fn new_blocks() { // elapsed, start slot is after block slot assert!(result.is_err()); - filter_slot = massa_proto_rs::massa::api::v1::NewBlocksFilter { - filter: Some( - massa_proto_rs::massa::api::v1::new_blocks_filter::Filter::SlotRange(SlotRange { - start_slot: None, - end_slot: Some(ProtoSlot { - period: 1, - thread: 15, - }), + filter_slot = grpc_api::NewBlocksFilter { + filter: Some(grpc_api::new_blocks_filter::Filter::SlotRange(SlotRange { + start_slot: None, + end_slot: Some(ProtoSlot { + period: 1, + thread: 15, }), - ), + })), }; tx_request @@ -516,12 +499,10 @@ async fn new_blocks() { // assert block is received assert!(result.signed_block.is_some()); - let mut filter_addr = massa_proto_rs::massa::api::v1::NewBlocksFilter { - filter: Some( - massa_proto_rs::massa::api::v1::new_blocks_filter::Filter::Addresses(Addresses { - addresses: vec!["AU12BTfZ7k1z6PsLEUZeHYNirz6WJ3NdrWto9H4TkVpkV9xE2TJg2".to_string()], - }), - ), + let mut filter_addr = grpc_api::NewBlocksFilter { + filter: Some(grpc_api::new_blocks_filter::Filter::Addresses(Addresses { + addresses: vec!["AU12BTfZ7k1z6PsLEUZeHYNirz6WJ3NdrWto9H4TkVpkV9xE2TJg2".to_string()], + })), }; tx_request @@ -540,12 +521,10 @@ async fn new_blocks() { // elapsed assert!(result.is_err()); - filter_addr = massa_proto_rs::massa::api::v1::NewBlocksFilter { - filter: Some( - massa_proto_rs::massa::api::v1::new_blocks_filter::Filter::Addresses(Addresses { - addresses: vec![address.to_string()], - }), - ), + filter_addr = grpc_api::NewBlocksFilter { + filter: Some(grpc_api::new_blocks_filter::Filter::Addresses(Addresses { + addresses: vec![address.to_string()], + })), }; tx_request @@ -568,16 +547,12 @@ async fn new_blocks() { assert!(result.signed_block.is_some()); - let mut filter_ids = massa_proto_rs::massa::api::v1::NewBlocksFilter { - filter: Some( - massa_proto_rs::massa::api::v1::new_blocks_filter::Filter::BlockIds( - massa_proto_rs::massa::model::v1::BlockIds { - block_ids: vec![ - "B1q4CBcuYo8YANEV34W4JRWVHrzcYns19VJfyAB7jT4qfitAnMC".to_string() - ], - }, - ), - ), + let mut filter_ids = grpc_api::NewBlocksFilter { + filter: Some(grpc_api::new_blocks_filter::Filter::BlockIds( + grpc_model::BlockIds { + block_ids: vec!["B1q4CBcuYo8YANEV34W4JRWVHrzcYns19VJfyAB7jT4qfitAnMC".to_string()], + }, + )), }; tx_request @@ -596,14 +571,12 @@ async fn new_blocks() { // elapsed assert!(result.is_err()); - filter_ids = massa_proto_rs::massa::api::v1::NewBlocksFilter { - filter: Some( - massa_proto_rs::massa::api::v1::new_blocks_filter::Filter::BlockIds( - massa_proto_rs::massa::model::v1::BlockIds { - block_ids: vec![block_op.id.to_string()], - }, - ), - ), + filter_ids = grpc_api::NewBlocksFilter { + filter: Some(grpc_api::new_blocks_filter::Filter::BlockIds( + grpc_model::BlockIds { + block_ids: vec![block_op.id.to_string()], + }, + )), }; tx_request @@ -626,12 +599,10 @@ async fn new_blocks() { assert!(result.signed_block.is_some()); - filter_addr = massa_proto_rs::massa::api::v1::NewBlocksFilter { - filter: Some( - massa_proto_rs::massa::api::v1::new_blocks_filter::Filter::Addresses(Addresses { - addresses: vec!["massa".to_string()], - }), - ), + filter_addr = grpc_api::NewBlocksFilter { + filter: Some(grpc_api::new_blocks_filter::Filter::Addresses(Addresses { + addresses: vec!["massa".to_string()], + })), }; tx_request @@ -683,20 +654,18 @@ async fn new_endorsements() { .unwrap() .into_inner(); - let mut filter_ids = massa_proto_rs::massa::api::v1::NewEndorsementsFilter { - filter: Some( - massa_proto_rs::massa::api::v1::new_endorsements_filter::Filter::EndorsementIds( - massa_proto_rs::massa::model::v1::EndorsementIds { - endorsement_ids: vec![ - "E1q4CBcuYo8YANEV34W4JRWVHrzcYns19VJfyAB7jT4qfitAnMC".to_string() - ], - }, - ), - ), + let mut filter_ids = grpc_api::NewEndorsementsFilter { + filter: Some(grpc_api::new_endorsements_filter::Filter::EndorsementIds( + grpc_model::EndorsementIds { + endorsement_ids: vec![ + "E1q4CBcuYo8YANEV34W4JRWVHrzcYns19VJfyAB7jT4qfitAnMC".to_string() + ], + }, + )), }; tx_request - .send(massa_proto_rs::massa::api::v1::NewEndorsementsRequest { + .send(grpc_api::NewEndorsementsRequest { filters: vec![filter_ids], }) .await @@ -709,18 +678,16 @@ async fn new_endorsements() { let result = tokio::time::timeout(Duration::from_secs(2), resp_stream.next()).await; assert!(result.is_err()); - filter_ids = massa_proto_rs::massa::api::v1::NewEndorsementsFilter { - filter: Some( - massa_proto_rs::massa::api::v1::new_endorsements_filter::Filter::EndorsementIds( - massa_proto_rs::massa::model::v1::EndorsementIds { - endorsement_ids: vec![endorsement.id.to_string()], - }, - ), - ), + filter_ids = grpc_api::NewEndorsementsFilter { + filter: Some(grpc_api::new_endorsements_filter::Filter::EndorsementIds( + grpc_model::EndorsementIds { + endorsement_ids: vec![endorsement.id.to_string()], + }, + )), }; tx_request - .send(massa_proto_rs::massa::api::v1::NewEndorsementsRequest { + .send(grpc_api::NewEndorsementsRequest { filters: vec![filter_ids], }) .await @@ -738,20 +705,16 @@ async fn new_endorsements() { assert!(result.signed_endorsement.is_some()); - let mut filter_addr = massa_proto_rs::massa::api::v1::NewEndorsementsFilter { - filter: Some( - massa_proto_rs::massa::api::v1::new_endorsements_filter::Filter::Addresses( - massa_proto_rs::massa::model::v1::Addresses { - addresses: vec![ - "AU12BTfZ7k1z6PsLEUZeHYNirz6WJ3NdrWto9H4TkVpkV9xE2TJg2".to_string() - ], - }, - ), - ), + let mut filter_addr = grpc_api::NewEndorsementsFilter { + filter: Some(grpc_api::new_endorsements_filter::Filter::Addresses( + grpc_model::Addresses { + addresses: vec!["AU12BTfZ7k1z6PsLEUZeHYNirz6WJ3NdrWto9H4TkVpkV9xE2TJg2".to_string()], + }, + )), }; tx_request - .send(massa_proto_rs::massa::api::v1::NewEndorsementsRequest { + .send(grpc_api::NewEndorsementsRequest { filters: vec![filter_addr], }) .await @@ -765,18 +728,16 @@ async fn new_endorsements() { // unknown address assert!(result.is_err()); - filter_addr = massa_proto_rs::massa::api::v1::NewEndorsementsFilter { - filter: Some( - massa_proto_rs::massa::api::v1::new_endorsements_filter::Filter::Addresses( - massa_proto_rs::massa::model::v1::Addresses { - addresses: vec![endorsement.content_creator_address.to_string()], - }, - ), - ), + filter_addr = grpc_api::NewEndorsementsFilter { + filter: Some(grpc_api::new_endorsements_filter::Filter::Addresses( + grpc_model::Addresses { + addresses: vec![endorsement.content_creator_address.to_string()], + }, + )), }; tx_request - .send(massa_proto_rs::massa::api::v1::NewEndorsementsRequest { + .send(grpc_api::NewEndorsementsRequest { filters: vec![filter_addr], }) .await @@ -794,20 +755,16 @@ async fn new_endorsements() { assert!(result.signed_endorsement.is_some()); - let mut filter_block_ids = massa_proto_rs::massa::api::v1::NewEndorsementsFilter { - filter: Some( - massa_proto_rs::massa::api::v1::new_endorsements_filter::Filter::BlockIds( - massa_proto_rs::massa::model::v1::BlockIds { - block_ids: vec![ - "B1q4CBcuYo8YANEV34W4JRWVHrzcYns19VJfyAB7jT4qfitAnMC".to_string() - ], - }, - ), - ), + let mut filter_block_ids = grpc_api::NewEndorsementsFilter { + filter: Some(grpc_api::new_endorsements_filter::Filter::BlockIds( + grpc_model::BlockIds { + block_ids: vec!["B1q4CBcuYo8YANEV34W4JRWVHrzcYns19VJfyAB7jT4qfitAnMC".to_string()], + }, + )), }; tx_request - .send(massa_proto_rs::massa::api::v1::NewEndorsementsRequest { + .send(grpc_api::NewEndorsementsRequest { filters: vec![filter_block_ids], }) .await @@ -820,18 +777,16 @@ async fn new_endorsements() { let result = tokio::time::timeout(Duration::from_secs(2), resp_stream.next()).await; assert!(result.is_err()); - filter_block_ids = massa_proto_rs::massa::api::v1::NewEndorsementsFilter { - filter: Some( - massa_proto_rs::massa::api::v1::new_endorsements_filter::Filter::BlockIds( - massa_proto_rs::massa::model::v1::BlockIds { - block_ids: vec![endorsement.content.endorsed_block.to_string()], - }, - ), - ), + filter_block_ids = grpc_api::NewEndorsementsFilter { + filter: Some(grpc_api::new_endorsements_filter::Filter::BlockIds( + grpc_model::BlockIds { + block_ids: vec![endorsement.content.endorsed_block.to_string()], + }, + )), }; tx_request - .send(massa_proto_rs::massa::api::v1::NewEndorsementsRequest { + .send(grpc_api::NewEndorsementsRequest { filters: vec![filter_block_ids], }) .await @@ -888,16 +843,14 @@ async fn new_filled_blocks() { .unwrap() .into_inner(); - let mut filter = massa_proto_rs::massa::api::v1::NewBlocksFilter { - filter: Some( - massa_proto_rs::massa::api::v1::new_blocks_filter::Filter::SlotRange(SlotRange { - start_slot: Some(ProtoSlot { - period: 1, - thread: 0, - }), - end_slot: None, + let mut filter = grpc_api::NewBlocksFilter { + filter: Some(grpc_api::new_blocks_filter::Filter::SlotRange(SlotRange { + start_slot: Some(ProtoSlot { + period: 1, + thread: 0, }), - ), + end_slot: None, + })), }; tx_request @@ -919,16 +872,14 @@ async fn new_filled_blocks() { assert!(result.filled_block.is_some()); - filter = massa_proto_rs::massa::api::v1::NewBlocksFilter { - filter: Some( - massa_proto_rs::massa::api::v1::new_blocks_filter::Filter::SlotRange(SlotRange { - start_slot: Some(ProtoSlot { - period: 1, - thread: 5, - }), - end_slot: None, + filter = grpc_api::NewBlocksFilter { + filter: Some(grpc_api::new_blocks_filter::Filter::SlotRange(SlotRange { + start_slot: Some(ProtoSlot { + period: 1, + thread: 5, }), - ), + end_slot: None, + })), }; tx_request @@ -946,16 +897,12 @@ async fn new_filled_blocks() { // stat slot is after block slot assert!(result.is_err()); - filter = massa_proto_rs::massa::api::v1::NewBlocksFilter { - filter: Some( - massa_proto_rs::massa::api::v1::new_blocks_filter::Filter::BlockIds( - massa_proto_rs::massa::model::v1::BlockIds { - block_ids: vec![ - "B1q4CBcuYo8YANEV34W4JRWVHrzcYns19VJfyAB7jT4qfitAnMC".to_string() - ], - }, - ), - ), + filter = grpc_api::NewBlocksFilter { + filter: Some(grpc_api::new_blocks_filter::Filter::BlockIds( + grpc_model::BlockIds { + block_ids: vec!["B1q4CBcuYo8YANEV34W4JRWVHrzcYns19VJfyAB7jT4qfitAnMC".to_string()], + }, + )), }; tx_request @@ -973,14 +920,12 @@ async fn new_filled_blocks() { // unknown block id assert!(result.is_err()); - filter = massa_proto_rs::massa::api::v1::NewBlocksFilter { - filter: Some( - massa_proto_rs::massa::api::v1::new_blocks_filter::Filter::BlockIds( - massa_proto_rs::massa::model::v1::BlockIds { - block_ids: vec![filled_block.header.id.to_string()], - }, - ), - ), + filter = grpc_api::NewBlocksFilter { + filter: Some(grpc_api::new_blocks_filter::Filter::BlockIds( + grpc_model::BlockIds { + block_ids: vec![filled_block.header.id.to_string()], + }, + )), }; tx_request @@ -1002,12 +947,10 @@ async fn new_filled_blocks() { assert!(result.filled_block.is_some()); - filter = massa_proto_rs::massa::api::v1::NewBlocksFilter { - filter: Some( - massa_proto_rs::massa::api::v1::new_blocks_filter::Filter::Addresses(Addresses { - addresses: vec!["AU12BTfZ7k1z6PsLEUZeHYNirz6WJ3NdrWto9H4TkVpkV9xE2TJg2".to_string()], - }), - ), + filter = grpc_api::NewBlocksFilter { + filter: Some(grpc_api::new_blocks_filter::Filter::Addresses(Addresses { + addresses: vec!["AU12BTfZ7k1z6PsLEUZeHYNirz6WJ3NdrWto9H4TkVpkV9xE2TJg2".to_string()], + })), }; tx_request @@ -1025,12 +968,10 @@ async fn new_filled_blocks() { // unknown address assert!(result.is_err()); - filter = massa_proto_rs::massa::api::v1::NewBlocksFilter { - filter: Some( - massa_proto_rs::massa::api::v1::new_blocks_filter::Filter::Addresses(Addresses { - addresses: vec![address.to_string()], - }), - ), + filter = grpc_api::NewBlocksFilter { + filter: Some(grpc_api::new_blocks_filter::Filter::Addresses(Addresses { + addresses: vec![address.to_string()], + })), }; tx_request @@ -1072,21 +1013,30 @@ async fn new_slot_execution_outputs() { // Given let mut state_changes = StateChanges::default(); // Create async pool changes - state_changes.async_pool_changes = get_random_async_pool_changes(3, config.thread_count); + let async_pool_changes = get_random_async_pool_changes(2, config.thread_count); + state_changes.async_pool_changes = async_pool_changes.clone(); // Create executed denunciations changes - state_changes.executed_denunciations_changes = get_random_executed_de_changes(3); + let executed_denunciations_changes = get_random_executed_de_changes(2); + state_changes.executed_denunciations_changes = executed_denunciations_changes.clone(); // Create executed operations changes - state_changes.executed_ops_changes = get_random_executed_ops_changes(3); + let executed_ops_changes = get_random_executed_ops_changes(2); + state_changes.executed_ops_changes = executed_ops_changes.clone(); // Create ledger changes - state_changes.ledger_changes = get_random_ledger_changes(3); + let ledger_changes = get_random_ledger_changes(2); + state_changes.ledger_changes = ledger_changes.clone(); // Create execution trail hash change - state_changes.execution_trail_hash_change = get_random_execution_trail_hash_change(true); + let execution_trail_hash_change = get_random_execution_trail_hash_change(true); + state_changes.execution_trail_hash_change = execution_trail_hash_change.clone(); let exec_output_1 = ExecutionOutput { slot: Slot::new(1, 5), - block_info: None, + block_info: Some(massa_execution_exports::ExecutedBlockInfo { + block_id: get_dummy_block_id("toto"), + current_version: 1, + announced_version: None, + }), state_changes, - events: get_random_eventstore(3), + events: get_random_eventstore(2), }; let (tx_request, rx) = tokio::sync::mpsc::channel(10); @@ -1107,17 +1057,15 @@ async fn new_slot_execution_outputs() { .unwrap() .into_inner(); - let mut filter = massa_proto_rs::massa::api::v1::NewSlotExecutionOutputsFilter { + let mut filter = grpc_api::NewSlotExecutionOutputsFilter { filter: Some( - massa_proto_rs::massa::api::v1::new_slot_execution_outputs_filter::Filter::SlotRange( - SlotRange { - start_slot: Some(ProtoSlot { - period: 1, - thread: 0, - }), - end_slot: None, - }, - ), + grpc_api::new_slot_execution_outputs_filter::Filter::SlotRange(SlotRange { + start_slot: Some(ProtoSlot { + period: 1, + thread: 0, + }), + end_slot: None, + }), ), }; @@ -1141,20 +1089,18 @@ async fn new_slot_execution_outputs() { assert!(result.output.is_some()); - filter = massa_proto_rs::massa::api::v1::NewSlotExecutionOutputsFilter { + filter = grpc_api::NewSlotExecutionOutputsFilter { filter: Some( - massa_proto_rs::massa::api::v1::new_slot_execution_outputs_filter::Filter::SlotRange( - SlotRange { - start_slot: Some(ProtoSlot { - period: 1, - thread: 0, - }), - end_slot: Some(ProtoSlot { - period: 1, - thread: 7, - }), - }, - ), + grpc_api::new_slot_execution_outputs_filter::Filter::SlotRange(SlotRange { + start_slot: Some(ProtoSlot { + period: 1, + thread: 0, + }), + end_slot: Some(ProtoSlot { + period: 1, + thread: 7, + }), + }), ), }; @@ -1178,17 +1124,15 @@ async fn new_slot_execution_outputs() { // start slot and end slot are in range assert!(result.output.is_some()); - filter = massa_proto_rs::massa::api::v1::NewSlotExecutionOutputsFilter { + filter = grpc_api::NewSlotExecutionOutputsFilter { filter: Some( - massa_proto_rs::massa::api::v1::new_slot_execution_outputs_filter::Filter::SlotRange( - SlotRange { - start_slot: Some(ProtoSlot { - period: 1, - thread: 7, - }), - end_slot: None, - }, - ), + grpc_api::new_slot_execution_outputs_filter::Filter::SlotRange(SlotRange { + start_slot: Some(ProtoSlot { + period: 1, + thread: 7, + }), + end_slot: None, + }), ), }; @@ -1208,15 +1152,13 @@ async fn new_slot_execution_outputs() { // start slot is after block slot assert!(result.is_err()); - // TODO add test when filter is updated - - filter = massa_proto_rs::massa::api::v1::NewSlotExecutionOutputsFilter { + filter = grpc_api::NewSlotExecutionOutputsFilter { filter: Some( - massa_proto_rs::massa::api::v1::new_slot_execution_outputs_filter::Filter::EventFilter( - massa_proto_rs::massa::api::v1::ExecutionEventFilter { + grpc_api::new_slot_execution_outputs_filter::Filter::EventFilter( + grpc_api::ExecutionEventFilter { filter: Some( - massa_proto_rs::massa::api::v1::execution_event_filter::Filter::OriginalOperationId( "O1q4CBcuYo8YANEV34W4JRWVHrzcYns19VJfyAB7jT4qfitAnMC" - .to_string() + grpc_api::execution_event_filter::Filter::OriginalOperationId( + "O1q4CBcuYo8YANEV34W4JRWVHrzcYns19VJfyAB7jT4qfitAnMC".to_string(), ), ), }, @@ -1237,9 +1179,123 @@ async fn new_slot_execution_outputs() { .unwrap(); let result = tokio::time::timeout(Duration::from_secs(2), resp_stream.next()).await; - dbg!(&result); assert!(result.is_err()); + // execution status filter + let mut filters = Vec::new(); + filter = grpc_api::NewSlotExecutionOutputsFilter { + filter: Some(grpc_api::new_slot_execution_outputs_filter::Filter::Status( + grpc_model::ExecutionOutputStatus::Final as i32, + )), + }; + filters.push(filter); + let mut filters = Vec::new(); + filter = grpc_api::NewSlotExecutionOutputsFilter { + filter: Some(grpc_api::new_slot_execution_outputs_filter::Filter::Status( + grpc_model::ExecutionOutputStatus::Candidate as i32, + )), + }; + filters.push(filter); + // event filter + filter = grpc_api::NewSlotExecutionOutputsFilter { + filter: Some( + grpc_api::new_slot_execution_outputs_filter::Filter::EventFilter( + grpc_api::ExecutionEventFilter { + filter: Some(grpc_api::execution_event_filter::Filter::None( + grpc_model::Empty {}, + )), + }, + ), + ), + }; + filters.push(filter); + // async pool changes filter + filter = grpc_api::NewSlotExecutionOutputsFilter { + filter: Some( + grpc_api::new_slot_execution_outputs_filter::Filter::AsyncPoolChangesFilter( + grpc_api::AsyncPoolChangesFilter { + filter: Some(grpc_api::async_pool_changes_filter::Filter::None( + grpc_model::Empty {}, + )), + }, + ), + ), + }; + filters.push(filter); + + // executed denunciations changes filter + filter = grpc_api::NewSlotExecutionOutputsFilter { + filter: Some( + grpc_api::new_slot_execution_outputs_filter::Filter::ExecutedDenounciationFilter( + grpc_api::ExecutedDenounciationFilter { + filter: Some(grpc_api::executed_denounciation_filter::Filter::None( + grpc_model::Empty {}, + )), + }, + ), + ), + }; + filters.push(filter); + let (op_id, (_, _)) = executed_ops_changes.iter().next().unwrap(); + // executed operations changes filter + filter = grpc_api::NewSlotExecutionOutputsFilter { + filter: Some( + grpc_api::new_slot_execution_outputs_filter::Filter::ExecutedOpsChangesFilter( + grpc_api::ExecutedOpsChangesFilter { + filter: Some(grpc_api::executed_ops_changes_filter::Filter::OperationId( + op_id.to_string(), + )), + }, + ), + ), + }; + filters.push(filter); + + // ledger changes filter + filter = grpc_api::NewSlotExecutionOutputsFilter { + filter: Some( + grpc_api::new_slot_execution_outputs_filter::Filter::LedgerChangesFilter( + grpc_api::LedgerChangesFilter { + filter: Some(grpc_api::ledger_changes_filter::Filter::None( + grpc_model::Empty {}, + )), + }, + ), + ), + }; + filters.push(filter); + + tx_request + .send(NewSlotExecutionOutputsRequest { filters }) + .await + .unwrap(); + tokio::time::sleep(Duration::from_millis(50)).await; + + slot_tx + .send(SlotExecutionOutput::ExecutedSlot(exec_output_1.clone())) + .unwrap(); + + let result = tokio::time::timeout(Duration::from_secs(5), resp_stream.next()) + .await + .unwrap() + .unwrap() + .unwrap(); + + // complexe filter result + assert!(result.output.is_some()); + assert!(result.output.clone().unwrap().execution_output.is_some()); + let state_changes = result + .output + .unwrap() + .execution_output + .unwrap() + .state_changes + .unwrap(); + assert!(state_changes.async_pool_changes.is_empty()); + assert!(state_changes.executed_ops_changes.len() == 1); + assert!(state_changes.executed_denunciations_changes.is_empty()); + assert!(state_changes.ledger_changes.is_empty()); + stop_handle.stop(); } @@ -1305,10 +1361,10 @@ async fn send_operations() { .unwrap(); match result.result.unwrap() { - massa_proto_rs::massa::api::v1::send_operations_response::Result::OperationIds(_) => { + grpc_api::send_operations_response::Result::OperationIds(_) => { panic!("should be error"); } - massa_proto_rs::massa::api::v1::send_operations_response::Result::Error(err) => { + grpc_api::send_operations_response::Result::Error(err) => { assert!(err.message.contains("invalid operation")); } } @@ -1331,7 +1387,7 @@ async fn send_operations() { .unwrap(); match result.result.unwrap() { - massa_proto_rs::massa::api::v1::send_operations_response::Result::Error(err) => { + grpc_api::send_operations_response::Result::Error(err) => { assert!(err .message .contains("Operation expire_period is lower than the current period of this node")); @@ -1362,11 +1418,11 @@ async fn send_operations() { .unwrap(); match result { - massa_proto_rs::massa::api::v1::send_operations_response::Result::OperationIds(ope_id) => { + grpc_api::send_operations_response::Result::OperationIds(ope_id) => { assert_eq!(ope_id.operation_ids.len(), 1); assert_eq!(ope_id.operation_ids[0], op2.id.to_string()); } - massa_proto_rs::massa::api::v1::send_operations_response::Result::Error(_) => { + grpc_api::send_operations_response::Result::Error(_) => { panic!("should be ok") } } @@ -1384,7 +1440,7 @@ async fn send_operations() { .unwrap(); match result.result.unwrap() { - massa_proto_rs::massa::api::v1::send_operations_response::Result::Error(err) => { + grpc_api::send_operations_response::Result::Error(err) => { assert_eq!(err.message, "too many operations per message"); } _ => { @@ -1475,7 +1531,7 @@ async fn send_endorsements() { .unwrap(); match result.result.unwrap() { - massa_proto_rs::massa::api::v1::send_endorsements_response::Result::Error(err) => { + grpc_api::send_endorsements_response::Result::Error(err) => { assert!(err.message.contains("failed to deserialize endorsement")) } _ => panic!("should be error"), @@ -1535,7 +1591,7 @@ async fn send_blocks() { // .unwrap(); // match result.result.unwrap() { - // massa_proto_rs::massa::api::v1::send_blocks_response::Result::Error(err) => { + // grpc_api::send_blocks_response::Result::Error(err) => { // assert!(err.message.contains("not available")) // } // _ => panic!("should be error"), From 52082bd34a8f4635b50d84f619da12394c3b36fa Mon Sep 17 00:00:00 2001 From: Moncef AOUDIA Date: Tue, 17 Oct 2023 18:23:55 +0200 Subject: [PATCH 10/13] refactor: enhanced async pool test --- massa-grpc/src/tests/stream.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/massa-grpc/src/tests/stream.rs b/massa-grpc/src/tests/stream.rs index 459c6a5c86b..6301a4f3bb2 100644 --- a/massa-grpc/src/tests/stream.rs +++ b/massa-grpc/src/tests/stream.rs @@ -1210,12 +1210,21 @@ async fn new_slot_execution_outputs() { }; filters.push(filter); // async pool changes filter + let can_be_executed = match async_pool_changes.0.iter().next().unwrap().1 { + massa_ledger_exports::SetUpdateOrDelete::Set(value) => Some(value.can_be_executed), + massa_ledger_exports::SetUpdateOrDelete::Update(value) => match value.can_be_executed { + massa_ledger_exports::SetOrKeep::Set(value) => Some(value), + massa_ledger_exports::SetOrKeep::Keep => None, + }, + massa_ledger_exports::SetUpdateOrDelete::Delete => None, + }; + filter = grpc_api::NewSlotExecutionOutputsFilter { filter: Some( grpc_api::new_slot_execution_outputs_filter::Filter::AsyncPoolChangesFilter( grpc_api::AsyncPoolChangesFilter { - filter: Some(grpc_api::async_pool_changes_filter::Filter::None( - grpc_model::Empty {}, + filter: Some(grpc_api::async_pool_changes_filter::Filter::CanBeExecuted( + can_be_executed.unwrap(), )), }, ), @@ -1291,7 +1300,7 @@ async fn new_slot_execution_outputs() { .unwrap() .state_changes .unwrap(); - assert!(state_changes.async_pool_changes.is_empty()); + assert!(state_changes.async_pool_changes.len() == 2); assert!(state_changes.executed_ops_changes.len() == 1); assert!(state_changes.executed_denunciations_changes.is_empty()); assert!(state_changes.ledger_changes.is_empty()); From 00c66b886df5ee70c6fce55feff83cc72b326747 Mon Sep 17 00:00:00 2001 From: Moncef AOUDIA Date: Tue, 17 Oct 2023 21:42:45 +0200 Subject: [PATCH 11/13] fix: rebasing issues --- Cargo.lock | 1 - massa-execution-exports/Cargo.toml | 5 ++--- massa-execution-exports/src/test_exports/mod.rs | 2 -- massa-grpc/Cargo.toml | 4 +--- massa-grpc/src/tests/stream.rs | 5 +++-- 5 files changed, 6 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 422b1b8f2b3..63bc82c7094 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2837,7 +2837,6 @@ dependencies = [ "massa_versioning", "mockall", "num", - "parking_lot", "rand", "tempfile", "thiserror", diff --git a/massa-execution-exports/Cargo.toml b/massa-execution-exports/Cargo.toml index 52de6a2ae1f..f5822b02500 100644 --- a/massa-execution-exports/Cargo.toml +++ b/massa-execution-exports/Cargo.toml @@ -5,8 +5,8 @@ authors = ["Massa Labs "] edition = "2021" [features] -gas_calibration = ["massa_ledger_exports/testing", "parking_lot", "tempfile"] -testing = ["massa_models/testing", "massa_ledger_exports/testing", "parking_lot", "tempfile", "mockall", "rand"] +gas_calibration = ["tempfile"] +testing = ["massa_models/testing", "tempfile", "mockall", "rand"] [dependencies] displaydoc = {workspace = true} @@ -22,7 +22,6 @@ massa_time = {workspace = true} massa_storage = {workspace = true} massa_final_state = {workspace = true} massa_pos_exports = {workspace = true} -massa_ledger_exports = {workspace = true, optional = true} massa_module_cache = {workspace = true} massa_versioning = {workspace = true} massa-sc-runtime = {workspace = true} diff --git a/massa-execution-exports/src/test_exports/mod.rs b/massa-execution-exports/src/test_exports/mod.rs index 84c781a3c50..5a3a00db59e 100644 --- a/massa-execution-exports/src/test_exports/mod.rs +++ b/massa-execution-exports/src/test_exports/mod.rs @@ -14,9 +14,7 @@ //! with an execution worker within tests. mod config; -mod mock; mod tools; pub use config::*; -pub use mock::*; pub use tools::*; diff --git a/massa-grpc/Cargo.toml b/massa-grpc/Cargo.toml index 92d0d78971d..4b90afa24dd 100644 --- a/massa-grpc/Cargo.toml +++ b/massa-grpc/Cargo.toml @@ -8,7 +8,7 @@ homepage = "https://massa.net" documentation = "https://docs.massa.net/" [features] -testing = ["dep:mockall", "dep:num", "dep:massa_channel"] +testing = [] [dependencies] # Internal packages @@ -55,7 +55,5 @@ tracing = { workspace = true } massa_bootstrap = { workspace = true, "features" = ["testing"] } massa_consensus_exports = { workspace = true, "features" = ["testing"] } massa_final_state = { workspace = true } -mockall = { workspace = true } num = { workspace = true } tokio = { workspace = true, "features" = ["test-util", "time"] } -num = {workspace = true} diff --git a/massa-grpc/src/tests/stream.rs b/massa-grpc/src/tests/stream.rs index 6301a4f3bb2..55d6f14f8e6 100644 --- a/massa-grpc/src/tests/stream.rs +++ b/massa-grpc/src/tests/stream.rs @@ -1,12 +1,13 @@ // Copyright (c) 2023 MASSA LABS -use crate::tests::mock::{grpc_public_service, MockExecutionCtrl, MockPoolCtrl}; +use crate::tests::mock::grpc_public_service; use massa_bootstrap::test_exports::{ get_dummy_block_id, get_random_async_pool_changes, get_random_executed_de_changes, get_random_executed_ops_changes, get_random_execution_trail_hash_change, get_random_ledger_changes, }; -use massa_consensus_exports::test_exports::MockConsensusControllerImpl; +use massa_consensus_exports::MockConsensusController; +use massa_execution_exports::MockExecutionController; use massa_execution_exports::{ test_exports::get_random_eventstore, ExecutionOutput, SlotExecutionOutput, }; From 22b1b408a8878564635efff7e33e2f6f9fd2e59c Mon Sep 17 00:00:00 2001 From: Moncef AOUDIA Date: Tue, 17 Oct 2023 22:39:14 +0200 Subject: [PATCH 12/13] fix: mock import issue --- massa-grpc/src/tests/stream.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/massa-grpc/src/tests/stream.rs b/massa-grpc/src/tests/stream.rs index 55d6f14f8e6..54e281a0192 100644 --- a/massa-grpc/src/tests/stream.rs +++ b/massa-grpc/src/tests/stream.rs @@ -16,6 +16,7 @@ use massa_models::{ address::Address, block::FilledBlock, secure_share::SecureShareSerializer, slot::Slot, stats::ExecutionStats, }; +use massa_pool_exports::MockPoolController; use massa_proto_rs::massa::api::v1::{self as grpc_api}; use massa_proto_rs::massa::model::v1::{self as grpc_model}; use massa_proto_rs::massa::{ From e6b8c90393529da8673f0b3f38b55b77a4df249a Mon Sep 17 00:00:00 2001 From: Moncef AOUDIA Date: Wed, 18 Oct 2023 15:13:32 +0200 Subject: [PATCH 13/13] refactor: add more tests --- massa-bootstrap/src/test_exports/mod.rs | 2 ++ massa-bootstrap/src/tests/scenarios.rs | 2 +- massa-grpc/src/tests/stream.rs | 33 ++++++++++++++++++++++++- 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/massa-bootstrap/src/test_exports/mod.rs b/massa-bootstrap/src/test_exports/mod.rs index 63a5b5e4ee4..106b0d12d2f 100644 --- a/massa-bootstrap/src/test_exports/mod.rs +++ b/massa-bootstrap/src/test_exports/mod.rs @@ -1,3 +1,5 @@ +// Copyright (c) 2023 MASSA LABS + /// Toolkit for testing purposes mod tools; diff --git a/massa-bootstrap/src/tests/scenarios.rs b/massa-bootstrap/src/tests/scenarios.rs index 7e50239bc37..c70ef886df4 100644 --- a/massa-bootstrap/src/tests/scenarios.rs +++ b/massa-bootstrap/src/tests/scenarios.rs @@ -1,4 +1,4 @@ -// Copyright (c) 2023 MASSA LABS +// Copyright (c) 2022 MASSA LABS use crate::listener::PollEvent; use crate::test_exports::{ diff --git a/massa-grpc/src/tests/stream.rs b/massa-grpc/src/tests/stream.rs index 54e281a0192..ff2857e6bd1 100644 --- a/massa-grpc/src/tests/stream.rs +++ b/massa-grpc/src/tests/stream.rs @@ -1191,7 +1191,6 @@ async fn new_slot_execution_outputs() { )), }; filters.push(filter); - let mut filters = Vec::new(); filter = grpc_api::NewSlotExecutionOutputsFilter { filter: Some(grpc_api::new_slot_execution_outputs_filter::Filter::Status( grpc_model::ExecutionOutputStatus::Candidate as i32, @@ -1307,6 +1306,38 @@ async fn new_slot_execution_outputs() { assert!(state_changes.executed_denunciations_changes.is_empty()); assert!(state_changes.ledger_changes.is_empty()); + // Too many filters + let mut filters = Vec::new(); + // executed operations changes filter + let filter = grpc_api::NewSlotExecutionOutputsFilter { + filter: Some( + grpc_api::new_slot_execution_outputs_filter::Filter::ExecutedOpsChangesFilter( + grpc_api::ExecutedOpsChangesFilter { + filter: Some(grpc_api::executed_ops_changes_filter::Filter::None( + grpc_model::Empty {}, + )), + }, + ), + ), + }; + for _ in 0..config.max_filters_per_request + 1 { + filters.push(filter.clone()); + } + + tx_request + .send(NewSlotExecutionOutputsRequest { filters: filters }) + .await + .unwrap(); + tokio::time::sleep(Duration::from_millis(50)).await; + + slot_tx + .send(SlotExecutionOutput::ExecutedSlot(exec_output_1.clone())) + .unwrap(); + + let result = tokio::time::timeout(Duration::from_secs(2), resp_stream.next()).await; + // Too many filters + assert!(result.unwrap().unwrap().is_err()); + stop_handle.stop(); }