diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/base58.h | 2 | ||||
-rw-r--r-- | src/bitcoinrpc.cpp | 118 | ||||
-rw-r--r-- | src/db.cpp | 137 | ||||
-rw-r--r-- | src/db.h | 20 | ||||
-rw-r--r-- | src/init.cpp | 21 | ||||
-rw-r--r-- | src/irc.cpp | 2 | ||||
-rw-r--r-- | src/main.cpp | 30 | ||||
-rw-r--r-- | src/main.h | 31 | ||||
-rw-r--r-- | src/makefile.linux-mingw | 2 | ||||
-rw-r--r-- | src/makefile.osx | 2 | ||||
-rw-r--r-- | src/makefile.unix | 2 | ||||
-rw-r--r-- | src/net.cpp | 21 | ||||
-rw-r--r-- | src/net.h | 1 | ||||
-rw-r--r-- | src/qt/bitcoin.qrc | 1 | ||||
-rw-r--r-- | src/qt/bitcoingui.cpp | 14 | ||||
-rw-r--r-- | src/qt/editaddressdialog.cpp | 2 | ||||
-rw-r--r-- | src/qt/forms/overviewpage.ui | 270 | ||||
-rw-r--r-- | src/qt/guiutil.h | 2 | ||||
-rw-r--r-- | src/qt/optionsmodel.cpp | 2 | ||||
-rw-r--r-- | src/qt/optionsmodel.h | 4 | ||||
-rw-r--r-- | src/qt/overviewpage.cpp | 13 | ||||
-rw-r--r-- | src/qt/overviewpage.h | 1 | ||||
-rw-r--r-- | src/qt/res/icons/debugwindow.png | bin | 0 -> 5402 bytes | |||
-rw-r--r-- | src/qt/rpcconsole.cpp | 4 | ||||
-rw-r--r-- | src/qt/rpcconsole.h | 3 | ||||
-rw-r--r-- | src/rpcdump.cpp | 2 | ||||
-rw-r--r-- | src/sync.cpp | 35 | ||||
-rw-r--r-- | src/sync.h | 77 | ||||
-rw-r--r-- | src/test/util_tests.cpp | 2 | ||||
-rw-r--r-- | src/util.cpp | 135 | ||||
-rw-r--r-- | src/util.h | 8 | ||||
-rw-r--r-- | src/wallet.cpp | 5 |
32 files changed, 516 insertions, 453 deletions
diff --git a/src/base58.h b/src/base58.h index 90ce34b05b..1391a13e0e 100644 --- a/src/base58.h +++ b/src/base58.h @@ -252,7 +252,7 @@ public: bool operator> (const CBase58Data& b58) const { return CompareTo(b58) > 0; } }; -/** base58-encoded bitcoin addresses. +/** base58-encoded Bitcoin addresses. * Public-key-hash-addresses have version 0 (or 111 testnet). * The data vector contains RIPEMD160(SHA256(pubkey)), where pubkey is the serialized public key. * Script-hash-addresses have version 5 (or 196 testnet). diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index e058978ebf..334425a9a9 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -115,6 +115,21 @@ HexBits(unsigned int nBits) return HexStr(BEGIN(uBits.cBits), END(uBits.cBits)); } +static std::string +HelpRequiringPassphrase() +{ + return pwalletMain->IsCrypted() + ? "\nrequires wallet passphrase to be set with walletpassphrase first" + : ""; +} + +static inline void +EnsureWalletIsUnlocked() +{ + if (pwalletMain->IsLocked()) + throw JSONRPCError(-13, "Error: Please enter the wallet passphrase with walletpassphrase first."); +} + enum DecomposeMode { DM_NONE = 0, DM_HASH, @@ -371,10 +386,7 @@ string CRPCTable::help(string strCommand) const const CRPCCommand *pcmd = mi->second; string strMethod = mi->first; // We already filter duplicates, but these deprecated screw up the sort order - if (strMethod == "getamountreceived" || - strMethod == "getallreceived" || - strMethod == "getblocknumber" || // deprecated - (strMethod.find("label") != string::npos)) + if (strMethod.find("label") != string::npos) continue; if (strCommand != "" && strMethod != strCommand) continue; @@ -421,10 +433,10 @@ Value stop(const Array& params, bool fHelp) if (fHelp || params.size() != 0) throw runtime_error( "stop\n" - "Stop bitcoin server."); + "Stop Bitcoin server."); // Shutdown will take long enough that the response should get back QueueShutdown(); - return "bitcoin server stopping"; + return "Bitcoin server stopping"; } @@ -439,18 +451,6 @@ Value getblockcount(const Array& params, bool fHelp) } -// deprecated -Value getblocknumber(const Array& params, bool fHelp) -{ - if (fHelp || params.size() != 0) - throw runtime_error( - "getblocknumber\n" - "Deprecated. Use getblockcount."); - - return nBestHeight; -} - - Value getconnectioncount(const Array& params, bool fHelp) { if (fHelp || params.size() != 0) @@ -577,7 +577,7 @@ Value getnewaddress(const Array& params, bool fHelp) if (fHelp || params.size() > 1) throw runtime_error( "getnewaddress [account]\n" - "Returns a new bitcoin address for receiving payments. " + "Returns a new Bitcoin address for receiving payments. " "If [account] is specified (recommended), it is added to the address book " "so payments received with the address will be credited to [account]."); @@ -644,7 +644,7 @@ Value getaccountaddress(const Array& params, bool fHelp) if (fHelp || params.size() != 1) throw runtime_error( "getaccountaddress <account>\n" - "Returns the current bitcoin address for receiving payments to this account."); + "Returns the current Bitcoin address for receiving payments to this account."); // Parse the account first so we don't generate a key if there's an error string strAccount = AccountFromValue(params[0]); @@ -667,7 +667,7 @@ Value setaccount(const Array& params, bool fHelp) CBitcoinAddress address(params[0].get_str()); if (!address.IsValid()) - throw JSONRPCError(-5, "Invalid bitcoin address"); + throw JSONRPCError(-5, "Invalid Bitcoin address"); string strAccount; @@ -697,7 +697,7 @@ Value getaccount(const Array& params, bool fHelp) CBitcoinAddress address(params[0].get_str()); if (!address.IsValid()) - throw JSONRPCError(-5, "Invalid bitcoin address"); + throw JSONRPCError(-5, "Invalid Bitcoin address"); string strAccount; map<CBitcoinAddress, string>::iterator mi = pwalletMain->mapAddressBook.find(address); @@ -746,19 +746,15 @@ Value settxfee(const Array& params, bool fHelp) Value sendtoaddress(const Array& params, bool fHelp) { - if (pwalletMain->IsCrypted() && (fHelp || params.size() < 2 || params.size() > 4)) - throw runtime_error( - "sendtoaddress <bitcoinaddress> <amount> [comment] [comment-to]\n" - "<amount> is a real and is rounded to the nearest 0.00000001\n" - "requires wallet passphrase to be set with walletpassphrase first"); - if (!pwalletMain->IsCrypted() && (fHelp || params.size() < 2 || params.size() > 4)) + if (fHelp || params.size() < 2 || params.size() > 4) throw runtime_error( "sendtoaddress <bitcoinaddress> <amount> [comment] [comment-to]\n" - "<amount> is a real and is rounded to the nearest 0.00000001"); + "<amount> is a real and is rounded to the nearest 0.00000001" + + HelpRequiringPassphrase()); CBitcoinAddress address(params[0].get_str()); if (!address.IsValid()) - throw JSONRPCError(-5, "Invalid bitcoin address"); + throw JSONRPCError(-5, "Invalid Bitcoin address"); // Amount int64 nAmount = AmountFromValue(params[1]); @@ -787,8 +783,7 @@ Value signmessage(const Array& params, bool fHelp) "signmessage <bitcoinaddress> <message>\n" "Sign a message with the private key of an address"); - if (pwalletMain->IsLocked()) - throw JSONRPCError(-13, "Error: Please enter the wallet passphrase with walletpassphrase first."); + EnsureWalletIsUnlocked(); string strAddress = params[0].get_str(); string strMessage = params[1].get_str(); @@ -856,7 +851,7 @@ Value getreceivedbyaddress(const Array& params, bool fHelp) CBitcoinAddress address = CBitcoinAddress(params[0].get_str()); CScript scriptPubKey; if (!address.IsValid()) - throw JSONRPCError(-5, "Invalid bitcoin address"); + throw JSONRPCError(-5, "Invalid Bitcoin address"); scriptPubKey.SetBitcoinAddress(address); if (!IsMine(*pwalletMain,scriptPubKey)) return (double)0.0; @@ -1037,7 +1032,8 @@ Value movecmd(const Array& params, bool fHelp) strComment = params[4].get_str(); CWalletDB walletdb(pwalletMain->strWalletFile); - walletdb.TxnBegin(); + if (!walletdb.TxnBegin()) + throw JSONRPCError(-20, "database error"); int64 nNow = GetAdjustedTime(); @@ -1059,7 +1055,8 @@ Value movecmd(const Array& params, bool fHelp) credit.strComment = strComment; walletdb.WriteAccountingEntry(credit); - walletdb.TxnCommit(); + if (!walletdb.TxnCommit()) + throw JSONRPCError(-20, "database error"); return true; } @@ -1067,20 +1064,16 @@ Value movecmd(const Array& params, bool fHelp) Value sendfrom(const Array& params, bool fHelp) { - if (pwalletMain->IsCrypted() && (fHelp || params.size() < 3 || params.size() > 6)) + if (fHelp || params.size() < 3 || params.size() > 6) throw runtime_error( "sendfrom <fromaccount> <tobitcoinaddress> <amount> [minconf=1] [comment] [comment-to]\n" - "<amount> is a real and is rounded to the nearest 0.00000001\n" - "requires wallet passphrase to be set with walletpassphrase first"); - if (!pwalletMain->IsCrypted() && (fHelp || params.size() < 3 || params.size() > 6)) - throw runtime_error( - "sendfrom <fromaccount> <tobitcoinaddress> <amount> [minconf=1] [comment] [comment-to]\n" - "<amount> is a real and is rounded to the nearest 0.00000001"); + "<amount> is a real and is rounded to the nearest 0.00000001" + + HelpRequiringPassphrase()); string strAccount = AccountFromValue(params[0]); CBitcoinAddress address(params[1].get_str()); if (!address.IsValid()) - throw JSONRPCError(-5, "Invalid bitcoin address"); + throw JSONRPCError(-5, "Invalid Bitcoin address"); int64 nAmount = AmountFromValue(params[2]); int nMinDepth = 1; if (params.size() > 3) @@ -1093,8 +1086,7 @@ Value sendfrom(const Array& params, bool fHelp) if (params.size() > 5 && params[5].type() != null_type && !params[5].get_str().empty()) wtx.mapValue["to"] = params[5].get_str(); - if (pwalletMain->IsLocked()) - throw JSONRPCError(-13, "Error: Please enter the wallet passphrase with walletpassphrase first."); + EnsureWalletIsUnlocked(); // Check funds int64 nBalance = GetAccountBalance(strAccount, nMinDepth); @@ -1112,15 +1104,11 @@ Value sendfrom(const Array& params, bool fHelp) Value sendmany(const Array& params, bool fHelp) { - if (pwalletMain->IsCrypted() && (fHelp || params.size() < 2 || params.size() > 4)) + if (fHelp || params.size() < 2 || params.size() > 4) throw runtime_error( "sendmany <fromaccount> {address:amount,...} [minconf=1] [comment]\n" - "amounts are double-precision floating point numbers\n" - "requires wallet passphrase to be set with walletpassphrase first"); - if (!pwalletMain->IsCrypted() && (fHelp || params.size() < 2 || params.size() > 4)) - throw runtime_error( - "sendmany <fromaccount> {address:amount,...} [minconf=1] [comment]\n" - "amounts are double-precision floating point numbers"); + "amounts are double-precision floating point numbers" + + HelpRequiringPassphrase()); string strAccount = AccountFromValue(params[0]); Object sendTo = params[1].get_obj(); @@ -1141,7 +1129,7 @@ Value sendmany(const Array& params, bool fHelp) { CBitcoinAddress address(s.name_); if (!address.IsValid()) - throw JSONRPCError(-5, string("Invalid bitcoin address:")+s.name_); + throw JSONRPCError(-5, string("Invalid Bitcoin address:")+s.name_); if (setAddress.count(address)) throw JSONRPCError(-8, string("Invalid parameter, duplicated address: ")+s.name_); @@ -1155,8 +1143,7 @@ Value sendmany(const Array& params, bool fHelp) vecSend.push_back(make_pair(scriptPubKey, nAmount)); } - if (pwalletMain->IsLocked()) - throw JSONRPCError(-13, "Error: Please enter the wallet passphrase with walletpassphrase first."); + EnsureWalletIsUnlocked(); // Check funds int64 nBalance = GetAccountBalance(strAccount, nMinDepth); @@ -1185,7 +1172,7 @@ Value addmultisigaddress(const Array& params, bool fHelp) { string msg = "addmultisigaddress <nrequired> <'[\"key\",\"key\"]'> [account]\n" "Add a nrequired-to-sign multisignature address to the wallet\"\n" - "each key is a bitcoin address or hex-encoded public key\n" + "each key is a Bitcoin address or hex-encoded public key\n" "If [account] is specified, assign address to [account]."; throw runtime_error(msg); } @@ -1209,7 +1196,7 @@ Value addmultisigaddress(const Array& params, bool fHelp) { const std::string& ks = keys[i].get_str(); - // Case 1: bitcoin address and we have full public key: + // Case 1: Bitcoin address and we have full public key: CBitcoinAddress address(ks); if (address.IsValid()) { @@ -1755,17 +1742,13 @@ Value backupwallet(const Array& params, bool fHelp) Value keypoolrefill(const Array& params, bool fHelp) { - if (pwalletMain->IsCrypted() && (fHelp || params.size() > 0)) + if (fHelp || params.size() > 0) throw runtime_error( "keypoolrefill\n" - "Fills the keypool, requires wallet passphrase to be set."); - if (!pwalletMain->IsCrypted() && (fHelp || params.size() > 0)) - throw runtime_error( - "keypoolrefill\n" - "Fills the keypool."); + "Fills the keypool." + + HelpRequiringPassphrase()); - if (pwalletMain->IsLocked()) - throw JSONRPCError(-13, "Error: Please enter the wallet passphrase with walletpassphrase first."); + EnsureWalletIsUnlocked(); pwalletMain->TopUpKeyPool(); @@ -1946,7 +1929,7 @@ Value encryptwallet(const Array& params, bool fHelp) // slack space in .dat files; that is bad if the old data is // unencrypted private keys. So: QueueShutdown(); - return "wallet encrypted; bitcoin server stopping, restart to run with encrypted wallet"; + return "wallet encrypted; Bitcoin server stopping, restart to run with encrypted wallet"; } @@ -2255,7 +2238,6 @@ static const CRPCCommand vRPCCommands[] = { "help", &help, true }, { "stop", &stop, true }, { "getblockcount", &getblockcount, true }, - { "getblocknumber", &getblocknumber, true }, { "getconnectioncount", &getconnectioncount, true }, { "getdifficulty", &getdifficulty, true }, { "getgenerate", &getgenerate, true }, @@ -2621,7 +2603,7 @@ void ThreadRPCServer(void* parg) vnThreadsRunning[THREAD_RPCLISTENER]--; PrintException(NULL, "ThreadRPCServer()"); } - printf("ThreadRPCServer exiting\n"); + printf("ThreadRPCServer exited\n"); } void ThreadRPCServer2(void* parg) diff --git a/src/db.cpp b/src/db.cpp index 5bd0528202..50f0891626 100644 --- a/src/db.cpp +++ b/src/db.cpp @@ -96,6 +96,7 @@ CDB::CDB(const char *pszFile, const char* pszMode) : pdb(NULL) dbenv.set_lk_max_locks(10000); dbenv.set_lk_max_objects(10000); dbenv.set_errfile(fopen(pathErrorFile.string().c_str(), "a")); /// debug + dbenv.set_flags(DB_TXN_WRITE_NOSYNC, 1); dbenv.set_flags(DB_AUTO_COMMIT, 1); dbenv.log_set_config(DB_LOG_AUTO_REMOVE, 1); ret = dbenv.open(pathDataDir.string().c_str(), @@ -164,8 +165,6 @@ void CDB::Close() unsigned int nMinutes = 0; if (fReadOnly) nMinutes = 1; - if (strFile == "addr.dat") - nMinutes = 2; if (strFile == "blkindex.dat") nMinutes = 2; if (strFile == "blkindex.dat" && IsInitialBlockDownload()) @@ -291,6 +290,7 @@ bool CDB::Rewrite(const string& strFile, const char* pszSkip) void DBFlush(bool fShutdown) { + int64 nStart = GetTimeMillis(); // Flush log data to the actual data file // on all files that are not in use printf("DBFlush(%s)%s\n", fShutdown ? "true" : "false", fDbEnvInit ? "" : " db not started"); @@ -310,7 +310,7 @@ void DBFlush(bool fShutdown) CloseDb(strFile); printf("%s checkpoint\n", strFile.c_str()); dbenv.txn_checkpoint(0, 0, 0); - if ((strFile != "blkindex.dat" && strFile != "addr.dat") || fDetachDB) { + if (strFile != "blkindex.dat" || fDetachDB) { printf("%s detach\n", strFile.c_str()); dbenv.lsn_reset(strFile.c_str(), 0); } @@ -320,6 +320,7 @@ void DBFlush(bool fShutdown) else mi++; } + printf("DBFlush(%s)%s ended %15"PRI64d"ms\n", fShutdown ? "true" : "false", fDbEnvInit ? "" : " db not started", GetTimeMillis() - nStart); if (fShutdown) { char** listp; @@ -463,11 +464,6 @@ bool CTxDB::WriteBlockIndex(const CDiskBlockIndex& blockindex) return Write(make_pair(string("blockindex"), blockindex.GetBlockHash()), blockindex); } -bool CTxDB::EraseBlockIndex(uint256 hash) -{ - return Erase(make_pair(string("blockindex"), hash)); -} - bool CTxDB::ReadHashBestChain(uint256& hashBestChain) { return Read(string("hashBestChain"), hashBestChain); @@ -737,65 +733,96 @@ bool CTxDB::LoadBlockIndex() // CAddrDB // -bool CAddrDB::WriteAddrman(const CAddrMan& addrman) + +CAddrDB::CAddrDB() { - return Write(string("addrman"), addrman); + pathAddr = GetDataDir() / "peers.dat"; } -bool CAddrDB::LoadAddresses() +bool CAddrDB::Write(const CAddrMan& addr) { - if (Read(string("addrman"), addrman)) - { - printf("Loaded %i addresses\n", addrman.size()); - return true; + // Generate random temporary filename + unsigned short randv = 0; + RAND_bytes((unsigned char *)&randv, sizeof(randv)); + std::string tmpfn = strprintf("peers.dat.%04x", randv); + + // serialize addresses, checksum data up to that point, then append csum + CDataStream ssPeers(SER_DISK, CLIENT_VERSION); + ssPeers << FLATDATA(pchMessageStart); + ssPeers << addr; + uint256 hash = Hash(ssPeers.begin(), ssPeers.end()); + ssPeers << hash; + + // open temp output file, and associate with CAutoFile + boost::filesystem::path pathTmp = GetDataDir() / tmpfn; + FILE *file = fopen(pathTmp.string().c_str(), "wb"); + CAutoFile fileout = CAutoFile(file, SER_DISK, CLIENT_VERSION); + if (!fileout) + return error("CAddrman::Write() : open failed"); + + // Write and commit header, data + try { + fileout << ssPeers; } - - // Read pre-0.6 addr records + catch (std::exception &e) { + return error("CAddrman::Write() : I/O error"); + } + FileCommit(fileout); + fileout.fclose(); - vector<CAddress> vAddr; - vector<vector<unsigned char> > vDelete; + // replace existing peers.dat, if any, with new peers.dat.XXXX + if (!RenameOver(pathTmp, pathAddr)) + return error("CAddrman::Write() : Rename-into-place failed"); - // Get cursor - Dbc* pcursor = GetCursor(); - if (!pcursor) - return false; - - loop - { - // Read next record - CDataStream ssKey(SER_DISK, CLIENT_VERSION); - CDataStream ssValue(SER_DISK, CLIENT_VERSION); - int ret = ReadAtCursor(pcursor, ssKey, ssValue); - if (ret == DB_NOTFOUND) - break; - else if (ret != 0) - return false; + return true; +} - // Unserialize - string strType; - ssKey >> strType; - if (strType == "addr") - { - CAddress addr; - ssValue >> addr; - vAddr.push_back(addr); - } +bool CAddrDB::Read(CAddrMan& addr) +{ + // open input file, and associate with CAutoFile + FILE *file = fopen(pathAddr.string().c_str(), "rb"); + CAutoFile filein = CAutoFile(file, SER_DISK, CLIENT_VERSION); + if (!filein) + return error("CAddrman::Read() : open failed"); + + // use file size to size memory buffer + int fileSize = GetFilesize(filein); + int dataSize = fileSize - sizeof(uint256); + vector<unsigned char> vchData; + vchData.resize(dataSize); + uint256 hashIn; + + // read data and checksum from file + try { + filein.read((char *)&vchData[0], dataSize); + filein >> hashIn; } - pcursor->close(); + catch (std::exception &e) { + return error("CAddrman::Read() 2 : I/O error or stream data corrupted"); + } + filein.fclose(); - addrman.Add(vAddr, CNetAddr("0.0.0.0")); - printf("Loaded %i addresses\n", addrman.size()); + CDataStream ssPeers(vchData, SER_DISK, CLIENT_VERSION); - // Note: old records left; we ran into hangs-on-startup - // bugs for some users who (we think) were running after - // an unclean shutdown. + // verify stored checksum matches input data + uint256 hashTmp = Hash(ssPeers.begin(), ssPeers.end()); + if (hashIn != hashTmp) + return error("CAddrman::Read() : checksum mismatch; data corrupted"); - return true; -} + // de-serialize address data + unsigned char pchMsgTmp[4]; + try { + ssPeers >> FLATDATA(pchMsgTmp); + ssPeers >> addr; + } + catch (std::exception &e) { + return error("CAddrman::Read() : I/O error or stream data corrupted"); + } -bool LoadAddresses() -{ - return CAddrDB("cr+").LoadAddresses(); -} + // finally, verify the network matches ours + if (memcmp(pchMsgTmp, pchMessageStart, sizeof(pchMsgTmp))) + return error("CAddrman::Read() : invalid network magic number"); + return true; +} @@ -216,7 +216,7 @@ public: if (!pdb) return false; DbTxn* ptxn = NULL; - int ret = dbenv.txn_begin(GetTxn(), &ptxn, DB_TXN_NOSYNC); + int ret = dbenv.txn_begin(GetTxn(), &ptxn, DB_TXN_WRITE_NOSYNC); if (!ptxn || ret != 0) return false; vTxn.push_back(ptxn); @@ -285,7 +285,6 @@ public: bool ReadDiskTx(COutPoint outpoint, CTransaction& tx, CTxIndex& txindex); bool ReadDiskTx(COutPoint outpoint, CTransaction& tx); bool WriteBlockIndex(const CDiskBlockIndex& blockindex); - bool EraseBlockIndex(uint256 hash); bool ReadHashBestChain(uint256& hashBestChain); bool WriteHashBestChain(uint256 hashBestChain); bool ReadBestInvalidWork(CBigNum& bnBestInvalidWork); @@ -296,20 +295,15 @@ public: -/** Access to the (IP) address database (addr.dat) */ -class CAddrDB : public CDB +/** Access to the (IP) address database (peers.dat) */ +class CAddrDB { -public: - CAddrDB(const char* pszMode="r+") : CDB("addr.dat", pszMode) { } private: - CAddrDB(const CAddrDB&); - void operator=(const CAddrDB&); + boost::filesystem::path pathAddr; public: - bool WriteAddrman(const CAddrMan& addr); - bool LoadAddresses(); + CAddrDB(); + bool Write(const CAddrMan& addr); + bool Read(CAddrMan& addr); }; -bool LoadAddresses(); - - #endif // BITCOIN_DB_H diff --git a/src/init.cpp b/src/init.cpp index 0c6baec1ce..47b6f92324 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -62,7 +62,7 @@ void Shutdown(void* parg) delete pwalletMain; CreateThread(ExitTimeout, NULL); Sleep(50); - printf("Bitcoin exiting\n\n"); + printf("Bitcoin exited\n\n"); fExit = true; exit(0); } @@ -162,7 +162,6 @@ bool static InitError(const std::string &str) { ThreadSafeMessageBox(str, _("Bitcoin"), wxOK | wxMODAL); return false; - } bool static InitWarning(const std::string &str) @@ -352,7 +351,7 @@ bool AppInit2() return false; } - // Make sure only a single bitcoin process is using the data directory. + // Make sure only a single Bitcoin process is using the data directory. boost::filesystem::path pathLockFile = GetDataDir() / ".lock"; FILE* file = fopen(pathLockFile.string().c_str(), "a"); // empty lock file; created if it doesn't exist. if (file) fclose(file); @@ -365,15 +364,21 @@ bool AppInit2() // Load data files // if (fDaemon) - fprintf(stdout, "bitcoin server starting\n"); + fprintf(stdout, "Bitcoin server starting\n"); int64 nStart; InitMessage(_("Loading addresses...")); printf("Loading addresses...\n"); nStart = GetTimeMillis(); - if (!LoadAddresses()) - strErrors << _("Error loading addr.dat") << "\n"; - printf(" addresses %15"PRI64d"ms\n", GetTimeMillis() - nStart); + + { + CAddrDB adb; + if (!adb.Read(addrman)) + printf("Invalid or missing peers.dat; recreating\n"); + } + + printf("Loaded %i addresses from peers.dat %"PRI64d"ms\n", + addrman.size(), GetTimeMillis() - nStart); InitMessage(_("Loading block index...")); printf("Loading block index...\n"); @@ -492,7 +497,7 @@ bool AppInit2() // Add wallet transactions that aren't already in a block to mapTransactions pwalletMain->ReacceptWalletTransactions(); - // Note: Bitcoin-QT stores several settings in the wallet, so we want + // Note: Bitcoin-Qt stores several settings in the wallet, so we want // to load the wallet BEFORE parsing command-line arguments, so // the command-line/bitcoin.conf settings override GUI setting. diff --git a/src/irc.cpp b/src/irc.cpp index 4baffedb54..f21772ac1f 100644 --- a/src/irc.cpp +++ b/src/irc.cpp @@ -200,7 +200,7 @@ void ThreadIRCSeed(void* parg) } catch (...) { PrintExceptionContinue(NULL, "ThreadIRCSeed()"); } - printf("ThreadIRCSeed exiting\n"); + printf("ThreadIRCSeed exited\n"); } void ThreadIRCSeed2(void* parg) diff --git a/src/main.cpp b/src/main.cpp index e40acf6d32..8ff6d6fec0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -719,7 +719,7 @@ bool CWalletTx::AcceptWalletTransaction(CTxDB& txdb, bool fCheckInputs) return false; } -bool CWalletTx::AcceptWalletTransaction() +bool CWalletTx::AcceptWalletTransaction() { CTxDB txdb("r"); return AcceptWalletTransaction(txdb); @@ -1514,7 +1514,9 @@ bool CBlock::SetBestChain(CTxDB& txdb, CBlockIndex* pindexNew) { uint256 hash = GetHash(); - txdb.TxnBegin(); + if (!txdb.TxnBegin()) + return error("SetBestChain() : TxnBegin failed"); + if (pindexGenesisBlock == NULL && hash == hashGenesisBlock) { txdb.WriteHashBestChain(hash); @@ -1563,7 +1565,10 @@ bool CBlock::SetBestChain(CTxDB& txdb, CBlockIndex* pindexNew) printf("SetBestChain() : ReadFromDisk failed\n"); break; } - txdb.TxnBegin(); + if (!txdb.TxnBegin()) { + printf("SetBestChain() : TxnBegin 2 failed\n"); + break; + } // errors now are not fatal, we still did a reorganisation to a new chain in a valid way if (!block.SetBestChainInner(txdb, pindex)) break; @@ -1621,7 +1626,8 @@ bool CBlock::AddToBlockIndex(unsigned int nFile, unsigned int nBlockPos) pindexNew->bnChainWork = (pindexNew->pprev ? pindexNew->pprev->bnChainWork : 0) + pindexNew->GetBlockWork(); CTxDB txdb; - txdb.TxnBegin(); + if (!txdb.TxnBegin()) + return false; txdb.WriteBlockIndex(CDiskBlockIndex(pindexNew)); if (!txdb.TxnCommit()) return false; @@ -1845,11 +1851,11 @@ bool CheckDiskSpace(uint64 nAdditionalBytes) { uint64 nFreeBytesAvailable = filesystem::space(GetDataDir()).available; - // Check for 15MB because database could create another 10MB log file at any time - if (nFreeBytesAvailable < (uint64)15000000 + nAdditionalBytes) + // Check for nMinDiskSpace bytes (currently 50MB) + if (nFreeBytesAvailable < nMinDiskSpace + nAdditionalBytes) { fShutdown = true; - string strMessage = _("Warning: Disk space is low "); + string strMessage = _("Warning: Disk space is low"); strMiscWarning = strMessage; printf("*** %s\n", strMessage.c_str()); ThreadSafeMessageBox(strMessage, "Bitcoin", wxOK | wxICON_EXCLAMATION | wxMODAL); @@ -2102,7 +2108,7 @@ bool LoadExternalBlockFile(FILE* fileIn) } } } - catch (std::exception &e) + catch (std::exception &e) { } } @@ -2698,7 +2704,9 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) } else if (fMissingInputs) { - printf("storing orphan tx %s\n", inv.hash.ToString().substr(0,10).c_str()); + printf("storing orphan tx %s (mapsz %d)\n", + inv.hash.ToString().substr(0,10).c_str(), + mapOrphanTransactions.size() + 1); AddOrphanTx(vMsg); // DoS prevention: do not allow mapOrphanTransactions to grow unbounded @@ -2964,7 +2972,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle) if (pto->nVersion == 0) return true; - // Keep-alive ping. We send a nonce of zero because we don't use it anywhere + // Keep-alive ping. We send a nonce of zero because we don't use it anywhere // right now. if (pto->nLastSend && GetTime() - pto->nLastSend > 30 * 60 && pto->vSend.empty()) { if (pto->nVersion > BIP0031_VERSION) @@ -3164,7 +3172,7 @@ void SHA256Transform(void* pstate, void* pinput, const void* pinit) ctx.h[i] = ((uint32_t*)pinit)[i]; SHA256_Update(&ctx, data, sizeof(data)); - for (int i = 0; i < 8; i++) + for (int i = 0; i < 8; i++) ((uint32_t*)pstate)[i] = ctx.h[i]; } diff --git a/src/main.h b/src/main.h index 5ac5547a3e..9700909f8b 100644 --- a/src/main.h +++ b/src/main.h @@ -10,10 +10,6 @@ #include "net.h" #include "script.h" -#ifdef WIN32 -#include <io.h> /* for _commit */ -#endif - #include <list> class CWallet; @@ -75,8 +71,8 @@ extern unsigned char pchMessageStart[4]; // Settings extern int64 nTransactionFee; - - +// Minimum disk space required - used in CheckDiskSpace() +static const uint64 nMinDiskSpace = 52428800; class CReserveKey; @@ -956,13 +952,7 @@ public: // Flush stdio buffers and commit to disk before returning fflush(fileout); if (!IsInitialBlockDownload() || (nBestHeight+1) % 500 == 0) - { -#ifdef WIN32 - _commit(_fileno(fileout)); -#else - fsync(fileno(fileout)); -#endif - } + FileCommit(fileout); return true; } @@ -1130,21 +1120,6 @@ public: return CheckProofOfWork(GetBlockHash(), nBits); } - bool EraseBlockFromDisk() - { - // Open history file - CAutoFile fileout = CAutoFile(OpenBlockFile(nFile, nBlockPos, "rb+"), SER_DISK, CLIENT_VERSION); - if (!fileout) - return false; - - // Overwrite with empty null block - CBlock block; - block.SetNull(); - fileout << block; - - return true; - } - enum { nMedianTimeSpan=11 }; int64 GetMedianTimePast() const diff --git a/src/makefile.linux-mingw b/src/makefile.linux-mingw index 1df1e28f1d..61b38a663e 100644 --- a/src/makefile.linux-mingw +++ b/src/makefile.linux-mingw @@ -70,7 +70,7 @@ OBJS= \ all: bitcoind.exe obj/build.h: FORCE - ../share/genbuild.sh obj/build.h + /bin/sh ../share/genbuild.sh obj/build.h version.cpp: obj/build.h DEFS += -DHAVE_BUILD_INFO diff --git a/src/makefile.osx b/src/makefile.osx index c927330c9c..227756f274 100644 --- a/src/makefile.osx +++ b/src/makefile.osx @@ -107,7 +107,7 @@ all: bitcoind -include obj-test/*.P obj/build.h: FORCE - ../share/genbuild.sh obj/build.h + /bin/sh ../share/genbuild.sh obj/build.h version.cpp: obj/build.h DEFS += -DHAVE_BUILD_INFO diff --git a/src/makefile.unix b/src/makefile.unix index b1cc89d0cb..04e17866e5 100644 --- a/src/makefile.unix +++ b/src/makefile.unix @@ -119,7 +119,7 @@ all: bitcoind -include obj-test/*.P obj/build.h: FORCE - ../share/genbuild.sh obj/build.h + /bin/sh ../share/genbuild.sh obj/build.h version.cpp: obj/build.h DEFS += -DHAVE_BUILD_INFO diff --git a/src/net.cpp b/src/net.cpp index bcaf750a2a..8d19387602 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -628,7 +628,7 @@ void ThreadSocketHandler(void* parg) vnThreadsRunning[THREAD_SOCKETHANDLER]--; throw; // support pthread_cancel() } - printf("ThreadSocketHandler exiting\n"); + printf("ThreadSocketHandler exited\n"); } void ThreadSocketHandler2(void* parg) @@ -985,7 +985,7 @@ void ThreadMapPort(void* parg) vnThreadsRunning[THREAD_UPNP]--; PrintException(NULL, "ThreadMapPort()"); } - printf("ThreadMapPort exiting\n"); + printf("ThreadMapPort exited\n"); } void ThreadMapPort2(void* parg) @@ -1147,7 +1147,7 @@ void ThreadDNSAddressSeed(void* parg) vnThreadsRunning[THREAD_DNSSEED]--; throw; // support pthread_cancel() } - printf("ThreadDNSAddressSeed exiting\n"); + printf("ThreadDNSAddressSeed exited\n"); } void ThreadDNSAddressSeed2(void* parg) @@ -1278,8 +1278,13 @@ unsigned int pnSeed[] = void DumpAddresses() { + int64 nStart = GetTimeMillis(); + CAddrDB adb; - adb.WriteAddrman(addrman); + adb.Write(addrman); + + printf("Flushed %d addresses to peers.dat %"PRI64d"ms\n", + addrman.size(), GetTimeMillis() - nStart); } void ThreadDumpAddress2(void* parg) @@ -1305,7 +1310,7 @@ void ThreadDumpAddress(void* parg) catch (std::exception& e) { PrintException(&e, "ThreadDumpAddress()"); } - printf("ThreadDumpAddress exiting\n"); + printf("ThreadDumpAddress exited\n"); } void ThreadOpenConnections(void* parg) @@ -1324,7 +1329,7 @@ void ThreadOpenConnections(void* parg) vnThreadsRunning[THREAD_OPENCONNECTIONS]--; PrintException(NULL, "ThreadOpenConnections()"); } - printf("ThreadOpenConnections exiting\n"); + printf("ThreadOpenConnections exited\n"); } void static ProcessOneShot() @@ -1477,7 +1482,7 @@ void ThreadOpenAddedConnections(void* parg) vnThreadsRunning[THREAD_ADDEDCONNECTIONS]--; PrintException(NULL, "ThreadOpenAddedConnections()"); } - printf("ThreadOpenAddedConnections exiting\n"); + printf("ThreadOpenAddedConnections exited\n"); } void ThreadOpenAddedConnections2(void* parg) @@ -1606,7 +1611,7 @@ void ThreadMessageHandler(void* parg) vnThreadsRunning[THREAD_MESSAGEHANDLER]--; PrintException(NULL, "ThreadMessageHandler()"); } - printf("ThreadMessageHandler exiting\n"); + printf("ThreadMessageHandler exited\n"); } void ThreadMessageHandler2(void* parg) @@ -19,7 +19,6 @@ #include "protocol.h" #include "addrman.h" -class CAddrDB; class CRequestTracker; class CNode; class CBlockIndex; diff --git a/src/qt/bitcoin.qrc b/src/qt/bitcoin.qrc index c910d5bef4..a6a2112478 100644 --- a/src/qt/bitcoin.qrc +++ b/src/qt/bitcoin.qrc @@ -39,6 +39,7 @@ <file alias="key">res/icons/key.png</file> <file alias="filesave">res/icons/filesave.png</file> <file alias="qrcode">res/icons/qrcode.png</file> + <file alias="debugwindow">res/icons/debugwindow.png</file> </qresource> <qresource prefix="/images"> <file alias="about">res/images/about.png</file> diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 6b97d97656..7070e59444 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -207,7 +207,7 @@ void BitcoinGUI::createActions() tabGroup->addAction(receiveCoinsAction); sendCoinsAction = new QAction(QIcon(":/icons/send"), tr("&Send coins"), this); - sendCoinsAction->setToolTip(tr("Send coins to a bitcoin address")); + sendCoinsAction->setToolTip(tr("Send coins to a Bitcoin address")); sendCoinsAction->setCheckable(true); sendCoinsAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_2)); tabGroup->addAction(sendCoinsAction); @@ -243,7 +243,7 @@ void BitcoinGUI::createActions() aboutQtAction->setToolTip(tr("Show information about Qt")); aboutQtAction->setMenuRole(QAction::AboutQtRole); optionsAction = new QAction(QIcon(":/icons/options"), tr("&Options..."), this); - optionsAction->setToolTip(tr("Modify configuration options for bitcoin")); + optionsAction->setToolTip(tr("Modify configuration options for Bitcoin")); optionsAction->setMenuRole(QAction::PreferencesRole); toggleHideAction = new QAction(QIcon(":/icons/bitcoin"), tr("Show/Hide &Bitcoin"), this); toggleHideAction->setToolTip(tr("Show or hide the Bitcoin window")); @@ -256,7 +256,7 @@ void BitcoinGUI::createActions() backupWalletAction->setToolTip(tr("Backup wallet to another location")); changePassphraseAction = new QAction(QIcon(":/icons/key"), tr("&Change Passphrase..."), this); changePassphraseAction->setToolTip(tr("Change the passphrase used for wallet encryption")); - openRPCConsoleAction = new QAction(tr("&Debug window"), this); + openRPCConsoleAction = new QAction(QIcon(":/icons/debugwindow"), tr("&Debug window"), this); openRPCConsoleAction->setToolTip(tr("Open debugging and diagnostic console")); verifyMessageAction = new QAction(QIcon(":/icons/transaction_0"), tr("&Verify message..."), this); verifyMessageAction->setToolTip(tr("Verify a message signature")); @@ -426,7 +426,7 @@ void BitcoinGUI::createTrayIcon() trayIconMenu->addAction(quitAction); #endif - notificator = new Notificator(tr("bitcoin-qt"), trayIcon); + notificator = new Notificator(qApp->applicationName(), trayIcon); } #ifndef Q_WS_MAC @@ -434,7 +434,7 @@ void BitcoinGUI::trayIconActivated(QSystemTrayIcon::ActivationReason reason) { if(reason == QSystemTrayIcon::Trigger) { - // Click on system tray icon triggers "show/hide bitcoin" + // Click on system tray icon triggers "show/hide Bitcoin" toggleHideAction->trigger(); } } @@ -574,12 +574,16 @@ void BitcoinGUI::setNumBlocks(int count) { tooltip = tr("Up to date") + QString(".<br>") + tooltip; labelBlocksIcon->setPixmap(QIcon(":/icons/synced").pixmap(STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE)); + + overviewPage->showOutOfSyncWarning(false); } else { tooltip = tr("Catching up...") + QString("<br>") + tooltip; labelBlocksIcon->setMovie(syncIconMovie); syncIconMovie->start(); + + overviewPage->showOutOfSyncWarning(true); } if(!text.isEmpty()) diff --git a/src/qt/editaddressdialog.cpp b/src/qt/editaddressdialog.cpp index cecb8aecd7..0d88aa47cb 100644 --- a/src/qt/editaddressdialog.cpp +++ b/src/qt/editaddressdialog.cpp @@ -93,7 +93,7 @@ void EditAddressDialog::accept() break; case AddressTableModel::INVALID_ADDRESS: QMessageBox::warning(this, windowTitle(), - tr("The entered address \"%1\" is not a valid bitcoin address.").arg(ui->addressEdit->text()), + tr("The entered address \"%1\" is not a valid Bitcoin address.").arg(ui->addressEdit->text()), QMessageBox::Ok, QMessageBox::Ok); return; case AddressTableModel::WALLET_UNLOCK_FAILURE: diff --git a/src/qt/forms/overviewpage.ui b/src/qt/forms/overviewpage.ui index aeace9f30d..6573517b24 100644 --- a/src/qt/forms/overviewpage.ui +++ b/src/qt/forms/overviewpage.ui @@ -24,104 +24,141 @@ <property name="frameShadow"> <enum>QFrame::Raised</enum> </property> - <layout class="QFormLayout" name="formLayout_2"> - <property name="fieldGrowthPolicy"> - <enum>QFormLayout::AllNonFixedFieldsGrow</enum> - </property> - <property name="horizontalSpacing"> - <number>12</number> - </property> - <property name="verticalSpacing"> - <number>12</number> - </property> - <item row="2" column="0"> - <widget class="QLabel" name="label"> - <property name="text"> - <string>Balance:</string> - </property> - </widget> - </item> - <item row="2" column="1"> - <widget class="QLabel" name="labelBalance"> - <property name="font"> - <font> - <weight>75</weight> - <bold>true</bold> - </font> - </property> - <property name="cursor"> - <cursorShape>IBeamCursor</cursorShape> - </property> - <property name="toolTip"> - <string>Your current balance</string> - </property> - <property name="text"> - <string notr="true">123.456 BTC</string> - </property> - <property name="textInteractionFlags"> - <set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set> - </property> - </widget> - </item> - <item row="4" column="0"> - <widget class="QLabel" name="label_2"> - <property name="text"> - <string>Number of transactions:</string> - </property> - </widget> - </item> - <item row="4" column="1"> - <widget class="QLabel" name="labelNumTransactions"> - <property name="toolTip"> - <string>Total number of transactions in wallet</string> - </property> - <property name="text"> - <string>0</string> - </property> - </widget> - </item> - <item row="3" column="0"> - <widget class="QLabel" name="label_3"> - <property name="text"> - <string>Unconfirmed:</string> - </property> - </widget> + <layout class="QVBoxLayout" name="verticalLayout_4"> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_4"> + <item> + <widget class="QLabel" name="label_5"> + <property name="font"> + <font> + <pointsize>11</pointsize> + <weight>75</weight> + <bold>true</bold> + </font> + </property> + <property name="text"> + <string>Wallet</string> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="labelWalletStatus"> + <property name="toolTip"> + <string>The displayed information may be out of date. Your wallet automatically synchronizes with the Bitcoin network after a connection is established, but this process has not completed yet.</string> + </property> + <property name="styleSheet"> + <string notr="true">QLabel { color: red; }</string> + </property> + <property name="text"> + <string notr="true">(out of sync)</string> + </property> + <property name="alignment"> + <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set> + </property> + </widget> + </item> + <item> + <spacer name="horizontalSpacer_2"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + </layout> </item> - <item row="3" column="1"> - <widget class="QLabel" name="labelUnconfirmed"> - <property name="font"> - <font> - <weight>75</weight> - <bold>true</bold> - </font> - </property> - <property name="cursor"> - <cursorShape>IBeamCursor</cursorShape> - </property> - <property name="toolTip"> - <string>Total of transactions that have yet to be confirmed, and do not yet count toward the current balance</string> - </property> - <property name="text"> - <string notr="true">0 BTC</string> - </property> - <property name="textInteractionFlags"> - <set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set> + <item> + <layout class="QFormLayout" name="formLayout_2"> + <property name="fieldGrowthPolicy"> + <enum>QFormLayout::AllNonFixedFieldsGrow</enum> </property> - </widget> - </item> - <item row="1" column="0"> - <widget class="QLabel" name="label_5"> - <property name="font"> - <font> - <pointsize>11</pointsize> - <weight>75</weight> - <bold>true</bold> - </font> + <property name="horizontalSpacing"> + <number>12</number> </property> - <property name="text"> - <string>Wallet</string> + <property name="verticalSpacing"> + <number>12</number> </property> - </widget> + <item row="0" column="0"> + <widget class="QLabel" name="label"> + <property name="text"> + <string>Balance:</string> + </property> + </widget> + </item> + <item row="0" column="1"> + <widget class="QLabel" name="labelBalance"> + <property name="font"> + <font> + <weight>75</weight> + <bold>true</bold> + </font> + </property> + <property name="cursor"> + <cursorShape>IBeamCursor</cursorShape> + </property> + <property name="toolTip"> + <string>Your current balance</string> + </property> + <property name="text"> + <string notr="true">123.456 BTC</string> + </property> + <property name="textInteractionFlags"> + <set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set> + </property> + </widget> + </item> + <item row="1" column="0"> + <widget class="QLabel" name="label_3"> + <property name="text"> + <string>Unconfirmed:</string> + </property> + </widget> + </item> + <item row="1" column="1"> + <widget class="QLabel" name="labelUnconfirmed"> + <property name="font"> + <font> + <weight>75</weight> + <bold>true</bold> + </font> + </property> + <property name="cursor"> + <cursorShape>IBeamCursor</cursorShape> + </property> + <property name="toolTip"> + <string>Total of transactions that have yet to be confirmed, and do not yet count toward the current balance</string> + </property> + <property name="text"> + <string notr="true">0 BTC</string> + </property> + <property name="textInteractionFlags"> + <set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set> + </property> + </widget> + </item> + <item row="2" column="0"> + <widget class="QLabel" name="label_2"> + <property name="text"> + <string>Number of transactions:</string> + </property> + </widget> + </item> + <item row="2" column="1"> + <widget class="QLabel" name="labelNumTransactions"> + <property name="toolTip"> + <string>Total number of transactions in wallet</string> + </property> + <property name="text"> + <string notr="true">0</string> + </property> + </widget> + </item> + </layout> </item> </layout> </widget> @@ -153,16 +190,49 @@ </property> <layout class="QVBoxLayout" name="verticalLayout"> <item> - <widget class="QLabel" name="label_4"> - <property name="text"> - <string><b>Recent transactions</b></string> - </property> - </widget> + <layout class="QHBoxLayout" name="horizontalLayout_2"> + <item> + <widget class="QLabel" name="label_4"> + <property name="text"> + <string><b>Recent transactions</b></string> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="labelTransactionsStatus"> + <property name="toolTip"> + <string>The displayed information may be out of date. Your wallet automatically synchronizes with the Bitcoin network after a connection is established, but this process has not completed yet.</string> + </property> + <property name="styleSheet"> + <string notr="true">QLabel { color: red; }</string> + </property> + <property name="text"> + <string notr="true">(out of sync)</string> + </property> + <property name="alignment"> + <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> + </property> + </widget> + </item> + <item> + <spacer name="horizontalSpacer"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + </layout> </item> <item> <widget class="QListView" name="listTransactions"> <property name="styleSheet"> - <string notr="true">QListView { background:transparent }</string> + <string notr="true">QListView { background: transparent; }</string> </property> <property name="frameShape"> <enum>QFrame::NoFrame</enum> diff --git a/src/qt/guiutil.h b/src/qt/guiutil.h index f30d5db35b..c5f9aae511 100644 --- a/src/qt/guiutil.h +++ b/src/qt/guiutil.h @@ -22,7 +22,7 @@ namespace GUIUtil QString dateTimeStr(const QDateTime &datetime); QString dateTimeStr(qint64 nTime); - // Render bitcoin addresses in monospace font + // Render Bitcoin addresses in monospace font QFont bitcoinAddressFont(); // Set up widgets for address and amounts diff --git a/src/qt/optionsmodel.cpp b/src/qt/optionsmodel.cpp index 181dec4400..9f1c6447ae 100644 --- a/src/qt/optionsmodel.cpp +++ b/src/qt/optionsmodel.cpp @@ -24,7 +24,7 @@ void OptionsModel::Init() nTransactionFee = settings.value("nTransactionFee").toLongLong(); language = settings.value("language", "").toString(); - // These are shared with core bitcoin; we want + // These are shared with core Bitcoin; we want // command-line options to override the GUI settings: if (settings.contains("fUseUPnP")) SoftSetBoolArg("-upnp", settings.value("fUseUPnP").toBool()); diff --git a/src/qt/optionsmodel.h b/src/qt/optionsmodel.h index 4315a33f8c..c0374689c6 100644 --- a/src/qt/optionsmodel.h +++ b/src/qt/optionsmodel.h @@ -3,8 +3,8 @@ #include <QAbstractListModel> -/** Interface from QT to configuration data structure for bitcoin client. - To QT, the options are presented as a list with the different options +/** Interface from Qt to configuration data structure for Bitcoin client. + To Qt, the options are presented as a list with the different options laid out vertically. This can be changed to a tree once the settings become sufficiently complex. diff --git a/src/qt/overviewpage.cpp b/src/qt/overviewpage.cpp index d0ba377967..d7bcc6f45e 100644 --- a/src/qt/overviewpage.cpp +++ b/src/qt/overviewpage.cpp @@ -105,6 +105,13 @@ OverviewPage::OverviewPage(QWidget *parent) : ui->listTransactions->setAttribute(Qt::WA_MacShowFocusRect, false); connect(ui->listTransactions, SIGNAL(clicked(QModelIndex)), this, SLOT(handleTransactionClicked(QModelIndex))); + + // init "out of sync" warning labels + ui->labelWalletStatus->setText("(" + tr("out of sync") + ")"); + ui->labelTransactionsStatus->setText("(" + tr("out of sync") + ")"); + + // start with displaying the "out of sync" warnings + showOutOfSyncWarning(true); } void OverviewPage::handleTransactionClicked(const QModelIndex &index) @@ -169,3 +176,9 @@ void OverviewPage::displayUnitChanged() txdelegate->unit = model->getOptionsModel()->getDisplayUnit(); ui->listTransactions->update(); } + +void OverviewPage::showOutOfSyncWarning(bool fShow) +{ + ui->labelWalletStatus->setVisible(fShow); + ui->labelTransactionsStatus->setVisible(fShow); +} diff --git a/src/qt/overviewpage.h b/src/qt/overviewpage.h index 1acd1b7f39..208b324feb 100644 --- a/src/qt/overviewpage.h +++ b/src/qt/overviewpage.h @@ -24,6 +24,7 @@ public: ~OverviewPage(); void setModel(WalletModel *model); + void showOutOfSyncWarning(bool fShow); public slots: void setBalance(qint64 balance, qint64 unconfirmedBalance); diff --git a/src/qt/res/icons/debugwindow.png b/src/qt/res/icons/debugwindow.png Binary files differnew file mode 100644 index 0000000000..1712adf0e7 --- /dev/null +++ b/src/qt/res/icons/debugwindow.png diff --git a/src/qt/rpcconsole.cpp b/src/qt/rpcconsole.cpp index 47fdac4208..0c77b05c56 100644 --- a/src/qt/rpcconsole.cpp +++ b/src/qt/rpcconsole.cpp @@ -109,7 +109,9 @@ RPCConsole::RPCConsole(QWidget *parent) : { ui->setupUi(this); -#ifndef WIN32 +#ifdef WIN32 + ui->openDebugLogfileButton->setIcon(QIcon(":/icons/export")); +#else // Show Debug logfile label and Open button only for Windows ui->labelDebugLogfile->setVisible(false); ui->openDebugLogfileButton->setVisible(false); diff --git a/src/qt/rpcconsole.h b/src/qt/rpcconsole.h index 0a7b10f4a2..27f41817ea 100644 --- a/src/qt/rpcconsole.h +++ b/src/qt/rpcconsole.h @@ -8,7 +8,7 @@ namespace Ui { } class ClientModel; -/** Local bitcoin RPC console. */ +/** Local Bitcoin RPC console. */ class RPCConsole: public QDialog { Q_OBJECT @@ -33,6 +33,7 @@ protected: private slots: void on_lineEdit_returnPressed(); void on_tabWidget_currentChanged(int index); + /** open the debug.log from the current datadir */ void on_openDebugLogfileButton_clicked(); public slots: diff --git a/src/rpcdump.cpp b/src/rpcdump.cpp index 1bc87e9217..1119aeaf75 100644 --- a/src/rpcdump.cpp +++ b/src/rpcdump.cpp @@ -88,7 +88,7 @@ Value dumpprivkey(const Array& params, bool fHelp) string strAddress = params[0].get_str(); CBitcoinAddress address; if (!address.SetString(strAddress)) - throw JSONRPCError(-5, "Invalid bitcoin address"); + throw JSONRPCError(-5, "Invalid Bitcoin address"); CSecret vchSecret; bool fCompressed; if (!pwalletMain->GetSecret(address, vchSecret, fCompressed)) diff --git a/src/sync.cpp b/src/sync.cpp index fd9bcb62bc..d8d86d525e 100644 --- a/src/sync.cpp +++ b/src/sync.cpp @@ -3,8 +3,9 @@ // file license.txt or http://www.opensource.org/licenses/mit-license.php. #include "sync.h" +#include "util.h" - +#include <boost/foreach.hpp> #ifdef DEBUG_LOCKORDER // @@ -40,7 +41,7 @@ private: typedef std::vector< std::pair<void*, CLockLocation> > LockStack; -static boost::interprocess::interprocess_mutex dd_mutex; +static boost::mutex dd_mutex; static std::map<std::pair<void*, void*>, LockStack> lockorders; static boost::thread_specific_ptr<LockStack> lockstack; @@ -66,7 +67,6 @@ static void potential_deadlock_detected(const std::pair<void*, void*>& mismatch, static void push_lock(void* c, const CLockLocation& locklocation, bool fTry) { - bool fOrderOK = true; if (lockstack.get() == NULL) lockstack.reset(new LockStack); @@ -75,20 +75,21 @@ static void push_lock(void* c, const CLockLocation& locklocation, bool fTry) (*lockstack).push_back(std::make_pair(c, locklocation)); - if (!fTry) BOOST_FOREACH(const PAIRTYPE(void*, CLockLocation)& i, (*lockstack)) - { - if (i.first == c) break; - - std::pair<void*, void*> p1 = std::make_pair(i.first, c); - if (lockorders.count(p1)) - continue; - lockorders[p1] = (*lockstack); - - std::pair<void*, void*> p2 = std::make_pair(c, i.first); - if (lockorders.count(p2)) - { - potential_deadlock_detected(p1, lockorders[p2], lockorders[p1]); - break; + if (!fTry) { + BOOST_FOREACH(const PAIRTYPE(void*, CLockLocation)& i, (*lockstack)) { + if (i.first == c) break; + + std::pair<void*, void*> p1 = std::make_pair(i.first, c); + if (lockorders.count(p1)) + continue; + lockorders[p1] = (*lockstack); + + std::pair<void*, void*> p2 = std::make_pair(c, i.first); + if (lockorders.count(p2)) + { + potential_deadlock_detected(p1, lockorders[p2], lockorders[p1]); + break; + } } } dd_mutex.unlock(); diff --git a/src/sync.h b/src/sync.h index 44d753ac15..1604338fb6 100644 --- a/src/sync.h +++ b/src/sync.h @@ -5,19 +5,19 @@ #ifndef BITCOIN_SYNC_H #define BITCOIN_SYNC_H -#include <boost/interprocess/sync/interprocess_recursive_mutex.hpp> -#include <boost/interprocess/sync/scoped_lock.hpp> -#include <boost/interprocess/sync/interprocess_semaphore.hpp> -#include <boost/interprocess/sync/lock_options.hpp> +#include <boost/thread/mutex.hpp> +#include <boost/thread/recursive_mutex.hpp> +#include <boost/thread/locks.hpp> +#include <boost/thread/condition_variable.hpp> /** Wrapped boost mutex: supports recursive locking, but no waiting */ -typedef boost::interprocess::interprocess_recursive_mutex CCriticalSection; +typedef boost::recursive_mutex CCriticalSection; /** Wrapped boost mutex: supports waiting but not recursive locking */ -typedef boost::interprocess::interprocess_mutex CWaitableCriticalSection; +typedef boost::mutex CWaitableCriticalSection; #ifdef DEBUG_LOCKORDER void EnterCritical(const char* pszName, const char* pszFile, int nLine, void* cs, bool fTry = false); @@ -32,12 +32,12 @@ template<typename Mutex> class CMutexLock { private: - boost::interprocess::scoped_lock<Mutex> lock; + boost::unique_lock<Mutex> lock; public: void Enter(const char* pszName, const char* pszFile, int nLine) { - if (!lock.owns()) + if (!lock.owns_lock()) { EnterCritical(pszName, pszFile, nLine, (void*)(lock.mutex())); #ifdef DEBUG_LOCKCONTENTION @@ -55,7 +55,7 @@ public: void Leave() { - if (lock.owns()) + if (lock.owns_lock()) { lock.unlock(); LeaveCritical(); @@ -64,17 +64,17 @@ public: bool TryEnter(const char* pszName, const char* pszFile, int nLine) { - if (!lock.owns()) + if (!lock.owns_lock()) { EnterCritical(pszName, pszFile, nLine, (void*)(lock.mutex()), true); lock.try_lock(); - if (!lock.owns()) + if (!lock.owns_lock()) LeaveCritical(); } - return lock.owns(); + return lock.owns_lock(); } - CMutexLock(Mutex& mutexIn, const char* pszName, const char* pszFile, int nLine, bool fTry = false) : lock(mutexIn, boost::interprocess::defer_lock) + CMutexLock(Mutex& mutexIn, const char* pszName, const char* pszFile, int nLine, bool fTry = false) : lock(mutexIn, boost::defer_lock) { if (fTry) TryEnter(pszName, pszFile, nLine); @@ -84,16 +84,16 @@ public: ~CMutexLock() { - if (lock.owns()) + if (lock.owns_lock()) LeaveCritical(); } operator bool() { - return lock.owns(); + return lock.owns_lock(); } - boost::interprocess::scoped_lock<Mutex> &GetLock() + boost::unique_lock<Mutex> &GetLock() { return lock; } @@ -117,47 +117,40 @@ typedef CMutexLock<CCriticalSection> CCriticalBlock; LeaveCritical(); \ } -#ifdef MAC_OSX -// boost::interprocess::interprocess_semaphore seems to spinlock on OSX; prefer polling instead class CSemaphore { private: - CCriticalSection cs; - int val; + boost::condition_variable condition; + boost::mutex mutex; + int value; public: - CSemaphore(int init) : val(init) {} + CSemaphore(int init) : value(init) {} void wait() { - do { - { - LOCK(cs); - if (val>0) { - val--; - return; - } - } - Sleep(100); - } while(1); + boost::unique_lock<boost::mutex> lock(mutex); + while (value < 1) { + condition.wait(lock); + } + value--; } bool try_wait() { - LOCK(cs); - if (val>0) { - val--; - return true; - } - return false; + boost::unique_lock<boost::mutex> lock(mutex); + if (value < 1) + return false; + value--; + return true; } void post() { - LOCK(cs); - val++; + { + boost::unique_lock<boost::mutex> lock(mutex); + value++; + } + condition.notify_one(); } }; -#else -typedef boost::interprocess::interprocess_semaphore CSemaphore; -#endif /** RAII-style semaphore lock */ class CSemaphoreGrant diff --git a/src/test/util_tests.cpp b/src/test/util_tests.cpp index 0393edb1a7..2bfda61675 100644 --- a/src/test/util_tests.cpp +++ b/src/test/util_tests.cpp @@ -105,7 +105,7 @@ BOOST_AUTO_TEST_CASE(util_DateTimeStrFormat) { BOOST_CHECK_EQUAL(DateTimeStrFormat("%x %H:%M:%S", 0), "01/01/70 00:00:00"); BOOST_CHECK_EQUAL(DateTimeStrFormat("%x %H:%M:%S", 0x7FFFFFFF), "01/19/38 03:14:07"); - // Formats used within bitcoin + // Formats used within Bitcoin BOOST_CHECK_EQUAL(DateTimeStrFormat("%x %H:%M:%S", 1317425777), "09/30/11 23:36:17"); BOOST_CHECK_EQUAL(DateTimeStrFormat("%x %H:%M", 1317425777), "09/30/11 23:36"); } diff --git a/src/util.cpp b/src/util.cpp index 823d00a4ee..c778e51e3b 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -27,6 +27,7 @@ namespace boost { #include <boost/foreach.hpp> #include <openssl/crypto.h> #include <openssl/rand.h> +#include <stdarg.h> #ifdef WIN32 #ifdef _MSC_VER @@ -47,6 +48,7 @@ namespace boost { #ifndef NOMINMAX #define NOMINMAX #endif +#include <io.h> /* for _commit */ #include "shlobj.h" #endif @@ -180,8 +182,6 @@ int GetRandInt(int nMax) - - inline int OutputDebugStringF(const char* pszFormat, ...) { int ret = 0; @@ -228,68 +228,30 @@ inline int OutputDebugStringF(const char* pszFormat, ...) { static CCriticalSection cs_OutputDebugStringF; - // accumulate a line at a time + // accumulate and output a line at a time { LOCK(cs_OutputDebugStringF); - static char pszBuffer[50000]; - static char* pend; - if (pend == NULL) - pend = pszBuffer; + static std::string buffer; + va_list arg_ptr; va_start(arg_ptr, pszFormat); - int limit = END(pszBuffer) - pend - 2; - int ret = _vsnprintf(pend, limit, pszFormat, arg_ptr); + buffer += vstrprintf(pszFormat, arg_ptr); va_end(arg_ptr); - if (ret < 0 || ret >= limit) - { - pend = END(pszBuffer) - 2; - *pend++ = '\n'; - } - else - pend += ret; - *pend = '\0'; - char* p1 = pszBuffer; - char* p2; - while ((p2 = strchr(p1, '\n'))) + + int line_start = 0, line_end; + while((line_end = buffer.find('\n', line_start)) != -1) { - p2++; - char c = *p2; - *p2 = '\0'; - OutputDebugStringA(p1); - *p2 = c; - p1 = p2; + OutputDebugStringA(buffer.substr(line_start, line_end - line_start).c_str()); + line_start = line_end + 1; } - if (p1 != pszBuffer) - memmove(pszBuffer, p1, pend - p1 + 1); - pend -= (p1 - pszBuffer); + buffer.erase(0, line_start); } } #endif return ret; } - -// Safer snprintf -// - prints up to limit-1 characters -// - output string is always null terminated even if limit reached -// - return value is the number of characters actually printed -int my_snprintf(char* buffer, size_t limit, const char* format, ...) -{ - if (limit == 0) - return 0; - va_list arg_ptr; - va_start(arg_ptr, format); - int ret = _vsnprintf(buffer, limit, format, arg_ptr); - va_end(arg_ptr); - if (ret < 0 || ret >= (int)limit) - { - ret = limit - 1; - buffer[limit-1] = 0; - } - return ret; -} - -string real_strprintf(const std::string &format, int dummy, ...) +string vstrprintf(const std::string &format, va_list ap) { char buffer[50000]; char* p = buffer; @@ -298,7 +260,7 @@ string real_strprintf(const std::string &format, int dummy, ...) loop { va_list arg_ptr; - va_start(arg_ptr, dummy); + va_copy(arg_ptr, ap); ret = _vsnprintf(p, limit, format.c_str(), arg_ptr); va_end(arg_ptr); if (ret >= 0 && ret < limit) @@ -316,19 +278,22 @@ string real_strprintf(const std::string &format, int dummy, ...) return str; } +string real_strprintf(const std::string &format, int dummy, ...) +{ + va_list arg_ptr; + va_start(arg_ptr, dummy); + string str = vstrprintf(format, arg_ptr); + va_end(arg_ptr); + return str; +} + bool error(const char *format, ...) { - char buffer[50000]; - int limit = sizeof(buffer); va_list arg_ptr; va_start(arg_ptr, format); - int ret = _vsnprintf(buffer, limit, format, arg_ptr); + std::string str = vstrprintf(format, arg_ptr); va_end(arg_ptr); - if (ret < 0 || ret >= limit) - { - buffer[limit - 1] = 0; - } - printf("ERROR: %s\n", buffer); + printf("ERROR: %s\n", str.c_str()); return false; } @@ -756,7 +721,7 @@ bool WildcardMatch(const string& str, const string& mask) -void FormatException(char* pszMessage, std::exception* pex, const char* pszThread) +static std::string FormatException(std::exception* pex, const char* pszThread) { #ifdef WIN32 char pszModule[MAX_PATH] = ""; @@ -765,37 +730,34 @@ void FormatException(char* pszMessage, std::exception* pex, const char* pszThrea const char* pszModule = "bitcoin"; #endif if (pex) - snprintf(pszMessage, 1000, + return strprintf( "EXCEPTION: %s \n%s \n%s in %s \n", typeid(*pex).name(), pex->what(), pszModule, pszThread); else - snprintf(pszMessage, 1000, + return strprintf( "UNKNOWN EXCEPTION \n%s in %s \n", pszModule, pszThread); } void LogException(std::exception* pex, const char* pszThread) { - char pszMessage[10000]; - FormatException(pszMessage, pex, pszThread); - printf("\n%s", pszMessage); + std::string message = FormatException(pex, pszThread); + printf("\n%s", message.c_str()); } void PrintException(std::exception* pex, const char* pszThread) { - char pszMessage[10000]; - FormatException(pszMessage, pex, pszThread); - printf("\n\n************************\n%s\n", pszMessage); - fprintf(stderr, "\n\n************************\n%s\n", pszMessage); - strMiscWarning = pszMessage; + std::string message = FormatException(pex, pszThread); + printf("\n\n************************\n%s\n", message.c_str()); + fprintf(stderr, "\n\n************************\n%s\n", message.c_str()); + strMiscWarning = message; throw; } void PrintExceptionContinue(std::exception* pex, const char* pszThread) { - char pszMessage[10000]; - FormatException(pszMessage, pex, pszThread); - printf("\n\n************************\n%s\n", pszMessage); - fprintf(stderr, "\n\n************************\n%s\n", pszMessage); - strMiscWarning = pszMessage; + std::string message = FormatException(pex, pszThread); + printf("\n\n************************\n%s\n", message.c_str()); + fprintf(stderr, "\n\n************************\n%s\n", message.c_str()); + strMiscWarning = message; } boost::filesystem::path GetDefaultDataDir() @@ -910,6 +872,27 @@ void CreatePidFile(const boost::filesystem::path &path, pid_t pid) } } +bool RenameOver(boost::filesystem::path src, boost::filesystem::path dest) +{ +#ifdef WIN32 + return MoveFileExA(src.string().c_str(), dest.string().c_str(), + MOVEFILE_REPLACE_EXISTING); +#else + int rc = std::rename(src.string().c_str(), dest.string().c_str()); + return (rc == 0); +#endif /* WIN32 */ +} + +void FileCommit(FILE *fileout) +{ + fflush(fileout); // harmless if redundantly called +#ifdef WIN32 + _commit(_fileno(fileout)); +#else + fsync(fileno(fileout)); +#endif +} + int GetFilesize(FILE* file) { int nSavePos = ftell(file); diff --git a/src/util.h b/src/util.h index 8e65fa7864..b90cb43eec 100644 --- a/src/util.h +++ b/src/util.h @@ -43,11 +43,6 @@ static const int64 CENT = 1000000; #define ARRAYLEN(array) (sizeof(array)/sizeof((array)[0])) #define printf OutputDebugStringF -#ifdef snprintf -#undef snprintf -#endif -#define snprintf my_snprintf - #ifndef PRI64d #if defined(_MSC_VER) || defined(__MSVCRT__) #define PRI64d "I64d" @@ -133,6 +128,7 @@ int my_snprintf(char* buffer, size_t limit, const char* format, ...); */ std::string real_strprintf(const std::string &format, int dummy, ...); #define strprintf(format, ...) real_strprintf(format, 0, __VA_ARGS__) +std::string vstrprintf(const std::string &format, va_list ap); bool error(const char *format, ...); void LogException(std::exception* pex, const char* pszThread); @@ -152,7 +148,9 @@ std::string EncodeBase64(const std::string& str); void ParseParameters(int argc, const char*const argv[]); bool WildcardMatch(const char* psz, const char* mask); bool WildcardMatch(const std::string& str, const std::string& mask); +void FileCommit(FILE *fileout); int GetFilesize(FILE* file); +bool RenameOver(boost::filesystem::path src, boost::filesystem::path dest); boost::filesystem::path GetDefaultDataDir(); const boost::filesystem::path &GetDataDir(bool fNetSpecific = true); boost::filesystem::path GetConfigFile(); diff --git a/src/wallet.cpp b/src/wallet.cpp index 998909897f..768f9f85ea 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -242,7 +242,8 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase) if (fFileBacked) { pwalletdbEncryption = new CWalletDB(strWalletFile); - pwalletdbEncryption->TxnBegin(); + if (!pwalletdbEncryption->TxnBegin()) + return false; pwalletdbEncryption->WriteMasterKey(nMasterKeyMaxID, kMasterKey); } @@ -1250,7 +1251,7 @@ string CWallet::SendMoneyToBitcoinAddress(const CBitcoinAddress& address, int64 if (nValue + nTransactionFee > GetBalance()) return _("Insufficient funds"); - // Parse bitcoin address + // Parse Bitcoin address CScript scriptPubKey; scriptPubKey.SetBitcoinAddress(address); |