mirror of
https://github.com/mimblewimble/grin.git
synced 2025-01-21 03:21:08 +03:00
Configurable max block weight for mining (aka soft limit) (#1976)
This commit is contained in:
parent
2e421191e2
commit
e4be820671
5 changed files with 21 additions and 8 deletions
|
@ -247,6 +247,13 @@ fn comments() -> HashMap<String, String> {
|
||||||
".to_string(),
|
".to_string(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
retval.insert(
|
||||||
|
"mineable_max_weight".to_string(),
|
||||||
|
"
|
||||||
|
#maximum total weight of transactions that can get selected to build a block
|
||||||
|
".to_string(),
|
||||||
|
);
|
||||||
|
|
||||||
retval.insert(
|
retval.insert(
|
||||||
"[server.stratum_mining_config]".to_string(),
|
"[server.stratum_mining_config]".to_string(),
|
||||||
"
|
"
|
||||||
|
|
|
@ -19,7 +19,6 @@ use std::collections::{HashMap, HashSet};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use util::RwLock;
|
use util::RwLock;
|
||||||
|
|
||||||
use core::consensus;
|
|
||||||
use core::core::hash::{Hash, Hashed};
|
use core::core::hash::{Hash, Hashed};
|
||||||
use core::core::id::{ShortId, ShortIdentifiable};
|
use core::core::id::{ShortId, ShortIdentifiable};
|
||||||
use core::core::transaction;
|
use core::core::transaction;
|
||||||
|
@ -27,10 +26,6 @@ use core::core::verifier_cache::VerifierCache;
|
||||||
use core::core::{Block, BlockHeader, BlockSums, Committed, Transaction, TxKernel};
|
use core::core::{Block, BlockHeader, BlockSums, Committed, Transaction, TxKernel};
|
||||||
use types::{BlockChain, PoolEntry, PoolEntryState, PoolError};
|
use types::{BlockChain, PoolEntry, PoolEntryState, PoolError};
|
||||||
|
|
||||||
// max weight leaving minimum space for a coinbase
|
|
||||||
const MAX_MINEABLE_WEIGHT: usize =
|
|
||||||
consensus::MAX_BLOCK_WEIGHT - consensus::BLOCK_OUTPUT_WEIGHT - consensus::BLOCK_KERNEL_WEIGHT;
|
|
||||||
|
|
||||||
pub struct Pool {
|
pub struct Pool {
|
||||||
/// Entries in the pool (tx + info + timer) in simple insertion order.
|
/// Entries in the pool (tx + info + timer) in simple insertion order.
|
||||||
pub entries: Vec<PoolEntry>,
|
pub entries: Vec<PoolEntry>,
|
||||||
|
@ -120,7 +115,7 @@ impl Pool {
|
||||||
/// appropriate to put in a mined block. Aggregates chains of dependent
|
/// appropriate to put in a mined block. Aggregates chains of dependent
|
||||||
/// transactions, orders by fee over weight and ensures to total weight
|
/// transactions, orders by fee over weight and ensures to total weight
|
||||||
/// doesn't exceed block limits.
|
/// doesn't exceed block limits.
|
||||||
pub fn prepare_mineable_transactions(&self) -> Result<Vec<Transaction>, PoolError> {
|
pub fn prepare_mineable_transactions(&self, max_weight: usize) -> Result<Vec<Transaction>, PoolError> {
|
||||||
let header = self.blockchain.chain_head()?;
|
let header = self.blockchain.chain_head()?;
|
||||||
let tx_buckets = self.bucket_transactions();
|
let tx_buckets = self.bucket_transactions();
|
||||||
|
|
||||||
|
@ -139,7 +134,7 @@ impl Pool {
|
||||||
let mut weight = 0;
|
let mut weight = 0;
|
||||||
flat_txs.retain(|tx| {
|
flat_txs.retain(|tx| {
|
||||||
weight += tx.tx_weight_as_block() as usize;
|
weight += tx.tx_weight_as_block() as usize;
|
||||||
weight < MAX_MINEABLE_WEIGHT
|
weight < max_weight
|
||||||
});
|
});
|
||||||
|
|
||||||
// Iteratively apply the txs to the current chain state,
|
// Iteratively apply the txs to the current chain state,
|
||||||
|
|
|
@ -255,6 +255,6 @@ impl TransactionPool {
|
||||||
/// Returns a vector of transactions from the txpool so we can build a
|
/// Returns a vector of transactions from the txpool so we can build a
|
||||||
/// block from them.
|
/// block from them.
|
||||||
pub fn prepare_mineable_transactions(&self) -> Result<Vec<Transaction>, PoolError> {
|
pub fn prepare_mineable_transactions(&self) -> Result<Vec<Transaction>, PoolError> {
|
||||||
self.txpool.prepare_mineable_transactions()
|
self.txpool.prepare_mineable_transactions(self.config.mineable_max_weight)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,6 +100,12 @@ pub struct PoolConfig {
|
||||||
/// Maximum capacity of the pool in number of transactions
|
/// Maximum capacity of the pool in number of transactions
|
||||||
#[serde = "default_max_stempool_size"]
|
#[serde = "default_max_stempool_size"]
|
||||||
pub max_stempool_size: usize,
|
pub max_stempool_size: usize,
|
||||||
|
|
||||||
|
/// Maximum total weight of transactions that can get selected to build a
|
||||||
|
/// block from. Allows miners to restrict the maximum weight of their
|
||||||
|
/// blocks.
|
||||||
|
#[serde = "default_mineable_max_weight"]
|
||||||
|
pub mineable_max_weight: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for PoolConfig {
|
impl Default for PoolConfig {
|
||||||
|
@ -108,6 +114,7 @@ impl Default for PoolConfig {
|
||||||
accept_fee_base: default_accept_fee_base(),
|
accept_fee_base: default_accept_fee_base(),
|
||||||
max_pool_size: default_max_pool_size(),
|
max_pool_size: default_max_pool_size(),
|
||||||
max_stempool_size: default_max_stempool_size(),
|
max_stempool_size: default_max_stempool_size(),
|
||||||
|
mineable_max_weight: default_mineable_max_weight(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -121,6 +128,9 @@ fn default_max_pool_size() -> usize {
|
||||||
fn default_max_stempool_size() -> usize {
|
fn default_max_stempool_size() -> usize {
|
||||||
50_000
|
50_000
|
||||||
}
|
}
|
||||||
|
fn default_mineable_max_weight() -> usize {
|
||||||
|
consensus::MAX_BLOCK_WEIGHT - consensus::BLOCK_OUTPUT_WEIGHT - consensus::BLOCK_KERNEL_WEIGHT
|
||||||
|
}
|
||||||
|
|
||||||
/// Represents a single entry in the pool.
|
/// Represents a single entry in the pool.
|
||||||
/// A single (possibly aggregated) transaction.
|
/// A single (possibly aggregated) transaction.
|
||||||
|
|
|
@ -169,6 +169,7 @@ pub fn test_setup(
|
||||||
accept_fee_base: 0,
|
accept_fee_base: 0,
|
||||||
max_pool_size: 50,
|
max_pool_size: 50,
|
||||||
max_stempool_size: 50,
|
max_stempool_size: 50,
|
||||||
|
mineable_max_weight: 10_000,
|
||||||
},
|
},
|
||||||
chain.clone(),
|
chain.clone(),
|
||||||
verifier_cache.clone(),
|
verifier_cache.clone(),
|
||||||
|
|
Loading…
Reference in a new issue