Skip to content

Commit a147687

Browse files
committed
Keep conflictedTxs in ConnectTrace per-block
1 parent d3167ba commit a147687

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/validation.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2179,17 +2179,17 @@ static int64_t nTimePostConnect = 0;
21792179
* part of a single ActivateBestChainStep call.
21802180
*
21812181
* This class also tracks transactions that are removed from the mempool as
2182-
* conflicts and can be used to pass all those transactions through
2183-
* SyncTransaction.
2182+
* conflicts (per block) and can be used to pass all those transactions
2183+
* through SyncTransaction.
21842184
*/
21852185
class ConnectTrace {
21862186
private:
21872187
std::vector<std::pair<CBlockIndex*, std::shared_ptr<const CBlock> > > blocksConnected;
2188-
std::vector<CTransactionRef> conflictedTxs;
2188+
std::vector<std::vector<CTransactionRef> > conflictedTxs;
21892189
CTxMemPool &pool;
21902190

21912191
public:
2192-
ConnectTrace(CTxMemPool &_pool) : pool(_pool) {
2192+
ConnectTrace(CTxMemPool &_pool) : conflictedTxs(1), pool(_pool) {
21932193
pool.NotifyEntryRemoved.connect(boost::bind(&ConnectTrace::NotifyEntryRemoved, this, _1, _2));
21942194
}
21952195

@@ -2199,6 +2199,7 @@ class ConnectTrace {
21992199

22002200
void BlockConnected(CBlockIndex* pindex, std::shared_ptr<const CBlock> pblock) {
22012201
blocksConnected.emplace_back(pindex, std::move(pblock));
2202+
conflictedTxs.emplace_back();
22022203
}
22032204

22042205
std::vector<std::pair<CBlockIndex*, std::shared_ptr<const CBlock> > >& GetBlocksConnected() {
@@ -2207,15 +2208,18 @@ class ConnectTrace {
22072208

22082209
void NotifyEntryRemoved(CTransactionRef txRemoved, MemPoolRemovalReason reason) {
22092210
if (reason == MemPoolRemovalReason::CONFLICT) {
2210-
conflictedTxs.push_back(txRemoved);
2211+
conflictedTxs.back().push_back(txRemoved);
22112212
}
22122213
}
22132214

22142215
void CallSyncTransactionOnConflictedTransactions() {
2215-
for (const auto& tx : conflictedTxs) {
2216-
GetMainSignals().SyncTransaction(*tx, NULL, CMainSignals::SYNC_TRANSACTION_NOT_IN_BLOCK);
2216+
for (const auto& txRemovedForBlock : conflictedTxs) {
2217+
for (const auto& tx : txRemovedForBlock) {
2218+
GetMainSignals().SyncTransaction(*tx, NULL, CMainSignals::SYNC_TRANSACTION_NOT_IN_BLOCK);
2219+
}
22172220
}
22182221
conflictedTxs.clear();
2222+
conflictedTxs.emplace_back();
22192223
}
22202224
};
22212225

0 commit comments

Comments
 (0)