diff --git a/blockchain/chain.go b/blockchain/chain.go index f838dd107..56717aaf4 100644 --- a/blockchain/chain.go +++ b/blockchain/chain.go @@ -134,7 +134,7 @@ type BestState struct { BlockSize uint64 // The size of the block. NumTxns uint64 // The number of txns in the block. TotalTxns uint64 // The total number of txns in the chain. - MedianTime time.Time // Median time as per CalcPastMedianTime. + MedianTime time.Time // Median time as per calcPastMedianTime. } // newBestState returns a new best stats instance for the given parameters. @@ -682,18 +682,6 @@ func (b *BlockChain) calcPastMedianTime(startNode *blockNode) (time.Time, error) return medianTimestamp, nil } -// CalcPastMedianTime calculates the median time of the previous few blocks -// prior to, and including, the end of the current best chain. It is primarily -// used to ensure new blocks have sane timestamps. -// -// This function is safe for concurrent access. -func (b *BlockChain) CalcPastMedianTime() (time.Time, error) { - b.chainLock.Lock() - defer b.chainLock.Unlock() - - return b.calcPastMedianTime(b.bestNode) -} - // getReorganizeNodes finds the fork point between the main chain and the passed // node and returns a list of block nodes that would need to be detached from // the main chain and a list of block nodes that would need to be attached to diff --git a/blockmanager.go b/blockmanager.go index 37967a621..16c57f309 100644 --- a/blockmanager.go +++ b/blockmanager.go @@ -213,12 +213,8 @@ func (b *blockManager) updateChainState(newestHash *chainhash.Hash, newestHeight b.chainState.newestHash = newestHash b.chainState.newestHeight = newestHeight - medianTime, err := b.chain.CalcPastMedianTime() - if err != nil { - b.chainState.pastMedianTimeErr = err - } else { - b.chainState.pastMedianTime = medianTime - } + b.chainState.pastMedianTime = b.chain.BestSnapshot().MedianTime + b.chainState.pastMedianTimeErr = nil } // findNextHeaderCheckpoint returns the next checkpoint after the passed height.