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: replace usize with u32 #699

Merged
merged 1 commit into from
Sep 21, 2022
Merged
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
16 changes: 10 additions & 6 deletions runtime/src/util/batch_return.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ use fvm_shared::error::ExitCode;

#[derive(Serialize_tuple, Deserialize_tuple, Clone, Debug, PartialEq, Eq)]
pub struct FailCode {
pub idx: usize,
pub idx: u32,
pub code: ExitCode,
}

#[derive(Serialize_tuple, Deserialize_tuple, Clone, PartialEq, Eq, Debug)]
pub struct BatchReturn {
// Total successes in batch
pub success_count: usize,
pub success_count: u32,
// Failure code and index for each failure in batch
pub fail_codes: Vec<FailCode>,
}
Expand All @@ -21,12 +21,12 @@ impl BatchReturn {
let mut ret = Vec::new();

for fail in &self.fail_codes {
for _ in ret.len()..fail.idx {
for _ in ret.len()..fail.idx as usize {
ret.push(ExitCode::OK)
}
ret.push(fail.code)
}
let batch_size = self.success_count + self.fail_codes.len();
let batch_size = self.success_count as usize + self.fail_codes.len();
for _ in ret.len()..batch_size {
ret.push(ExitCode::OK)
}
Expand Down Expand Up @@ -55,12 +55,16 @@ impl BatchReturnGen {
}

pub fn add_fail(&mut self, code: ExitCode) -> &mut Self {
self.fail_codes.push(FailCode { idx: self.success_count + self.fail_codes.len(), code });
self.fail_codes
.push(FailCode { idx: (self.success_count + self.fail_codes.len()) as u32, code });
self
}

pub fn gen(&self) -> BatchReturn {
assert_eq!(self.expect_count, self.success_count + self.fail_codes.len(), "programmer error, mismatched batch size {} and processed count {} batch return must include success/fail for all inputs", self.expect_count, self.success_count + self.fail_codes.len());
BatchReturn { success_count: self.success_count, fail_codes: self.fail_codes.clone() }
BatchReturn {
success_count: self.success_count as u32,
fail_codes: self.fail_codes.clone(),
}
}
}