mirror of
https://github.com/mimblewimble/grin.git
synced 2025-01-20 19:11:08 +03:00
Add a maximum size to stempool (#1895)
* Add a maximum size to stempool * Simplify logic
This commit is contained in:
parent
d3a8613e43
commit
24ed4b787a
4 changed files with 26 additions and 2 deletions
|
@ -240,6 +240,13 @@ fn comments() -> HashMap<String, String> {
|
|||
".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(),
|
||||
"
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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(),
|
||||
|
|
Loading…
Reference in a new issue