Skip to content

Commit 38b92b9

Browse files
committed
init: improve dmn collateral locking.
1) Walk-through the DMN list only once instead of one-time per wallet. 2) Remove wallet dependency on evo/deterministicmns.h.
1 parent 918db4e commit 38b92b9

File tree

4 files changed

+15
-22
lines changed

4 files changed

+15
-22
lines changed

src/init.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1750,10 +1750,13 @@ bool AppInitMain()
17501750

17511751
// automatic lock for DMN
17521752
if (gArgs.GetBoolArg("-mnconflock", DEFAULT_MNCONFLOCK)) {
1753+
LogPrintf("Locking masternode collaterals...\n");
17531754
const auto& mnList = deterministicMNManager->GetListAtChainTip();
1754-
for (CWallet* pwallet : vpwallets) {
1755-
pwallet->ScanMasternodeCollateralsAndLock(mnList);
1756-
}
1755+
mnList.ForEachMN(false, [&](const CDeterministicMNCPtr& dmn) {
1756+
for (CWallet* pwallet : vpwallets) {
1757+
pwallet->LockOutpointIfMineWithMutex(nullptr, dmn->collateralOutpoint);
1758+
}
1759+
});
17571760
}
17581761
#endif
17591762

src/wallet/wallet.cpp

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
#include "checkpoints.h"
1515
#include "coincontrol.h"
16-
#include "evo/deterministicmns.h"
16+
#include "evo/providertx.h"
1717
#include "guiinterfaceutil.h"
1818
#include "masternode.h"
1919
#include "policy/policy.h"
@@ -4121,6 +4121,11 @@ void CWallet::AutoCombineDust(CConnman* connman)
41214121
}
41224122
}
41234123

4124+
void CWallet::LockOutpointIfMineWithMutex(const CTransactionRef& ptx, const COutPoint& c)
4125+
{
4126+
WITH_LOCK(cs_wallet, LockOutpointIfMine(ptx, c));
4127+
}
4128+
41244129
void CWallet::LockOutpointIfMine(const CTransactionRef& ptx, const COutPoint& c)
41254130
{
41264131
AssertLockHeld(cs_wallet);
@@ -4140,17 +4145,6 @@ void CWallet::LockOutpointIfMine(const CTransactionRef& ptx, const COutPoint& c)
41404145
}
41414146
}
41424147

4143-
// Called during Init
4144-
void CWallet::ScanMasternodeCollateralsAndLock(const CDeterministicMNList& mnList)
4145-
{
4146-
LOCK(cs_wallet);
4147-
4148-
LogPrintf("Locking masternode collaterals...\n");
4149-
mnList.ForEachMN(false, [&](const CDeterministicMNCPtr& dmn) {
4150-
LockOutpointIfMine(nullptr, dmn->collateralOutpoint);
4151-
});
4152-
}
4153-
41544148
// Called from AddToWalletIfInvolvingMe
41554149
void CWallet::LockIfMyCollateral(const CTransactionRef& ptx)
41564150
{

src/wallet/wallet.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ class ScriptPubKeyMan;
9999
class SaplingScriptPubKeyMan;
100100
class SaplingNoteData;
101101
struct SaplingNoteEntry;
102-
class CDeterministicMNList;
103102

104103
/** (client) version numbers for particular wallet features */
105104
enum WalletFeature {
@@ -886,13 +885,11 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
886885
* -- If ptx is null, c is the output of a transaction in mapWallet
887886
*/
888887
void LockOutpointIfMine(const CTransactionRef& ptx, const COutPoint& c);
889-
890888
/*
891-
* Locks cs_wallet
892-
* Called during Init. If a DMN collateral is found in the wallet,
893-
* lock the corresponding coin, to prevent accidental spending.
889+
* Same functionality as above but locking the cs_wallet mutex internally.
890+
* future: add capability to lock the mutex from outside of this class without exposing it.
894891
*/
895-
void ScanMasternodeCollateralsAndLock(const CDeterministicMNList& mnList);
892+
void LockOutpointIfMineWithMutex(const CTransactionRef& ptx, const COutPoint& c);
896893

897894
/*
898895
* Requires cs_wallet lock.

test/lint/lint-circular-dependencies.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ EXPECTED_CIRCULAR_DEPENDENCIES=(
4343
"chain -> legacy/stakemodifier -> stakeinput -> chain"
4444
"chain -> legacy/stakemodifier -> validation -> chain"
4545
"chainparamsbase -> util/system -> logging -> chainparamsbase"
46-
"evo/deterministicmns -> masternode -> wallet/wallet -> evo/deterministicmns"
4746
"kernel -> stakeinput -> wallet/wallet -> kernel"
4847
"legacy/validation_zerocoin_legacy -> wallet/wallet -> validation -> legacy/validation_zerocoin_legacy"
4948
"qt/askpassphrasedialog -> qt/pivx/pivxgui -> qt/pivx/topbar -> qt/askpassphrasedialog"

0 commit comments

Comments
 (0)