From 4986c35d74afd6fc313d7637eb0220f3df500009 Mon Sep 17 00:00:00 2001 From: Gavin Andresen Date: Mon, 19 Dec 2011 19:04:47 -0500 Subject: [PATCH 1/7] Code cleanup: use ECDSA_size() instead of fixed 10,000 byte sig buffer, and explicity init static var --- src/key.h | 13 +++++++------ src/main.cpp | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/key.h b/src/key.h index 89d82fc8036..477f550bcf4 100644 --- a/src/key.h +++ b/src/key.h @@ -214,13 +214,14 @@ public: bool Sign(uint256 hash, std::vector& vchSig) { - vchSig.clear(); - unsigned char pchSig[10000]; - unsigned int nSize = 0; - if (!ECDSA_sign(0, (unsigned char*)&hash, sizeof(hash), pchSig, &nSize, pkey)) + unsigned int nSize = ECDSA_size(pkey); + vchSig.resize(nSize); // Make sure it is big enough + if (!ECDSA_sign(0, (unsigned char*)&hash, sizeof(hash), &vchSig[0], &nSize, pkey)) + { + vchSig.clear(); return false; - vchSig.resize(nSize); - memcpy(&vchSig[0], pchSig, nSize); + } + vchSig.resize(nSize); // Shrink to fit actual size return true; } diff --git a/src/main.cpp b/src/main.cpp index 652d4c1f981..cd02652660a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1921,7 +1921,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) } // Ask the first connected node for block updates - static int nAskedForBlocks; + static int nAskedForBlocks = 0; if (!pfrom->fClient && (pfrom->nVersion < 32000 || pfrom->nVersion >= 32400) && (nAskedForBlocks < 1 || vNodes.size() <= 1)) From 76a3bfa17c65481088df5713c0619f67cd856a83 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Thu, 15 Mar 2012 22:55:12 -0400 Subject: [PATCH 2/7] Fix Win32 RPC Crashes. --- bitcoin-qt.pro | 4 ++-- contrib/gitian-descriptors/qt-win32.yml | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/bitcoin-qt.pro b/bitcoin-qt.pro index 790c0751ca0..7fcb5079adb 100644 --- a/bitcoin-qt.pro +++ b/bitcoin-qt.pro @@ -251,8 +251,8 @@ isEmpty(BOOST_INCLUDE_PATH) { macx:BOOST_INCLUDE_PATH = /opt/local/include } -windows:LIBS += -lws2_32 -windows:DEFINES += WIN32 +windows:LIBS += -lmingwthrd -lws2_32 +windows:DEFINES += _MT WIN32 windows:RC_FILE = src/qt/res/bitcoin-qt.rc macx:HEADERS += src/qt/macdockiconhandler.h diff --git a/contrib/gitian-descriptors/qt-win32.yml b/contrib/gitian-descriptors/qt-win32.yml index 6eb76b21707..adccebbb918 100644 --- a/contrib/gitian-descriptors/qt-win32.yml +++ b/contrib/gitian-descriptors/qt-win32.yml @@ -47,6 +47,7 @@ script: | cp -a bin $SRCDIR/ cd $INSTDIR find . -name *.prl | xargs -l sed 's|/$||' -i + sed 's/QMAKE_LIBS_QT_ENTRY = -lmingw32 -lqtmain/QMAKE_LIBS_QT_ENTRY = -lqtmain/' -i mkspecs/unsupported/win32-g++-cross/qmake.conf #sed 's|QMAKE_PRL_LIBS.*|QMAKE_PRL_LIBS = -lQtDeclarative -lQtScript -lQtSvg -lQtSql -lQtXmlPatterns -lQtGui -lgdi32 -lcomdlg32 -loleaut32 -limm32 -lwinmm -lwinspool -lmsimg32 -lQtNetwork -lQtCore -lole32 -luuid -lws2_32 -ladvapi32 -lshell32 -luser32 -lkernel32|' -i imports/Qt/labs/particles/qmlparticlesplugin.prl # as zip stores file timestamps, use faketime to intercept stat calls to set dates for all files to reference date From ffef16404d16678d54e767dda6c301ad51fb82a7 Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Fri, 16 Mar 2012 16:04:26 -0400 Subject: [PATCH 3/7] Bump version to 0.4.5 --- contrib/Bitcoin.app/Contents/Info.plist | 2 +- doc/README | 2 +- doc/README_windows.txt | 2 +- share/setup.nsi | 6 +++--- src/serialize.h | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/contrib/Bitcoin.app/Contents/Info.plist b/contrib/Bitcoin.app/Contents/Info.plist index bef67460c88..b34827e3ca8 100644 --- a/contrib/Bitcoin.app/Contents/Info.plist +++ b/contrib/Bitcoin.app/Contents/Info.plist @@ -17,7 +17,7 @@ CFBundlePackageType APPL CFBundleShortVersionString - 0.4.4 + 0.4.5 CFBundleSignature ???? CFBundleVersion diff --git a/doc/README b/doc/README index 197f03dd56b..e572b2dd530 100644 --- a/doc/README +++ b/doc/README @@ -1,4 +1,4 @@ -Bitcoin 0.4.4 BETA +Bitcoin 0.4.5 BETA Copyright (c) 2009-2012 Bitcoin Developers Distributed under the MIT/X11 software license, see the accompanying diff --git a/doc/README_windows.txt b/doc/README_windows.txt index ad357130c27..6a551a0b971 100644 --- a/doc/README_windows.txt +++ b/doc/README_windows.txt @@ -1,4 +1,4 @@ -Bitcoin 0.4.4 BETA +Bitcoin 0.4.5 BETA Copyright (c) 2009-2012 Bitcoin Developers Distributed under the MIT/X11 software license, see the accompanying diff --git a/share/setup.nsi b/share/setup.nsi index 05983117909..643b0ffef8b 100644 --- a/share/setup.nsi +++ b/share/setup.nsi @@ -5,7 +5,7 @@ SetCompressor /SOLID lzma # General Symbol Definitions !define REGKEY "SOFTWARE\$(^Name)" -!define VERSION 0.4.4 +!define VERSION 0.4.5 !define COMPANY "Bitcoin project" !define URL http://www.bitcoin.org/ @@ -45,13 +45,13 @@ Var StartMenuGroup !insertmacro MUI_LANGUAGE English # Installer attributes -OutFile bitcoin-0.4.4-win32-setup.exe +OutFile bitcoin-0.4.5-win32-setup.exe InstallDir $PROGRAMFILES\Bitcoin CRCCheck on XPStyle on BrandingText " " ShowInstDetails show -VIProductVersion 0.4.4.0 +VIProductVersion 0.4.5.0 VIAddVersionKey ProductName Bitcoin VIAddVersionKey ProductVersion "${VERSION}" VIAddVersionKey CompanyName "${COMPANY}" diff --git a/src/serialize.h b/src/serialize.h index 2bc3a071d77..491169ff58b 100644 --- a/src/serialize.h +++ b/src/serialize.h @@ -59,7 +59,7 @@ class CDataStream; class CAutoFile; static const unsigned int MAX_SIZE = 0x02000000; -static const int VERSION = 40400; +static const int VERSION = 40500; static const char* pszSubVer = ""; static const bool VERSION_IS_BETA = true; From f322aa4d600f64eea8395811900dc98d562f1dac Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Fri, 16 Mar 2012 16:11:11 -0400 Subject: [PATCH 4/7] Bump version to 0.5.0.5 --- bitcoin-qt.pro | 2 +- doc/README | 2 +- doc/README_windows.txt | 2 +- share/setup.nsi | 6 +++--- src/serialize.h | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/bitcoin-qt.pro b/bitcoin-qt.pro index 7fcb5079adb..64b9670bfde 100644 --- a/bitcoin-qt.pro +++ b/bitcoin-qt.pro @@ -1,6 +1,6 @@ TEMPLATE = app TARGET = -VERSION = 0.5.0.4 +VERSION = 0.5.0.5 INCLUDEPATH += src src/json src/qt DEFINES += QT_GUI BOOST_THREAD_USE_LIB CONFIG += no_include_pwd diff --git a/doc/README b/doc/README index 6af11c3497e..9b3c561cbe1 100644 --- a/doc/README +++ b/doc/README @@ -1,4 +1,4 @@ -Bitcoin 0.5.0.4 BETA +Bitcoin 0.5.0.5 BETA Copyright (c) 2009-2012 Bitcoin Developers Distributed under the MIT/X11 software license, see the accompanying diff --git a/doc/README_windows.txt b/doc/README_windows.txt index 25cb0692665..c23b0ea84d5 100644 --- a/doc/README_windows.txt +++ b/doc/README_windows.txt @@ -1,4 +1,4 @@ -Bitcoin 0.5.0.4 BETA +Bitcoin 0.5.0.5 BETA Copyright (c) 2009-2012 Bitcoin Developers Distributed under the MIT/X11 software license, see the accompanying diff --git a/share/setup.nsi b/share/setup.nsi index 76ae81762db..4f764153e18 100644 --- a/share/setup.nsi +++ b/share/setup.nsi @@ -5,7 +5,7 @@ SetCompressor /SOLID lzma # General Symbol Definitions !define REGKEY "SOFTWARE\$(^Name)" -!define VERSION 0.5.0.4 +!define VERSION 0.5.0.5 !define COMPANY "Bitcoin project" !define URL http://www.bitcoin.org/ @@ -45,13 +45,13 @@ Var StartMenuGroup !insertmacro MUI_LANGUAGE English # Installer attributes -OutFile bitcoin-0.5.0.4-win32-setup.exe +OutFile bitcoin-0.5.0.5-win32-setup.exe InstallDir $PROGRAMFILES\Bitcoin CRCCheck on XPStyle on BrandingText " " ShowInstDetails show -VIProductVersion 0.5.0.4 +VIProductVersion 0.5.0.5 VIAddVersionKey ProductName Bitcoin VIAddVersionKey ProductVersion "${VERSION}" VIAddVersionKey CompanyName "${COMPANY}" diff --git a/src/serialize.h b/src/serialize.h index f5772024434..f10f933b163 100644 --- a/src/serialize.h +++ b/src/serialize.h @@ -60,7 +60,7 @@ class CDataStream; class CAutoFile; static const unsigned int MAX_SIZE = 0x02000000; -static const int VERSION = 50004; +static const int VERSION = 50005; static const char* pszSubVer = ""; static const bool VERSION_IS_BETA = true; From 458b6e64368b06f8951e2fe5849272c11923dca8 Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Wed, 15 Feb 2012 14:47:08 +0100 Subject: [PATCH 5/7] fix default suffixes in save dialog in GNOME, make it more clear that PNG is used (solves #833) --- src/qt/addressbookpage.cpp | 6 ++--- src/qt/guiutil.cpp | 49 ++++++++++++++++++++++++++++++++++++++ src/qt/guiutil.h | 15 ++++++++++++ src/qt/transactionview.cpp | 6 ++--- 4 files changed, 68 insertions(+), 8 deletions(-) diff --git a/src/qt/addressbookpage.cpp b/src/qt/addressbookpage.cpp index 0a147c9e104..76061233fc8 100644 --- a/src/qt/addressbookpage.cpp +++ b/src/qt/addressbookpage.cpp @@ -7,7 +7,6 @@ #include #include -#include #include AddressBookPage::AddressBookPage(Mode mode, Tabs tab, QWidget *parent) : @@ -206,10 +205,9 @@ void AddressBookPage::done(int retval) void AddressBookPage::exportClicked() { // CSV is currently the only supported format - QString filename = QFileDialog::getSaveFileName( + QString filename = GUIUtil::getSaveFileName( this, - tr("Export Address Book Data"), - QDir::currentPath(), + tr("Export Address Book Data"), QString(), tr("Comma separated file (*.csv)")); if (filename.isNull()) return; diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp index bc443ceeb65..d1490c8f705 100644 --- a/src/qt/guiutil.cpp +++ b/src/qt/guiutil.cpp @@ -11,6 +11,8 @@ #include #include #include +#include +#include QString GUIUtil::dateTimeStr(qint64 nTime) { @@ -86,3 +88,50 @@ bool GUIUtil::parseBitcoinURL(QString url, SendCoinsRecipient *out) QUrl urlInstance(url); return parseBitcoinURL(&urlInstance, out); } + +QString GUIUtil::getSaveFileName(QWidget *parent, const QString &caption, + const QString &dir, + const QString &filter, + QString *selectedSuffixOut) +{ + QString selectedFilter; + QString myDir; + if(dir.isEmpty()) // Default to user documents location + { + myDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation); + } + else + { + myDir = dir; + } + QString result = QFileDialog::getSaveFileName(parent, caption, myDir, filter, &selectedFilter); + + /* Extract first suffix from filter pattern "Description (*.foo)" or "Description (*.foo *.bar ...) */ + QRegExp filter_re(".* \\(\\*\\.(.*)[ \\)]"); + QString selectedSuffix; + if(filter_re.exactMatch(selectedFilter)) + { + selectedSuffix = filter_re.cap(1); + } + + /* Add suffix if needed */ + QFileInfo info(result); + if(!result.isEmpty()) + { + if(info.suffix().isEmpty() && !selectedSuffix.isEmpty()) + { + /* No suffix specified, add selected suffix */ + if(!result.endsWith(".")) + result.append("."); + result.append(selectedSuffix); + } + } + + /* Return selected suffix if asked to */ + if(selectedSuffixOut) + { + *selectedSuffixOut = selectedSuffix; + } + return result; +} + diff --git a/src/qt/guiutil.h b/src/qt/guiutil.h index 129ab730384..d7523aa15c9 100644 --- a/src/qt/guiutil.h +++ b/src/qt/guiutil.h @@ -30,6 +30,21 @@ public: // See Bitcoin URL definition discussion here: https://bitcointalk.org/index.php?topic=33490.0 static bool parseBitcoinURL(const QUrl *url, SendCoinsRecipient *out); static bool parseBitcoinURL(QString url, SendCoinsRecipient *out); + + /** Get save file name, mimics QFileDialog::getSaveFileName, except that it appends a default suffix + when no suffix is provided by the user. + + @param[in] parent Parent window (or 0) + @param[in] caption Window caption (or empty, for default) + @param[in] dir Starting directory (or empty, to default to documents directory) + @param[in] filter Filter specification such as "Comma Separated Files (*.csv)" + @param[out] selectedSuffixOut Pointer to return the suffix (file type) that was selected (or 0). + Can be useful when choosing the save file format based on suffix. + */ + static QString getSaveFileName(QWidget *parent=0, const QString &caption=QString(), + const QString &dir=QString(), const QString &filter=QString(), + QString *selectedSuffixOut=0); + }; #endif // GUIUTIL_H diff --git a/src/qt/transactionview.cpp b/src/qt/transactionview.cpp index 3ef31854fb4..0bfce351a49 100644 --- a/src/qt/transactionview.cpp +++ b/src/qt/transactionview.cpp @@ -20,7 +20,6 @@ #include #include #include -#include #include #include #include @@ -265,10 +264,9 @@ void TransactionView::changedAmount(const QString &amount) void TransactionView::exportClicked() { // CSV is currently the only supported format - QString filename = QFileDialog::getSaveFileName( + QString filename = GUIUtil::getSaveFileName( this, - tr("Export Transaction Data"), - QDir::currentPath(), + tr("Export Transaction Data"), QString(), tr("Comma separated file (*.csv)")); if (filename.isNull()) return; From 91aadbdacf9a3111da76eb831ea36d6827e1d6fc Mon Sep 17 00:00:00 2001 From: Gavin Andresen Date: Thu, 16 Feb 2012 10:22:31 -0500 Subject: [PATCH 6/7] Fix issue #848 : broken mining on testnet --- src/main.cpp | 20 ++++++++++++++++++-- src/main.h | 2 ++ src/rpc.cpp | 2 +- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index cd02652660a..ebf51ae1469 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -807,6 +807,15 @@ void static InvalidChainFound(CBlockIndex* pindexNew) printf("InvalidChainFound: WARNING: Displayed transactions may not be correct! You may need to upgrade, or other nodes may need to upgrade.\n"); } +void CBlock::UpdateTime(const CBlockIndex* pindexPrev) +{ + nTime = max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime()); + + // Updating time can change work required on testnet: + if (fTestNet) + nBits = GetNextWorkRequired(pindexPrev, this); +} + @@ -2896,7 +2905,7 @@ CBlock* CreateNewBlock(CReserveKey& reservekey) // Fill in header pblock->hashPrevBlock = pindexPrev->GetBlockHash(); pblock->hashMerkleRoot = pblock->BuildMerkleTree(); - pblock->nTime = max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime()); + pblock->UpdateTime(pindexPrev); pblock->nBits = GetNextWorkRequired(pindexPrev, pblock.get()); pblock->nNonce = 0; @@ -3053,6 +3062,7 @@ void static BitcoinMiner(CWallet *pwallet) FormatHashBuffers(pblock.get(), pmidstate, pdata, phash1); unsigned int& nBlockTime = *(unsigned int*)(pdata + 64 + 4); + unsigned int& nBlockBits = *(unsigned int*)(pdata + 64 + 8); unsigned int& nBlockNonce = *(unsigned int*)(pdata + 64 + 12); @@ -3140,8 +3150,14 @@ void static BitcoinMiner(CWallet *pwallet) break; // Update nTime every few seconds - pblock->nTime = max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime()); + pblock->UpdateTime(pindexPrev); nBlockTime = ByteReverse(pblock->nTime); + if (fTestNet) + { + // Changing pblock->nTime can change work required on testnet: + nBlockBits = ByteReverse(pblock->nBits); + hashTarget = CBigNum().SetCompact(pblock->nBits).getuint256(); + } } } } diff --git a/src/main.h b/src/main.h index 3e381b060b2..278f4f01c05 100644 --- a/src/main.h +++ b/src/main.h @@ -846,6 +846,8 @@ public: return n; } + void UpdateTime(const CBlockIndex* pindexPrev); + uint256 BuildMerkleTree() const { diff --git a/src/rpc.cpp b/src/rpc.cpp index 8967b2c9968..aade32ac1d8 100644 --- a/src/rpc.cpp +++ b/src/rpc.cpp @@ -1548,7 +1548,7 @@ Value getwork(const Array& params, bool fHelp) } // Update nTime - pblock->nTime = max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime()); + pblock->UpdateTime(pindexPrev); pblock->nNonce = 0; // Update nExtraNonce From 27960a36de879634ee8c491d0f4fe8160e8a4f75 Mon Sep 17 00:00:00 2001 From: Gavin Andresen Date: Thu, 16 Feb 2012 10:22:31 -0500 Subject: [PATCH 7/7] Fix issue #848 : broken mining on testnet --- src/bitcoinrpc.cpp | 4 ++-- src/main.cpp | 20 ++++++++++++++++++-- src/main.h | 2 ++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index 36490e94f71..1f57bf9cd0d 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -1654,7 +1654,7 @@ Value getwork(const Array& params, bool fHelp) } // Update nTime - pblock->nTime = max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime()); + pblock->UpdateTime(pindexPrev); pblock->nNonce = 0; // Update nExtraNonce @@ -1751,7 +1751,7 @@ Value getmemorypool(const Array& params, bool fHelp) } // Update nTime - pblock->nTime = max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime()); + pblock->UpdateTime(pindexPrev); pblock->nNonce = 0; Array transactions; diff --git a/src/main.cpp b/src/main.cpp index 747805450a7..78a7ec3d275 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -820,6 +820,15 @@ void static InvalidChainFound(CBlockIndex* pindexNew) printf("InvalidChainFound: WARNING: Displayed transactions may not be correct! You may need to upgrade, or other nodes may need to upgrade.\n"); } +void CBlock::UpdateTime(const CBlockIndex* pindexPrev) +{ + nTime = max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime()); + + // Updating time can change work required on testnet: + if (fTestNet) + nBits = GetNextWorkRequired(pindexPrev, this); +} + @@ -2949,7 +2958,7 @@ CBlock* CreateNewBlock(CReserveKey& reservekey) // Fill in header pblock->hashPrevBlock = pindexPrev->GetBlockHash(); pblock->hashMerkleRoot = pblock->BuildMerkleTree(); - pblock->nTime = max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime()); + pblock->UpdateTime(pindexPrev); pblock->nBits = GetNextWorkRequired(pindexPrev, pblock.get()); pblock->nNonce = 0; @@ -3105,6 +3114,7 @@ void static BitcoinMiner(CWallet *pwallet) FormatHashBuffers(pblock.get(), pmidstate, pdata, phash1); unsigned int& nBlockTime = *(unsigned int*)(pdata + 64 + 4); + unsigned int& nBlockBits = *(unsigned int*)(pdata + 64 + 8); unsigned int& nBlockNonce = *(unsigned int*)(pdata + 64 + 12); @@ -3192,8 +3202,14 @@ void static BitcoinMiner(CWallet *pwallet) break; // Update nTime every few seconds - pblock->nTime = max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime()); + pblock->UpdateTime(pindexPrev); nBlockTime = ByteReverse(pblock->nTime); + if (fTestNet) + { + // Changing pblock->nTime can change work required on testnet: + nBlockBits = ByteReverse(pblock->nBits); + hashTarget = CBigNum().SetCompact(pblock->nBits).getuint256(); + } } } } diff --git a/src/main.h b/src/main.h index a1fb548f087..083d34029a9 100644 --- a/src/main.h +++ b/src/main.h @@ -856,6 +856,8 @@ public: return n; } + void UpdateTime(const CBlockIndex* pindexPrev); + uint256 BuildMerkleTree() const {