Skip to content

Commit 312d27b

Browse files
committed
Merge #17477: Remove the mempool's NotifyEntryAdded and NotifyEntryRemoved signals
e57980b [mempool] Remove NotifyEntryAdded and NotifyEntryRemoved callbacks (John Newbery) 2dd561f [validation] Remove pool member from ConnectTrace (John Newbery) 969b65f [validation] Remove NotifyEntryRemoved callback from ConnectTrace (John Newbery) 5613f98 [validation] Remove conflictedTxs from PerBlockConnectTrace (John Newbery) cdb8934 [validation interface] Remove vtxConflicted from BlockConnected (John Newbery) 1168394 [wallet] Notify conflicted transactions in TransactionRemovedFromMempool (John Newbery) Pull request description: These boost signals were added in #9371, before we had a `TransactionRemovedFromMempool` method in the validation interface. The `NotifyEntryAdded` callback was used by validation to build a vector of conflicted transactions when connecting a block, which the wallet was notified of in the `BlockConnected` CValidationInterface callback. Now that we have a `TransactionRemovedFromMempool` callback, we can fire that signal directly from the mempool for conflicted transactions. Note that #9371 was implemented to ensure `-walletnotify` events were fired for these conflicted transaction. We inadvertently stopped sending these notifications in #16624 (Sep 2019 commit 7e89994). We should probably fix that, but in a different PR. ACKs for top commit: jonatack: Re-ACK e57980b ryanofsky: Code review ACK e57980b, no code changes since previous review, but helpful new code comments have been added and the PR description is now more clear about where the old code came from Tree-SHA512: 3bdbaf1ef2731e788462d4756e69c42a1efdcf168691ce1bbfdaa4b7b55ac3c5b1fd4ab7b90bcdec653703600501b4224d252cfc086aef28f9ce0da3b0563a69
2 parents 527c398 + e57980b commit 312d27b

18 files changed

+58
-65
lines changed

src/index/base.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,7 @@ bool BaseIndex::Rewind(const CBlockIndex* current_tip, const CBlockIndex* new_ti
188188
return true;
189189
}
190190

