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 improvement #238

Merged
merged 4 commits into from
Mar 15, 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{}, nil
return common.Hash{}, errDropped
}

chainID, err := m.NetworkID(ctx)
Expand Down
19 changes: 13 additions & 6 deletions ethstorage/miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package miner

import (
"context"
"errors"
"fmt"
"math/big"
"sync"
Expand Down Expand Up @@ -32,6 +33,7 @@ const (
var (
minedEventSig = crypto.Keccak256Hash([]byte("MinedBlock(uint256,uint256,uint256,uint256,address,uint256)"))
errCh = make(chan miningError, 10)
errDropped = errors.New("dropped: not enough profit")
)

type task struct {
Expand Down Expand Up @@ -314,8 +316,8 @@ func (w *worker) notifyResultLoop() {
// resultLoop is a standalone goroutine to submit mining result to L1 contract.
func (w *worker) resultLoop() {
defer w.wg.Done()
var succeeded, dropped int
errorCache := make([]miningError, 0)
totalSubmitted := 0
ticker := time.NewTicker(1 * time.Minute)
defer ticker.Stop()
for {
Expand All @@ -332,10 +334,15 @@ func (w *worker) resultLoop() {
*result,
w.config,
)
totalSubmitted++
if err != nil {
errorCache = append(errorCache, miningError{result.startShardId, result.blockNumber, err})
w.lg.Error("Failed to submit mined result", "shard", result.startShardId, "block", result.blockNumber, "error", err.Error())
if err == errDropped {
dropped++
} else {
errorCache = append(errorCache, miningError{result.startShardId, result.blockNumber, err})
w.lg.Error("Failed to submit mined result", "shard", result.startShardId, "block", result.blockNumber, "error", err.Error())
}
} else {
succeeded++
}
if txHash != (common.Hash{}) {
// waiting for tx confirmation or timeout
Expand All @@ -360,9 +367,9 @@ func (w *worker) resultLoop() {
w.notifyResultLoop()
case <-ticker.C:
if len(errorCache) > 0 {
log.Error("Mining stats", "totalSubmitted", totalSubmitted, "totalErrors", len(errorCache), "lastError", errorCache[len(errorCache)-1])
log.Error("Mining stats", "succeeded", succeeded, "failed", len(errorCache), "dropped", dropped, "lastError", errorCache[len(errorCache)-1])
} else {
log.Info("Mining stats", "totalSubmitted", totalSubmitted, "totalErrors", len(errorCache))
log.Info("Mining stats", "succeeded", succeeded, "failed", len(errorCache), "dropped", dropped)
}
case err := <-errCh:
errorCache = append(errorCache, err)
Expand Down
Loading