diff --git a/config/src/comments.rs b/config/src/comments.rs index 3a2dda559..f25d5ffa6 100644 --- a/config/src/comments.rs +++ b/config/src/comments.rs @@ -240,6 +240,13 @@ fn comments() -> HashMap { ".to_string(), ); + retval.insert( + "max_stempool_size".to_string(), + " +#maximum number of transactions allowed in the stempool +".to_string(), + ); + retval.insert( "[server.stratum_mining_config]".to_string(), " diff --git a/pool/src/transaction_pool.rs b/pool/src/transaction_pool.rs index 063566d95..1be724b3f 100644 --- a/pool/src/transaction_pool.rs +++ b/pool/src/transaction_pool.rs @@ -141,7 +141,7 @@ impl TransactionPool { } // Do we have the capacity to accept this transaction? - self.is_acceptable(&tx)?; + self.is_acceptable(&tx, stem)?; // Make sure the transaction is valid before anything else. tx.validate(self.verifier_cache.clone()) @@ -215,12 +215,20 @@ impl TransactionPool { /// Whether the transaction is acceptable to the pool, given both how /// full the pool is and the transaction weight. - fn is_acceptable(&self, tx: &Transaction) -> Result<(), PoolError> { + fn is_acceptable(&self, tx: &Transaction, stem: bool) -> Result<(), PoolError> { if self.total_size() > self.config.max_pool_size { // TODO evict old/large transactions instead return Err(PoolError::OverCapacity); } + // Check that the stempool can accept this transaction + if stem { + if self.stempool.size() > self.config.max_stempool_size { + // TODO evict old/large transactions instead + return Err(PoolError::OverCapacity); + } + } + // for a basic transaction (1 input, 2 outputs) - // (-1 * 1) + (4 * 2) + 1 = 8 // 8 * 10 = 80 diff --git a/pool/src/types.rs b/pool/src/types.rs index d51319e01..c21fcf264 100644 --- a/pool/src/types.rs +++ b/pool/src/types.rs @@ -96,6 +96,10 @@ pub struct PoolConfig { /// Maximum capacity of the pool in number of transactions #[serde = "default_max_pool_size"] pub max_pool_size: usize, + + /// Maximum capacity of the pool in number of transactions + #[serde = "default_max_stempool_size"] + pub max_stempool_size: usize, } impl Default for PoolConfig { @@ -103,6 +107,7 @@ impl Default for PoolConfig { PoolConfig { accept_fee_base: default_accept_fee_base(), max_pool_size: default_max_pool_size(), + max_stempool_size: default_max_stempool_size(), } } } @@ -113,6 +118,9 @@ fn default_accept_fee_base() -> u64 { fn default_max_pool_size() -> usize { 50_000 } +fn default_max_stempool_size() -> usize { + 50_000 +} /// Represents a single entry in the pool. /// A single (possibly aggregated) transaction. diff --git a/pool/tests/common/mod.rs b/pool/tests/common/mod.rs index 48c599d51..2a1a4b620 100644 --- a/pool/tests/common/mod.rs +++ b/pool/tests/common/mod.rs @@ -168,6 +168,7 @@ pub fn test_setup( PoolConfig { accept_fee_base: 0, max_pool_size: 50, + max_stempool_size: 50, }, chain.clone(), verifier_cache.clone(),