Skip to content

Commit

Permalink
bugfix: mobilecoind should return a grpc NOT_FOUND error code when le…
Browse files Browse the repository at this point in the history
…dger data is not found (#3787)

* return NOT_FOUND grpc error code instead of INVALID_ARG/INTERNAL_ERROR when a ledger record wasnt found
  • Loading branch information
eranrund authored Dec 11, 2023
1 parent b6c98c9 commit a6ae003
Showing 1 changed file with 28 additions and 9 deletions.
37 changes: 28 additions & 9 deletions mobilecoind/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -591,12 +591,15 @@ impl<T: BlockchainConnection + UserTxConnection + 'static, FPR: FogPubkeyResolve
let index = self
.ledger_db
.get_tx_out_index_by_public_key(&compressed_tx_public_key)
.map_err(|err| {
rpc_internal_error(
.map_err(|err| match err {
LedgerError::NotFound => {
RpcStatus::with_message(RpcStatusCode::NOT_FOUND, "tx_out not found".into())
}
_ => rpc_internal_error(
"ledger_db.get_tx_out_index_by_public_key",
err,
&self.logger,
)
),
})?;

let tx_out = self.ledger_db.get_tx_out_by_index(index).map_err(|err| {
Expand Down Expand Up @@ -793,9 +796,19 @@ impl<T: BlockchainConnection + UserTxConnection + 'static, FPR: FogPubkeyResolve

let excluded_indexes = excluded
.iter()
.map(|tx_out| self.ledger_db.get_tx_out_index_by_hash(&tx_out.hash()))
.collect::<Result<Vec<u64>, LedgerError>>()
.map_err(|e| rpc_internal_error("ledger_error", e, &self.logger))?; // TODO better error handling
.enumerate()
.map(|(idx, tx_out)| {
self.ledger_db
.get_tx_out_index_by_hash(&tx_out.hash())
.map_err(|err| match err {
LedgerError::NotFound => RpcStatus::with_message(
RpcStatusCode::NOT_FOUND,
format!("tx_out {idx} not found"),
),
_ => rpc_internal_error("get_tx_out_index_by_hash", err, &self.logger),
})
})
.collect::<Result<Vec<u64>, RpcStatus>>()?;

let mixins_with_proofs: Vec<(TxOut, TxOutMembershipProof)> = self
.transactions_manager
Expand Down Expand Up @@ -830,9 +843,15 @@ impl<T: BlockchainConnection + UserTxConnection + 'static, FPR: FogPubkeyResolve
.get_indices()
.iter()
.map(|idx| {
self.ledger_db.get_tx_out_by_index(*idx).map_err(|err| {
rpc_invalid_arg_error("get_tx_out_by_index", err, &self.logger)
})
self.ledger_db
.get_tx_out_by_index(*idx)
.map_err(|err| match err {
LedgerError::NotFound => RpcStatus::with_message(
RpcStatusCode::NOT_FOUND,
format!("tx_out {idx} not found"),
),
_ => rpc_invalid_arg_error("get_tx_out_by_index", err, &self.logger),
})
})
.collect::<Result<Vec<TxOut>, RpcStatus>>()?,

Expand Down

0 comments on commit a6ae003

Please sign in to comment.