fix staking wallet fix.

This commit is contained in:
blackjok3r
2019-05-18 23:38:49 +08:00
parent 1583446b47
commit 02a3f08894
2 changed files with 5 additions and 6 deletions

View File

@@ -2896,7 +2896,7 @@ bool CWalletTx::RelayWalletTransaction()
{ {
if ( pwallet == 0 ) if ( pwallet == 0 )
{ {
fprintf(stderr,"unexpected null pwallet in RelayWalletTransaction\n"); //fprintf(stderr,"unexpected null pwallet in RelayWalletTransaction\n");
return(false); return(false);
} }
assert(pwallet->GetBroadcastTransactions()); assert(pwallet->GetBroadcastTransactions());

View File

@@ -964,21 +964,20 @@ DBErrors CWalletDB::LoadWallet(CWallet* pwallet)
// staking chains with vin-empty error is a failed staking tx. // staking chains with vin-empty error is a failed staking tx.
// we remove then re add the tx here to stop needing a full rescan, which does not actually fix the problem. // we remove then re add the tx here to stop needing a full rescan, which does not actually fix the problem.
int32_t reAdded = 0; int32_t reAdded = 0;
CWalletDB walletdb(pwallet->strWalletFile, "r+", false);
BOOST_FOREACH (uint256& hash, deadTxns) BOOST_FOREACH (uint256& hash, deadTxns)
{ {
fprintf(stderr, "Removing corrupt tx from wallet.%s\n", hash.ToString().c_str()); fprintf(stderr, "Removing possible orphaned staking transaction from wallet.%s\n", hash.ToString().c_str());
if (!EraseTx(hash)) if (!EraseTx(hash))
fprintf(stderr, "could not delete tx.%s\n",hash.ToString().c_str()); fprintf(stderr, "could not delete tx.%s\n",hash.ToString().c_str());
uint256 blockhash; CTransaction tx; uint256 blockhash; CTransaction tx;
if (GetTransaction(hash,tx,blockhash,true)) if ( GetTransaction(hash,tx,blockhash,false) && mapBlockIndex.find(blockhash) != mapBlockIndex.end() )
{ {
CWalletTx wtx(pwallet,tx); CWalletTx wtx(pwallet,tx);
pwallet->AddToWallet(wtx, false, &walletdb); pwallet->AddToWallet(wtx, true, NULL);
reAdded++; reAdded++;
} }
} }
fprintf(stderr, "Cleared %li corrupted transactions from wallet. Readded %i known transactions.\n",deadTxns.size(),reAdded); fprintf(stderr, "Cleared %li orphaned staking transactions from wallet. Readded %i real transactions.\n",deadTxns.size(),reAdded);
fNoncriticalErrors = false; fNoncriticalErrors = false;
deadTxns.clear(); deadTxns.clear();
} }