Skip to content

Commit

Permalink
authority-client: properly convert tonic::Status to SuiError
Browse files Browse the repository at this point in the history
  • Loading branch information
bmwill committed May 3, 2022
1 parent cdddf1f commit 9c689eb
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 42 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 7 additions & 38 deletions sui_core/src/authority_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,7 @@ impl AuthorityAPI for NetworkAuthorityClient {
transaction: Transaction,
) -> Result<TransactionInfoResponse, SuiError> {
let request = BincodeEncodedPayload::try_from(&transaction).unwrap();
let response = self
.client()
.transaction(request)
.await
.map_err(|_| SuiError::UnexpectedMessage)?
.into_inner();
let response = self.client().transaction(request).await?.into_inner();

response
.deserialize()
Expand All @@ -134,8 +129,7 @@ impl AuthorityAPI for NetworkAuthorityClient {
let response = self
.client()
.confirmation_transaction(request)
.await
.map_err(|_| SuiError::UnexpectedMessage)?
.await?
.into_inner();

response
Expand All @@ -151,10 +145,7 @@ impl AuthorityAPI for NetworkAuthorityClient {
let response = self
.client()
.consensus_transaction(request)
.await
.map_err(|e| SuiError::GenericAuthorityError {
error: e.to_string(),
})?
.await?
.into_inner();

response
Expand All @@ -169,12 +160,7 @@ impl AuthorityAPI for NetworkAuthorityClient {
request: AccountInfoRequest,
) -> Result<AccountInfoResponse, SuiError> {
let request = BincodeEncodedPayload::try_from(&request).unwrap();
let response = self
.client()
.account_info(request)
.await
.map_err(|_| SuiError::UnexpectedMessage)?
.into_inner();
let response = self.client().account_info(request).await?.into_inner();

response
.deserialize()
Expand All @@ -186,12 +172,7 @@ impl AuthorityAPI for NetworkAuthorityClient {
request: ObjectInfoRequest,
) -> Result<ObjectInfoResponse, SuiError> {
let request = BincodeEncodedPayload::try_from(&request).unwrap();
let response = self
.client()
.object_info(request)
.await
.map_err(|_| SuiError::UnexpectedMessage)?
.into_inner();
let response = self.client().object_info(request).await?.into_inner();

response
.deserialize()
Expand All @@ -204,12 +185,7 @@ impl AuthorityAPI for NetworkAuthorityClient {
request: TransactionInfoRequest,
) -> Result<TransactionInfoResponse, SuiError> {
let request = BincodeEncodedPayload::try_from(&request).unwrap();
let response = self
.client()
.transaction_info(request)
.await
.map_err(|_| SuiError::UnexpectedMessage)?
.into_inner();
let response = self.client().transaction_info(request).await?.into_inner();

response
.deserialize()
Expand All @@ -222,14 +198,7 @@ impl AuthorityAPI for NetworkAuthorityClient {
request: BatchInfoRequest,
) -> Result<BatchInfoResponseItemStream, SuiError> {
let request = BincodeEncodedPayload::try_from(&request).unwrap();
let response_stream = self
.client()
.batch_info(request)
.await
.map_err(|e| SuiError::GenericAuthorityError {
error: format!("Batch error: {}", e),
})?
.into_inner();
let response_stream = self.client().batch_info(request).await?.into_inner();

let stream = response_stream
.map_err(|_| SuiError::UnexpectedMessage)
Expand Down
3 changes: 3 additions & 0 deletions sui_core/tests/staged/sui.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,9 @@ SuiError:
101:
SignatureKeyGenError:
NEWTYPE: STR
102:
RpcError:
NEWTYPE: STR
TransactionData:
STRUCT:
- kind:
Expand Down
1 change: 1 addition & 0 deletions sui_types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ zeroize = "1.5.4"
hkdf = "0.12.3"
digest = "0.10.3"
schemars ="0.8.8"
tonic = "0.7"

name_variant = { git = "https://github.com/MystenLabs/mysten-infra", rev = "97a056f85555fa2afe497d6abb7cf6bf8faa63cf" }
typed-store = { git = "https://github.com/MystenLabs/mysten-infra", rev = "d2976a45420147ad821baae96e6fe4b12215f743" }
Expand Down
17 changes: 13 additions & 4 deletions sui_types/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

use crate::base_types::*;
use crate::committee::EpochId;
use crate::{base_types::*, committee::EpochId};
use move_binary_format::errors::{PartialVMError, VMError};
use narwhal_executor::ExecutionStateError;
use narwhal_executor::SubscriberError;
use narwhal_executor::{ExecutionStateError, SubscriberError};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use std::fmt::Debug;
Expand Down Expand Up @@ -316,6 +314,11 @@ pub enum SuiError {
HkdfError(String),
#[error("Signature key generation error: {0}")]
SignatureKeyGenError(String),

// These are errors that occur when an RPC fails and is simply the utf8 message sent in a
// Tonic::Status
#[error("{0}")]
RpcError(String),
}

pub type SuiResult<T = ()> = Result<T, SuiError>;
Expand Down Expand Up @@ -343,6 +346,12 @@ impl std::convert::From<SubscriberError> for SuiError {
}
}

impl From<tonic::Status> for SuiError {
fn from(status: tonic::Status) -> Self {
Self::RpcError(status.message().to_owned())
}
}

impl ExecutionStateError for SuiError {
fn node_error(&self) -> bool {
matches!(
Expand Down

0 comments on commit 9c689eb

Please sign in to comment.