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

Complete the missing commits #854

Merged
merged 20 commits into from
Dec 18, 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
8 changes: 4 additions & 4 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
# We must fetch at least the immediate parents so that if this is
# a pull request then we can checkout the head.
Expand All @@ -43,7 +43,7 @@ jobs:

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand All @@ -54,7 +54,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v1
uses: github/codeql-action/autobuild@v3

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
Expand All @@ -68,4 +68,4 @@ jobs:
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
uses: github/codeql-action/analyze@v3
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
The next generation of the Qitmeer network implementation with the plug-able VMs under the MeerDAG consensus.

### Installation
***make sure you have go-lang version `1.19.x` or above (`1.20.x` is recommended) installed on the system to build.***
***make sure you have go-lang version `1.21.x` or above (`1.22.x` is recommended) installed on the system to build.***

* Build from source
```bash
Expand Down
134 changes: 0 additions & 134 deletions cmd/miner/common/rpc.go

This file was deleted.

6 changes: 3 additions & 3 deletions cmd/miner/core/robot.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ package core

import (
"context"
"github.com/Qitmeer/qng/cmd/miner/common"
"strings"
"sync"

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

//var devicesTypesForMining = cl.DeviceTypeAll
Expand All @@ -30,13 +31,12 @@ type MinerRobot struct {
Quit context.Context
Work *Work
ClDevices []string
Rpc *common.RpcClient
Pool bool
SubmitStr chan string
UseDevices []string
}

//init GPU device
// init GPU device
func (this *MinerRobot) InitDevice() {
this.UseDevices = []string{}
if this.Cfg.OptionConfig.UseDevices != "" {
Expand Down
6 changes: 3 additions & 3 deletions cmd/miner/core/work.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ package core

import (
"context"
"sync"

"github.com/Qitmeer/qng/cmd/miner/common"
"github.com/Qitmeer/qng/core/types"
"sync"
)

const SYMBOL_PMEER = "MEER"
Expand All @@ -19,10 +20,9 @@ type BaseWork interface {
PoolSubmit(subm string) error
}

//standard work template
// standard work template
type Work struct {
Cfg *common.GlobalConfig
Rpc *common.RpcClient
Clean bool
sync.Mutex
Quit context.Context
Expand Down
12 changes: 6 additions & 6 deletions cmd/miner/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,21 @@ package main

import (
"context"
"github.com/Qitmeer/qng/cmd/miner/common"
"github.com/Qitmeer/qng/cmd/miner/core"
qitmeer "github.com/Qitmeer/qng/cmd/miner/symbols/lib"
"log"
"os"
"os/signal"
"runtime"
"strings"
"time"

"github.com/Qitmeer/qng/cmd/miner/common"
"github.com/Qitmeer/qng/cmd/miner/core"
qitmeer "github.com/Qitmeer/qng/cmd/miner/symbols/lib"
)

var robotminer core.Robot

//init the config file
// init the config file
func init() {
cfg, _, err := common.LoadConfig()
if err != nil {
Expand Down Expand Up @@ -50,15 +51,14 @@ func main() {
common.MinerLoger.Info("All services exited")
}

//get current coin miner
// get current coin miner
func GetRobot(cfg *common.GlobalConfig) core.Robot {
switch strings.ToUpper(cfg.NecessaryConfig.Symbol) {
case core.SYMBOL_PMEER:
r := &qitmeer.QitmeerRobot{}
r.Cfg = cfg
r.NeedGBT = make(chan struct{}, 1)
r.Started = uint32(time.Now().Unix())
r.Rpc = &common.RpcClient{Cfg: cfg}
r.SubmitStr = make(chan string)
r.PendingBlocks = map[string]qitmeer.PendingBlock{}
return r
Expand Down
2 changes: 1 addition & 1 deletion cmd/miner/symbols/lib/pow_meer_cpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (this *MeerCrypto) Mine(wg *sync.WaitGroup) {
}
hData := make([]byte, 128)
copy(hData[0:types.MaxBlockHeaderPayload-pow.PROOFDATA_LENGTH], this.header.BlockData())
nonce++
nonce = common.RandUint64()
this.AllDiffOneShares++
b := make([]byte, 8)
binary.LittleEndian.PutUint64(b, nonce)
Expand Down
3 changes: 1 addition & 2 deletions cmd/miner/symbols/lib/robot.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ func (this *QitmeerRobot) Run(ctx context.Context) {
common.MinerLoger.Info(fmt.Sprintf("[%s miner] start", connectName))
this.Work = QitmeerWork{}
this.Work.Cfg = this.Cfg
this.Work.Rpc = this.Rpc
this.Work.stra = this.Stratu
this.Work.Quit = this.Quit
this.Work.WorkLock = sync.Mutex{}
Expand Down Expand Up @@ -223,7 +222,6 @@ func (this *QitmeerRobot) SubmitWork() {
this.SubmitLock.Unlock()
continue
}
this.Work.LastSubmit = time.Now()

var err error
var txID string
Expand Down Expand Up @@ -266,6 +264,7 @@ func (this *QitmeerRobot) SubmitWork() {
continue
} else {
if !this.Pool { // solo
this.Work.LastSubmit = time.Now()
this.PendingBlocks[txID] = PendingBlock{
CoinbaseHash: txID,
BlockHash: blockHash,
Expand Down
28 changes: 18 additions & 10 deletions cmd/miner/symbols/lib/work.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

var ErrSameWork = fmt.Errorf("Same work, Had Submitted!")
var ErrLimitWork = fmt.Errorf("Submission interval Limited")
var hasSubmits = map[string]bool{}

type QitmeerWork struct {
core.Work
Expand All @@ -34,6 +35,8 @@ type QitmeerWork struct {
WorkLock sync.Mutex
WsClient *client.Client
LastSubmit time.Time
GbtID int64
SubmitID int64
}

func (this *QitmeerWork) GetPowType() pow.PowType {
Expand Down Expand Up @@ -72,7 +75,7 @@ func (this *QitmeerWork) Get() bool {
continue
}
if this.Block != nil && this.Block.ParentRoot == header.ParentRoot &&
(time.Now().Unix()-this.GetWorkTime) < int64(this.Cfg.OptionConfig.Timeout)*10 {
(time.Now().Unix()-this.GetWorkTime) < int64(this.Cfg.OptionConfig.TaskInterval)/1000 {
common.MinerLoger.Warn("GetRemoteGBT Repeat", "old block parent root", this.Block.ParentRoot, "current", header.ParentRoot)
//not has new work
return false
Expand All @@ -83,14 +86,14 @@ func (this *QitmeerWork) Get() bool {

// BuildBlock
func (this *QitmeerWork) BuildBlock(header *types.BlockHeader) bool {
this.Rpc.GbtID++
this.GbtID++
this.Block = &BlockHeader{}
this.Block.ParentRoot = header.ParentRoot
this.Block.WorkData = header.BlockData()
this.Block.Target = fmt.Sprintf("%064x", pow.CompactToBig(header.Difficulty))
this.Block.GBTID = this.Rpc.GbtID
common.LatestGBTID = this.Rpc.GbtID
common.MinerLoger.Debug(fmt.Sprintf("getRemoteBlockTemplate , target :%s , GBTID:%d", this.Block.Target, this.Rpc.GbtID))
this.Block.GBTID = this.GbtID
common.LatestGBTID = this.GbtID
common.MinerLoger.Debug(fmt.Sprintf("getRemoteBlockTemplate , target :%s , GBTID:%d", this.Block.Target, this.GbtID))
this.GetWorkTime = time.Now().Unix()
return true
}
Expand All @@ -99,17 +102,21 @@ func (this *QitmeerWork) BuildBlock(header *types.BlockHeader) bool {
func (this *QitmeerWork) Submit(header *types.BlockHeader, gbtID string) (string, int, error) {
this.Lock()
defer this.Unlock()
if v, ok := hasSubmits[header.ParentRoot.String()]; ok && v {
return "", 0, ErrSameWork
}

gbtIDInt64, _ := strconv.ParseInt(gbtID, 10, 64)
if this.Rpc.GbtID != gbtIDInt64 {
common.MinerLoger.Debug(fmt.Sprintf("gbt old , target :%d , current:%d", this.Rpc.GbtID, gbtIDInt64))
if this.GbtID != gbtIDInt64 {
common.MinerLoger.Debug(fmt.Sprintf("gbt old , target :%d , current:%d", this.GbtID, gbtIDInt64))
return "", 0, ErrSameWork
}
this.Rpc.SubmitID++
this.SubmitID++

id := fmt.Sprintf("miner_submit_gbtID:%s_id:%d", gbtID, this.Rpc.SubmitID)
id := fmt.Sprintf("miner_submit_gbtID:%s_id:%d", gbtID, this.SubmitID)
res, err := this.WsClient.SubmitBlockHeader(header)
if err != nil {
common.MinerLoger.Error("[submit error] " + id + " " + err.Error())
common.MinerLoger.Error("[submit error] parent root", header.ParentRoot.String(), id)
if strings.Contains(err.Error(), "The tips of block is expired") {
return "", 0, ErrSameWork
}
Expand All @@ -121,6 +128,7 @@ func (this *QitmeerWork) Submit(header *types.BlockHeader, gbtID string) (string
}
return "", 0, errors.New("[submit data failed]" + err.Error())
}
hasSubmits[header.ParentRoot.String()] = true
return res.CoinbaseTxID, int(res.Height), err
}

Expand Down
Loading
Loading