Skip to content

Commit ef55e1f

Browse files
committed
Support Develop pow type
1 parent d672af7 commit ef55e1f

File tree

22 files changed

+126
-28
lines changed

22 files changed

+126
-28
lines changed

cmd/miner/common/utils.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ func DiffToTarget(diff float64, powLimit *big.Int, powType pow.PowType) (*big.In
122122
max := powLimit
123123
target := new(big.Int)
124124
if powType == pow.BLAKE2BD || powType == pow.X8R16 ||
125-
powType == pow.QITMEERKECCAK256 || powType == pow.X16RV3 || powType == pow.MEERXKECCAKV1 {
125+
powType == pow.QITMEERKECCAK256 || powType == pow.X16RV3 || powType == pow.MEERXKECCAKV1 || powType == pow.DEVELOP {
126126
target.Div(max, divisor)
127127
} else {
128128
target.Div(divisor, max)

cmd/miner/core/stratum.go

+2
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ func GetPowType(powName string) pow.PowType {
6262
return pow.CUCKATOO
6363
case "meer_crypto":
6464
return pow.MEERXKECCAKV1
65+
case "develop":
66+
return pow.DEVELOP
6567
}
6668
return pow.BLAKE2BD
6769
}

cmd/miner/symbols/lib/robot.go

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626

2727
const (
2828
POW_MEER_CRYPTO = "meer_crypto"
29+
DEVELOP = "develop"
2930
)
3031

3132
type PendingBlock struct {

cmd/miner/symbols/lib/stratum.go

+2
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ func (s *QitmeerStratum) CalcBasePowLimit() *big.Int {
125125
switch s.PowType {
126126
case pow.MEERXKECCAKV1:
127127
return new(big.Int).Sub(new(big.Int).Lsh(big.NewInt(1), s.Cfg.OptionConfig.BaseDiff), big.NewInt(1))
128+
case pow.DEVELOP:
129+
return new(big.Int).Sub(new(big.Int).Lsh(big.NewInt(1), s.Cfg.OptionConfig.BaseDiff), big.NewInt(1))
128130
}
129131
return params.MainNetParams.PowConfig.Blake2bdPowLimit
130132
}

cmd/miner/symbols/lib/work.go

+2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ func (this *QitmeerWork) GetPowType() pow.PowType {
3939
switch this.Cfg.NecessaryConfig.Pow {
4040
case POW_MEER_CRYPTO:
4141
return pow.MEERXKECCAKV1
42+
case DEVELOP:
43+
return pow.DEVELOP
4244
default:
4345
return pow.BLAKE2BD
4446
}

config/config.go

-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ type Config struct {
6363
GBTNotify []string `long:"gbtnotify" description:"HTTP URL list to be notified of new block template"`
6464
ObsoleteHeight int `long:"obsoleteheight" description:"What is the maximum allowable height of block obsolescence for submission"`
6565
SubmitNoSynced bool `long:"allowsubmitwhennotsynced" description:"Allow the node to accept blocks from RPC while not synced (this flag is mainly used for testing)"`
66-
NoPowCheck bool `long:"nopowcheck" description:"Enable no pow check for debug node"`
6766

6867
//WebSocket support
6968
RPCMaxWebsockets int `long:"rpcmaxwebsockets" description:"Max number of RPC websocket connections"`

core/blockchain/process.go

-3
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,6 @@ func (b *BlockChain) ProcessBlock(block *types.SerializedBlock, flags BehaviorFl
4747
return nil, false, fmt.Errorf("Already exists in the queue:%s", block.Hash().String())
4848
}
4949
b.processQueueMap.Store(bh, nil)
50-
if b.consensus.Config().NoPowCheck {
51-
flags |= BFNoPoWCheck
52-
}
5350
msg := processMsg{block: block, flags: flags, result: make(chan *processResult), source: source}
5451
b.msgChan <- &msg
5552
result := <-msg.result

core/blockchain/validate.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ func (b *BlockChain) checkBlockHeaderContext(block *types.SerializedBlock, prevN
751751

752752
header := &block.Block().Header
753753
if !flags.Has(BFFastAdd) {
754-
if !flags.Has(BFNoPoWCheck) {
754+
if !b.params.IsDevelopPow() {
755755
instance := pow.GetInstance(header.Pow.GetPowType(), 0, []byte{})
756756
instance.SetMainHeight(pow.MainHeight(prevNode.GetHeight() + 1))
757757
instance.SetParams(b.params.PowConfig)

core/types/pow/config.go

+3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ type PowConfig struct {
3737
MeerXKeccakV1PowLimit *big.Int
3838
MeerXKeccakV1PowLimitBits uint32
3939

40+
DevelopPowLimit *big.Int
41+
DevelopPowLimitBits uint32
42+
4043
// cuckoo difficulty calc params min difficulty
4144
CuckarooMinDifficulty uint32
4245
CuckaroomMinDifficulty uint32

core/types/pow/develop.go

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// Copyright (c) 2017-2020 The qitmeer developers
2+
// license that can be found in the LICENSE file.
3+
// Reference resources of rust bitVector
4+
package pow
5+
6+
import (
7+
"encoding/binary"
8+
"github.com/Qitmeer/qng/common/hash"
9+
"github.com/Qitmeer/qng/core/json"
10+
"math/big"
11+
)
12+
13+
type Develop struct {
14+
Pow
15+
}
16+
17+
func (this *Develop) GetPowResult() json.PowResult {
18+
return json.PowResult{
19+
PowName: PowMapString[this.GetPowType()].(string),
20+
PowType: uint8(this.GetPowType()),
21+
Nonce: this.GetNonce(),
22+
ProofData: nil,
23+
}
24+
}
25+
26+
func (this *Develop) Verify(headerData []byte, blockHash hash.Hash, targetDiffBits uint32) error {
27+
return nil
28+
}
29+
30+
func (this *Develop) GetNextDiffBig(weightedSumDiv *big.Int, oldDiffBig *big.Int, currentPowPercent *big.Int) *big.Int {
31+
return oldDiffBig
32+
}
33+
34+
func (this *Develop) GetSafeDiff(cur_reduce_diff uint64) *big.Int {
35+
limitBits := this.params.DevelopPowLimitBits
36+
limitBitsBig := CompactToBig(limitBits)
37+
return limitBitsBig
38+
}
39+
40+
// compare the target
41+
// wether target match the target diff
42+
func (this *Develop) CompareDiff(newTarget *big.Int, target *big.Int) bool {
43+
return newTarget.Cmp(target) <= 0
44+
}
45+
46+
// pow proof data
47+
func (this *Develop) Bytes() PowBytes {
48+
r := make(PowBytes, 0)
49+
//write pow type 1 byte
50+
r = append(r, []byte{byte(this.PowType)}...)
51+
// write nonce 8 bytes
52+
n := make([]byte, 8)
53+
binary.LittleEndian.PutUint64(n, this.Nonce)
54+
r = append(r, n...)
55+
//write ProofData 169 bytes
56+
r = append(r, this.ProofData[:]...)
57+
return PowBytes(r)
58+
}
59+
60+
// pow proof data
61+
func (this *Develop) BlockData() PowBytes {
62+
l := len(this.Bytes())
63+
return PowBytes(this.Bytes()[:l-PROOFDATA_LENGTH])
64+
}
65+
66+
// not support
67+
func (this *Develop) FindSolver(headerData []byte, blockHash hash.Hash, targetDiffBits uint32) bool {
68+
if err := this.Verify(headerData, blockHash, targetDiffBits); err == nil {
69+
return true
70+
}
71+
return false
72+
}

core/types/pow/difficultymanager/kaspad.go

-3
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,6 @@ func (m *kaspadDiff) RequiredDifficulty(block model.Block, newBlockTime time.Tim
115115

116116
// RequiredDifficultyByWindows returns the difficulty required for some block
117117
func (dm *kaspadDiff) RequiredDifficultyByWindows(targetsWindow blockWindow) (uint32, error) {
118-
if len(targetsWindow) < 1 || dm.con.Config().NoPowCheck {
119-
return dm.genesisBits, nil
120-
}
121118
return dm.requiredDifficultyFromTargetsWindow(targetsWindow)
122119
}
123120

core/types/pow/difficultymanager/meer.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func (m *meerDiff) RequiredDifficulty(block model.Block, newBlockTime time.Time,
103103
baseTarget := powInstance.GetSafeDiff(0)
104104
originCurrentBlock := block
105105
// Genesis block.
106-
if block == nil || m.con.Config().NoPowCheck {
106+
if block == nil {
107107
return pow.BigToCompact(baseTarget), nil
108108
}
109109

core/types/pow/ipow.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const (
3030
QITMEERKECCAK256 PowType = 6
3131
CRYPTONIGHT PowType = 7
3232
MEERXKECCAKV1 PowType = 8
33+
DEVELOP PowType = 9
3334
)
3435

3536
var PowMapString = map[PowType]interface{}{
@@ -42,6 +43,7 @@ var PowMapString = map[PowType]interface{}{
4243
QITMEERKECCAK256: "qitmeer_keccak256",
4344
CRYPTONIGHT: "cryptonight",
4445
MEERXKECCAKV1: "meer_xkeccak_v1",
46+
DEVELOP: "develop",
4547
}
4648

4749
func GetPowName(powType PowType) string {
@@ -102,7 +104,7 @@ type Pow struct {
102104
mainHeight MainHeight
103105
}
104106

105-
//get pow instance
107+
// get pow instance
106108
func GetInstance(powType PowType, nonce uint64, proofData []byte) IPow {
107109
var instance IPow
108110
switch powType {
@@ -124,6 +126,8 @@ func GetInstance(powType PowType, nonce uint64, proofData []byte) IPow {
124126
instance = &CryptoNight{}
125127
case MEERXKECCAKV1:
126128
instance = &MeerXKeccakV1{}
129+
case DEVELOP:
130+
instance = &Develop{}
127131
default:
128132
instance = &Blake2bd{}
129133
}
@@ -161,7 +165,7 @@ func (this *Pow) GetProofData() string {
161165
return this.ProofData.String()
162166
}
163167

164-
//set proof data except pow type
168+
// set proof data except pow type
165169
func (this *Pow) SetProofData(data []byte) {
166170
l := len(data)
167171
copy(this.ProofData[0:l], data[:])
@@ -173,7 +177,7 @@ func (this *Pow) PowPercent() *big.Int {
173177
return targetPercent
174178
}
175179

176-
//check pow is available
180+
// check pow is available
177181
func (this *Pow) CheckAvailable() bool {
178182
return this.params.GetPercentByHeightAndType(this.mainHeight, this.PowType) > 0
179183
}

node/api.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,11 @@ func NewPublicBlockChainAPI(node *QitmeerFull) *PublicBlockChainAPI {
6060
func (api *PublicBlockChainAPI) GetNodeInfo() (interface{}, error) {
6161
best := api.node.GetBlockChain().BestSnapshot()
6262
node := api.node.GetBlockChain().BlockDAG().GetBlock(&best.Hash)
63-
powNodes := api.node.GetBlockChain().GetCurrentPowDiff(node, pow.MEERXKECCAKV1)
63+
powType := pow.MEERXKECCAKV1
64+
if params.ActiveNetParams.Params.IsDevelopPow() {
65+
powType = pow.DEVELOP
66+
}
67+
powNodes := api.node.GetBlockChain().GetCurrentPowDiff(node, powType)
6468
ret := &json.InfoNodeResult{
6569
ID: api.node.GetPeerServer().PeerID().String(),
6670
Version: int32(1000000*version.Major + 10000*version.Minor + 100*version.Patch),
@@ -70,7 +74,7 @@ func (api *PublicBlockChainAPI) GetNodeInfo() (interface{}, error) {
7074
TimeOffset: int64(api.node.GetBlockChain().TimeSource().Offset().Seconds()),
7175
Connections: int32(len(api.node.GetPeerServer().Peers().Active())),
7276
PowDiff: &json.PowDiff{
73-
CurrentDiff: getDifficultyRatio(powNodes, api.node.node.Params, pow.MEERXKECCAKV1),
77+
CurrentDiff: getDifficultyRatio(powNodes, api.node.node.Params, powType),
7478
},
7579
Network: params.ActiveNetParams.Name,
7680
Confirmations: meerdag.StableConfirmations,
@@ -127,7 +131,8 @@ func getDifficultyRatio(target *big.Int, params *params.Params, powType pow.PowT
127131
powType == pow.QITMEERKECCAK256 ||
128132
powType == pow.X8R16 ||
129133
powType == pow.X16RV3 ||
130-
powType == pow.CRYPTONIGHT {
134+
powType == pow.CRYPTONIGHT ||
135+
powType == pow.DEVELOP {
131136
if target.Cmp(big.NewInt(0)) > 0 {
132137
difficulty = new(big.Rat).SetFrac(base, target)
133138
}

params/params.go

+12
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,18 @@ func (p *Params) HasTax() bool {
294294
return false
295295
}
296296

297+
func (p *Params) IsDevelopPow() bool {
298+
if len(p.PowConfig.Percent) <= 0 {
299+
return false
300+
}
301+
for _, pt := range p.PowConfig.Percent {
302+
if _, ok := pt[pow.DEVELOP]; ok {
303+
return true
304+
}
305+
}
306+
return false
307+
}
308+
297309
var (
298310
// ErrDuplicateNet describes an error where the parameters for a network
299311
// could not be set due to the network already being a standard

params/params_mainnet.go

+2
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ var MainNetParams = Params{
6666
CuckatooMinDifficulty: 0x1300000 * 4,
6767
MeerXKeccakV1PowLimit: mainPowLimit,
6868
MeerXKeccakV1PowLimitBits: 0x1b0fffff,
69+
DevelopPowLimit: privNetPowLimit,
70+
DevelopPowLimitBits: 0x207fffff,
6971
Percent: map[pow.MainHeight]pow.PercentItem{
7072
pow.MainHeight(0): {
7173
pow.MEERXKECCAKV1: 100,

params/params_mixnet.go

+2
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ var MixNetParams = Params{
7272
CryptoNightPowLimitBits: 0x2003ffff,
7373
MeerXKeccakV1PowLimit: testMixNetPowLimit,
7474
MeerXKeccakV1PowLimitBits: 0x1f0198f2,
75+
DevelopPowLimit: privNetPowLimit,
76+
DevelopPowLimitBits: 0x207fffff,
7577
//hash ffffffffffffffff000000000000000000000000000000000000000000000000 corresponding difficulty is 48 for edge bits 24
7678
// Uniform field type uint64 value is 48 . bigToCompact the uint32 value
7779
// 24 edge_bits only need hash 1*4 times use for privnet if GPS is 2. need 50 /2 * 2 ≈ 1min find once

params/params_privnet.go

+2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ var PrivNetParams = Params{
5555
QitmeerKeccak256PowLimitBits: 0x207fffff,
5656
MeerXKeccakV1PowLimit: privNetPowLimit,
5757
MeerXKeccakV1PowLimitBits: 0x207fffff,
58+
DevelopPowLimit: privNetPowLimit,
59+
DevelopPowLimitBits: 0x207fffff,
5860
//hash ffffffffffffffff000000000000000000000000000000000000000000000000 corresponding difficulty is 48 for edge bits 24
5961
// Uniform field type uint64 value is 48 . bigToCompact the uint32 value
6062
// 24 edge_bits only need hash 1 times use for privnet if GPS is 2. need 50 /2 = 25s find once

params/params_testnet.go

+2
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ var TestNetParams = Params{
5959
QitmeerKeccak256PowLimitBits: 0x0, // compact from of testNetPowLimit 0
6060
MeerXKeccakV1PowLimit: testNetPowLimit,
6161
MeerXKeccakV1PowLimitBits: 0x1f0198f2, // compact from of testNetPowLimit (2^242-1)
62+
DevelopPowLimit: privNetPowLimit,
63+
DevelopPowLimitBits: 0x207fffff,
6264
//hash ffffffffffffffff000000000000000000000000000000000000000000000000 corresponding difficulty is 48 for edge bits 24
6365
// Uniform field type uint64 value is 48 . bigToCompact the uint32 value
6466
// 24 edge_bits only need hash 1*4 times use for privnet if GPS is 2. need 50 /2 * 4 = 1min find once

services/common/flags.go

-7
Original file line numberDiff line numberDiff line change
@@ -632,12 +632,6 @@ var (
632632
Value: false,
633633
Destination: &cfg.SubmitNoSynced,
634634
},
635-
&cli.BoolFlag{
636-
Name: "nopowcheck",
637-
Usage: "Enable no pow check for debug node",
638-
Value: false,
639-
Destination: &cfg.NoPowCheck,
640-
},
641635
}
642636
)
643637

@@ -674,7 +668,6 @@ func DefaultConfig(homeDir string) *config.Config {
674668
RPCPass: defaultRPCPass,
675669
ObsoleteHeight: defaultObsoleteHeight,
676670
SubmitNoSynced: false,
677-
NoPowCheck: false,
678671
}
679672
if len(homeDir) > 0 {
680673
hd, err := filepath.Abs(homeDir)

services/miner/cpuworker.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ out:
307307
continue
308308
}
309309
start := time.Now()
310-
if w.miner.cfg.NoPowCheck {
310+
if params.ActiveNetParams.Params.IsDevelopPow() {
311311
time.Sleep(params.ActiveNetParams.Params.TargetTimePerBlock)
312312
}
313313
sb := w.solveBlock()
@@ -414,9 +414,6 @@ func (w *CPUWorker) solveBlock() *types.Block {
414414
instance.SetParams(params.ActiveNetParams.Params.PowConfig)
415415
hashesCompleted += 2
416416
header.Pow = instance
417-
if w.miner.cfg.NoPowCheck {
418-
return block
419-
}
420417
if header.Pow.FindSolver(header.BlockData(), header.BlockHash(), header.Difficulty) {
421418
w.updateHashes <- hashesCompleted
422419
return block

services/miner/miner.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -935,6 +935,10 @@ func (m *Miner) CheckSubMainChainTip(parents []*hash.Hash) error {
935935
}
936936

937937
func NewMiner(consensus model.Consensus, policy *mining.Policy, txpool *mempool.TxPool, p2pSer model.P2PService) *Miner {
938+
powType := pow.MEERXKECCAKV1
939+
if params.ActiveNetParams.Params.IsDevelopPow() {
940+
powType = pow.DEVELOP
941+
}
938942
m := Miner{
939943
msgChan: make(chan interface{}),
940944
quit: make(chan struct{}),
@@ -943,7 +947,7 @@ func NewMiner(consensus model.Consensus, policy *mining.Policy, txpool *mempool.
943947
sigCache: consensus.SigCache(),
944948
txpool: txpool,
945949
timeSource: consensus.MedianTimeSource(),
946-
powType: pow.MEERXKECCAKV1,
950+
powType: powType,
947951
events: consensus.Events(),
948952
coinbaseFlags: mining.CoinbaseFlagsStatic,
949953
consensus: consensus,

0 commit comments

Comments
 (0)