Skip to content

Commit c03a715

Browse files
committed
Store extra weight on CTxMemPoolEntry
1 parent d152f91 commit c03a715

File tree

9 files changed

+14
-9
lines changed

9 files changed

+14
-9
lines changed

src/bench/mempool_eviction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ static void AddTx(const CTransactionRef& tx, const CAmount& nFee, CTxMemPool& po
2121
pool.addUnchecked(CTxMemPoolEntry(
2222
tx, nFee, nTime, dPriority, nHeight, sequence,
2323
tx->GetValueOut(),
24-
spendsCoinbase, sigOpCost, lp));
24+
spendsCoinbase, /*extra_weight=*/0, sigOpCost, lp));
2525
}
2626

2727
// Right now this is only testing eviction performance in an extremely small

src/bench/mempool_stress.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ static void AddTx(const CTransactionRef& tx, CTxMemPool& pool) EXCLUSIVE_LOCKS_R
2222
bool spendsCoinbase = false;
2323
unsigned int sigOpCost = 4;
2424
LockPoints lp;
25-
pool.addUnchecked(CTxMemPoolEntry(tx, 1000, nTime, nHeight, sequence, /*entry_tx_inputs_coin_age=*/coin_age, tx->GetValueOut(), spendsCoinbase, sigOpCost, lp));
25+
pool.addUnchecked(CTxMemPoolEntry(tx, 1000, nTime, nHeight, sequence, /*entry_tx_inputs_coin_age=*/coin_age, tx->GetValueOut(), spendsCoinbase, /*extra_weight=*/0, sigOpCost, lp));
2626
}
2727

2828
struct Available {

src/bench/rpc_mempool.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
static void AddTx(const CTransactionRef& tx, const CAmount& fee, CTxMemPool& pool) EXCLUSIVE_LOCKS_REQUIRED(cs_main, pool.cs)
1818
{
1919
LockPoints lp;
20-
pool.addUnchecked(CTxMemPoolEntry(tx, fee, /*time=*/0, /*entry_height=*/0, /*entry_sequence=*/0, /*entry_tx_inputs_coin_age=*/0.0, /*in_chain_input_value=*/0, /*spends_coinbase=*/false, /*sigops_cost=*/4, lp));
20+
pool.addUnchecked(CTxMemPoolEntry(tx, fee, /*time=*/0, /*entry_height=*/0, /*entry_sequence=*/0, /*entry_tx_inputs_coin_age=*/0.0, /*in_chain_input_value=*/0, /*spends_coinbase=*/false, /*extra_weight=*/0, /*sigops_cost=*/4, lp));
2121
}
2222

2323
static void RpcMempool(benchmark::Bench& bench)

src/kernel/mempool_entry.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ class CTxMemPoolEntry
8787
const int64_t nTime; //!< Local time when entering the mempool
8888
const uint64_t entry_sequence; //!< Sequence number used to determine whether this transaction is too recent for relay
8989
const int64_t sigOpCost; //!< Total sigop cost
90+
const int32_t m_extra_weight; //!< Policy-only additional transaction weight beyond nTxWeight
9091
const size_t nModSize; //!< Cached modified size for priority
9192
const double entryPriority; //!< Priority when entering the mempool
9293
const unsigned int entryHeight; //!< Chain height when entering the mempool
@@ -118,6 +119,7 @@ class CTxMemPoolEntry
118119
double entry_tx_inputs_coin_age,
119120
CAmount in_chain_input_value,
120121
bool spends_coinbase,
122+
int32_t extra_weight,
121123
int64_t sigops_cost, LockPoints lp)
122124
: tx{tx},
123125
nFee{fee},
@@ -126,6 +128,7 @@ class CTxMemPoolEntry
126128
nTime{time},
127129
entry_sequence{entry_sequence},
128130
sigOpCost{sigops_cost},
131+
m_extra_weight{extra_weight},
129132
nModSize{CalculateModifiedSize(*tx, GetTxSize())},
130133
entryPriority{ComputePriority2(entry_tx_inputs_coin_age, nModSize)},
131134
entryHeight{entry_height},

src/node/interfaces.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@ class ChainImpl : public Chain
726726
{
727727
if (!m_node.mempool) return {};
728728
LockPoints lp;
729-
CTxMemPoolEntry entry(tx, 0, 0, 0, 0, 0, 0, false, 0, lp);
729+
CTxMemPoolEntry entry(tx, 0, 0, 0, 0, 0, 0, false, /*extra_weight=*/0, 0, lp);
730730
LOCK(m_node.mempool->cs);
731731
return m_node.mempool->CheckPackageLimits({tx}, entry.GetTxSize());
732732
}

