Skip to content

Commit 2584925

Browse files
committed
Merge #10178: Remove CValidationInterface::UpdatedTransaction
9fececb Remove CValidationInterface::UpdatedTransaction (Matt Corallo) d89f8ad Make DisconnectBlock and ConnectBlock static in validation.cpp (Matt Corallo) Tree-SHA512: 146597b538c09c1e8071f4f88ffeba0645c6816f86030b142174bd298cc18ae09a400e6ca8de04d091e37b635f99f4c05982c09e6729691eb8ca6b8439ab97ca
2 parents a077a90 + 9fececb commit 2584925

File tree

6 files changed

+41
-40
lines changed

6 files changed

+41
-40
lines changed

src/validation.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1524,7 +1524,11 @@ bool ApplyTxInUndo(const CTxInUndo& undo, CCoinsViewCache& view, const COutPoint
15241524
return fClean;
15251525
}
15261526

1527-
bool DisconnectBlock(const CBlock& block, CValidationState& state, const CBlockIndex* pindex, CCoinsViewCache& view, bool* pfClean)
1527+
/** Undo the effects of this block (with given index) on the UTXO set represented by coins.
1528+
* In case pfClean is provided, operation will try to be tolerant about errors, and *pfClean
1529+
* will be true if no problems were found. Otherwise, the return value will be false in case
1530+
* of problems. Note that in any case, coins may be modified. */
1531+
static bool DisconnectBlock(const CBlock& block, CValidationState& state, const CBlockIndex* pindex, CCoinsViewCache& view, bool* pfClean = NULL)
15281532
{
15291533
assert(pindex->GetBlockHash() == view.GetBestBlock());
15301534

@@ -1677,8 +1681,11 @@ static int64_t nTimeIndex = 0;
16771681
static int64_t nTimeCallbacks = 0;
16781682
static int64_t nTimeTotal = 0;
16791683

1680-
bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pindex,
1681-
CCoinsViewCache& view, const CChainParams& chainparams, bool fJustCheck)
1684+
/** Apply the effects of this block (with given index) on the UTXO set represented by coins.
1685+
* Validity checks that depend on the UTXO set are also done; ConnectBlock()
1686+
* can fail if those validity checks fail (among other reasons). */
1687+
static bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pindex,
1688+
CCoinsViewCache& view, const CChainParams& chainparams, bool fJustCheck = false)
16821689
{
16831690
AssertLockHeld(cs_main);
16841691
assert(pindex);
@@ -1917,12 +1924,6 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
19171924
int64_t nTime5 = GetTimeMicros(); nTimeIndex += nTime5 - nTime4;
19181925
LogPrint(BCLog::BENCH, " - Index writing: %.2fms [%.2fs]\n", 0.001 * (nTime5 - nTime4), nTimeIndex * 0.000001);
19191926

1920-
// Watch for changes to the previous coinbase transaction.
1921-
static uint256 hashPrevBestCoinBase;
1922-
GetMainSignals().UpdatedTransaction(hashPrevBestCoinBase);
1923-
hashPrevBestCoinBase = block.vtx[0]->GetHash();
1924-
1925-
19261927
int64_t nTime6 = GetTimeMicros(); nTimeCallbacks += nTime6 - nTime5;
19271928
LogPrint(BCLog::BENCH, " - Callbacks: %.2fms [%.2fs]\n", 0.001 * (nTime6 - nTime5), nTimeCallbacks * 0.000001);
19281929

src/validation.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -483,18 +483,6 @@ bool CheckBlock(const CBlock& block, CValidationState& state, const Consensus::P
483483
bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& state, const Consensus::Params& consensusParams, const CBlockIndex* pindexPrev, int64_t nAdjustedTime);
484484
bool ContextualCheckBlock(const CBlock& block, CValidationState& state, const Consensus::Params& consensusParams, const CBlockIndex* pindexPrev);
485485

486-
/** Apply the effects of this block (with given index) on the UTXO set represented by coins.
487-
* Validity checks that depend on the UTXO set are also done; ConnectBlock()
488-
* can fail if those validity checks fail (among other reasons). */
489-
bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pindex, CCoinsViewCache& coins,
490-
const CChainParams& chainparams, bool fJustCheck = false);
491-
492-
/** Undo the effects of this block (with given index) on the UTXO set represented by coins.
493-
* In case pfClean is provided, operation will try to be tolerant about errors, and *pfClean
494-
* will be true if no problems were found. Otherwise, the return value will be false in case
495-
* of problems. Note that in any case, coins may be modified. */
496-
bool DisconnectBlock(const CBlock& block, CValidationState& state, const CBlockIndex* pindex, CCoinsViewCache& coins, bool* pfClean = NULL);
497-
498486
/** Check a block is completely valid from start to finish (only works on top of our current best block, with cs_main held) */
499487
bool TestBlockValidity(CValidationState& state, const CChainParams& chainparams, const CBlock& block, CBlockIndex* pindexPrev, bool fCheckPOW = true, bool fCheckMerkleRoot = true);
500488

