diff --git a/ethstorage/miner/l1_mining_api.go b/ethstorage/miner/l1_mining_api.go index 32e8e70d..732c4ac9 100644 --- a/ethstorage/miner/l1_mining_api.go +++ b/ethstorage/miner/l1_mining_api.go @@ -170,7 +170,7 @@ func (m *l1MiningAPI) SubmitMinedResult(ctx context.Context, contract common.Add "profitEstimated", weiToEther(profit), "minimumProfit", weiToEther(cfg.MinimumProfit), ) - return common.Hash{}, fmt.Errorf("dropped: not enough profit") + return common.Hash{}, nil } chainID, err := m.NetworkID(ctx) diff --git a/ethstorage/miner/worker.go b/ethstorage/miner/worker.go index 62012c5e..46af37b2 100644 --- a/ethstorage/miner/worker.go +++ b/ethstorage/miner/worker.go @@ -31,6 +31,7 @@ const ( var ( minedEventSig = crypto.Keccak256Hash([]byte("MinedBlock(uint256,uint256,uint256,uint256,address,uint256)")) + errCh = make(chan miningError, 10) ) type task struct { @@ -54,6 +55,16 @@ func (t *taskItem) String() string { return fmt.Sprintf("shard: %d, thread: %d, block: %v", t.shardIdx, t.thread, t.blockNumber) } +type miningError struct { + shardIdx uint64 + block *big.Int + err error +} + +func (e miningError) String() string { + return fmt.Sprintf("shard %d: block %v: %s", e.shardIdx, e.block, e.err.Error()) +} + type result struct { blockNumber *big.Int startShardId uint64 @@ -262,6 +273,11 @@ func (w *worker) taskLoop(taskCh chan *taskItem) { case ti := <-taskCh: success, err := w.mineTask(ti) if err != nil { + select { + case errCh <- miningError{ti.shardIdx, ti.blockNumber, err}: + default: + w.lg.Warn("Sent miningError to errCh failed", "lenOfCh", len(errCh)) + } w.lg.Warn("Mine task fail", "shard", ti.shardIdx, "thread", ti.thread, "block", ti.blockNumber, "err", err.Error()) } if success { @@ -298,11 +314,6 @@ func (w *worker) notifyResultLoop() { // resultLoop is a standalone goroutine to submit mining result to L1 contract. func (w *worker) resultLoop() { defer w.wg.Done() - type miningError struct { - shardIdx uint64 - block *big.Int - err error - } errorCache := make([]miningError, 0) totalSubmitted := 0 ticker := time.NewTicker(1 * time.Minute) @@ -353,6 +364,8 @@ func (w *worker) resultLoop() { } else { log.Info("Mining stats", "totalSubmitted", totalSubmitted, "totalErrors", len(errorCache)) } + case err := <-errCh: + errorCache = append(errorCache, err) case <-w.exitCh: w.lg.Warn("Worker is exiting from result loop...") return