Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mining stats #230

Merged
merged 6 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
30 changes: 30 additions & 0 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,6 +314,10 @@ func (w *worker) notifyResultLoop() {
// resultLoop is a standalone goroutine to submit mining result to L1 contract.
func (w *worker) resultLoop() {
defer w.wg.Done()
errorCache := make([]miningError, 0)
totalSubmitted := 0
ticker := time.NewTicker(1 * time.Minute)
syntrust marked this conversation as resolved.
Show resolved Hide resolved
defer ticker.Stop()
for {
select {
case <-w.resultCh:
Expand All @@ -312,7 +332,9 @@ func (w *worker) resultLoop() {
*result,
w.config,
)
totalSubmitted++
if err != nil {
errorCache = append(errorCache, miningError{result.startShardId, result.blockNumber, err})
syntrust marked this conversation as resolved.
Show resolved Hide resolved
w.lg.Error("Failed to submit mined result", "shard", result.startShardId, "block", result.blockNumber, "error", err.Error())
}
if txHash != (common.Hash{}) {
Expand All @@ -336,6 +358,14 @@ func (w *worker) resultLoop() {
}
// optimistically check next result if exists
w.notifyResultLoop()
case <-ticker.C:
if len(errorCache) > 0 {
log.Error("Mining stats", "totalSubmitted", totalSubmitted, "totalErrors", len(errorCache), "lastError", errorCache[len(errorCache)-1])
} 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
Loading