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.
std::string strWalletFileName;
unsigned int nNodeLifespan;
unsigned int nDerivationMethodIndex;
+bool fUseFastIndex;
enum Checkpoints::CPMode CheckpointsMode;
//////////////////////////////////////////////////////////////////////////////
" -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" +
// ********************************************************* 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");
if(strCpMode == "permissive")
CheckpointsMode = Checkpoints::PERMISSIVE;
- if(GetArg("-derivationmethod", "sha512") == "scrypt+sha512")
- nDerivationMethodIndex = 1;
+ nDerivationMethodIndex = 0;
fTestNet = GetBoolArg("-testnet");
if (fTestNet) {
int64 nTransactionFee = MIN_TX_FEE;
int64 nMinimumInputValue = MIN_TX_FEE;
-bool fStakeUsePooledKeys = false;
extern enum Checkpoints::CPMode CheckpointsMode;
//////////////////////////////////////////////////////////////////////////////
// Settings
extern int64 nTransactionFee;
extern int64 nMinimumInputValue;
-extern bool fStakeUsePooledKeys;
+extern bool fUseFastIndex;
extern unsigned int nDerivationMethodIndex;
// Minimum disk space required - used in CheckDiskSpace()
/** Used to marshal pointers into hashes for db storage. */
class CDiskBlockIndex : public CBlockIndex
{
+private:
+ uint256 blockHash;
+
public:
uint256 hashPrev;
uint256 hashNext;
{
hashPrev = 0;
hashNext = 0;
+ blockHash = 0;
}
explicit CDiskBlockIndex(CBlockIndex* pindex) : CBlockIndex(*pindex)
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;
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
{
<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: '%s'</source>
<translation>Invalid -tor address: '%s'</translation>
<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: '%s'</source>
<translation>Неверный адрес -tor: '%s'</translation>
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;
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())
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;
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()) {
// 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;
}