Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multi: Move update blk time to blk templ generator. #1454

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cpuminer.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ func (m *CPUMiner) solveBlock(msgBlock *wire.MsgBlock, ticker *time.Ticker, quit
return false
}

err = UpdateBlockTime(msgBlock, m.g.blockManager)
err = m.g.UpdateBlockTime(header)
if err != nil {
minrLog.Warnf("CPU miner unable to update block template "+
"time: %v", err)
Expand Down
12 changes: 5 additions & 7 deletions mining.go
Original file line number Diff line number Diff line change
Expand Up @@ -2036,23 +2036,21 @@ mempoolLoop:
// consensus rules. Finally, it will update the target difficulty if needed
// based on the new time for the test networks since their target difficulty can
// change based upon time.
func UpdateBlockTime(msgBlock *wire.MsgBlock, bManager *blockManager) error {
func (g *BlkTmplGenerator) UpdateBlockTime(header *wire.BlockHeader) error {
// The new timestamp is potentially adjusted to ensure it comes after
// the median time of the last several blocks per the chain consensus
// rules.
newTimestamp := medianAdjustedTime(bManager.chain.BestSnapshot(),
bManager.server.timeSource)
msgBlock.Header.Timestamp = newTimestamp
newTimestamp := medianAdjustedTime(g.chain.BestSnapshot(), g.timeSource)
header.Timestamp = newTimestamp

// If running on a network that requires recalculating the difficulty,
// do so now.
if activeNetParams.ReduceMinDifficulty {
difficulty, err := bManager.chain.CalcNextRequiredDifficulty(
newTimestamp)
difficulty, err := g.chain.CalcNextRequiredDifficulty(newTimestamp)
if err != nil {
return miningRuleError(ErrGettingDifficulty, err.Error())
}
msgBlock.Header.Bits = difficulty
header.Bits = difficulty
}

return nil
Expand Down
4 changes: 2 additions & 2 deletions rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -2300,7 +2300,7 @@ func (state *gbtWorkState) updateBlockTemplate(s *rpcServer, useCoinbaseValue bo
// Update the time of the block template to the current time
// while accounting for the median time of the past several
// blocks per the chain consensus rules.
err := UpdateBlockTime(msgBlock, s.server.blockManager)
err := s.generator.UpdateBlockTime(&msgBlock.Header)
if err != nil {
context := "Failed to update timestamp"
return rpcInternalError(err.Error(), context)
Expand Down Expand Up @@ -3970,7 +3970,7 @@ func handleGetWorkRequest(s *rpcServer) (interface{}, error) {
// Update the time of the block template to the current time
// while accounting for the median time of the past several
// blocks per the chain consensus rules.
err := UpdateBlockTime(msgBlock, s.server.blockManager)
err := s.generator.UpdateBlockTime(&msgBlock.Header)
if err != nil {
return nil, rpcInternalError(err.Error(),
"Failed to update block time")
Expand Down