Browse Source

Log IP from session

pool
Sammy Libre 8 years ago
parent
commit
2441426d56
  1. 4
      go-pool/stratum/handlers.go
  2. 18
      go-pool/stratum/miner.go

4
go-pool/stratum/handlers.go

@ -80,12 +80,12 @@ func (s *StratumServer) handleSubmitRPC(cs *Session, params *SubmitParams) (*Sub @@ -80,12 +80,12 @@ func (s *StratumServer) handleSubmitRPC(cs *Session, params *SubmitParams) (*Sub
t := s.currentBlockTemplate()
if job.height != t.height {
log.Printf("Stale share for height %d from %s@%s", job.height, miner.id, miner.ip)
log.Printf("Stale share for height %d from %s@%s", job.height, miner.id, cs.ip)
atomic.AddUint64(&miner.staleShares, 1)
return nil, &ErrorReply{Code: -1, Message: "Block expired"}
}
validShare := miner.processShare(s, cs.endpoint, job, t, nonce, params.Result)
validShare := miner.processShare(s, cs, job, t, nonce, params.Result)
if !validShare {
return nil, &ErrorReply{Code: -1, Message: "Low difficulty share"}
}

18
go-pool/stratum/miner.go

@ -132,12 +132,12 @@ func (m *Miner) hashrate(estimationWindow time.Duration) float64 { @@ -132,12 +132,12 @@ func (m *Miner) hashrate(estimationWindow time.Duration) float64 {
return float64(totalShares) / float64(boundary)
}
func (m *Miner) processShare(s *StratumServer, e *Endpoint, job *Job, t *BlockTemplate, nonce string, result string) bool {
func (m *Miner) processShare(s *StratumServer, cs *Session, job *Job, t *BlockTemplate, nonce string, result string) bool {
r := s.rpc()
shareBuff := make([]byte, len(t.buffer))
copy(shareBuff, t.buffer)
copy(shareBuff[t.reservedOffset+4:t.reservedOffset+7], e.instanceId)
copy(shareBuff[t.reservedOffset+4:t.reservedOffset+7], cs.endpoint.instanceId)
extraBuff := new(bytes.Buffer)
binary.Write(extraBuff, binary.BigEndian, job.extraNonce)
@ -156,15 +156,15 @@ func (m *Miner) processShare(s *StratumServer, e *Endpoint, job *Job, t *BlockTe @@ -156,15 +156,15 @@ func (m *Miner) processShare(s *StratumServer, e *Endpoint, job *Job, t *BlockTe
}
if !s.config.BypassShareValidation && hex.EncodeToString(hashBytes) != result {
log.Printf("Bad hash from miner %v@%v", m.id, m.ip)
log.Printf("Bad hash from miner %v@%v", m.id, cs.ip)
atomic.AddUint64(&m.invalidShares, 1)
return false
}
hashDiff := util.GetHashDifficulty(hashBytes).Int64() // FIXME: Will return max int64 value if overflows
atomic.AddInt64(&s.roundShares, e.config.Difficulty)
atomic.AddInt64(&s.roundShares, cs.endpoint.config.Difficulty)
atomic.AddUint64(&m.validShares, 1)
m.storeShare(e.config.Difficulty)
m.storeShare(cs.endpoint.config.Difficulty)
block := hashDiff >= t.difficulty
@ -188,16 +188,16 @@ func (m *Miner) processShare(s *StratumServer, e *Endpoint, job *Job, t *BlockTe @@ -188,16 +188,16 @@ func (m *Miner) processShare(s *StratumServer, e *Endpoint, job *Job, t *BlockTe
atomic.AddUint64(&m.accepts, 1)
atomic.AddUint64(&r.Accepts, 1)
atomic.StoreInt64(&r.LastSubmissionAt, now)
log.Printf("Block %s found at height %d by miner %v@%v with ratio %.4f", blockFastHash[0:6], t.height, m.id, m.ip, ratio)
log.Printf("Block %s found at height %d by miner %v@%v with ratio %.4f", blockFastHash[0:6], t.height, m.id, cs.ip, ratio)
// Immediately refresh current BT and send new jobs
s.refreshBlockTemplate(true)
}
} else if hashDiff < e.config.Difficulty {
log.Printf("Rejected low difficulty share of %v from %v@%v", hashDiff, m.id, m.ip)
} else if hashDiff < cs.endpoint.config.Difficulty {
log.Printf("Rejected low difficulty share of %v from %v@%v", hashDiff, m.id, cs.ip)
atomic.AddUint64(&m.invalidShares, 1)
return false
}
log.Printf("Valid share at difficulty %v/%v", e.config.Difficulty, hashDiff)
log.Printf("Valid share at difficulty %v/%v", cs.endpoint.config.Difficulty, hashDiff)
return true
}

Loading…
Cancel
Save