-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
executable file
·130 lines (110 loc) · 3.69 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package main
import (
"flag"
"fmt"
"log"
"math"
"os"
"strconv"
"strings"
"github.com/robvanmieghem/go-opencl/cl"
"github.com/consensus-ai/sentient-miner/algorithms/sentient"
"github.com/consensus-ai/sentient-miner/mining"
)
// Version is the released version string of sentient-miner
var Version = "v0.1.2"
var intensity = 16
var devicesTypesForMining = cl.DeviceTypeAll
func main() {
log.SetOutput(os.Stdout)
printVersion := flag.Bool("v", false, "Show version and exit")
noCPU := flag.Bool("nocpu", false, "If set, don't use the CPU for mining. Uses all devices by default")
flag.IntVar(&intensity, "I", intensity, "Intensity")
host := flag.String("url", "localhost:9910", "daemon or server host and port, for stratum servers, use `stratum+tcp://<host>:<port>`")
pooluser := flag.String("user", "payoutaddress.rigname", "username, most stratum servers take this in the form [payoutaddress].[rigname]")
excludedDevices := flag.String("E", "", "Exclude devices: comma separated list of device numbers")
flag.Parse()
if *printVersion {
fmt.Println("sentient-miner version", Version)
os.Exit(0)
}
if *noCPU {
devicesTypesForMining = cl.DeviceTypeGPU
}
globalItemSize := int(math.Exp2(float64(intensity)))
platforms, err := cl.GetPlatforms()
if err != nil {
log.Panic(err)
}
clDevices := make([]*cl.Device, 0, 4)
for _, platform := range platforms {
log.Println("Platform", platform.Name())
platormDevices, err := cl.GetDevices(platform, devicesTypesForMining)
if err != nil {
log.Println(err)
}
log.Println(len(platormDevices), "device(s) found:")
for i, device := range platormDevices {
log.Println(i, "-", device.Type(), "-", device.Name())
clDevices = append(clDevices, device)
}
}
if len(clDevices) == 0 {
log.Println("No suitable OpenCL devices found")
os.Exit(1)
}
//Filter the excluded devices
miningDevices := make(map[int]*cl.Device)
for i, device := range clDevices {
if deviceExcludedForMining(i, *excludedDevices) {
continue
}
miningDevices[i] = device
}
nrOfMiningDevices := len(miningDevices)
var hashRateReportsChannel = make(chan *mining.HashRateReport, nrOfMiningDevices*10)
var miner mining.Miner
log.Println("Starting sentient mining")
c := sentient.NewClient(*host, *pooluser, Version)
miner = &sentient.Miner{
ClDevices: miningDevices,
HashRateReports: hashRateReportsChannel,
Intensity: intensity,
GlobalItemSize: globalItemSize,
Client: c,
}
miner.Mine()
socketEndpoint, ok := os.LookupEnv("SENTIENT_MINER_CURRENT_HASHRATE_ENDPOINT")
if !ok {
socketEndpoint = ":5555"
}
hashRatesSocketFrequency := 1 // 1 second
if socketFrequencyStr, ok := os.LookupEnv("SENTIENT_MINER_CURRENT_HASHRATE_FREQUENCY"); ok {
if i64, err := strconv.ParseInt(socketFrequencyStr, 10, 32); err == nil {
hashRatesSocketFrequency = int(i64)
}
}
stdOutSink := mining.NewHashRateStdOutSink()
socketSink := mining.NewHashRateSocketSink(socketEndpoint, hashRatesSocketFrequency)
//Start printing out the hashrates of the different gpu's
hashRateReports := make(map[int]float64)
for {
//No need to print at every hashreport, we have time
for i := 0; i < nrOfMiningDevices; i++ {
report := <-hashRateReportsChannel
hashRateReports[report.MinerID] = report.HashRate
}
stdOutSink.SetCurrentHashRates(hashRateReports)
socketSink.SetCurrentHashRates(hashRateReports)
}
}
//deviceExcludedForMining checks if the device is in the exclusion list
func deviceExcludedForMining(deviceID int, excludedDevices string) bool {
excludedDevicesList := strings.Split(excludedDevices, ",")
for _, excludedDevice := range excludedDevicesList {
if strconv.Itoa(deviceID) == excludedDevice {
return true
}
}
return false
}