Skip to content

Commit 4851d09

Browse files
committed
Merge pull request #4446
209377a Use GetBlockTime() more (jtimon)
2 parents 5e1b7a2 + 209377a commit 4851d09

File tree

9 files changed

+19
-19
lines changed

9 files changed

+19
-19
lines changed

src/checkpoints.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ namespace Checkpoints {
127127
} else {
128128
double nCheapBefore = data.nTransactionsLastCheckpoint;
129129
double nExpensiveBefore = pindex->nChainTx - data.nTransactionsLastCheckpoint;
130-
double nExpensiveAfter = (nNow - pindex->nTime)/86400.0*data.fTransactionsPerDay;
130+
double nExpensiveAfter = (nNow - pindex->GetBlockTime())/86400.0*data.fTransactionsPerDay;
131131
fWorkBefore = nCheapBefore + nExpensiveBefore*fSigcheckVerificationFactor;
132132
fWorkAfter = nExpensiveAfter*fSigcheckVerificationFactor;
133133
}

src/main.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1786,7 +1786,7 @@ bool ConnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex, C
17861786

17871787
// BIP16 didn't become active until Apr 1 2012
17881788
int64_t nBIP16SwitchTime = 1333238400;
1789-
bool fStrictPayToScriptHash = (pindex->nTime >= nBIP16SwitchTime);
1789+
bool fStrictPayToScriptHash = (pindex->GetBlockTime() >= nBIP16SwitchTime);
17901790

