Changeset View
Standalone View
src/chain.h
Show First 20 Lines • Show All 124 Lines • ▼ Show 20 Lines | public: | ||||
CBlockIndex() { SetNull(); } | CBlockIndex() { SetNull(); } | ||||
CBlockIndex(const CBlockHeader &block) { | CBlockIndex(const CBlockHeader &block) { | ||||
SetNull(); | SetNull(); | ||||
nVersion = block.nVersion; | nVersion = block.nVersion; | ||||
hashMerkleRoot = block.hashMerkleRoot; | hashMerkleRoot = block.hashMerkleRoot; | ||||
nTime = block.nTime; | nTime = block.nTime; | ||||
// Default to block time if nTimeReceived is never set, which | nTimeReceived = 0; | ||||
// in effect assumes that this block is honestly mined. | |||||
// Note that nTimeReceived isn't written to disk, so blocks read from | |||||
// disk will be assumed to be honestly mined. | |||||
nTimeReceived = block.nTime; | |||||
nBits = block.nBits; | nBits = block.nBits; | ||||
nNonce = block.nNonce; | nNonce = block.nNonce; | ||||
} | } | ||||
CDiskBlockPos GetBlockPos() const { | CDiskBlockPos GetBlockPos() const { | ||||
CDiskBlockPos ret; | CDiskBlockPos ret; | ||||
if (nStatus.hasData()) { | if (nStatus.hasData()) { | ||||
ret.nFile = nFile; | ret.nFile = nFile; | ||||
Show All 25 Lines | public: | ||||
} | } | ||||
uint256 GetBlockHash() const { return *phashBlock; } | uint256 GetBlockHash() const { return *phashBlock; } | ||||
int64_t GetBlockTime() const { return int64_t(nTime); } | int64_t GetBlockTime() const { return int64_t(nTime); } | ||||
int64_t GetBlockTimeMax() const { return int64_t(nTimeMax); } | int64_t GetBlockTimeMax() const { return int64_t(nTimeMax); } | ||||
int64_t GetHeaderReceivedTime() const { return nTimeReceived; } | int64_t GetHeaderReceivedTime(bool guessUnknownTime = true) const { | ||||
deadalnix: Is there any callsite that rely on time being non zero ? | |||||
deadalnixUnsubmitted Not Done Inline ActionsIf none rely on this then just refactor. I don't think there are many callsites so it is worth investigating. deadalnix: If none rely on this then just refactor. I don't think there are many callsites so it is worth… | |||||
jasonbcoxUnsubmitted Not Done Inline ActionsNot currently. Fabien and Shae were experimenting with it in other diffs. I figure making this change allows us to continue experiments until the matter of penalizing blocks based on received time is settled. jasonbcox: Not currently. Fabien and Shae were experimenting with it in other diffs. I figure making this… | |||||
FabienAuthorUnsubmitted Done Inline ActionsI found a single case where the behaviour was changed when returning 0: in the GetReceivedTimeDiff function below which is called in AcceptBlock for logging only. Fabien: I found a single case where the behaviour was changed when returning 0: in the… | |||||
deadalnixUnsubmitted Not Done Inline ActionsAdding bool parameter is an antipattern so clearly we are not talking about anything costless here, but actually making the code worse. If there is no reason to make the code worse, then just refactor this and the one callsite. deadalnix: Adding [bool parameter is an antipattern](https://medium.com/@amlcurran/clean-code-the-curse-of… | |||||
if (guessUnknownTime && nTimeReceived == 0) { | |||||
return GetBlockTime(); | |||||
} | |||||
return nTimeReceived; | |||||
} | |||||
int64_t GetReceivedTimeDiff() const { | int64_t GetReceivedTimeDiff() const { | ||||
return GetHeaderReceivedTime() - GetBlockTime(); | return GetHeaderReceivedTime() - GetBlockTime(); | ||||
} | } | ||||
enum { nMedianTimeSpan = 11 }; | enum { nMedianTimeSpan = 11 }; | ||||
int64_t GetMedianTimePast() const { | int64_t GetMedianTimePast() const { | ||||
▲ Show 20 Lines • Show All 228 Lines • Show Last 20 Lines |
Is there any callsite that rely on time being non zero ?