Skip to content

Commit

Permalink
feat: adding consensus manager to ComponentExecutionConfig and Mempoo…
Browse files Browse the repository at this point in the history
…lNodeConfig

commit-id:3811a2b1
  • Loading branch information
lev-starkware committed Aug 15, 2024
1 parent 010f5d4 commit 7cc317e
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 4 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

50 changes: 50 additions & 0 deletions config/mempool/default_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,51 @@
"privacy": "Public",
"value": 3
},
"components.consensus_manager.component_type": {
"description": "The component type.",
"privacy": "Public",
"value": "AsynchronousComponent"
},
"components.consensus_manager.execute": {
"description": "The component execution flag.",
"privacy": "Public",
"value": true
},
"components.consensus_manager.local_config.#is_none": {
"description": "Flag for an optional field.",
"privacy": "TemporaryValue",
"value": false
},
"components.consensus_manager.local_config.channel_buffer_size": {
"description": "The communication channel buffer size.",
"privacy": "Public",
"value": 32
},
"components.consensus_manager.location": {
"description": "The component location.",
"privacy": "Public",
"value": "Local"
},
"components.consensus_manager.remote_config.#is_none": {
"description": "Flag for an optional field.",
"privacy": "TemporaryValue",
"value": true
},
"components.consensus_manager.remote_config.ip": {
"description": "The remote component server ip.",
"privacy": "Public",
"value": "0.0.0.0"
},
"components.consensus_manager.remote_config.port": {
"description": "The remote component server port.",
"privacy": "Public",
"value": 8080
},
"components.consensus_manager.remote_config.retries": {
"description": "The max number of retries for sending a message.",
"privacy": "Public",
"value": 3
},
"components.gateway.component_type": {
"description": "The component type.",
"privacy": "Public",
Expand Down Expand Up @@ -144,6 +189,11 @@
"privacy": "Public",
"value": 3
},
"consensus_manager_config.consensus_config_param_1": {
"description": "The first consensus manager configuration parameter",
"privacy": "Public",
"value": 1
},
"gateway_config.network_config.ip": {
"description": "The gateway server ip.",
"privacy": "Public",
Expand Down
1 change: 1 addition & 0 deletions crates/mempool_node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ rstest.workspace = true
serde.workspace = true
starknet_batcher.workspace = true
starknet_batcher_types.workspace = true
starknet_consensus_manager.workspace = true
starknet_gateway.workspace = true
starknet_mempool.workspace = true
starknet_mempool_infra.workspace = true
Expand Down
13 changes: 10 additions & 3 deletions crates/mempool_node/src/config/config_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ fn test_invalid_components_config() {
// Initialize an invalid config and check that the validator finds an error.
let component_config = ComponentConfig {
batcher: ComponentExecutionConfig { execute: false, ..ComponentExecutionConfig::default() },
consensus_manager: ComponentExecutionConfig { execute: false, ..ComponentExecutionConfig::default() },
gateway: ComponentExecutionConfig { execute: false, ..ComponentExecutionConfig::default() },
mempool: ComponentExecutionConfig { execute: false, ..ComponentExecutionConfig::default() },
};
Expand All @@ -138,11 +139,13 @@ fn test_invalid_components_config() {
/// Test the validation of the struct ComponentConfig.
/// The validation validates at least one of the components is set with execute: true.
#[rstest]
#[case(true, false, false)]
#[case(false, true, false)]
#[case(false, false, true)]
#[case(true, false, false, false)]
#[case(false, true, false, false)]
#[case(false, false, true, false)]
#[case(false, false, false, true)]
fn test_valid_components_config(
#[case] batcher_component_execute: bool,
#[case] consensus_manager_component_execute: bool,
#[case] gateway_component_execute: bool,
#[case] mempool_component_execute: bool,
) {
Expand All @@ -152,6 +155,10 @@ fn test_valid_components_config(
execute: batcher_component_execute,
..ComponentExecutionConfig::default()
},
consensus_manager: ComponentExecutionConfig {
execute: consensus_manager_component_execute,
..ComponentExecutionConfig::default()
},
gateway: ComponentExecutionConfig {
execute: gateway_component_execute,
..ComponentExecutionConfig::default()
Expand Down
24 changes: 23 additions & 1 deletion crates/mempool_node/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use papyrus_config::loading::load_and_process_config;
use papyrus_config::{ConfigError, ParamPath, ParamPrivacyInput, SerializedParam};
use serde::{Deserialize, Serialize};
use starknet_batcher::config::BatcherConfig;
use starknet_consensus_manager::config::ConsensusManagerConfig;
use starknet_gateway::config::{GatewayConfig, RpcStateReaderConfig};
use starknet_mempool_infra::component_definitions::{
LocalComponentCommunicationConfig,
Expand Down Expand Up @@ -137,6 +138,16 @@ impl ComponentExecutionConfig {
remote_config: None,
}
}

pub fn consensus_manager_default_config() -> Self {
Self {
execute: true,
location: LocationType::Local,
component_type: ComponentType::AsynchronousComponent,
local_config: Some(LocalComponentCommunicationConfig::default()),
remote_config: None,
}
}
}

pub fn validate_single_component_config(
Expand Down Expand Up @@ -169,6 +180,8 @@ pub struct ComponentConfig {
#[validate]
pub batcher: ComponentExecutionConfig,
#[validate]
pub consensus_manager: ComponentExecutionConfig,
#[validate]
pub gateway: ComponentExecutionConfig,
#[validate]
pub mempool: ComponentExecutionConfig,
Expand All @@ -178,6 +191,7 @@ impl Default for ComponentConfig {
fn default() -> Self {
Self {
batcher: ComponentExecutionConfig::batcher_default_config(),
consensus_manager: ComponentExecutionConfig::consensus_manager_default_config(),
gateway: ComponentExecutionConfig::gateway_default_config(),
mempool: ComponentExecutionConfig::mempool_default_config(),
}
Expand All @@ -189,6 +203,7 @@ impl SerializeConfig for ComponentConfig {
#[allow(unused_mut)]
let mut sub_configs = vec![
append_sub_config_name(self.batcher.dump(), "batcher"),
append_sub_config_name(self.consensus_manager.dump(), "consensus_manager"),
append_sub_config_name(self.gateway.dump(), "gateway"),
append_sub_config_name(self.mempool.dump(), "mempool"),
];
Expand All @@ -198,7 +213,11 @@ impl SerializeConfig for ComponentConfig {
}

pub fn validate_components_config(components: &ComponentConfig) -> Result<(), ValidationError> {
if components.gateway.execute || components.mempool.execute || components.batcher.execute {
if components.gateway.execute
|| components.mempool.execute
|| components.batcher.execute
|| components.consensus_manager.execute
{
return Ok(());
}

Expand All @@ -215,6 +234,8 @@ pub struct MempoolNodeConfig {
#[validate]
pub batcher_config: BatcherConfig,
#[validate]
pub consensus_manager_config: ConsensusManagerConfig,
#[validate]
pub gateway_config: GatewayConfig,
#[validate]
pub rpc_state_reader_config: RpcStateReaderConfig,
Expand All @@ -228,6 +249,7 @@ impl SerializeConfig for MempoolNodeConfig {
let mut sub_configs = vec![
append_sub_config_name(self.components.dump(), "components"),
append_sub_config_name(self.batcher_config.dump(), "batcher_config"),
append_sub_config_name(self.consensus_manager_config.dump(), "consensus_manager_config"),
append_sub_config_name(self.gateway_config.dump(), "gateway_config"),
append_sub_config_name(self.rpc_state_reader_config.dump(), "rpc_state_reader_config"),
append_sub_config_name(self.compiler_config.dump(), "compiler_config"),
Expand Down

0 comments on commit 7cc317e

Please sign in to comment.