Skip to content
This repository has been archived by the owner on Oct 7, 2024. It is now read-only.

Commit

Permalink
Made it so the miner doesn't stop after finding a block. This is impo…
Browse files Browse the repository at this point in the history
…rtant to keep nodes progressing in case of forks due to missing sub blocks
  • Loading branch information
kiltsonfire committed Feb 16, 2023
1 parent a05ba89 commit e0e96ee
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
@@ -35,7 +35,7 @@ type Miner struct {

// Blake3pow consensus engine used to seal a block
engine *blake3pow.Blake3pow

// Current header to mine
header *types.Header

@@ -46,7 +46,7 @@ type Miner struct {
updateCh chan *types.Header

// Channel to submit completed work
resultCh chan *types.Header
resultCh chan *types.Header

// Track previous block number for pretty printing
previousNumber [common.HierarchyDepth]uint64
@@ -119,9 +119,9 @@ func main() {
engine: blake3Engine,
sliceClients: connectToSlice(config),
header: types.EmptyHeader(),
updateCh: make(chan *types.Header, resultQueueSize),
updateCh: make(chan *types.Header, resultQueueSize),
resultCh: make(chan *types.Header, resultQueueSize),
previousNumber: [common.HierarchyDepth]uint64{0,0,0},
previousNumber: [common.HierarchyDepth]uint64{0, 0, 0},
}
log.Println("Starting Quai cpu miner in location ", config.Location)
m.fetchPendingHeader()
@@ -132,7 +132,7 @@ func main() {
<-exit
}

func (m *Miner) client(ctx int) *ethclient.Client {return m.sliceClients[ctx]}
func (m *Miner) client(ctx int) *ethclient.Client { return m.sliceClients[ctx] }

// subscribePendingHeader subscribes to the head of the mining nodes in order to pass
// the most up to date block to the miner within the manager.
@@ -182,7 +182,7 @@ func (m *Miner) miningLoop() error {
// Interrupt previous sealing operation
interrupt()
stopCh = make(chan struct{})
number := [common.HierarchyDepth]uint64{header.NumberU64(common.PRIME_CTX),header.NumberU64(common.REGION_CTX),header.NumberU64(common.ZONE_CTX)}
number := [common.HierarchyDepth]uint64{header.NumberU64(common.PRIME_CTX), header.NumberU64(common.REGION_CTX), header.NumberU64(common.ZONE_CTX)}
primeStr := fmt.Sprint(number[common.PRIME_CTX])
regionStr := fmt.Sprint(number[common.REGION_CTX])
zoneStr := fmt.Sprint(number[common.ZONE_CTX])
@@ -199,8 +199,9 @@ func (m *Miner) miningLoop() error {
}
log.Println("Mining Block: ", fmt.Sprintf("[%s %s %s]", primeStr, regionStr, zoneStr), "location", header.Location(), "difficulty", header.DifficultyArray())
}
m.previousNumber = [common.HierarchyDepth]uint64{header.NumberU64(common.PRIME_CTX),header.NumberU64(common.REGION_CTX),header.NumberU64(common.ZONE_CTX)}
m.previousNumber = [common.HierarchyDepth]uint64{header.NumberU64(common.PRIME_CTX), header.NumberU64(common.REGION_CTX), header.NumberU64(common.ZONE_CTX)}
header.SetTime(uint64(time.Now().Unix()))
m.header = header
if err := m.engine.Seal(header, m.resultCh, stopCh); err != nil {
log.Println("Block sealing failed", "err", err)
}
@@ -211,15 +212,15 @@ func (m *Miner) miningLoop() error {
// WatchHashRate is a simple method to watch the hashrate of our miner and log the output.
func (m *Miner) hashratePrinter() {
ticker := time.NewTicker(60 * time.Second)
toSiUnits := func (hr float64) (float64, string) {
toSiUnits := func(hr float64) (float64, string) {
reduced := hr
order := 0
for {
if reduced >= 1000 {
reduced /= 1000
order += 3
} else {
break;
break
}
}
switch order {
@@ -275,7 +276,9 @@ func (m *Miner) resultLoop() error {
if order <= common.ZONE_CTX {
go m.sendMinedHeader(common.ZONE_CTX, header, &wg)
}
m.updateCh <- m.header
}

}
}

0 comments on commit e0e96ee

Please sign in to comment.