diff --git a/main.go b/main.go index f253415..97f06d4 100644 --- a/main.go +++ b/main.go @@ -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,7 +212,7 @@ 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 { @@ -219,7 +220,7 @@ func (m *Miner) hashratePrinter() { 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 } + } }