From 4986c35d74afd6fc313d7637eb0220f3df500009 Mon Sep 17 00:00:00 2001 From: Gavin Andresen Date: Mon, 19 Dec 2011 19:04:47 -0500 Subject: [PATCH 1/3] 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 ffef16404d16678d54e767dda6c301ad51fb82a7 Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Fri, 16 Mar 2012 16:04:26 -0400 Subject: [PATCH 2/3] 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 91aadbdacf9a3111da76eb831ea36d6827e1d6fc Mon Sep 17 00:00:00 2001 From: Gavin Andresen Date: Thu, 16 Feb 2012 10:22:31 -0500 Subject: [PATCH 3/3] 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