Skip to content

Commit 45f34e1

Browse files
committed
Implement HasValidMN, HasValidMNByCollateral and GetValidMNByCollateral
1 parent bc29fe1 commit 45f34e1

File tree

4 files changed

+31
-22
lines changed

4 files changed

+31
-22
lines changed

src/evo/deterministicmns.cpp

+9-14
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,15 @@ CDeterministicMNCPtr CDeterministicMNList::GetMNByCollateral(const COutPoint& co
151151
return GetUniquePropertyMN(collateralOutpoint);
152152
}
153153

154+
CDeterministicMNCPtr CDeterministicMNList::GetValidMNByCollateral(const COutPoint& collateralOutpoint) const
155+
{
156+
auto dmn = GetMNByCollateral(collateralOutpoint);
157+
if (dmn && !IsMNValid(dmn)) {
158+
return nullptr;
159+
}
160+
return dmn;
161+
}
162+
154163
static int CompareByLastPaid_GetHeight(const CDeterministicMN& dmn)
155164
{
156165
int height = dmn.pdmnState->nLastPaidHeight;
@@ -826,20 +835,6 @@ CDeterministicMNList CDeterministicMNManager::GetListAtChainTip()
826835
return GetListForBlock(tipBlockHash);
827836
}
828837

829-
bool CDeterministicMNManager::HasValidMNCollateralAtChainTip(const COutPoint& outpoint)
830-
{
831-
auto mnList = GetListAtChainTip();
832-
auto dmn = mnList.GetMNByCollateral(outpoint);
833-
return dmn && mnList.IsMNValid(dmn);
834-
}
835-
836-
bool CDeterministicMNManager::HasMNCollateralAtChainTip(const COutPoint& outpoint)
837-
{
838-
auto mnList = GetListAtChainTip();
839-
auto dmn = mnList.GetMNByCollateral(outpoint);
840-
return dmn != nullptr;
841-
}
842-
843838
bool CDeterministicMNManager::IsProTxWithCollateral(const CTransactionRef& tx, uint32_t n)
844839
{
845840
if (tx->nVersion != 3 || tx->nType != TRANSACTION_PROVIDER_REGISTER) {

src/evo/deterministicmns.h

+13-4
Original file line numberDiff line numberDiff line change
@@ -289,10 +289,23 @@ class CDeterministicMNList
289289
{
290290
return GetMN(proTxHash) != nullptr;
291291
}
292+
bool HasValidMN(const uint256& proTxHash) const
293+
{
294+
return GetValidMN(proTxHash) != nullptr;
295+
}
296+
bool HasMNByCollateral(const COutPoint& collateralOutpoint) const
297+
{
298+
return GetMNByCollateral(collateralOutpoint) != nullptr;
299+
}
300+
bool HasValidMNByCollateral(const COutPoint& collateralOutpoint) const
301+
{
302+
return GetValidMNByCollateral(collateralOutpoint) != nullptr;
303+
}
292304
CDeterministicMNCPtr GetMN(const uint256& proTxHash) const;
293305
CDeterministicMNCPtr GetValidMN(const uint256& proTxHash) const;
294306
CDeterministicMNCPtr GetMNByOperatorKey(const CBLSPublicKey& pubKey);
295307
CDeterministicMNCPtr GetMNByCollateral(const COutPoint& collateralOutpoint) const;
308+
CDeterministicMNCPtr GetValidMNByCollateral(const COutPoint& collateralOutpoint) const;
296309
CDeterministicMNCPtr GetMNPayee() const;
297310

298311
/**
@@ -479,10 +492,6 @@ class CDeterministicMNManager
479492
CDeterministicMNList GetListForBlock(const uint256& blockHash);
480493
CDeterministicMNList GetListAtChainTip();
481494

482-
// TODO remove after removal of old non-deterministic lists
483-
bool HasValidMNCollateralAtChainTip(const COutPoint& outpoint);
484-
bool HasMNCollateralAtChainTip(const COutPoint& outpoint);
485-
486495
// Test if given TX is a ProRegTx which also contains the collateral at index n
487496
bool IsProTxWithCollateral(const CTransactionRef& tx, uint32_t n);
488497

src/masternodeman.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ bool CMasternodeMan::Has(const COutPoint& outpoint)
643643
{
644644
LOCK(cs);
645645
if (deterministicMNManager->IsDIP3Active()) {
646-
return deterministicMNManager->HasValidMNCollateralAtChainTip(outpoint);
646+
return deterministicMNManager->GetListAtChainTip().HasValidMNByCollateral(outpoint);
647647
} else {
648648
return mapMasternodes.find(outpoint) != mapMasternodes.end();
649649
}

src/wallet/wallet.cpp

+8-3
Original file line numberDiff line numberDiff line change
@@ -1121,10 +1121,11 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFlushOnClose)
11211121
}
11221122
AddToSpends(hash);
11231123

1124+
auto mnList = deterministicMNManager->GetListAtChainTip();
11241125
for(unsigned int i = 0; i < wtx.tx->vout.size(); ++i) {
11251126
if (IsMine(wtx.tx->vout[i]) && !IsSpent(hash, i)) {
11261127
setWalletUTXO.insert(COutPoint(hash, i));
1127-
if (deterministicMNManager->IsProTxWithCollateral(wtx.tx, i) || deterministicMNManager->HasMNCollateralAtChainTip(COutPoint(hash, i))) {
1128+
if (deterministicMNManager->IsProTxWithCollateral(wtx.tx, i) || mnList.HasMNByCollateral(COutPoint(hash, i))) {
11281129
LockCoin(COutPoint(hash, i));
11291130
}
11301131
}
@@ -3989,11 +3990,13 @@ DBErrors CWallet::LoadWallet(bool& fFirstRunRet)
39893990
// This avoids accidential spending of collaterals. They can still be unlocked manually if a spend is really intended.
39903991
void CWallet::AutoLockMasternodeCollaterals()
39913992
{
3993+
auto mnList = deterministicMNManager->GetListAtChainTip();
3994+
39923995
LOCK2(cs_main, cs_wallet);
39933996
for (const auto& pair : mapWallet) {
39943997
for (unsigned int i = 0; i < pair.second.tx->vout.size(); ++i) {
39953998
if (IsMine(pair.second.tx->vout[i]) && !IsSpent(pair.first, i)) {
3996-
if (deterministicMNManager->IsProTxWithCollateral(pair.second.tx, i) || deterministicMNManager->HasMNCollateralAtChainTip(COutPoint(pair.first, i))) {
3999+
if (deterministicMNManager->IsProTxWithCollateral(pair.second.tx, i) || mnList.HasMNByCollateral(COutPoint(pair.first, i))) {
39974000
LockCoin(COutPoint(pair.first, i));
39984001
}
39994002
}
@@ -4643,11 +4646,13 @@ void CWallet::ListLockedCoins(std::vector<COutPoint>& vOutpts)
46434646

46444647
void CWallet::ListProTxCoins(std::vector<COutPoint>& vOutpts)
46454648
{
4649+
auto mnList = deterministicMNManager->GetListAtChainTip();
4650+
46464651
AssertLockHeld(cs_wallet);
46474652
for (const auto &o : setWalletUTXO) {
46484653
if (mapWallet.count(o.hash)) {
46494654
const auto &p = mapWallet[o.hash];
4650-
if (deterministicMNManager->IsProTxWithCollateral(p.tx, o.n) || deterministicMNManager->HasMNCollateralAtChainTip(o)) {
4655+
if (deterministicMNManager->IsProTxWithCollateral(p.tx, o.n) || mnList.HasMNByCollateral(o)) {
46514656
vOutpts.emplace_back(o);
46524657
}
46534658
}

0 commit comments

Comments
 (0)