Skip to content

Commit

Permalink
chore: use anyhow::Result instead of Box<dyn Error>
Browse files Browse the repository at this point in the history
  • Loading branch information
dartdart26 committed Aug 30, 2024
1 parent 85371aa commit 508dc47
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 21 deletions.
4 changes: 2 additions & 2 deletions fhevm-engine/executor/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::error::Error;
use anyhow::Result;

mod cli;
mod server;

fn main() -> Result<(), Box<dyn Error>> {
fn main() -> Result<()> {
let args = cli::parse_args();
server::start(&args)?;
Ok(())
Expand Down
11 changes: 6 additions & 5 deletions fhevm-engine/executor/src/server.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::{cell::Cell, collections::HashMap, error::Error, sync::Arc};
use std::{cell::Cell, collections::HashMap, sync::Arc};

use anyhow::Result;
use common::FheOperation;
use executor::{
fhevm_executor_server::{FhevmExecutor, FhevmExecutorServer},
Expand All @@ -26,7 +27,7 @@ pub mod executor {
tonic::include_proto!("fhevm.executor");
}

pub fn start(args: &crate::cli::Args) -> Result<(), Box<dyn Error>> {
pub fn start(args: &crate::cli::Args) -> Result<()> {
let runtime = tokio::runtime::Builder::new_multi_thread()
.worker_threads(args.tokio_threads)
.max_blocking_threads(args.fhe_compute_threads)
Expand All @@ -41,7 +42,7 @@ pub fn start(args: &crate::cli::Args) -> Result<(), Box<dyn Error>> {
.add_service(FhevmExecutorServer::new(executor))
.serve(addr)
.await?;
Ok::<(), Box<dyn Error>>(())
Ok::<(), anyhow::Error>(())
})?;
Ok(())
}
Expand Down Expand Up @@ -184,7 +185,7 @@ impl FhevmExecutorService {
fn decompress_compressed_ciphertexts(
cts: &Vec<CompressedCiphertext>,
state: &mut ComputationState,
) -> Result<(), Box<dyn Error>> {
) -> Result<()> {
for ct in cts.iter() {
let ct_type = get_ct_type(&ct.handle)?;
let supported_ct = SupportedFheCiphertexts::decompress(ct_type, &ct.serialization)?;
Expand Down Expand Up @@ -234,7 +235,7 @@ impl FhevmExecutorService {
state: &mut ComputationState,
) -> Result<Vec<CompressedCiphertext>, SyncComputeError> {
// Collect computation inputs.
let inputs: Result<Vec<SupportedFheCiphertexts>, Box<dyn Error>> = comp
let inputs: Result<Vec<SupportedFheCiphertexts>> = comp
.inputs
.iter()
.map(|sync_input| match &sync_input.input {
Expand Down
22 changes: 8 additions & 14 deletions fhevm-engine/fhevm-engine-common/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::error::Error;

use anyhow::Result;
use tfhe::integer::U256;
use tfhe::prelude::FheDecrypt;
use tfhe::{CompressedCiphertextList, CompressedCiphertextListBuilder};
Expand Down Expand Up @@ -314,30 +313,25 @@ impl SupportedFheCiphertexts {
bincode::serialize(&list).expect("compressed list serialization")
}

pub fn decompress(ct_type: i16, list: &[u8]) -> Result<Self, Box<dyn Error>> {
pub fn decompress(ct_type: i16, list: &[u8]) -> Result<Self> {
let list: CompressedCiphertextList = bincode::deserialize(list)?;
match ct_type {
1 => Ok(SupportedFheCiphertexts::FheBool(
list.get(0)?
.ok_or(Box::new(FhevmError::MissingTfheRsData))?,
list.get(0)?.ok_or(FhevmError::MissingTfheRsData)?,
)),
2 => Ok(SupportedFheCiphertexts::FheUint8(
list.get(0)?
.ok_or(Box::new(FhevmError::MissingTfheRsData))?,
list.get(0)?.ok_or(FhevmError::MissingTfheRsData)?,
)),
3 => Ok(SupportedFheCiphertexts::FheUint16(
list.get(0)?
.ok_or(Box::new(FhevmError::MissingTfheRsData))?,
list.get(0)?.ok_or(FhevmError::MissingTfheRsData)?,
)),
4 => Ok(SupportedFheCiphertexts::FheUint32(
list.get(0)?
.ok_or(Box::new(FhevmError::MissingTfheRsData))?,
list.get(0)?.ok_or(FhevmError::MissingTfheRsData)?,
)),
5 => Ok(SupportedFheCiphertexts::FheUint64(
list.get(0)?
.ok_or(Box::new(FhevmError::MissingTfheRsData))?,
list.get(0)?.ok_or(FhevmError::MissingTfheRsData)?,
)),
_ => Err(Box::new(FhevmError::UnknownFheType(ct_type as i32))),
_ => Err(FhevmError::UnknownFheType(ct_type as i32).into()),
}
}
}
Expand Down

0 comments on commit 508dc47

Please sign in to comment.