Skip to content

Commit

Permalink
Merge bitcoin#10178: Remove CValidationInterface::UpdatedTransaction
Browse files Browse the repository at this point in the history
9fececb Remove CValidationInterface::UpdatedTransaction (Matt Corallo)
d89f8ad Make DisconnectBlock and ConnectBlock static in validation.cpp (Matt Corallo)

Tree-SHA512: 146597b538c09c1e8071f4f88ffeba0645c6816f86030b142174bd298cc18ae09a400e6ca8de04d091e37b635f99f4c05982c09e6729691eb8ca6b8439ab97ca

undo unintended change
  • Loading branch information
laanwj authored and PastaPastaPasta committed Jun 15, 2019
1 parent 6332310 commit d28cbd8
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 29 deletions.
11 changes: 4 additions & 7 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1582,8 +1582,10 @@ int ApplyTxInUndo(Coin&& undo, CCoinsViewCache& view, const COutPoint& out)
}

/** Undo the effects of this block (with given index) on the UTXO set represented by coins.
* When UNCLEAN or FAILED is returned, view is left in an indeterminate state. */
static DisconnectResult DisconnectBlock(const CBlock& block, CValidationState& state, const CBlockIndex* pindex, CCoinsViewCache& view)
* In case pfClean is provided, operation will try to be tolerant about errors, and *pfClean
* will be true if no problems were found. Otherwise, the return value will be FAILED in case
* of problems. Note that in any case, coins may be modified. */
static DisconnectResult DisconnectBlock(const CBlock& block, CValidationState& state, const CBlockIndex* pindex, CCoinsViewCache& view, bool* pfClean = NULL)
{
assert(pindex->GetBlockHash() == view.GetBestBlock());

Expand Down Expand Up @@ -2313,11 +2315,6 @@ static bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockInd
int64_t nTime6 = GetTimeMicros(); nTimeIndex += nTime6 - nTime5;
LogPrint(BCLog::BENCHMARK, " - Index writing: %.2fms [%.2fs]\n", 0.001 * (nTime6 - nTime5), nTimeIndex * 0.000001);

// Watch for changes to the previous coinbase transaction.
static uint256 hashPrevBestCoinBase;
GetMainSignals().UpdatedTransaction(hashPrevBestCoinBase);
hashPrevBestCoinBase = block.vtx[0]->GetHash();

evoDb->WriteBestBlock(pindex->GetBlockHash());

int64_t nTime7 = GetTimeMicros(); nTimeCallbacks += nTime7 - nTime6;
Expand Down
3 changes: 0 additions & 3 deletions src/validationinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ void RegisterValidationInterface(CValidationInterface* pwalletIn) {
g_signals.BlockDisconnected.connect(boost::bind(&CValidationInterface::BlockDisconnected, pwalletIn, _1, _2));
g_signals.NotifyTransactionLock.connect(boost::bind(&CValidationInterface::NotifyTransactionLock, pwalletIn, _1, _2));
g_signals.NotifyChainLock.connect(boost::bind(&CValidationInterface::NotifyChainLock, pwalletIn, _1, _2));
g_signals.UpdatedTransaction.connect(boost::bind(&CValidationInterface::UpdatedTransaction, pwalletIn, _1));
g_signals.SetBestChain.connect(boost::bind(&CValidationInterface::SetBestChain, pwalletIn, _1));
g_signals.Inventory.connect(boost::bind(&CValidationInterface::Inventory, pwalletIn, _1));
g_signals.Broadcast.connect(boost::bind(&CValidationInterface::ResendWalletTransactions, pwalletIn, _1, _2));
Expand All @@ -40,7 +39,6 @@ void UnregisterValidationInterface(CValidationInterface* pwalletIn) {
g_signals.Broadcast.disconnect(boost::bind(&CValidationInterface::ResendWalletTransactions, pwalletIn, _1, _2));
g_signals.Inventory.disconnect(boost::bind(&CValidationInterface::Inventory, pwalletIn, _1));
g_signals.SetBestChain.disconnect(boost::bind(&CValidationInterface::SetBestChain, pwalletIn, _1));
g_signals.UpdatedTransaction.disconnect(boost::bind(&CValidationInterface::UpdatedTransaction, pwalletIn, _1));
g_signals.NotifyChainLock.disconnect(boost::bind(&CValidationInterface::NotifyChainLock, pwalletIn, _1, _2));
g_signals.NotifyTransactionLock.disconnect(boost::bind(&CValidationInterface::NotifyTransactionLock, pwalletIn, _1, _2));
g_signals.TransactionAddedToMempool.disconnect(boost::bind(&CValidationInterface::TransactionAddedToMempool, pwalletIn, _1));
Expand All @@ -62,7 +60,6 @@ void UnregisterAllValidationInterfaces() {
g_signals.Broadcast.disconnect_all_slots();
g_signals.Inventory.disconnect_all_slots();
g_signals.SetBestChain.disconnect_all_slots();
g_signals.UpdatedTransaction.disconnect_all_slots();
g_signals.NotifyTransactionLock.disconnect_all_slots();
g_signals.NotifyChainLock.disconnect_all_slots();
g_signals.TransactionAddedToMempool.disconnect_all_slots();
Expand Down
3 changes: 0 additions & 3 deletions src/validationinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ class CValidationInterface {
virtual void NotifyInstantSendDoubleSpendAttempt(const CTransaction &currentTx, const CTransaction &previousTx) {}
virtual void NotifyMasternodeListChanged(bool undo, const CDeterministicMNList& oldMNList, const CDeterministicMNListDiff& diff) {}
virtual void SetBestChain(const CBlockLocator &locator) {}
virtual bool UpdatedTransaction(const uint256 &hash) { return false;}
virtual void Inventory(const uint256 &hash) {}
virtual void ResendWalletTransactions(int64_t nBestBlockTime, CConnman* connman) {}
virtual void BlockChecked(const CBlock&, const CValidationState&) {}
Expand Down Expand Up @@ -92,8 +91,6 @@ struct CMainSignals {
boost::signals2::signal<void(const CTransaction &currentTx, const CTransaction &previousTx)> NotifyInstantSendDoubleSpendAttempt;
/** Notifies listeners that the MN list changed */
boost::signals2::signal<void(bool undo, const CDeterministicMNList& oldMNList, const CDeterministicMNListDiff& diff)> NotifyMasternodeListChanged;
/** Notifies listeners of an updated transaction without new data (for now: a coinbase potentially becoming visible). */
boost::signals2::signal<bool (const uint256 &)> UpdatedTransaction;
/** Notifies listeners of a new active block chain. */
boost::signals2::signal<void (const CBlockLocator &)> SetBestChain;
/** Notifies listeners about an inventory item being seen on the network. */
Expand Down
41 changes: 27 additions & 14 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1331,6 +1331,33 @@ void CWallet::BlockConnected(const std::shared_ptr<const CBlock>& pblock, const
for (size_t i = 0; i < pblock->vtx.size(); i++) {
SyncTransaction(pblock->vtx[i], pindex, i);
}

// The GUI expects a NotifyTransactionChanged when a coinbase tx
// which is in our wallet moves from in-the-best-block to
// 2-confirmations (as it only displays them at that time).
// We do that here.
if (hashPrevBestCoinbase.IsNull()) {
// Immediately after restart we have no idea what the coinbase
// transaction from the previous block is.
// For correctness we scan over the entire wallet, looking for
// the previous block's coinbase, just in case it is ours, so
// that we can notify the UI that it should now be displayed.
if (pindex->pprev) {
for (const std::pair<uint256, CWalletTx>& p : mapWallet) {
if (p.second.IsCoinBase() && p.second.hashBlock == pindex->pprev->GetBlockHash()) {
NotifyTransactionChanged(this, p.first, CT_UPDATED);
break;
}
}
}
} else {
std::map<uint256, CWalletTx>::const_iterator mi = mapWallet.find(hashPrevBestCoinbase);
if (mi != mapWallet.end()) {
NotifyTransactionChanged(this, hashPrevBestCoinbase, CT_UPDATED);
}
}

hashPrevBestCoinbase = pblock->vtx[0]->GetHash();
}

void CWallet::BlockDisconnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindexDisconnected) {
Expand Down Expand Up @@ -4468,20 +4495,6 @@ void CWallet::GetAllReserveKeys(std::set<CKeyID>& setAddress) const
}
}

bool CWallet::UpdatedTransaction(const uint256 &hashTx)
{
{
LOCK(cs_wallet);
// Only notify UI if this transaction is in this wallet
std::map<uint256, CWalletTx>::const_iterator mi = mapWallet.find(hashTx);
if (mi != mapWallet.end()){
NotifyTransactionChanged(this, hashTx, CT_UPDATED);
return true;
}
}
return false;
}

void CWallet::GetScriptForMining(std::shared_ptr<CReserveScript> &script)
{
std::shared_ptr<CReserveKey> rKey = std::make_shared<CReserveKey>(this);
Expand Down
6 changes: 4 additions & 2 deletions src/wallet/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,10 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface

std::unique_ptr<CWalletDBWrapper> dbw;

// Used to NotifyTransactionChanged of the previous block's coinbase when
// the next block comes in
uint256 hashPrevBestCoinbase;

public:
/*
* Main wallet lock.
Expand Down Expand Up @@ -1085,8 +1089,6 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface

bool DelAddressBook(const CTxDestination& address);

bool UpdatedTransaction(const uint256 &hashTx) override;

void Inventory(const uint256 &hash) override
{
{
Expand Down

0 comments on commit d28cbd8

Please sign in to comment.