Skip to content

Commit

Permalink
repair bad tx's in repairwallet
Browse files Browse the repository at this point in the history
add code to fixspentcoins to check for coins that are not final and not
confirmed, and allow them to be deleted by repairwallet.

This commit also changes IsConfirmed() to not automatically assume that
if it is in our db then it is confirmed.
  • Loading branch information
presstab committed Nov 18, 2014
1 parent 6bfe1dd commit 76fca01
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 32 deletions.
15 changes: 15 additions & 0 deletions src/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2327,6 +2327,21 @@ void CWallet::FixSpentCoins(int& nMismatchFound, int64& nBalanceInQuestion, int&
BOOST_FOREACH(CWalletTx* pcoin, vCoins)
{
uint256 hash = pcoin->GetHash();

// presstab HyperStake
// This finds and deletes transactions that were never accepted by the network
// needs to be located above the readtxindex code or else it will not be triggered
if(!pcoin->IsFinal() || !pcoin->IsConfirmed())
{
nOrphansFound++;
if (!fCheckOnly)
{
EraseFromWallet(hash);
NotifyTransactionChanged(this, hash, CT_DELETED);
}
printf("FixSpentCoins %s orphaned transaction %s\n", fCheckOnly ? "found" : "removed", hash.ToString().c_str());
}

// Find the corresponding transaction index
CTxIndex txindex;
if (!txdb.ReadTxIndex(hash, txindex) && !(pcoin->IsCoinBase() || pcoin->IsCoinStake()))
Expand Down
36 changes: 4 additions & 32 deletions src/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -681,38 +681,10 @@ class CWalletTx : public CMerkleTx
return true;
if (!IsFromMe()) // using wtx's cached debit
return false;

// If no confirmations but it's from us, we can still
// consider it confirmed if all dependencies are confirmed
std::map<uint256, const CMerkleTx*> mapPrev;
std::vector<const CMerkleTx*> vWorkQueue;
vWorkQueue.reserve(vtxPrev.size()+1);
vWorkQueue.push_back(this);
for (unsigned int i = 0; i < vWorkQueue.size(); i++)
{
const CMerkleTx* ptx = vWorkQueue[i];

if (!ptx->IsFinal())
return false;
if (ptx->GetDepthInMainChain() >= 1)
continue;
if (!pwallet->IsFromMe(*ptx))
return false;

if (mapPrev.empty())
{
BOOST_FOREACH(const CMerkleTx& tx, vtxPrev)
mapPrev[tx.GetHash()] = &tx;
}

BOOST_FOREACH(const CTxIn& txin, ptx->vin)
{
if (!mapPrev.count(txin.prevout.hash))
return false;
vWorkQueue.push_back(mapPrev[txin.prevout.hash]);
}
}
return true;

//presstab HyperStake, removed code that checks walletdb for confirmation, we want blockchain info only

return false;
}

bool WriteToDisk();
Expand Down

0 comments on commit 76fca01

Please sign in to comment.