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

add Submission frequency #627

Merged
merged 1 commit into from
Mar 13, 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
36 changes: 17 additions & 19 deletions cmd/miner/symbols/lib/robot.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ type QitmeerRobot struct {
PendingLock sync.Mutex
SubmitLock sync.Mutex
WsClient *client.Client
SubmitCount int
SubmitStart time.Time
LastSubmit time.Time
}

func (this *QitmeerRobot) GetPow(i int, ctx context.Context, uart_path string, allCount uint64) core.BaseDevice {
Expand Down Expand Up @@ -183,6 +182,11 @@ func (this *QitmeerRobot) ListenWork() {
}

func (this *QitmeerRobot) NotifyWork(r bool) {
if time.Since(this.LastSubmit) < time.Duration(this.Cfg.OptionConfig.TaskInterval)*time.Millisecond {
<-time.After(time.Since(this.LastSubmit))
this.NotifyWork(this.Work.Get())
return
}
if r {
validDeviceCount := 0
for _, dev := range this.Devices {
Expand All @@ -207,7 +211,6 @@ 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 @@ -223,27 +226,22 @@ func (this *QitmeerRobot) SubmitWork() {
this.StaleShares++
continue
}
this.SubmitCount++

this.SubmitLock.Lock()
if time.Since(this.LastSubmit) < time.Duration(this.Cfg.OptionConfig.TaskInterval)*time.Millisecond {
this.SubmitLock.Unlock()
<-time.After(time.Since(this.LastSubmit))
this.NotifyWork(this.Work.Get())
continue
}
this.LastSubmit = time.Now()
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))
spent := time.Since(this.SubmitStart)
offset := allNeedTime - spent
common.MinerLoger.Info(fmt.Sprintf("Finished mining %d blocks", this.Cfg.OptionConfig.WindowSize), "spent", spent, "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 Expand Up @@ -317,8 +315,8 @@ func (this *QitmeerRobot) SubmitWork() {
}, 1, func() {
})

common.MinerLoger.Info(fmt.Sprintf("Submit block, block hash=%s , height=%d",
blockHash, height))
common.MinerLoger.Info(fmt.Sprintf("Submit block, block hash=%s , height=%d , next submit will after %s",
blockHash, height, this.LastSubmit.Add(time.Duration(this.Cfg.OptionConfig.TaskInterval)*time.Millisecond).Format(time.RFC3339)))
this.PendingLock.Unlock()
} else {
this.ValidShares++
Expand Down
2 changes: 1 addition & 1 deletion cmd/miner/symbols/lib/work.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (this *QitmeerWork) Get() bool {
this.Block.Target = fmt.Sprintf("%064x", pow.CompactToBig(header.Difficulty))
this.Block.GBTID = this.Rpc.GbtID
common.LatestGBTID = this.Rpc.GbtID
common.MinerLoger.Info(fmt.Sprintf("getRemoteBlockTemplate , target :%s , GBTID:%d", this.Block.Target, this.Rpc.GbtID))
common.MinerLoger.Trace(fmt.Sprintf("getRemoteBlockTemplate , target :%s , GBTID:%d", this.Block.Target, this.Rpc.GbtID))
return true
}
}
Expand Down
Loading