From 933cdf50e8f7539c51e7c9c545fa43a5a87ffdce Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Mon, 30 Jun 2014 10:27:44 -0500 Subject: [PATCH] Export constant for the maximum time offset. This commit creates and exports a new constant, MaxTimeOffsetSeconds, which is the maximum number of seconds a block timestamp is allowed to be ahead of the current time. Previously this value was hard coded into the consensus rule path, however it is useful better to have it defined as a constant and exported so other callers can access it. No consensus rules have been changed with this commit. --- validate.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/validate.go b/validate.go index 127e4672..ba6c9ef5 100644 --- a/validate.go +++ b/validate.go @@ -29,6 +29,11 @@ const ( // the lock time is a uint32, the max is sometime around 2106. lockTimeThreshold uint32 = 5e8 // Tue Nov 5 00:53:20 1985 UTC + // MaxTimeOffsetSeconds is the maximum number of seconds a block time + // is allowed to be ahead of the current time. This is currently 2 + // hours. + MaxTimeOffsetSeconds = 2 * 60 * 60 + // MinCoinbaseScriptLen is the minimum length a coinbase script can be. MinCoinbaseScriptLen = 2 @@ -462,8 +467,9 @@ func checkBlockSanity(block *btcutil.Block, powLimit *big.Int, flags BehaviorFla return ruleError(ErrInvalidTime, str) } - // Ensure the block time is not more than 2 hours in the future. - if header.Timestamp.After(time.Now().Add(time.Hour * 2)) { + // Ensure the block time is not too far in the future. + maxTimestamp := time.Now().Add(time.Second * MaxTimeOffsetSeconds) + if header.Timestamp.After(maxTimestamp) { str := fmt.Sprintf("block timestamp of %v is too far in the "+ "future", header.Timestamp) return ruleError(ErrTimeTooNew, str)