Cache scrypt hashes on disk
authoralex <alex@alex-VirtualBox.(none)>
Tue, 31 Dec 2013 17:04:16 +0000 (21:04 +0400)
committeralex <alex@alex-VirtualBox.(none)>
Tue, 31 Dec 2013 17:04:16 +0000 (21:04 +0400)
instead of recalculating every time. This policy is able to give us 10-20x startng speed up. User can disable caching with -fastindex=0 option.

Note that this commit makes blockindex code incompatible with old blockchain database files. You need to remove old blockchain files and syncronize with the network again.

Another changes:

1. Stake pooled keys are removed.

src/init.cpp
src/main.cpp
src/main.h
src/qt/locale/bitcoin_en.ts
src/qt/locale/bitcoin_ru.ts
src/txdb-bdb.cpp
src/txdb-leveldb.cpp
src/wallet.cpp

index 80405c9..f406c76 100644 (file)
@@ -31,6 +31,7 @@ CClientUIInterface uiInterface;
 std::string strWalletFileName;
 unsigned int nNodeLifespan;
 unsigned int nDerivationMethodIndex;
+bool fUseFastIndex;
 enum Checkpoints::CPMode CheckpointsMode;
 
 //////////////////////////////////////////////////////////////////////////////
@@ -250,8 +251,6 @@ std::string HelpMessage()
         "  -bind=<addr>           " + _("Bind to given address. Use [host]:port notation for IPv6") + "\n" +
         "  -dnsseed               " + _("Find peers using DNS lookup (default: 1)") + "\n" +
         "  -cppolicy              " + _("Sync checkpoints policy (default: strict)") + "\n" +
-        "  -stakepooledkeys       " + _("Use pooled pubkeys for the last coinstake output (default: 0)") + "\n" +
-        "  -derivationmethod      " + _("Which key derivation method to use by default (default: sha512)") + "\n" +
         "  -banscore=<n>          " + _("Threshold for disconnecting misbehaving peers (default: 100)") + "\n" +
         "  -bantime=<n>           " + _("Number of seconds to keep misbehaving peers from reconnecting (default: 86400)") + "\n" +
         "  -maxreceivebuffer=<n>  " + _("Maximum per-connection receive buffer, <n>*1000 bytes (default: 5000)") + "\n" +
@@ -360,7 +359,7 @@ bool AppInit2()
     // ********************************************************* Step 2: parameter interactions
 
     nNodeLifespan = GetArg("-addrlifespan", 7);
-    fStakeUsePooledKeys = GetBoolArg("-stakepooledkeys", false);
+    fUseFastIndex = GetBoolArg("-fastindex", true);
 
     CheckpointsMode = Checkpoints::STRICT;
     std::string strCpMode = GetArg("-cppolicy", "strict");
@@ -374,8 +373,7 @@ bool AppInit2()
     if(strCpMode == "permissive")
         CheckpointsMode = Checkpoints::PERMISSIVE;
 
