Skip to content

Commit

Permalink
Mining a work share with -3 bits
Browse files Browse the repository at this point in the history
  • Loading branch information
gameofpointers committed May 24, 2024
1 parent 7db1510 commit ed5b70b
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"log"
"math/big"

"os"
"strconv"
Expand Down Expand Up @@ -32,7 +33,9 @@ const (
)

var (
exit = make(chan bool)
exit = make(chan bool)
big2e256 = new(big.Int).Exp(big.NewInt(2), big.NewInt(256), big.NewInt(0)) // 2^256

)

type Miner struct {
Expand Down Expand Up @@ -314,6 +317,18 @@ func (m *Miner) resultLoop() {
for {
select {
case header := <-m.resultCh:
// check if the mined object is a workshare or a block
target := new(big.Int).Div(big2e256, header.Difficulty())
powHash, err := m.engine.ComputePowHash(header.WorkObjectHeader())
if err != nil {
log.Println("Error computing pow hash: ", err)
continue
}
if new(big.Int).SetBytes(powHash.Bytes()).Cmp(target) > 0 {
log.Println("Mined a work share", header.Hash())
m.sliceClients[common.ZONE_CTX].ReceiveWorkShare(context.Background(), header.WorkObjectHeader())
continue
}
_, order, err := m.engine.CalcOrder(header)
if err != nil {
log.Println("Error calculating order: ", err)
Expand Down

0 comments on commit ed5b70b

Please sign in to comment.