Skip to content

Commit

Permalink
pool: Remove code related to Obelisk DCR1.
Browse files Browse the repository at this point in the history
The Obelisk DCR1 is no longer supported since it mines blake256 and the
hash algorithm is now blake3.
  • Loading branch information
davecgh committed Sep 29, 2023
1 parent 7bd28ff commit fc2439b
Show file tree
Hide file tree
Showing 8 changed files with 7 additions and 215 deletions.
8 changes: 3 additions & 5 deletions internal/gui/assets/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,12 @@ <h1>Mining Pool Overview</h1>
</div>
<div class="carousel-text col-lg-8 col-12 px-4">
<h2>Identify the Miner</h2>
<p> The pool currently supports the miners and their associated linked firmwares listed
below:
<p>The pool currently supports the miners below:
</p>
<div class="d-flex flex-row">
<ul>
<li><a
rel="noopener noreferrer"
href="https://mining.obelisk.tech/downloads/firmware/obelisk-sc1-v1.3.2.img">Obelisk&nbsp;DCR1</a>
<li>
Coming Soon!
</li>
</ul>
</div>
Expand Down
77 changes: 0 additions & 77 deletions pool/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,13 +413,6 @@ func (c *Client) handleSubscribeRequest(req *Request, allowed bool) error {

var resp *Response
switch miner {
case ObeliskDCR1:
// The DCR1 is not fully complaint with the stratum spec.
// It uses a 4-byte extraNonce2 regardless of the
// extraNonce2Size provided.
resp = SubscribeResponse(*req.ID, nid, c.extraNonce1,
ExtraNonce2Size, nil)

default:
// The default case handles mining clients that support the
// stratum spec and respect the extraNonce2Size provided.
Expand Down Expand Up @@ -880,35 +873,6 @@ func (c *Client) process() {
}
}

// reversePrevBlockWords reverses each 4-byte word in the provided hex encoded
// previous block hash.
func reversePrevBlockWords(hashE string) string {
var buf bytes.Buffer
for i := 0; i < len(hashE); i += 8 {
_, _ = buf.WriteString(hashE[i+6 : i+8])
_, _ = buf.WriteString(hashE[i+4 : i+6])
_, _ = buf.WriteString(hashE[i+2 : i+4])
_, _ = buf.WriteString(hashE[i : i+2])
}
return buf.String()
}

// hexReversed reverses a hex string.
func hexReversed(in string) (string, error) {
const funcName = "hexReversed"
if len(in)%2 != 0 {
desc := fmt.Sprintf("%s: expected even hex input length, got %d",
funcName, len(in))
return "", errs.PoolError(errs.HexLength, desc)
}
var buf bytes.Buffer
for i := len(in) - 1; i > -1; i -= 2 {
_ = buf.WriteByte(in[i-1])
_ = buf.WriteByte(in[i])
}
return buf.String(), nil
}

// handleCPUWork prepares work for the cpu miner.
func (c *Client) handleCPUWork(req *Request) {
const miner = "CPU"
Expand All @@ -922,43 +886,6 @@ func (c *Client) handleCPUWork(req *Request) {
atomic.StoreInt64(&c.lastWorkTime, time.Now().Unix())
}

// handleObeliskDCR1Work prepares work for the Obelisk DCR1.
func (c *Client) handleObeliskDCR1Work(req *Request) {
miner := "ObeliskDCR1"
jobID, prevBlock, genTx1, genTx2, blockVersion, nBits, nTime,
cleanJob, err := ParseWorkNotification(req)
if err != nil {
log.Errorf("%s: %v", miner, err)
}

// The DCR1 requires the nBits and nTime fields of a mining.notify message
// as big endian.
nBits, err = hexReversed(nBits)
if err != nil {
log.Errorf("%s: %v for nBits", miner, err)
c.cancel()
return
}
nTime, err = hexReversed(nTime)
if err != nil {
log.Errorf("%s: %v for nTime", miner, err)
c.cancel()
return
}

prevBlockRev := reversePrevBlockWords(prevBlock)
workNotif := WorkNotification(jobID, prevBlockRev,
genTx1, genTx2, blockVersion, nBits, nTime, cleanJob)
err = c.encoder.Encode(workNotif)
if err != nil {
log.Errorf("%s: work encoding error, %v", miner, err)
c.cancel()
return
}

atomic.StoreInt64(&c.lastWorkTime, time.Now().Unix())
}

// setHashRate updates the client's hash rate.
func (c *Client) setHashRate(hash *big.Rat) {
c.hashRateMtx.Lock()
Expand Down Expand Up @@ -1125,10 +1052,6 @@ func (c *Client) send() {
c.handleCPUWork(req)
log.Tracef("%s notified of new work", id)

case ObeliskDCR1:
c.handleObeliskDCR1Work(req)
log.Tracef("%s notified of new work", id)

default:
log.Errorf("unknown miner for client: %s, "+
"message: %s", miner, req.String())
Expand Down
101 changes: 0 additions & 101 deletions pool/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package pool

import (
"bufio"
"bytes"
"context"
"encoding/json"
"errors"
Expand Down Expand Up @@ -375,43 +374,6 @@ func testClientMessageHandling(t *testing.T) {
t.Fatalf("expected %s message method, got %s", SetDifficulty, req.Method)
}

// Ensure an Obelisk DCR1 client receives a valid non-error
// response when a valid subscribe request is sent.
err = setMiner(client, ObeliskDCR1)
if err != nil {
t.Fatalf("unexpected set miner error: %v", err)
}

id++
dcr1, dcr1Version := splitMinerID(dcr1ID)
r = SubscribeRequest(&id, userAgent(dcr1, dcr1Version), "")
err = sE.Encode(r)
if err != nil {
t.Fatalf("[Encode] unexpected error: %v", err)
}
select {
case <-client.ctx.Done():
t.Fatalf("client context done: %v", err)
case data = <-recvCh:
}
msg, mType, err = IdentifyMessage(data)
if err != nil {
t.Fatalf("[IdentifyMessage] unexpected error: %v", err)
}
if mType != ResponseMessage {
t.Fatalf("expected a subscribe response message, got %v", mType)
}
resp, ok = msg.(*Response)
if !ok {
t.Fatalf("expected subsribe response with id %d, got %d", *r.ID, resp.ID)
}
if resp.ID != *r.ID {
t.Fatalf("expected subscribe response with id %d, got %d", *r.ID, resp.ID)
}
if resp.Error != nil {
t.Fatalf("expected a non-error response, got %s", resp.Error.Message)
}

// Ensure a CPU client receives a valid non-error response when a
// valid subscribe request is sent.
err = setMiner(client, CPU)
Expand Down Expand Up @@ -544,35 +506,6 @@ func testClientMessageHandling(t *testing.T) {
client.lastWorkTime)
}

// Send a work notification to an Obelisk DCR1 client.
err = setMiner(client, ObeliskDCR1)
if err != nil {
t.Fatalf("unexpected set miner error: %v", err)
}

select {
case <-client.ctx.Done():
t.Fatalf("client context done: %v", err)
case client.ch <- r:
}

// Ensure the work notification received is unique to the DCR1.
var dcr1Work []byte
select {
case <-client.ctx.Done():
t.Fatalf("client context done: %v", err)
case dcr1Work = <-recvCh:
}
if bytes.Equal(cpuWork, dcr1Work) {
t.Fatalf("expected obelisk DCR1 work to be different from cpu work")
}

// Claim a weighted share for the Obelisk DCR1.
err = client.claimWeightedShare()
if err != nil {
t.Fatalf("[claimWeightedShare (DCR1)] unexpected error: %v", err)
}

// Ensure a CPU client receives an error response when
// a malformed work submission is sent.
err = setMiner(client, CPU)
Expand Down Expand Up @@ -872,40 +805,6 @@ func testClientMessageHandling(t *testing.T) {
t.Fatalf("expected no-error work submission response, got %v", resp.Error)
}

// Ensure the pool processes Obelisk DCR1 work submissions.
err = setMiner(client, ObeliskDCR1)
if err != nil {
t.Fatalf("unexpected set miner error: %v", err)
}

id++
sub = SubmitWorkRequest(&id, "tcl", job.UUID, "00000000",
"954cee5d", "6ddf0200")
err = sE.Encode(sub)
if err != nil {
t.Fatalf("[Encode] unexpected error: %v", err)
}
var dcr1Sub []byte
select {
case <-client.ctx.Done():
t.Fatalf("client context done: %v", err)
case dcr1Sub = <-recvCh:
}
msg, mType, err = IdentifyMessage(dcr1Sub)
if err != nil {
t.Fatalf("[IdentifyMessage] unexpected error: %v", err)
}
if mType != ResponseMessage {
t.Fatalf("expected a response message, got %v", mType)
}
resp, ok = msg.(*Response)
if !ok {
t.Fatalf("unable to cast message as response")
}
if resp.ID != *sub.ID {
t.Fatalf("expected a response with id %d, got %d", *sub.ID, resp.ID)
}

// Ensure the client gets terminated if it sends an unknown message type.
id++
r = &Request{
Expand Down
2 changes: 0 additions & 2 deletions pool/difficulty.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
// Supported mining clients.
const (
CPU = "cpu"
ObeliskDCR1 = "obeliskdcr1"
NiceHashValidator = "nicehash"
)

Expand All @@ -28,7 +27,6 @@ var (
// corresponding hash rates.
minerHashes = map[string]*big.Int{
CPU: new(big.Int).SetInt64(5e3),
ObeliskDCR1: new(big.Int).SetInt64(1.2e12),
NiceHashValidator: new(big.Int).SetInt64(20e10),
}
)
Expand Down
2 changes: 1 addition & 1 deletion pool/hashdata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

func testHashData(t *testing.T) {
miner := ObeliskDCR1
const miner = CPU
extraNonce1 := "ca750c60"
ip := "127.0.0.1:5550"
now := time.Now()
Expand Down
22 changes: 0 additions & 22 deletions pool/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -604,28 +604,6 @@ func GenerateSolvedBlockHeader(headerE string, extraNonce1E string,
copy(headerEB[288:296], []byte(extraNonce1E))
copy(headerEB[296:304], []byte(extraNonce2E))

// The Obelisk DCR1 does not respect the extraNonce2Size specified in the
// mining.subscribe response sent to it. It returns a 4-byte extraNonce2
// regardless of the extraNonce2Size provided.
// The extraNonce2 value submitted is exclusively the extraNonce2.
// The nTime and nonce values submitted are big endian, they have to
// be reversed to little endian before header reconstruction.
case ObeliskDCR1:
nTimeERev, err := hexReversed(nTimeE)
if err != nil {
return nil, err
}
copy(headerEB[272:280], []byte(nTimeERev))

nonceERev, err := hexReversed(nonceE)
if err != nil {
return nil, err
}
copy(headerEB[280:288], []byte(nonceERev))

copy(headerEB[288:296], []byte(extraNonce1E))
copy(headerEB[296:304], []byte(extraNonce2E))

default:
desc := fmt.Sprintf("miner %s is unknown", miner)
return nil, errs.MsgError(errs.MinerUnknown, desc)
Expand Down
7 changes: 2 additions & 5 deletions pool/miner_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ var (
// These miner ids represent the expected identifications returned by
// supported miners in their mining.subscribe requests.

cpuID = "cpuminer/1.0.0"
dcr1ID = "cgminer/4.10.0"
nhID = "NiceHash/1.0.0"
cpuID = "cpuminer/1.0.0"
nhID = "NiceHash/1.0.0"
)

// minerIDPair represents miner subscription identification pairing
Expand All @@ -43,11 +42,9 @@ func newMinerIDPair(id string, miners ...string) *minerIDPair {
func generateMinerIDs() map[string]*minerIDPair {
ids := make(map[string]*minerIDPair)
cpu := newMinerIDPair(cpuID, CPU)
obelisk := newMinerIDPair(dcr1ID, ObeliskDCR1)
nicehash := newMinerIDPair(nhID, NiceHashValidator)

ids[cpu.id] = cpu
ids[obelisk.id] = obelisk
ids[nicehash.id] = nicehash
return ids
}
Expand Down
3 changes: 1 addition & 2 deletions pool/share.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ import (
//
// (Hash of Miner X * Weight of LHM)/ Hash of LHM
var ShareWeights = map[string]*big.Rat{
CPU: new(big.Rat).SetFloat64(1.0), // Reserved for testing.
ObeliskDCR1: new(big.Rat).SetFloat64(1.0),
CPU: new(big.Rat).SetFloat64(1.0), // Reserved for testing.
}

// shareID generates a unique share id using the provided account, creation
Expand Down

0 comments on commit fc2439b

Please sign in to comment.