Skip to content

Commit 7eaf86d

Browse files
committed
trivial: Suggested cleanups to surrounding code
bitcoin/bitcoin#18982 (review)
1 parent b604c5c commit 7eaf86d

File tree

4 files changed

+24
-28
lines changed

4 files changed

+24
-28
lines changed

src/validationinterface.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -199,22 +199,22 @@ void CMainSignals::UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockInd
199199
fInitialDownload);
200200
}
201201

202-
void CMainSignals::TransactionAddedToMempool(const CTransactionRef &ptx) {
203-
auto event = [ptx, this] {
204-
m_internals->Iterate([&](CValidationInterface& callbacks) { callbacks.TransactionAddedToMempool(ptx); });
202+
void CMainSignals::TransactionAddedToMempool(const CTransactionRef& tx) {
203+
auto event = [tx, this] {
204+
m_internals->Iterate([&](CValidationInterface& callbacks) { callbacks.TransactionAddedToMempool(tx); });
205205
};
206206
ENQUEUE_AND_LOG_EVENT(event, "%s: txid=%s wtxid=%s", __func__,
207-
ptx->GetHash().ToString(),
208-
ptx->GetWitnessHash().ToString());
207+
tx->GetHash().ToString(),
208+
tx->GetWitnessHash().ToString());
209209
}
210210

211-
void CMainSignals::TransactionRemovedFromMempool(const CTransactionRef &ptx, MemPoolRemovalReason reason) {
212-
auto event = [ptx, reason, this] {
213-
m_internals->Iterate([&](CValidationInterface& callbacks) { callbacks.TransactionRemovedFromMempool(ptx, reason); });
211+
void CMainSignals::TransactionRemovedFromMempool(const CTransactionRef& tx, MemPoolRemovalReason reason) {
212+
auto event = [tx, reason, this] {
213+
m_internals->Iterate([&](CValidationInterface& callbacks) { callbacks.TransactionRemovedFromMempool(tx, reason); });
214214
};
215215
ENQUEUE_AND_LOG_EVENT(event, "%s: txid=%s wtxid=%s", __func__,
216-
ptx->GetHash().ToString(),
217-
ptx->GetWitnessHash().ToString());
216+
tx->GetHash().ToString(),
217+
tx->GetWitnessHash().ToString());
218218
}
219219

220220
void CMainSignals::BlockConnected(const std::shared_ptr<const CBlock> &pblock, const CBlockIndex *pindex) {

src/validationinterface.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class CValidationInterface {
9797
*
9898
* Called on a background thread.
9999
*/
100-
virtual void TransactionAddedToMempool(const CTransactionRef &ptxn) {}
100+
virtual void TransactionAddedToMempool(const CTransactionRef& tx) {}
101101
/**
102102
* Notifies listeners of a transaction leaving mempool.
103103
*
@@ -130,7 +130,7 @@ class CValidationInterface {
130130
*
131131
* Called on a background thread.
132132
*/
133-
virtual void TransactionRemovedFromMempool(const CTransactionRef &ptx, MemPoolRemovalReason reason) {}
133+
virtual void TransactionRemovedFromMempool(const CTransactionRef& tx, MemPoolRemovalReason reason) {}
134134
/**
135135
* Notifies listeners of a block being connected.
136136
* Provides a vector of transactions evicted from the mempool as a result.
@@ -197,8 +197,8 @@ class CMainSignals {
197197

198198

199199
void UpdatedBlockTip(const CBlockIndex *, const CBlockIndex *, bool fInitialDownload);
200-
void TransactionAddedToMempool(const CTransactionRef &);
201-
void TransactionRemovedFromMempool(const CTransactionRef &, MemPoolRemovalReason);
200+
void TransactionAddedToMempool(const CTransactionRef&);
201+
void TransactionRemovedFromMempool(const CTransactionRef&, MemPoolRemovalReason);
202202
void BlockConnected(const std::shared_ptr<const CBlock> &, const CBlockIndex *pindex);
203203
void BlockDisconnected(const std::shared_ptr<const CBlock> &, const CBlockIndex* pindex);
204204
void ChainStateFlushed(const CBlockLocator &);

src/wallet/wallet.cpp

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,20 +1101,19 @@ void CWallet::SyncTransaction(const CTransactionRef& ptx, CWalletTx::Confirmatio
11011101
MarkInputsDirty(ptx);
11021102
}
11031103

1104-
void CWallet::transactionAddedToMempool(const CTransactionRef& ptx) {
1104+
void CWallet::transactionAddedToMempool(const CTransactionRef& tx) {
11051105
LOCK(cs_wallet);
1106-
CWalletTx::Confirmation confirm(CWalletTx::Status::UNCONFIRMED, /* block_height */ 0, {}, /* nIndex */ 0);
1107-
SyncTransaction(ptx, confirm);
1106+
SyncTransaction(tx, {CWalletTx::Status::UNCONFIRMED, /* block height */ 0, /* block hash */ {}, /* index */ 0});
11081107

1109-
auto it = mapWallet.find(ptx->GetHash());
1108+
auto it = mapWallet.find(tx->GetHash());
11101109
if (it != mapWallet.end()) {
11111110
it->second.fInMempool = true;
11121111
}
11131112
}
11141113

1115-
void CWallet::transactionRemovedFromMempool(const CTransactionRef &ptx, MemPoolRemovalReason reason) {
1114+
void CWallet::transactionRemovedFromMempool(const CTransactionRef& tx, MemPoolRemovalReason reason) {
11161115
LOCK(cs_wallet);
1117-
auto it = mapWallet.find(ptx->GetHash());
1116+
auto it = mapWallet.find(tx->GetHash());
11181117
if (it != mapWallet.end()) {
11191118
it->second.fInMempool = false;
11201119
}
@@ -1146,7 +1145,7 @@ void CWallet::transactionRemovedFromMempool(const CTransactionRef &ptx, MemPoolR
11461145
// distinguishing between conflicted and unconfirmed transactions are
11471146
// imperfect, and could be improved in general, see
11481147
// https://github.com/bitcoin-core/bitcoin-devwiki/wiki/Wallet-Transaction-Conflict-Tracking
1149-
SyncTransaction(ptx, {CWalletTx::Status::UNCONFIRMED, /* block height */ 0, /* block hash */ {}, /* index */ 0});
1148+
SyncTransaction(tx, {CWalletTx::Status::UNCONFIRMED, /* block height */ 0, /* block hash */ {}, /* index */ 0});
11501149
}
11511150
}
11521151

@@ -1158,8 +1157,7 @@ void CWallet::blockConnected(const CBlock& block, int height)
11581157
m_last_block_processed_height = height;
11591158
m_last_block_processed = block_hash;
11601159
for (size_t index = 0; index < block.vtx.size(); index++) {
1161-
CWalletTx::Confirmation confirm(CWalletTx::Status::CONFIRMED, height, block_hash, index);
1162-
SyncTransaction(block.vtx[index], confirm);
1160+
SyncTransaction(block.vtx[index], {CWalletTx::Status::CONFIRMED, height, block_hash, (int)index});
11631161
transactionRemovedFromMempool(block.vtx[index], MemPoolRemovalReason::BLOCK);
11641162
}
11651163
}
@@ -1175,8 +1173,7 @@ void CWallet::blockDisconnected(const CBlock& block, int height)
11751173
m_last_block_processed_height = height - 1;
11761174
m_last_block_processed = block.hashPrevBlock;
11771175
for (const CTransactionRef& ptx : block.vtx) {
1178-
CWalletTx::Confirmation confirm(CWalletTx::Status::UNCONFIRMED, /* block_height */ 0, {}, /* nIndex */ 0);
1179-
SyncTransaction(ptx, confirm);
1176+
SyncTransaction(ptx, {CWalletTx::Status::UNCONFIRMED, /* block height */ 0, /* block hash */ {}, /* index */ 0});
11801177
}
11811178
}
11821179

@@ -1716,8 +1713,7 @@ CWallet::ScanResult CWallet::ScanForWalletTransactions(const uint256& start_bloc
17161713
break;
17171714
}
17181715
for (size_t posInBlock = 0; posInBlock < block.vtx.size(); ++posInBlock) {
1719-
CWalletTx::Confirmation confirm(CWalletTx::Status::CONFIRMED, block_height, block_hash, posInBlock);
1720-
SyncTransaction(block.vtx[posInBlock], confirm, fUpdate);
1716+
SyncTransaction(block.vtx[posInBlock], {CWalletTx::Status::CONFIRMED, block_height, block_hash, (int)posInBlock}, fUpdate);
17211717
}
17221718
// scan succeeded, record block as most recent successfully scanned
17231719
result.last_scanned_block = block_hash;

src/wallet/wallet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -923,7 +923,7 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati
923923
uint256 last_failed_block;
924924
};
925925
ScanResult ScanForWalletTransactions(const uint256& start_block, int start_height, Optional<int> max_height, const WalletRescanReserver& reserver, bool fUpdate);
926-
void transactionRemovedFromMempool(const CTransactionRef &ptx, MemPoolRemovalReason reason) override;
926+
void transactionRemovedFromMempool(const CTransactionRef& tx, MemPoolRemovalReason reason) override;
927927
void ReacceptWalletTransactions() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
928928
void ResendWalletTransactions();
929929
struct Balance {

0 commit comments

Comments
 (0)