Skip to content

Commit

Permalink
Reserve space for free transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
watto-engineer committed Mar 2, 2023
1 parent 54339f0 commit 882eb48
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,8 @@ void BlockAssembler::addPackageTxs(int &nPackagesSelected, int &nDescendantsUpda
const int64_t MAX_CONSECUTIVE_FAILURES = 1000;
int64_t nConsecutiveFailed = 0;

uint64_t blockSize = 0;

while (mi != m_mempool.mapTx.get<ancestor_score>().end() || !mapModifiedTx.empty()) {
// First try to find a new transaction in mapTx to evaluate.
if (mi != m_mempool.mapTx.get<ancestor_score>().end() &&
Expand Down Expand Up @@ -606,7 +608,7 @@ void BlockAssembler::addPackageTxs(int &nPackagesSelected, int &nDescendantsUpda
packageSigOps = modit->nSigOpCountWithAncestors;
}

if (packageFees < blockMinFeeRate.GetFee(packageSize)) {
if (packageFees < blockMinFeeRate.GetFee(packageSize) && packageSize + blockSize > DEFAULT_BLOCK_PRIORITY_SIZE) {
// Everything else we might consider has a lower fee rate
return;
}
Expand Down Expand Up @@ -649,6 +651,8 @@ void BlockAssembler::addPackageTxs(int &nPackagesSelected, int &nDescendantsUpda
// This transaction will make it in; reset the failed counter.
nConsecutiveFailed = 0;

blockSize += packageSize;

// Package can be added. Sort the entries in a valid order.
std::vector<CTxMemPool::txiter> sortedEntries;
SortForBlock(ancestors, sortedEntries);
Expand Down
2 changes: 2 additions & 0 deletions src/policy/policy.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class CTxOut;

/** Default for -blockmaxsize, which controls the maximum size of block the mining code will create **/
static const unsigned int DEFAULT_BLOCK_MAX_SIZE = 2000000;
/** Default for -blockprioritysize, maximum space for zero/low-fee transactions **/
static const unsigned int DEFAULT_BLOCK_PRIORITY_SIZE = 50000;
/** Default for -blockmintxfee, which sets the minimum feerate for a transaction in blocks created by mining code **/
static const unsigned int DEFAULT_BLOCK_MIN_TX_FEE = 1000;
/** The maximum size for transactions we're willing to relay/mine */
Expand Down
2 changes: 1 addition & 1 deletion src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ static bool AcceptToMemoryPoolWorker(const CChainParams& chainparams, CTxMemPool
}

// No transactions are allowed below minRelayTxFee except from disconnected blocks
if (!bypass_limits && nModifiedFees < ::minRelayTxFee.GetFee(nSize)) {
if (!bypass_limits && nModifiedFees < ::minRelayTxFee.GetFee(nSize) && nSize > DEFAULT_BLOCK_PRIORITY_SIZE) {
return state.Invalid(ValidationInvalidReason::TX_MEMPOOL_POLICY, false, REJECT_INSUFFICIENTFEE, "min relay fee not met", strprintf("%d < %d", nModifiedFees, ::minRelayTxFee.GetFee(nSize)));
}

Expand Down

0 comments on commit 882eb48

Please sign in to comment.