Dash related fixes for per-utxo DB

This commit is contained in:
Alexander Block 2017-09-26 16:33:46 +02:00
parent 92bb65894b
commit 9ad56fe18a
6 changed files with 28 additions and 26 deletions

View File

@ -598,8 +598,8 @@ bool CInstantSend::ResolveConflicts(const CTxLockCandidate& txLockCandidate)
} }
// Not in block yet, make sure all its inputs are still unspent // Not in block yet, make sure all its inputs are still unspent
BOOST_FOREACH(const CTxIn& txin, txLockCandidate.txLockRequest.vin) { BOOST_FOREACH(const CTxIn& txin, txLockCandidate.txLockRequest.vin) {
CCoins coins; Coin coin;
if(!GetUTXOCoins(txin.prevout, coins)) { if(!GetUTXOCoin(txin.prevout, coin)) {
// Not in UTXO anymore? A conflicting tx was mined while we were waiting for votes. // Not in UTXO anymore? A conflicting tx was mined while we were waiting for votes.
LogPrintf("CInstantSend::ResolveConflicts -- ERROR: Failed to find UTXO %s, can't complete Transaction Lock\n", txin.prevout.ToStringShort()); LogPrintf("CInstantSend::ResolveConflicts -- ERROR: Failed to find UTXO %s, can't complete Transaction Lock\n", txin.prevout.ToStringShort());
return false; return false;
@ -935,14 +935,14 @@ bool CTxLockRequest::IsValid() const
BOOST_FOREACH(const CTxIn& txin, vin) { BOOST_FOREACH(const CTxIn& txin, vin) {
CCoins coins; Coin coin;
if(!GetUTXOCoins(txin.prevout, coins)) { if(!GetUTXOCoin(txin.prevout, coin)) {
LogPrint("instantsend", "CTxLockRequest::IsValid -- Failed to find UTXO %s\n", txin.prevout.ToStringShort()); LogPrint("instantsend", "CTxLockRequest::IsValid -- Failed to find UTXO %s\n", txin.prevout.ToStringShort());
return false; return false;
} }
int nTxAge = chainActive.Height() - coins.nHeight + 1; int nTxAge = chainActive.Height() - coin.nHeight + 1;
// 1 less than the "send IX" gui requires, in case of a block propagating the network at the time // 1 less than the "send IX" gui requires, in case of a block propagating the network at the time
int nConfirmationsRequired = INSTANTSEND_CONFIRMATIONS_REQUIRED - 1; int nConfirmationsRequired = INSTANTSEND_CONFIRMATIONS_REQUIRED - 1;
@ -952,7 +952,7 @@ bool CTxLockRequest::IsValid() const
return false; return false;
} }
nValueIn += coins.vout[txin.prevout.n].nValue; nValueIn += coin.out.nValue;
} }
if(nValueIn > sporkManager.GetSporkValue(SPORK_5_INSTANTSEND_MAX_VALUE)*COIN) { if(nValueIn > sporkManager.GetSporkValue(SPORK_5_INSTANTSEND_MAX_VALUE)*COIN) {
@ -991,13 +991,13 @@ bool CTxLockVote::IsValid(CNode* pnode, CConnman& connman) const
return false; return false;
} }
CCoins coins; Coin coin;
if(!GetUTXOCoins(outpoint, coins)) { if(!GetUTXOCoin(outpoint, coin)) {
LogPrint("instantsend", "CTxLockVote::IsValid -- Failed to find UTXO %s\n", outpoint.ToStringShort()); LogPrint("instantsend", "CTxLockVote::IsValid -- Failed to find UTXO %s\n", outpoint.ToStringShort());
return false; return false;
} }
int nLockInputHeight = coins.nHeight + 4; int nLockInputHeight = coin.nHeight + 4;
int nRank; int nRank;
if(!mnodeman.GetMasternodeRank(outpointMasternode, nRank, nLockInputHeight, MIN_INSTANTSEND_PROTO_VERSION)) { if(!mnodeman.GetMasternodeRank(outpointMasternode, nRank, nLockInputHeight, MIN_INSTANTSEND_PROTO_VERSION)) {

View File

@ -123,16 +123,16 @@ CMasternode::CollateralStatus CMasternode::CheckCollateral(const COutPoint& outp
{ {
AssertLockHeld(cs_main); AssertLockHeld(cs_main);
CCoins coins; Coin coin;
if(!GetUTXOCoins(outpoint, coins)) { if(!GetUTXOCoin(outpoint, coin)) {
return COLLATERAL_UTXO_NOT_FOUND; return COLLATERAL_UTXO_NOT_FOUND;
} }
if(coins.vout[outpoint.n].nValue != 1000 * COIN) { if(coin.out.nValue != 1000 * COIN) {
return COLLATERAL_INVALID_AMOUNT; return COLLATERAL_INVALID_AMOUNT;
} }
nHeightRet = coins.nHeight; nHeightRet = coin.nHeight;
return COLLATERAL_OK; return COLLATERAL_OK;
} }

View File

@ -193,9 +193,9 @@ void CPrivateSendServer::ProcessMessage(CNode* pfrom, std::string& strCommand, C
LogPrint("privatesend", "DSVIN -- txin=%s\n", txin.ToString()); LogPrint("privatesend", "DSVIN -- txin=%s\n", txin.ToString());
CCoins coins; Coin coin;
if(GetUTXOCoins(txin.prevout, coins)) { if(GetUTXOCoin(txin.prevout, coin)) {
nValueIn += coins.vout[txin.prevout.n].nValue; nValueIn += coin.out.nValue;
} else { } else {
LogPrintf("DSVIN -- missing input! tx=%s", tx.ToString()); LogPrintf("DSVIN -- missing input! tx=%s", tx.ToString());
PushStatus(pfrom, STATUS_REJECTED, ERR_MISSING_TX, connman); PushStatus(pfrom, STATUS_REJECTED, ERR_MISSING_TX, connman);

View File

@ -189,12 +189,12 @@ bool CPrivateSend::IsCollateralValid(const CTransaction& txCollateral)
} }
BOOST_FOREACH(const CTxIn txin, txCollateral.vin) { BOOST_FOREACH(const CTxIn txin, txCollateral.vin) {
CCoins coins; Coin coin;
if(!GetUTXOCoins(txin.prevout, coins)) { if(!GetUTXOCoin(txin.prevout, coin)) {
LogPrint("privatesend", "CPrivateSend::IsCollateralValid -- Unknown inputs in collateral transaction, txCollateral=%s", txCollateral.ToString()); LogPrint("privatesend", "CPrivateSend::IsCollateralValid -- Unknown inputs in collateral transaction, txCollateral=%s", txCollateral.ToString());
return false; return false;
} }
nValueIn += coins.vout[txin.prevout.n].nValue; nValueIn += coin.out.nValue;
} }
//collateral transactions are required to pay out a small fee to the miners //collateral transactions are required to pay out a small fee to the miners

View File

@ -443,19 +443,21 @@ unsigned int GetP2SHSigOpCount(const CTransaction& tx, const CCoinsViewCache& in
return nSigOps; return nSigOps;
} }
bool GetUTXOCoins(const COutPoint& outpoint, CCoins& coins) bool GetUTXOCoin(const COutPoint& outpoint, Coin& coin)
{ {
LOCK(cs_main); LOCK(cs_main);
return !(!pcoinsTip->GetCoins(outpoint.hash, coins) || if (!pcoinsTip->GetCoin(outpoint, coin))
(unsigned int)outpoint.n>=coins.vout.size() || return false;
coins.vout[outpoint.n].IsNull()); if (coin.IsSpent())
return false;
return true;
} }
int GetUTXOHeight(const COutPoint& outpoint) int GetUTXOHeight(const COutPoint& outpoint)
{ {
// -1 means UTXO is yet unknown or already spent // -1 means UTXO is yet unknown or already spent
CCoins coins; Coin coin;
return GetUTXOCoins(outpoint, coins) ? coins.nHeight : -1; return GetUTXOCoin(outpoint, coin) ? coin.nHeight : -1;
} }
int GetUTXOConfirmations(const COutPoint& outpoint) int GetUTXOConfirmations(const COutPoint& outpoint)

View File

@ -300,7 +300,7 @@ void PruneAndFlush();
bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransaction &tx, bool fLimitFree, bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransaction &tx, bool fLimitFree,
bool* pfMissingInputs, bool fOverrideMempoolLimit=false, bool fRejectAbsurdFee=false, bool fDryRun=false); bool* pfMissingInputs, bool fOverrideMempoolLimit=false, bool fRejectAbsurdFee=false, bool fDryRun=false);
bool GetUTXOCoins(const COutPoint& outpoint, CCoins& coins); bool GetUTXOCoin(const COutPoint& outpoint, Coin& coin);
int GetUTXOHeight(const COutPoint& outpoint); int GetUTXOHeight(const COutPoint& outpoint);
int GetUTXOConfirmations(const COutPoint& outpoint); int GetUTXOConfirmations(const COutPoint& outpoint);