diff --git a/internal/mining/bgblktmplgenerator.go b/internal/mining/bgblktmplgenerator.go index 4c05bdeccd..144be747ad 100644 --- a/internal/mining/bgblktmplgenerator.go +++ b/internal/mining/bgblktmplgenerator.go @@ -358,12 +358,8 @@ func NewBgBlkTmplGenerator(cfg *BgBlkTmplConfig) *BgBlkTmplGenerator { // UpdateBlockTime updates the timestamp in the passed header to the current // time while taking into account the median time of the last several blocks to // ensure the new time is after that time per the chain 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 (g *BgBlkTmplGenerator) UpdateBlockTime(header *wire.BlockHeader) error { - return g.tg.UpdateBlockTime(header) +func (g *BgBlkTmplGenerator) UpdateBlockTime(header *wire.BlockHeader) { + g.tg.UpdateBlockTime(header) } // sendQueueRegenEvent sends the provided regen event on the internal queue diff --git a/internal/mining/cpuminer/cpuminer.go b/internal/mining/cpuminer/cpuminer.go index bafba1a967..7a04766751 100644 --- a/internal/mining/cpuminer/cpuminer.go +++ b/internal/mining/cpuminer/cpuminer.go @@ -216,19 +216,6 @@ func (m *CPUMiner) submitBlock(block *dcrutil.Block) bool { return false } - // When the reduce min difficulty option is set it is possible that the - // required difficulty changed while a block was being solved and will - // therefore result in an error due to having the incorrect required - // difficulty set in the header. In that case, only log the error as - // debug since it is expected to happen from time to time and not really - // an error. - if m.cfg.ChainParams.ReduceMinDifficulty && - errors.Is(rErr, blockchain.ErrHighHash) { - log.Debugf("Block submitted via CPU miner rejected because of "+ - "ReduceMinDifficulty time sync failure: %v", err) - return false - } - // Other rule errors should be reported. log.Errorf("Block submitted via CPU miner rejected: %v", err) return false @@ -327,17 +314,11 @@ func (m *CPUMiner) solveBlock(ctx context.Context, header *wire.BlockHeader, sta // Non-blocking select to fall through } - err := m.g.UpdateBlockTime(header) - if err != nil { - log.Warnf("CPU miner unable to update block template "+ - "time: %v", err) - } + m.g.UpdateBlockTime(header) - // Update the bits and time in the serialized header bytes - // directly too since they might have changed. - const bitsOffset = 116 + // Update time in the serialized header bytes directly too since + // it might have changed. const timestampOffset = 136 - littleEndian.PutUint32(hdrBytes[bitsOffset:], header.Bits) timestamp := uint32(header.Timestamp.Unix()) littleEndian.PutUint32(hdrBytes[timestampOffset:], timestamp) } diff --git a/internal/mining/mining.go b/internal/mining/mining.go index 537c7d54f9..768423677d 100644 --- a/internal/mining/mining.go +++ b/internal/mining/mining.go @@ -871,19 +871,6 @@ func (g *BlkTmplGenerator) handleTooFewVoters(nextHeight int64, ts := g.medianAdjustedTime() block.Header.Timestamp = ts - // If we're on testnet, the time since this last block listed as the - // parent must be taken into consideration. - if g.cfg.ChainParams.ReduceMinDifficulty { - parentHash := topBlock.MsgBlock().Header.PrevBlock - - requiredDifficulty, err := g.cfg.CalcNextRequiredDifficulty(&parentHash, ts) - if err != nil { - return nil, makeError(ErrGettingDifficulty, err.Error()) - } - - block.Header.Bits = requiredDifficulty - } - // Recalculate the size. block.Header.Size = uint32(block.SerializeSize()) @@ -2343,27 +2330,10 @@ nextPriorityQueueItem: // UpdateBlockTime updates the timestamp in the passed header to the current // time while taking into account the median time of the last several blocks to // ensure the new time is after that time per the chain 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 (g *BlkTmplGenerator) UpdateBlockTime(header *wire.BlockHeader) error { +func (g *BlkTmplGenerator) UpdateBlockTime(header *wire.BlockHeader) { // 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 := g.medianAdjustedTime() header.Timestamp = newTimestamp - - // If running on a network that requires recalculating the difficulty, - // do so now. - if g.cfg.ChainParams.ReduceMinDifficulty { - difficulty, err := g.cfg.CalcNextRequiredDifficulty(&header.PrevBlock, - newTimestamp) - if err != nil { - return makeError(ErrGettingDifficulty, err.Error()) - } - header.Bits = difficulty - } - - return nil } diff --git a/internal/rpcserver/interface.go b/internal/rpcserver/interface.go index 3782807599..05a33aa914 100644 --- a/internal/rpcserver/interface.go +++ b/internal/rpcserver/interface.go @@ -528,7 +528,7 @@ type BlockTemplater interface { // UpdateBlockTime updates the timestamp in the passed header to the current // time while taking into account the consensus rules. - UpdateBlockTime(header *wire.BlockHeader) error + UpdateBlockTime(header *wire.BlockHeader) } // FiltererV2 provides an interface for retrieving a block's version 2 GCS diff --git a/internal/rpcserver/rpcserver.go b/internal/rpcserver/rpcserver.go index c7d410e726..3817c564a3 100644 --- a/internal/rpcserver/rpcserver.go +++ b/internal/rpcserver/rpcserver.go @@ -3771,11 +3771,7 @@ func handleGetWorkRequest(ctx context.Context, s *Server) (interface{}, error) { // consensus rules. Note that the header is copied to avoid mutating the // shared block template. headerCopy := template.Block.Header - err := bt.UpdateBlockTime(&headerCopy) - if err != nil { - context := "Failed to update block time" - return nil, rpcInternalError(err.Error(), context) - } + bt.UpdateBlockTime(&headerCopy) // Serialize the block header into a buffer large enough to hold the // the block header and the internal blake256 padding that is added and @@ -3788,7 +3784,7 @@ func handleGetWorkRequest(ctx context.Context, s *Server) (interface{}, error) { // data[144:152] --> ExtraNonce data := make([]byte, 0, getworkDataLen) buf := bytes.NewBuffer(data) - err = headerCopy.Serialize(buf) + err := headerCopy.Serialize(buf) if err != nil { context := "Failed to serialize data" return nil, rpcInternalError(err.Error(), context) diff --git a/internal/rpcserver/rpcserverhandlers_test.go b/internal/rpcserver/rpcserverhandlers_test.go index b613053f20..aadfe0d7f6 100644 --- a/internal/rpcserver/rpcserverhandlers_test.go +++ b/internal/rpcserver/rpcserverhandlers_test.go @@ -1023,12 +1023,11 @@ func (s *testTemplateSubber) PublishTemplateNtfn(templateNtfn *mining.TemplateNt // testBlockTemplater provides a mock block templater by implementing the // mining.BlockTemplater interface. type testBlockTemplater struct { - subscriptions map[*testTemplateSubber]struct{} - regenReason mining.TemplateUpdateReason - currTemplate *mining.BlockTemplate - currTemplateErr error - updateBlockTimeErr error - simulateNewNtfn bool + subscriptions map[*testTemplateSubber]struct{} + regenReason mining.TemplateUpdateReason + currTemplate *mining.BlockTemplate + currTemplateErr error + simulateNewNtfn bool } // ForceRegen asks the block templater to generate a new template immediately. @@ -1066,9 +1065,7 @@ func (b *testBlockTemplater) CurrentTemplate() (*mining.BlockTemplate, error) { // UpdateBlockTime updates the timestamp in the passed header to the current // time while taking into account the consensus rules. -func (b *testBlockTemplater) UpdateBlockTime(header *wire.BlockHeader) error { - return b.updateBlockTimeErr -} +func (b *testBlockTemplater) UpdateBlockTime(header *wire.BlockHeader) {} // testTxMempooler provides a mock mempool transaction data source by // implementing the TxMempooler interface. @@ -5765,18 +5762,6 @@ func TestHandleGetWork(t *testing.T) { }(), wantErr: true, errCode: dcrjson.ErrRPCMisc, - }, { - name: "handleGetWork: unable to update block time", - handler: handleGetWork, - cmd: &types.GetWorkCmd{}, - mockMiningState: defaultMockMiningState(), - mockBlockTemplater: func() *testBlockTemplater { - templater := defaultMockBlockTemplater() - templater.updateBlockTimeErr = errors.New("unable to update block time") - return templater - }(), - wantErr: true, - errCode: dcrjson.ErrRPCInternal.Code, }, { name: "handleGetWork: data is not equal to getworkDataLen (192 bytes)", handler: handleGetWork,