Skip to content

Commit

Permalink
stats more err
Browse files Browse the repository at this point in the history
  • Loading branch information
syntrust committed Mar 9, 2024
1 parent 717f2a9 commit 765ac65
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion ethstorage/miner/l1_mining_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
23 changes: 18 additions & 5 deletions ethstorage/miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 765ac65

Please sign in to comment.