diff --git a/Cargo.lock b/Cargo.lock index 22cd64f4f9..4911ca8901 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3253,6 +3253,7 @@ name = "kaspa-rpc-service" version = "0.14.1" dependencies = [ "async-trait", + "itertools 0.11.0", "kaspa-addresses", "kaspa-consensus-core", "kaspa-consensus-notify", diff --git a/rpc/service/Cargo.toml b/rpc/service/Cargo.toml index d606d51533..592178b66a 100644 --- a/rpc/service/Cargo.toml +++ b/rpc/service/Cargo.toml @@ -33,4 +33,5 @@ async-trait.workspace = true log.workspace = true tokio.workspace = true triggered.workspace = true +itertools.workspace = true workflow-rpc.workspace = true diff --git a/rpc/service/src/service.rs b/rpc/service/src/service.rs index 7ad4b1657d..a9d428c468 100644 --- a/rpc/service/src/service.rs +++ b/rpc/service/src/service.rs @@ -4,6 +4,7 @@ use super::collector::{CollectorFromConsensus, CollectorFromIndex}; use crate::converter::{consensus::ConsensusConverter, index::IndexConverter, protocol::ProtocolConverter}; use crate::service::NetworkType::{Mainnet, Testnet}; use async_trait::async_trait; +use itertools::Itertools; use kaspa_consensus_core::api::counters::ProcessingCounters; use kaspa_consensus_core::errors::block::RuleError; use kaspa_consensus_core::{ @@ -64,6 +65,7 @@ use kaspa_txscript::{extract_script_pub_key_address, pay_to_address_script}; use kaspa_utils::{channel::Channel, triggers::SingleTrigger}; use kaspa_utils_tower::counters::TowerConnectionCounters; use kaspa_utxoindex::api::UtxoIndexProxy; +use std::iter; use std::{ collections::HashMap, iter::once, @@ -495,24 +497,24 @@ NOTE: This error usually indicates an RPC conversion error between the node and let transaction_id = transaction.id(); let inputs = &transaction.inputs; - let empty_indices = inputs - .iter() - .enumerate() - .filter_map(|(index, input)| (input.signature_script.is_empty()).then_some(index.to_string())) - .collect::>(); - if !empty_indices.is_empty() { - Err(RpcError::EmptySignatureScript(transaction_id, empty_indices.join(", "))) + let mut empty_indices = + inputs.iter().enumerate().filter_map(|(index, input)| (input.signature_script.is_empty()).then_some(index.to_string())); + let first_empty = empty_indices.next(); + if let Some(first_empty) = first_empty { + Err(RpcError::EmptySignatureScript(transaction_id, iter::once(first_empty).chain(empty_indices).join(", "))) } else { let session = self.consensus_manager.consensus().unguarded_session(); let orphan = match allow_orphan { true => Orphan::Allowed, false => Orphan::Forbidden, }; - self.flow_context.submit_rpc_transaction(&session, transaction, orphan).await.map_err(|err| { - let err = RpcError::RejectedTransaction(transaction_id, err.to_string()); - debug!("{err}"); - err - })?; + self.flow_context + .submit_rpc_transaction(&session, transaction, orphan) + .await + .as_ref() + .map_err(ToString::to_string) + .map_err(|err| RpcError::RejectedTransaction(transaction_id, err)) + .inspect_err(|err| debug!("{err}"))?; Ok(SubmitTransactionResponse::new(transaction_id)) } }