Skip to content

Commit

Permalink
3.7.11.0-Leisure
Browse files Browse the repository at this point in the history
Fixed
 - Fix wallet being locked while flushing. It now requires a clean shutdown
   or a backup to migrate the wallet.dat to a different system, #1010 (@jamescowens).

Changed
 - Automatic backups can now be disabled by using `-walletbackupinterval=0`, #1018 (@denravonska).
 - Trigger a fix spent coins check on start and after block disconnect, #1018 (@denravonska).
  • Loading branch information
denravonska committed Mar 15, 2018
2 parents 250d96a + 5d571a7 commit 375a78e
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 22 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [3.7.11.0] 2018-03-15, leisure
### Fixed
- Fix wallet being locked while flushing. It now requires a clean shutdown
or a backup to migrate the wallet.dat to a different system, #1010 (@jamescowens).

### Changed
- Automatic backups can now be disabled by using `-walletbackupinterval=0`,
#1018 (@denravonska).
- Trigger a fix spent coins check on start and after block disconnect, #1018 (@denravonska).

## [3.7.10.0] 2018-03-05, leisure
### Fixed
- Fix sync issues due to beacon age checks, #1003 (@denravonska).
Expand Down
2 changes: 2 additions & 0 deletions src/backup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ bool BackupWallet(const CWallet& wallet, const std::string& strDest)
// Flush log data to the dat file
bitdb.CloseDb(wallet.strWalletFile);
bitdb.CheckpointLSN(wallet.strWalletFile);
printf("Issuing lsn_reset for backup file portability.\n");
bitdb.lsn_reset(wallet.strWalletFile);
bitdb.mapFileUseCount.erase(wallet.strWalletFile);

// Copy wallet.dat
Expand Down
2 changes: 1 addition & 1 deletion src/clientversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// These need to be macros, as version.cpp's and bitcoin-qt.rc's voodoo requires it
#define CLIENT_VERSION_MAJOR 3
#define CLIENT_VERSION_MINOR 7
#define CLIENT_VERSION_REVISION 10
#define CLIENT_VERSION_REVISION 11
#define CLIENT_VERSION_BUILD 0

// Converts the parameter X to a string after macro replacement on X has been performed.
Expand Down
9 changes: 8 additions & 1 deletion src/db.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,16 @@ void CDBEnv::CheckpointLSN(std::string strFile)
dbenv.txn_checkpoint(0, 0, 0);
if (fMockDb)
return;
dbenv.lsn_reset(strFile.c_str(), 0);
// The below line is commented out. LSN reset is not necessary and improper. Txn_checkpoint alone will flush in memory log to the database file.
// This was causing extraordinary long flush times for large wallets.
// Flush is called when the wallet is closed upon client shutdown, and the below line is included there to ensure portability of wallet.dat.
//dbenv.lsn_reset(strFile.c_str(), 0);
}

void CDBEnv::lsn_reset(const std::string& strFile)
{
dbenv.lsn_reset(strFile.c_str(),0);
}

CDB::CDB(const char *pszFile, const char* pszMode) :
pdb(NULL), activeTxn(NULL)
Expand Down
2 changes: 1 addition & 1 deletion src/db.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class CDBEnv
void Close();
void Flush(bool fShutdown);
void CheckpointLSN(std::string strFile);

void lsn_reset(const std::string& strFile);
void CloseDb(const std::string& strFile);
bool RemoveDb(const std::string& strFile);

Expand Down
6 changes: 5 additions & 1 deletion src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1032,8 +1032,12 @@ bool AppInit2(ThreadHandlerPtr threads)
if (!strErrors.str().empty())
return InitError(strErrors.str());

// Add wallet transactions that aren't already in a block to mapTransactions
// Add wallet transactions that aren't already in a block to mapTransactions
pwalletMain->ReacceptWalletTransactions();

int nMismatchSpent;
int64_t nBalanceInQuestion;
pwalletMain->FixSpentCoins(nMismatchSpent, nBalanceInQuestion);

return true;
}
20 changes: 5 additions & 15 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3612,6 +3612,10 @@ bool ReorganizeChain(CTxDB& txdb, unsigned &cnt_dis, unsigned &cnt_con, CBlock &
"Please Reindex the chain and Restart.\n");
exit(1); //todo
}

int nMismatchSpent;
int64_t nBalanceInQuestion;
pwalletMain->FixSpentCoins(nMismatchSpent, nBalanceInQuestion);
}

if (fDebug && cnt_dis>0) printf("ReorganizeChain: disconnected %d blocks\n",cnt_dis);
Expand Down Expand Up @@ -4497,23 +4501,13 @@ void GridcoinServices()

//Backup the wallet once per 900 blocks or as specified in config:
int nWBI = GetArg("-walletbackupinterval", 900);
if (nWBI == 0)
nWBI = 900;

if (TimerMain("backupwallet", nWBI))
if (nWBI && TimerMain("backupwallet", nWBI))
{
bool bWalletBackupResults = BackupWallet(*pwalletMain, GetBackupFilename("wallet.dat"));
bool bConfigBackupResults = BackupConfigFile(GetBackupFilename("gridcoinresearch.conf"));
printf("Daily backup results: Wallet -> %s Config -> %s\r\n", (bWalletBackupResults ? "true" : "false"), (bConfigBackupResults ? "true" : "false"));
}

if (false && TimerMain("FixSpentCoins",60))
{
int nMismatchSpent;
int64_t nBalanceInQuestion;
pwalletMain->FixSpentCoins(nMismatchSpent, nBalanceInQuestion);
}

if (TimerMain("MyNeuralMagnitudeReport",30))
{
try
Expand All @@ -4529,10 +4523,6 @@ void GridcoinServices()
{
printf("Error in MyNeuralMagnitudeReport1.");
}
catch(...)
{
printf("Error in MyNeuralMagnitudeReport.");
}
}

// Every N blocks as a Synchronized TEAM:
Expand Down
2 changes: 1 addition & 1 deletion src/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2386,7 +2386,7 @@ void CWallet::FixSpentCoins(int& nMismatchFound, int64_t& nBalanceInQuestion, bo
}
else if (IsMine(pcoin->vout[n]) && !pcoin->IsSpent(n) && (txindex.vSpent.size() > n && !txindex.vSpent[n].IsNull()))
{
if (fDebug) printf("FixSpentCoins found spent coin %s gC %s[%d], %s\n",
printf("FixSpentCoins found spent coin %s gC %s[%d], %s\n",
FormatMoney(pcoin->vout[n].nValue).c_str(), pcoin->GetHash().ToString().c_str(), n, fCheckOnly? "repair not attempted" : "repairing");
nMismatchFound++;
nBalanceInQuestion += pcoin->vout[n].nValue;
Expand Down
7 changes: 5 additions & 2 deletions src/walletdb.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -670,8 +670,11 @@ void ThreadFlushWalletDB(void* parg)
// Flush wallet.dat so it's self contained
bitdb.CloseDb(strFile);
bitdb.CheckpointLSN(strFile);

bitdb.mapFileUseCount.erase(mi++);
// The below line is commented out, because the above line (CheckpointLSN) should have never had
// lsn_reset in it. lsn_reset should only be called on the final flush when the wallet is closed.
// This is handled in CDB::Flush, which has a while loop that also does in the right place what
// the intention of the below line was.
// bitdb.mapFileUseCount.erase(mi++);
if (fDebug10) printf("Flushed wallet.dat %" PRId64 "ms\n", GetTimeMillis() - nStart);
}
}
Expand Down

0 comments on commit 375a78e

Please sign in to comment.