Skip to content

Commit

Permalink
Fix the dataset and light cache generation.
Browse files Browse the repository at this point in the history
  • Loading branch information
wam-rd committed Jan 4, 2024
1 parent 59e81f9 commit f19c8a5
Show file tree
Hide file tree
Showing 3 changed files with 230 additions and 31 deletions.
18 changes: 18 additions & 0 deletions cmd/karlsenminer/mineloop.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
nativeerrors "errors"
"fmt"
"math/rand"
"sync/atomic"
"time"
Expand Down Expand Up @@ -40,6 +41,7 @@ func mineLoop(client *minerClient, numberOfBlocks uint64, targetBlocksPerSecond
})

spawn("blocksLoop", func() {
fmt.Printf("blocksLoop -- log0\n")
const windowSize = 10
hasBlockRateTarget := targetBlocksPerSecond != 0
var windowTicker, blockTicker *time.Ticker
Expand Down Expand Up @@ -72,6 +74,7 @@ func mineLoop(client *minerClient, numberOfBlocks uint64, targetBlocksPerSecond
})

spawn("handleFoundBlock", func() {
fmt.Printf("handleFoundBlock -- log0\n")
for i := uint64(0); numberOfBlocks == 0 || i < numberOfBlocks; i++ {
block := <-foundBlockChan
err := handleFoundBlock(client, block)
Expand All @@ -95,8 +98,16 @@ func mineLoop(client *minerClient, numberOfBlocks uint64, targetBlocksPerSecond

func logHashRate() {
spawn("logHashRate", func() {
fmt.Printf("logHashRate -- log0\n")
//_, state, _ := templatemanager.Get()
//fmt.Printf("logHashRate -- log1\n")
lastCheck := time.Now()
for range time.Tick(logHashRateInterval) {

//fmt.Printf("logHashRate -- log2\n")
//fmt.Printf("logHashRate -- IsContextReady : %t\n", state.IsContextReady())
//fmt.Printf("logHashRate -- IsContextReady : %t\n", state.IsContextReady())

currentHashesTried := atomic.LoadUint64(&hashesTried)
currentTime := time.Now()
kiloHashesTried := float64(currentHashesTried) / 1000.0
Expand Down Expand Up @@ -137,8 +148,10 @@ func handleFoundBlock(client *minerClient, block *externalapi.DomainBlock) error

func mineNextBlock(mineWhenNotSynced bool) *externalapi.DomainBlock {
nonce := rand.Uint64() // Use the global concurrent-safe random source.
//fmt.Printf("mineNextBlock -- log0\n")
for {
nonce++
//fmt.Printf("mineNextBlock -- log1\n")
// For each nonce we try to build a block from the most up to date
// block template.
// In the rare case where the nonce space is exhausted for a specific
Expand All @@ -163,8 +176,11 @@ func getBlockForMining(mineWhenNotSynced bool) (*externalapi.DomainBlock, *pow.S
const sleepTime = 500 * time.Millisecond
const sleepTimeWhenNotSynced = 5 * time.Second

//fmt.Printf("getBlockForMining -- log0\n")

for {
tryCount++
//fmt.Printf("getBlockForMining -- log1\n")

shouldLog := (tryCount-1)%10 == 0
template, state, isSynced := templatemanager.Get()
Expand All @@ -190,6 +206,7 @@ func getBlockForMining(mineWhenNotSynced bool) (*externalapi.DomainBlock, *pow.S
func templatesLoop(client *minerClient, miningAddr util.Address, errChan chan error) {
getBlockTemplate := func() {
template, err := client.GetBlockTemplate(miningAddr.String(), "karlsenminer-"+version.Version())
fmt.Printf("Getting Block template\n")
if nativeerrors.Is(err, router.ErrTimeout) {
log.Warnf("Got timeout while requesting block template from %s: %s", client.Address(), err)
reconnectErr := client.Reconnect()
Expand All @@ -207,6 +224,7 @@ func templatesLoop(client *minerClient, miningAddr util.Address, errChan chan er
errChan <- errors.Wrapf(err, "Error getting block template from %s", client.Address())
return
}
fmt.Printf("Template SET\n")
err = templatemanager.Set(template)
if err != nil {
errChan <- errors.Wrapf(err, "Error setting block template from %s", client.Address())
Expand Down
Loading

0 comments on commit f19c8a5

Please sign in to comment.