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

miner time control #607

Merged
merged 4 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 4 additions & 0 deletions cmd/miner/common/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ type OptionalConfig struct {
Freqs string `long:"freqs" description:"freq settings" default-mask:"1000,200|"`
BaseDiff uint `long:"base_diff" description:"base_diff settings,default 4G" default-mask:"224"`
UartPath string `long:"uart_path" description:"uarts path split with ," default-mask:"/dev/ttyS1"`
WindowSize int `long:"windowsize" description:"windows size" default-mask:"10"`
BlockPerTime int `long:"blockpertime" description:"block per time" default-mask:"1"`
}

type PoolConfig struct {
Expand Down Expand Up @@ -204,6 +206,8 @@ func LoadConfig() (*GlobalConfig, []string, error) {
TaskForceStop: true,
ForceSolo: false,
NumOfChips: 14,
WindowSize: 10,
BlockPerTime: 1,
}

// Create the home directory if it doesn't already exist.
Expand Down
6 changes: 4 additions & 2 deletions cmd/miner/core/device.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/**
/*
*
Qitmeer
james
*/
Expand All @@ -7,10 +8,11 @@ package core
import (
"context"
"fmt"
"github.com/Qitmeer/qng/cmd/miner/common"
"math"
"sync"
"time"

"github.com/Qitmeer/qng/cmd/miner/common"
)

type BaseDevice interface {
Expand Down
17 changes: 17 additions & 0 deletions cmd/miner/symbols/lib/robot.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ type QitmeerRobot struct {
PendingLock sync.Mutex
SubmitLock sync.Mutex
WsClient *client.Client
SubmitCount int
SubmitStart time.Time
}

func (this *QitmeerRobot) GetPow(i int, ctx context.Context, uart_path string, allCount uint64) core.BaseDevice {
Expand Down Expand Up @@ -205,6 +207,7 @@ func (this *QitmeerRobot) NotifyWork(r bool) {
func (this *QitmeerRobot) SubmitWork() {
common.MinerLoger.Info("listen submit block server")
this.Wg.Add(1)
this.SubmitStart = time.Now()
go func() {
defer this.Wg.Done()
str := ""
Expand All @@ -220,12 +223,26 @@ func (this *QitmeerRobot) SubmitWork() {
this.StaleShares++
continue
}
this.SubmitCount++
this.SubmitLock.Lock()
var err error
var txID string
var height int
var blockHash string
var gbtID string
if this.SubmitCount == this.Cfg.OptionConfig.WindowSize {
allNeedTime := time.Duration(this.Cfg.OptionConfig.WindowSize * this.Cfg.OptionConfig.BlockPerTime * int(time.Second))
offset := allNeedTime - time.Since(this.SubmitStart)
common.MinerLoger.Info("Finished mining 10 blocks", "spent", time.Since(this.SubmitStart), "slept", offset)
if offset > 0 {
t1 := time.NewTimer(offset)
<-t1.C
t1.Stop()
}
this.SubmitCount = 0
this.SubmitStart = time.Now()

}
if this.Pool {
arr = strings.Split(str, "-")
// block = arr[0]
Expand Down
6 changes: 3 additions & 3 deletions services/miner/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,9 @@ func (api *PublicMinerAPI) SubmitBlockHeader(hexBlockHeader string, extraNonce *
}

func (api *PublicMinerAPI) checkSubmitLimit() error {
if time.Since(api.miner.stats.LastestSubmit) < SubmitInterval {
return fmt.Errorf("Submission interval Limited:%s < %s\n", time.Since(api.miner.stats.LastestSubmit), SubmitInterval)
}
// if time.Since(api.miner.stats.LastestSubmit) < SubmitInterval {
// return fmt.Errorf("Submission interval Limited:%s < %s\n", time.Since(api.miner.stats.LastestSubmit), SubmitInterval)
// }
return nil
}

Expand Down
Loading