From 41d51408028b1346bcdee25190e3f084b6fbc1c1 Mon Sep 17 00:00:00 2001 From: rink1969 Date: Fri, 21 Nov 2025 14:09:48 +0800 Subject: [PATCH] fix: invalid tx in pool --- src/core/chain.rs | 15 ++++++++------- src/core/controller.rs | 10 +++------- src/core/pool.rs | 6 +++--- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/src/core/chain.rs b/src/core/chain.rs index 606e20c..ed2c7e7 100644 --- a/src/core/chain.rs +++ b/src/core/chain.rs @@ -143,7 +143,7 @@ impl Chain { let height = self.block_number + 1; let (tx_hash_list, quota) = { - let mut pool = self.pool.write().await; + let pool = self.pool.read().await; let ret = pool.package(); let (pool_len, pool_quota) = pool.pool_status(); info!( @@ -301,8 +301,8 @@ impl Chain { if let Some(Tx::UtxoTx(utxo_tx)) = raw_tx.tx.clone() { let res = { let mut auditor = self.auditor.write().await; - auditor.update_system_config(&utxo_tx); let mut pool = self.pool.write().await; + auditor.update_system_config(&utxo_tx); pool.update_system_config(&utxo_tx) }; if res { @@ -322,11 +322,12 @@ impl Chain { let tx_hash_list = get_tx_hash_list(block.body.as_ref().ok_or(StatusCodeEnum::NoneBlockBody)?)?; - self.auditor - .write() - .await - .insert_tx_hash(block_height, tx_hash_list.clone()); - self.pool.write().await.remove(&tx_hash_list, block_height); + { + let mut auditor = self.auditor.write().await; + let mut pool = self.pool.write().await; + auditor.insert_tx_hash(block_height, tx_hash_list.clone()); + pool.remove(&tx_hash_list, block_height); + } info!( "update auditor and pool, tx_hash_list len {}", tx_hash_list.len() diff --git a/src/core/controller.rs b/src/core/controller.rs index 5aa83b5..5d7f6e4 100644 --- a/src/core/controller.rs +++ b/src/core/controller.rs @@ -237,16 +237,12 @@ impl Controller { broadcast: bool, ) -> Result, StatusCodeEnum> { let tx_hash = get_tx_hash(&raw_tx)?.to_vec(); - - { - let auditor = self.auditor.read().await; - auditor.auditor_check(&raw_tx)?; - } - crypto_check_async(Arc::new(raw_tx.clone())).await?; let res = { + let auditor = self.auditor.read().await; let mut pool = self.pool.write().await; + auditor.auditor_check(&raw_tx)?; pool.insert(raw_tx.clone()) }; if res { @@ -295,8 +291,8 @@ impl Controller { let mut hashes = Vec::new(); { let auditor = self.auditor.read().await; - auditor.auditor_check_batch(&raw_txs)?; let mut pool = self.pool.write().await; + auditor.auditor_check_batch(&raw_txs)?; for raw_tx in raw_txs.body.clone() { let hash = get_tx_hash(&raw_tx)?.to_vec(); if pool.insert(raw_tx) { diff --git a/src/core/pool.rs b/src/core/pool.rs index 6f86fc3..9d93aee 100644 --- a/src/core/pool.rs +++ b/src/core/pool.rs @@ -135,7 +135,7 @@ impl Pool { }); } - pub fn package(&mut self) -> (Vec>, u64) { + pub fn package(&self) -> (Vec>, u64) { let system_config = &self.sys_config; let mut quota_limit = system_config.quota_limit; let mut pack_tx = vec![]; @@ -174,8 +174,8 @@ fn tx_is_valid(sys_config: &SystemConfig, raw_tx: &RawTransaction, height: u64) match &raw_tx.tx { Some(Tx::NormalTx(ref normal_tx)) => match normal_tx.transaction { Some(ref tx) => { - height < tx.valid_until_block - && tx.valid_until_block <= height + sys_config.block_limit + height <= tx.valid_until_block + && tx.valid_until_block < height + sys_config.block_limit } None => false, },