Skip to content

Commit

Permalink
Pass oldList and diff instead of newList into NotifyMasternodeListCha…
Browse files Browse the repository at this point in the history
…nged
  • Loading branch information
codablock committed Apr 9, 2019
1 parent 1ba8694 commit db781b3
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/dsnotificationinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ void CDSNotificationInterface::SyncTransaction(const CTransaction &tx, const CBl
CPrivateSend::SyncTransaction(tx, pindex, posInBlock);
}

void CDSNotificationInterface::NotifyMasternodeListChanged(const CDeterministicMNList& newList)
void CDSNotificationInterface::NotifyMasternodeListChanged(bool undo, const CDeterministicMNList& oldMNList, const CDeterministicMNListDiff& diff)
{
CMNAuth::NotifyMasternodeListChanged(newList);
CMNAuth::NotifyMasternodeListChanged(undo, oldMNList, diff);
governance.CheckMasternodeOrphanObjects(connman);
governance.CheckMasternodeOrphanVotes(connman);
governance.UpdateCachesAndClean();
Expand Down
2 changes: 1 addition & 1 deletion src/dsnotificationinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class CDSNotificationInterface : public CValidationInterface
void NotifyHeaderTip(const CBlockIndex *pindexNew, bool fInitialDownload) override;
void UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload) override;
void SyncTransaction(const CTransaction &tx, const CBlockIndex *pindex, int posInBlock) override;
void NotifyMasternodeListChanged(const CDeterministicMNList& newList) override;
void NotifyMasternodeListChanged(bool undo, const CDeterministicMNList& oldMNList, const CDeterministicMNListDiff& diff) override;
void NotifyChainLock(const CBlockIndex* pindex) override;

private:
Expand Down
14 changes: 11 additions & 3 deletions src/evo/deterministicmns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ bool CDeterministicMNManager::ProcessBlock(const CBlock& block, const CBlockInde

// Don't hold cs while calling signals
if (!diff.addedMNs.empty() || !diff.removedMns.empty()) {
GetMainSignals().NotifyMasternodeListChanged(newList);
GetMainSignals().NotifyMasternodeListChanged(false, oldList, diff);
}

const auto& consensusParams = Params().GetConsensus();
Expand All @@ -522,20 +522,28 @@ bool CDeterministicMNManager::UndoBlock(const CBlock& block, const CBlockIndex*
int nHeight = pindex->nHeight;
uint256 blockHash = block.GetHash();

CDeterministicMNList curList;
CDeterministicMNList prevList;
CDeterministicMNListDiff diff;
{
LOCK(cs);
evoDb.Read(std::make_pair(DB_LIST_DIFF, blockHash), diff);

if (diff.HasChanges()) {
// need to call this before erasing
curList = GetListForBlock(blockHash);
prevList = GetListForBlock(pindex->pprev->GetBlockHash());
}

evoDb.Erase(std::make_pair(DB_LIST_DIFF, blockHash));
evoDb.Erase(std::make_pair(DB_LIST_SNAPSHOT, blockHash));

mnListsCache.erase(blockHash);
}

if (!diff.addedMNs.empty() || !diff.removedMns.empty()) {
auto prevList = GetListForBlock(pindex->pprev->GetBlockHash());
GetMainSignals().NotifyMasternodeListChanged(prevList);
auto inversedDiff = curList.BuildDiff(prevList);
GetMainSignals().NotifyMasternodeListChanged(true, curList, inversedDiff);
}

const auto& consensusParams = Params().GetConsensus();
Expand Down
4 changes: 2 additions & 2 deletions src/validationinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void RegisterValidationInterface(CValidationInterface* pwalletIn) {
g_signals.NotifyGovernanceObject.connect(boost::bind(&CValidationInterface::NotifyGovernanceObject, pwalletIn, _1));
g_signals.NotifyGovernanceVote.connect(boost::bind(&CValidationInterface::NotifyGovernanceVote, pwalletIn, _1));
g_signals.NotifyInstantSendDoubleSpendAttempt.connect(boost::bind(&CValidationInterface::NotifyInstantSendDoubleSpendAttempt, pwalletIn, _1, _2));
g_signals.NotifyMasternodeListChanged.connect(boost::bind(&CValidationInterface::NotifyMasternodeListChanged, pwalletIn, _1));
g_signals.NotifyMasternodeListChanged.connect(boost::bind(&CValidationInterface::NotifyMasternodeListChanged, pwalletIn, _1, _2, _3));
}

void UnregisterValidationInterface(CValidationInterface* pwalletIn) {
Expand All @@ -51,7 +51,7 @@ void UnregisterValidationInterface(CValidationInterface* pwalletIn) {
g_signals.NotifyGovernanceObject.disconnect(boost::bind(&CValidationInterface::NotifyGovernanceObject, pwalletIn, _1));
g_signals.NotifyGovernanceVote.disconnect(boost::bind(&CValidationInterface::NotifyGovernanceVote, pwalletIn, _1));
g_signals.NotifyInstantSendDoubleSpendAttempt.disconnect(boost::bind(&CValidationInterface::NotifyInstantSendDoubleSpendAttempt, pwalletIn, _1, _2));
g_signals.NotifyMasternodeListChanged.disconnect(boost::bind(&CValidationInterface::NotifyMasternodeListChanged, pwalletIn, _1));
g_signals.NotifyMasternodeListChanged.disconnect(boost::bind(&CValidationInterface::NotifyMasternodeListChanged, pwalletIn, _1, _2, _3));
}

void UnregisterAllValidationInterfaces() {
Expand Down
5 changes: 3 additions & 2 deletions src/validationinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class CValidationState;
class CGovernanceVote;
class CGovernanceObject;
class CDeterministicMNList;
class CDeterministicMNListDiff;
class uint256;

// These functions dispatch to one or all registered wallets
Expand All @@ -43,7 +44,7 @@ class CValidationInterface {
virtual void NotifyGovernanceVote(const CGovernanceVote &vote) {}
virtual void NotifyGovernanceObject(const CGovernanceObject &object) {}
virtual void NotifyInstantSendDoubleSpendAttempt(const CTransaction &currentTx, const CTransaction &previousTx) {}
virtual void NotifyMasternodeListChanged(const CDeterministicMNList& newList) {}
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) {}
Expand Down Expand Up @@ -86,7 +87,7 @@ struct CMainSignals {
/** Notifies listeners of a attempted InstantSend double spend*/
boost::signals2::signal<void(const CTransaction &currentTx, const CTransaction &previousTx)> NotifyInstantSendDoubleSpendAttempt;
/** Notifies listeners that the MN list changed */
boost::signals2::signal<void(const CDeterministicMNList& newList)> NotifyMasternodeListChanged;
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. */
Expand Down

0 comments on commit db781b3

Please sign in to comment.