(shardIdx uint64, block eth.L1BlockRef)
| 340 | } |
| 341 | |
| 342 | func (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. |
| 368 | func (w *worker) taskLoop(taskCh chan *taskItem) { |
no test coverage detected