src/test/fuzz/util/mempool.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ CTxMemPoolEntry ConsumeTxMemPoolEntry(FuzzedDataProvider& fuzzed_data_provider,
3838
const double coin_age = fuzzed_data_provider.ConsumeFloatingPoint<double>();
3939
const unsigned int entry_height = fuzzed_data_provider.ConsumeIntegralInRange<unsigned int>(0, std::numeric_limits<unsigned int>::max() - 1);
4040
const bool spends_coinbase = fuzzed_data_provider.ConsumeBool();
41+
const int32_t extra_weight = fuzzed_data_provider.ConsumeIntegralInRange<int32_t>(0, GetTransactionWeight(tx) * 3);
4142
const unsigned int sig_op_cost = fuzzed_data_provider.ConsumeIntegralInRange<unsigned int>(0, MAX_BLOCK_SIGOPS_COST);
42-
return CTxMemPoolEntry{MakeTransactionRef(tx), fee, time, entry_height, entry_sequence, /*entry_tx_inputs_coin_age=*/coin_age, tx.GetValueOut(), spends_coinbase, sig_op_cost, {}};
43+
return CTxMemPoolEntry{MakeTransactionRef(tx), fee, time, entry_height, entry_sequence, /*entry_tx_inputs_coin_age=*/coin_age, tx.GetValueOut(), spends_coinbase, extra_weight, sig_op_cost, {}};
4344
}

src/test/util/setup_common.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ std::vector<CTransactionRef> TestChain100Setup::PopulateMempool(FastRandomContex
566566
/*time=*/0, /*entry_height=*/ height, /*entry_sequence=*/0,
567567
/*entry_tx_inputs_coin_age=*/coin_age,
568568
in_chain_input_value,
569-
/*spends_coinbase=*/false, /*sigops_cost=*/4, lp));
569+
/*spends_coinbase=*/false, /*extra_weight=*/0, /*sigops_cost=*/4, lp));
570570
}
571571
--num_transactions;
572572
}
@@ -598,7 +598,7 @@ void TestChain100Setup::MockMempoolMinFee(const CFeeRate& target_feerate)
598598
/*time=*/0, /*entry_height=*/1, /*entry_sequence=*/0,
599599
/*entry_tx_inputs_coin_age=*/0.0,
600600
/*in_chain_input_value=*/0,
601-
/*spends_coinbase=*/true, /*sigops_cost=*/1, lp));
601+
/*spends_coinbase=*/true, /*extra_weight=*/0, /*sigops_cost=*/1, lp));
602602
m_node.mempool->TrimToSize(0);
603603
assert(m_node.mempool->GetMinFee() == target_feerate);
604604
}

src/test/util/txmempool.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ CTxMemPoolEntry TestMemPoolEntryHelper::FromTx(const CTransactionRef& tx) const
3939
{
4040
constexpr double coin_age{0};
4141
const CAmount inChainValue = 0;
42-
return CTxMemPoolEntry{tx, nFee, TicksSinceEpoch<std::chrono::seconds>(time), nHeight, m_sequence, /*entry_tx_inputs_coin_age=*/coin_age, inChainValue, spendsCoinbase, sigOpCost, lp};
42+
return CTxMemPoolEntry{tx, nFee, TicksSinceEpoch<std::chrono::seconds>(time), nHeight, m_sequence, /*entry_tx_inputs_coin_age=*/coin_age, inChainValue, spendsCoinbase, /*extra_weight=*/0, sigOpCost, lp};
4343
}
4444

4545
std::optional<std::string> CheckPackageMempoolAcceptResult(const Package& txns,

src/validation.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1002,10 +1002,11 @@ bool MemPoolAccept::PreChecks(ATMPArgs& args, Workspace& ws)
10021002
// Set entry_sequence to 0 when rejectmsg_zero_mempool_entry_seq is used; this allows txs from a block
10031003
// reorg to be marked earlier than any child txs that were already in the mempool.
10041004
const uint64_t entry_sequence = args.m_ignore_rejects.count(rejectmsg_zero_mempool_entry_seq) ? 0 : m_pool.GetSequence();
1005+
int32_t extra_weight = CalculateExtraTxWeight(*ptx, m_view, ::g_weight_per_data_byte);
10051006
entry.reset(new CTxMemPoolEntry(ptx, ws.m_base_fees, nAcceptTime, m_active_chainstate.m_chain.Height(), entry_sequence,
10061007
/*entry_tx_inputs_coin_age=*/coin_age,
10071008
inChainInputValue,
1008-
fSpendsCoinbase, nSigOpsCost, lock_points.value()));
1009+
fSpendsCoinbase, extra_weight, nSigOpsCost, lock_points.value()));
10091010
ws.m_vsize = entry->GetTxSize();
10101011

10111012
// To avoid rejecting low-sigop bare-multisig transactions, the sigops

0 commit comments

Comments
 (0)