mirror of
https://github.com/kvazar-network/keva-stratum.git
synced 2025-02-09 21:46:25 +00:00
Log IP from session
This commit is contained in:
parent
d2a769e093
commit
2441426d56
@ -80,12 +80,12 @@ func (s *StratumServer) handleSubmitRPC(cs *Session, params *SubmitParams) (*Sub
|
|||||||
|
|
||||||
t := s.currentBlockTemplate()
|
t := s.currentBlockTemplate()
|
||||||
if job.height != t.height {
|
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)
|
atomic.AddUint64(&miner.staleShares, 1)
|
||||||
return nil, &ErrorReply{Code: -1, Message: "Block expired"}
|
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 {
|
if !validShare {
|
||||||
return nil, &ErrorReply{Code: -1, Message: "Low difficulty share"}
|
return nil, &ErrorReply{Code: -1, Message: "Low difficulty share"}
|
||||||
}
|
}
|
||||||
|
@ -132,12 +132,12 @@ func (m *Miner) hashrate(estimationWindow time.Duration) float64 {
|
|||||||
return float64(totalShares) / float64(boundary)
|
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()
|
r := s.rpc()
|
||||||
|
|
||||||
shareBuff := make([]byte, len(t.buffer))
|
shareBuff := make([]byte, len(t.buffer))
|
||||||
copy(shareBuff, 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)
|
extraBuff := new(bytes.Buffer)
|
||||||
binary.Write(extraBuff, binary.BigEndian, job.extraNonce)
|
binary.Write(extraBuff, binary.BigEndian, job.extraNonce)
|
||||||
@ -156,15 +156,15 @@ func (m *Miner) processShare(s *StratumServer, e *Endpoint, job *Job, t *BlockTe
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !s.config.BypassShareValidation && hex.EncodeToString(hashBytes) != result {
|
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)
|
atomic.AddUint64(&m.invalidShares, 1)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
hashDiff := util.GetHashDifficulty(hashBytes).Int64() // FIXME: Will return max int64 value if overflows
|
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)
|
atomic.AddUint64(&m.validShares, 1)
|
||||||
m.storeShare(e.config.Difficulty)
|
m.storeShare(cs.endpoint.config.Difficulty)
|
||||||
|
|
||||||
block := hashDiff >= t.difficulty
|
block := hashDiff >= t.difficulty
|
||||||
|
|
||||||
@ -188,16 +188,16 @@ func (m *Miner) processShare(s *StratumServer, e *Endpoint, job *Job, t *BlockTe
|
|||||||
atomic.AddUint64(&m.accepts, 1)
|
atomic.AddUint64(&m.accepts, 1)
|
||||||
atomic.AddUint64(&r.Accepts, 1)
|
atomic.AddUint64(&r.Accepts, 1)
|
||||||
atomic.StoreInt64(&r.LastSubmissionAt, now)
|
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
|
// Immediately refresh current BT and send new jobs
|
||||||
s.refreshBlockTemplate(true)
|
s.refreshBlockTemplate(true)
|
||||||
}
|
}
|
||||||
} else if hashDiff < e.config.Difficulty {
|
} else if hashDiff < cs.endpoint.config.Difficulty {
|
||||||
log.Printf("Rejected low difficulty share of %v from %v@%v", hashDiff, m.id, m.ip)
|
log.Printf("Rejected low difficulty share of %v from %v@%v", hashDiff, m.id, cs.ip)
|
||||||
atomic.AddUint64(&m.invalidShares, 1)
|
atomic.AddUint64(&m.invalidShares, 1)
|
||||||
return false
|
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
|
return true
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user