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

Fix for backend causing wrong earnings estimates #593

Merged
merged 1 commit into from
Feb 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions backend/mining.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ func (m *Backend) StartMining() bool {
cycles := 0
nhr := util.GetNetHash()
th := util.GetTipHeight()
var avgEarning float64
continueLoop := true
for continueLoop {
cycles++
Expand Down Expand Up @@ -113,8 +114,11 @@ func (m *Backend) StartMining() bool {

m.runtime.Events.Emit("networkHashRate", fmt.Sprintf("%0.2f %s", netHash, hashrateUnit))

coinsPerDay := util.GetCoinsPerDay(th)
avgEarning := float64(hr) / float64(nhr) * float64(coinsPerDay)
// Avoids wrong estimates when the backend is unavailable
if th != 0 && nhr != 0 {
coinsPerDay := util.GetCoinsPerDay(th)
avgEarning = float64(hr) / float64(nhr) * float64(coinsPerDay)
}

m.runtime.Events.Emit("avgEarnings", fmt.Sprintf("%0.2f VTC", avgEarning))

Expand Down