191-
void BaseIndex::BlockConnected(const std::shared_ptr<const CBlock>& block, const CBlockIndex* pindex,
192-
const std::vector<CTransactionRef>& txn_conflicted)
191+
void BaseIndex::BlockConnected(const std::shared_ptr<const CBlock>& block, const CBlockIndex* pindex)
193192
{
194193
if (!m_synced) {
195194
return;

src/index/base.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ class BaseIndex : public CValidationInterface
6464
bool Commit();
6565

6666
protected:
67-
void BlockConnected(const std::shared_ptr<const CBlock>& block, const CBlockIndex* pindex,
68-
const std::vector<CTransactionRef>& txn_conflicted) override;
67+
void BlockConnected(const std::shared_ptr<const CBlock>& block, const CBlockIndex* pindex) override;
6968

7069
void ChainStateFlushed(const CBlockLocator& locator) override;
7170

src/init.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
#include <boost/algorithm/string/classification.hpp>
7474
#include <boost/algorithm/string/replace.hpp>
7575
#include <boost/algorithm/string/split.hpp>
76+
#include <boost/signals2/signal.hpp>
7677
#include <boost/thread.hpp>
7778

7879
#if ENABLE_ZMQ

src/interfaces/chain.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,9 @@ class NotificationsHandlerImpl : public Handler, CValidationInterface
172172
{
173173
m_notifications->TransactionRemovedFromMempool(tx);
174174
}
175-
void BlockConnected(const std::shared_ptr<const CBlock>& block,
176-
const CBlockIndex* index,
177-
const std::vector<CTransactionRef>& tx_conflicted) override
175+
void BlockConnected(const std::shared_ptr<const CBlock>& block, const CBlockIndex* index) override
178176
{
179-
m_notifications->BlockConnected(*block, tx_conflicted, index->nHeight);
177+
m_notifications->BlockConnected(*block, index->nHeight);
180178
}
181179
void BlockDisconnected(const std::shared_ptr<const CBlock>& block, const CBlockIndex* index) override
182180
{

src/interfaces/chain.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ class Chain
219219
virtual ~Notifications() {}
220220
virtual void TransactionAddedToMempool(const CTransactionRef& tx) {}
221221
virtual void TransactionRemovedFromMempool(const CTransactionRef& ptx) {}
222-
virtual void BlockConnected(const CBlock& block, const std::vector<CTransactionRef>& tx_conflicted, int height) {}
222+
virtual void BlockConnected(const CBlock& block, int height) {}
223223
virtual void BlockDisconnected(const CBlock& block, int height) {}
224224
virtual void UpdatedBlockTip() {}
225225
virtual void ChainStateFlushed(const CBlockLocator& locator) {}

src/interfaces/node.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737

3838
#include <univalue.h>
3939

40+
#include <boost/signals2/signal.hpp>
41+
4042
class CWallet;
4143
fs::path GetWalletDir();
4244
std::vector<fs::path> ListWalletDir();

src/net_processing.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1134,7 +1134,7 @@ PeerLogicValidation::PeerLogicValidation(CConnman* connmanIn, BanMan* banman, CS
11341134
* Evict orphan txn pool entries (EraseOrphanTx) based on a newly connected
11351135
* block. Also save the time of the last tip update.
11361136
*/
1137-
void PeerLogicValidation::BlockConnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindex, const std::vector<CTransactionRef>& vtxConflicted)
1137+
void PeerLogicValidation::BlockConnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindex)
11381138
{
11391139
{
11401140
LOCK(g_cs_orphans);

src/net_processing.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class PeerLogicValidation final : public CValidationInterface, public NetEventsI
3535
/**
3636
* Overridden from CValidationInterface.
3737
*/
38-
void BlockConnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindexConnected, const std::vector<CTransactionRef>& vtxConflicted) override;
38+
void BlockConnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindexConnected) override;
3939
void BlockDisconnected(const std::shared_ptr<const CBlock> &block, const CBlockIndex* pindex) override;
4040
/**
4141
* Overridden from CValidationInterface.

src/test/validation_block_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ struct TestSubscriber : public CValidationInterface {
4242
BOOST_CHECK_EQUAL(m_expected_tip, pindexNew->GetBlockHash());
4343
}
4444

45-
void BlockConnected(const std::shared_ptr<const CBlock>& block, const CBlockIndex* pindex, const std::vector<CTransactionRef>& txnConflicted) override
45+
void BlockConnected(const std::shared_ptr<const CBlock>& block, const CBlockIndex* pindex) override
4646
{
4747
BOOST_CHECK_EQUAL(m_expected_tip, block->hashPrevBlock);
4848
BOOST_CHECK_EQUAL(m_expected_tip, pindex->pprev->GetBlockHash());

src/txmempool.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,6 @@ void CTxMemPool::AddTransactionsUpdated(unsigned int n)
355355

356356
void CTxMemPool::addUnchecked(const CTxMemPoolEntry &entry, setEntries &setAncestors, bool validFeeEstimate)
357357
{
358-
NotifyEntryAdded(entry.GetSharedTx());
359358
// Add to memory pool without checking anything.
360359
// Used by AcceptToMemoryPool(), which DOES do
361360
// all the appropriate checks.
@@ -406,10 +405,12 @@ void CTxMemPool::addUnchecked(const CTxMemPoolEntry &entry, setEntries &setAnces
406405

407406
void CTxMemPool::removeUnchecked(txiter it, MemPoolRemovalReason reason)
408407
{
409-
CTransactionRef ptx = it->GetSharedTx();
410-
NotifyEntryRemoved(ptx, reason);
411-
if (reason != MemPoolRemovalReason::BLOCK && reason != MemPoolRemovalReason::CONFLICT) {
412-
GetMainSignals().TransactionRemovedFromMempool(ptx);
408+
if (reason != MemPoolRemovalReason::BLOCK) {
409+
// Notify clients that a transaction has been removed from the mempool
410+
// for any reason except being included in a block. Clients interested
411+
// in transactions included in blocks can subscribe to the BlockConnected
412+
// notification.
413+
GetMainSignals().TransactionRemovedFromMempool(it->GetSharedTx());
413414
}
414415

415416
const uint256 hash = it->GetTx().GetHash();

0 commit comments

Comments
 (0)