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: single miner endpoint. #274

Merged
merged 14 commits into from
Dec 10, 2020
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@

dcrpool is a stratum decred mining pool. It currently supports:

* Obelisk DCR1 (default port: 5551)
* Innosilicon D9 (default port: 5552, supported firmware: [D9_20180602_094459.swu](https://github.com/decred/dcrpool/releases/download/v1.1.0-rc1/D9_20180602_094459.swu))
* Antminer DR3 (default port: 5553)
* Antminer DR5 (default port: 5554)
* Whatsminer D1 (default port: 5555)
* Obelisk DCR1 (supported firmware: [obelisk-sc1-v1.3.2.img](https://mining.obelisk.tech/downloads/firmware/obelisk-sc1-v1.3.2.img))
* Innosilicon D9 (supported firmware: [d9_20190521_071217.swu](http://www.innosilicon.com.cn/download/d9_20190521_071217.swu))
* Antminer DR3 (supported firmware: [Antminer-DR3-201907161805-410M.tar.gz](https://file12.bitmain.com/shop-product/firmware/Antminer%20DR3/Firmware/007201907271437364778LxDsS1k06AF/Antminer-DR3-201907161805-410M.tar.gz))
* Antminer DR5 (supported firmware: [Antminer-DR5-201907161801-600M.tar.gz](https://file12.bitmain.com/shop-product/firmware/Antminer%20DR5/Firmware/00720190727142534231Ato7d2300650/Antminer-DR5-201907161801-600M.tar.gz))
* Whatsminer D1 (supported firmware: [upgrade-whatsminer-h6-20190404.18.zip](https://github.com/decred/dcrpool/files/5651882/upgrade-whatsminer-h6-20190404.18.zip))

The default port all supported miners connect to the pool via is `:5550`.
The pool can be configured to mine in solo pool mode or as a publicly available
mining pool. Solo pool mode represents a private mining pool operation where
all connected miners to the pool are owned by the pool administrator. For this
Expand Down
3 changes: 2 additions & 1 deletion cmd/miner/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (m *Miner) authenticate() error {
// subscribe sends a stratum miner subscribe message.
func (m *Miner) subscribe() error {
id := m.nextID()
req := pool.SubscribeRequest(&id, "cpuminer", version(), m.notifyID)
req := pool.SubscribeRequest(&id, "cpuminer", minerVersion(), m.notifyID)
err := m.encoder.Encode(req)
if err != nil {
return err
Expand Down Expand Up @@ -284,6 +284,7 @@ func (m *Miner) process(ctx context.Context) {
m.extraNonce2Size = extraNonce2Size
m.notifyID = notifyID
m.subscribed = true
log.Trace("Miner successfully subscribed.")

case pool.Submit:
accepted, sErr, err := pool.ParseSubmitWorkResponse(resp)
Expand Down
7 changes: 6 additions & 1 deletion cmd/miner/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,16 @@ var (
appBuild = "dev"
)

// minerVersion returns the version of the miner per semantic versioning.
func minerVersion() string {
return fmt.Sprintf("%d.%d.%d", appMajor, appMinor, appPatch)
}

// version returns the application version as a properly formed string per the
// semantic versioning 2.0.0 spec (http://semver.org/).
func version() string {
// Start with the major, minor, and patch versions.
version := fmt.Sprintf("%d.%d.%d", appMajor, appMinor, appPatch)
version := minerVersion()

// Append pre-release version if there is one. The hyphen called for
// by the semantic versioning spec is automatically appended and should
Expand Down
27 changes: 9 additions & 18 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,7 @@ const (
defaultGUIPort = 8080
defaultGUIDir = "gui"
defaultUseLEHTTPS = false
defaultCPUPort = 5550
defaultDCR1Port = 5551
defaultD9Port = 5552
defaultDR3Port = 5553
defaultDR5Port = 5554
defaultD1Port = 5555
defaultMinerPort = 5550
defaultDesignation = "YourPoolNameHere"
defaultMaxConnectionsPerHost = 100 // 100 connected clients per host
defaultWalletAccount = 0
Expand All @@ -64,6 +59,8 @@ const (
defaultPGUser = "dcrpooluser"
defaultPGPass = "12345"
defaultPGDBName = "dcrpooldb"
defaultMonitorCycle = time.Minute * 2
defaultMaxUpgradeTries = 10
)

var (
Expand Down Expand Up @@ -126,12 +123,7 @@ type config struct {
Designation string `long:"designation" ini-name:"designation" description:"The designated codename for this pool. Customises the logo in the top toolbar."`
MaxConnectionsPerHost uint32 `long:"maxconnperhost" ini-name:"maxconnperhost" description:"The maximum number of connections allowed per host."`
Profile string `long:"profile" ini-name:"profile" description:"Enable HTTP profiling on given [addr:]port -- NOTE port must be between 1024 and 65536"`
CPUPort uint32 `long:"cpuport" ini-name:"cpuport" description:"CPU miner connection port."`
D9Port uint32 `long:"d9port" ini-name:"d9port" description:"Innosilicon D9 connection port."`
DR3Port uint32 `long:"dr3port" ini-name:"dr3port" description:"Antminer DR3 connection port."`
DR5Port uint32 `long:"dr5port" ini-name:"dr5port" description:"Antminer DR5 connection port."`
D1Port uint32 `long:"d1port" ini-name:"d1port" description:"Whatsminer D1 connection port."`
DCR1Port uint32 `long:"dcr1port" ini-name:"dcr1port" description:"Obelisk DCR1 connection port."`
MinerPort uint32 `long:"minerport" ini-name:"minerport" description:"Miner connection port."`
CoinbaseConfTimeout time.Duration `long:"conftimeout" ini-name:"conftimeout" description:"The duration to wait for coinbase confirmations."`
GenCertsOnly bool `long:"gencertsonly" ini-name:"gencertsonly" description:"Only generate needed TLS key pairs and terminate."`
UsePostgres bool `long:"postgres" ini-name:"postgres" description:"Use postgres database instead of bolt."`
Expand All @@ -141,6 +133,8 @@ type config struct {
PGPass string `long:"postgrespass" ini-name:"postgrespass" description:"Password for postgres authentication."`
PGDBName string `long:"postgresdbname" ini-name:"postgresdbname" description:"Postgres database name."`
PurgeDB bool `long:"purgedb" ini-name:"purgedb" description:"Wipes all existing data on startup for a postgres backend. This intended for simnet testing purposes only."`
MonitorCycle time.Duration `long:"monitorcycle" ini-name:"monitorcycle" description:"Time spent monitoring a mining client for possible upgrades."`
MaxUpgradeTries uint32 `long:"maxupgradetries" ini-name:"maxupgradetries" description:"Maximum consecuctive miner monitoring and upgrade tries."`
poolFeeAddrs []dcrutil.Address
dcrdRPCCerts []byte
net *params
Expand Down Expand Up @@ -367,12 +361,7 @@ func loadConfig() (*config, []string, error) {
WalletTLSKey: defaultWalletTLSKeyFile,
Designation: defaultDesignation,
MaxConnectionsPerHost: defaultMaxConnectionsPerHost,
CPUPort: defaultCPUPort,
D9Port: defaultD9Port,
DR3Port: defaultDR3Port,
DR5Port: defaultDR5Port,
D1Port: defaultD1Port,
DCR1Port: defaultDCR1Port,
MinerPort: defaultMinerPort,
WalletAccount: defaultWalletAccount,
CoinbaseConfTimeout: defaultCoinbaseConfTimeout,
UsePostgres: defaultUsePostgres,
Expand All @@ -381,6 +370,8 @@ func loadConfig() (*config, []string, error) {
PGUser: defaultPGUser,
PGPass: defaultPGPass,
PGDBName: defaultPGDBName,
MonitorCycle: defaultMonitorCycle,
MaxUpgradeTries: defaultMaxUpgradeTries,
}

// Service options which are only added on Windows.
Expand Down
53 changes: 6 additions & 47 deletions dcrpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,46 +50,6 @@ func newPool(db pool.Database, cfg *config) (*miningPool, error) {
powLimit := cfg.net.PowLimit
powLimitF, _ := new(big.Float).SetInt(powLimit).Float64()
iterations := math.Pow(2, 256-math.Floor(math.Log2(powLimitF)))
addPort := func(ports map[string]uint32, key string, entry uint32) error {
var match bool
var miner string
for m, port := range ports {
if port == entry {
match = true
miner = m
break
}
}
if match {
return fmt.Errorf("%s and %s share port %d", key, miner, entry)
}
ports[key] = entry
return nil
}

// Ensure provided miner ports are unique.
minerPorts := make(map[string]uint32)
_ = addPort(minerPorts, pool.CPU, cfg.CPUPort)
err := addPort(minerPorts, pool.InnosiliconD9, cfg.D9Port)
if err != nil {
return nil, err
}
err = addPort(minerPorts, pool.AntminerDR3, cfg.DR3Port)
if err != nil {
return nil, err
}
err = addPort(minerPorts, pool.AntminerDR5, cfg.DR5Port)
if err != nil {
return nil, err
}
err = addPort(minerPorts, pool.WhatsminerD1, cfg.D1Port)
if err != nil {
return nil, err
}
err = addPort(minerPorts, pool.ObeliskDCR1, cfg.DCR1Port)
if err != nil {
return nil, err
}

hcfg := &pool.HubConfig{
DB: db,
Expand All @@ -102,11 +62,15 @@ func newPool(db pool.Database, cfg *config) (*miningPool, error) {
PoolFeeAddrs: cfg.poolFeeAddrs,
SoloPool: cfg.SoloPool,
NonceIterations: iterations,
MinerPorts: minerPorts,
MinerPort: cfg.MinerPort,
MaxConnectionsPerHost: cfg.MaxConnectionsPerHost,
WalletAccount: cfg.WalletAccount,
CoinbaseConfTimeout: cfg.CoinbaseConfTimeout,
MonitorCycle: cfg.MonitorCycle,
MaxUpgradeTries: cfg.MaxUpgradeTries,
}

var err error
p.hub, err = pool.NewHub(p.cancel, hcfg)
if err != nil {
return nil, fmt.Errorf("failed to initialize hub: %v", err)
Expand Down Expand Up @@ -182,10 +146,6 @@ func newPool(db pool.Database, cfg *config) (*miningPool, error) {
if err != nil {
return nil, err
}
err = p.hub.Listen()
if err != nil {
return nil, err
}

csrfSecret, err := p.hub.CSRFSecret()
if err != nil {
Expand All @@ -206,7 +166,7 @@ func newPool(db pool.Database, cfg *config) (*miningPool, error) {
Designation: cfg.Designation,
PoolFee: cfg.PoolFee,
CSRFSecret: csrfSecret,
MinerPorts: minerPorts,
MinerPort: cfg.MinerPort,
WithinLimit: p.hub.WithinLimit,
FetchLastWorkHeight: p.hub.FetchLastWorkHeight,
FetchLastPaymentInfo: p.hub.FetchLastPaymentInfo,
Expand All @@ -225,7 +185,6 @@ func newPool(db pool.Database, cfg *config) (*miningPool, error) {

p.gui, err = gui.NewGUI(gcfg)
if err != nil {
p.hub.CloseListeners()
return nil, err
}
return p, nil
Expand Down
18 changes: 9 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@ require (
github.com/decred/dcrd/crypto/blake256 v1.0.0
github.com/decred/dcrd/dcrjson/v3 v3.1.0
github.com/decred/dcrd/dcrutil/v3 v3.0.0
github.com/decred/dcrd/rpc/jsonrpc/types/v2 v2.1.0
github.com/decred/dcrd/rpcclient/v6 v6.0.0
github.com/decred/dcrd/rpc/jsonrpc/types/v2 v2.3.0
github.com/decred/dcrd/rpcclient/v6 v6.0.2
github.com/decred/dcrd/wire v1.4.0
github.com/decred/slog v1.1.0
github.com/gorilla/csrf v1.7.0
github.com/gorilla/mux v1.7.4
github.com/gorilla/sessions v1.2.0
github.com/gorilla/mux v1.8.0
github.com/gorilla/sessions v1.2.1
github.com/gorilla/websocket v1.4.2
github.com/jessevdk/go-flags v1.4.1-0.20200711081900-c17162fe8fd7
github.com/jrick/logrotate v1.0.0
github.com/kr/pretty v0.1.0 // indirect
github.com/lib/pq v1.8.0
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
go.etcd.io/bbolt v1.3.5
golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a
golang.org/x/time v0.0.0-20200416051211-89c76fbcd5d1
google.golang.org/grpc v1.32.0
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
golang.org/x/crypto v0.0.0-20201124201722-c8d3bf9c5392
golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e
google.golang.org/grpc v1.33.2
gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b // indirect
)
Loading