Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F13115645
D1441.id4124.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Subscribers
None
D1441.id4124.diff
View Options
diff --git a/src/chain.h b/src/chain.h
--- a/src/chain.h
+++ b/src/chain.h
@@ -394,7 +394,11 @@
int64_t GetBlockTimeMax() const { return int64_t(nTimeMax); }
- int64_t GetHeaderTimeReceived() const { return nTimeReceived; }
+ int64_t GetHeaderReceivedTime() const { return nTimeReceived; }
+
+ int64_t GetReceivedTimeDiff() const {
+ return GetHeaderReceivedTime() - GetBlockTime();
+ }
enum { nMedianTimeSpan = 11 };
diff --git a/src/validation.cpp b/src/validation.cpp
--- a/src/validation.cpp
+++ b/src/validation.cpp
@@ -3265,6 +3265,7 @@
pindexNew->nHeight = pindexNew->pprev->nHeight + 1;
pindexNew->BuildSkip();
}
+ pindexNew->nTimeReceived = GetTime();
pindexNew->nTimeMax =
(pindexNew->pprev
? std::max(pindexNew->pprev->nTimeMax, pindexNew->nTime)
@@ -3883,9 +3884,33 @@
// process an unrequested block if it's new and has enough work to
// advance our tip, and isn't too many blocks ahead.
bool fAlreadyHave = pindex->nStatus.hasData();
+
+ // Compare block header timestamps and received times of the block and the
+ // chaintip. If they have the same chain height, use these diffs as a
+ // tie-breaker, attempting to pick the more honestly-mined block.
+ int64_t newBlockTimeDiff = std::llabs(pindex->GetReceivedTimeDiff());
+ int64_t chainTipTimeDiff =
+ chainActive.Tip() ? std::llabs(chainActive.Tip()->GetReceivedTimeDiff())
+ : 0;
+
+ bool isSameHeightAndMoreHonestlyMined =
+ chainActive.Tip() &&
+ (pindex->nChainWork == chainActive.Tip()->nChainWork) &&
+ (newBlockTimeDiff < chainTipTimeDiff);
+ if (isSameHeightAndMoreHonestlyMined) {
+ LogPrintf("Chain tip timestamp-to-received-time difference: hash=%s, "
+ "diff=%d\n",
+ chainActive.Tip()->GetBlockHash().ToString(),
+ chainTipTimeDiff);
+ LogPrintf("New block timestamp-to-received-time difference: hash=%s, "
+ "diff=%d\n",
+ pindex->GetBlockHash().ToString(), newBlockTimeDiff);
+ }
+
bool fHasMoreWork =
(chainActive.Tip() ? pindex->nChainWork > chainActive.Tip()->nChainWork
: true);
+
// Blocks that are too out-of-order needlessly limit the effectiveness of
// pruning, because pruning will not delete block files that contain any
// blocks which are too close in height to the tip. Apply this test
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Mar 1, 11:38 (2 h, 50 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5187650
Default Alt Text
D1441.id4124.diff (2 KB)
Attached To
D1441: Add logging for block header receive time
Event Timeline
Log In to Comment