src/validationinterface.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ void RegisterValidationInterface(CValidationInterface* pwalletIn) {
1717
g_signals.TransactionAddedToMempool.connect(boost::bind(&CValidationInterface::TransactionAddedToMempool, pwalletIn, _1));
1818
g_signals.BlockConnected.connect(boost::bind(&CValidationInterface::BlockConnected, pwalletIn, _1, _2, _3));
1919
g_signals.BlockDisconnected.connect(boost::bind(&CValidationInterface::BlockDisconnected, pwalletIn, _1));
20-
g_signals.UpdatedTransaction.connect(boost::bind(&CValidationInterface::UpdatedTransaction, pwalletIn, _1));
2120
g_signals.SetBestChain.connect(boost::bind(&CValidationInterface::SetBestChain, pwalletIn, _1));
2221
g_signals.Inventory.connect(boost::bind(&CValidationInterface::Inventory, pwalletIn, _1));
2322
g_signals.Broadcast.connect(boost::bind(&CValidationInterface::ResendWalletTransactions, pwalletIn, _1, _2));
@@ -32,7 +31,6 @@ void UnregisterValidationInterface(CValidationInterface* pwalletIn) {
3231
g_signals.Broadcast.disconnect(boost::bind(&CValidationInterface::ResendWalletTransactions, pwalletIn, _1, _2));
3332
g_signals.Inventory.disconnect(boost::bind(&CValidationInterface::Inventory, pwalletIn, _1));
3433
g_signals.SetBestChain.disconnect(boost::bind(&CValidationInterface::SetBestChain, pwalletIn, _1));
35-
g_signals.UpdatedTransaction.disconnect(boost::bind(&CValidationInterface::UpdatedTransaction, pwalletIn, _1));
3634
g_signals.TransactionAddedToMempool.disconnect(boost::bind(&CValidationInterface::TransactionAddedToMempool, pwalletIn, _1));
3735
g_signals.BlockConnected.disconnect(boost::bind(&CValidationInterface::BlockConnected, pwalletIn, _1, _2, _3));
3836
g_signals.BlockDisconnected.disconnect(boost::bind(&CValidationInterface::BlockDisconnected, pwalletIn, _1));
@@ -46,7 +44,6 @@ void UnregisterAllValidationInterfaces() {
4644
g_signals.Broadcast.disconnect_all_slots();
4745
g_signals.Inventory.disconnect_all_slots();
4846
g_signals.SetBestChain.disconnect_all_slots();
49-
g_signals.UpdatedTransaction.disconnect_all_slots();
5047
g_signals.TransactionAddedToMempool.disconnect_all_slots();
5148
g_signals.BlockConnected.disconnect_all_slots();
5249
g_signals.BlockDisconnected.disconnect_all_slots();

src/validationinterface.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ class CValidationInterface {
3737
virtual void BlockConnected(const std::shared_ptr<const CBlock> &block, const CBlockIndex *pindex, const std::vector<CTransactionRef> &txnConflicted) {}
3838
virtual void BlockDisconnected(const std::shared_ptr<const CBlock> &block) {}
3939
virtual void SetBestChain(const CBlockLocator &locator) {}
40-
virtual void UpdatedTransaction(const uint256 &hash) {}
4140
virtual void Inventory(const uint256 &hash) {}
4241
virtual void ResendWalletTransactions(int64_t nBestBlockTime, CConnman* connman) {}
4342
virtual void BlockChecked(const CBlock&, const CValidationState&) {}
@@ -60,8 +59,6 @@ struct CMainSignals {
6059
boost::signals2::signal<void (const std::shared_ptr<const CBlock> &, const CBlockIndex *pindex, const std::vector<CTransactionRef> &)> BlockConnected;
6160
/** Notifies listeners of a block being disconnected */
6261
boost::signals2::signal<void (const std::shared_ptr<const CBlock> &)> BlockDisconnected;
63-
/** Notifies listeners of an updated transaction without new data (for now: a coinbase potentially becoming visible). */
64-
boost::signals2::signal<void (const uint256 &)> UpdatedTransaction;
6562
/** Notifies listeners of a new active block chain. */
6663
boost::signals2::signal<void (const CBlockLocator &)> SetBestChain;
6764
/** Notifies listeners about an inventory item being seen on the network. */

src/wallet/wallet.cpp

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,6 +1155,33 @@ void CWallet::BlockConnected(const std::shared_ptr<const CBlock>& pblock, const
11551155
for (size_t i = 0; i < pblock->vtx.size(); i++) {
11561156
SyncTransaction(pblock->vtx[i], pindex, i);
11571157
}
1158+
1159+
// The GUI expects a NotifyTransactionChanged when a coinbase tx
1160+
// which is in our wallet moves from in-the-best-block to
1161+
// 2-confirmations (as it only displays them at that time).
1162+
// We do that here.
1163+
if (hashPrevBestCoinbase.IsNull()) {
1164+
// Immediately after restart we have no idea what the coinbase
1165+
// transaction from the previous block is.
1166+
// For correctness we scan over the entire wallet, looking for
1167+
// the previous block's coinbase, just in case it is ours, so
1168+
// that we can notify the UI that it should now be displayed.
1169+
if (pindex->pprev) {
1170+
for (const std::pair<uint256, CWalletTx>& p : mapWallet) {
1171+
if (p.second.IsCoinBase() && p.second.hashBlock == pindex->pprev->GetBlockHash()) {
1172+
NotifyTransactionChanged(this, p.first, CT_UPDATED);
1173+
break;
1174+
}
1175+
}
1176+
}
1177+
} else {
1178+
std::map<uint256, CWalletTx>::const_iterator mi = mapWallet.find(hashPrevBestCoinbase);
1179+
if (mi != mapWallet.end()) {
1180+
NotifyTransactionChanged(this, hashPrevBestCoinbase, CT_UPDATED);
1181+
}
1182+
}
1183+
1184+
hashPrevBestCoinbase = pblock->vtx[0]->GetHash();
11581185
}
11591186

11601187
void CWallet::BlockDisconnected(const std::shared_ptr<const CBlock>& pblock) {
@@ -3383,17 +3410,6 @@ void CWallet::GetAllReserveKeys(std::set<CKeyID>& setAddress) const
33833410
}
33843411
}
33853412

3386-
void CWallet::UpdatedTransaction(const uint256 &hashTx)
3387-
{
3388-
{
3389-
LOCK(cs_wallet);
3390-
// Only notify UI if this transaction is in this wallet
3391-
std::map<uint256, CWalletTx>::const_iterator mi = mapWallet.find(hashTx);
3392-
if (mi != mapWallet.end())
3393-
NotifyTransactionChanged(this, hashTx, CT_UPDATED);
3394-
}
3395-
}
3396-
33973413
void CWallet::GetScriptForMining(std::shared_ptr<CReserveScript> &script)
33983414
{
33993415
std::shared_ptr<CReserveKey> rKey = std::make_shared<CReserveKey>(this);

src/wallet/wallet.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,10 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
713713
*/
714714
bool AddWatchOnly(const CScript& dest) override;
715715

716+
// Used to NotifyTransactionChanged of the previous block's coinbase when
717+
// the next block comes in
718+
uint256 hashPrevBestCoinbase;
719+
716720
public:
717721
/*
718722
* Main wallet lock.
@@ -978,8 +982,6 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
978982

979983
bool DelAddressBook(const CTxDestination& address);
980984

981-
void UpdatedTransaction(const uint256 &hashTx) override;
982-
983985
void Inventory(const uint256 &hash) override
984986
{
985987
{

0 commit comments

Comments
 (0)