Skip to content

Commit

Permalink
feat: adding new parameters to the component execution config
Browse files Browse the repository at this point in the history
commit-id:54781e9e
  • Loading branch information
lev-starkware committed Aug 8, 2024
1 parent 8f66c2d commit d80da28
Show file tree
Hide file tree
Showing 7 changed files with 415 additions and 32 deletions.
3 changes: 3 additions & 0 deletions Cargo.lock

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

80 changes: 80 additions & 0 deletions config/mempool/default_config.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,94 @@
{
"components.gateway.component_type": {
"description": "The component type.",
"privacy": "Public",
"value": "IndependentComponent"
},
"components.gateway.execute": {
"description": "The component execution flag.",
"privacy": "Public",
"value": true
},
"components.gateway.local_config.#is_none": {
"description": "Flag for an optional field.",
"privacy": "TemporaryValue",
"value": false
},
"components.gateway.local_config.channel_buffer_size": {
"description": "The communication channel buffer size.",
"privacy": "Public",
"value": 32
},
"components.gateway.location": {
"description": "The component location.",
"privacy": "Public",
"value": "Local"
},
"components.gateway.remote_config.#is_none": {
"description": "Flag for an optional field.",
"privacy": "TemporaryValue",
"value": true
},
"components.gateway.remote_config.ip": {
"description": "The remote component server ip.",
"privacy": "Public",
"value": "0.0.0.0"
},
"components.gateway.remote_config.port": {
"description": "The remote component server port.",
"privacy": "Public",
"value": 8080
},
"components.gateway.remote_config.retries": {
"description": "The max number of retries for sending a message.",
"privacy": "Public",
"value": 3
},
"components.mempool.component_type": {
"description": "The component type.",
"privacy": "Public",
"value": "SynchronousComponent"
},
"components.mempool.execute": {
"description": "The component execution flag.",
"privacy": "Public",
"value": true
},
"components.mempool.local_config.#is_none": {
"description": "Flag for an optional field.",
"privacy": "TemporaryValue",
"value": false
},
"components.mempool.local_config.channel_buffer_size": {
"description": "The communication channel buffer size.",
"privacy": "Public",
"value": 32
},
"components.mempool.location": {
"description": "The component location.",
"privacy": "Public",
"value": "Local"
},
"components.mempool.remote_config.#is_none": {
"description": "Flag for an optional field.",
"privacy": "TemporaryValue",
"value": true
},
"components.mempool.remote_config.ip": {
"description": "The remote component server ip.",
"privacy": "Public",
"value": "0.0.0.0"
},
"components.mempool.remote_config.port": {
"description": "The remote component server port.",
"privacy": "Public",
"value": 8080
},
"components.mempool.remote_config.retries": {
"description": "The max number of retries for sending a message.",
"privacy": "Public",
"value": 3
},
"gateway_config.compiler_config.sierra_to_casm_compiler_config.max_bytecode_size": {
"description": "Limitation of contract bytecode size.",
"privacy": "Public",
Expand Down
2 changes: 2 additions & 0 deletions crates/mempool_infra/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ workspace = true
async-trait.workspace = true
bincode.workspace = true
hyper = { workspace = true, features = ["client", "http2", "server", "tcp"] }
papyrus_config = { path = "../papyrus_config", version = "0.4.0-rc.0" }
rstest.workspace = true
serde = { workspace = true, features = ["derive"] }
thiserror.workspace = true
tokio.workspace = true
tracing.workspace = true
tracing-subscriber = { workspace = true, features = ["env-filter"] }
validator.workspace = true

[dev-dependencies]
assert_matches.workspace = true
Expand Down
71 changes: 71 additions & 0 deletions crates/mempool_infra/src/component_definitions.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
use std::collections::BTreeMap;
use std::net::IpAddr;

use async_trait::async_trait;
use papyrus_config::dumping::{ser_param, SerializeConfig};
use papyrus_config::{ParamPath, ParamPrivacyInput, SerializedParam};
use serde::{Deserialize, Serialize};
use thiserror::Error;
use tokio::sync::mpsc::{Receiver, Sender};
use validator::Validate;

const DEFAULT_CHANNEL_BUFFER_SIZE: usize = 32;
const DEFAULT_RETRIES: usize = 3;

#[async_trait]
pub trait ComponentRequestHandler<Request, Response> {
Expand Down Expand Up @@ -43,3 +52,65 @@ pub enum ServerError {
#[error("Could not deserialize client request: {0}")]
RequestDeserializationFailure(String),
}

// The communication configuration of the local component.
#[derive(Clone, Debug, Serialize, Deserialize, Validate, PartialEq)]
pub struct LocalComponentCommunicationConfig {
pub channel_buffer_size: usize,
}

impl SerializeConfig for LocalComponentCommunicationConfig {
fn dump(&self) -> BTreeMap<ParamPath, SerializedParam> {
BTreeMap::from_iter([ser_param(
"channel_buffer_size",
&self.channel_buffer_size,
"The communication channel buffer size.",
ParamPrivacyInput::Public,
)])
}
}

impl Default for LocalComponentCommunicationConfig {
fn default() -> Self {
Self { channel_buffer_size: DEFAULT_CHANNEL_BUFFER_SIZE }
}
}

// The communication configuration of the remote component.
#[derive(Clone, Debug, Serialize, Deserialize, Validate, PartialEq)]
pub struct RemoteComponentCommunicationConfig {
pub ip: IpAddr,
pub port: u16,
pub retries: usize,
}

impl SerializeConfig for RemoteComponentCommunicationConfig {
fn dump(&self) -> BTreeMap<ParamPath, SerializedParam> {
BTreeMap::from_iter([
ser_param(
"ip",
&self.ip.to_string(),
"The remote component server ip.",
ParamPrivacyInput::Public,
),
ser_param(
"port",
&self.port,
"The remote component server port.",
ParamPrivacyInput::Public,
),
ser_param(
"retries",
&self.retries,
"The max number of retries for sending a message.",
ParamPrivacyInput::Public,
),
])
}
}

impl Default for RemoteComponentCommunicationConfig {
fn default() -> Self {
Self { ip: "0.0.0.0".parse().unwrap(), port: 8080, retries: DEFAULT_RETRIES }
}
}
1 change: 1 addition & 0 deletions crates/mempool_node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ clap.workspace = true
const_format.workspace = true
futures.workspace = true
papyrus_config.workspace = true
rstest.workspace = true
serde.workspace = true
starknet_gateway.workspace = true
starknet_mempool.workspace = true
Expand Down
Loading

0 comments on commit d80da28

Please sign in to comment.