Skip to content

Commit 1e9684f

Browse files
committed
mempool_entry: add mempool entry sequence number
1 parent 54ba330 commit 1e9684f

File tree

10 files changed

+18
-10
lines changed

10 files changed

+18
-10
lines changed

src/bench/mempool_eviction.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ static void AddTx(const CTransactionRef& tx, const CAmount& nFee, CTxMemPool& po
1313
{
1414
int64_t nTime = 0;
1515
unsigned int nHeight = 1;
16+
uint64_t sequence = 0;
1617
bool spendsCoinbase = false;
1718
unsigned int sigOpCost = 4;
1819
LockPoints lp;
1920
pool.addUnchecked(CTxMemPoolEntry(
20-
tx, nFee, nTime, nHeight,
21+
tx, nFee, nTime, nHeight, sequence,
2122
spendsCoinbase, sigOpCost, lp));
2223
}
2324

src/bench/mempool_stress.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ static void AddTx(const CTransactionRef& tx, CTxMemPool& pool) EXCLUSIVE_LOCKS_R
1616
{
1717
int64_t nTime = 0;
1818
unsigned int nHeight = 1;
19+
uint64_t sequence = 0;
1920
bool spendsCoinbase = false;
2021
unsigned int sigOpCost = 4;
2122
LockPoints lp;
22-
pool.addUnchecked(CTxMemPoolEntry(tx, 1000, nTime, nHeight, spendsCoinbase, sigOpCost, lp));
23+
pool.addUnchecked(CTxMemPoolEntry(tx, 1000, nTime, nHeight, sequence, spendsCoinbase, sigOpCost, lp));
2324
}
2425

2526
struct Available {

src/bench/rpc_mempool.cpp

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

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

src/kernel/mempool_entry.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ class CTxMemPoolEntry
7979
const size_t nUsageSize; //!< ... and total memory usage
8080
const int64_t nTime; //!< Local time when entering the mempool
8181
const unsigned int entryHeight; //!< Chain height when entering the mempool
82+
const uint64_t entry_sequence; //!< Sequence number used to determine w hether this transaction is too recent for relay
8283
const bool spendsCoinbase; //!< keep track of transactions that spend a coinbase
8384
const int64_t sigOpCost; //!< Total sigop cost
8485
CAmount m_modified_fee; //!< Used for determining the priority of the transaction for mining in a block
@@ -101,7 +102,7 @@ class CTxMemPoolEntry
101102

102103
public:
103104
CTxMemPoolEntry(const CTransactionRef& tx, CAmount fee,
104-
int64_t time, unsigned int entry_height,
105+
int64_t time, unsigned int entry_height, uint64_t entry_sequence,
105106
bool spends_coinbase,
106107
int64_t sigops_cost, LockPoints lp)
107108
: tx{tx},
@@ -110,6 +111,7 @@ class CTxMemPoolEntry
110111
nUsageSize{RecursiveDynamicUsage(tx)},
111112
nTime{time},
112113
entryHeight{entry_height},
114+
entry_sequence{entry_sequence},
113115
spendsCoinbase{spends_coinbase},
114116
sigOpCost{sigops_cost},
115117
m_modified_fee{nFee},
@@ -130,6 +132,7 @@ class CTxMemPoolEntry
130132
int32_t GetTxWeight() const { return nTxWeight; }
131133
std::chrono::seconds GetTime() const { return std::chrono::seconds{nTime}; }
132134
unsigned int GetHeight() const { return entryHeight; }
135+
uint64_t GetSequence() const { return entry_sequence; }
133136
int64_t GetSigOpCost() const { return sigOpCost; }
134137
CAmount GetModifiedFee() const { return m_modified_fee; }
135138
size_t DynamicMemoryUsage() const { return nUsageSize; }

src/node/interfaces.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ class ChainImpl : public Chain
676676
{
677677
if (!m_node.mempool) return true;
678678
LockPoints lp;
679-
CTxMemPoolEntry entry(tx, 0, 0, 0, false, 0, lp);
679+
CTxMemPoolEntry entry(tx, 0, 0, 0, 0, false, 0, lp);
680680
const CTxMemPool::Limits& limits{m_node.mempool->m_limits};
681681
LOCK(m_node.mempool->cs);
682682
return m_node.mempool->CalculateMemPoolAncestors(entry, limits).has_value();

src/test/fuzz/util/mempool.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ CTxMemPoolEntry ConsumeTxMemPoolEntry(FuzzedDataProvider& fuzzed_data_provider,
2323
const CAmount fee{ConsumeMoney(fuzzed_data_provider, /*max=*/std::numeric_limits<CAmount>::max() / CAmount{100'000})};
2424
assert(MoneyRange(fee));
2525
const int64_t time = fuzzed_data_provider.ConsumeIntegral<int64_t>();
26+
const uint64_t entry_sequence{fuzzed_data_provider.ConsumeIntegral<uint64_t>()};
2627
const unsigned int entry_height = fuzzed_data_provider.ConsumeIntegral<unsigned int>();
2728
const bool spends_coinbase = fuzzed_data_provider.ConsumeBool();
2829
const unsigned int sig_op_cost = fuzzed_data_provider.ConsumeIntegralInRange<unsigned int>(0, MAX_BLOCK_SIGOPS_COST);
29-
return CTxMemPoolEntry{MakeTransactionRef(tx), fee, time, entry_height, spends_coinbase, sig_op_cost, {}};
30+
return CTxMemPoolEntry{MakeTransactionRef(tx), fee, time, entry_height, entry_sequence, spends_coinbase, sig_op_cost, {}};
3031
}

src/test/util/setup_common.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ std::vector<CTransactionRef> TestChain100Setup::PopulateMempool(FastRandomContex
437437
LOCK2(cs_main, m_node.mempool->cs);
438438
LockPoints lp;
439439
m_node.mempool->addUnchecked(CTxMemPoolEntry(ptx, /*fee=*/(total_in - num_outputs * amount_per_output),
440-
/*time=*/0, /*entry_height=*/1,
440+
/*time=*/0, /*entry_height=*/1, /*entry_sequence=*/0,
441441
/*spends_coinbase=*/false, /*sigops_cost=*/4, lp));
442442
}
443443
--num_transactions;
@@ -467,7 +467,7 @@ void TestChain100Setup::MockMempoolMinFee(const CFeeRate& target_feerate)
467467
const auto tx_fee = target_feerate.GetFee(GetVirtualTransactionSize(*tx)) -
468468
m_node.mempool->m_incremental_relay_feerate.GetFee(GetVirtualTransactionSize(*tx));
469469
m_node.mempool->addUnchecked(CTxMemPoolEntry(tx, /*fee=*/tx_fee,
470-
/*time=*/0, /*entry_height=*/1,
470+
/*time=*/0, /*entry_height=*/1, /*entry_sequence=*/0,
471471
/*spends_coinbase=*/true, /*sigops_cost=*/1, lp));
472472
m_node.mempool->TrimToSize(0);
473473
assert(m_node.mempool->GetMinFee() == target_feerate);

src/test/util/txmempool.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,5 @@ CTxMemPoolEntry TestMemPoolEntryHelper::FromTx(const CMutableTransaction& tx) co
3434

3535
CTxMemPoolEntry TestMemPoolEntryHelper::FromTx(const CTransactionRef& tx) const
3636
{
37-
return CTxMemPoolEntry{tx, nFee, TicksSinceEpoch<std::chrono::seconds>(time), nHeight, spendsCoinbase, sigOpCost, lp};
37+
return CTxMemPoolEntry{tx, nFee, TicksSinceEpoch<std::chrono::seconds>(time), nHeight, m_sequence, spendsCoinbase, sigOpCost, lp};
3838
}

src/test/util/txmempool.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ struct TestMemPoolEntryHelper {
1919
CAmount nFee{0};
2020
NodeSeconds time{};
2121
unsigned int nHeight{1};
22+
uint64_t m_sequence{0};
2223
bool spendsCoinbase{false};
2324
unsigned int sigOpCost{4};
2425
LockPoints lp;
@@ -30,6 +31,7 @@ struct TestMemPoolEntryHelper {
3031
TestMemPoolEntryHelper& Fee(CAmount _fee) { nFee = _fee; return *this; }
3132
TestMemPoolEntryHelper& Time(NodeSeconds tp) { time = tp; return *this; }
3233
TestMemPoolEntryHelper& Height(unsigned int _height) { nHeight = _height; return *this; }
34+
TestMemPoolEntryHelper& Sequence(uint64_t _seq) { m_sequence = _seq; return *this; }
3335
TestMemPoolEntryHelper& SpendsCoinbase(bool _flag) { spendsCoinbase = _flag; return *this; }
3436
TestMemPoolEntryHelper& SigOpsCost(unsigned int _sigopsCost) { sigOpCost = _sigopsCost; return *this; }
3537
};

src/validation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,7 @@ bool MemPoolAccept::PreChecks(ATMPArgs& args, Workspace& ws)
834834
}
835835
}
836836

837-
entry.reset(new CTxMemPoolEntry(ptx, ws.m_base_fees, nAcceptTime, m_active_chainstate.m_chain.Height(),
837+
entry.reset(new CTxMemPoolEntry(ptx, ws.m_base_fees, nAcceptTime, m_active_chainstate.m_chain.Height(), m_pool.GetSequence(),
838838
fSpendsCoinbase, nSigOpsCost, lock_points.value()));
839839
ws.m_vsize = entry->GetTxSize();
840840

0 commit comments

Comments
 (0)