diff --git a/core/mempool/src/adapter/mod.rs b/core/mempool/src/adapter/mod.rs index 29f9b07d3..32d990229 100644 --- a/core/mempool/src/adapter/mod.rs +++ b/core/mempool/src/adapter/mod.rs @@ -1,3 +1,5 @@ +use super::TxContext; + pub mod message; use std::{ @@ -248,10 +250,12 @@ where let sig = tx.signature.as_ref(); C::verify_signature(hash.as_ref(), sig, pub_key).map_err(|_| { - self.network.report( - ctx, - TrustFeedback::Worse(format!("Mempool wrong signature of tx {:?}", tx.tx_hash)), - ); + if ctx.is_network_origin_txs() { + self.network.report( + ctx, + TrustFeedback::Worse(format!("Mempool wrong signature of tx {:?}", tx.tx_hash)), + ); + } MemPoolError::CheckSig { tx_hash: tx.tx_hash, } @@ -269,10 +273,12 @@ where let tx_hash = Hash::digest(fixed_bytes); if tx_hash != stx.tx_hash { - self.network.report( - ctx, - TrustFeedback::Worse(format!("Mempool wrong tx_hash of tx {:?}", stx.tx_hash)), - ); + if ctx.is_network_origin_txs() { + self.network.report( + ctx, + TrustFeedback::Worse(format!("Mempool wrong tx_hash of tx {:?}", stx.tx_hash)), + ); + } let wrong_hash = MemPoolError::CheckHash { expect: stx.tx_hash, actual: tx_hash, @@ -284,10 +290,15 @@ where // check tx size let max_tx_size = self.max_tx_size.load(Ordering::SeqCst); if size > max_tx_size { - self.network.report( - ctx, - TrustFeedback::Bad(format!("Mempool exceed size limit of tx {:?}", stx.tx_hash)), - ); + if ctx.is_network_origin_txs() { + self.network.report( + ctx, + TrustFeedback::Bad(format!( + "Mempool exceed size limit of tx {:?}", + stx.tx_hash + )), + ); + } return Err(MemPoolError::ExceedSizeLimit { tx_hash, max_tx_size, @@ -300,13 +311,15 @@ where let cycles_limit_config = self.cycles_limit.load(Ordering::SeqCst); let cycles_limit_tx = stx.raw.cycles_limit; if cycles_limit_tx > cycles_limit_config { - self.network.report( - ctx, - TrustFeedback::Bad(format!( - "Mempool exceed cycle limit of tx {:?}", - stx.tx_hash - )), - ); + if ctx.is_network_origin_txs() { + self.network.report( + ctx, + TrustFeedback::Bad(format!( + "Mempool exceed cycle limit of tx {:?}", + stx.tx_hash + )), + ); + } return Err(MemPoolError::ExceedCyclesLimit { tx_hash, cycles_limit_tx, @@ -318,10 +331,12 @@ where // Verify chain id let latest_block = self.storage.get_latest_block().await?; if latest_block.header.chain_id != stx.raw.chain_id { - self.network.report( - ctx, - TrustFeedback::Worse(format!("Mempool wrong chain of tx {:?}", stx.tx_hash)), - ); + if ctx.is_network_origin_txs() { + self.network.report( + ctx, + TrustFeedback::Worse(format!("Mempool wrong chain of tx {:?}", stx.tx_hash)), + ); + } let wrong_chain_id = MemPoolError::WrongChain { tx_hash: stx.tx_hash, }; @@ -334,10 +349,12 @@ where let timeout_gap = self.timeout_gap.load(Ordering::SeqCst); if stx.raw.timeout > latest_height + timeout_gap { - self.network.report( - ctx, - TrustFeedback::Bad(format!("Mempool invalid timeout of tx {:?}", stx.tx_hash)), - ); + if ctx.is_network_origin_txs() { + self.network.report( + ctx, + TrustFeedback::Bad(format!("Mempool invalid timeout of tx {:?}", stx.tx_hash)), + ); + } let invalid_timeout = MemPoolError::InvalidTimeout { tx_hash: stx.tx_hash, }; @@ -346,10 +363,12 @@ where } if stx.raw.timeout < latest_height { - self.network.report( - ctx, - TrustFeedback::Bad(format!("Mempool timeout of tx {:?}", stx.tx_hash)), - ); + if ctx.is_network_origin_txs() { + self.network.report( + ctx, + TrustFeedback::Bad(format!("Mempool timeout of tx {:?}", stx.tx_hash)), + ); + } let timeout = MemPoolError::Timeout { tx_hash: stx.tx_hash, timeout: stx.raw.timeout, @@ -381,7 +400,9 @@ where } fn report_good(&self, ctx: Context) { - self.network.report(ctx, TrustFeedback::Good); + if ctx.is_network_origin_txs() { + self.network.report(ctx, TrustFeedback::Good); + } } fn set_args(&self, timeout_gap: u64, cycles_limit: u64, max_tx_size: u64) {