Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add max_decoding_message_size config #12

Merged
merged 3 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]


## [0.8.0] - 2023-09-11
### Changes
- Add `max_decoding_message_size` configuration to gRPC server and client libs.


## [0.7.1] - 2023-08-11
### Fixed
- Remove the `version` attribute from the `eth-state-fold-test` dependency to prevent it from being published.


## [0.7.0] - 2023-08-10
### Changes
- Publish crates to crates.io instead of the `cartesi` private registry.
Expand Down Expand Up @@ -142,7 +149,8 @@ reestablishing it at every subscription attempt.
## [0.1.0] - 2021-12-28
- Initial release

[Unreleased]: https://github.com/cartesi/state-fold/compare/v0.7.1...HEAD
[Unreleased]: https://github.com/cartesi/state-fold/compare/v0.8.0...HEAD
[0.8.0]: https://github.com/cartesi/state-fold/compare/v0.7.1...v0.8.0
[0.7.1]: https://github.com/cartesi/state-fold/compare/v0.7.0...v0.7.1
[0.7.0]: https://github.com/cartesi/state-fold/compare/v0.6.3...v0.7.0
[0.6.3]: https://github.com/cartesi/state-fold/compare/v0.6.2...v0.6.3
Expand Down
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ members = [
]

[workspace.package]
version = "0.7.1"
version = "0.8.0"

authors = [
"Gabriel Coutinho de Paula <[email protected]>",
Expand All @@ -31,10 +31,10 @@ repository = "https://github.com/cartesi/state-fold"


[workspace.dependencies]
eth-state-fold-types = { version = "0.7", path = "state-fold-types" }
eth-block-history = { version = "0.7", path = "block-history" }
eth-state-fold = { version = "0.7", path = "state-fold" }
eth-state-server-common = { version = "0.7", path = "state-server-common" }
eth-state-fold-types = { version = "0.8", path = "state-fold-types" }
eth-block-history = { version = "0.8", path = "block-history" }
eth-state-fold = { version = "0.8", path = "state-fold" }
eth-state-server-common = { version = "0.8", path = "state-server-common" }
eth-state-fold-test = { path = "state-fold-test" }

ethabi = "18"
Expand Down
8 changes: 8 additions & 0 deletions state-client-lib/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,17 @@ pub struct SCEnvCLIConfig {
/// Default confirmations
#[arg(long, env)]
pub sc_default_confirmations: Option<usize>,

/// Maximum size of a decoded message
#[arg(long, env, default_value_t = 100 * 1024 * 1024)]
pub ss_max_decoding_message_size: usize,
}

#[derive(Clone, Debug)]
pub struct SCConfig {
pub grpc_endpoint: String,
pub default_confirmations: usize,
pub max_decoding_message_size: usize,
}

#[derive(Debug, Snafu)]
Expand Down Expand Up @@ -49,9 +54,12 @@ impl SCConfig {
.sc_default_confirmations
.unwrap_or(DEFAULT_DEFAULT_CONFIRMATIONS);

let max_decoding_message_size = env_cli_config.ss_max_decoding_message_size;

Ok(SCConfig {
grpc_endpoint,
default_confirmations,
max_decoding_message_size,
})
}
}
6 changes: 4 additions & 2 deletions state-client-lib/src/grpc_client.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// (c) Cartesi and individual authors (see AUTHORS)
// SPDX-License-Identifier: Apache-2.0 (see LICENSE)

use crate::config::SCConfig;
use crate::{error::*, BlockServer, StateServer};

use ethers::core::types::H256;
Expand Down Expand Up @@ -33,8 +34,9 @@ pub struct GrpcStateFoldClient<I, S> {
}

impl<I, S> GrpcStateFoldClient<I, S> {
pub fn new_from_channel(channel: Channel) -> Self {
let client = StateFoldClient::new(channel);
pub fn new_from_channel(channel: Channel, config: &SCConfig) -> Self {
let client = StateFoldClient::new(channel)
.max_decoding_message_size(config.max_decoding_message_size);

Self {
client,
Expand Down
8 changes: 8 additions & 0 deletions state-server-lib/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,18 @@ pub struct StateServerEnvCLIConfig {
/// Server address
#[arg(long, env)]
pub ss_server_address: Option<String>,

/// Maximum size of a decoded message
#[arg(long, env, default_value_t = 100 * 1024 * 1024)]
pub ss_max_decoding_message_size: usize,
}

#[derive(Clone, Debug)]
pub struct StateServerConfig {
pub state_fold: SFConfig,
pub block_history: BHConfig,
pub server_address: std::net::SocketAddr,
pub max_decoding_message_size: usize,
}

#[derive(Debug, Snafu)]
Expand Down Expand Up @@ -53,10 +58,13 @@ impl StateServerConfig {
.parse()
.context(AddressParseSnafu)?;

let max_decoding_message_size = env_cli_config.ss_max_decoding_message_size;

Ok(Self {
state_fold,
block_history,
server_address,
max_decoding_message_size,
})
}
}
13 changes: 8 additions & 5 deletions state-server-lib/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// (c) Cartesi and individual authors (see AUTHORS)
// SPDX-License-Identifier: Apache-2.0 (see LICENSE)
use crate::grpc_server::StateServer;
use crate::{config::StateServerConfig, grpc_server::StateServer};

use eth_state_fold::Foldable;
use eth_state_fold_types::ethers::providers::Middleware;
Expand All @@ -15,7 +15,7 @@ pub async fn start_server<
UD: Send + Sync + 'static,
F: Foldable<UserData = UD> + 'static,
>(
address: std::net::SocketAddr,
config: &StateServerConfig,
state_server: StateServer<M, UD, F>,
kill_switch: oneshot::Receiver<()>,
) -> Result<(), tonic::transport::Error>
Expand All @@ -31,13 +31,16 @@ where

let block_subscriber = Arc::clone(&state_server.block_subscriber);

tracing::info!("StateFoldServer listening on {}", address);
tracing::info!("StateFoldServer listening on {}", config.server_address);

Server::builder()
.trace_fn(|_| tracing::trace_span!("state_fold_server"))
.add_service(health_server)
.add_service(StateFoldServer::new(state_server))
.serve_with_shutdown(address, async {
.add_service(
StateFoldServer::new(state_server)
.max_decoding_message_size(config.max_decoding_message_size),
)
.serve_with_shutdown(config.server_address, async {
select! {
r = block_subscriber.wait_for_completion() => {
tracing::error!("`block_subscriber` has exited: {:?}", r);
Expand Down
Loading