Skip to content

Commit

Permalink
Map view error to appropriate status; don't retry if NotFound/Already…
Browse files Browse the repository at this point in the history
  • Loading branch information
afck authored Dec 17, 2024
1 parent 95d7316 commit 7afdc08
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 12 deletions.
8 changes: 3 additions & 5 deletions linera-rpc/src/grpc/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,13 @@ impl GrpcClient {
info!("gRPC request interrupted: {}; retrying", status);
true
}
Code::Ok
| Code::Cancelled
| Code::NotFound
| Code::AlreadyExists
| Code::ResourceExhausted => {
Code::Ok | Code::Cancelled | Code::ResourceExhausted => {
error!("Unexpected gRPC status: {}; retrying", status);
true
}
Code::InvalidArgument
| Code::NotFound
| Code::AlreadyExists
| Code::PermissionDenied
| Code::FailedPrecondition
| Code::OutOfRange
Expand Down
3 changes: 1 addition & 2 deletions linera-service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ benchmark = [
"linera-base/test",
"linera-client/benchmark",
"linera-chain/benchmark",
"dep:linera-sdk",
]
wasmer = ["linera-client/wasmer", "linera-execution/wasmer", "linera-storage/wasmer"]
wasmtime = [
Expand Down Expand Up @@ -90,7 +89,7 @@ linera-client = { workspace = true, features = ["fs"] }
linera-core.workspace = true
linera-execution = { workspace = true, features = ["fs"] }
linera-rpc = { workspace = true, features = ["server", "simple-network"] }
linera-sdk = { workspace = true, optional = true }
linera-sdk = { workspace = true }
linera-storage.workspace = true
linera-storage-service = { workspace = true, optional = true }
linera-version.workspace = true
Expand Down
35 changes: 30 additions & 5 deletions linera-service/src/proxy/grpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ use linera_rpc::{
GRPC_MAX_MESSAGE_SIZE,
},
};
use linera_sdk::views::ViewError;
use linera_storage::Storage;
use prost::Message;
use tokio::{select, task::JoinSet};
Expand Down Expand Up @@ -332,6 +333,30 @@ where
}
}
}

/// Returns the appropriate gRPC status for the given [`ViewError`].
fn error_to_status(err: ViewError) -> Status {
let mut status = match &err {
ViewError::TooLargeValue | ViewError::BcsError(_) => {
Status::invalid_argument(err.to_string())
}
ViewError::StoreError { .. }
| ViewError::TokioJoinError(_)
| ViewError::TryLockError(_)
| ViewError::InconsistentEntries
| ViewError::PostLoadValuesError
| ViewError::IoError(_) => Status::internal(err.to_string()),
ViewError::KeyTooLong | ViewError::ArithmeticError(_) => {
Status::out_of_range(err.to_string())
}
ViewError::NotFound(_)
| ViewError::BlobsNotFound(_)
| ViewError::CannotAcquireCollectionEntry
| ViewError::MissingEntries => Status::not_found(err.to_string()),
};
status.set_source(Arc::new(err));
status
}
}

#[async_trait]
Expand Down Expand Up @@ -461,7 +486,7 @@ where
.storage
.read_blob(blob_id)
.await
.map_err(|err| Status::from_error(Box::new(err)))?;
.map_err(Self::error_to_status)?;
Ok(Response::new(blob.into_inner_content().try_into()?))
}

Expand All @@ -476,7 +501,7 @@ where
.storage
.read_certificate(hash)
.await
.map_err(|err| Status::from_error(Box::new(err)))?
.map_err(Self::error_to_status)?
.into();
Ok(Response::new(certificate.try_into()?))
}
Expand Down Expand Up @@ -506,7 +531,7 @@ where
.storage
.read_certificates(batch.to_vec())
.await
.map_err(|err| Status::from_error(Box::new(err)))?
.map_err(Self::error_to_status)?
{
if grpc_message_limiter.fits::<Certificate>(certificate.clone().into())? {
certificates.push(linera_chain::types::Certificate::from(certificate));
Expand All @@ -532,7 +557,7 @@ where
.storage
.read_blob_state(blob_id)
.await
.map_err(|err| Status::from_error(Box::new(err)))?;
.map_err(Self::error_to_status)?;
Ok(Response::new(blob_state.last_used_by.into()))
}

Expand All @@ -547,7 +572,7 @@ where
.storage
.missing_blobs(&blob_ids)
.await
.map_err(|err| Status::from_error(Box::new(err)))?;
.map_err(Self::error_to_status)?;
Ok(Response::new(missing_blob_ids.try_into()?))
}
}
Expand Down

0 comments on commit 7afdc08

Please sign in to comment.