blockchain: Remove exported CalcPastTimeMedian func.
This removes the exported CalcPastTimeMedian function from the blockchain package as it is no longer needed since the information is now available via the BestState snapshot. Also, update the only known caller of this, which is the chain state in block manager, to use the snapshot instead. In reality, now that everything the block manager chain state provides is available via the blockchain BestState snapshot, the entire thing can be removed, however that will be done in a separate to commit to keep the changes targeted.
This commit is contained in:
parent
e88f2d7bf4
commit
1cba5c8fc0
2 changed files with 3 additions and 19 deletions
|
@ -134,7 +134,7 @@ type BestState struct {
|
||||||
BlockSize uint64 // The size of the block.
|
BlockSize uint64 // The size of the block.
|
||||||
NumTxns uint64 // The number of txns in the block.
|
NumTxns uint64 // The number of txns in the block.
|
||||||
TotalTxns uint64 // The total number of txns in the chain.
|
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.
|
// 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
|
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
|
// 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
|
// 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
|
// the main chain and a list of block nodes that would need to be attached to
|
||||||
|
|
|
@ -213,12 +213,8 @@ func (b *blockManager) updateChainState(newestHash *chainhash.Hash, newestHeight
|
||||||
|
|
||||||
b.chainState.newestHash = newestHash
|
b.chainState.newestHash = newestHash
|
||||||
b.chainState.newestHeight = newestHeight
|
b.chainState.newestHeight = newestHeight
|
||||||
medianTime, err := b.chain.CalcPastMedianTime()
|
b.chainState.pastMedianTime = b.chain.BestSnapshot().MedianTime
|
||||||
if err != nil {
|
b.chainState.pastMedianTimeErr = nil
|
||||||
b.chainState.pastMedianTimeErr = err
|
|
||||||
} else {
|
|
||||||
b.chainState.pastMedianTime = medianTime
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// findNextHeaderCheckpoint returns the next checkpoint after the passed height.
|
// findNextHeaderCheckpoint returns the next checkpoint after the passed height.
|
||||||
|
|
Loading…
Reference in a new issue