Skip to content
Open
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
1 change: 1 addition & 0 deletions crates/core/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,7 @@ pub struct GrpcConfig {
pub listen_address: String,
pub tls_client_ca_root: Option<PathBuf>,
pub permissive_cors: Option<bool>,
pub max_dump_history_items: Option<u32>,
}

#[derive(Deserialize, Serialize, Clone)]
Expand Down
1 change: 1 addition & 0 deletions src/bin/dolos/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ impl ConfigEditor {
listen_address: "[::]:50051".into(),
tls_client_ca_root: None,
permissive_cors: Some(true),
max_dump_history_items: None,
}
.into();
} else {
Expand Down
4 changes: 3 additions & 1 deletion src/serve/grpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ where

async fn run(cfg: Self::Config, domain: D, cancel: C) -> Result<(), ServeError> {
let addr = cfg.listen_address.parse().unwrap();
let max_history_items = cfg.max_dump_history_items.unwrap_or(100);

let sync_service = sync::SyncServiceImpl::new(domain.clone(), cancel.clone());
let sync_service =
sync::SyncServiceImpl::new(domain.clone(), cancel.clone(), max_history_items);
Comment on lines +33 to +34
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of passing individual settings, clone the config struct directly and pass it ot the service. Let the service decide what it needs.

let sync_service = u5c::sync::sync_service_server::SyncServiceServer::new(sync_service);

let query_service = query::QueryServiceImpl::new(domain.clone());
Expand Down
19 changes: 11 additions & 8 deletions src/serve/grpc/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ use tonic::{Request, Response, Status};

use crate::prelude::*;

const MAX_DUMP_HISTORY_ITEMS: u32 = 100;

fn u5c_to_chain_point(block_ref: u5c::sync::BlockRef) -> Result<ChainPoint, Status> {
Ok(ChainPoint::Specific(
block_ref.slot,
Expand Down Expand Up @@ -97,20 +95,22 @@ where
domain: D,
mapper: interop::Mapper<D>,
cancel: C,
max_history_items: u32,
}

impl<D, C> SyncServiceImpl<D, C>
where
D: Domain + LedgerContext,
C: CancelToken,
{
pub fn new(domain: D, cancel: C) -> Self {
pub fn new(domain: D, cancel: C, max_history_items: u32) -> Self {
let mapper = Mapper::new(domain.clone());

Self {
domain,
mapper,
cancel,
max_history_items,
}
}
}
Expand Down Expand Up @@ -186,9 +186,10 @@ where

let from = msg.start_token.map(|x| x.slot);

if msg.max_items > MAX_DUMP_HISTORY_ITEMS {
if msg.max_items > self.max_history_items {
return Err(Status::invalid_argument(format!(
"max_items must be less than or equal to {MAX_DUMP_HISTORY_ITEMS}"
"max_items must be less than or equal to {}",
self.max_history_items
)));
}

Expand Down Expand Up @@ -288,7 +289,7 @@ mod tests {
use dolos_core::ImportExt;
domain.import_blocks(batch).unwrap();

let service = SyncServiceImpl::new(domain, cancel);
let service = SyncServiceImpl::new(domain, cancel, 100);

let mut start_token = None;

Expand Down Expand Up @@ -331,11 +332,13 @@ mod tests {
let domain = ToyDomain::new(None, None);
let cancel = CancelTokenImpl::default();

let service = SyncServiceImpl::new(domain, cancel);
let max_configurable = 10;

let service = SyncServiceImpl::new(domain, cancel, max_configurable);

let request = u5c::sync::DumpHistoryRequest {
start_token: None,
max_items: MAX_DUMP_HISTORY_ITEMS + 1,
max_items: max_configurable + 1,
field_mask: None,
};

Expand Down
Loading