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

chore(general): Update catalyst-ci version #371

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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 hermes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ string_slice = "deny"
unchecked_duration_subtraction = "deny"
unreachable = "deny"
missing_docs_in_private_items = "deny"
arithmetic_side_effects = "deny"

[workspace.dependencies]
# specific commit from the `catalyst` branch
Expand Down
2 changes: 1 addition & 1 deletion hermes/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.03 AS rust-ci
IMPORT github.com/input-output-hk/catalyst-ci/earthly/rust:v3.2.28 AS rust-ci
# Use when debugging cat-ci locally.
# IMPORT ../../catalyst-ci/earthly/rust AS rust-ci

Expand Down
14 changes: 6 additions & 8 deletions hermes/bin/src/hdf5/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl std::io::Read for File {
let remaining_len = file_size.saturating_sub(self.pos);

let reading_len = std::cmp::min(buf.len(), remaining_len);
let selection = hdf5::Selection::new(self.pos..self.pos + reading_len);
let selection = hdf5::Selection::new(self.pos..self.pos.saturating_add(reading_len));

let data = self
.hdf5_ds
Expand All @@ -96,7 +96,7 @@ impl std::io::Write for File {
let new_shape = [file_size.saturating_add(increasing_len)];
self.hdf5_ds.resize(new_shape).map_err(map_to_io_error)?;

let selection = hdf5::Selection::new(self.pos..self.pos + buf.len());
let selection = hdf5::Selection::new(self.pos..self.pos.saturating_add(buf.len()));

self.hdf5_ds
.write_slice(buf, selection)
Expand Down Expand Up @@ -133,12 +133,10 @@ impl std::io::Seek for File {
self.pos = n;
Ok(self.pos.try_into().map_err(map_to_io_error)?)
},
None => {
Err(std::io::Error::new(
std::io::ErrorKind::InvalidInput,
"Invalid seek to a negative or overflowing position",
))
},
None => Err(std::io::Error::new(
std::io::ErrorKind::InvalidInput,
"Invalid seek to a negative or overflowing position",
)),
}
}

Expand Down
36 changes: 21 additions & 15 deletions hermes/bin/src/runtime_extensions/hermes/cron/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ impl Sub for CronDuration {
type Output = Self;

fn sub(self, rhs: Self) -> Self::Output {
Self(self.0 - rhs.0)
Self(self.0.saturating_sub(rhs.0))
}
}