17911791
unsigned int flags = SCRIPT_VERIFY_NOCACHE |
17921792
(fStrictPayToScriptHash ? SCRIPT_VERIFY_P2SH : SCRIPT_VERIFY_NONE);
@@ -2435,7 +2435,7 @@ bool AcceptBlockHeader(CBlockHeader& block, CValidationState& state, CBlockIndex
24352435
if (pcheckpoint && block.hashPrevBlock != (chainActive.Tip() ? chainActive.Tip()->GetBlockHash() : uint256(0)))
24362436
{
24372437
// Extra checks to prevent "fill up memory by spamming with bogus blocks"
2438-
int64_t deltaTime = block.GetBlockTime() - pcheckpoint->nTime;
2438+
int64_t deltaTime = block.GetBlockTime() - pcheckpoint->GetBlockTime();
24392439
if (deltaTime < 0)
24402440
{
24412441
return state.DoS(100, error("CheckBlockHeader() : block with timestamp before last checkpoint"),
@@ -2546,7 +2546,7 @@ bool AcceptBlock(CBlock& block, CValidationState& state, CBlockIndex** ppindex,
25462546
CDiskBlockPos blockPos;
25472547
if (dbp != NULL)
25482548
blockPos = *dbp;
2549-
if (!FindBlockPos(state, blockPos, nBlockSize+8, nHeight, block.nTime, dbp != NULL))
2549+
if (!FindBlockPos(state, blockPos, nBlockSize+8, nHeight, block.GetBlockTime(), dbp != NULL))
25502550
return error("AcceptBlock() : FindBlockPos failed");
25512551
if (dbp == NULL)
25522552
if (!WriteBlockToDisk(block, blockPos))
@@ -3144,7 +3144,7 @@ bool InitBlockIndex() {
31443144
unsigned int nBlockSize = ::GetSerializeSize(block, SER_DISK, CLIENT_VERSION);
31453145
CDiskBlockPos blockPos;
31463146
CValidationState state;
3147-
if (!FindBlockPos(state, blockPos, nBlockSize+8, 0, block.nTime))
3147+
if (!FindBlockPos(state, blockPos, nBlockSize+8, 0, block.GetBlockTime()))
31483148
return error("LoadBlockIndex() : FindBlockPos failed");
31493149
if (!WriteBlockToDisk(block, blockPos))
31503150
return error("LoadBlockIndex() : writing genesis block to disk failed");

src/pow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead
2626
// Special difficulty rule for testnet:
2727
// If the new block's timestamp is more than 2* 10 minutes
2828
// then allow mining of a min-difficulty block.
29-
if (pblock->nTime > pindexLast->nTime + Params().TargetSpacing()*2)
29+
if (pblock->GetBlockTime() > pindexLast->GetBlockTime() + Params().TargetSpacing()*2)
3030
return nProofOfWorkLimit;
3131
else
3232
{

src/qt/clientmodel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ QDateTime ClientModel::getLastBlockDate() const
8585
if (chainActive.Tip())
8686
return QDateTime::fromTime_t(chainActive.Tip()->GetBlockTime());
8787
else
88-
return QDateTime::fromTime_t(Params().GenesisBlock().nTime); // Genesis block's time of current network
88+
return QDateTime::fromTime_t(Params().GenesisBlock().GetBlockTime()); // Genesis block's time of current network
8989
}
9090

9191
double ClientModel::getVerificationProgress() const

src/rpcdump.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ Value importwallet(const Array& params, bool fHelp)
157157
if (!file.is_open())
158158
throw JSONRPCError(RPC_INVALID_PARAMETER, "Cannot open wallet dump file");
159159

160-
int64_t nTimeBegin = chainActive.Tip()->nTime;
160+
int64_t nTimeBegin = chainActive.Tip()->GetBlockTime();
161161

162162
bool fGood = true;
163163

@@ -215,7 +215,7 @@ Value importwallet(const Array& params, bool fHelp)
215215
pwalletMain->ShowProgress("", 100); // hide progress dialog in GUI
216216

217217
CBlockIndex *pindex = chainActive.Tip();
218-
while (pindex && pindex->pprev && pindex->nTime > nTimeBegin - 7200)
218+
while (pindex && pindex->pprev && pindex->GetBlockTime() > nTimeBegin - 7200)
219219
pindex = pindex->pprev;
220220

221221
if (!pwalletMain->nTimeFirstKey || nTimeBegin < pwalletMain->nTimeFirstKey)
@@ -301,7 +301,7 @@ Value dumpwallet(const Array& params, bool fHelp)
301301
file << strprintf("# Wallet dump created by Bitcoin %s (%s)\n", CLIENT_BUILD, CLIENT_DATE);
302302
file << strprintf("# * Created on %s\n", EncodeDumpTime(GetTime()));
303303
file << strprintf("# * Best block at time of backup was %i (%s),\n", chainActive.Height(), chainActive.Tip()->GetBlockHash().ToString());
304-
file << strprintf("# mined on %s\n", EncodeDumpTime(chainActive.Tip()->nTime));
304+
file << strprintf("# mined on %s\n", EncodeDumpTime(chainActive.Tip()->GetBlockTime()));
305305
file << "\n";
306306
for (std::vector<std::pair<int64_t, CKeyID> >::const_iterator it = vKeyBirth.begin(); it != vKeyBirth.end(); it++) {
307307
const CKeyID &keyid = it->second;

src/rpcmining.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ Value getblocktemplate(const Array& params, bool fHelp)
442442
result.push_back(Pair("noncerange", "00000000ffffffff"));
443443
result.push_back(Pair("sigoplimit", (int64_t)MAX_BLOCK_SIGOPS));
444444
result.push_back(Pair("sizelimit", (int64_t)MAX_BLOCK_SIZE));
445-
result.push_back(Pair("curtime", (int64_t)pblock->nTime));
445+
result.push_back(Pair("curtime", pblock->GetBlockTime()));
446446
result.push_back(Pair("bits", strprintf("%08x", pblock->nBits)));
447447
result.push_back(Pair("height", (int64_t)(pindexPrev->nHeight+1)));
448448

src/rpcrawtransaction.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, Object& entry)
9999
if (chainActive.Contains(pindex))
100100
{
101101
entry.push_back(Pair("confirmations", 1 + chainActive.Height() - pindex->nHeight));
102-
entry.push_back(Pair("time", (int64_t)pindex->nTime));
103-
entry.push_back(Pair("blocktime", (int64_t)pindex->nTime));
102+
entry.push_back(Pair("time", pindex->GetBlockTime()));
103+
entry.push_back(Pair("blocktime", pindex->GetBlockTime()));
104104
}
105105
else
106106
entry.push_back(Pair("confirmations", 0));

src/rpcwallet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ void WalletTxToJSON(const CWalletTx& wtx, Object& entry)
5050
{
5151
entry.push_back(Pair("blockhash", wtx.hashBlock.GetHex()));
5252
entry.push_back(Pair("blockindex", wtx.nIndex));
53-
entry.push_back(Pair("blocktime", (int64_t)(mapBlockIndex[wtx.hashBlock]->nTime)));
53+
entry.push_back(Pair("blocktime", mapBlockIndex[wtx.hashBlock]->GetBlockTime()));
5454
}
5555
uint256 hash = wtx.GetHash();
5656
entry.push_back(Pair("txid", hash.GetHex()));

src/wallet.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -515,8 +515,8 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFromLoadWallet)
515515
{
516516
if (mapBlockIndex.count(wtxIn.hashBlock))
517517
{
518-
unsigned int latestNow = wtx.nTimeReceived;
519-
unsigned int latestEntry = 0;
518+
int64_t latestNow = wtx.nTimeReceived;
519+
int64_t latestEntry = 0;
520520
{
521521
// Tolerate times up to the last timestamp in the wallet not more than 5 minutes into the future
522522
int64_t latestTolerated = latestNow + 300;
@@ -547,7 +547,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFromLoadWallet)
547547
}
548548
}
549549

550-
unsigned int& blocktime = mapBlockIndex[wtxIn.hashBlock]->nTime;
550+
int64_t blocktime = mapBlockIndex[wtxIn.hashBlock]->GetBlockTime();
551551
wtx.nTimeSmart = std::max(latestEntry, std::min(blocktime, latestNow));
552552
}
553553
else
@@ -889,7 +889,7 @@ int CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate)
889889

890890
// no need to read and scan block, if block was created before
891891
// our wallet birthday (as adjusted for block time variability)
892-
while (pindex && nTimeFirstKey && (pindex->nTime < (nTimeFirstKey - 7200)))
892+
while (pindex && nTimeFirstKey && (pindex->GetBlockTime() < (nTimeFirstKey - 7200)))
893893
pindex = chainActive.Next(pindex);
894894

895895
ShowProgress(_("Rescanning..."), 0); // show rescan progress in GUI as dialog or on splashscreen, if -rescan on startup
@@ -2087,7 +2087,7 @@ void CWallet::GetKeyBirthTimes(std::map<CKeyID, int64_t> &mapKeyBirth) const {
20872087

20882088
// Extract block timestamps for those keys
20892089
for (std::map<CKeyID, CBlockIndex*>::const_iterator it = mapKeyFirstBlock.begin(); it != mapKeyFirstBlock.end(); it++)
2090-
mapKeyBirth[it->first] = it->second->nTime - 7200; // block times can be 2h off
2090+
mapKeyBirth[it->first] = it->second->GetBlockTime() - 7200; // block times can be 2h off
20912091
}
20922092

20932093
bool CWallet::AddDestData(const CTxDestination &dest, const std::string &key, const std::string &value)

0 commit comments

Comments
 (0)