0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-08 10:31:50 -05:00

trivial: Suggested cleanups to surrounding code

https://github.com/bitcoin/bitcoin/pull/18982#pullrequestreview-416974841
This commit is contained in:
Russell Yanofsky 2020-05-22 16:30:07 -04:00
parent b604c5c8b5
commit 7eaf86d3bf
4 changed files with 24 additions and 28 deletions

View file

@ -199,22 +199,22 @@ void CMainSignals::UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockInd
fInitialDownload); fInitialDownload);
} }
void CMainSignals::TransactionAddedToMempool(const CTransactionRef &ptx) { void CMainSignals::TransactionAddedToMempool(const CTransactionRef& tx) {
auto event = [ptx, this] { auto event = [tx, this] {
m_internals->Iterate([&](CValidationInterface& callbacks) { callbacks.TransactionAddedToMempool(ptx); }); m_internals->Iterate([&](CValidationInterface& callbacks) { callbacks.TransactionAddedToMempool(tx); });
}; };
ENQUEUE_AND_LOG_EVENT(event, "%s: txid=%s wtxid=%s", __func__, ENQUEUE_AND_LOG_EVENT(event, "%s: txid=%s wtxid=%s", __func__,
ptx->GetHash().ToString(), tx->GetHash().ToString(),
ptx->GetWitnessHash().ToString()); tx->GetWitnessHash().ToString());
} }
void CMainSignals::TransactionRemovedFromMempool(const CTransactionRef &ptx, MemPoolRemovalReason reason) { void CMainSignals::TransactionRemovedFromMempool(const CTransactionRef& tx, MemPoolRemovalReason reason) {
auto event = [ptx, reason, this] { auto event = [tx, reason, this] {
m_internals->Iterate([&](CValidationInterface& callbacks) { callbacks.TransactionRemovedFromMempool(ptx, reason); }); m_internals->Iterate([&](CValidationInterface& callbacks) { callbacks.TransactionRemovedFromMempool(tx, reason); });
}; };
ENQUEUE_AND_LOG_EVENT(event, "%s: txid=%s wtxid=%s", __func__, ENQUEUE_AND_LOG_EVENT(event, "%s: txid=%s wtxid=%s", __func__,
ptx->GetHash().ToString(), tx->GetHash().ToString(),
ptx->GetWitnessHash().ToString()); tx->GetWitnessHash().ToString());
} }
void CMainSignals::BlockConnected(const std::shared_ptr<const CBlock> &pblock, const CBlockIndex *pindex) { void CMainSignals::BlockConnected(const std::shared_ptr<const CBlock> &pblock, const CBlockIndex *pindex) {

View file

@ -97,7 +97,7 @@ protected:
* *
* Called on a background thread. * Called on a background thread.
*/ */
virtual void TransactionAddedToMempool(const CTransactionRef &ptxn) {} virtual void TransactionAddedToMempool(const CTransactionRef& tx) {}
/** /**
* Notifies listeners of a transaction leaving mempool. * Notifies listeners of a transaction leaving mempool.
* *
@ -130,7 +130,7 @@ protected:
* *
* Called on a background thread. * Called on a background thread.
*/ */
virtual void TransactionRemovedFromMempool(const CTransactionRef &ptx, MemPoolRemovalReason reason) {} virtual void TransactionRemovedFromMempool(const CTransactionRef& tx, MemPoolRemovalReason reason) {}
/** /**
* Notifies listeners of a block being connected. * Notifies listeners of a block being connected.
* Provides a vector of transactions evicted from the mempool as a result. * Provides a vector of transactions evicted from the mempool as a result.

View file

@ -1101,20 +1101,19 @@ void CWallet::SyncTransaction(const CTransactionRef& ptx, CWalletTx::Confirmatio
MarkInputsDirty(ptx); MarkInputsDirty(ptx);
} }
void CWallet::transactionAddedToMempool(const CTransactionRef& ptx) { void CWallet::transactionAddedToMempool(const CTransactionRef& tx) {
LOCK(cs_wallet); LOCK(cs_wallet);
CWalletTx::Confirmation confirm(CWalletTx::Status::UNCONFIRMED, /* block_height */ 0, {}, /* nIndex */ 0); SyncTransaction(tx, {CWalletTx::Status::UNCONFIRMED, /* block height */ 0, /* block hash */ {}, /* index */ 0});
SyncTransaction(ptx, confirm);
auto it = mapWallet.find(ptx->GetHash()); auto it = mapWallet.find(tx->GetHash());
if (it != mapWallet.end()) { if (it != mapWallet.end()) {
it->second.fInMempool = true; it->second.fInMempool = true;
} }
} }
void CWallet::transactionRemovedFromMempool(const CTransactionRef &ptx, MemPoolRemovalReason reason) { void CWallet::transactionRemovedFromMempool(const CTransactionRef& tx, MemPoolRemovalReason reason) {
LOCK(cs_wallet); LOCK(cs_wallet);
auto it = mapWallet.find(ptx->GetHash()); auto it = mapWallet.find(tx->GetHash());
if (it != mapWallet.end()) { if (it != mapWallet.end()) {
it->second.fInMempool = false; it->second.fInMempool = false;
} }
@ -1146,7 +1145,7 @@ void CWallet::transactionRemovedFromMempool(const CTransactionRef &ptx, MemPoolR
// distinguishing between conflicted and unconfirmed transactions are // distinguishing between conflicted and unconfirmed transactions are
// imperfect, and could be improved in general, see // imperfect, and could be improved in general, see
// https://github.com/bitcoin-core/bitcoin-devwiki/wiki/Wallet-Transaction-Conflict-Tracking // https://github.com/bitcoin-core/bitcoin-devwiki/wiki/Wallet-Transaction-Conflict-Tracking
SyncTransaction(ptx, {CWalletTx::Status::UNCONFIRMED, /* block height */ 0, /* block hash */ {}, /* index */ 0}); SyncTransaction(tx, {CWalletTx::Status::UNCONFIRMED, /* block height */ 0, /* block hash */ {}, /* index */ 0});
} }
} }
@ -1158,8 +1157,7 @@ void CWallet::blockConnected(const CBlock& block, int height)
m_last_block_processed_height = height; m_last_block_processed_height = height;
m_last_block_processed = block_hash; m_last_block_processed = block_hash;
for (size_t index = 0; index < block.vtx.size(); index++) { for (size_t index = 0; index < block.vtx.size(); index++) {
CWalletTx::Confirmation confirm(CWalletTx::Status::CONFIRMED, height, block_hash, index); SyncTransaction(block.vtx[index], {CWalletTx::Status::CONFIRMED, height, block_hash, (int)index});
SyncTransaction(block.vtx[index], confirm);
transactionRemovedFromMempool(block.vtx[index], MemPoolRemovalReason::BLOCK); transactionRemovedFromMempool(block.vtx[index], MemPoolRemovalReason::BLOCK);
} }
} }
@ -1175,8 +1173,7 @@ void CWallet::blockDisconnected(const CBlock& block, int height)
m_last_block_processed_height = height - 1; m_last_block_processed_height = height - 1;
m_last_block_processed = block.hashPrevBlock; m_last_block_processed = block.hashPrevBlock;
for (const CTransactionRef& ptx : block.vtx) { for (const CTransactionRef& ptx : block.vtx) {
CWalletTx::Confirmation confirm(CWalletTx::Status::UNCONFIRMED, /* block_height */ 0, {}, /* nIndex */ 0); SyncTransaction(ptx, {CWalletTx::Status::UNCONFIRMED, /* block height */ 0, /* block hash */ {}, /* index */ 0});
SyncTransaction(ptx, confirm);
} }
} }
@ -1716,8 +1713,7 @@ CWallet::ScanResult CWallet::ScanForWalletTransactions(const uint256& start_bloc
break; break;
} }
for (size_t posInBlock = 0; posInBlock < block.vtx.size(); ++posInBlock) { for (size_t posInBlock = 0; posInBlock < block.vtx.size(); ++posInBlock) {
CWalletTx::Confirmation confirm(CWalletTx::Status::CONFIRMED, block_height, block_hash, posInBlock); SyncTransaction(block.vtx[posInBlock], {CWalletTx::Status::CONFIRMED, block_height, block_hash, (int)posInBlock}, fUpdate);
SyncTransaction(block.vtx[posInBlock], confirm, fUpdate);
} }
// scan succeeded, record block as most recent successfully scanned // scan succeeded, record block as most recent successfully scanned
result.last_scanned_block = block_hash; result.last_scanned_block = block_hash;

View file

@ -923,7 +923,7 @@ public:
uint256 last_failed_block; uint256 last_failed_block;
}; };
ScanResult ScanForWalletTransactions(const uint256& start_block, int start_height, Optional<int> max_height, const WalletRescanReserver& reserver, bool fUpdate); ScanResult ScanForWalletTransactions(const uint256& start_block, int start_height, Optional<int> max_height, const WalletRescanReserver& reserver, bool fUpdate);
void transactionRemovedFromMempool(const CTransactionRef &ptx, MemPoolRemovalReason reason) override; void transactionRemovedFromMempool(const CTransactionRef& tx, MemPoolRemovalReason reason) override;
void ReacceptWalletTransactions() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); void ReacceptWalletTransactions() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
void ResendWalletTransactions(); void ResendWalletTransactions();
struct Balance { struct Balance {