MCPcopy Create free account
hub / github.com/ethstorage/es-node / updateDifficulty

Method updateDifficulty

ethstorage/miner/worker.go:342–365  ·  view source on GitHub ↗
(shardIdx uint64, block eth.L1BlockRef)

Source from the content-addressed store, hash-verified

340}
341
342func (w *worker) updateDifficulty(shardIdx uint64, block eth.L1BlockRef) (*big.Int, error) {
343 info, err := w.l1API.GetMiningInfo(
344 context.Background(),
345 w.storageMgr.ContractAddress(),
346 shardIdx,
347 )
348 if err != nil {
349 w.lg.Warn("Failed to get es mining info", "error", err.Error())
350 return nil, err
351 }
352 w.lg.Info("Mining info retrieved", "shard", shardIdx, "block", block.Number, "difficulty", info.Difficulty, "lastMineTime", info.LastMineTime, "proofsSubmitted", info.BlockMined)
353
354 if block.Time <= info.LastMineTime {
355 return nil, errors.New("minedTs too small")
356 }
357 reqDiff := new(big.Int).Div(maxUint256, expectedDiff(
358 block.Time-info.LastMineTime,
359 info.Difficulty,
360 w.config.Cutoff,
361 w.config.DiffAdjDivisor,
362 w.config.MinimumDiff,
363 ))
364 return reqDiff, nil
365}
366
367// taskLoop is a standalone goroutine to fetch mining task from the task channel and mine the task.
368func (w *worker) taskLoop(taskCh chan *taskItem) {

Callers 1

newWorkLoopMethod · 0.95

Calls 4

expectedDiffFunction · 0.85
GetMiningInfoMethod · 0.65
ContractAddressMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected