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
BOOST_FOREACH(const CTxIn& txin, txLockCandidate.txLockRequest.vin) {
CCoins coins;
if(!GetUTXOCoins(txin.prevout, coins)) {
Coin coin;
if(!GetUTXOCoin(txin.prevout, coin)) {
// 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());
return false;
@ -935,14 +935,14 @@ bool CTxLockRequest::IsValid() const
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());
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
int nConfirmationsRequired = INSTANTSEND_CONFIRMATIONS_REQUIRED - 1;
@ -952,7 +952,7 @@ bool CTxLockRequest::IsValid() const
return false;
}
nValueIn += coins.vout[txin.prevout.n].nValue;
nValueIn += coin.out.nValue;
}
if(nValueIn > sporkManager.GetSporkValue(SPORK_5_INSTANTSEND_MAX_VALUE)*COIN) {
@ -991,13 +991,13 @@ bool CTxLockVote::IsValid(CNode* pnode, CConnman& connman) const
return false;
}
CCoins coins;
if(!GetUTXOCoins(outpoint, coins)) {
Coin coin;
if(!GetUTXOCoin(outpoint, coin)) {
LogPrint("instantsend", "CTxLockVote::IsValid -- Failed to find UTXO %s\n", outpoint.ToStringShort());
return false;
}
int nLockInputHeight = coins.nHeight + 4;
int nLockInputHeight = coin.nHeight + 4;
int nRank;
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);
CCoins coins;
if(!GetUTXOCoins(outpoint, coins)) {
Coin coin;
if(!GetUTXOCoin(outpoint, coin)) {
return COLLATERAL_UTXO_NOT_FOUND;
}
if(coins.vout[outpoint.n].nValue != 1000 * COIN) {
if(coin.out.nValue != 1000 * COIN) {
return COLLATERAL_INVALID_AMOUNT;
}
nHeightRet = coins.nHeight;
nHeightRet = coin.nHeight;
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());
CCoins coins;
if(GetUTXOCoins(txin.prevout, coins)) {
nValueIn += coins.vout[txin.prevout.n].nValue;
Coin coin;
if(GetUTXOCoin(txin.prevout, coin)) {
nValueIn += coin.out.nValue;
} else {
LogPrintf("DSVIN -- missing input! tx=%s", tx.ToString());
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) {
CCoins coins;
if(!GetUTXOCoins(txin.prevout, coins)) {
Coin coin;
if(!GetUTXOCoin(txin.prevout, coin)) {
LogPrint("privatesend", "CPrivateSend::IsCollateralValid -- Unknown inputs in collateral transaction, txCollateral=%s", txCollateral.ToString());
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

View File

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