MCPcopy Index your code
hub / github.com/CovenantSQL/CovenantSQL / ComputeBlockNonce

Method ComputeBlockNonce

pow/cpuminer/miner.go:66–102  ·  view source on GitHub ↗

ComputeBlockNonce find nonce make HashBlock() match the MiningBlock Difficulty from the startNonce if interrupted or stopped highest difficulty nonce will be sent to the NonceCh HACK(auxten): make calculation parallel.

(
	block MiningBlock,
	startNonce Uint256,
	difficulty int,
)

Source from the content-addressed store, hash-verified

64// if interrupted or stopped highest difficulty nonce will be sent to the NonceCh
65// HACK(auxten): make calculation parallel.
66func (miner *CPUMiner) ComputeBlockNonce(
67 block MiningBlock,
68 startNonce Uint256,
69 difficulty int,
70) (err error) {
71
72 var (
73 bestNonce NonceInfo
74 )
75 for i := startNonce; ; i.Inc() {
76 select {
77 case <-block.Stop:
78 log.Info("stop block nonce job")
79 block.NonceChan <- bestNonce
80 return errors.New("mining job stopped")
81 case <-miner.quit:
82 log.Info("stop block nonce worker")
83 block.NonceChan <- bestNonce
84 return errors.New("miner interrupted")
85 default:
86 currentHash := HashBlock(block.Data, i)
87 currentDifficulty := currentHash.Difficulty()
88 if currentDifficulty >= difficulty {
89 bestNonce.Difficulty = currentDifficulty
90 bestNonce.Nonce = i
91 bestNonce.Hash.SetBytes(currentHash[:])
92 block.NonceChan <- bestNonce
93 return
94 }
95 if currentDifficulty > bestNonce.Difficulty {
96 bestNonce.Difficulty = currentDifficulty
97 bestNonce.Nonce = i
98 bestNonce.Hash.SetBytes(currentHash[:])
99 }
100 }
101 }
102}

Callers 8

GetPubKeyNonceFunction · 0.95
nonceLoopFunction · 0.95
TestCPUMiner_HashBlockFunction · 0.95
createLocalNodesFunction · 0.95
createNodesWithPublicKeyFunction · 0.80

Calls 6

InfoFunction · 0.92
HashBlockFunction · 0.85
IncMethod · 0.80
SetBytesMethod · 0.80
NewMethod · 0.65
DifficultyMethod · 0.45

Tested by 6

TestCPUMiner_HashBlockFunction · 0.76
createLocalNodesFunction · 0.76
createNodesWithPublicKeyFunction · 0.64