fix(validator-node): return error if contract_id empty for publish_contract_acceptance grpc
Description
Returns invalid argument if contract id is not provided
Log error if publishing fails
Motivation and Context
If contract_id was not provided, a zero hash would be used and published.
How Has This Been Tested?
Manually
@@ -37,7 +37,7 @@ use tari_dan_core::{
use tokio::{task, time};
use tonic::{Request, Response, Status};
-const _LOG_TARGET: &str = "tari::validator_node::grpc";
+const LOG_TARGET: &str = "tari::validator_node::grpc";
pub struct ValidatorNodeGrpcServer<TServiceSpecification: ServiceSpecification> {
node_identity: NodeIdentity,
@@ -77,7 +77,8 @@ impl<TServiceSpecification: ServiceSpecification + 'static> rpc::validator_node_
) -> Result<Response<rpc::PublishContractAcceptanceResponse>, tonic::Status> {
let mut wallet_client = self.wallet_client.clone();
let request = request.into_inner();
- let contract_id = FixedHash::try_from(request.contract_id).unwrap_or_default();
+ let contract_id =
+ FixedHash::try_from(request.contract_id).map_err(|err| tonic::Status::invalid_argument(err.to_string()))?;
let validator_node_public_key = self.node_identity.public_key();
let signature = Signature::default();
@@ -89,10 +90,13 @@ impl<TServiceSpecification: ServiceSpecification + 'static> rpc::validator_node_
tx_id,
status: "Accepted".to_string(),
})),
- Err(_) => Ok(Response::new(rpc::PublishContractAcceptanceResponse {
+ Err(err) => {
+ log::error!(target: LOG_TARGET, "publish_contract_acceptance: {}", err);
+ Ok(Response::new(rpc::PublishContractAcceptanceResponse {
status: "Errored".to_string(),
tx_id: 0_u64,
- })),
+ }))
+ },
}
}
