diff --git a/core/mempool/src/adapter/mod.rs b/core/mempool/src/adapter/mod.rs index 866faa5c9..01745c18d 100644 --- a/core/mempool/src/adapter/mod.rs +++ b/core/mempool/src/adapter/mod.rs @@ -1,6 +1,6 @@ pub mod message; -use std::sync::atomic::{AtomicU64, AtomicUsize, Ordering}; +use std::sync::atomic::{AtomicUsize, Ordering}; use std::{collections::HashMap, error::Error, marker::PhantomData, sync::Arc, time::Duration}; use dashmap::DashMap; @@ -11,6 +11,7 @@ use futures::{ use log::{debug, error}; use parking_lot::Mutex; +use protocol::constants::{MAX_GAS_LIMIT, MIN_TRANSACTION_GAS_LIMIT}; use protocol::traits::{ Context, Gossip, Interoperation, MemPoolAdapter, PeerTrust, Priority, ReadOnlyStorage, Rpc, TrustFeedback, @@ -122,7 +123,6 @@ pub struct DefaultMemPoolAdapter { trie_db: Arc, addr_nonce: DashMap, - gas_limit: AtomicU64, max_tx_size: AtomicUsize, chain_id: u64, @@ -146,7 +146,6 @@ where storage: Arc, trie_db: Arc, chain_id: u64, - gas_limit: u64, max_tx_size: usize, broadcast_txs_size: usize, broadcast_txs_interval: u64, @@ -168,7 +167,6 @@ where trie_db, addr_nonce: DashMap::new(), - gas_limit: AtomicU64::new(gas_limit), max_tx_size: AtomicUsize::new(max_tx_size), chain_id, @@ -253,7 +251,25 @@ where fn verify_gas_limit(&self, ctx: Context, stx: &SignedTransaction) -> ProtocolResult<()> { let gas_limit_tx = stx.transaction.unsigned.gas_limit(); - if gas_limit_tx > &U64::from(self.gas_limit.load(Ordering::Acquire)) { + if gas_limit_tx < &(MIN_TRANSACTION_GAS_LIMIT.into()) { + if ctx.is_network_origin_txs() { + self.network.report( + ctx, + TrustFeedback::Bad(format!( + "Mempool under gas limit of tx {:#x}", + stx.transaction.hash + )), + ); + } + + return Err(MemPoolError::UnderGasLimit { + tx_hash: stx.transaction.hash, + gas_limit_tx: gas_limit_tx.low_u64(), + } + .into()); + } + + if gas_limit_tx > &(MAX_GAS_LIMIT.into()) { if ctx.is_network_origin_txs() { self.network.report( ctx, @@ -263,10 +279,10 @@ where )), ); } + return Err(MemPoolError::ExceedGasLimit { - tx_hash: stx.transaction.hash, - gas_limit_tx: gas_limit_tx.low_u64(), - gas_limit_config: self.gas_limit.load(Ordering::Acquire), + tx_hash: stx.transaction.hash, + gas_limit_tx: gas_limit_tx.low_u64(), } .into()); } @@ -474,10 +490,9 @@ where &self, _context: Context, _state_root: MerkleRoot, - cycles_limit: u64, + _cycles_limit: u64, max_tx_size: u64, ) { - self.gas_limit.store(cycles_limit, Ordering::Release); self.max_tx_size .store(max_tx_size as usize, Ordering::Release); self.addr_nonce.clear(); diff --git a/core/mempool/src/lib.rs b/core/mempool/src/lib.rs index 308ee73f6..97165c2a7 100644 --- a/core/mempool/src/lib.rs +++ b/core/mempool/src/lib.rs @@ -391,15 +391,23 @@ pub enum MemPoolError { }, #[display( - fmt = "Tx: {:?} exceeds cycle limit, tx: {}, config: {}", + fmt = "Tx: {:?} exceeds 30000000, tx gas limit {}", tx_hash, - gas_limit_tx, - gas_limit_config + gas_limit_tx )] ExceedGasLimit { - tx_hash: Hash, - gas_limit_config: u64, - gas_limit_tx: u64, + tx_hash: Hash, + gas_limit_tx: u64, + }, + + #[display( + fmt = "Tx: {:?} gas price is less than 21000, tx gas limit {}", + tx_hash, + gas_limit_tx + )] + UnderGasLimit { + tx_hash: Hash, + gas_limit_tx: u64, }, #[display(fmt = "Tx nonce {} is invalid current nonce {}", tx_nonce, current)] diff --git a/core/run/src/lib.rs b/core/run/src/lib.rs index f536c9ffd..05018cd6a 100644 --- a/core/run/src/lib.rs +++ b/core/run/src/lib.rs @@ -345,7 +345,6 @@ where Arc::clone(storage), Arc::clone(trie_db), current_header.chain_id, - current_header.gas_limit.low_u64(), config.pool_size as usize, config.broadcast_txs_size, config.broadcast_txs_interval,