Advertisement
Guest User

ppcoin3 changes

a guest
Feb 23rd, 2013
1,071
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 88.45 KB | None | 0 0
  1. diff -N -r -u ppcoin-0.2.2ppc-linux/src/bitcoin-qt.pro ppcoin-0.3.0-linux/src/bitcoin-qt.pro
  2. --- ppcoin-0.2.2ppc-linux/src/bitcoin-qt.pro    2012-11-12 13:41:49.000000000 -0800
  3. +++ ppcoin-0.3.0-linux/src/bitcoin-qt.pro       2013-02-16 21:33:40.000000000 -0800
  4. @@ -1,5 +1,5 @@
  5.  TEMPLATE = app
  6. -TARGET =
  7. +TARGET = ppcoin-qt
  8.  VERSION = 0.6.3.0
  9.  INCLUDEPATH += src src/json src/qt
  10.  DEFINES += QT_GUI BOOST_THREAD_USE_LIB BOOST_SPIRIT_THREADSAFE
  11. @@ -158,7 +158,8 @@
  12.      src/qt/notificator.h \
  13.      src/qt/qtipcserver.h \
  14.      src/allocators.h \
  15. -    src/ui_interface.h
  16. +    src/ui_interface.h \
  17. +    src/kernel.h
  18.  
  19.  SOURCES += src/qt/bitcoin.cpp src/qt/bitcoingui.cpp \
  20.      src/qt/transactiontablemodel.cpp \
  21. @@ -212,7 +213,8 @@
  22.      src/qt/askpassphrasedialog.cpp \
  23.      src/protocol.cpp \
  24.      src/qt/notificator.cpp \
  25. -    src/qt/qtipcserver.cpp
  26. +    src/qt/qtipcserver.cpp \
  27. +    src/kernel.cpp
  28.  
  29.  RESOURCES += \
  30.      src/qt/bitcoin.qrc
  31. diff -N -r -u ppcoin-0.2.2ppc-linux/src/contrib/gitian-descriptors/gitian-win32.yml ppcoin-0.3.0-linux/src/contrib/gitian-descriptors/gitian-win32.yml
  32. --- ppcoin-0.2.2ppc-linux/src/contrib/gitian-descriptors/gitian-win32.yml       2012-11-12 13:41:48.000000000 -0800
  33. +++ ppcoin-0.3.0-linux/src/contrib/gitian-descriptors/gitian-win32.yml  2013-02-16 21:33:42.000000000 -0800
  34. @@ -15,16 +15,16 @@
  35.  - "url": "https://github.com/ppcoin/ppcoin.git"
  36.    "dir": "ppcoin"
  37.  files:
  38. -#- "qt-win32-4.7.4-gitian.zip"
  39. +- "qt-win32-4.7.4-gitian.zip"
  40.  - "boost-win32-1.47.0-gitian.zip"
  41.  - "ppcoin-deps-0.0.1.zip"
  42.  script: |
  43.    #
  44. -  #mkdir $HOME/qt
  45. -  #cd $HOME/qt
  46. -  #unzip ../build/qt-win32-4.7.4-gitian.zip
  47. -  cd $HOME/build
  48. -  #export PATH=$PATH:$HOME/qt/bin/
  49. +  mkdir $HOME/qt
  50. +  cd $HOME/qt
  51. +  unzip ../build/qt-win32-4.7.4-gitian.zip
  52. +  cd $HOME/build/
  53. +  export PATH=$PATH:$HOME/qt/bin/
  54.    #
  55.    mkdir boost_1_47_0
  56.    cd boost_1_47_0
  57. @@ -51,9 +51,9 @@
  58.    export LD_PRELOAD=/usr/lib/faketime/libfaketime.so.1
  59.    export FAKETIME=$REFERENCE_DATETIME
  60.    export TZ=UTC
  61. -  #$HOME/qt/src/bin/qmake -spec unsupported/win32-g++-cross MINIUPNPC_LIB_PATH=$HOME/build/miniupnpc MINIUPNPC_INCLUDE_PATH=$HOME/build/ BDB_LIB_PATH=$HOME/build/db-4.8.30.NC/build_unix BDB_INCLUDE_PATH=$HOME/build/db-4.8.30.NC/build_unix BOOST_LIB_PATH=$HOME/build/boost_1_47_0/stage/lib BOOST_INCLUDE_PATH=$HOME/build/boost_1_47_0 BOOST_LIB_SUFFIX=-mt-s BOOST_THREAD_LIB_SUFFIX=_win32-mt-s OPENSSL_LIB_PATH=$HOME/build/openssl-1.0.1b OPENSSL_INCLUDE_PATH=$HOME/build/openssl-1.0.1b/include QRENCODE_LIB_PATH=$HOME/build/qrencode-3.2.0/.libs QRENCODE_INCLUDE_PATH=$HOME/build/qrencode-3.2.0 USE_QRCODE=1 INCLUDEPATH=$HOME/build DEFINES=BOOST_THREAD_USE_LIB BITCOIN_NEED_QT_PLUGINS=1 QMAKE_LRELEASE=lrelease QMAKE_CXXFLAGS=-frandom-seed=ppcoin QMAKE_LFLAGS=-frandom-seed=ppcoin USE_BUILD_INFO=1
  62. -  #make $MAKEOPTS
  63. -  #cp release/bitcoin-qt.exe $OUTDIR/
  64. +  $HOME/qt/src/bin/qmake -spec unsupported/win32-g++-cross MINIUPNPC_LIB_PATH=$HOME/build/miniupnpc MINIUPNPC_INCLUDE_PATH=$HOME/build/ BDB_LIB_PATH=$HOME/build/db-4.8.30.NC/build_unix BDB_INCLUDE_PATH=$HOME/build/db-4.8.30.NC/build_unix BOOST_LIB_PATH=$HOME/build/boost_1_47_0/stage/lib BOOST_INCLUDE_PATH=$HOME/build/boost_1_47_0 BOOST_LIB_SUFFIX=-mt-s BOOST_THREAD_LIB_SUFFIX=_win32-mt-s OPENSSL_LIB_PATH=$HOME/build/openssl-1.0.1b OPENSSL_INCLUDE_PATH=$HOME/build/openssl-1.0.1b/include QRENCODE_LIB_PATH=$HOME/build/qrencode-3.2.0/.libs QRENCODE_INCLUDE_PATH=$HOME/build/qrencode-3.2.0 USE_QRCODE=1 INCLUDEPATH=$HOME/build DEFINES=BOOST_THREAD_USE_LIB BITCOIN_NEED_QT_PLUGINS=1 QMAKE_LRELEASE=lrelease QMAKE_CXXFLAGS=-frandom-seed=ppcoin QMAKE_LFLAGS=-frandom-seed=ppcoin USE_BUILD_INFO=1
  65. +  make $MAKEOPTS
  66. +  cp release/ppcoin-qt.exe $OUTDIR/
  67.    #
  68.    cd src
  69.    export LD_PRELOAD=/usr/lib/faketime/libfaketime.so.1
  70. @@ -68,7 +68,7 @@
  71.    git archive HEAD | tar -x -C nsis
  72.    cd nsis/src
  73.    mkdir ../release
  74. -  #cp ../../release/* ../release/
  75. +  cp ../../release/* ../release/
  76.    cp ../../src/*.exe .
  77.    makensis ../share/setup.nsi
  78.    cp ../share/ppcoin-*-win32-setup.exe $OUTDIR/
  79. diff -N -r -u ppcoin-0.2.2ppc-linux/src/contrib/gitian-descriptors/gitian.yml ppcoin-0.3.0-linux/src/contrib/gitian-descriptors/gitian.yml
  80. --- ppcoin-0.2.2ppc-linux/src/contrib/gitian-descriptors/gitian.yml     2012-11-12 13:41:48.000000000 -0800
  81. +++ ppcoin-0.3.0-linux/src/contrib/gitian-descriptors/gitian.yml        2013-02-16 21:33:42.000000000 -0800
  82. @@ -49,8 +49,8 @@
  83.    make -f makefile.unix STATIC=1 OPENSSL_INCLUDE_PATH="$INSTDIR/include" OPENSSL_LIB_PATH="$INSTDIR/lib" $MAKEOPTS ppcoind USE_UPNP=1 DEBUGFLAGS=
  84.    mkdir -p $OUTDIR/bin/$GBUILD_BITS
  85.    install -s ppcoind $OUTDIR/bin/$GBUILD_BITS
  86. -#Do not build qt gui client for now
  87. -#  cd ..
  88. -#  qmake INCLUDEPATH="$INSTDIR/include" LIBS="-L$INSTDIR/lib" RELEASE=1 USE_QRCODE=1
  89. -#  make $MAKEOPTS
  90. -#  install bitcoin-qt $OUTDIR/bin/$GBUILD_BITS
  91. +  #
  92. +  cd ..
  93. +  qmake INCLUDEPATH="$INSTDIR/include" LIBS="-L$INSTDIR/lib" RELEASE=1 USE_QRCODE=1
  94. +  make $MAKEOPTS
  95. +  install ppcoin-qt $OUTDIR/bin/$GBUILD_BITS
  96. diff -N -r -u ppcoin-0.2.2ppc-linux/src/doc/README ppcoin-0.3.0-linux/src/doc/README
  97. --- ppcoin-0.2.2ppc-linux/src/doc/README        2012-11-12 13:41:49.000000000 -0800
  98. +++ ppcoin-0.3.0-linux/src/doc/README   2013-02-16 21:33:41.000000000 -0800
  99. @@ -1,6 +1,6 @@
  100. -PPCoin 0.2.2 BETA
  101. +PPCoin 0.3.0 BETA
  102.  
  103. -Copyright (c) 2011-2012 PPCoin Developers
  104. +Copyright (c) 2011-2013 PPCoin Developers
  105.  Distributed under the MIT/X11 software license, see the accompanying
  106.  file license.txt or http://www.opensource.org/licenses/mit-license.php.
  107.  This product includes software developed by the OpenSSL Project for use in
  108. @@ -19,7 +19,9 @@
  109.  Setup
  110.  -----
  111.  Unpack the files into a directory and run:
  112. + bin/32/ppcoin-qt (GUI, 32-bit)
  113.   bin/32/ppcoind (headless, 32-bit)
  114. + bin/64/ppcoin-qt (GUI, 64-bit)
  115.   bin/64/ppcoind (headless, 64-bit)
  116.  
  117.  The software automatically finds other nodes to connect to.  You can
  118. @@ -31,12 +33,13 @@
  119.  
  120.  Upgrade
  121.  -------
  122. -All you existing coins/transactions should be intact with the upgrade.
  123. +All your existing coins/transactions should be intact with the upgrade.
  124.  To upgrade from 0.2, first backup wallet
  125.  ppcoind backupwallet <destination_backup_file>
  126.  Then shutdown ppcoind by
  127.  ppcoind stop
  128. -Start up the new ppcoind (0.2.2).
  129. +Remove files inside wallet directory other than wallet.dat and ppcoin.conf
  130. +Start up the new ppcoind (0.3.0). It would start re-download of block chain.
  131.  
  132.  
  133.  See the documentation/wiki at the ppcoin website:
  134. diff -N -r -u ppcoin-0.2.2ppc-linux/src/doc/README_windows.txt ppcoin-0.3.0-linux/src/doc/README_windows.txt
  135. --- ppcoin-0.2.2ppc-linux/src/doc/README_windows.txt    2012-11-12 13:41:49.000000000 -0800
  136. +++ ppcoin-0.3.0-linux/src/doc/README_windows.txt       2013-02-16 21:33:41.000000000 -0800
  137. @@ -1,6 +1,6 @@
  138. -PPCoin 0.2.2 BETA
  139. +PPCoin 0.3.0 BETA
  140.  
  141. -Copyright (c) 2011-2012 PPCoin Developers
  142. +Copyright (c) 2011-2013 PPCoin Developers
  143.  Distributed under the MIT/X11 software license, see the accompanying
  144.  file license.txt or http://www.opensource.org/licenses/mit-license.php.
  145.  This product includes software developed by the OpenSSL Project for use in
  146. @@ -18,11 +18,12 @@
  147.  
  148.  Setup
  149.  -----
  150. -After completing windows setup then run windows command line (cmd)
  151. +After completing windows setup then run ppcoin-qt.
  152. +Alternatively you can run windows command line (cmd) in ppcoin program dir.
  153.    cd daemon
  154.    ppcoind
  155.  You would need to create a configuration file ppcoin.conf in the default
  156. -wallet directory. Grant access to ppcoind.exe in anti-virus and firewall
  157. +wallet directory. Grant access to ppcoind/ppcoin-qt in anti-virus and firewall
  158.  applications if necessary.
  159.  
  160.  The software automatically finds other nodes to connect to.  You can
  161. @@ -34,12 +35,13 @@
  162.  
  163.  Upgrade
  164.  -------
  165. -All you existing coins/transactions should be intact with the upgrade.
  166. +All your existing coins/transactions should be intact with the upgrade.
  167.  To upgrade from 0.2, first backup wallet
  168.  ppcoind backupwallet <destination_backup_file>
  169.  Then shutdown ppcoind by
  170.  ppcoind stop
  171. -Start up the new ppcoind (0.2.2).
  172. +Remove files inside wallet directory other than wallet.dat and ppcoin.conf
  173. +Start up the new ppcoin-qt (0.3.0). It would start re-download of block chain.
  174.  
  175.  
  176.  See the documentation/wiki at the ppcoin website:
  177. diff -N -r -u ppcoin-0.2.2ppc-linux/src/share/setup.nsi ppcoin-0.3.0-linux/src/share/setup.nsi
  178. --- ppcoin-0.2.2ppc-linux/src/share/setup.nsi   2012-11-12 13:41:49.000000000 -0800
  179. +++ ppcoin-0.3.0-linux/src/share/setup.nsi      2013-02-16 21:33:51.000000000 -0800
  180. @@ -5,7 +5,7 @@
  181.  
  182.  # General Symbol Definitions
  183.  !define REGKEY "SOFTWARE\$(^Name)"
  184. -!define VERSION 0.2.2
  185. +!define VERSION 0.3.0
  186.  !define COMPANY "PPCoin project"
  187.  !define URL http://www.ppcoin.org/
  188.  
  189. @@ -20,7 +20,7 @@
  190.  !define MUI_STARTMENUPAGE_REGISTRY_KEY ${REGKEY}
  191.  !define MUI_STARTMENUPAGE_REGISTRY_VALUENAME StartMenuGroup
  192.  !define MUI_STARTMENUPAGE_DEFAULTFOLDER PPCoin
  193. -#!define MUI_FINISHPAGE_RUN $INSTDIR\bitcoin-qt.exe
  194. +!define MUI_FINISHPAGE_RUN $INSTDIR\ppcoin-qt.exe
  195.  !define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\modern-uninstall.ico"
  196.  !define MUI_UNWELCOMEFINISHPAGE_BITMAP "../share/pixmaps/nsis-wizard.bmp"
  197.  !define MUI_UNFINISHPAGE_NOAUTOCLOSE
  198. @@ -45,13 +45,13 @@
  199.  !insertmacro MUI_LANGUAGE English
  200.  
  201.  # Installer attributes
  202. -OutFile ppcoin-0.2.2-win32-setup.exe
  203. +OutFile ppcoin-0.3.0-win32-setup.exe
  204.  InstallDir $PROGRAMFILES\PPCoin
  205.  CRCCheck on
  206.  XPStyle on
  207.  BrandingText " "
  208.  ShowInstDetails show
  209. -VIProductVersion 0.2.2.0
  210. +VIProductVersion 0.3.0.0
  211.  VIAddVersionKey ProductName PPCoin
  212.  VIAddVersionKey ProductVersion "${VERSION}"
  213.  VIAddVersionKey CompanyName "${COMPANY}"
  214. @@ -66,7 +66,7 @@
  215.  Section -Main SEC0000
  216.      SetOutPath $INSTDIR
  217.      SetOverwrite on
  218. -    #File ../release/bitcoin-qt.exe
  219. +    File ../release/ppcoin-qt.exe
  220.      File /oname=license.txt ../COPYING
  221.      File /oname=readme.txt ../doc/README_windows.txt
  222.      SetOutPath $INSTDIR\daemon
  223. @@ -87,7 +87,7 @@
  224.      WriteUninstaller $INSTDIR\uninstall.exe
  225.      !insertmacro MUI_STARTMENU_WRITE_BEGIN Application
  226.      CreateDirectory $SMPROGRAMS\$StartMenuGroup
  227. -    #CreateShortcut "$SMPROGRAMS\$StartMenuGroup\Bitcoin.lnk" $INSTDIR\bitcoin-qt.exe
  228. +    CreateShortcut "$SMPROGRAMS\$StartMenuGroup\PPCoin.lnk" $INSTDIR\ppcoin-qt.exe
  229.      CreateShortcut "$SMPROGRAMS\$StartMenuGroup\Uninstall PPCoin.lnk" $INSTDIR\uninstall.exe
  230.      !insertmacro MUI_STARTMENU_WRITE_END
  231.      WriteRegStr HKCU "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" DisplayName "$(^Name)"
  232. @@ -121,7 +121,7 @@
  233.  
  234.  # Uninstaller sections
  235.  Section /o -un.Main UNSEC0000
  236. -    #Delete /REBOOTOK $INSTDIR\bitcoin-qt.exe
  237. +    Delete /REBOOTOK $INSTDIR\ppcoin-qt.exe
  238.      Delete /REBOOTOK $INSTDIR\license.txt
  239.      Delete /REBOOTOK $INSTDIR\readme.txt
  240.      RMDir /r /REBOOTOK $INSTDIR\daemon
  241. @@ -132,8 +132,8 @@
  242.  Section -un.post UNSEC0001
  243.      DeleteRegKey HKCU "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)"
  244.      Delete /REBOOTOK "$SMPROGRAMS\$StartMenuGroup\Uninstall PPCoin.lnk"
  245. -    #Delete /REBOOTOK "$SMPROGRAMS\$StartMenuGroup\Bitcoin.lnk"
  246. -    #Delete /REBOOTOK "$SMSTARTUP\Bitcoin.lnk"
  247. +    Delete /REBOOTOK "$SMPROGRAMS\$StartMenuGroup\PPCoin.lnk"
  248. +    Delete /REBOOTOK "$SMSTARTUP\PPCoin.lnk"
  249.      Delete /REBOOTOK $INSTDIR\uninstall.exe
  250.      Delete /REBOOTOK $INSTDIR\debug.log
  251.      Delete /REBOOTOK $INSTDIR\db.log
  252. diff -N -r -u ppcoin-0.2.2ppc-linux/src/src/base58.h ppcoin-0.3.0-linux/src/src/base58.h
  253. --- ppcoin-0.2.2ppc-linux/src/src/base58.h      2012-11-12 13:41:36.000000000 -0800
  254. +++ ppcoin-0.3.0-linux/src/src/base58.h 2013-02-16 21:33:43.000000000 -0800
  255. @@ -365,7 +365,7 @@
  256.      void SetSecret(const CSecret& vchSecret, bool fCompressed)
  257.      {
  258.          assert(vchSecret.size() == 32);
  259. -        SetData(fTestNet ? 239 : 128, &vchSecret[0], vchSecret.size());
  260. +        SetData(128 + (fTestNet ? CBitcoinAddress::PUBKEY_ADDRESS_TEST : CBitcoinAddress::PUBKEY_ADDRESS), &vchSecret[0], vchSecret.size());
  261.          if (fCompressed)
  262.              vchData.push_back(1);
  263.      }
  264. @@ -384,10 +384,10 @@
  265.          bool fExpectTestNet = false;
  266.          switch(nVersion)
  267.          {
  268. -            case 128:
  269. +             case (128 + CBitcoinAddress::PUBKEY_ADDRESS):
  270.                  break;
  271.  
  272. -            case 239:
  273. +            case (128 + CBitcoinAddress::PUBKEY_ADDRESS_TEST):
  274.                  fExpectTestNet = true;
  275.                  break;
  276.  
  277. diff -N -r -u ppcoin-0.2.2ppc-linux/src/src/bitcoinrpc.cpp ppcoin-0.3.0-linux/src/src/bitcoinrpc.cpp
  278. --- ppcoin-0.2.2ppc-linux/src/src/bitcoinrpc.cpp        2012-11-12 13:41:37.000000000 -0800
  279. +++ ppcoin-0.3.0-linux/src/src/bitcoinrpc.cpp   2013-02-16 21:33:51.000000000 -0800
  280. @@ -1,6 +1,6 @@
  281.  // Copyright (c) 2010 Satoshi Nakamoto
  282.  // Copyright (c) 2009-2012 The Bitcoin developers
  283. -// Copyright (c) 2011-2012 The PPCoin developers
  284. +// Copyright (c) 2011-2013 The PPCoin developers
  285.  // Distributed under the MIT/X11 software license, see the accompanying
  286.  // file COPYING or http://www.opensource.org/licenses/mit-license.php.
  287.  
  288. @@ -153,6 +153,11 @@
  289.          result.push_back(Pair("previousblockhash", blockindex->pprev->GetBlockHash().GetHex()));
  290.      if (blockindex->pnext)
  291.          result.push_back(Pair("nextblockhash", blockindex->pnext->GetBlockHash().GetHex()));
  292. +    result.push_back(Pair("flags", strprintf("%s%s", blockindex->IsProofOfStake()? "proof-of-stake" : "proof-of-work", blockindex->GeneratedStakeModifier()? " stake-modifier": "")));
  293. +    result.push_back(Pair("proofhash", blockindex->IsProofOfStake()? blockindex->hashProofOfStake.GetHex() : blockindex->GetBlockHash().GetHex()));
  294. +    result.push_back(Pair("entropybit", (int)blockindex->GetStakeEntropyBit()));
  295. +    result.push_back(Pair("modifier", strprintf("%016"PRI64x, blockindex->nStakeModifier)));
  296. +    result.push_back(Pair("modifierchecksum", strprintf("%08x", blockindex->nStakeModifierChecksum)));
  297.      Array txinfo;
  298.      BOOST_FOREACH (const CTransaction& tx, block.vtx)
  299.      {
  300. diff -N -r -u ppcoin-0.2.2ppc-linux/src/src/checkpoints.cpp ppcoin-0.3.0-linux/src/src/checkpoints.cpp
  301. --- ppcoin-0.2.2ppc-linux/src/src/checkpoints.cpp       2012-11-12 13:41:44.000000000 -0800
  302. +++ ppcoin-0.3.0-linux/src/src/checkpoints.cpp  2013-02-16 21:33:43.000000000 -0800
  303. @@ -1,5 +1,5 @@
  304.  // Copyright (c) 2009-2012 The Bitcoin developers
  305. -// Copyright (c) 2011-2012 The PPCoin developers
  306. +// Copyright (c) 2011-2013 The PPCoin developers
  307.  // Distributed under the MIT/X11 software license, see the accompanying
  308.  // file COPYING or http://www.opensource.org/licenses/mit-license.php.
  309.  
  310. @@ -26,7 +26,9 @@
  311.      static MapCheckpoints mapCheckpoints =
  312.          boost::assign::map_list_of
  313.          ( 0, hashGenesisBlockOfficial )
  314. -        ; // ppcoin: no checkpoint yet; to be created in future releases
  315. +        ( 19080, uint256("0x000000000000bca54d9ac17881f94193fd6a270c1bb21c3bf0b37f588a40dbd7"))
  316. +        ( 30583, uint256("0xd39d1481a7eecba48932ea5913be58ad3894c7ee6d5a8ba8abeb772c66a6696e"))
  317. +        ;
  318.  
  319.      bool CheckHardened(int nHeight, const uint256& hash)
  320.      {
  321. @@ -351,6 +353,16 @@
  322.          return (nBestHeight >= pindexSync->nHeight + nCoinbaseMaturity ||
  323.                  pindexSync->GetBlockTime() + nStakeMinAge < GetAdjustedTime());
  324.      }
  325. +
  326. +    // Is the sync-checkpoint too old?
  327. +    bool IsSyncCheckpointTooOld(unsigned int nSeconds)
  328. +    {
  329. +        LOCK(cs_hashSyncCheckpoint);
  330. +        // sync-checkpoint should always be accepted block
  331. +        assert(mapBlockIndex.count(hashSyncCheckpoint));
  332. +        const CBlockIndex* pindexSync = mapBlockIndex[hashSyncCheckpoint];
  333. +        return (pindexSync->GetBlockTime() + nSeconds < GetAdjustedTime());
  334. +    }
  335.  }
  336.  
  337.  // ppcoin: sync-checkpoint master key
  338. diff -N -r -u ppcoin-0.2.2ppc-linux/src/src/checkpoints.h ppcoin-0.3.0-linux/src/src/checkpoints.h
  339. --- ppcoin-0.2.2ppc-linux/src/src/checkpoints.h 2012-11-12 13:41:36.000000000 -0800
  340. +++ ppcoin-0.3.0-linux/src/src/checkpoints.h    2013-02-16 21:33:43.000000000 -0800
  341. @@ -1,5 +1,5 @@
  342.  // Copyright (c) 2009-2012 The Bitcoin developers
  343. -// Copyright (c) 2011-2012 The PPCoin developers
  344. +// Copyright (c) 2011-2013 The PPCoin developers
  345.  // Distributed under the MIT/X11 software license, see the accompanying
  346.  // file COPYING or http://www.opensource.org/licenses/mit-license.php.
  347.  #ifndef BITCOIN_CHECKPOINT_H
  348. @@ -9,8 +9,6 @@
  349.  #include "net.h"
  350.  #include "util.h"
  351.  
  352. -#define STAKE_MIN_AGE (60 * 60 * 24 * 30) // minimum age 30 days for coin age
  353. -#define STAKE_MAX_AGE (60 * 60 * 24 * 90) // stake age for full weight
  354.  #define CHECKPOINT_MAX_SPAN (60 * 60 * 4) // max 4 hours before latest block
  355.  
  356.  class uint256;
  357. @@ -47,6 +45,7 @@
  358.      bool SetCheckpointPrivKey(std::string strPrivKey);
  359.      bool SendSyncCheckpoint(uint256 hashCheckpoint);
  360.      bool IsMatureSyncCheckpoint();
  361. +    bool IsSyncCheckpointTooOld(unsigned int nSeconds);
  362.  }
  363.  
  364.  // ppcoin: synchronized checkpoint
  365. diff -N -r -u ppcoin-0.2.2ppc-linux/src/src/db.cpp ppcoin-0.3.0-linux/src/src/db.cpp
  366. --- ppcoin-0.2.2ppc-linux/src/src/db.cpp        2012-11-12 13:41:45.000000000 -0800
  367. +++ ppcoin-0.3.0-linux/src/src/db.cpp   2013-02-16 21:33:45.000000000 -0800
  368. @@ -1,6 +1,6 @@
  369.  // Copyright (c) 2009-2010 Satoshi Nakamoto
  370.  // Copyright (c) 2009-2012 The Bitcoin developers
  371. -// Copyright (c) 2011-2012 The PPCoin developers
  372. +// Copyright (c) 2011-2013 The PPCoin developers
  373.  // Distributed under the MIT/X11 software license, see the accompanying
  374.  // file COPYING or http://www.opensource.org/licenses/mit-license.php.
  375.  
  376. @@ -9,6 +9,7 @@
  377.  #include "checkpoints.h"
  378.  #include "util.h"
  379.  #include "main.h"
  380. +#include "kernel.h"
  381.  #include <boost/version.hpp>
  382.  #include <boost/filesystem.hpp>
  383.  #include <boost/filesystem/fstream.hpp>
  384. @@ -580,8 +581,11 @@
  385.              pindexNew->nHeight        = diskindex.nHeight;
  386.              pindexNew->nMint          = diskindex.nMint;
  387.              pindexNew->nMoneySupply   = diskindex.nMoneySupply;
  388. -            pindexNew->fProofOfStake  = diskindex.fProofOfStake;
  389. +            pindexNew->nFlags         = diskindex.nFlags;
  390. +            pindexNew->nStakeModifier = diskindex.nStakeModifier;
  391.              pindexNew->prevoutStake   = diskindex.prevoutStake;
  392. +            pindexNew->nStakeTime     = diskindex.nStakeTime;
  393. +            pindexNew->hashProofOfStake = diskindex.hashProofOfStake;
  394.              pindexNew->nVersion       = diskindex.nVersion;
  395.              pindexNew->hashMerkleRoot = diskindex.hashMerkleRoot;
  396.              pindexNew->nTime          = diskindex.nTime;
  397. @@ -596,7 +600,7 @@
  398.                  return error("LoadBlockIndex() : CheckIndex failed at %d", pindexNew->nHeight);
  399.  
  400.              // ppcoin: build setStakeSeen
  401. -            if (pindexNew->fProofOfStake)
  402. +            if (pindexNew->IsProofOfStake())
  403.                  setStakeSeen.insert(make_pair(pindexNew->prevoutStake, pindexNew->nStakeTime));
  404.          }
  405.          else
  406. @@ -626,6 +630,10 @@
  407.      {
  408.          CBlockIndex* pindex = item.second;
  409.          pindex->bnChainTrust = (pindex->pprev ? pindex->pprev->bnChainTrust : 0) + pindex->GetBlockTrust();
  410. +        // ppcoin: calculate stake modifier checksum
  411. +        pindex->nStakeModifierChecksum = GetStakeModifierChecksum(pindex);
  412. +        if (!CheckStakeModifierCheckpoints(pindex->nHeight, pindex->nStakeModifierChecksum))
  413. +            return error("CTxDB::LoadBlockIndex() : Failed stake modifier checkpoint height=%d, modifier=0x%016"PRI64x, pindex->nHeight, pindex->nStakeModifier);
  414.      }
  415.  
  416.      // Load hashBestChain pointer to end of best chain
  417. diff -N -r -u ppcoin-0.2.2ppc-linux/src/src/init.cpp ppcoin-0.3.0-linux/src/src/init.cpp
  418. --- ppcoin-0.2.2ppc-linux/src/src/init.cpp      2012-11-12 13:41:45.000000000 -0800
  419. +++ ppcoin-0.3.0-linux/src/src/init.cpp 2013-02-16 21:33:51.000000000 -0800
  420. @@ -1,6 +1,6 @@
  421.  // Copyright (c) 2009-2010 Satoshi Nakamoto
  422.  // Copyright (c) 2009-2012 The Bitcoin developers
  423. -// Copyright (c) 2011-2012 The PPCoin developers
  424. +// Copyright (c) 2011-2013 The PPCoin developers
  425.  // Distributed under the MIT/X11 software license, see the accompanying
  426.  // file COPYING or http://www.opensource.org/licenses/mit-license.php.
  427.  #include "db.h"
  428. @@ -449,7 +449,7 @@
  429.          if (walletdb.ReadBestBlock(locator))
  430.              pindexRescan = locator.GetBlockIndex();
  431.      }
  432. -    if (pindexBest != pindexRescan)
  433. +    if (pindexBest != pindexRescan && pindexBest && pindexRescan && pindexBest->nHeight > pindexRescan->nHeight)
  434.      {
  435.          InitMessage(_("Rescanning..."));
  436.          printf("Rescanning last %i blocks (from block %i)...\n", pindexBest->nHeight - pindexRescan->nHeight, pindexRescan->nHeight);
  437. diff -N -r -u ppcoin-0.2.2ppc-linux/src/src/kernel.cpp ppcoin-0.3.0-linux/src/src/kernel.cpp
  438. --- ppcoin-0.2.2ppc-linux/src/src/kernel.cpp    1969-12-31 16:00:00.000000000 -0800
  439. +++ ppcoin-0.3.0-linux/src/src/kernel.cpp       2013-02-16 21:33:43.000000000 -0800
  440. @@ -0,0 +1,403 @@
  441. +// Copyright (c) 2012-2013 The PPCoin developers
  442. +// Distributed under the MIT/X11 software license, see the accompanying
  443. +// file COPYING or http://www.opensource.org/licenses/mit-license.php.
  444. +
  445. +#include <boost/assign/list_of.hpp>
  446. +
  447. +#include "kernel.h"
  448. +#include "db.h"
  449. +
  450. +using namespace std;
  451. +
  452. +// Protocol switch time of v0.3 kernel protocol
  453. +unsigned int nProtocolV03SwitchTime     = 1363800000;
  454. +unsigned int nProtocolV03TestSwitchTime = 1359781000;
  455. +
  456. +// Modifier interval: time to elapse before new modifier is computed
  457. +// Set to 6-hour for production network and 20-minute for test network
  458. +unsigned int nModifierInterval = MODIFIER_INTERVAL;
  459. +
  460. +// Hard checkpoints of stake modifiers to ensure they are deterministic
  461. +static std::map<int, unsigned int> mapStakeModifierCheckpoints =
  462. +    boost::assign::map_list_of
  463. +    ( 0, 0x0e00670bu )
  464. +    ( 19080, 0xad4e4d29u )
  465. +    ( 30583, 0xdc7bf136u )
  466. +    ;
  467. +
  468. +// Whether the given coinstake is subject to new v0.3 protocol
  469. +bool IsProtocolV03(unsigned int nTimeCoinStake)
  470. +{
  471. +    return (nTimeCoinStake >= (fTestNet? nProtocolV03TestSwitchTime : nProtocolV03SwitchTime));
  472. +}
  473. +
  474. +// Get the last stake modifier and its generation time from a given block
  475. +static bool GetLastStakeModifier(const CBlockIndex* pindex, uint64& nStakeModifier, int64& nModifierTime)
  476. +{
  477. +    if (!pindex)
  478. +        return error("GetLastStakeModifier: null pindex");
  479. +    while (pindex && pindex->pprev && !pindex->GeneratedStakeModifier())
  480. +        pindex = pindex->pprev;
  481. +    if (!pindex->GeneratedStakeModifier())
  482. +        return error("GetLastStakeModifier: no generation at genesis block");
  483. +    nStakeModifier = pindex->nStakeModifier;
  484. +    nModifierTime = pindex->GetBlockTime();
  485. +    return true;
  486. +}
  487. +
  488. +// Get selection interval section (in seconds)
  489. +static int64 GetStakeModifierSelectionIntervalSection(int nSection)
  490. +{
  491. +    assert (nSection >= 0 && nSection < 64);
  492. +    return (nModifierInterval * 63 / (63 + ((63 - nSection) * (MODIFIER_INTERVAL_RATIO - 1))));
  493. +}
  494. +
  495. +// Get stake modifier selection interval (in seconds)
  496. +static int64 GetStakeModifierSelectionInterval()
  497. +{
  498. +    int64 nSelectionInterval = 0;
  499. +    for (int nSection=0; nSection<64; nSection++)
  500. +        nSelectionInterval += GetStakeModifierSelectionIntervalSection(nSection);
  501. +    return nSelectionInterval;
  502. +}
  503. +
  504. +// select a block from the candidate blocks in vSortedByTimestamp, excluding
  505. +// already selected blocks in vSelectedBlocks, and with timestamp up to
  506. +// nSelectionIntervalStop.
  507. +static bool SelectBlockFromCandidates(
  508. +    vector<pair<int64, uint256> >& vSortedByTimestamp,
  509. +    map<uint256, const CBlockIndex*>& mapSelectedBlocks,
  510. +    int64 nSelectionIntervalStop, uint64 nStakeModifierPrev,
  511. +    const CBlockIndex** pindexSelected)
  512. +{
  513. +    bool fSelected = false;
  514. +    uint256 hashBest = 0;
  515. +    *pindexSelected = (const CBlockIndex*) 0;
  516. +    BOOST_FOREACH(const PAIRTYPE(int64, uint256)& item, vSortedByTimestamp)
  517. +    {
  518. +        if (!mapBlockIndex.count(item.second))
  519. +            return error("SelectBlockFromCandidates: failed to find block index for candidate block %s", item.second.ToString().c_str());
  520. +        const CBlockIndex* pindex = mapBlockIndex[item.second];
  521. +        if (fSelected && pindex->GetBlockTime() > nSelectionIntervalStop)
  522. +            break;
  523. +        if (mapSelectedBlocks.count(pindex->GetBlockHash()) > 0)
  524. +            continue;
  525. +        // compute the selection hash by hashing its proof-hash and the
  526. +        // previous proof-of-stake modifier
  527. +        uint256 hashProof = pindex->IsProofOfStake()? pindex->hashProofOfStake : pindex->GetBlockHash();
  528. +        CDataStream ss(SER_GETHASH, 0);
  529. +        ss << hashProof << nStakeModifierPrev;
  530. +        uint256 hashSelection = Hash(ss.begin(), ss.end());
  531. +        // the selection hash is divided by 2**32 so that proof-of-stake block
  532. +        // is always favored over proof-of-work block. this is to preserve
  533. +        // the energy efficiency property
  534. +        if (pindex->IsProofOfStake())
  535. +            hashSelection >>= 32;
  536. +        if (fSelected && hashSelection < hashBest)
  537. +        {
  538. +            hashBest = hashSelection;
  539. +            *pindexSelected = (const CBlockIndex*) pindex;
  540. +        }
  541. +        else if (!fSelected)
  542. +        {
  543. +            fSelected = true;
  544. +            hashBest = hashSelection;
  545. +            *pindexSelected = (const CBlockIndex*) pindex;
  546. +        }
  547. +    }
  548. +    if (fDebug && GetBoolArg("-printstakemodifier"))
  549. +        printf("SelectBlockFromCandidates: selection hash=%s\n", hashBest.ToString().c_str());
  550. +    return fSelected;
  551. +}
  552. +
  553. +// Stake Modifier (hash modifier of proof-of-stake):
  554. +// The purpose of stake modifier is to prevent a txout (coin) owner from
  555. +// computing future proof-of-stake generated by this txout at the time
  556. +// of transaction confirmation. To meet kernel protocol, the txout
  557. +// must hash with a future stake modifier to generate the proof.
  558. +// Stake modifier consists of bits each of which is contributed from a
  559. +// selected block of a given block group in the past.
  560. +// The selection of a block is based on a hash of the block's proof-hash and
  561. +// the previous stake modifier.
  562. +// Stake modifier is recomputed at a fixed time interval instead of every
  563. +// block. This is to make it difficult for an attacker to gain control of
  564. +// additional bits in the stake modifier, even after generating a chain of
  565. +// blocks.
  566. +bool ComputeNextStakeModifier(const CBlockIndex* pindexPrev, uint64& nStakeModifier, bool& fGeneratedStakeModifier)
  567. +{
  568. +    nStakeModifier = 0;
  569. +    fGeneratedStakeModifier = false;
  570. +    if (!pindexPrev)
  571. +    {
  572. +        fGeneratedStakeModifier = true;
  573. +        return true;  // genesis block's modifier is 0
  574. +    }
  575. +    // First find current stake modifier and its generation block time
  576. +    // if it's not old enough, return the same stake modifier
  577. +    int64 nModifierTime = 0;
  578. +    if (!GetLastStakeModifier(pindexPrev, nStakeModifier, nModifierTime))
  579. +        return error("ComputeNextStakeModifier: unable to get last modifier");
  580. +    if (fDebug)
  581. +    {
  582. +        printf("ComputeNextStakeModifier: prev modifier=0x%016"PRI64x" time=%s\n", nStakeModifier, DateTimeStrFormat(nModifierTime).c_str());
  583. +    }
  584. +    if (nModifierTime / nModifierInterval >= pindexPrev->GetBlockTime() / nModifierInterval)
  585. +        return true;
  586. +
  587. +    // Sort candidate blocks by timestamp
  588. +    vector<pair<int64, uint256> > vSortedByTimestamp;
  589. +    vSortedByTimestamp.reserve(64 * nModifierInterval / STAKE_TARGET_SPACING);
  590. +    int64 nSelectionInterval = GetStakeModifierSelectionInterval();
  591. +    int64 nSelectionIntervalStart = (pindexPrev->GetBlockTime() / nModifierInterval) * nModifierInterval - nSelectionInterval;
  592. +    const CBlockIndex* pindex = pindexPrev;
  593. +    while (pindex && pindex->GetBlockTime() >= nSelectionIntervalStart)
  594. +    {
  595. +        vSortedByTimestamp.push_back(make_pair(pindex->GetBlockTime(), pindex->GetBlockHash()));
  596. +        pindex = pindex->pprev;
  597. +    }
  598. +    int nHeightFirstCandidate = pindex ? (pindex->nHeight + 1) : 0;
  599. +    reverse(vSortedByTimestamp.begin(), vSortedByTimestamp.end());
  600. +    sort(vSortedByTimestamp.begin(), vSortedByTimestamp.end());
  601. +
  602. +    // Select 64 blocks from candidate blocks to generate stake modifier
  603. +    uint64 nStakeModifierNew = 0;
  604. +    int64 nSelectionIntervalStop = nSelectionIntervalStart;
  605. +    map<uint256, const CBlockIndex*> mapSelectedBlocks;
  606. +    for (int nRound=0; nRound<min(64, (int)vSortedByTimestamp.size()); nRound++)
  607. +    {
  608. +        // add an interval section to the current selection round
  609. +        nSelectionIntervalStop += GetStakeModifierSelectionIntervalSection(nRound);
  610. +        // select a block from the candidates of current round
  611. +        if (!SelectBlockFromCandidates(vSortedByTimestamp, mapSelectedBlocks, nSelectionIntervalStop, nStakeModifier, &pindex))
  612. +            return error("ComputeNextStakeModifier: unable to select block at round %d", nRound);
  613. +        // write the entropy bit of the selected block
  614. +        nStakeModifierNew |= (((uint64)pindex->GetStakeEntropyBit()) << nRound);
  615. +        // add the selected block from candidates to selected list
  616. +        mapSelectedBlocks.insert(make_pair(pindex->GetBlockHash(), pindex));
  617. +        if (fDebug && GetBoolArg("-printstakemodifier"))
  618. +            printf("ComputeNextStakeModifier: selected round %d stop=%s height=%d bit=%d\n",
  619. +                nRound, DateTimeStrFormat(nSelectionIntervalStop).c_str(), pindex->nHeight, pindex->GetStakeEntropyBit());
  620. +    }
  621. +
  622. +    // Print selection map for visualization of the selected blocks
  623. +    if (fDebug && GetBoolArg("-printstakemodifier"))
  624. +    {
  625. +        string strSelectionMap = "";
  626. +        // '-' indicates proof-of-work blocks not selected
  627. +        strSelectionMap.insert(0, pindexPrev->nHeight - nHeightFirstCandidate + 1, '-');
  628. +        pindex = pindexPrev;
  629. +        while (pindex && pindex->nHeight >= nHeightFirstCandidate)
  630. +        {
  631. +            // '=' indicates proof-of-stake blocks not selected
  632. +            if (pindex->IsProofOfStake())
  633. +                strSelectionMap.replace(pindex->nHeight - nHeightFirstCandidate, 1, "=");
  634. +            pindex = pindex->pprev;
  635. +        }
  636. +        BOOST_FOREACH(const PAIRTYPE(uint256, const CBlockIndex*)& item, mapSelectedBlocks)
  637. +        {
  638. +            // 'S' indicates selected proof-of-stake blocks
  639. +            // 'W' indicates selected proof-of-work blocks
  640. +            strSelectionMap.replace(item.second->nHeight - nHeightFirstCandidate, 1, item.second->IsProofOfStake()? "S" : "W");
  641. +        }
  642. +        printf("ComputeNextStakeModifier: selection height [%d, %d] map %s\n", nHeightFirstCandidate, pindexPrev->nHeight, strSelectionMap.c_str());
  643. +    }
  644. +    if (fDebug)
  645. +    {
  646. +        printf("ComputeNextStakeModifier: new modifier=0x%016"PRI64x" time=%s\n", nStakeModifierNew, DateTimeStrFormat(pindexPrev->GetBlockTime()).c_str());
  647. +    }
  648. +
  649. +    nStakeModifier = nStakeModifierNew;
  650. +    fGeneratedStakeModifier = true;
  651. +    return true;
  652. +}
  653. +
  654. +// The stake modifier used to hash for a stake kernel is chosen as the stake
  655. +// modifier about a selection interval later than the coin generating the kernel
  656. +static bool GetKernelStakeModifier(uint256 hashBlockFrom, uint64& nStakeModifier, int& nStakeModifierHeight, int64& nStakeModifierTime, bool fPrintProofOfStake)
  657. +{
  658. +    nStakeModifier = 0;
  659. +    if (!mapBlockIndex.count(hashBlockFrom))
  660. +        return error("GetKernelStakeModifier() : block not indexed");
  661. +    const CBlockIndex* pindexFrom = mapBlockIndex[hashBlockFrom];
  662. +    nStakeModifierHeight = pindexFrom->nHeight;
  663. +    nStakeModifierTime = pindexFrom->GetBlockTime();
  664. +    int64 nStakeModifierSelectionInterval = GetStakeModifierSelectionInterval();
  665. +    const CBlockIndex* pindex = pindexFrom;
  666. +    // loop to find the stake modifier later by a selection interval
  667. +    while (nStakeModifierTime < pindexFrom->GetBlockTime() + nStakeModifierSelectionInterval)
  668. +    {
  669. +        if (!pindex->pnext)
  670. +        {   // reached best block; may happen if node is behind on block chain
  671. +            if (fPrintProofOfStake || (pindex->GetBlockTime() + nStakeMinAge - nStakeModifierSelectionInterval > GetAdjustedTime()))
  672. +                return error("GetKernelStakeModifier() : reached best block %s at height %d from block %s",
  673. +                    pindex->GetBlockHash().ToString().c_str(), pindex->nHeight, hashBlockFrom.ToString().c_str());
  674. +            else
  675. +                return false;
  676. +        }
  677. +        pindex = pindex->pnext;
  678. +        if (pindex->GeneratedStakeModifier())
  679. +        {
  680. +            nStakeModifierHeight = pindex->nHeight;
  681. +            nStakeModifierTime = pindex->GetBlockTime();
  682. +        }
  683. +    }
  684. +    nStakeModifier = pindex->nStakeModifier;
  685. +    return true;
  686. +}
  687. +
  688. +// ppcoin kernel protocol
  689. +// coinstake must meet hash target according to the protocol:
  690. +// kernel (input 0) must meet the formula
  691. +//     hash(nStakeModifier + txPrev.block.nTime + txPrev.offset + txPrev.nTime + txPrev.vout.n + nTime) < bnTarget * nCoinDayWeight
  692. +// this ensures that the chance of getting a coinstake is proportional to the
  693. +// amount of coin age one owns.
  694. +// The reason this hash is chosen is the following:
  695. +//   nStakeModifier:
  696. +//       (v0.3) scrambles computation to make it very difficult to precompute
  697. +//              future proof-of-stake at the time of the coin's confirmation
  698. +//       (v0.2) nBits (deprecated): encodes all past block timestamps
  699. +//   txPrev.block.nTime: prevent nodes from guessing a good timestamp to
  700. +//                       generate transaction for future advantage
  701. +//   txPrev.offset: offset of txPrev inside block, to reduce the chance of
  702. +//                  nodes generating coinstake at the same time
  703. +//   txPrev.nTime: reduce the chance of nodes generating coinstake at the same
  704. +//                 time
  705. +//   txPrev.vout.n: output number of txPrev, to reduce the chance of nodes
  706. +//                  generating coinstake at the same time
  707. +//   block/tx hash should not be used here as they can be generated in vast
  708. +//   quantities so as to generate blocks faster, degrading the system back into
  709. +//   a proof-of-work situation.
  710. +//
  711. +bool CheckStakeKernelHash(unsigned int nBits, const CBlock& blockFrom, unsigned int nTxPrevOffset, const CTransaction& txPrev, const COutPoint& prevout, unsigned int nTimeTx, uint256& hashProofOfStake, bool fPrintProofOfStake)
  712. +{
  713. +    if (nTimeTx < txPrev.nTime)  // Transaction timestamp violation
  714. +        return error("CheckStakeKernelHash() : nTime violation");
  715. +
  716. +    unsigned int nTimeBlockFrom = blockFrom.GetBlockTime();
  717. +    if (nTimeBlockFrom + nStakeMinAge > nTimeTx) // Min age requirement
  718. +        return error("CheckStakeKernelHash() : min age violation");
  719. +
  720. +    CBigNum bnTargetPerCoinDay;
  721. +    bnTargetPerCoinDay.SetCompact(nBits);
  722. +    int64 nValueIn = txPrev.vout[prevout.n].nValue;
  723. +    // v0.3 protocol kernel hash weight starts from 0 at the 30-day min age
  724. +    // this change increases active coins participating the hash and helps
  725. +    // to secure the network when proof-of-stake difficulty is low
  726. +    int64 nTimeWeight = min((int64)nTimeTx - txPrev.nTime, (int64)STAKE_MAX_AGE) - (IsProtocolV03(nTimeTx)? nStakeMinAge : 0);
  727. +    CBigNum bnCoinDayWeight = CBigNum(nValueIn) * nTimeWeight / COIN / (24 * 60 * 60);
  728. +    // Calculate hash
  729. +    CDataStream ss(SER_GETHASH, 0);
  730. +    uint64 nStakeModifier = 0;
  731. +    int nStakeModifierHeight = 0;
  732. +    int64 nStakeModifierTime = 0;
  733. +    if (IsProtocolV03(nTimeTx))  // v0.3 protocol
  734. +    {
  735. +        if (!GetKernelStakeModifier(blockFrom.GetHash(), nStakeModifier, nStakeModifierHeight, nStakeModifierTime, fPrintProofOfStake))
  736. +            return false;
  737. +        ss << nStakeModifier;
  738. +    }
  739. +    else // v0.2 protocol
  740. +    {
  741. +        ss << nBits;
  742. +    }
  743. +
  744. +    ss << nTimeBlockFrom << nTxPrevOffset << txPrev.nTime << prevout.n << nTimeTx;
  745. +    hashProofOfStake = Hash(ss.begin(), ss.end());
  746. +    if (fPrintProofOfStake)
  747. +    {
  748. +        if (IsProtocolV03(nTimeTx))
  749. +            printf("CheckStakeKernelHash() : using modifier 0x%016"PRI64x" at height=%d timestamp=%s for block from height=%d timestamp=%s\n",
  750. +                nStakeModifier, nStakeModifierHeight,
  751. +                DateTimeStrFormat(nStakeModifierTime).c_str(),
  752. +                mapBlockIndex[blockFrom.GetHash()]->nHeight,
  753. +                DateTimeStrFormat(blockFrom.GetBlockTime()).c_str());
  754. +        printf("CheckStakeKernelHash() : check protocol=%s modifier=0x%016"PRI64x" nTimeBlockFrom=%u nTxPrevOffset=%u nTimeTxPrev=%u nPrevout=%u nTimeTx=%u hashProof=%s\n",
  755. +            IsProtocolV03(nTimeTx)? "0.3" : "0.2",
  756. +            IsProtocolV03(nTimeTx)? nStakeModifier : (uint64) nBits,
  757. +            nTimeBlockFrom, nTxPrevOffset, txPrev.nTime, prevout.n, nTimeTx,
  758. +            hashProofOfStake.ToString().c_str());
  759. +    }
  760. +
  761. +    // Now check if proof-of-stake hash meets target protocol
  762. +    if (CBigNum(hashProofOfStake) > bnCoinDayWeight * bnTargetPerCoinDay)
  763. +        return false;
  764. +    if (fDebug && !fPrintProofOfStake)
  765. +    {
  766. +        if (IsProtocolV03(nTimeTx))
  767. +            printf("CheckStakeKernelHash() : using modifier 0x%016"PRI64x" at height=%d timestamp=%s for block from height=%d timestamp=%s\n",
  768. +                nStakeModifier, nStakeModifierHeight,
  769. +                DateTimeStrFormat(nStakeModifierTime).c_str(),
  770. +                mapBlockIndex[blockFrom.GetHash()]->nHeight,
  771. +                DateTimeStrFormat(blockFrom.GetBlockTime()).c_str());
  772. +        printf("CheckStakeKernelHash() : pass protocol=%s modifier=0x%016"PRI64x" nTimeBlockFrom=%u nTxPrevOffset=%u nTimeTxPrev=%u nPrevout=%u nTimeTx=%u hashProof=%s\n",
  773. +            IsProtocolV03(nTimeTx)? "0.3" : "0.2",
  774. +            IsProtocolV03(nTimeTx)? nStakeModifier : (uint64) nBits,
  775. +            nTimeBlockFrom, nTxPrevOffset, txPrev.nTime, prevout.n, nTimeTx,
  776. +            hashProofOfStake.ToString().c_str());
  777. +    }
  778. +    return true;
  779. +}
  780. +
  781. +// Check kernel hash target and coinstake signature
  782. +bool CheckProofOfStake(const CTransaction& tx, unsigned int nBits, uint256& hashProofOfStake)
  783. +{
  784. +    if (!tx.IsCoinStake())
  785. +        return error("CheckProofOfStake() : called on non-coinstake %s", tx.GetHash().ToString().c_str());
  786. +
  787. +    // Kernel (input 0) must match the stake hash target per coin age (nBits)
  788. +    const CTxIn& txin = tx.vin[0];
  789. +
  790. +    // First try finding the previous transaction in database
  791. +    CTxDB txdb("r");
  792. +    CTransaction txPrev;
  793. +    CTxIndex txindex;
  794. +    if (!txPrev.ReadFromDisk(txdb, txin.prevout, txindex))
  795. +        return tx.DoS(1, error("CheckProofOfStake() : INFO: read txPrev failed"));  // previous transaction not in main chain, may occur during initial download
  796. +    txdb.Close();
  797. +
  798. +    // Verify signature
  799. +    if (!VerifySignature(txPrev, tx, 0, true, 0))
  800. +        return tx.DoS(100, error("CheckProofOfStake() : VerifySignature failed on coinstake %s", tx.GetHash().ToString().c_str()));
  801. +
  802. +    // Read block header
  803. +    CBlock block;
  804. +    if (!block.ReadFromDisk(txindex.pos.nFile, txindex.pos.nBlockPos, false))
  805. +        return fDebug? error("CheckProofOfStake() : read block failed") : false; // unable to read block of previous transaction
  806. +
  807. +    if (!CheckStakeKernelHash(nBits, block, txindex.pos.nTxPos - txindex.pos.nBlockPos, txPrev, txin.prevout, tx.nTime, hashProofOfStake, fDebug))
  808. +        return tx.DoS(1, error("CheckProofOfStake() : INFO: check kernel failed on coinstake %s, hashProof=%s", tx.GetHash().ToString().c_str(), hashProofOfStake.ToString().c_str())); // may occur during initial download or if behind on block chain sync
  809. +
  810. +    return true;
  811. +}
  812. +
  813. +// Check whether the coinstake timestamp meets protocol
  814. +bool CheckCoinStakeTimestamp(int64 nTimeBlock, int64 nTimeTx)
  815. +{
  816. +    if (IsProtocolV03(nTimeTx))  // v0.3 protocol
  817. +        return (nTimeBlock == nTimeTx);
  818. +    else // v0.2 protocol
  819. +        return ((nTimeTx <= nTimeBlock) && (nTimeBlock <= nTimeTx + nMaxClockDrift));
  820. +}
  821. +
  822. +// Get stake modifier checksum
  823. +unsigned int GetStakeModifierChecksum(const CBlockIndex* pindex)
  824. +{
  825. +    assert (pindex->pprev || pindex->GetBlockHash() == hashGenesisBlock);
  826. +    // Hash previous checksum with flags, hashProofOfStake and nStakeModifier
  827. +    CDataStream ss(SER_GETHASH, 0);
  828. +    if (pindex->pprev)
  829. +        ss << pindex->pprev->nStakeModifierChecksum;
  830. +    ss << pindex->nFlags << pindex->hashProofOfStake << pindex->nStakeModifier;
  831. +    uint256 hashChecksum = Hash(ss.begin(), ss.end());
  832. +    hashChecksum >>= (256 - 32);
  833. +    return hashChecksum.Get64();
  834. +}
  835. +
  836. +// Check stake modifier hard checkpoints
  837. +bool CheckStakeModifierCheckpoints(int nHeight, unsigned int nStakeModifierChecksum)
  838. +{
  839. +    if (fTestNet) return true; // Testnet has no checkpoints
  840. +    if (mapStakeModifierCheckpoints.count(nHeight))
  841. +        return nStakeModifierChecksum == mapStakeModifierCheckpoints[nHeight];
  842. +    return true;
  843. +}
  844. diff -N -r -u ppcoin-0.2.2ppc-linux/src/src/kernel.h ppcoin-0.3.0-linux/src/src/kernel.h
  845. --- ppcoin-0.2.2ppc-linux/src/src/kernel.h      1969-12-31 16:00:00.000000000 -0800
  846. +++ ppcoin-0.3.0-linux/src/src/kernel.h 2013-02-16 21:33:44.000000000 -0800
  847. @@ -0,0 +1,44 @@
  848. +// Copyright (c) 2012-2013 The PPCoin developers
  849. +// Distributed under the MIT/X11 software license, see the accompanying
  850. +// file COPYING or http://www.opensource.org/licenses/mit-license.php.
  851. +#ifndef PPCOIN_KERNEL_H
  852. +#define PPCOIN_KERNEL_H
  853. +
  854. +#include "main.h"
  855. +
  856. +// MODIFIER_INTERVAL: time to elapse before new modifier is computed
  857. +static const unsigned int MODIFIER_INTERVAL = 6 * 60 * 60;
  858. +extern unsigned int nModifierInterval;
  859. +
  860. +// MODIFIER_INTERVAL_RATIO:
  861. +// ratio of group interval length between the last group and the first group
  862. +static const int MODIFIER_INTERVAL_RATIO = 3;
  863. +
  864. +// Protocol switch time of v0.3 kernel protocol
  865. +extern unsigned int nProtocolV03SwitchTime;
  866. +extern unsigned int nProtocolV03TestSwitchTime;
  867. +
  868. +// Whether a given coinstake is subject to new v0.3 protocol
  869. +bool IsProtocolV03(unsigned int nTimeCoinStake);
  870. +
  871. +// Compute the hash modifier for proof-of-stake
  872. +bool ComputeNextStakeModifier(const CBlockIndex* pindexPrev, uint64& nStakeModifier, bool& fGeneratedStakeModifier);
  873. +
  874. +// Check whether stake kernel meets hash target
  875. +// Sets hashProofOfStake on success return
  876. +bool CheckStakeKernelHash(unsigned int nBits, const CBlock& blockFrom, unsigned int nTxPrevOffset, const CTransaction& txPrev, const COutPoint& prevout, unsigned int nTimeTx, uint256& hashProofOfStake, bool fPrintProofOfStake=false);
  877. +
  878. +// Check kernel hash target and coinstake signature
  879. +// Sets hashProofOfStake on success return
  880. +bool CheckProofOfStake(const CTransaction& tx, unsigned int nBits, uint256& hashProofOfStake);
  881. +
  882. +// Check whether the coinstake timestamp meets protocol
  883. +bool CheckCoinStakeTimestamp(int64 nTimeBlock, int64 nTimeTx);
  884. +
  885. +// Get stake modifier checksum
  886. +unsigned int GetStakeModifierChecksum(const CBlockIndex* pindex);
  887. +
  888. +// Check stake modifier hard checkpoints
  889. +bool CheckStakeModifierCheckpoints(int nHeight, unsigned int nStakeModifierChecksum);
  890. +
  891. +#endif // PPCOIN_KERNEL_H
  892. diff -N -r -u ppcoin-0.2.2ppc-linux/src/src/main.cpp ppcoin-0.3.0-linux/src/src/main.cpp
  893. --- ppcoin-0.2.2ppc-linux/src/src/main.cpp      2012-11-12 13:41:36.000000000 -0800
  894. +++ ppcoin-0.3.0-linux/src/src/main.cpp 2013-02-16 21:33:45.000000000 -0800
  895. @@ -1,6 +1,6 @@
  896.  // Copyright (c) 2009-2010 Satoshi Nakamoto
  897.  // Copyright (c) 2009-2012 The Bitcoin developers
  898. -// Copyright (c) 2011-2012 The PPCoin developers
  899. +// Copyright (c) 2011-2013 The PPCoin developers
  900.  // Distributed under the MIT/X11 software license, see the accompanying
  901.  // file COPYING or http://www.opensource.org/licenses/mit-license.php.
  902.  
  903. @@ -9,6 +9,7 @@
  904.  #include "net.h"
  905.  #include "init.h"
  906.  #include "ui_interface.h"
  907. +#include "kernel.h"
  908.  #include <boost/algorithm/string/replace.hpp>
  909.  #include <boost/filesystem.hpp>
  910.  #include <boost/filesystem/fstream.hpp>
  911. @@ -48,6 +49,7 @@
  912.  map<uint256, CBlock*> mapOrphanBlocks;
  913.  multimap<uint256, CBlock*> mapOrphanBlocksByPrev;
  914.  set<pair<COutPoint, unsigned int> > setStakeSeenOrphan;
  915. +map<uint256, uint256> mapProofOfStake;
  916.  
  917.  map<uint256, CDataStream*> mapOrphanTransactions;
  918.  map<uint256, map<uint256, CDataStream*> > mapOrphanTransactionsByPrev;
  919. @@ -867,8 +869,7 @@
  920.  }
  921.  
  922.  static const int64 nTargetTimespan = 7 * 24 * 60 * 60;  // one week
  923. -static const int64 nTargetSpacingStake = 10 * 60;       // ten minutes
  924. -static const int64 nTargetSpacingWorkMax = 2 * 60 * 60; // two hours
  925. +static const int64 nTargetSpacingWorkMax = 12 * STAKE_TARGET_SPACING; // 2-hour
  926.  
  927.  //
  928.  // minimum amount of work that could possibly be required nTime after
  929. @@ -916,7 +917,7 @@
  930.      // ppcoin: retarget with exponential moving toward target spacing
  931.      CBigNum bnNew;
  932.      bnNew.SetCompact(pindexPrev->nBits);
  933. -    int64 nTargetSpacing = fProofOfStake? nTargetSpacingStake : min(nTargetSpacingWorkMax, nTargetSpacingStake * (1 + pindexLast->nHeight - pindexPrev->nHeight));
  934. +    int64 nTargetSpacing = fProofOfStake? STAKE_TARGET_SPACING : min(nTargetSpacingWorkMax, (int64) STAKE_TARGET_SPACING * (1 + pindexLast->nHeight - pindexPrev->nHeight));
  935.      int64 nInterval = nTargetTimespan / nTargetSpacing;
  936.      bnNew *= ((nInterval - 1) * nTargetSpacing + nActualSpacing + nActualSpacing);
  937.      bnNew /= ((nInterval + 1) * nTargetSpacing);
  938. @@ -1675,69 +1676,6 @@
  939.  }
  940.  
  941.  
  942. -// ppcoin: coinstake must meet hash target according to the protocol:
  943. -// kernel (input 0) must meet the formula
  944. -//     hash(nBits + txPrev.block.nTime + txPrev.offset + txPrev.nTime + txPrev.vout.n + nTime) < bnTarget * nCoinDay
  945. -// this ensures that the chance of getting a coinstake is proportional to the
  946. -// amount of coin age one owns.
  947. -// The reason this hash is chosen is the following:
  948. -//   nBits: encodes all past block timestamps, making computing hash in advance
  949. -//          more difficult
  950. -//   txPrev.block.nTime: prevent nodes from guessing a good timestamp to
  951. -//                       generate transaction for future advantage
  952. -//   txPrev.offset: offset of txPrev inside block, to reduce the chance of
  953. -//                  nodes generating coinstake at the same time
  954. -//   txPrev.nTime: reduce the chance of nodes generating coinstake at the same
  955. -//                 time
  956. -//   txPrev.vout.n: output number of txPrev, to reduce the chance of nodes
  957. -//                  generating coinstake at the same time
  958. -//   block/tx hash should not be used here as they can be generated in vast
  959. -//   quantities so as to generate blocks faster, degrading the system back into
  960. -//   a proof-of-work situation.
  961. -//
  962. -bool CTransaction::CheckProofOfStake(unsigned int nBits) const
  963. -{
  964. -    CBigNum bnTargetPerCoinDay;
  965. -    bnTargetPerCoinDay.SetCompact(nBits);
  966. -
  967. -    if (!IsCoinStake())
  968. -        return true;
  969. -
  970. -    // Kernel (input 0) must match the stake hash target per coin age (nBits)
  971. -    const CTxIn& txin = vin[0];
  972. -
  973. -    // First try finding the previous transaction in database
  974. -    CTxDB txdb("r");
  975. -    CTransaction txPrev;
  976. -    CTxIndex txindex;
  977. -    if (!txPrev.ReadFromDisk(txdb, txin.prevout, txindex))
  978. -        return false;  // previous transaction not in main chain
  979. -    txdb.Close();
  980. -    if (nTime < txPrev.nTime)
  981. -        return false;  // Transaction timestamp violation
  982. -
  983. -    // Verify signature
  984. -    if (!VerifySignature(txPrev, *this, 0, true, 0))
  985. -        return DoS(100, error("CheckProofOfStake() : VerifySignature failed on coinstake %s", GetHash().ToString().c_str()));
  986. -
  987. -    // Read block header
  988. -    CBlock block;
  989. -    if (!block.ReadFromDisk(txindex.pos.nFile, txindex.pos.nBlockPos, false))
  990. -        return false; // unable to read block of previous transaction
  991. -    if (block.GetBlockTime() + nStakeMinAge > nTime)
  992. -        return false; // only count coins meeting min age requirement
  993. -
  994. -    int64 nValueIn = txPrev.vout[txin.prevout.n].nValue;
  995. -    CBigNum bnCoinDay = CBigNum(nValueIn) * min(nTime-txPrev.nTime, (unsigned int)STAKE_MAX_AGE) / COIN / (24 * 60 * 60);
  996. -    // Calculate hash
  997. -    CDataStream ss(SER_GETHASH, 0);
  998. -    ss << nBits << block.nTime << (txindex.pos.nTxPos - txindex.pos.nBlockPos) << txPrev.nTime << txin.prevout.n << nTime;
  999. -    if (CBigNum(Hash(ss.begin(), ss.end())) <= bnCoinDay * bnTargetPerCoinDay)
  1000. -        return true;
  1001. -    else
  1002. -        return DoS(100, error("CheckProofOfStake() : check target failed on coinstake %s", GetHash().ToString().c_str()));
  1003. -}
  1004. -
  1005.  // ppcoin: total coin age spent in transaction, in the unit of coin-days.
  1006.  // Only those coins meeting minimum age requirement counts. As those
  1007.  // transactions not in main chain are not currently indexed so we
  1008. @@ -1818,11 +1756,8 @@
  1009.      CBlockIndex* pindexNew = new CBlockIndex(nFile, nBlockPos, *this);
  1010.      if (!pindexNew)
  1011.          return error("AddToBlockIndex() : new CBlockIndex failed");
  1012. -    map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.insert(make_pair(hash, pindexNew)).first;
  1013. -    if (pindexNew->fProofOfStake)
  1014. -        setStakeSeen.insert(make_pair(pindexNew->prevoutStake, pindexNew->nStakeTime));
  1015.  
  1016. -    pindexNew->phashBlock = &((*mi).first);
  1017. +    pindexNew->phashBlock = &hash;
  1018.      map<uint256, CBlockIndex*>::iterator miPrev = mapBlockIndex.find(hashPrevBlock);
  1019.      if (miPrev != mapBlockIndex.end())
  1020.      {
  1021. @@ -1833,6 +1768,35 @@
  1022.      // ppcoin: compute chain trust score
  1023.      pindexNew->bnChainTrust = (pindexNew->pprev ? pindexNew->pprev->bnChainTrust : 0) + pindexNew->GetBlockTrust();
  1024.  
  1025. +    // ppcoin: compute stake entropy bit for stake modifier
  1026. +    if (!pindexNew->SetStakeEntropyBit(GetStakeEntropyBit()))
  1027. +        return error("AddToBlockIndex() : SetStakeEntropyBit() failed");
  1028. +
  1029. +    // ppcoin: record proof-of-stake hash value
  1030. +    if (pindexNew->IsProofOfStake())
  1031. +    {
  1032. +        if (!mapProofOfStake.count(hash))
  1033. +            return error("AddToBlockIndex() : hashProofOfStake not found in map");
  1034. +        pindexNew->hashProofOfStake = mapProofOfStake[hash];
  1035. +    }
  1036. +
  1037. +    // ppcoin: compute stake modifier
  1038. +    uint64 nStakeModifier = 0;
  1039. +    bool fGeneratedStakeModifier = false;
  1040. +    if (!ComputeNextStakeModifier(pindexNew->pprev, nStakeModifier, fGeneratedStakeModifier))
  1041. +        return error("AddToBlockIndex() : ComputeNextStakeModifier() failed");
  1042. +    pindexNew->SetStakeModifier(nStakeModifier, fGeneratedStakeModifier);
  1043. +    pindexNew->nStakeModifierChecksum = GetStakeModifierChecksum(pindexNew);
  1044. +    if (!CheckStakeModifierCheckpoints(pindexNew->nHeight, pindexNew->nStakeModifierChecksum))
  1045. +        return error("AddToBlockIndex() : Rejected by stake modifier checkpoint height=%d, modifier=0x%016"PRI64x, pindexNew->nHeight, nStakeModifier);
  1046. +
  1047. +    // Add to mapBlockIndex
  1048. +    map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.insert(make_pair(hash, pindexNew)).first;
  1049. +    if (pindexNew->IsProofOfStake())
  1050. +        setStakeSeen.insert(make_pair(pindexNew->prevoutStake, pindexNew->nStakeTime));
  1051. +    pindexNew->phashBlock = &((*mi).first);
  1052. +
  1053. +    // Write to disk block index
  1054.      CTxDB txdb;
  1055.      if (!txdb.TxnBegin())
  1056.          return false;
  1057. @@ -1900,8 +1864,8 @@
  1058.          return DoS(50, error("CheckBlock() : coinbase timestamp is too early"));
  1059.  
  1060.      // Check coinstake timestamp
  1061. -    if (IsProofOfStake() && GetBlockTime() > (int64)vtx[1].nTime + nMaxClockDrift)
  1062. -        return DoS(50, error("CheckBlock() : coinstake timestamp is too early"));
  1063. +    if (IsProofOfStake() && !CheckCoinStakeTimestamp(GetBlockTime(), (int64)vtx[1].nTime))
  1064. +        return DoS(50, error("CheckBlock() : coinstake timestamp violation nTimeBlock=%u nTimeTx=%u", GetBlockTime(), vtx[1].nTime));
  1065.  
  1066.      // Check coinbase reward
  1067.      if (vtx[0].GetValueOut() > (IsProofOfWork()? (GetProofOfWorkReward(nBits) - vtx[0].GetMinFee() + MIN_TX_FEE) : 0))
  1068. @@ -2029,10 +1993,16 @@
  1069.          return error("ProcessBlock() : CheckBlock FAILED");
  1070.  
  1071.      // ppcoin: verify hash target and signature of coinstake tx
  1072. -    if (pblock->IsProofOfStake() && !pblock->vtx[1].CheckProofOfStake(pblock->nBits))
  1073. +    if (pblock->IsProofOfStake())
  1074.      {
  1075. -        printf("WARNING: ProcessBlock(): check proof-of-stake failed for block %s\n", hash.ToString().c_str());
  1076. -        return false; // do not error here as we expect this during initial block download
  1077. +        uint256 hashProofOfStake = 0;
  1078. +        if (!CheckProofOfStake(pblock->vtx[1], pblock->nBits, hashProofOfStake))
  1079. +        {
  1080. +            printf("WARNING: ProcessBlock(): check proof-of-stake failed for block %s\n", hash.ToString().c_str());
  1081. +            return false; // do not error here as we expect this during initial block download
  1082. +        }
  1083. +        if (!mapProofOfStake.count(hash)) // add to mapProofOfStake
  1084. +            mapProofOfStake.insert(make_pair(hash, hashProofOfStake));
  1085.      }
  1086.  
  1087.      CBlockIndex* pcheckpoint = Checkpoints::GetLastSyncCheckpoint();
  1088. @@ -2241,10 +2211,11 @@
  1089.          nStakeMinAge = 60 * 60 * 24; // test net min age is 1 day
  1090.          nCoinbaseMaturity = 60;
  1091.          bnInitialHashTarget = CBigNum(~uint256(0) >> 29);
  1092. +        nModifierInterval = 60 * 20; // test net modifier interval is 20 minutes
  1093.      }
  1094.  
  1095. -    printf("%s Network: genesis=0x%s nBitsLimit=0x%08x nBitsInitial=0x%08x nStakeMinAge=%d nCoinbaseMaturity=%d\n",
  1096. -           fTestNet? "Test" : "PPCoin", hashGenesisBlock.ToString().substr(0, 20).c_str(), bnProofOfWorkLimit.GetCompact(), bnInitialHashTarget.GetCompact(), nStakeMinAge, nCoinbaseMaturity);
  1097. +    printf("%s Network: genesis=0x%s nBitsLimit=0x%08x nBitsInitial=0x%08x nStakeMinAge=%d nCoinbaseMaturity=%d nModifierInterval=%d\n",
  1098. +           fTestNet? "Test" : "PPCoin", hashGenesisBlock.ToString().substr(0, 20).c_str(), bnProofOfWorkLimit.GetCompact(), bnInitialHashTarget.GetCompact(), nStakeMinAge, nCoinbaseMaturity, nModifierInterval);
  1099.  
  1100.      //
  1101.      // Load block index
  1102. @@ -2284,7 +2255,7 @@
  1103.          block.nVersion = 1;
  1104.          block.nTime    = 1345084287;
  1105.          block.nBits    = bnProofOfWorkLimit.GetCompact();
  1106. -        block.nNonce   = 2179302059;
  1107. +        block.nNonce   = 2179302059u;
  1108.  
  1109.          if (fTestNet)
  1110.          {
  1111. @@ -2454,11 +2425,11 @@
  1112.      }
  1113.  
  1114.      // ppcoin: should not enter safe mode for longer invalid chain
  1115. -    // ppcoin: if sync-checkpoint too old enter safe mode
  1116. -    if (Checkpoints::IsMatureSyncCheckpoint() && !fTestNet)
  1117. +    // ppcoin: if sync-checkpoint is too old do not enter safe mode
  1118. +    if (Checkpoints::IsSyncCheckpointTooOld(60 * 60 * 24 * 10) && !fTestNet)
  1119.      {
  1120. -        nPriority = 2000;
  1121. -        strStatusBar = strRPC = "WARNING: Checkpoint is too old. Wait for block chain to download, or notify developers of the issue.";
  1122. +        nPriority = 100;
  1123. +        strStatusBar = "WARNING: Checkpoint is too old. Wait for block chain to download, or notify developers of the issue.";
  1124.      }
  1125.  
  1126.      // ppcoin: if detected invalid checkpoint enter safe mode
  1127. @@ -3623,13 +3594,18 @@
  1128.      {
  1129.          pblock->nBits = GetNextTargetRequired(pindexPrev, true);
  1130.          CTransaction txCoinStake;
  1131. -        int64 nSearchTime = GetAdjustedTime();
  1132. +        int64 nSearchTime = txCoinStake.nTime; // search to current time
  1133.          if (nSearchTime > nLastCoinStakeSearchTime)
  1134.          {
  1135.              if (pwallet->CreateCoinStake(*pwallet, pblock->nBits, nSearchTime-nLastCoinStakeSearchTime, txCoinStake))
  1136.              {
  1137. -                pblock->vtx.push_back(txCoinStake);
  1138. -                pblock->vtx[0].vout[0].SetEmpty();
  1139. +                if (txCoinStake.nTime >= max(pindexPrev->GetMedianTimePast()+1, pindexPrev->GetBlockTime() - nMaxClockDrift))
  1140. +                {   // make sure coinstake would meet timestamp protocol
  1141. +                    // as it would be the same as the block timestamp
  1142. +                    pblock->vtx[0].vout[0].SetEmpty();
  1143. +                    pblock->vtx[0].nTime = txCoinStake.nTime;
  1144. +                    pblock->vtx.push_back(txCoinStake);
  1145. +                }
  1146.              }
  1147.              nLastCoinStakeSearchInterval = nSearchTime - nLastCoinStakeSearchTime;
  1148.              nLastCoinStakeSearchTime = nSearchTime;
  1149. @@ -3724,7 +3700,7 @@
  1150.                  continue;
  1151.  
  1152.              // Timestamp limit
  1153. -            if (tx.nTime > GetAdjustedTime())
  1154. +            if (tx.nTime > GetAdjustedTime() || (pblock->IsProofOfStake() && tx.nTime > pblock->vtx[1].nTime))
  1155.                  continue;
  1156.  
  1157.              // ppcoin: simplify transaction fee - allow free = false
  1158. @@ -3786,9 +3762,12 @@
  1159.      // Fill in header
  1160.      pblock->hashPrevBlock  = pindexPrev->GetBlockHash();
  1161.      pblock->hashMerkleRoot = pblock->BuildMerkleTree();
  1162. +    if (pblock->IsProofOfStake())
  1163. +        pblock->nTime      = pblock->vtx[1].nTime; //same as coinstake timestamp
  1164.      pblock->nTime          = max(pindexPrev->GetMedianTimePast()+1, pblock->GetMaxTransactionTime());
  1165.      pblock->nTime          = max(pblock->GetBlockTime(), pindexPrev->GetBlockTime() - nMaxClockDrift);
  1166. -    pblock->UpdateTime(pindexPrev);
  1167. +    if (pblock->IsProofOfWork())
  1168. +        pblock->UpdateTime(pindexPrev);
  1169.      pblock->nNonce         = 0;
  1170.  
  1171.      return pblock.release();
  1172. diff -N -r -u ppcoin-0.2.2ppc-linux/src/src/main.h ppcoin-0.3.0-linux/src/src/main.h
  1173. --- ppcoin-0.2.2ppc-linux/src/src/main.h        2012-11-12 13:41:45.000000000 -0800
  1174. +++ ppcoin-0.3.0-linux/src/src/main.h   2013-02-16 21:33:43.000000000 -0800
  1175. @@ -1,6 +1,6 @@
  1176.  // Copyright (c) 2009-2010 Satoshi Nakamoto
  1177.  // Copyright (c) 2009-2012 The Bitcoin developers
  1178. -// Copyright (c) 2011-2012 The PPCoin developers
  1179. +// Copyright (c) 2011-2013 The PPCoin developers
  1180.  // Distributed under the MIT/X11 software license, see the accompanying
  1181.  // file COPYING or http://www.opensource.org/licenses/mit-license.php.
  1182.  #ifndef BITCOIN_MAIN_H
  1183. @@ -41,6 +41,10 @@
  1184.  static const int COINBASE_MATURITY_PPC = 500;
  1185.  // Threshold for nLockTime: below this value it is interpreted as block number, otherwise as UNIX timestamp.
  1186.  static const int LOCKTIME_THRESHOLD = 500000000; // Tue Nov  5 00:53:20 1985 UTC
  1187. +static const int STAKE_TARGET_SPACING = 10 * 60; // 10-minute block spacing
  1188. +static const int STAKE_MIN_AGE = 60 * 60 * 24 * 30; // minimum age for coin age
  1189. +static const int STAKE_MAX_AGE = 60 * 60 * 24 * 90; // stake age of full weight
  1190. +
  1191.  #ifdef USE_UPNP
  1192.  static const int fHaveUPnP = true;
  1193.  #else
  1194. @@ -743,7 +747,6 @@
  1195.      bool CheckTransaction() const;
  1196.      bool AcceptToMemoryPool(CTxDB& txdb, bool fCheckInputs=true, bool* pfMissingInputs=NULL);
  1197.      bool GetCoinAge(CTxDB& txdb, uint64& nCoinAge) const;  // ppcoin: get transaction coin age
  1198. -    bool CheckProofOfStake(unsigned int nBits) const;
  1199.  
  1200.  protected:
  1201.      const CTxOut& GetOutputFor(const CTxIn& input, const MapPrevTx& inputs) const;
  1202. @@ -956,6 +959,18 @@
  1203.  
  1204.      void UpdateTime(const CBlockIndex* pindexPrev);
  1205.  
  1206. +    // ppcoin: entropy bit for stake modifier if chosen by modifier
  1207. +    unsigned int GetStakeEntropyBit() const
  1208. +    {
  1209. +        uint160 hashSig = Hash160(vchBlockSig);
  1210. +        if (fDebug && GetBoolArg("-printstakemodifier"))
  1211. +            printf("GetStakeEntropyBit: hashSig=%s", hashSig.ToString().c_str());
  1212. +        hashSig >>= 159; // take the first bit of the hash
  1213. +        if (fDebug && GetBoolArg("-printstakemodifier"))
  1214. +            printf(" entropybit=%d\n", hashSig.Get64());
  1215. +        return hashSig.Get64();
  1216. +    }
  1217. +
  1218.      // ppcoin: two types of block: proof-of-work or proof-of-stake
  1219.      bool IsProofOfStake() const
  1220.      {
  1221. @@ -1155,9 +1170,22 @@
  1222.      int nHeight;
  1223.      int64 nMint;
  1224.      int64 nMoneySupply;
  1225. -    bool fProofOfStake; // ppcoin: is the block of proof-of-stake type
  1226. +
  1227. +    unsigned int nFlags;  // ppcoin: block index flags
  1228. +    enum  
  1229. +    {
  1230. +        BLOCK_PROOF_OF_STAKE = (1 << 0), // is proof-of-stake block
  1231. +        BLOCK_STAKE_ENTROPY  = (1 << 1), // entropy bit for stake modifier
  1232. +        BLOCK_STAKE_MODIFIER = (1 << 2), // regenerated stake modifier
  1233. +    };
  1234. +
  1235. +    uint64 nStakeModifier; // hash modifier for proof-of-stake
  1236. +    unsigned int nStakeModifierChecksum; // checksum of index; in-memeory only
  1237. +
  1238. +    // proof-of-stake specific fields
  1239.      COutPoint prevoutStake;
  1240.      unsigned int nStakeTime;
  1241. +    uint256 hashProofOfStake;
  1242.  
  1243.      // block header
  1244.      int nVersion;
  1245. @@ -1178,7 +1206,10 @@
  1246.          bnChainTrust = 0;
  1247.          nMint = 0;
  1248.          nMoneySupply = 0;
  1249. -        fProofOfStake = true;
  1250. +        nFlags = 0;
  1251. +        nStakeModifier = 0;
  1252. +        nStakeModifierChecksum = 0;
  1253. +        hashProofOfStake = 0;
  1254.          prevoutStake.SetNull();
  1255.          nStakeTime = 0;
  1256.  
  1257. @@ -1200,9 +1231,13 @@
  1258.          bnChainTrust = 0;
  1259.          nMint = 0;
  1260.          nMoneySupply = 0;
  1261. -        fProofOfStake = block.IsProofOfStake();
  1262. -        if (fProofOfStake)
  1263. +        nFlags = 0;
  1264. +        nStakeModifier = 0;
  1265. +        nStakeModifierChecksum = 0;
  1266. +        hashProofOfStake = 0;
  1267. +        if (block.IsProofOfStake())
  1268.          {
  1269. +            SetProofOfStake();
  1270.              prevoutStake = block.vtx[1].vin[0].prevout;
  1271.              nStakeTime = block.vtx[1].nTime;
  1272.          }
  1273. @@ -1248,7 +1283,7 @@
  1274.          bnTarget.SetCompact(nBits);
  1275.          if (bnTarget <= 0)
  1276.              return 0;
  1277. -        return (fProofOfStake? (CBigNum(1)<<256) / (bnTarget+1) : 1);
  1278. +        return (IsProofOfStake()? (CBigNum(1)<<256) / (bnTarget+1) : 1);
  1279.      }
  1280.  
  1281.      bool IsInMainChain() const
  1282. @@ -1306,20 +1341,53 @@
  1283.  
  1284.      bool IsProofOfWork() const
  1285.      {
  1286. -        return !fProofOfStake;
  1287. +        return !(nFlags & BLOCK_PROOF_OF_STAKE);
  1288.      }
  1289.  
  1290.      bool IsProofOfStake() const
  1291.      {
  1292. -        return fProofOfStake;
  1293. +        return (nFlags & BLOCK_PROOF_OF_STAKE);
  1294. +    }
  1295. +
  1296. +    void SetProofOfStake()
  1297. +    {
  1298. +        nFlags |= BLOCK_PROOF_OF_STAKE;
  1299. +    }
  1300. +
  1301. +    unsigned int GetStakeEntropyBit() const
  1302. +    {
  1303. +        return ((nFlags & BLOCK_STAKE_ENTROPY) >> 1);
  1304. +    }
  1305. +
  1306. +    bool SetStakeEntropyBit(unsigned int nEntropyBit)
  1307. +    {
  1308. +        if (nEntropyBit > 1)
  1309. +            return false;
  1310. +        nFlags |= (nEntropyBit? BLOCK_STAKE_ENTROPY : 0);
  1311. +        return true;
  1312. +    }
  1313. +
  1314. +    bool GeneratedStakeModifier() const
  1315. +    {
  1316. +        return (nFlags & BLOCK_STAKE_MODIFIER);
  1317. +    }
  1318. +
  1319. +    void SetStakeModifier(uint64 nModifier, bool fGeneratedStakeModifier)
  1320. +    {
  1321. +        nStakeModifier = nModifier;
  1322. +        if (fGeneratedStakeModifier)
  1323. +            nFlags |= BLOCK_STAKE_MODIFIER;
  1324.      }
  1325.  
  1326.      std::string ToString() const
  1327.      {
  1328. -        return strprintf("CBlockIndex(nprev=%08x, pnext=%08x, nFile=%d, nBlockPos=%-6d nHeight=%d, nMint=%s, nMoneySupply=%s, fProofOfStake=%d prevoutStake=(%s), nStakeTime=%d merkle=%s, hashBlock=%s)",
  1329. +        return strprintf("CBlockIndex(nprev=%08x, pnext=%08x, nFile=%d, nBlockPos=%-6d nHeight=%d, nMint=%s, nMoneySupply=%s, nFlags=(%s)(%d)(%s), nStakeModifier=%016"PRI64x", nStakeModifierChecksum=%08x, hashProofOfStake=%s, prevoutStake=(%s), nStakeTime=%d merkle=%s, hashBlock=%s)",
  1330.              pprev, pnext, nFile, nBlockPos, nHeight,
  1331.              FormatMoney(nMint).c_str(), FormatMoney(nMoneySupply).c_str(),
  1332. -            fProofOfStake, prevoutStake.ToString().c_str(), nStakeTime,
  1333. +            GeneratedStakeModifier() ? "MOD" : "-", GetStakeEntropyBit(), IsProofOfStake()? "PoS" : "PoW",
  1334. +            nStakeModifier, nStakeModifierChecksum,
  1335. +            hashProofOfStake.ToString().c_str(),
  1336. +            prevoutStake.ToString().c_str(), nStakeTime,
  1337.              hashMerkleRoot.ToString().substr(0,10).c_str(),
  1338.              GetBlockHash().ToString().substr(0,20).c_str());
  1339.      }
  1340. @@ -1362,16 +1430,19 @@
  1341.          READWRITE(nHeight);
  1342.          READWRITE(nMint);
  1343.          READWRITE(nMoneySupply);
  1344. -        READWRITE(fProofOfStake);
  1345. -        if (fProofOfStake)
  1346. +        READWRITE(nFlags);
  1347. +        READWRITE(nStakeModifier);
  1348. +        if (IsProofOfStake())
  1349.          {
  1350.              READWRITE(prevoutStake);
  1351.              READWRITE(nStakeTime);
  1352. +            READWRITE(hashProofOfStake);
  1353.          }
  1354.          else if (fRead)
  1355.          {
  1356.              const_cast<CDiskBlockIndex*>(this)->prevoutStake.SetNull();
  1357.              const_cast<CDiskBlockIndex*>(this)->nStakeTime = 0;
  1358. +            const_cast<CDiskBlockIndex*>(this)->hashProofOfStake = 0;
  1359.          }
  1360.  
  1361.          // block header
  1362. diff -N -r -u ppcoin-0.2.2ppc-linux/src/src/makefile.linux-mingw ppcoin-0.3.0-linux/src/src/makefile.linux-mingw
  1363. --- ppcoin-0.2.2ppc-linux/src/src/makefile.linux-mingw  2012-11-12 13:41:45.000000000 -0800
  1364. +++ ppcoin-0.3.0-linux/src/src/makefile.linux-mingw     2013-02-16 21:33:51.000000000 -0800
  1365. @@ -64,7 +64,8 @@
  1366.      obj/util.o \
  1367.      obj/wallet.o \
  1368.      obj/walletdb.o \
  1369. -    obj/noui.o
  1370. +    obj/noui.o \
  1371. +    obj/kernel.o
  1372.  
  1373.  all: ppcoind.exe
  1374.  
  1375. diff -N -r -u ppcoin-0.2.2ppc-linux/src/src/makefile.mingw ppcoin-0.3.0-linux/src/src/makefile.mingw
  1376. --- ppcoin-0.2.2ppc-linux/src/src/makefile.mingw        2012-11-12 13:41:45.000000000 -0800
  1377. +++ ppcoin-0.3.0-linux/src/src/makefile.mingw   2013-02-16 21:33:44.000000000 -0800
  1378. @@ -118,7 +118,8 @@
  1379.      obj/util.o \
  1380.      obj/wallet.o \
  1381.      obj/walletdb.o \
  1382. -    obj/noui.o
  1383. +    obj/noui.o \
  1384. +    obj/kernel.o
  1385.  
  1386.  
  1387.  all: ppcoind.exe
  1388. diff -N -r -u ppcoin-0.2.2ppc-linux/src/src/makefile.unix ppcoin-0.3.0-linux/src/src/makefile.unix
  1389. --- ppcoin-0.2.2ppc-linux/src/src/makefile.unix 2012-11-12 13:41:44.000000000 -0800
  1390. +++ ppcoin-0.3.0-linux/src/src/makefile.unix    2013-02-16 21:33:51.000000000 -0800
  1391. @@ -1,5 +1,5 @@
  1392.  # Copyright (c) 2009-2010 Satoshi Nakamoto
  1393. -# Copyright (c) 2011 The PPCoin developers
  1394. +# Copyright (c) 2011-2012 The PPCoin developers
  1395.  # Distributed under the MIT/X11 software license, see the accompanying
  1396.  # file license.txt or http://www.opensource.org/licenses/mit-license.php.
  1397.  
  1398. @@ -107,7 +107,8 @@
  1399.      obj/util.o \
  1400.      obj/wallet.o \
  1401.      obj/walletdb.o \
  1402. -    obj/noui.o
  1403. +    obj/noui.o \
  1404. +    obj/kernel.o
  1405.  
  1406.  
  1407.  all: ppcoind
  1408. diff -N -r -u ppcoin-0.2.2ppc-linux/src/src/net.cpp ppcoin-0.3.0-linux/src/src/net.cpp
  1409. --- ppcoin-0.2.2ppc-linux/src/src/net.cpp       2012-11-12 13:41:45.000000000 -0800
  1410. +++ ppcoin-0.3.0-linux/src/src/net.cpp  2013-02-16 21:33:45.000000000 -0800
  1411. @@ -1,6 +1,6 @@
  1412.  // Copyright (c) 2009-2010 Satoshi Nakamoto
  1413.  // Copyright (c) 2009-2012 The Bitcoin developers
  1414. -// Copyright (c) 2011-2012 The PPCoin developers
  1415. +// Copyright (c) 2011-2013 The PPCoin developers
  1416.  // Distributed under the MIT/X11 software license, see the accompanying
  1417.  // file COPYING or http://www.opensource.org/licenses/mit-license.php.
  1418.  
  1419. @@ -1050,7 +1050,7 @@
  1420.  
  1421.  unsigned int pnSeed[] =
  1422.  {
  1423. -    0xd749a5bc, 0xf649a5bc,
  1424. +    0x231621b2,
  1425.  };
  1426.  
  1427.  void DumpAddresses()
  1428. diff -N -r -u ppcoin-0.2.2ppc-linux/src/src/qt/bitcoinamountfield.cpp ppcoin-0.3.0-linux/src/src/qt/bitcoinamountfield.cpp
  1429. --- ppcoin-0.2.2ppc-linux/src/src/qt/bitcoinamountfield.cpp     2012-11-12 13:41:37.000000000 -0800
  1430. +++ ppcoin-0.3.0-linux/src/src/qt/bitcoinamountfield.cpp        2013-02-16 21:33:48.000000000 -0800
  1431. @@ -22,7 +22,7 @@
  1432.      amount->setDecimals(8);
  1433.      amount->installEventFilter(this);
  1434.      amount->setMaximumWidth(170);
  1435. -    amount->setSingleStep(0.001);
  1436. +    amount->setSingleStep(1.0);
  1437.  
  1438.      QHBoxLayout *layout = new QHBoxLayout(this);
  1439.      layout->addWidget(amount);
  1440. diff -N -r -u ppcoin-0.2.2ppc-linux/src/src/qt/bitcoin.cpp ppcoin-0.3.0-linux/src/src/qt/bitcoin.cpp
  1441. --- ppcoin-0.2.2ppc-linux/src/src/qt/bitcoin.cpp        2012-11-12 13:41:44.000000000 -0800
  1442. +++ ppcoin-0.3.0-linux/src/src/qt/bitcoin.cpp   2013-02-16 21:33:48.000000000 -0800
  1443. @@ -1,5 +1,6 @@
  1444.  /*
  1445.   * W.J. van der Laan 2011-2012
  1446. + * The PPCoin Developers 2013
  1447.   */
  1448.  #include "bitcoingui.h"
  1449.  #include "clientmodel.h"
  1450. @@ -177,12 +178,12 @@
  1451.  
  1452.      // Application identification (must be set before OptionsModel is initialized,
  1453.      // as it is used to locate QSettings)
  1454. -    app.setOrganizationName("Bitcoin");
  1455. -    app.setOrganizationDomain("bitcoin.org");
  1456. +    app.setOrganizationName("PPCoin");
  1457. +    app.setOrganizationDomain("ppcoin.org");
  1458.      if(GetBoolArg("-testnet")) // Separate UI settings for testnet
  1459. -        app.setApplicationName("Bitcoin-Qt-testnet");
  1460. +        app.setApplicationName("PPCoin-Qt-testnet");
  1461.      else
  1462. -        app.setApplicationName("Bitcoin-Qt");
  1463. +        app.setApplicationName("PPCoin-Qt");
  1464.  
  1465.      // ... then GUI settings:
  1466.      OptionsModel optionsModel;
  1467. diff -N -r -u ppcoin-0.2.2ppc-linux/src/src/qt/bitcoingui.cpp ppcoin-0.3.0-linux/src/src/qt/bitcoingui.cpp
  1468. --- ppcoin-0.2.2ppc-linux/src/src/qt/bitcoingui.cpp     2012-11-12 13:41:44.000000000 -0800
  1469. +++ ppcoin-0.3.0-linux/src/src/qt/bitcoingui.cpp        2013-02-16 21:33:50.000000000 -0800
  1470. @@ -3,7 +3,7 @@
  1471.   *
  1472.   * W.J. van der Laan 2011-2012
  1473.   * The Bitcoin Developers 2011-2012
  1474. - * The PPCoin Developers 2011-2012
  1475. + * The PPCoin Developers 2011-2013
  1476.   */
  1477.  #include "bitcoingui.h"
  1478.  #include "transactiontablemodel.h"
  1479. @@ -25,6 +25,7 @@
  1480.  #include "askpassphrasedialog.h"
  1481.  #include "notificator.h"
  1482.  #include "guiutil.h"
  1483. +#include "wallet.h"
  1484.  
  1485.  #ifdef Q_WS_MAC
  1486.  #include "macdockiconhandler.h"
  1487. @@ -70,7 +71,7 @@
  1488.      resize(850, 550);
  1489.      setWindowTitle(tr("PPCoin Wallet"));
  1490.  #ifndef Q_WS_MAC
  1491. -    setWindowIcon(QIcon(":icons/bitcoin"));
  1492. +    setWindowIcon(QIcon(":icons/ppcoin"));
  1493.  #else
  1494.      setUnifiedTitleAndToolBarOnMac(true);
  1495.      QApplication::setAttribute(Qt::AA_DontShowIconsInMenus);
  1496. @@ -227,17 +228,17 @@
  1497.      quitAction->setToolTip(tr("Quit application"));
  1498.      quitAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q));
  1499.      quitAction->setMenuRole(QAction::QuitRole);
  1500. -    aboutAction = new QAction(QIcon(":/icons/bitcoin"), tr("&About %1").arg(qApp->applicationName()), this);
  1501. -    aboutAction->setToolTip(tr("Show information about Bitcoin"));
  1502. +    aboutAction = new QAction(QIcon(":/icons/ppcoin"), tr("&About %1").arg(qApp->applicationName()), this);
  1503. +    aboutAction->setToolTip(tr("Show information about PPCoin"));
  1504.      aboutAction->setMenuRole(QAction::AboutRole);
  1505.      aboutQtAction = new QAction(tr("About &Qt"), this);
  1506.      aboutQtAction->setToolTip(tr("Show information about Qt"));
  1507.      aboutQtAction->setMenuRole(QAction::AboutQtRole);
  1508.      optionsAction = new QAction(QIcon(":/icons/options"), tr("&Options..."), this);
  1509. -    optionsAction->setToolTip(tr("Modify configuration options for bitcoin"));
  1510. +    optionsAction->setToolTip(tr("Modify configuration options for ppcoin"));
  1511.      optionsAction->setMenuRole(QAction::PreferencesRole);
  1512. -    toggleHideAction = new QAction(QIcon(":/icons/bitcoin"), tr("Show/Hide &Bitcoin"), this);
  1513. -    toggleHideAction->setToolTip(tr("Show or hide the Bitcoin window"));
  1514. +    toggleHideAction = new QAction(QIcon(":/icons/ppcoin"), tr("Show/Hide &PPCoin"), this);
  1515. +    toggleHideAction->setToolTip(tr("Show or hide the PPCoin window"));
  1516.      exportAction = new QAction(QIcon(":/icons/export"), tr("&Export..."), this);
  1517.      exportAction->setToolTip(tr("Export the data in the current tab to a file"));
  1518.      encryptWalletAction = new QAction(QIcon(":/icons/lock_closed"), tr("&Encrypt Wallet"), this);
  1519. @@ -317,9 +318,9 @@
  1520.              QString title_testnet = windowTitle() + QString(" ") + tr("[testnet]");
  1521.              setWindowTitle(title_testnet);
  1522.  #ifndef Q_WS_MAC
  1523. -            setWindowIcon(QIcon(":icons/bitcoin_testnet"));
  1524. +            setWindowIcon(QIcon(":icons/ppcoin_testnet"));
  1525.  #else
  1526. -            MacDockIconHandler::instance()->setIcon(QIcon(":icons/bitcoin_testnet"));
  1527. +            MacDockIconHandler::instance()->setIcon(QIcon(":icons/ppcoin_testnet"));
  1528.  #endif
  1529.              if(trayIcon)
  1530.              {
  1531. @@ -376,7 +377,7 @@
  1532.      trayIcon = new QSystemTrayIcon(this);
  1533.      trayIconMenu = new QMenu(this);
  1534.      trayIcon->setContextMenu(trayIconMenu);
  1535. -    trayIcon->setToolTip(tr("Bitcoin client"));
  1536. +    trayIcon->setToolTip(tr("PPCoin client"));
  1537.      trayIcon->setIcon(QIcon(":/icons/toolbar"));
  1538.      connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
  1539.              this, SLOT(trayIconActivated(QSystemTrayIcon::ActivationReason)));
  1540. @@ -403,7 +404,7 @@
  1541.      trayIconMenu->addAction(quitAction);
  1542.  #endif
  1543.  
  1544. -    notificator = new Notificator(tr("bitcoin-qt"), trayIcon);
  1545. +    notificator = new Notificator(tr("ppcoin-qt"), trayIcon);
  1546.  }
  1547.  
  1548.  #ifndef Q_WS_MAC
  1549. @@ -467,7 +468,7 @@
  1550.      default: icon = ":/icons/connect_4"; break;
  1551.      }
  1552.      labelConnectionsIcon->setPixmap(QIcon(icon).pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
  1553. -    labelConnectionsIcon->setToolTip(tr("%n active connection(s) to Bitcoin network", "", count));
  1554. +    labelConnectionsIcon->setToolTip(tr("%n active connection(s) to PPCoin network", "", count));
  1555.  }
  1556.  
  1557.  void BitcoinGUI::setNumBlocks(int count)
  1558. @@ -777,7 +778,7 @@
  1559.      case WalletModel::Unlocked:
  1560.          labelEncryptionIcon->show();
  1561.          labelEncryptionIcon->setPixmap(QIcon(":/icons/lock_open").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
  1562. -        labelEncryptionIcon->setToolTip(tr("Wallet is <b>encrypted</b> and currently <b>unlocked</b>"));
  1563. +        labelEncryptionIcon->setToolTip(fWalletUnlockMintOnly? tr("Wallet is <b>encrypted</b> and currently <b>unlocked for block minting only</b>") : tr("Wallet is <b>encrypted</b> and currently <b>unlocked</b>"));
  1564.          encryptWalletAction->setChecked(true);
  1565.          changePassphraseAction->setEnabled(true);
  1566.          encryptWalletAction->setEnabled(false); // TODO: decrypt currently not supported
  1567. diff -N -r -u ppcoin-0.2.2ppc-linux/src/src/qt/bitcoin.qrc ppcoin-0.3.0-linux/src/src/qt/bitcoin.qrc
  1568. --- ppcoin-0.2.2ppc-linux/src/src/qt/bitcoin.qrc        2012-11-12 13:41:39.000000000 -0800
  1569. +++ ppcoin-0.3.0-linux/src/src/qt/bitcoin.qrc   2013-02-16 21:33:50.000000000 -0800
  1570. @@ -1,6 +1,7 @@
  1571.  <RCC>
  1572.      <qresource prefix="/icons">
  1573.          <file alias="bitcoin">res/icons/bitcoin.png</file>
  1574. +        <file alias="ppcoin">res/icons/ppcoin.png</file>
  1575.          <file alias="address-book">res/icons/address-book.png</file>
  1576.          <file alias="quit">res/icons/quit.png</file>
  1577.          <file alias="send">res/icons/send.png</file>
  1578. @@ -23,6 +24,7 @@
  1579.          <file alias="editcopy">res/icons/editcopy.png</file>
  1580.          <file alias="add">res/icons/add.png</file>
  1581.          <file alias="bitcoin_testnet">res/icons/bitcoin_testnet.png</file>
  1582. +        <file alias="ppcoin_testnet">res/icons/ppcoin_testnet.png</file>
  1583.          <file alias="toolbar_testnet">res/icons/toolbar_testnet.png</file>
  1584.          <file alias="edit">res/icons/edit.png</file>
  1585.          <file alias="history">res/icons/history.png</file>
  1586. @@ -41,7 +43,7 @@
  1587.      </qresource>
  1588.      <qresource prefix="/images">
  1589.          <file alias="about">res/images/about.png</file>
  1590. -        <file alias="splash">res/images/splash2.jpg</file>
  1591. +        <file alias="splash">res/images/ppcoin_splash.png</file>
  1592.          <file alias="qrcode">res/images/qrcode.png</file>
  1593.      </qresource>
  1594.      <qresource prefix="/movies">
  1595. diff -N -r -u ppcoin-0.2.2ppc-linux/src/src/qt/forms/aboutdialog.ui ppcoin-0.3.0-linux/src/src/qt/forms/aboutdialog.ui
  1596. --- ppcoin-0.2.2ppc-linux/src/src/qt/forms/aboutdialog.ui       2012-11-12 13:41:40.000000000 -0800
  1597. +++ ppcoin-0.3.0-linux/src/src/qt/forms/aboutdialog.ui  2013-02-16 21:33:48.000000000 -0800
  1598. @@ -11,7 +11,7 @@
  1599.     </rect>
  1600.    </property>
  1601.    <property name="windowTitle">
  1602. -   <string>About Bitcoin</string>
  1603. +   <string>About PPCoin</string>
  1604.    </property>
  1605.    <layout class="QHBoxLayout" name="horizontalLayout_2">
  1606.     <item>
  1607. @@ -50,7 +50,7 @@
  1608.         <item>
  1609.          <widget class="QLabel" name="label">
  1610.           <property name="text">
  1611. -          <string>&lt;b&gt;Bitcoin&lt;/b&gt; version</string>
  1612. +          <string>&lt;b&gt;PPCoin&lt;/b&gt; version</string>
  1613.           </property>
  1614.           <property name="textInteractionFlags">
  1615.            <set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
  1616. @@ -86,6 +86,19 @@
  1617.        </layout>
  1618.       </item>
  1619.       <item>
  1620. +      <widget class="QLabel" name="label_ppcoin_copyright">
  1621. +       <property name="text">
  1622. +        <string>Copyright © 2011-2013 PPCoin Developers</string>
  1623. +       </property>
  1624. +       <property name="wordWrap">
  1625. +        <bool>true</bool>
  1626. +       </property>
  1627. +       <property name="textInteractionFlags">
  1628. +        <set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
  1629. +       </property>
  1630. +      </widget>
  1631. +     </item>
  1632. +     <item>
  1633.        <widget class="QLabel" name="label_2">
  1634.         <property name="text">
  1635.          <string>Copyright © 2009-2012 Bitcoin Developers
  1636. diff -N -r -u ppcoin-0.2.2ppc-linux/src/src/qt/forms/qrcodedialog.ui ppcoin-0.3.0-linux/src/src/qt/forms/qrcodedialog.ui
  1637. --- ppcoin-0.2.2ppc-linux/src/src/qt/forms/qrcodedialog.ui      2012-11-12 13:41:40.000000000 -0800
  1638. +++ ppcoin-0.3.0-linux/src/src/qt/forms/qrcodedialog.ui 2013-02-16 21:33:48.000000000 -0800
  1639. @@ -102,7 +102,7 @@
  1640.                 </sizepolicy>
  1641.                </property>
  1642.                <property name="text">
  1643. -               <string>BTC</string>
  1644. +               <string>PPC</string>
  1645.                </property>
  1646.                <property name="buddy">
  1647.                 <cstring>lnReqAmount</cstring>
  1648. diff -N -r -u ppcoin-0.2.2ppc-linux/src/src/qt/forms/sendcoinsentry.ui ppcoin-0.3.0-linux/src/src/qt/forms/sendcoinsentry.ui
  1649. --- ppcoin-0.2.2ppc-linux/src/src/qt/forms/sendcoinsentry.ui    2012-11-12 13:41:40.000000000 -0800
  1650. +++ ppcoin-0.3.0-linux/src/src/qt/forms/sendcoinsentry.ui       2013-02-16 21:33:48.000000000 -0800
  1651. @@ -90,7 +90,7 @@
  1652.       <item>
  1653.        <widget class="QValidatedLineEdit" name="payTo">
  1654.         <property name="toolTip">
  1655. -        <string>The address to send the payment to  (e.g. 1NS17iag9jJgTHD1VXjvLCEnZuQ3rJDE9L)</string>
  1656. +        <string>The address to send the payment to</string>
  1657.         </property>
  1658.         <property name="maxLength">
  1659.          <number>34</number>
  1660. diff -N -r -u ppcoin-0.2.2ppc-linux/src/src/qt/res/bitcoin-qt.rc ppcoin-0.3.0-linux/src/src/qt/res/bitcoin-qt.rc
  1661. --- ppcoin-0.2.2ppc-linux/src/src/qt/res/bitcoin-qt.rc  2012-11-12 13:41:39.000000000 -0800
  1662. +++ ppcoin-0.3.0-linux/src/src/qt/res/bitcoin-qt.rc     2013-02-16 21:33:50.000000000 -0800
  1663. @@ -1 +1 @@
  1664. -IDI_ICON1 ICON DISCARDABLE "icons/bitcoin.ico"
  1665. +IDI_ICON1 ICON DISCARDABLE "icons/ppcoin.ico"
  1666. Binary files ppcoin-0.2.2ppc-linux/src/src/qt/res/icons/ppcoin.ico and ppcoin-0.3.0-linux/src/src/qt/res/icons/ppcoin.ico differ
  1667. Binary files ppcoin-0.2.2ppc-linux/src/src/qt/res/icons/ppcoin.png and ppcoin-0.3.0-linux/src/src/qt/res/icons/ppcoin.png differ
  1668. Binary files ppcoin-0.2.2ppc-linux/src/src/qt/res/icons/ppcoin_testnet.png and ppcoin-0.3.0-linux/src/src/qt/res/icons/ppcoin_testnet.png differ
  1669. Binary files ppcoin-0.2.2ppc-linux/src/src/qt/res/icons/toolbar.png and ppcoin-0.3.0-linux/src/src/qt/res/icons/toolbar.png differ
  1670. Binary files ppcoin-0.2.2ppc-linux/src/src/qt/res/icons/toolbar_testnet.png and ppcoin-0.3.0-linux/src/src/qt/res/icons/toolbar_testnet.png differ
  1671. Binary files ppcoin-0.2.2ppc-linux/src/src/qt/res/images/ppcoin_splash.png and ppcoin-0.3.0-linux/src/src/qt/res/images/ppcoin_splash.png differ
  1672. diff -N -r -u ppcoin-0.2.2ppc-linux/src/src/qt/sendcoinsdialog.cpp ppcoin-0.3.0-linux/src/src/qt/sendcoinsdialog.cpp
  1673. --- ppcoin-0.2.2ppc-linux/src/src/qt/sendcoinsdialog.cpp        2012-11-12 13:41:44.000000000 -0800
  1674. +++ ppcoin-0.3.0-linux/src/src/qt/sendcoinsdialog.cpp   2013-02-16 21:33:45.000000000 -0800
  1675. @@ -125,7 +125,7 @@
  1676.          break;
  1677.      case WalletModel::InvalidAmount:
  1678.          QMessageBox::warning(this, tr("Send Coins"),
  1679. -            tr("The amount to pay must be larger than 0."),
  1680. +            tr("The amount to pay must be at least one cent (0.01)."),
  1681.              QMessageBox::Ok, QMessageBox::Ok);
  1682.          break;
  1683.      case WalletModel::AmountExceedsBalance:
  1684. diff -N -r -u ppcoin-0.2.2ppc-linux/src/src/qt/sendcoinsentry.cpp ppcoin-0.3.0-linux/src/src/qt/sendcoinsentry.cpp
  1685. --- ppcoin-0.2.2ppc-linux/src/src/qt/sendcoinsentry.cpp 2012-11-12 13:41:40.000000000 -0800
  1686. +++ ppcoin-0.3.0-linux/src/src/qt/sendcoinsentry.cpp    2013-02-16 21:33:48.000000000 -0800
  1687. @@ -22,7 +22,7 @@
  1688.  #endif
  1689.  
  1690.  #if QT_VERSION >= 0x040700
  1691. -    ui->payTo->setPlaceholderText(tr("Enter a Bitcoin address (e.g. 1NS17iag9jJgTHD1VXjvLCEnZuQ3rJDE9L)"));
  1692. +    ui->payTo->setPlaceholderText(tr("Enter a PPCoin address"));
  1693.      ui->addAsLabel->setPlaceholderText(tr("Enter a label for this address to add it to your address book"));
  1694.  #endif
  1695.      setFocusPolicy(Qt::TabFocus);
  1696. diff -N -r -u ppcoin-0.2.2ppc-linux/src/src/qt/transactionview.cpp ppcoin-0.3.0-linux/src/src/qt/transactionview.cpp
  1697. --- ppcoin-0.2.2ppc-linux/src/src/qt/transactionview.cpp        2012-11-12 13:41:44.000000000 -0800
  1698. +++ ppcoin-0.3.0-linux/src/src/qt/transactionview.cpp   2013-02-16 21:33:50.000000000 -0800
  1699. @@ -167,7 +167,7 @@
  1700.          transactionView->setSelectionBehavior(QAbstractItemView::SelectRows);
  1701.          transactionView->setSelectionMode(QAbstractItemView::ExtendedSelection);
  1702.          transactionView->setSortingEnabled(true);
  1703. -        transactionView->sortByColumn(TransactionTableModel::Status, Qt::DescendingOrder);
  1704. +        transactionView->sortByColumn(TransactionTableModel::Date, Qt::DescendingOrder);
  1705.          transactionView->verticalHeader()->hide();
  1706.  
  1707.          transactionView->horizontalHeader()->resizeSection(
  1708. diff -N -r -u ppcoin-0.2.2ppc-linux/src/src/qt/walletmodel.cpp ppcoin-0.3.0-linux/src/src/qt/walletmodel.cpp
  1709. --- ppcoin-0.2.2ppc-linux/src/src/qt/walletmodel.cpp    2012-11-12 13:41:39.000000000 -0800
  1710. +++ ppcoin-0.3.0-linux/src/src/qt/walletmodel.cpp       2013-02-16 21:33:48.000000000 -0800
  1711. @@ -97,7 +97,7 @@
  1712.          }
  1713.          setAddress.insert(rcp.address);
  1714.  
  1715. -        if(rcp.amount <= 0)
  1716. +        if(rcp.amount < MIN_TXOUT_AMOUNT)
  1717.          {
  1718.              return InvalidAmount;
  1719.          }
  1720. diff -N -r -u ppcoin-0.2.2ppc-linux/src/src/rpcdump.cpp ppcoin-0.3.0-linux/src/src/rpcdump.cpp
  1721. --- ppcoin-0.2.2ppc-linux/src/src/rpcdump.cpp   2012-11-12 13:41:36.000000000 -0800
  1722. +++ ppcoin-0.3.0-linux/src/src/rpcdump.cpp      2013-02-16 21:33:44.000000000 -0800
  1723. @@ -1,5 +1,5 @@
  1724.  // Copyright (c) 2009-2012 Bitcoin Developers
  1725. -// Copyright (c) 2012 The PPCoin developers
  1726. +// Copyright (c) 2012-2013 The PPCoin developers
  1727.  // Distributed under the MIT/X11 software license, see the accompanying
  1728.  // file COPYING or http://www.opensource.org/licenses/mit-license.php.
  1729.  
  1730. @@ -54,6 +54,8 @@
  1731.      bool fGood = vchSecret.SetString(strSecret);
  1732.  
  1733.      if (!fGood) throw JSONRPCError(-5,"Invalid private key");
  1734. +    if (fWalletUnlockMintOnly) // ppcoin: no importprivkey in mint-only mode
  1735. +        throw JSONRPCError(-102, "Wallet is unlocked for minting only.");
  1736.  
  1737.      CKey key;
  1738.      bool fCompressed;
  1739. @@ -90,6 +92,8 @@
  1740.      CBitcoinAddress address;
  1741.      if (!address.SetString(strAddress))
  1742.          throw JSONRPCError(-5, "Invalid ppcoin address");
  1743. +    if (fWalletUnlockMintOnly) // ppcoin: no dumpprivkey in mint-only mode
  1744. +        throw JSONRPCError(-102, "Wallet is unlocked for minting only.");
  1745.      CSecret vchSecret;
  1746.      bool fCompressed;
  1747.      if (!pwalletMain->GetSecret(address, vchSecret, fCompressed))
  1748. diff -N -r -u ppcoin-0.2.2ppc-linux/src/src/version.cpp ppcoin-0.3.0-linux/src/src/version.cpp
  1749. --- ppcoin-0.2.2ppc-linux/src/src/version.cpp   2012-11-12 13:41:36.000000000 -0800
  1750. +++ ppcoin-0.3.0-linux/src/src/version.cpp      2013-02-16 21:33:45.000000000 -0800
  1751. @@ -36,7 +36,7 @@
  1752.  // git will put "#define GIT_ARCHIVE 1" on the next line inside archives.
  1753.  #define GIT_ARCHIVE 1
  1754.  #ifdef GIT_ARCHIVE
  1755. -#    define GIT_COMMIT_ID "290825c"
  1756. +#    define GIT_COMMIT_ID "be62545"
  1757.  #    define GIT_COMMIT_DATE "$Format:%cD"
  1758.  #endif
  1759.  
  1760. diff -N -r -u ppcoin-0.2.2ppc-linux/src/src/version.h ppcoin-0.3.0-linux/src/src/version.h
  1761. --- ppcoin-0.2.2ppc-linux/src/src/version.h     2012-11-12 13:41:44.000000000 -0800
  1762. +++ ppcoin-0.3.0-linux/src/src/version.h        2013-02-16 21:33:51.000000000 -0800
  1763. @@ -1,4 +1,5 @@
  1764.  // Copyright (c) 2012 The Bitcoin developers
  1765. +// Copyright (c) 2012-2013 The PPCoin developers
  1766.  // Distributed under the MIT/X11 software license, see the accompanying
  1767.  // file COPYING or http://www.opensource.org/licenses/mit-license.php.
  1768.  #ifndef BITCOIN_VERSION_H
  1769. @@ -28,15 +29,15 @@
  1770.  
  1771.  // ppcoin version - intended for display purpose ONLY
  1772.  #define PPCOIN_VERSION_MAJOR       0
  1773. -#define PPCOIN_VERSION_MINOR       2
  1774. -#define PPCOIN_VERSION_REVISION    2
  1775. +#define PPCOIN_VERSION_MINOR       3
  1776. +#define PPCOIN_VERSION_REVISION    0
  1777.  #define PPCOIN_VERSION_BUILD       0
  1778.  
  1779.  //
  1780.  // network protocol versioning
  1781.  //
  1782.  
  1783. -static const int PROTOCOL_VERSION = 60002;
  1784. +static const int PROTOCOL_VERSION = 60003;
  1785.  
  1786.  // earlier versions not supported as of Feb 2012, and are disconnected
  1787.  // NOTE: as of bitcoin v0.6 message serialization (vSend, vRecv) still
  1788. diff -N -r -u ppcoin-0.2.2ppc-linux/src/src/wallet.cpp ppcoin-0.3.0-linux/src/src/wallet.cpp
  1789. --- ppcoin-0.2.2ppc-linux/src/src/wallet.cpp    2012-11-12 13:41:35.000000000 -0800
  1790. +++ ppcoin-0.3.0-linux/src/src/wallet.cpp       2013-02-16 21:33:43.000000000 -0800
  1791. @@ -1,14 +1,14 @@
  1792.  // Copyright (c) 2009-2010 Satoshi Nakamoto
  1793.  // Copyright (c) 2009-2012 The Bitcoin developers
  1794. -// Copyright (c) 2011-2012 The PPCoin developers
  1795. +// Copyright (c) 2011-2013 The PPCoin developers
  1796.  // Distributed under the MIT/X11 software license, see the accompanying
  1797.  // file COPYING or http://www.opensource.org/licenses/mit-license.php.
  1798.  
  1799.  #include "wallet.h"
  1800.  #include "walletdb.h"
  1801.  #include "crypter.h"
  1802. -#include "checkpoints.h"
  1803.  #include "ui_interface.h"
  1804. +#include "kernel.h"
  1805.  
  1806.  using namespace std;
  1807.  
  1808. @@ -71,7 +71,7 @@
  1809.      return CWalletDB(strWalletFile).WriteCScript(Hash160(redeemScript), redeemScript);
  1810.  }
  1811.  
  1812. -// ppcoin: optional setting to create coinstake only when unlocked;
  1813. +// ppcoin: optional setting to unlock wallet for block minting only;
  1814.  //         serves to disable the trivial sendmoney when OS account compromised
  1815.  bool fWalletUnlockMintOnly = false;
  1816.  
  1817. @@ -834,7 +834,10 @@
  1818.          BOOST_FOREACH(PAIRTYPE(const unsigned int, CWalletTx*)& item, mapSorted)
  1819.          {
  1820.              CWalletTx& wtx = *item.second;
  1821. -            wtx.RelayWalletTransaction(txdb);
  1822. +            if (wtx.CheckTransaction())
  1823. +                wtx.RelayWalletTransaction(txdb);
  1824. +            else
  1825. +                printf("ResendWalletTransactions() : CheckTransaction failed for transaction %s\n", wtx.GetHash().ToString().c_str());
  1826.          }
  1827.      }
  1828.  }
  1829. @@ -1247,21 +1250,18 @@
  1830.          CBlock block;
  1831.          if (!block.ReadFromDisk(txindex.pos.nFile, txindex.pos.nBlockPos, false))
  1832.              continue;
  1833. -        if (block.GetBlockTime() + nStakeMinAge > txNew.nTime - nMaxClockDrift)
  1834. +        static int nMaxStakeSearchInterval = 60;
  1835. +        if (block.GetBlockTime() + nStakeMinAge > txNew.nTime - nMaxStakeSearchInterval)
  1836.              continue; // only count coins meeting min age requirement
  1837.  
  1838. -        int64 nValueIn = pcoin.first->vout[pcoin.second].nValue;
  1839. -        CBigNum bnCoinDay = CBigNum(nValueIn) * min(txNew.nTime-pcoin.first->nTime, (unsigned int)STAKE_MAX_AGE) / COIN / (24 * 60 * 60);
  1840. -
  1841.          bool fKernelFound = false;
  1842. -        for (int n=0; n<min(nSearchInterval,(int64)5) && !fKernelFound && !fShutdown; n++)
  1843. +        for (unsigned int n=0; n<min(nSearchInterval,(int64)nMaxStakeSearchInterval) && !fKernelFound && !fShutdown; n++)
  1844.          {
  1845. -            // Randomly pick a timestamp from protocol allowed range
  1846. -            txNew.nTime = GetAdjustedTime() - GetRandInt(nMaxClockDrift - 60);
  1847. -            // Calculate hash
  1848. -            CDataStream ss(SER_GETHASH, 0);
  1849. -            ss << nBits << block.nTime << (txindex.pos.nTxPos - txindex.pos.nBlockPos) << pcoin.first->nTime << pcoin.second << txNew.nTime;
  1850. -            if (CBigNum(Hash(ss.begin(), ss.end())) <= bnCoinDay * bnTargetPerCoinDay)
  1851. +            // Search backward in time from the given txNew timestamp
  1852. +            // Search nSearchInterval seconds back up to nMaxStakeSearchInterval
  1853. +            uint256 hashProofOfStake = 0;
  1854. +            COutPoint prevoutStake = COutPoint(pcoin.first->GetHash(), pcoin.second);
  1855. +            if (CheckStakeKernelHash(nBits, block, txindex.pos.nTxPos - txindex.pos.nBlockPos, *pcoin.first, prevoutStake, txNew.nTime - n, hashProofOfStake))
  1856.              {
  1857.                  // Found a kernel
  1858.                  if (fDebug && GetBoolArg("-printcoinstake"))
  1859. @@ -1298,7 +1298,8 @@
  1860.                  }
  1861.                  else
  1862.                      scriptPubKeyOut = scriptPubKeyKernel;
  1863. -    
  1864. +
  1865. +                txNew.nTime -= n;
  1866.                  txNew.vin.push_back(CTxIn(pcoin.first->GetHash(), pcoin.second));
  1867.                  nCredit += pcoin.first->vout[pcoin.second].nValue;
  1868.                  vwtxPrev.push_back(pcoin.first);
  1869. @@ -1308,6 +1309,7 @@
  1870.                  if (fDebug && GetBoolArg("-printcoinstake"))
  1871.                      printf("CreateCoinStake : added kernel type=%d\n", whichType);
  1872.                  fKernelFound = true;
  1873. +                break;
  1874.              }
  1875.          }
  1876.          if (fKernelFound || fShutdown)
  1877. @@ -1334,6 +1336,9 @@
  1878.              // Do not add additional significant input
  1879.              if (pcoin.first->vout[pcoin.second].nValue > nCombineThreshold)
  1880.                  continue;
  1881. +            // Do not add input that is still too young
  1882. +            if (pcoin.first->nTime + STAKE_MAX_AGE > txNew.nTime)
  1883. +                continue;
  1884.              txNew.vin.push_back(CTxIn(pcoin.first->GetHash(), pcoin.second));
  1885.              nCredit += pcoin.first->vout[pcoin.second].nValue;
  1886.              vwtxPrev.push_back(pcoin.first);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement