Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multi: various improvements #297

Merged
merged 8 commits into from
Jan 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,25 @@ adminpass=adminpass
guidir=/home/gui
```

The configuration above uses a [Bolt database](https://github.com/etcd-io/bbolt).
To switch to a [Postgres database](https://www.postgresql.org/) additional config
options will be needed, refer to [postgres.md](./docs/postgres.md).

### Example output of a solo pool startup

```no-highlight
dcrpool --configfile=pool.conf --homedir=/tmp/dcrpool-harness/pool
2020-12-22 20:10:31.120 [INF] POOL: Maximum work submission generation time at pool difficulty is 28s.
2020-12-22 20:10:31.129 [INF] POOL: Solo pool mode active.
2020-12-22 20:10:31.149 [INF] MP: Version: 1.1.0+dev
2020-12-22 20:10:31.149 [INF] MP: Runtime: Go version go1.15.6
2020-12-22 20:10:31.149 [INF] MP: Home dir: /tmp/dcrpool-harness/pool
2020-12-22 20:10:31.149 [INF] MP: Started dcrpool.
2020-12-22 20:10:31.149 [INF] GUI: Starting GUI server on port 8080 (https)
2020-12-22 20:10:31.149 [INF] MP: Creating profiling server listening on 127.0.0.1:6060
2020-12-22 20:10:31.150 [INF] POOL: listening on :5550
```

### Example of a mining pool configuration

```no-highlight
Expand All @@ -133,7 +152,27 @@ adminpass=adminpass
guidir=/home/gui
```

Refer to [config descriptions](config.go) for more detail.
The configuration above uses a [Bolt database](https://github.com/etcd-io/bbolt).
To switch to a [Postgres database](https://www.postgresql.org/) additional config
options will be needed, refer to [postgres.md](./docs/postgres.md).

### Example output of a mining pool startup

```no-highlight
dcrpool --configfile=pool.conf --homedir=/tmp/dcrpool-harness/pool
2020-12-22 19:57:45.795 [INF] POOL: Maximum work submission generation time at pool difficulty is 20s.
2020-12-22 19:57:45.816 [INF] POOL: Payment method is PPLNS.
2020-12-22 19:57:45.916 [INF] MP: Version: 1.1.0+dev
2020-12-22 19:57:45.916 [INF] MP: Runtime: Go version go1.15.6
2020-12-22 19:57:45.916 [INF] MP: Creating profiling server listening on 127.0.0.1:6060
2020-12-22 19:57:45.916 [INF] MP: Home dir: /tmp/dcrpool-harness/pool
2020-12-22 19:57:45.917 [INF] MP: Started dcrpool.
2020-12-22 19:57:45.917 [INF] GUI: Starting GUI server on port 8080 (https)
2020-12-22 19:57:45.932 [INF] POOL: listening on :5550
```

Refer to [config descriptions](config.go) for more detail.


## Wallet accounts

Expand Down
43 changes: 25 additions & 18 deletions cmd/miner/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,29 +125,25 @@ func (m *Miner) keepAlive(ctx context.Context) {
poolAddr := strings.Replace(m.config.Pool, "stratum+tcp", "", 1)
conn, err := net.Dial("tcp", poolAddr)
if err != nil {
log.Errorf("unable to connect to %s: %v", m.config.Pool, err)
continue
}

m.conn = conn
m.encoder = json.NewEncoder(m.conn)
m.reader = bufio.NewReader(m.conn)
err = m.subscribe()
if err != nil {
log.Errorf("unable to subscribe miner: %v", err)
continue
}

err = m.authenticate()
if err != nil {
log.Errorf("unable to authenticate miner: %v", err)
continue
}
log.Debugf("miner connected to %s", poolAddr)

m.connectedMtx.Lock()
m.connected = true
m.connectedMtx.Unlock()

log.Debugf("miner reconnected to %s", poolAddr)
err = m.subscribe()
if err != nil {
log.Errorf("unable to subscribe miner: %v", err)
continue
}
}
}
}
Expand Down Expand Up @@ -214,7 +210,10 @@ func (m *Miner) process(ctx context.Context) {
for {
select {
case <-ctx.Done():
m.conn.Close()
if m.conn != nil {
m.conn.Close()
}

m.wg.Done()
return

Expand Down Expand Up @@ -246,26 +245,27 @@ func (m *Miner) process(ctx context.Context) {

switch method {
case pool.Authorize:
status, errStr, err := pool.ParseAuthorizeResponse(resp)
status, sErr, err := pool.ParseAuthorizeResponse(resp)
if err != nil {
log.Errorf("parse authorize response error: %v", err)
m.cancel()
continue
}

if errStr != nil {
log.Errorf("authorize error: %s", errStr)
if sErr != nil {
log.Errorf("authorize error: %v", sErr)
m.cancel()
continue
}

if !status {
log.Error("unable to authorize request for miner")
log.Error("authorization request failed for miner")
m.cancel()
continue
}

m.authorized = true

log.Trace("Miner successfully authorized.")

case pool.Subscribe:
Expand All @@ -284,6 +284,14 @@ func (m *Miner) process(ctx context.Context) {
m.extraNonce2Size = extraNonce2Size
m.notifyID = notifyID
m.subscribed = true

err = m.authenticate()
if err != nil {
log.Errorf("unable to authenticate miner: %v", err)
m.cancel()
continue
}

log.Trace("Miner successfully subscribed.")

case pool.Submit:
Expand All @@ -301,8 +309,7 @@ func (m *Miner) process(ctx context.Context) {
}

if sErr != nil {
log.Errorf("stratum mining.submit error: [%d, %s, %s]",
sErr.Code, sErr.Message, sErr.Traceback)
log.Errorf("mining.submit error: %v", sErr)
continue
}

Expand Down
27 changes: 27 additions & 0 deletions cmd/miner/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,33 @@ func loadConfig() (*config, []string, error) {
}
}

if cfg.Pool == "" {
str := "%s: the pool address cannot be an empty string"
err := fmt.Errorf(str, funcName)
fmt.Fprintln(os.Stderr, err)
fmt.Fprintln(os.Stderr, usageMessage)
return nil, nil, err
}

// Check the pool addres is a valid address.
_, poolPort, err := net.SplitHostPort(cfg.Pool)
if err != nil {
str := "%s: invalid pool address, %s"
err := fmt.Errorf(str, funcName, err)
fmt.Fprintln(os.Stderr, err)
fmt.Fprintln(os.Stderr, usageMessage)
return nil, nil, err
}

// Finally, check the pool port is in range.
if port, _ := strconv.Atoi(poolPort); port < 1024 || port > 65535 {
str := "%s: profile: address %s: port must be between 1024 and 65535"
err := fmt.Errorf(str, funcName, cfg.Profile)
fmt.Fprintln(os.Stderr, err)
fmt.Fprintln(os.Stderr, usageMessage)
return nil, nil, err
}

availableCPUs := runtime.NumCPU()
if cfg.MaxProcs < 1 || cfg.MaxProcs > availableCPUs {
log.Warnf("%d is not a valid value for MaxProcs. Defaulting to %d.", cfg.MaxProcs, availableCPUs)
Expand Down
12 changes: 5 additions & 7 deletions cmd/miner/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package main

import (
"context"
"fmt"
"net/http"
"os"
"os/signal"
Expand All @@ -22,8 +21,7 @@ func main() {
// and configures it accordingly.
cfg, _, err := loadConfig()
if err != nil {
fmt.Println(err)
return
os.Exit(1)
}

runtime.GOMAXPROCS(cfg.MaxProcs)
Expand All @@ -34,15 +32,15 @@ func main() {
}
}()

// Initialize and run the client.
ctx, cancel := context.WithCancel(context.Background())
miner := NewMiner(cfg, cancel)

log.Infof("Version: %s", version())
log.Infof("Runtime: Go version %s", runtime.Version())
log.Infof("Home dir: %s", cfg.HomeDir)
log.Infof("Started miner.")

// Initialize and run the client.
ctx, cancel := context.WithCancel(context.Background())
miner := NewMiner(cfg, cancel)

if cfg.Profile != "" {
// Start the profiler.
go func() {
Expand Down
Loading