Skip to content

Commit c5d11a6

Browse files
committed
chore: apply PR reviews suggestions
- fix/enhance some doc comments and logs - use u64 everywhere for offset configuration and parsing - `expand_epoch`: - use const value from `"latest".len()` instead of `7` - tests: add decimal cases
1 parent 35df8a6 commit c5d11a6

File tree

5 files changed

+12
-10
lines changed

5 files changed

+12
-10
lines changed

mithril-aggregator/src/database/repository/signed_entity_store.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub trait SignedEntityStorer: Sync + Send {
4444
total: usize,
4545
) -> StdResult<Vec<SignedEntityRecord>>;
4646

47-
/// Get Cardano database signed entities by epoch
47+
/// Get signed entities by signed entity type and epoch
4848
async fn get_last_signed_entities_by_type_and_epoch(
4949
&self,
5050
signed_entity_type_id: &SignedEntityTypeDiscriminants,

mithril-aggregator/src/http_server/routes/artifact_routes/cardano_database.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ fn artifact_cardano_database_list(
2323
.and_then(handlers::list_artifacts)
2424
}
2525

26-
/// GET /artifact/cardano-database/epoch/:epoch{-offset}
26+
/// GET /artifact/cardano-database/epoch/:epoch
2727
fn artifact_cardano_database_list_by_epoch(
2828
router_state: &RouterState,
2929
) -> impl Filter<Extract = (impl warp::Reply + use<>,), Error = warp::Rejection> + Clone + use<> {
@@ -113,7 +113,7 @@ mod handlers {
113113
logger: Logger,
114114
epoch_service: EpochServiceWrapper,
115115
http_message_service: Arc<dyn MessageService>,
116-
max_artifact_epoch_offset: u32,
116+
max_artifact_epoch_offset: u64,
117117
) -> Result<impl warp::Reply, Infallible> {
118118
let expanded_epoch = match parameters::expand_epoch(&epoch, epoch_service).await {
119119
Ok(epoch) => epoch,
@@ -126,11 +126,11 @@ mod handlers {
126126
}
127127
};
128128

129-
if expanded_epoch.has_offset_greater_than(max_artifact_epoch_offset as u64) {
129+
if expanded_epoch.has_offset_greater_than(max_artifact_epoch_offset) {
130130
return Ok(reply::bad_request(
131131
"invalid_epoch".to_string(),
132132
format!(
133-
"offset greater than max configured: epoch:`{epoch}`, max offset:`{max_artifact_epoch_offset}`"
133+
"offset greater than maximum allowed value: epoch:`{epoch}`, max offset:`{max_artifact_epoch_offset}`"
134134
),
135135
));
136136
}

mithril-aggregator/src/http_server/routes/artifact_routes/cardano_stake_distribution.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ pub mod handlers {
121121
http_message_service: Arc<dyn MessageService>,
122122
metrics_service: Arc<MetricsService>,
123123
epoch_service: EpochServiceWrapper,
124-
max_artifact_epoch_offset: u32,
124+
max_artifact_epoch_offset: u64,
125125
) -> Result<impl warp::Reply, Infallible> {
126126
metrics_service
127127
.get_artifact_detail_cardano_stake_distribution_total_served_since_startup()
@@ -141,11 +141,11 @@ pub mod handlers {
141141
}
142142
};
143143

144-
if expanded_epoch.has_offset_greater_than(max_artifact_epoch_offset as u64) {
144+
if expanded_epoch.has_offset_greater_than(max_artifact_epoch_offset) {
145145
return Ok(reply::bad_request(
146146
"invalid_epoch".to_string(),
147147
format!(
148-
"offset greater than max configured: epoch:`{epoch}`, max offset:`{max_artifact_epoch_offset}`"
148+
"offset greater than maximum allowed value: epoch:`{epoch}`, max offset:`{max_artifact_epoch_offset}`"
149149
),
150150
));
151151
}

mithril-aggregator/src/http_server/routes/middlewares.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ pub mod parameters {
276276
.epoch_of_current_data()
277277
.map(ExpandedEpoch::Latest)
278278
} else if epoch_str.starts_with("latest-") {
279-
let (_, offset_str) = epoch_str.split_at(7);
279+
let (_, offset_str) = epoch_str.split_at("latest-".len());
280280
let offset = offset_str
281281
.parse::<u64>()
282282
.with_context(|| "Invalid epoch offset: must be a number")?;
@@ -503,6 +503,8 @@ mod tests {
503503
"latest+",
504504
"latest+0",
505505
"latest+293",
506+
"latest-4.5",
507+
"latest+2.9",
506508
"latest-invalid",
507509
] {
508510
parameters::expand_epoch(invalid_epoch, epoch_service.clone())

mithril-aggregator/src/http_server/routes/router.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub struct RouterConfig {
3131
pub allowed_discriminants: BTreeSet<SignedEntityTypeDiscriminants>,
3232
pub cardano_transactions_prover_max_hashes_allowed_by_request: usize,
3333
pub cardano_db_artifacts_directory: PathBuf,
34-
pub max_artifact_epoch_offset: u32,
34+
pub max_artifact_epoch_offset: u64,
3535
pub snapshot_directory: PathBuf,
3636
pub cardano_node_version: String,
3737
pub allow_http_serve_directory: bool,

0 commit comments

Comments
 (0)