-    if(GetArg("-derivationmethod", "sha512") == "scrypt+sha512")
-        nDerivationMethodIndex = 1;
+    nDerivationMethodIndex = 0;
 
     fTestNet = GetBoolArg("-testnet");
     if (fTestNet) {
index 63700ac..7e62654 100644 (file)
@@ -79,7 +79,6 @@ const string strMessageMagic = "NovaCoin Signed Message:\n";
 int64 nTransactionFee = MIN_TX_FEE;
 int64 nMinimumInputValue = MIN_TX_FEE;
 
-bool fStakeUsePooledKeys = false;
 extern enum Checkpoints::CPMode CheckpointsMode;
 
 //////////////////////////////////////////////////////////////////////////////
index ed202c4..4955be9 100644 (file)
@@ -88,7 +88,7 @@ extern std::map<uint256, CBlock*> mapOrphanBlocks;
 // Settings
 extern int64 nTransactionFee;
 extern int64 nMinimumInputValue;
-extern bool fStakeUsePooledKeys;
+extern bool fUseFastIndex;
 extern unsigned int nDerivationMethodIndex;
 
 // Minimum disk space required - used in CheckDiskSpace()
@@ -1349,6 +1349,9 @@ public:
 /** Used to marshal pointers into hashes for db storage. */
 class CDiskBlockIndex : public CBlockIndex
 {
+private:
+    uint256 blockHash;
+
 public:
     uint256 hashPrev;
     uint256 hashNext;
@@ -1357,6 +1360,7 @@ public:
     {
         hashPrev = 0;
         hashNext = 0;
+        blockHash = 0;
     }
 
     explicit CDiskBlockIndex(CBlockIndex* pindex) : CBlockIndex(*pindex)
@@ -1398,10 +1402,14 @@ public:
         READWRITE(nTime);
         READWRITE(nBits);
         READWRITE(nNonce);
+        READWRITE(blockHash);
     )
 
     uint256 GetBlockHash() const
     {
+        if (fUseFastIndex && (nTime < GetAdjustedTime() - 12 * nMaxClockDrift) && blockHash != 0)
+            return blockHash;
+
         CBlock block;
         block.nVersion        = nVersion;
         block.hashPrevBlock   = hashPrev;
@@ -1409,9 +1417,11 @@ public:
         block.nTime           = nTime;
         block.nBits           = nBits;
         block.nNonce          = nNonce;
-        return block.GetHash();
-    }
 
+        const_cast<CDiskBlockIndex*>(this)->blockHash = block.GetHash();
+
+        return blockHash;
+    }
 
     std::string ToString() const
     {
index 93e70da..e1f22b1 100644 (file)
@@ -2787,14 +2787,6 @@ This label turns red, if the priority is smaller than &quot;medium&quot;.
         <translation type="obsolete">Sync checkpoints policy (default: strict)</translation>
     </message>
     <message>
-        <source>Use pooled pubkeys for the last coinstake output (default: 0)</source>
-        <translation type="obsolete">Use pooled pubkeys for the last coinstake output (default: 0)</translation>
-    </message>
-    <message>
-        <source>Which key derivation method to use by default (default: sha512)</source>
-        <translation type="obsolete">Which key derivation method to use by default (default: sha512)</translation>
-    </message>
-    <message>
         <location line="+12"/>
         <source>Invalid -tor address: &apos;%s&apos;</source>
         <translation>Invalid -tor address: &apos;%s&apos;</translation>
index 78d6e18..556d599 100644 (file)
@@ -2799,14 +2799,6 @@ This label turns red, if the priority is smaller than &quot;medium&quot;.
         <translation type="obsolete">Политика синхронизированных меток (по умолчанию: strict)</translation>
     </message>
     <message>
-        <source>Use pooled pubkeys for the last coinstake output (default: 0)</source>
-        <translation type="obsolete">Использовать для coinstake транзакций ключи из пула (по умолчанию: 0)</translation>
-    </message>
-    <message>
-        <source>Which key derivation method to use by default (default: sha512)</source>
-        <translation type="obsolete">Выбор функции для создания ключа шифрования (по умолчанию: sha512)</translation>
-    </message>
-    <message>
         <location line="+12"/>
         <source>Invalid -tor address: &apos;%s&apos;</source>
         <translation>Неверный адрес -tor: &apos;%s&apos;</translation>
index 41883d0..d9ed8da 100644 (file)
@@ -376,8 +376,10 @@ bool CTxDB::LoadBlockIndexGuts()
             CDiskBlockIndex diskindex;
             ssValue >> diskindex;
 
+            uint256 blockHash = diskindex.GetBlockHash();
+
             // Construct block index object
-            CBlockIndex* pindexNew = InsertBlockIndex(diskindex.GetBlockHash());
+            CBlockIndex* pindexNew = InsertBlockIndex(blockHash);
             pindexNew->pprev          = InsertBlockIndex(diskindex.hashPrev);
             pindexNew->pnext          = InsertBlockIndex(diskindex.hashNext);
             pindexNew->nFile          = diskindex.nFile;
@@ -397,7 +399,7 @@ bool CTxDB::LoadBlockIndexGuts()
             pindexNew->nNonce         = diskindex.nNonce;
 
             // Watch for genesis block
-            if (pindexGenesisBlock == NULL && diskindex.GetBlockHash() == (!fTestNet ? hashGenesisBlock : hashGenesisBlockTestNet))
+            if (pindexGenesisBlock == NULL && blockHash == (!fTestNet ? hashGenesisBlock : hashGenesisBlockTestNet))
                 pindexGenesisBlock = pindexNew;
 
             if (!pindexNew->CheckIndex())
index 5be8753..a52a230 100644 (file)
@@ -319,8 +319,10 @@ bool CTxDB::LoadBlockIndex()
         CDiskBlockIndex diskindex;
         ssValue >> diskindex;
 
+        uint256 blockHash = diskindex.GetBlockHash();
+
         // Construct block index object
-        CBlockIndex* pindexNew    = InsertBlockIndex(diskindex.GetBlockHash());
+        CBlockIndex* pindexNew    = InsertBlockIndex(blockHash);
         pindexNew->pprev          = InsertBlockIndex(diskindex.hashPrev);
         pindexNew->pnext          = InsertBlockIndex(diskindex.hashNext);
         pindexNew->nFile          = diskindex.nFile;
@@ -340,7 +342,7 @@ bool CTxDB::LoadBlockIndex()
         pindexNew->nNonce         = diskindex.nNonce;
 
         // Watch for genesis block
-        if (pindexGenesisBlock == NULL && diskindex.GetBlockHash() == hashGenesisBlock)
+        if (pindexGenesisBlock == NULL && blockHash == (!fTestNet ? hashGenesisBlock : hashGenesisBlockTestNet))
             pindexGenesisBlock = pindexNew;
 
         if (!pindexNew->CheckIndex()) {
index 5894dca..3c28c0a 100644 (file)
@@ -1627,19 +1627,6 @@ bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int
         // Set output amount
         if (txNew.vout.size() == 3)
         {
-            // Should we use keys from pool for the last coinstake output?
-            if (fStakeUsePooledKeys)
-            {
-                CReserveKey reservekey((CWallet*) &keystore);
-
-                // Replace current key with the new one
-                txNew.vout[2].SetNull();
-                txNew.vout[2].scriptPubKey << reservekey.GetReservedKey() << OP_CHECKSIG;
-
-                // Remove key from pool
-                reservekey.KeepKey();
-            }
-
             txNew.vout[1].nValue = ((nCredit - nMinFee) / 2 / CENT) * CENT;
             txNew.vout[2].nValue = nCredit - nMinFee - txNew.vout[1].nValue;
         }