Expand Down Expand Up @@ -241,22 +241,28 @@ mod tests {
// every monday and the first day of January
let cron: Cron = "0 0 1 1 7".parse().unwrap();
let times: Vec<DateTime<Utc>> = cron.clone().iter_from(datetime).take(5).collect();
assert_eq!(times, vec![
Utc.with_ymd_and_hms(1970, 1, 1, 0, 0, 0).unwrap(),
Utc.with_ymd_and_hms(1970, 1, 3, 0, 0, 0).unwrap(),
Utc.with_ymd_and_hms(1970, 1, 10, 0, 0, 0).unwrap(),
Utc.with_ymd_and_hms(1970, 1, 17, 0, 0, 0).unwrap(),
Utc.with_ymd_and_hms(1970, 1, 24, 0, 0, 0).unwrap(),
]);
assert_eq!(
times,
vec![
Utc.with_ymd_and_hms(1970, 1, 1, 0, 0, 0).unwrap(),
Utc.with_ymd_and_hms(1970, 1, 3, 0, 0, 0).unwrap(),
Utc.with_ymd_and_hms(1970, 1, 10, 0, 0, 0).unwrap(),
Utc.with_ymd_and_hms(1970, 1, 17, 0, 0, 0).unwrap(),
Utc.with_ymd_and_hms(1970, 1, 24, 0, 0, 0).unwrap(),
]
);

let cron: Cron = "0 0 1 1,3,5,7,9,11 *".parse().unwrap();
let times: Vec<DateTime<Utc>> = cron.clone().iter_from(datetime).take(5).collect();
assert_eq!(times, vec![
Utc.with_ymd_and_hms(1970, 1, 1, 0, 0, 0).unwrap(),
Utc.with_ymd_and_hms(1970, 3, 1, 0, 0, 0).unwrap(),
Utc.with_ymd_and_hms(1970, 5, 1, 0, 0, 0).unwrap(),
Utc.with_ymd_and_hms(1970, 7, 1, 0, 0, 0).unwrap(),
Utc.with_ymd_and_hms(1970, 9, 1, 0, 0, 0).unwrap(),
]);
assert_eq!(
times,
vec![
Utc.with_ymd_and_hms(1970, 1, 1, 0, 0, 0).unwrap(),
Utc.with_ymd_and_hms(1970, 3, 1, 0, 0, 0).unwrap(),
Utc.with_ymd_and_hms(1970, 5, 1, 0, 0, 0).unwrap(),
Utc.with_ymd_and_hms(1970, 7, 1, 0, 0, 0).unwrap(),
Utc.with_ymd_and_hms(1970, 9, 1, 0, 0, 0).unwrap(),
]
);
}
}
84 changes: 36 additions & 48 deletions hermes/bin/src/runtime_extensions/hermes/cron/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ pub(crate) fn mkdelay_crontab(
duration: Instant, tag: CronEventTag,
) -> wasmtime::Result<CronJobDelay> {
// Add the delay to the current time.
let delayed = Utc::now() + TimeDelta::nanoseconds(duration.try_into()?);
let delayed = Utc::now()
.checked_add_signed(TimeDelta::nanoseconds(duration.try_into()?))
.ok_or(Error::InvalidTimestamp)?;
let timestamp = delayed
.timestamp_nanos_opt()
.ok_or(Error::InvalidTimestamp)?
Expand Down Expand Up @@ -238,26 +240,22 @@ impl CronComponent {
fn merge(self, other: CronComponent) -> Option<Self> {
match self {
Self::All => Some(self),
Self::At(when) => {
match other {
Self::All => Some(Self::All),
Self::At(w) if w == when => Some(self),
Self::Range((a, b)) if (a..=b).contains(&when) => Some(other),
_ => None,
}
Self::At(when) => match other {
Self::All => Some(Self::All),
Self::At(w) if w == when => Some(self),
Self::Range((a, b)) if (a..=b).contains(&when) => Some(other),
_ => None,
},
Self::Range((first, last)) => {
match other {
Self::All => Some(Self::All),
Self::At(w) if (first..=last).contains(&w) => Some(self),
Self::Range((a, b))
if ((first..=last).contains(&a) || (first..=last).contains(&b))
|| ((a..=b).contains(&first) || (a..=b).contains(&last)) =>
{
Some(Self::Range((min(first, a), max(last, b))))
},
_ => None,
}
Self::Range((first, last)) => match other {
Self::All => Some(Self::All),
Self::At(w) if (first..=last).contains(&w) => Some(self),
Self::Range((a, b))
if ((first..=last).contains(&a) || (first..=last).contains(&b))
|| ((a..=b).contains(&first) || (a..=b).contains(&last)) =>
{
Some(Self::Range((min(first, a), max(last, b))))
},
_ => None,
},
}
}
Expand All @@ -277,19 +275,15 @@ impl PartialEq for CronComponent {
fn eq(&self, other: &Self) -> bool {
match self {
Self::All => matches!(other, Self::All),
Self::At(when) => {
match other {
Self::At(w) if w == when => true,
Self::Range((a, b)) if (a..=b).contains(&when) => true,
_ => false,
}
Self::At(when) => match other {
Self::At(w) if w == when => true,
Self::Range((a, b)) if (a..=b).contains(&when) => true,
_ => false,
},
Self::Range((first, last)) => {
match other {
Self::At(w) if first == w && last == w => true,
Self::Range((a, b)) if first == a && last == b => true,
_ => false,
}
Self::Range((first, last)) => match other {
Self::At(w) if first == w && last == w => true,
Self::Range((a, b)) if first == a && last == b => true,
_ => false,
},
}
}
Expand All @@ -312,24 +306,18 @@ impl Eq for CronComponent {}
impl Ord for CronComponent {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
match self {
Self::All => {
match other {
Self::All => std::cmp::Ordering::Equal,
_ => std::cmp::Ordering::Greater,
}
Self::All => match other {
Self::All => std::cmp::Ordering::Equal,
_ => std::cmp::Ordering::Greater,
},
Self::At(when) => {
match other {
Self::At(w) => when.cmp(w),
_ => std::cmp::Ordering::Less,
}
Self::At(when) => match other {
Self::At(w) => when.cmp(w),
_ => std::cmp::Ordering::Less,
},
Self::Range((first, last)) => {
match other {
Self::All => std::cmp::Ordering::Less,
Self::At(_) => std::cmp::Ordering::Greater,
Self::Range((start, end)) => first.cmp(start).then(last.cmp(end)),
}
Self::Range((first, last)) => match other {
Self::All => std::cmp::Ordering::Less,
Self::At(_) => std::cmp::Ordering::Greater,
Self::Range((start, end)) => first.cmp(start).then(last.cmp(end)),
},
}
}
Expand Down
18 changes: 10 additions & 8 deletions hermes/bin/src/runtime_extensions/hermes/cron/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ impl CronEventQueue {
} else {
// If the timestamp is in the future,
// update the waiting task.
#[allow(clippy::arithmetic_side_effects)]
let sleep_duration = ts - trigger_time;
self.update_waiting_task(ts, sleep_duration);
// Since `ts` is in the future, we can break
Expand Down Expand Up @@ -202,6 +203,7 @@ impl CronEventQueue {
if !on_cron_event.last {
// Re-schedule the event by calculating the next timestamp after now.
if let Some(next_timestamp) = on_cron_event.tick_after(None) {
#[allow(clippy::arithmetic_side_effects)]
let duration = next_timestamp - trigger_time;
cron_queue_delay(app_name, duration.into(), on_cron_event.tag.tag)?;
}
Expand Down Expand Up @@ -507,10 +509,10 @@ mod tests {
// sets the waiting_event
assert!(!queue.waiting_event.is_empty());
// lists the event in the app queue
assert_eq!(queue.ls_events(&hermes_app_name, &None), vec![(
cron_entry_1().tag,
IS_LAST
)]);
assert_eq!(
queue.ls_events(&hermes_app_name, &None),
vec![(cron_entry_1().tag, IS_LAST)]
);
}

#[test]
Expand All @@ -530,10 +532,10 @@ mod tests {
// which communicates with the static `CRON_INTERNAL_STATE`.
assert!(queue.trigger().is_ok());
assert!(!queue.waiting_event.is_empty());
assert_eq!(queue.ls_events(&hermes_app_name, &None), vec![(
cron_entry_2().tag,
IS_NOT_LAST
),]);
assert_eq!(
queue.ls_events(&hermes_app_name, &None),
vec![(cron_entry_2().tag, IS_NOT_LAST),]
);
// wait for the waiting task to finish
sleep(std::time::Duration::from_millis(500));
// Trigger manually
Expand Down
23 changes: 11 additions & 12 deletions hermes/bin/src/runtime_extensions/hermes/crypto/bip39.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ fn get_prefix_index_bits(prefix_list: Vec<String>, language: Language) -> Result
/// Note that if entropy bits is needed, multiply the `total_entropy_bytes` by 8.
fn generate_entropy(word_count: usize) -> Result<Vec<u8>, Errno> {
// Number of bytes entropy calculate from mnemonic word.
let total_entropy_bytes = word_count * 4 / 3;
let total_entropy_bytes = word_count.saturating_mul(4) / 3;
// Maximum length of mnemonic is 24 words which is 32 bytes entropy.
let mut total_entropy_bytes_max = [0u8; 32];
// Random number
Expand Down Expand Up @@ -211,7 +211,7 @@ fn get_check_sum_bits(entropy_bits: &[u8], word_count: usize) -> Vec<u8> {
// Retrieve the first `checksum_len` checksum bits from the hash result.
let mut checksum_bits = Vec::new();
for i in 0..checksum_len {
checksum_bits.push(hash_result[0] >> (7 - i) & 1);
checksum_bits.push(hash_result[0] >> (7usize.saturating_sub(i)) & 1);
}
checksum_bits
}
Expand All @@ -223,11 +223,11 @@ fn get_word_indices(entropy_bits: &[u8], word_count: usize) -> Vec<u16> {
// Separate entropy bits into 11 bits and convert to decimal.
// This decimal will be used to get the word index.
for i in 0..word_count {
let mut idx = 0;
let mut idx = 0u16;
for j in 0..11 {
if let Some(value) = entropy_bits.get(i * 11 + j) {
if let Some(value) = entropy_bits.get(i.saturating_mul(11).saturating_add(j)) {
if *value > 0 {
idx += 1 << (10 - j);
idx = idx.saturating_add(1 << (10usize.saturating_sub(j)));
}
}
}
Expand Down Expand Up @@ -257,7 +257,7 @@ fn decimal_to_binary_array(decimal: u16) -> [u8; 11] {
while n > 0 {
if let Some(value) = binary.get_mut(index) {
let bit = n % 2;
index += 1;
index = index.saturating_add(1);
*value = bit as u8;
n /= 2;
}
Expand All @@ -268,7 +268,7 @@ fn decimal_to_binary_array(decimal: u16) -> [u8; 11] {
if let Some(value) = binary.get_mut(index) {
*value = 0;
}
index += 1;
index = index.saturating_add(1);
}
binary.reverse();
binary
Expand All @@ -278,10 +278,9 @@ fn decimal_to_binary_array(decimal: u16) -> [u8; 11] {
fn bits_to_bytes(bits: &[u8]) -> Vec<u8> {
bits.chunks(8)
.map(|chunk| {
chunk
.iter()
.enumerate()
.fold(0, |acc, (i, &bit)| acc | ((bit) << (7 - i)))
chunk.iter().enumerate().fold(0, |acc, (i, &bit)| {
acc | ((bit) << (7usize.saturating_sub(i)))
})
})
.collect()
}
Expand All @@ -308,7 +307,7 @@ fn byte_to_bit(entropy: Vec<u8>, entropy_bits: &mut Vec<u8>, word_count: usize)
for j in (0..8).rev() {
// Should not exceed the word_count / 3 * 32
// which is number of entropy bits for the mnemonic word count.
if entropy_bits.len() >= word_count / 3 * 32 {
if entropy_bits.len() >= word_count.saturating_div(3).saturating_mul(32) {
break;
}
entropy_bits.push((byte >> j) & 1);
Expand Down
2 changes: 2 additions & 0 deletions hermes/clippy.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
allow-unwrap-in-tests = true
allow-expect-in-tests = true
allow-panic-in-tests = true
arithmetic-side-effects-allowed = ["num_bigint::BigInt"]
2 changes: 1 addition & 1 deletion hermes/crates/cbork/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.1.24 AS rust-ci
IMPORT github.com/input-output-hk/catalyst-ci/earthly/rust:v3.2.28 AS rust-ci
# Use when debugging cat-ci locally.
# IMPORT ../../catalyst-ci/earthly/rust AS rust-ci

Expand Down
2 changes: 1 addition & 1 deletion wasm/integration-test/cardano/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.03 AS rust-ci
IMPORT github.com/input-output-hk/catalyst-ci/earthly/rust:v3.2.28 AS rust-ci
# Use when debugging cat-ci locally.
# IMPORT ../../catalyst-ci/earthly/rust AS rust-ci

Expand Down
2 changes: 1 addition & 1 deletion wasm/integration-test/http_reply/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.03 AS rust-ci
IMPORT github.com/input-output-hk/catalyst-ci/earthly/rust:v3.2.28 AS rust-ci
# Use when debugging cat-ci locally.
# IMPORT ../../catalyst-ci/earthly/rust AS rust-ci

Expand Down
2 changes: 1 addition & 1 deletion wasm/integration-test/ipfs/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.03 AS rust-ci
IMPORT github.com/input-output-hk/catalyst-ci/earthly/rust:v3.2.28 AS rust-ci
# Use when debugging cat-ci locally.
# IMPORT ../../catalyst-ci/earthly/rust AS rust-ci

Expand Down
2 changes: 1 addition & 1 deletion wasm/integration-test/sqlite/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.03 AS rust-ci
IMPORT github.com/input-output-hk/catalyst-ci/earthly/rust:v3.2.28 AS rust-ci
# Use when debugging cat-ci locally.
# IMPORT ../../catalyst-ci/earthly/rust AS rust-ci

Expand Down
2 changes: 1 addition & 1 deletion wasm/integration-test/wasi-filesystem/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.03 AS rust-ci
IMPORT github.com/input-output-hk/catalyst-ci/earthly/rust:v3.2.28 AS rust-ci
# Use when debugging cat-ci locally.
# IMPORT ../../catalyst-ci/earthly/rust AS rust-ci

Expand Down
1 change: 1 addition & 0 deletions wasm/wasi-hermes-component-adapter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ string_slice = "deny"
unchecked_duration_subtraction = "deny"
unreachable = "deny"
missing_docs_in_private_items = "deny"
arithmetic_side_effects = "deny"

[workspace.dependencies]
wit-bindgen = { version = "0.19.2", default-features = false } # Anything after 0.19.2 does not work. Do not bump version.
Expand Down
Loading
Loading