From: alex Date: Tue, 31 Dec 2013 17:04:16 +0000 (+0400) Subject: Cache scrypt hashes on disk X-Git-Tag: v0.4.4.6-nvc~1 X-Git-Url: https://git.novaco.in/?p=novacoin.git;a=commitdiff_plain;h=c0e8991ed1b482d0dab75f86e415fc63d1104d68 Cache scrypt hashes on disk 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. --- diff --git a/src/init.cpp b/src/init.cpp index 80405c9..f406c76 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -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= " + _("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= " + _("Threshold for disconnecting misbehaving peers (default: 100)") + "\n" + " -bantime= " + _("Number of seconds to keep misbehaving peers from reconnecting (default: 86400)") + "\n" + " -maxreceivebuffer= " + _("Maximum per-connection receive buffer, *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) { diff --git a/src/main.cpp b/src/main.cpp index 63700ac..7e62654 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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; ////////////////////////////////////////////////////////////////////////////// diff --git a/src/main.h b/src/main.h index ed202c4..4955be9 100644 --- a/src/main.h +++ b/src/main.h @@ -88,7 +88,7 @@ extern std::map 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(this)->blockHash = block.GetHash(); + + return blockHash; + } std::string ToString() const { diff --git a/src/qt/locale/bitcoin_en.ts b/src/qt/locale/bitcoin_en.ts index 93e70da..e1f22b1 100644 --- a/src/qt/locale/bitcoin_en.ts +++ b/src/qt/locale/bitcoin_en.ts @@ -2787,14 +2787,6 @@ This label turns red, if the priority is smaller than "medium". Sync checkpoints policy (default: strict) - Use pooled pubkeys for the last coinstake output (default: 0) - Use pooled pubkeys for the last coinstake output (default: 0) - - - Which key derivation method to use by default (default: sha512) - Which key derivation method to use by default (default: sha512) - - Invalid -tor address: '%s' Invalid -tor address: '%s' diff --git a/src/qt/locale/bitcoin_ru.ts b/src/qt/locale/bitcoin_ru.ts index 78d6e18..556d599 100644 --- a/src/qt/locale/bitcoin_ru.ts +++ b/src/qt/locale/bitcoin_ru.ts @@ -2799,14 +2799,6 @@ This label turns red, if the priority is smaller than "medium". Политика синхронизированных меток (по умолчанию: strict) - Use pooled pubkeys for the last coinstake output (default: 0) - Использовать для coinstake транзакций ключи из пула (по умолчанию: 0) - - - Which key derivation method to use by default (default: sha512) - Выбор функции для создания ключа шифрования (по умолчанию: sha512) - - Invalid -tor address: '%s' Неверный адрес -tor: '%s' diff --git a/src/txdb-bdb.cpp b/src/txdb-bdb.cpp index 41883d0..d9ed8da 100644 --- a/src/txdb-bdb.cpp +++ b/src/txdb-bdb.cpp @@ -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()) diff --git a/src/txdb-leveldb.cpp b/src/txdb-leveldb.cpp index 5be8753..a52a230 100644 --- a/src/txdb-leveldb.cpp +++ b/src/txdb-leveldb.cpp @@ -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()) { diff --git a/src/wallet.cpp b/src/wallet.cpp index 5894dca..3c28c0a 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -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; }