Merge branch 'master' of https://github.com/bitcoin/bitcoin
authorWladimir J. van der Laan <laanwj@gmail.com>
Sat, 3 Sep 2011 07:09:34 +0000 (09:09 +0200)
committerWladimir J. van der Laan <laanwj@gmail.com>
Sat, 3 Sep 2011 07:09:34 +0000 (09:09 +0200)
1  2 
src/main.cpp
src/serialize.h
src/util.cpp

diff --combined src/main.cpp
@@@ -31,7 -31,6 +31,7 @@@ map<uint256, CBlockIndex*> mapBlockInde
  uint256 hashGenesisBlock("0x000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f");
  static CBigNum bnProofOfWorkLimit(~uint256(0) >> 32);
  const int nTotalBlocksEstimate = 140700; // Conservative estimate of total nr of blocks on main chain
 +int nMaxBlocksOfOtherNodes = 0; // Maximum amount of blocks that other nodes claim to have
  const int nInitialBlockThreshold = 120; // Regard blocks up until N-threshold as "initial download"
  CBlockIndex* pindexGenesisBlock = NULL;
  int nBestHeight = -1;
@@@ -727,12 -726,6 +727,12 @@@ int GetTotalBlocksEstimate(
      }
  }
  
 +// Return maximum amount of blocks that other nodes claim to have
 +int GetMaxBlocksOfOtherNodes()
 +{
 +    return nMaxBlocksOfOtherNodes;
 +}
 +
  bool IsInitialBlockDownload()
  {
      if (pindexBest == NULL || nBestHeight < (GetTotalBlocksEstimate()-nInitialBlockThreshold))
@@@ -1830,7 -1823,9 +1830,9 @@@ bool static ProcessMessage(CNode* pfrom
  
          // Ask the first connected node for block updates
          static int nAskedForBlocks;
-         if (!pfrom->fClient && (nAskedForBlocks < 1 || vNodes.size() <= 1))
+         if (!pfrom->fClient &&
+             (pfrom->nVersion < 32000 || pfrom->nVersion >= 32400) &&
+              (nAskedForBlocks < 1 || vNodes.size() <= 1))
          {
              nAskedForBlocks++;
              pfrom->PushGetBlocks(pindexBest, uint256(0));
          pfrom->fSuccessfullyConnected = true;
  
          printf("version message: version %d, blocks=%d\n", pfrom->nVersion, pfrom->nStartingHeight);
 +        if(pfrom->nStartingHeight > nMaxBlocksOfOtherNodes)
 +        {
 +            nMaxBlocksOfOtherNodes = pfrom->nStartingHeight;
 +        }
      }
  
  
diff --combined src/serialize.h
@@@ -31,7 -31,6 +31,7 @@@ typedef unsigned long long  uint64
  #endif
  
  #ifdef __WXMSW__
 +#include <windows.h>
  // This is used to attempt to keep keying material out of swap
  // Note that VirtualLock does not provide this as a guarantee on Windows,
  // but, in practice, memory that has been VirtualLock'd almost never gets written to
@@@ -60,7 -59,7 +60,7 @@@ class CDataStream
  class CAutoFile;
  static const unsigned int MAX_SIZE = 0x02000000;
  
- static const int VERSION = 32500;
+ static const int VERSION = 40000;
  static const char* pszSubVer = "";
  static const bool VERSION_IS_BETA = true;
  
diff --combined src/util.cpp
@@@ -264,7 -264,8 +264,7 @@@ int my_snprintf(char* buffer, size_t li
      return ret;
  }
  
 -
 -string strprintf(const char* format, ...)
 +string strprintf(const std::string &format, ...)
  {
      char buffer[50000];
      char* p = buffer;
      {
          va_list arg_ptr;
          va_start(arg_ptr, format);
 -        ret = _vsnprintf(p, limit, format, arg_ptr);
 +        ret = _vsnprintf(p, limit, format.c_str(), arg_ptr);
          va_end(arg_ptr);
          if (ret >= 0 && ret < limit)
              break;
      return str;
  }
  
 -
 -bool error(const char* format, ...)
 +bool error(const std::string &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);
 +    int ret = _vsnprintf(buffer, limit, format.c_str(), arg_ptr);
      va_end(arg_ptr);
      if (ret < 0 || ret >= limit)
      {
@@@ -921,16 -923,22 +921,22 @@@ string FormatFullVersion(
  
  struct CLockLocation
  {
-     std::string mutexName;
-     std::string sourceFile;
-     int sourceLine;
      CLockLocation(const char* pszName, const char* pszFile, int nLine)
      {
          mutexName = pszName;
          sourceFile = pszFile;
          sourceLine = nLine;
      }
+     std::string ToString() const
+     {
+         return mutexName+"  "+sourceFile+":"+itostr(sourceLine);
+     }
+ private:
+     std::string mutexName;
+     std::string sourceFile;
+     int sourceLine;
  };
  
  typedef std::vector< std::pair<CCriticalSection*, CLockLocation> > LockStack;
@@@ -948,14 -956,14 +954,14 @@@ static void potential_deadlock_detected
      {
          if (i.first == mismatch.first) printf(" (1)");
          if (i.first == mismatch.second) printf(" (2)");
-         printf(" %s  %s:%d\n", i.second.mutexName.c_str(), i.second.sourceFile.c_str(), i.second.sourceLine);
+         printf(" %s\n", i.second.ToString().c_str());
      }
      printf("Current lock order is:\n");
      BOOST_FOREACH(const PAIRTYPE(CCriticalSection*, CLockLocation)& i, s1)
      {
          if (i.first == mismatch.first) printf(" (1)");
          if (i.first == mismatch.second) printf(" (2)");
-         printf(" %s  %s:%d\n", i.second.mutexName.c_str(), i.second.sourceFile.c_str(), i.second.sourceLine);
+         printf(" %s\n", i.second.ToString().c_str());
      }
  }
  
@@@ -965,6 -973,7 +971,7 @@@ static void push_lock(CCriticalSection
      if (lockstack.get() == NULL)
          lockstack.reset(new LockStack);
  
+     if (fDebug) printf("Locking: %s\n", locklocation.ToString().c_str());
      dd_mutex.lock();
  
      (*lockstack).push_back(std::make_pair(c, locklocation));
  
  static void pop_lock()
  {
+     if (fDebug) 
+     {
+         const CLockLocation& locklocation = (*lockstack).rbegin()->second;
+         printf("Unlocked: %s\n", locklocation.ToString().c_str());
+     }
+     dd_mutex.lock();
      (*lockstack).pop_back();
+     dd_mutex.unlock();
  }
  
  void CCriticalSection::Enter(const char* pszName, const char* pszFile, int nLine)