Skip to content
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
3 changes: 2 additions & 1 deletion catalyst-gateway/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,5 @@ panic = "deny"
string_slice = "deny"
unchecked_duration_subtraction = "deny"
unreachable = "deny"
missing_docs_in_private_items = "deny"
missing_docs_in_private_items = "deny"
arithmetic_side_effects = "deny"
2 changes: 1 addition & 1 deletion catalyst-gateway/Earthfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
VERSION 0.8

IMPORT github.com/input-output-hk/catalyst-ci/earthly/rust:v3.2.27 AS rust-ci
IMPORT github.com/input-output-hk/catalyst-ci/earthly/rust:v3.2.28 AS rust-ci

#cspell: words rustfmt toolsets USERARCH stdcfgs

Expand Down
2 changes: 1 addition & 1 deletion catalyst-gateway/bin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ repository.workspace = true
workspace = true

[dependencies]
cardano-chain-follower = { version = "0.0.6", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "v0.0.10" }
cardano-chain-follower = {version = "0.0.6", git = "https://github.com/input-output-hk/catalyst-libs.git", tag="v0.0.10" }
c509-certificate = { version = "0.0.3", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "v0.0.3" }
rbac-registration = { version = "0.0.2", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "v0.0.8" }

Expand Down
21 changes: 13 additions & 8 deletions catalyst-gateway/bin/src/cardano/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ impl SyncParams {

/// Convert a result back into parameters for a retry.
fn retry(&self) -> Self {
let retry_count = self.retries + 1;
let retry_count = self.retries.saturating_add(1);

let mut backoff = None;

Expand Down Expand Up @@ -200,7 +200,7 @@ impl SyncParams {
done.first_is_immutable = first_immutable;
done.last_indexed_block = last;
done.last_is_immutable = last_immutable;
done.total_blocks_synced += synced;
done.total_blocks_synced = done.total_blocks_synced.saturating_add(synced);
done.last_blocks_synced = synced;

done.result = Arc::new(Some(result));
Expand Down Expand Up @@ -298,7 +298,7 @@ fn sync_subchain(params: SyncParams) -> tokio::task::JoinHandle<SyncParams> {
first_immutable = last_immutable;
first_indexed_block = Some(block.point());
}
blocks_synced += 1;
blocks_synced = blocks_synced.saturating_add(1);
},
cardano_chain_follower::Kind::Rollback => {
warn!("TODO: Live Chain rollback");
Expand Down Expand Up @@ -423,7 +423,11 @@ impl SyncTask {
} else if let Some(result) = finished.result.as_ref() {
match result {
Ok(()) => {
self.current_sync_tasks -= 1;
self.current_sync_tasks =
self.current_sync_tasks.checked_sub(1).unwrap_or_else(|| {
error!("current_sync_tasks -= 1 overflow");
0
});
info!(chain=%self.cfg.chain, report=%finished,
"The Immutable follower completed successfully.");

Expand Down Expand Up @@ -472,9 +476,10 @@ impl SyncTask {
if self.start_slot < self.immutable_tip_slot {
// Will also break if there are no more slots left to sync.
while self.current_sync_tasks < self.cfg.sync_tasks {
let end_slot = self
.immutable_tip_slot
.min(self.start_slot + self.cfg.sync_chunk_max_slots);
let end_slot = self.immutable_tip_slot.min(
self.start_slot
.saturating_add(self.cfg.sync_chunk_max_slots),
);

if let Some((first_point, last_point)) =
self.get_syncable_range(self.start_slot, end_slot)
Expand All @@ -484,7 +489,7 @@ impl SyncTask {
first_point,
last_point.clone(),
)));
self.current_sync_tasks += 1;
self.current_sync_tasks = self.current_sync_tasks.saturating_add(1);
}

// The one slot overlap is deliberate, it doesn't hurt anything and prevents all off
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fn merge_consecutive_sync_records(mut synced_chunks: Vec<SyncStatus>) -> Vec<Syn
// The new record is contained fully within the previous one.
// We will ignore the new record and use the previous one instead.
current_status = Some(current);
} else if rec.start_slot <= current.end_slot + 1 {
} else if rec.start_slot <= current.end_slot.saturating_add(1) {
// Either overlaps, or is directly consecutive.
// But not fully contained within the previous one.
current_status = Some(SyncStatus {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,14 @@ fn build_stake_info(
for txn_map in txos_by_txn.into_values() {
for txo_info in txn_map.into_values() {
if txo_info.spent_slot_no.is_none() {
stake_info.ada_amount +=
i64::try_from(txo_info.value).map_err(|err| anyhow!(err))?;
let value = i64::try_from(txo_info.value).map_err(|err| anyhow!(err))?;
stake_info.ada_amount =
stake_info.ada_amount.checked_add(value).ok_or_else(|| {
anyhow!(
"Total stake amount overflow: {} + {value}",
stake_info.ada_amount
)
})?;

for asset in txo_info.assets.into_values().flatten() {
stake_info.native_tokens.push(StakedNativeTokenInfo {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,13 @@ impl CatalystRBACTokenV1 {
// The token is considered old if it was issued more than max_age ago.
// And newer than an allowed clock skew value
// This is a safety measure to avoid replay attacks.
((now - max_age) < token_age) && ((now + max_skew) > token_age)
let Some(min_time) = now.checked_sub(max_age) else {
return false;
};
let Some(max_time) = now.checked_add(max_skew) else {
return false;
};
(min_time < token_age) && (max_time > token_age)
}
}

Expand Down
7 changes: 6 additions & 1 deletion catalyst-gateway/bin/src/settings/chain_follower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,12 @@ impl EnvVars {
default_dl_chunk_size,
1,
MAX_DL_CHUNK_SIZE,
) * ONE_MEGABYTE;
)
.checked_mul(ONE_MEGABYTE)
.unwrap_or_else(|| {
info!("Too big 'CHAIN_FOLLOWER_DL_CHUNK_SIZE' value, default value {default_dl_chunk_size} is used");
default_dl_chunk_size
});
dl_config = dl_config.with_chunk_size(chunk_size);

let queue_ahead = StringEnvVar::new_as(
Expand Down
1 change: 1 addition & 0 deletions catalyst-gateway/clippy.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
allow-unwrap-in-tests = true
allow-expect-in-tests = true
allow-panic-in-tests = true
arithmetic-side-effects-allowed = ["num_bigint::BigInt"]
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,5 @@ panic = "deny"
string_slice = "deny"
unchecked_duration_subtraction = "deny"
unreachable = "deny"
missing_docs_in_private_items = "deny"
missing_docs_in_private_items = "deny"
arithmetic_side_effects = "deny"
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
VERSION 0.8

IMPORT github.com/input-output-hk/catalyst-ci/earthly/rust:v3.2.27 AS rust-ci
IMPORT github.com/input-output-hk/catalyst-ci/earthly/rust:v3.2.28 AS rust-ci
IMPORT ../ AS flutter-rust-bridge

# builder : Setup the builder
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
allow-unwrap-in-tests = true
allow-expect-in-tests = true
allow-panic-in-tests = true
arithmetic-side-effects-allowed = ["num_bigint::BigInt"]
Loading